import Mathlib
import Development.AbelianVarietyTheory.PublishedTheorems.Divisors₂.GeometricallyConnectedOfIsIsoRestrict
import Development.AbelianVarietyTheory.Definitions.Divisors.ExistsIsLogMult
import Development.AbelianVarietyTheory.Definitions.Divisors.AdjKltOfLtDisc
import Development.AbelianVarietyTheory.Proofs.DivisorProofs.RingEquivTransportsVarietyPairData
open CategoryTheory AlgebraicGeometry TopologicalSpace
open ReciprocityTheory.ChartRestriction.G ReciprocityTheory.ChartRestriction.G.Semi ReciprocityTheory.ChartRestriction.G.Geo.Tor ReciprocityTheory.AnForm.R
open GlobalTheory GlobalTheory.Cartier GlobalTheory.TopForm GlobalTheory.Discrepancy GlobalTheory.FieldPair

set_option autoImplicit false

namespace GlobalTheory.FieldPair

theorem placeEquiv_ringEquiv : ∀ {k K K' : Type} [Field k] [CharZero k] [Field K] [Field K'] (c : k →+* K) (c' : k →+* K') (e : K ≃+* K'), (∀ a, e (c a) = c' a) → ∃ Φ : Place c ≃ Place c', ∀ E : Place c, (∀ a, e a ∈ (Φ E).ring ↔ a ∈ E.ring) ∧ (∀ a, (Φ E).ord (e a) = E.ord a) ∧ (∀ φ : K →₀ ℚ, (Φ E).ordQ (Finsupp.mapDomain e φ) = E.ordQ φ) ∧ ∀ (n : ℕ) (x : Fin n → K), TrBasis c x → (Φ E).formOrd (dForm c' (e ∘ x)) = E.formOrd (dForm c x) := by
  intro k K K' _ _ _ _ c c' e he
  refine ⟨⟨RingEquivTransport.place e he,
    RingEquivTransport.place e.symm (RingEquivTransport.symm_apply e he),
    RingEquivTransport.place_symm_place e he, RingEquivTransport.place_place_symm e he⟩,
    fun E => ⟨RingEquivTransport.apply_mem_place e he E, RingEquivTransport.ord_place e he E,
      RingEquivTransport.ordQ_place e he E, fun n x _ => ?_⟩⟩
  have hd : dForm c' (e ∘ x) = TopForm.formMap n e.toRingHom (RingHom.ext he) (dForm c x) :=
    (TopForm.formMap_dForm e.toRingHom (RingHom.ext he) x).symm
  change (RingEquivTransport.place e he E).formOrd _ = _
  rw [hd]
  exact RingEquivTransport.formOrd_place e he E _

end GlobalTheory.FieldPair
