File size: 26,596 Bytes
720fa25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
import Mathlib
import OAI.Geometry.BallPacking.Surfaces.QuadricAnnulusDomain
import OAI.Geometry.BallPacking.Forms.ManifoldMapDifferential

namespace OAI

noncomputable section

namespace PackingSufficiencySupport.CubicModel
open scoped ContDiff Manifold Topology
open Set Function Manifold
open DiagonalQuadrics DiagonalQuadrics.Explicit Hamiltonian

 def planeAffine : PlaneBase →L[ℂ] Affine 1 :=
  (ContinuousLinearMap.fst ℂ ℂ ℂ).prod
    (ContinuousLinearMap.pi fun _ : Fin 1 => ContinuousLinearMap.snd ℂ ℂ ℂ)

 theorem planeAffine_injective : Injective planeAffine := by
  intro z w h
  exact Prod.ext (congrArg (fun q : Affine 1 => q.1) h)
    (congrArg (fun q : Affine 1 => q.2 0) h)

 def projectiveInclusion (x : BaseCurve) : Affine 1 := planeAffine (inclusion x)
 def phaseInclusion (x : BaseCurve) : PlanePhase (Option (Fin 1)) :=
  affinePhase 1 (projectiveInclusion x)

 theorem phaseInclusion_smooth :
    ContMDiff 𝓘(ℝ,RealModel) 𝓘(ℝ,PlanePhase (Option (Fin 1))) ∞ phaseInclusion :=
  (affinePhase 1).contDiff.contMDiff.comp
    ((planeAffine.restrictScalars ℝ).contDiff.contMDiff.comp
      ((projection_contDiff.restrict_scalars ℝ).contMDiff.comp
        (real_inclusion_contMDiff (parameters 0))))

 def curveFSPrimitive (c : ℝ) : ManifoldOneForm RealModel BaseCurve :=
  manifoldPullbackOneForm (fun _ => affineFSPrimitive c) phaseInclusion 0
 def curveFSForm (c : ℝ) : ManifoldTwoForm RealModel BaseCurve :=
  manifoldPullbackTwoForm (fun _ => affineFSForm c) phaseInclusion 0

 theorem curveFSPrimitive_smooth (c : ℝ) :
    SmoothOneFormFamily (fun _ : ℝ => curveFSPrimitive c) := by
  have hα : SmoothOneFormFamily (fun _ : ℝ =>
      (affineFSPrimitive c : PlanePhase (Option (Fin 1)) → _)) :=
    vector_oneForm_smooth (affineFSPrimitive_smooth c)
  intro b
  exact manifoldPullbackOneForm_smooth (α := fun _ : ℝ =>
    (affineFSPrimitive c : PlanePhase (Option (Fin 1)) → _)) phaseInclusion_smooth hα b

 theorem curveFSForm_smooth (c : ℝ) : SmoothTwoForm (curveFSForm c) := by
  have hΩ : SmoothTwoForm (affineFSForm c : PlanePhase (Option (Fin 1)) → _) :=
    vector_twoForm_smooth (affineFSForm_smooth c)
  have hΩf : SmoothTwoFormFamily (fun _ : ℝ =>
      (affineFSForm c : PlanePhase (Option (Fin 1)) → _)) := SmoothTwoFormFamily.const hΩ
  have hs : SmoothTwoFormFamily (fun t : ℝ =>
      manifoldPullbackTwoForm (fun _ => (affineFSForm c : PlanePhase (Option (Fin 1)) → _))
        phaseInclusion t) :=
    manifoldPullbackTwoForm_smooth (Ω := fun _ =>
      (affineFSForm c : PlanePhase (Option (Fin 1)) → _)) phaseInclusion_smooth hΩf
  exact hs.eval 0

 theorem curveFSPrimitive_exterior (c : ℝ) :
    manifoldExteriorOneForm (curveFSPrimitive c)=curveFSForm c := by
  have hα : ∀ z : PlanePhase (Option (Fin 1)),ContDiffOn ℝ ∞
      (chartOneForm (affineFSPrimitive c) z) (extChartAt 𝓘(ℝ,PlanePhase (Option (Fin 1))) z).target := by
    intro z
    rw [show chartOneForm (affineFSPrimitive c) z=affineFSPrimitive c from
      funext (vector_chartOneForm (affineFSPrimitive c) z)]
    exact (affineFSPrimitive_smooth c).contDiffOn
  funext x
  change manifoldExteriorOneForm (manifoldPullbackOneForm
    (fun _ => (affineFSPrimitive c : PlanePhase (Option (Fin 1)) → _)) phaseInclusion 0) x=_
  rw [manifold_pullback_exterior hα phaseInclusion_smooth x]
  rw [vector_exteriorOneForm,← affineFSForm_eq_exterior]
  rfl

 theorem curveFSForm_skew (c : ℝ) (x : BaseCurve) (v w : RealModel) :
    curveFSForm c x v w= -curveFSForm c x w v := affineFSForm_skew c _ _ _

 def cubicChart (b : BaseCurve) : ℂ → Affine 1 :=
  planeAffine ∘ projection ∘ (normalChartAt (parameters 0) b).inclusionChart b

 theorem cubicChart_smooth (b : BaseCurve) : ContDiffOn ℂ ∞ (cubicChart b)
    ((normalChartAt (parameters 0) b).sliceChart b).target :=
  planeAffine.contDiff.comp_contDiffOn (projection_contDiff.comp_contDiffOn
    ((normalChartAt (parameters 0) b).inclusionChart_smooth b))

 theorem cubicChart_derivative_one_ne (b : BaseCurve) {y : ℂ}
    (hy : y∈((normalChartAt (parameters 0) b).sliceChart b).target) :
    fderiv ℂ (cubicChart b) y 1≠0 := by
  let e := normalChartAt (parameters 0) b
  let f := e.inclusionChart b
  have hf : DifferentiableAt ℂ f y :=
    ((e.inclusionChart_smooth b).contDiffAt ((e.sliceChart b).open_target.mem_nhds hy)).differentiableAt (by simp)
  have hp : DifferentiableAt ℂ (projection ∘ f) y := (projection_contDiff.differentiable (by simp) (f y)).comp y hf
  have hne : (projection (f y)).1≠0 := inclusion_fst_ne_zero ((e.sliceChart b).symm y)
  have hr : DifferentiableAt ℂ recovery (projection (f y)) :=
    (recovery_contDiffOn.contDiffAt ((isOpen_ne_fun continuous_fst continuous_const).mem_nhds hne)).differentiableAt (by simp)
  have heq : recovery ∘ (projection ∘ f)=f := by
    funext z
    exact recovery_inclusion ((e.sliceChart b).symm z)
  have hd : (fderiv ℂ recovery (projection (f y))).comp (fderiv ℂ (projection ∘ f) y)=fderiv ℂ f y := by
    calc
      _=fderiv ℂ (recovery ∘ (projection ∘ f)) y := by
        simpa only [Function.comp_apply] using (fderiv_comp y hr hp).symm
      _=_ := congrArg (fun g => fderiv ℂ g y) heq
  intro hz
  have hz' : planeAffine (fderiv ℂ (projection ∘ f) y 1)=0 := by
    change (fderiv ℂ (planeAffine ∘ (projection ∘ f)) y) 1=0 at hz
    rw [fderiv_comp y planeAffine.differentiableAt hp,ContinuousLinearMap.fderiv] at hz
    exact hz
  have hp0 : fderiv ℂ (projection ∘ f) y 1=0 :=
    planeAffine_injective (by simpa only [map_zero] using hz')
  apply e.inclusionChart_derivative_one_ne b hy
  have hx := congrArg (fun L : ℂ→L[ℂ] Affine 2 => L 1) hd
  simpa only [ContinuousLinearMap.comp_apply,hp0,map_zero] using hx.symm

 theorem phase_chart_function (b : BaseCurve) :
    (phaseInclusion ∘ (extChartAt 𝓘(ℝ,RealModel) b).symm)=
      affinePhase 1 ∘ cubicChart b ∘ Complex.equivRealProdCLM.symm := by
  funext y
  have he : chartAt RealModel b=realChart (parameters 0) b := rfl
  simp only [mfld_simps,he,realChart,Function.comp_apply,phaseInclusion,
    projectiveInclusion,cubicChart,inclusion,NormalChart.inclusionChart]
  rfl

 theorem phase_chart_derivative (b : BaseCurve) {y : RealModel}
    (hy : y∈(extChartAt 𝓘(ℝ,RealModel) b).target) :
    manifoldMapDifferential (E := PlanePhase (Option (Fin 1))) (F := RealModel)
      (phaseInclusion ∘ (extChartAt 𝓘(ℝ,RealModel) b).symm) y=
    realPhaseDerivative (fderiv ℂ (cubicChart b) (Complex.equivRealProdCLM.symm y)) := by
  change mfderiv 𝓘(ℝ,RealModel) 𝓘(ℝ,PlanePhase (Option (Fin 1))) _ y=_
  rw [mfderiv_eq_fderiv,phase_chart_function]
  have hdf := ((cubicChart_smooth b).contDiffAt
    (((normalChartAt (parameters 0) b).sliceChart b).open_target.mem_nhds
      (realChart_complex_target (parameters 0) b hy))).differentiableAt (by simp)
  exact ((affinePhase 1).hasFDerivAt.comp y
    ((hdf.hasFDerivAt.restrictScalars ℝ).comp y Complex.equivRealProdCLM.symm.hasFDerivAt)).fderiv

 theorem curveFSForm_positive {c : ℝ} (hc : 0<c) (b : BaseCurve) {y : RealModel}
    (hy : y∈(extChartAt 𝓘(ℝ,RealModel) b).target) :
    0<chartTwoForm (curveFSForm c) b y (1,0) (0,1) := by
  rw [curveFSForm,chartTwoForm_manifoldPullback phaseInclusion_smooth (p := (0,y)) hy]
  change 0<affineFSForm c _
    (manifoldMapDifferential (E := PlanePhase (Option (Fin 1))) (F := RealModel)
      (phaseInclusion ∘ (extChartAt 𝓘(ℝ,RealModel) b).symm) y (1,0))
    (manifoldMapDifferential (E := PlanePhase (Option (Fin 1))) (F := RealModel)
      (phaseInclusion ∘ (extChartAt 𝓘(ℝ,RealModel) b).symm) y (0,1))
  rw [phase_chart_derivative b hy]
  apply affineFSForm_holomorphic_positive hc
  exact cubicChart_derivative_one_ne b (realChart_complex_target (parameters 0) b hy)

def weightedProjection (D m : ℕ) (z : PlaneBase) : Affine 3 :=
  (z.1^(D-m),![z.2^(D-m),z.1^(D-m)*z.2^m,z.1^m*z.2^(D-m)])

def weightedHomogeneous (D m : ℕ) (u v w : ℂ) : Fin 5 → ℂ :=
  ![u^D,u^m*v^(D-m),u^m*w^(D-m),v^(D-m)*w^m,v^m*w^(D-m)]

 theorem weightedProjection_contDiff (D m : ℕ) : ContDiff ℂ ∞ (weightedProjection D m) := by
  apply ContDiff.prodMk (contDiff_fst.pow (D-m))
  apply contDiff_pi.mpr
  intro j
  fin_cases j
  · exact contDiff_snd.pow (D-m)
  · exact (contDiff_fst.pow (D-m)).mul (contDiff_snd.pow m)
  · exact (contDiff_fst.pow m).mul (contDiff_snd.pow (D-m))

 theorem weightedHomogeneous_homogeneous (D m : ℕ) (hm : m≤D) (ζ u v w : ℂ) :
    weightedHomogeneous D m (ζ*u) (ζ*v) (ζ*w)=ζ^D • weightedHomogeneous D m u v w := by
  have hD : m+(D-m)=D := Nat.add_sub_of_le hm
  have hD' : (D-m)+m=D := Nat.sub_add_cancel hm
  funext j
  fin_cases j
  · change (ζ*u)^D=ζ^D*u^D
    exact mul_pow ζ u D
  · change (ζ*u)^m*(ζ*v)^(D-m)=ζ^D*(u^m*v^(D-m))
    calc
      _=(ζ^m*ζ^(D-m))*(u^m*v^(D-m)) := by simp only [mul_pow]; ring
      _=_ := by rw [←pow_add,hD]
  · change (ζ*u)^m*(ζ*w)^(D-m)=ζ^D*(u^m*w^(D-m))
    calc
      _=(ζ^m*ζ^(D-m))*(u^m*w^(D-m)) := by simp only [mul_pow]; ring
      _=_ := by rw [←pow_add,hD]
  · change (ζ*v)^(D-m)*(ζ*w)^m=ζ^D*(v^(D-m)*w^m)
    calc
      _=(ζ^(D-m)*ζ^m)*(v^(D-m)*w^m) := by simp only [mul_pow]; ring
      _=_ := by rw [←pow_add,hD']
  · change (ζ*v)^m*(ζ*w)^(D-m)=ζ^D*(v^m*w^(D-m))
    calc
      _=(ζ^m*ζ^(D-m))*(v^m*w^(D-m)) := by simp only [mul_pow]; ring
      _=_ := by rw [←pow_add,hD]

 theorem weightedProjection_fderiv_fst (D m : ℕ) (z v : PlaneBase) :
    (fderiv ℂ (weightedProjection D m) z v).1=(D-m:ℕ)*z.1^(D-m-1)*v.1 := by
  have h := ((hasFDerivAt_fst (𝕜 := ℂ) (p := z)).pow (D-m))
  have hc := (ContinuousLinearMap.fst ℂ ℂ (Fin 3→ℂ)).hasFDerivAt.comp z
    ((weightedProjection_contDiff D m).differentiable (by simp) z).hasFDerivAt
  have he : (ContinuousLinearMap.fst ℂ ℂ (Fin 3→ℂ)) ∘ weightedProjection D m=
      fun z : PlaneBase => z.1^(D-m) := rfl
  rw [he] at hc
  have hd := hc.unique h
  have hh := congrArg (fun A : PlaneBase→L[ℂ] ℂ => A v) hd
  simpa only [ContinuousLinearMap.comp_apply,ContinuousLinearMap.coe_fst',
    smul_apply,nsmul_eq_mul,smul_eq_mul] using hh

 theorem weightedProjection_fderiv_snd (D m : ℕ) (z v : PlaneBase) :
    (fderiv ℂ (weightedProjection D m) z v).2 0=(D-m:ℕ)*z.2^(D-m-1)*v.2 := by
  let P : Affine 3→L[ℂ] ℂ := (ContinuousLinearMap.proj 0).comp (ContinuousLinearMap.snd ℂ ℂ (Fin 3→ℂ))
  have h := ((hasFDerivAt_snd (𝕜 := ℂ) (p := z)).pow (D-m))
  have hc := P.hasFDerivAt.comp z
    ((weightedProjection_contDiff D m).differentiable (by simp) z).hasFDerivAt
  have he : P ∘ weightedProjection D m=fun z : PlaneBase => z.2^(D-m) := rfl
  rw [he] at hc
  have hd := hc.unique h
  have hh := congrArg (fun A : PlaneBase→L[ℂ] ℂ => A v) hd
  simpa only [P,ContinuousLinearMap.comp_apply,ContinuousLinearMap.coe_snd',
    ContinuousLinearMap.proj_apply,smul_apply,nsmul_eq_mul,smul_eq_mul] using hh

 theorem weightedProjection_fderiv_kernel {D m : ℕ} (hm : m<D) {z : PlaneBase}
    (hzv : z.1≠0) (hzw : z.2≠0) {v : PlaneBase}
    (hv : fderiv ℂ (weightedProjection D m) z v=0) : v=0 := by
  have hL : (D-m:ℕ)≠0 := (Nat.sub_pos_of_lt hm).ne'
  have hLc : ((D-m:ℕ):ℂ)≠0 := by exact_mod_cast hL
  have hv0 := weightedProjection_fderiv_fst D m z v
  have hw0 := weightedProjection_fderiv_snd D m z v
  rw [hv] at hv0 hw0
  apply Prod.ext
  · exact (mul_eq_zero.mp hv0.symm).resolve_left (mul_ne_zero hLc (pow_ne_zero _ hzv))
  · exact (mul_eq_zero.mp hw0.symm).resolve_left (mul_ne_zero hLc (pow_ne_zero _ hzw))

 def weightedInclusion (D m : ℕ) (x : BaseCurve) : Affine 3 :=
  weightedProjection D m (inclusion x)

 theorem weightedInclusion_smooth (D m : ℕ) :
    ContMDiff 𝓘(ℂ,ℂ) 𝓘(ℂ,Affine 3) ∞ (weightedInclusion D m) :=
  (weightedProjection_contDiff D m).contMDiff.comp inclusion_contMDiff

 def weightedChart (D m : ℕ) (b : BaseCurve) : ℂ → Affine 3 :=
  weightedProjection D m ∘ projection ∘ (normalChartAt (parameters 0) b).inclusionChart b

 theorem weightedChart_smooth (D m : ℕ) (b : BaseCurve) :
    ContDiffOn ℂ ∞ (weightedChart D m b) ((normalChartAt (parameters 0) b).sliceChart b).target :=
  (weightedProjection_contDiff D m).comp_contDiffOn
    (projection_contDiff.comp_contDiffOn ((normalChartAt (parameters 0) b).inclusionChart_smooth b))

 theorem weightedChart_derivative_one_ne {D m : ℕ} (hm : m<D) (b : BaseCurve) {y : ℂ}
    (hy : y∈((normalChartAt (parameters 0) b).sliceChart b).target) :
    fderiv ℂ (weightedChart D m b) y 1≠0 := by
  let e := normalChartAt (parameters 0) b
  let f := projection ∘ e.inclusionChart b
  have hf : DifferentiableAt ℂ f y :=
    ((projection_contDiff.comp_contDiffOn (e.inclusionChart_smooth b)).contDiffAt
      ((e.sliceChart b).open_target.mem_nhds hy)).differentiableAt (by simp)
  intro hz
  change fderiv ℂ (weightedProjection D m ∘ f) y 1=0 at hz
  rw [fderiv_comp y ((weightedProjection_contDiff D m).differentiable (by simp) _) hf] at hz
  have hz' : fderiv ℂ f y 1=0 := weightedProjection_fderiv_kernel hm
    (inclusion_fst_ne_zero ((e.sliceChart b).symm y))
    (inclusion_snd_ne_zero ((e.sliceChart b).symm y)) hz
  apply cubicChart_derivative_one_ne b hy
  change fderiv ℂ (planeAffine ∘ f) y 1=0
  rw [fderiv_comp y planeAffine.differentiableAt hf,ContinuousLinearMap.fderiv,
    ContinuousLinearMap.comp_apply,hz',map_zero]

 def weightedPhaseInclusion (D m : ℕ) (x : BaseCurve) : PlanePhase (Option (Fin 3)) :=
  affinePhase 3 (weightedInclusion D m x)

 theorem weightedPhaseInclusion_smooth (D m : ℕ) :
    ContMDiff 𝓘(ℝ,RealModel) 𝓘(ℝ,PlanePhase (Option (Fin 3))) ∞ (weightedPhaseInclusion D m) :=
  (affinePhase 3).contDiff.contMDiff.comp
    (((weightedProjection_contDiff D m).restrict_scalars ℝ).contMDiff.comp
      ((projection_contDiff.restrict_scalars ℝ).contMDiff.comp
        (real_inclusion_contMDiff (parameters 0))))

 def weightedFSPrimitive (D m : ℕ) (c : ℝ) : ManifoldOneForm RealModel BaseCurve :=
  manifoldPullbackOneForm (fun _ => affineFSPrimitive c) (weightedPhaseInclusion D m) 0
 def weightedFSForm (D m : ℕ) (c : ℝ) : ManifoldTwoForm RealModel BaseCurve :=
  manifoldPullbackTwoForm (fun _ => affineFSForm c) (weightedPhaseInclusion D m) 0

 theorem weightedFSPrimitive_smooth (D m : ℕ) (c : ℝ) :
    SmoothOneFormFamily (fun _ : ℝ => weightedFSPrimitive D m c) := by
  have hα : SmoothOneFormFamily (fun _ : ℝ =>
      (affineFSPrimitive c : PlanePhase (Option (Fin 3)) → _)) :=
    vector_oneForm_smooth (affineFSPrimitive_smooth c)
  intro b
  exact manifoldPullbackOneForm_smooth (α := fun _ : ℝ =>
    (affineFSPrimitive c : PlanePhase (Option (Fin 3)) → _)) (weightedPhaseInclusion_smooth D m) hα b

 theorem weightedFSForm_smooth (D m : ℕ) (c : ℝ) : SmoothTwoForm (weightedFSForm D m c) := by
  have hΩ : SmoothTwoForm (affineFSForm c : PlanePhase (Option (Fin 3)) → _) :=
    vector_twoForm_smooth (affineFSForm_smooth c)
  have hΩf : SmoothTwoFormFamily (fun _ : ℝ =>
      (affineFSForm c : PlanePhase (Option (Fin 3)) → _)) := SmoothTwoFormFamily.const hΩ
  have hs : SmoothTwoFormFamily (fun t : ℝ =>
      manifoldPullbackTwoForm (fun _ => (affineFSForm c : PlanePhase (Option (Fin 3)) → _))
        (weightedPhaseInclusion D m) t) :=
    manifoldPullbackTwoForm_smooth (Ω := fun _ =>
      (affineFSForm c : PlanePhase (Option (Fin 3)) → _)) (weightedPhaseInclusion_smooth D m) hΩf
  exact hs.eval 0

 theorem weightedFSPrimitive_exterior (D m : ℕ) (c : ℝ) :
    manifoldExteriorOneForm (weightedFSPrimitive D m c)=weightedFSForm D m c := by
  have hα : ∀ z : PlanePhase (Option (Fin 3)),ContDiffOn ℝ ∞
      (chartOneForm (affineFSPrimitive c) z) (extChartAt 𝓘(ℝ,PlanePhase (Option (Fin 3))) z).target := by
    intro z
    rw [show chartOneForm (affineFSPrimitive c) z=affineFSPrimitive c from
      funext (vector_chartOneForm (affineFSPrimitive c) z)]
    exact (affineFSPrimitive_smooth c).contDiffOn
  funext x
  change manifoldExteriorOneForm (manifoldPullbackOneForm
    (fun _ => (affineFSPrimitive c : PlanePhase (Option (Fin 3)) → _)) (weightedPhaseInclusion D m) 0) x=_
  rw [manifold_pullback_exterior hα (weightedPhaseInclusion_smooth D m) x]
  rw [vector_exteriorOneForm,← affineFSForm_eq_exterior]
  rfl

 theorem weightedFSForm_skew (D m : ℕ) (c : ℝ) (x : BaseCurve) (v w : RealModel) :
    weightedFSForm D m c x v w= -weightedFSForm D m c x w v := affineFSForm_skew c _ _ _

 theorem weighted_phase_chart_function (D m : ℕ) (b : BaseCurve) :
    (weightedPhaseInclusion D m ∘ (extChartAt 𝓘(ℝ,RealModel) b).symm)=
      affinePhase 3 ∘ weightedChart D m b ∘ Complex.equivRealProdCLM.symm := by
  funext y
  have he : chartAt RealModel b=realChart (parameters 0) b := rfl
  simp only [mfld_simps,he,realChart,Function.comp_apply,weightedPhaseInclusion,
    weightedInclusion,weightedChart,inclusion,NormalChart.inclusionChart]
  rfl

 theorem weighted_phase_chart_derivative (D m : ℕ) (b : BaseCurve) {y : RealModel}
    (hy : y∈(extChartAt 𝓘(ℝ,RealModel) b).target) :
    manifoldMapDifferential (E := PlanePhase (Option (Fin 3))) (F := RealModel)
      (weightedPhaseInclusion D m ∘ (extChartAt 𝓘(ℝ,RealModel) b).symm) y=
    realPhaseDerivative (fderiv ℂ (weightedChart D m b) (Complex.equivRealProdCLM.symm y)) := by
  change mfderiv 𝓘(ℝ,RealModel) 𝓘(ℝ,PlanePhase (Option (Fin 3))) _ y=_
  rw [mfderiv_eq_fderiv,weighted_phase_chart_function]
  have hdf := ((weightedChart_smooth D m b).contDiffAt
    (((normalChartAt (parameters 0) b).sliceChart b).open_target.mem_nhds
      (realChart_complex_target (parameters 0) b hy))).differentiableAt (by simp)
  exact ((affinePhase 3).hasFDerivAt.comp y
    ((hdf.hasFDerivAt.restrictScalars ℝ).comp y Complex.equivRealProdCLM.symm.hasFDerivAt)).fderiv

 theorem weightedFSForm_positive {D m : ℕ} (hm : m<D) {c : ℝ} (hc : 0<c) (b : BaseCurve) {y : RealModel}
    (hy : y∈(extChartAt 𝓘(ℝ,RealModel) b).target) :
    0<chartTwoForm (weightedFSForm D m c) b y (1,0) (0,1) := by
  rw [weightedFSForm,chartTwoForm_manifoldPullback (weightedPhaseInclusion_smooth D m) (p := (0,y)) hy]
  change 0<affineFSForm c _
    (manifoldMapDifferential (E := PlanePhase (Option (Fin 3))) (F := RealModel)
      (weightedPhaseInclusion D m ∘ (extChartAt 𝓘(ℝ,RealModel) b).symm) y (1,0))
    (manifoldMapDifferential (E := PlanePhase (Option (Fin 3))) (F := RealModel)
      (weightedPhaseInclusion D m ∘ (extChartAt 𝓘(ℝ,RealModel) b).symm) y (0,1))
  rw [weighted_phase_chart_derivative D m b hy]
  apply affineFSForm_holomorphic_positive hc
  exact weightedChart_derivative_one_ne hm b (realChart_complex_target (parameters 0) b hy)

end PackingSufficiencySupport.CubicModel

namespace PackingSufficiencySupport.DiagonalQuadrics
open scoped ContDiff Topology
open Set Function
open Hamiltonian
open scoped BigOperators ComplexConjugate
section

variable {m : ℕ} (a : Fin m → ℂ) (ε : Fin m → Bool)

def infinityRegularPoint (s : ℂ) : Affine m := (s,infinityRoot a ε s)

theorem infinityRegularPoint_contDiffAt {s : ℂ} (hs : s∈infinityRegion a) :
    ContDiffAt ℂ ∞ (infinityRegularPoint a ε) s :=
  contDiffAt_id.prodMk (infinityRoot_contDiffAt a ε hs)

theorem infinityRegularPoint_fderiv {s : ℂ} (hs : s∈infinityRegion a) (u : ℂ) :
    fderiv ℂ (infinityRegularPoint a ε) s u=(u,fderiv ℂ (infinityRoot a ε) s u) := by
  have hr := ((infinityRoot_contDiffAt a ε hs).differentiableAt (by simp)).hasFDerivAt
  have H := (hasFDerivAt_id s).prodMk hr
  change HasFDerivAt (infinityRegularPoint a ε) _ s at H
  rw [H.fderiv]
  rfl

theorem infinityPoint_fderiv {s : ℂ} (hs : s∈infinityDomain a) (u : ℂ) :
    fderiv ℂ (infinityPoint a ε) s u=
      (-u/s^2,fun j => (fderiv ℂ (infinityRoot a ε) s u j)/s-
        (infinityRoot a ε s j/s)*(u/s)) := by
  have hi := (hasDerivAt_inv hs.1).hasFDerivAt
  have hr := ((infinityRoot_contDiffAt a ε hs.2).differentiableAt (by simp)).hasFDerivAt
  have H := hi.prodMk (hi.smul hr)
  change HasFDerivAt (infinityPoint a ε) _ s at H
  rw [H.fderiv]
  apply Prod.ext
  · change u * (-(s^2)⁻¹)= -u/s^2
    ring
  · funext j
    change s⁻¹ * (fderiv ℂ (infinityRoot a ε) s u j)+
      (u * (-(s^2)⁻¹))*infinityRoot a ε s j=_
    ring

theorem realPhaseDerivative_fderiv {f : ℂ → Affine m} {s : ℂ}
    (hf : DifferentiableAt ℂ f s) :
    fderiv ℝ (fun y : Plane => affinePhase m (f (Complex.equivRealProdCLM.symm y)))
      (Complex.equivRealProdCLM s)=realPhaseDerivative (fderiv ℂ f s) := by
  have hd := (affinePhase m).hasFDerivAt.comp (Complex.equivRealProdCLM s)
    ((hf.hasFDerivAt.restrictScalars ℝ).comp (Complex.equivRealProdCLM s)
      Complex.equivRealProdCLM.symm.hasFDerivAt)
  simpa only [ContinuousLinearEquiv.symm_apply_apply,Function.comp_def,realPhaseDerivative] using hd.fderiv

end

 def complexArea (z v : ℂ) : ℝ := (conj z*v).im

 theorem complexArea_apply (z v : ℂ) : complexArea z v=z.re*v.im-z.im*v.re := by
  simp only [complexArea,Complex.mul_im,Complex.conj_re,Complex.conj_im]
  ring

 theorem complexArea_sub (z v w : ℂ) : complexArea z (v-w)=complexArea z v-complexArea z w := by
  simp only [complexArea,mul_sub,Complex.sub_im]

 theorem complexArea_mul (s z v : ℂ) : complexArea (s*z) (s*v)=Complex.normSq s*complexArea z v := by
  unfold complexArea
  rw [map_mul]
  have he : conj s*conj z*(s*v)=(Complex.normSq s : ℂ)*(conj z*v) := by
    rw [Complex.normSq_eq_conj_mul_self]
    ring
  rw [he]
  simp only [Complex.mul_im,Complex.ofReal_re,Complex.ofReal_im,zero_mul,add_zero]

 theorem complexArea_self_mul (z u : ℂ) : complexArea z (z*u)=Complex.normSq z*u.im := by
  unfold complexArea
  rw [← mul_assoc,← Complex.normSq_eq_conj_mul_self]
  simp only [Complex.mul_im,Complex.ofReal_re,Complex.ofReal_im,zero_mul,add_zero]

 theorem complex_div_im (s u : ℂ) : (u/s).im=complexArea s u/Complex.normSq s := by
  rw [Complex.div_im,complexArea_apply]
  ring

 theorem complexArea_div_derivative (s w u v : ℂ) :
    complexArea (w/s) (v/s-(w/s)*(u/s))=
      complexArea w v/Complex.normSq s - Complex.normSq w/(Complex.normSq s)^2*complexArea s u := by
  rw [complexArea_sub,complexArea_self_mul,Complex.normSq_div,complex_div_im]
  have h : complexArea (w/s) (v/s)=complexArea w v/Complex.normSq s := by
    rw [div_eq_mul_inv,div_eq_mul_inv,mul_comm w,mul_comm v,complexArea_mul,Complex.normSq_inv]
    ring
  rw [h]
  ring

 theorem phaseSq_affinePhase {m : ℕ} (z : Affine m) :
    phaseSq (affinePhase m z)=Complex.normSq z.1+∑ j,Complex.normSq (z.2 j) := by
  simp only [phaseSq,phaseDot_apply,Fintype.sum_option,affinePhase_none,affinePhase_some]
  rfl

 theorem phaseArea_affinePhase {m : ℕ} (z v : Affine m) :
    phaseArea (affinePhase m z) (affinePhase m v)=complexArea z.1 v.1+∑ j,complexArea (z.2 j) (v.2 j) := by
  simp only [phaseArea_apply,Fintype.sum_option,affinePhase_none,affinePhase_some,complexArea_apply]

 theorem affineFSPrimitive_complex {m : ℕ} (c : ℝ) (z v : Affine m) :
    affineFSPrimitive c (affinePhase m z) (affinePhase m v)=
      c/(2*(1+Complex.normSq z.1+∑ j,Complex.normSq (z.2 j)))*
        (complexArea z.1 v.1+∑ j,complexArea (z.2 j) (v.2 j)) := by
  change c/(2*(1+phaseSq (affinePhase m z)))*phaseArea (affinePhase m z) (affinePhase m v)=_
  rw [phaseSq_affinePhase,phaseArea_affinePhase]
  rw [add_assoc]

 theorem affineFSPrimitive_projective_swap {m : ℕ} (c : ℝ) {s : ℂ} (hs : s≠0)
    (w : Fin m → ℂ) (u : ℂ) (v : Fin m → ℂ) :
    affineFSPrimitive c (affinePhase m (s⁻¹,fun j => w j/s))
      (affinePhase m (-u/s^2,fun j => v j/s-(w j/s)*(u/s)))=
    affineFSPrimitive c (affinePhase m (s,w)) (affinePhase m (u,v))-
      c/(2*Complex.normSq s)*complexArea s u := by
  have hq : Complex.normSq s≠0 := mt Complex.normSq_eq_zero.mp hs
  have hden : 0<1+Complex.normSq s+∑ j,Complex.normSq (w j) := by
    have hw : 0≤∑ j,Complex.normSq (w j) := Finset.sum_nonneg fun j _ => Complex.normSq_nonneg _
    linarith [Complex.normSq_nonneg s]
  have hbase : complexArea (s⁻¹) (-u/s^2)= -(complexArea s u)/(Complex.normSq s)^2 := by
    have h := complexArea_div_derivative s 1 u 0
    have he : (0 : ℂ)/s-(1/s)*(u/s)= -u/s^2 := by ring
    rw [he] at h
    simp only [one_div,complexArea_apply,Complex.one_re,Complex.one_im,Complex.zero_re,
      Complex.zero_im,mul_zero,sub_zero,Complex.normSq_one,zero_div,zero_sub] at h ⊢
    exact h.trans (by ring)
  rw [affineFSPrimitive_complex,affineFSPrimitive_complex,hbase,Complex.normSq_inv]
  simp only [Complex.normSq_div,complexArea_div_derivative,Finset.sum_sub_distrib,
    ← Finset.sum_div,← Finset.sum_mul]
  have hd : 1+Complex.normSq s+∑ j,Complex.normSq (w j)≠0 := ne_of_gt hden
  field_simp [hq,hd]
  ring_nf
  field_simp [hd]
  ring

end PackingSufficiencySupport.DiagonalQuadrics

namespace PackingSufficiencySupport.Hamiltonian
open scoped Manifold ContDiff

variable {E F G : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
  [NormedAddCommGroup F] [NormedSpace ℝ F] [NormedAddCommGroup G] [NormedSpace ℝ G]
  {M N P : Type*} [TopologicalSpace M] [ChartedSpace E M]
  [TopologicalSpace N] [ChartedSpace F N] [TopologicalSpace P] [ChartedSpace G P]

 theorem manifoldMapDifferential_comp {g : N → M} {f : P → N} {x : P}
    (hg : MDifferentiableAt 𝓘(ℝ,F) 𝓘(ℝ,E) g (f x))
    (hf : MDifferentiableAt 𝓘(ℝ,G) 𝓘(ℝ,F) f x) :
    manifoldMapDifferential (E := E) (F := G) (g ∘ f) x=
      (manifoldMapDifferential (E := E) (F := F) g (f x)).comp (manifoldMapDifferential (E := F) (F := G) f x) :=
  (hg.hasMFDerivAt.comp x hf.hasMFDerivAt).mfderiv

 theorem euclideanPullbackOneForm_comp {g : N → M} {f : G → N} {x : G}
    (hg : MDifferentiableAt 𝓘(ℝ,F) 𝓘(ℝ,E) g (f x))
    (hf : MDifferentiableAt 𝓘(ℝ,G) 𝓘(ℝ,F) f x)
    (α : ManifoldOneForm E M) :
    euclideanPullbackOneForm (E := F) (F := G) (fun _ => manifoldPullbackOneForm (E := E) (F := F) (fun _ => α) g 0) f (0,x)=
      euclideanPullbackOneForm (E := E) (F := G) (fun _ => α) (g ∘ f) (0,x) := by
  change (α (g (f x))).comp
    ((manifoldMapDifferential (E := E) (F := F) g (f x)).comp
      (manifoldMapDifferential (E := F) (F := G) f x))=
    (α (g (f x))).comp (manifoldMapDifferential (E := E) (F := G) (g ∘ f) x)
  rw [manifoldMapDifferential_comp hg hf]

end PackingSufficiencySupport.Hamiltonian
end

end OAI