File size: 6,275 Bytes
8e4d533
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import Mathlib

namespace OAI

section
section
section
noncomputable section
namespace CannonPackingGeometry
open Set Metric

lemma half_cos_pos {a : ℝ} (ha : a∈Ioo (0:ℝ) Real.pi) : 0<Real.cos (a/2) :=
  Real.cos_pos_of_mem_Ioo ⟨by linarith [Real.pi_pos,ha.1],by linarith [ha.2]⟩

theorem intrinsic_inradius_identity {a b c x y z q : ℝ}
    (ha : a∈Ioo (0:ℝ) Real.pi) (hb : b∈Ioo (0:ℝ) Real.pi)
    (hc : c∈Ioo (0:ℝ) Real.pi) (hsum : a+b+c=Real.pi)
    (hx : 0<x) (hy : 0<y) (hz : 0<z) (_hq : 0<q)
    (hax : Real.tan (a/2)=q/x) (hby : Real.tan (b/2)=q/y)
    (hcz : Real.tan (c/2)=q/z) : q^2*(x+y+z)=x*y*z := by
  have hca := half_cos_pos ha
  have hcb := half_cos_pos hb
  have hcc := half_cos_pos hc
  have hsa : Real.sin (a/2)=q/x*Real.cos (a/2) := by
    rw [Real.tan_eq_sin_div_cos] at hax
    exact (div_eq_iff hca.ne').mp hax
  have hsb : Real.sin (b/2)=q/y*Real.cos (b/2) := by
    rw [Real.tan_eq_sin_div_cos] at hby
    exact (div_eq_iff hcb.ne').mp hby
  have hsc : Real.sin (c/2)=q/z*Real.cos (c/2) := by
    rw [Real.tan_eq_sin_div_cos] at hcz
    exact (div_eq_iff hcc.ne').mp hcz
  have hangle : a/2+b/2+c/2=Real.pi/2 := by linarith
  have hzero : Real.cos (a/2+b/2+c/2)=0 := by rw [hangle,Real.cos_pi_div_two]
  rw [Real.cos_add,Real.cos_add,Real.sin_add,hsa,hsb,hsc] at hzero
  have hprod : Real.cos (a/2)*Real.cos (b/2)*Real.cos (c/2)≠0 := by positivity
  have hid : (1-q/y*(q/z)-q/x*(q/z)-q/x*(q/y))*
      (Real.cos (a/2)*Real.cos (b/2)*Real.cos (c/2))=0 := by nlinarith only [hzero]
  have he := (mul_eq_zero.mp hid).resolve_right hprod
  field_simp [hx.ne',hy.ne',hz.ne'] at he
  nlinarith only [he]

theorem intrinsic_cosine_law {a x y z q : ℝ}
    (ha : a∈Ioo (0:ℝ) Real.pi) (hx : 0<x) (_hy : 0<y) (_hz : 0<z)
    (hax : Real.tan (a/2)=q/x) (hid : q^2*(x+y+z)=x*y*z) :
    2*(x+y)*(x+z)*Real.cos a=(x+y)^2+(x+z)^2-(y+z)^2 := by
  have hca := half_cos_pos ha
  have hsa : Real.sin (a/2)=q/x*Real.cos (a/2) := by
    rw [Real.tan_eq_sin_div_cos] at hax
    exact (div_eq_iff hca.ne').mp hax
  have ht := Real.sin_sq_add_cos_sq (a/2)
  rw [hsa] at ht
  have ht' : (q^2+x^2)*Real.cos (a/2)^2=x^2 := by
    field_simp [hx.ne'] at ht
    nlinarith only [ht]
  have hc : Real.cos a=2*Real.cos (a/2)^2-1 := by
    convert Real.cos_two_mul (a/2) using 1
    congr 1
    ring
  rw [hc]
  have hdiv : (x+y)*(x+z)=(x+y+z)*(q^2+x^2)/x := by
    apply (eq_div_iff hx.ne').mpr
    nlinarith only [hid]
  rw [show 2*(x+y)*(x+z)=2*((x+y)*(x+z)) by ring,hdiv]
  field_simp [hx.ne']
  linear_combination 4*(x+y+z)*ht'-2*hid

def trianglePoint (x z a : ℝ) : ℂ := ⟨(x+z)*Real.cos a,(x+z)*Real.sin a⟩

theorem intrinsic_triangle {a b c x y z q : ℝ}
    (ha : a∈Ioo (0:ℝ) Real.pi) (hb : b∈Ioo (0:ℝ) Real.pi)
    (hc : c∈Ioo (0:ℝ) Real.pi) (hsum : a+b+c=Real.pi)
    (hx : 0<x) (hy : 0<y) (hz : 0<z) (hq : 0<q)
    (hax : Real.tan (a/2)=q/x) (hby : Real.tan (b/2)=q/y)
    (hcz : Real.tan (c/2)=q/z) :
    dist (0:ℂ) (x+y : ℂ)=x+y ∧
    dist (0:ℂ) (trianglePoint x z a)=x+z ∧
    dist (x+y : ℂ) (trianglePoint x z a)=y+z ∧
    0<(trianglePoint x z a).im := by
  have hid := intrinsic_inradius_identity ha hb hc hsum hx hy hz hq hax hby hcz
  have hcos := intrinsic_cosine_law ha hx hy hz hax hid
  have hsincos := Real.sin_sq_add_cos_sq a
  have hnorm : ‖trianglePoint x z a‖^2=(x+z)^2 := by
    rw [Complex.sq_norm]
    simp only [trianglePoint,Complex.normSq_apply]
    nlinarith only [hsincos]
  have hnorm' : ‖(x+y : ℂ)-trianglePoint x z a‖^2=(y+z)^2 := by
    rw [Complex.sq_norm]
    simp only [trianglePoint,Complex.normSq_apply,Complex.sub_re,Complex.sub_im,
      Complex.add_re,Complex.add_im,Complex.ofReal_re,Complex.ofReal_im]
    nlinarith only [hsincos,hcos]
  refine ⟨?_,?_,?_,?_⟩
  · rw [dist_zero_left,←Complex.ofReal_add,Complex.norm_real,Real.norm_eq_abs,abs_of_pos (add_pos hx hy)]
  · rw [dist_zero_left]
    nlinarith [norm_nonneg (trianglePoint x z a)]
  · rw [dist_eq_norm]
    nlinarith [norm_nonneg ((x+y : ℂ)-trianglePoint x z a)]
  · exact mul_pos (add_pos hx hz) (Real.sin_pos_of_pos_of_lt_pi ha.1 ha.2)
end CannonPackingGeometry

end
end
section
noncomputable section
namespace CannonPackingGeometry
open Set

def cornerAngle {V A : Type*} (vertex : A × Fin 3 → V) (θ : A × Fin 3 → ℝ)
    (f : A) (v : V) : ℝ := by
  classical
  exact ∑ k : Fin 3, if vertex (f,k)=v then θ (f,k) else 0

lemma cornerAngle_at {V A : Type*} (vertex : A × Fin 3 → V) (θ : A × Fin 3 → ℝ)
    (hinj : ∀ f,Function.Injective (fun k=>vertex (f,k))) (f : A) (k : Fin 3) :
    cornerAngle vertex θ f (vertex (f,k))=θ (f,k) := by
  classical
  unfold cornerAngle
  rw [Finset.sum_eq_single k]
  · simp
  · intro j hj hjk
    simp only [ite_eq_right (fun h=>hjk (hinj f h))]
  · simp

lemma cornerAngle_zero {V A : Type*} (vertex : A × Fin 3 → V) (θ : A × Fin 3 → ℝ)
    (f : A) (v : V) (h : ¬∃ k,vertex (f,k)=v) : cornerAngle vertex θ f v=0 := by
  classical
  apply Finset.sum_eq_zero
  intro k hk
  exact ite_eq_right (fun hk=>h ⟨k,hk⟩)

lemma sum_cornerAngle {V A : Type*} [Fintype A] [DecidableEq V] (vertex : A × Fin 3 → V)
    (θ : A × Fin 3 → ℝ) (v : V) :
    (∑ f,cornerAngle vertex θ f v)=∑ i : A × Fin 3,if vertex i=v then θ i else 0 := by
  classical
  simp only [cornerAngle,Fintype.sum_prod_type]
  apply Finset.sum_congr rfl
  intro f hf
  apply Finset.sum_congr rfl
  intro k hk
  by_cases h : vertex (f,k)=v <;> simp [h]

theorem intrinsic_cosine_law_fin3 (θ r : Fin 3 → ℝ) (q : ℝ)
    (hθ : ∀ k,θ k∈Ioo (0:ℝ) Real.pi) (hs : ∑ k,θ k=Real.pi)
    (hr : ∀ k,0<r k) (hq : 0<q)
    (ht : ∀ k,Real.tan (θ k/2)=q/r k) {i j k : Fin 3}
    (hij : i≠j) (hik : i≠k) (hjk : j≠k) :
    2*(r i+r j)*(r i+r k)*Real.cos (θ i)=
      (r i+r j)^2+(r i+r k)^2-(r j+r k)^2 := by
  have hs' : θ 0+θ 1+θ 2=Real.pi := by simpa only [Fin.sum_univ_three] using hs
  have hid := intrinsic_inradius_identity (hθ 0) (hθ 1) (hθ 2) hs'
    (hr 0) (hr 1) (hr 2) hq (ht 0) (ht 1) (ht 2)
  apply intrinsic_cosine_law (hθ i) (hr i) (hr j) (hr k) (ht i)
  fin_cases i <;> fin_cases j <;> fin_cases k <;> simp_all
  all_goals nlinarith only [hid]
end CannonPackingGeometry

end
end
end
end

end OAI