import Mathlib
import OAI.GroupTheory.SimpleAmenable.Arithmetic.PolygonArithmetic
namespace OAI
section
section
open scoped symmDiff
namespace SimpleAmenable
open scoped commutatorElement
open scoped commutatorElement
section ConcurrentDenominators
noncomputable def lineNormal (a : ℕ) (j : Fin 4) : CutRing × CutRing :=
![(1,0),(0,1),(-(cutTau^a),1),(1,-(cutTau^a))] j
noncomputable def lineDet (a : ℕ) (i j : Fin 4) : CutRing :=
(lineNormal a i).1*(lineNormal a j).2-(lineNormal a j).1*(lineNormal a i).2
theorem cutForm_normal (a : ℕ) (j : Fin 4) (z : ℝ × ℝ) :
cutForm a j z = ordinary (lineNormal a j).1*z.1+ordinary (lineNormal a j).2*z.2 := by
fin_cases j <;> simp [cutForm,lineNormal] <;> ring
theorem lineDet_ne_zero {a : ℕ} (ha : 0 fin_cases j <;>
simp_all [lineDet,lineNormal]
theorem intersection_pair_denominator (a : ℕ) (i j : Fin 4)
(c d : CutRing) (z : ℝ × ℝ)
(hi : cutForm a i z = ordinary c) (hj : cutForm a j z = ordinary d) :
∃ u v : CutRing,
ordinary u=((QuadraticAlgebra.norm (lineDet a i j) : ℤ) : ℝ)*z.1 ∧
ordinary v=((QuadraticAlgebra.norm (lineDet a i j) : ℤ) : ℝ)*z.2 := by
let δ := lineDet a i j
let x := c*(lineNormal a j).2-d*(lineNormal a i).2
let y := (lineNormal a i).1*d-(lineNormal a j).1*c
have hx : ordinary x=ordinary δ*z.1 := by
rw [cutForm_normal] at hi hj
simp only [x,δ,lineDet,map_sub,map_mul]
linear_combination -(ordinary (lineNormal a j).2)*hi+(ordinary (lineNormal a i).2)*hj
have hy : ordinary y=ordinary δ*z.2 := by
rw [cutForm_normal] at hi hj
simp only [y,δ,lineDet,map_sub,map_mul]
linear_combination -(ordinary (lineNormal a i).1)*hj+(ordinary (lineNormal a j).1)*hi
refine ⟨x*star δ,y*star δ,?_,?_⟩ <;>
simp only [map_mul,hx,hy,← conjugate_eq_ordinary_star]
· rw [← cut_norm_identity δ]; ring
· rw [← cut_norm_identity δ]; ring
noncomputable def commonVertexDenominator (a : ℕ) : ℕ :=
(∏ i : Fin 4, ∏ j : Fin 4,
if i=j then (1 : ℤ) else QuadraticAlgebra.norm (lineDet a i j)).natAbs
theorem commonVertexDenominator_pos {a : ℕ} (ha : 0 ∏ j : Fin 4, if i=j then (1 : ℤ) else QuadraticAlgebra.norm (lineDet a i j))
(Finset.mem_univ i)
have hj := Finset.dvd_prod_of_mem
(fun j : Fin 4 => if i=j then (1 : ℤ) else QuadraticAlgebra.norm (lineDet a i j))
(Finset.mem_univ j)
have hh : QuadraticAlgebra.norm (lineDet a i j) ∣
∏ j : Fin 4, if i=j then (1 : ℤ) else QuadraticAlgebra.norm (lineDet a i j) := by
simpa only [ite_eq_right hij] using hj
exact hh.trans hi
theorem all_intersections_common_denominator {a : ℕ} (_ha : 0
simp only [map_mul,map_intCast,hu,hv,hkr] <;> ring
end ConcurrentDenominators
section VertexResidues
noncomputable def cutResidue (D : ℕ) (z : CutRing) : CutRing :=
⟨z.re % (D : ℤ),z.im % (D : ℤ)⟩
noncomputable def cutQuotient (D : ℕ) (z : CutRing) : CutRing :=
⟨z.re / (D : ℤ),z.im / (D : ℤ)⟩
theorem cut_residue_decomposition (D : ℕ) (z : CutRing) :
z = cutResidue D z + (D : CutRing)*cutQuotient D z := by
ext <;> simp [cutResidue,cutQuotient,Int.emod_add_mul_ediv]
noncomputable def finiteCutResidue (D : ℕ) (t : Fin D × Fin D) : CutRing :=
⟨t.1.val,t.2.val⟩
theorem cutResidue_exists_finite {D : ℕ} (hD : 0 simp [cutResidue,finiteCutResidue,p,q,Int.emod_nonneg _ (ne_of_gt hDi)]
noncomputable def vertexRepresentative (D : ℕ)
(t : (Fin D × Fin D) × (Fin D × Fin D)) : ℝ × ℝ :=
(ordinary (finiteCutResidue D t.1)/(D : ℝ),ordinary (finiteCutResidue D t.2)/(D : ℝ))
theorem denominated_vertex_normal_form {D : ℕ} (hD : 0