File size: 27,662 Bytes
a2ee19a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
import Mathlib
import OAI.Probability.ParisiFinite.Compatible

namespace OAI

/-! Insertion From Forward. -/

noncomputable section

open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder
open Filter
open scoped BigOperators
open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate
open scoped InnerProductSpace ComplexConjugate
open scoped InnerProductSpace ComplexConjugate
namespace ForwardControl
variable {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H]

 

theorem insertion_from_forward (U A : H ≃ₗᵢ[ℂ] H) (P : H →L[ℂ] H)
    (hP : ∀ x, ‖P x‖ ≤ ‖x‖) (Ω : H) (ζ : ℂ) :
    ‖U.symm (P (U Ω))-A.symm (P (A Ω))‖ ≤
      ‖U Ω-ζ • A Ω‖+‖U (A.symm (P (A Ω)))-ζ • A (A.symm (P (A Ω)))‖ := by
  rw [← U.norm_map (U.symm (P (U Ω))-A.symm (P (A Ω))),map_sub,U.apply_symm_apply]
  calc
    _ ≤ ‖P (U Ω)-ζ • P (A Ω)‖+
        ‖ζ • P (A Ω)-U (A.symm (P (A Ω)))‖ := norm_sub_le_norm_sub_add_norm_sub _ _ _
    _ ≤ ‖U Ω-ζ • A Ω‖+
        ‖U (A.symm (P (A Ω)))-ζ • A (A.symm (P (A Ω)))‖ := by
      rw [A.apply_symm_apply,norm_sub_rev (ζ • P (A Ω))]
      exact add_le_add (by simpa only [map_sub,map_smul] using hP (U Ω-ζ • A Ω)) le_rfl

 
theorem insertion_split_bound (U A : H ≃ₗᵢ[ℂ] H) (P : H →L[ℂ] H)
    (hP : ∀x, ‖P x‖ ≤ ‖x‖) (Ω : H) (ζ : ℂ)
    (O S : H →L[ℂ] H) (hsplit : ∀x, U x=O x+S x)
    (r ε : ℝ) (hr : 0 ≤ r)
    (hS : ∀x, ‖S x‖ ≤ r*‖x‖)
    (hO₀ : ‖O Ω-ζ • A Ω‖ ≤ ε)
    (hO₁ : ‖O (A.symm (P (A Ω)))-ζ • A (A.symm (P (A Ω)))‖ ≤ ε) :
    ‖U.symm (P (U Ω))-A.symm (P (A Ω))‖ ≤ 2*ε+2*r*‖Ω‖ := by
  have hv : ‖A.symm (P (A Ω))‖ ≤ ‖Ω‖ := by
    rw [A.symm.norm_map]
    exact (hP _).trans_eq (A.norm_map _)
  have hb (x : H) : ‖U x-ζ • A x‖ ≤ ‖O x-ζ • A x‖+r*‖x‖ := by
    rw [hsplit]
    have he : O x+S x-ζ • A x=(O x-ζ • A x)+S x := by abel
    rw [he]
    exact (norm_add_le _ _).trans (add_le_add le_rfl (hS x))
  have h := insertion_from_forward U A P hP Ω ζ
  have h0 := hb Ω
  have h1 := hb (A.symm (P (A Ω)))
  have hh := mul_le_mul_of_nonneg_left hv hr
  linarith

 

theorem selective_flip_bound (V : H ≃ₗᵢ[ℂ] H) (Z F : H →L[ℂ] H)
    (hZ : ∀x, ‖Z x‖ ≤ ‖x‖) (hanti : ∀x, Z (F x)=-F (Z x)) (o s : H) :
    ‖V.symm (Z (V (o+s)))-(Z o-Z s)‖ ≤
      ‖V o-o‖+‖V s-F s‖+‖V (Z o)-Z o‖+‖V (Z s)-F (Z s)‖ := by
  rw [← V.norm_map (V.symm (Z (V (o+s)))-(Z o-Z s)),map_sub,V.apply_symm_apply]
  have he : Z (V (o+s))-V (Z o-Z s) =
      Z (V o-o)+Z (V s-F s)-(V (Z o)-Z o)+(V (Z s)-F (Z s)) := by
    simp only [map_add,map_sub,hanti]
    abel
  rw [he]
  have h1 := norm_add_le (Z (V o-o)+Z (V s-F s)-(V (Z o)-Z o))
    (V (Z s)-F (Z s))
  have h2 := norm_sub_le (Z (V o-o)+Z (V s-F s)) (V (Z o)-Z o)
  have h3 := norm_add_le (Z (V o-o)) (Z (V s-F s))
  have h4 := hZ (V o-o)
  have h5 := hZ (V s-F s)
  linarith

 

theorem actual_flip_change (U V : H ≃ₗᵢ[ℂ] H) (Z F : H →L[ℂ] H)
    (hZ : ∀x, ‖Z x‖ ≤ ‖x‖) (hanti : ∀x, Z (F x)=-F (Z x))
    (Ω o s : H) (hx : U Ω=o+s) :
    ‖U.symm (V.symm (Z (V (U Ω))))-U.symm (Z (U Ω))+
      (2:ℂ) • U.symm (Z s)‖ ≤
      ‖V o-o‖+‖V s-F s‖+‖V (Z o)-Z o‖+‖V (Z s)-F (Z s)‖ := by
  have he : U.symm (V.symm (Z (V (U Ω))))-U.symm (Z (U Ω))+
      (2:ℂ) • U.symm (Z s) =
      U.symm (V.symm (Z (V (o+s)))-(Z o-Z s)) := by
    rw [hx]
    simp only [map_sub,map_add]
    module
  rw [he,U.symm.norm_map]
  exact selective_flip_bound V Z F hZ hanti o s

 

theorem special_transport_bound (V : H ≃ₗᵢ[ℂ] H) (Z F : H →L[ℂ] H)
    (hZ : ∀x, ‖Z x‖ ≤ ‖x‖) (hanti : ∀x, Z (F x)=-F (Z x)) (s : H) :
    ‖V.symm (Z (V s))+Z s‖ ≤ ‖V s-F s‖+‖V (Z s)-F (Z s)‖ := by
  rw [← V.norm_map (V.symm (Z (V s))+Z s),map_add,V.apply_symm_apply]
  have he : Z (V s)+V (Z s)=Z (V s-F s)+(V (Z s)-F (Z s)) := by
    rw [map_sub,hanti]
    abel
  rw [he]
  exact (norm_add_le _ _).trans (add_le_add (hZ _) le_rfl)

end ForwardControl

namespace PointedTree
open CoherentFock RootSpin

 
theorem abs_treeEnergy_le (n : ℕ) (d : Mode n) : |treeEnergy n d| ≤ ‖d‖^2 := by
  calc
    _ ≤ ‖⟪centeredMap (empty n) d,rootShift n d⟫_ℂ‖ := Complex.abs_re_le_norm _
    _ ≤ ‖centeredMap (empty n) d‖*‖rootShift n d‖ := norm_inner_le_norm _ _
    _ = _ := by simp [pow_two]

 

def ordinaryValue (w : List Gate) : ℝ := treeEnergy w.length (ordinary w w.length).insertion

theorem ordinary_energy_succ (w : List Gate) (n : ℕ) (hn : w.length ≤ n) :
    treeEnergy (n+1) (ordinary w (n+1)).insertion=treeEnergy n (ordinary w n).insertion := by
  rw [← ordinary_insertion_empty w n hn,treeEnergy_empty]

theorem ordinary_energy_stable (w : List Gate) (n : ℕ) (hn : w.length ≤ n) :
    treeEnergy n (ordinary w n).insertion=ordinaryValue w := by
  induction n,hn using Nat.le_induction with
  | base => rfl
  | succ n hn ih => rw [ordinary_energy_succ w n hn,ih]

theorem abs_ordinaryValue_le_one (w : List Gate) : |ordinaryValue w| ≤ 1 := by
  simpa only [ordinaryValue,EvenUnitary.norm_insertion,one_pow] using abs_treeEnergy_le w.length (ordinary w w.length).insertion

end PointedTree

namespace SpinOperators
variable {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] [CompleteSpace H]
@[simp] theorem actEquiv_symm_apply (A : Matrix (Fin 2) (Fin 2) ℂ)
    (hA : A ∈ unitary _) (x : Double H) :
    (actEquiv A hA).symm x=act A.conjTranspose x := by
  apply (actEquiv A hA).injective
  rw [LinearIsometryEquiv.apply_symm_apply,actEquiv_apply]
  change x=(act A).comp (act A.conjTranspose) x
  rw [← act_mul]
  have h := (Unitary.mem_iff.mp hA).2
  change A*A.conjTranspose=1 at h
  rw [h,act_one]
  rfl
end SpinOperators

namespace CoherentFock
open RootSpin
variable {E : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E]

@[simp] theorem rootY_apply (x : SpinSpace E) (i : Fin 2) :
    SpinOperators.act Y x i=if i=0 then (-Complex.I) • x 1 else Complex.I • x 0 := by
  fin_cases i <;> simp [SpinOperators.act_apply,Y,Fin.sum_univ_two]

theorem WZ_rootY (d : E) :
    (WZ d).comp (SpinOperators.act Y)=(SpinOperators.act Y).comp (WZ (-d)) := by
  ext x i
  fin_cases i <;> simp [WZ_apply,Y]

@[simp] theorem WZ_same (d : E) (x : SpinSpace E) : WZ d (WZ d x)=WZ (d+d) x := by
  change (WZ d).comp (WZ d) x=_
  rw [WZ_mul]
  have hi : (⟪d,d⟫_ℂ).im=0 := inner_self_im (𝕜 := ℂ) d
  change Complex.exp ((-(⟪d,d⟫_ℂ).im:ℝ)*Complex.I) • WZ (d+d) x=WZ (d+d) x
  rw [hi]
  simp

 
theorem one_layer_insertion (d : E) (β : ℝ) (x : SpinSpace E) :
    WZ (-d) (SpinOperators.act (R β).conjTranspose
      (SpinOperators.act Z (SpinOperators.act (R β) (WZ d x))))=
      (Real.cos (2*β):ℂ) • SpinOperators.act Z x+
      (Real.sin (2*β):ℂ) • SpinOperators.act Y (WZ (d+d) x) := by
  change WZ (-d) ((SpinOperators.act (R β).conjTranspose).comp
    ((SpinOperators.act Z).comp (SpinOperators.act (R β))) (WZ d x))=_
  rw [← ContinuousLinearMap.comp_assoc,← SpinOperators.act_mul,← SpinOperators.act_mul,R_conjugate_Z]
  change WZ (-d) (SpinOperators.rep
    ((Real.cos (2*β):ℂ) • Z+(Real.sin (2*β):ℂ) • Y) (WZ d x))=_
  simp only [map_add,map_smul,SpinOperators.rep_apply,add_apply,smul_apply]
  congr 1
  · congr 1
    change (WZ (-d)).comp (SpinOperators.act Z) (WZ d x)=_
    rw [WZ_rootZ]
    change SpinOperators.act Z (WZ (-d) (WZ d x))=_
    rw [← costEquiv_symm_apply,← costEquiv_apply,LinearIsometryEquiv.symm_apply_apply]
  · congr 1
    change (WZ (-d)).comp (SpinOperators.act Y) (WZ d x)=_
    rw [WZ_rootY,neg_neg]
    exact congrArg (SpinOperators.act Y) (WZ_same d x)
end CoherentFock

namespace PointedTree
open CoherentFock RootSpin

 
def initialDirection (n : ℕ) : Mode n := (EvenUnitary.ident n).insertion

@[simp] theorem initialDirection_coe (n : ℕ) :
    (initialDirection n : Level n)=root n Z (vac n) := rfl

@[simp] theorem initialDirection_norm (n : ℕ) : ‖initialDirection n‖=1 :=
  EvenUnitary.norm_insertion _

@[simp] theorem initialDirection_empty (n : ℕ) :
    centeredMap (empty n) (initialDirection n)=initialDirection (n+1) :=
  (EvenUnitary.compatible_ident n).insertion

 

theorem ordinary_one_insertion (n : ℕ) (γ β : ℝ) :
    ((ordinary [.mixer β,.cost γ] (n+1)).insertion : Level (n+1))=
      (Real.cos (2*β):ℂ) • (initialDirection (n+1) : Level (n+1))+
      (Real.sin (2*β):ℂ) • SpinOperators.act Y
        (WZ ((-(2*γ):ℂ) • initialDirection n) (vac (n+1))) := by
  change (costEquiv ((-(γ:ℂ)) • initialDirection n)).symm
    ((SpinOperators.actEquiv (R β) (R_unitary β)).symm
      (SpinOperators.act Z (SpinOperators.act (R β)
        (costEquiv ((-(γ:ℂ)) • initialDirection n) (vac (n+1))))))=_
  rw [costEquiv_symm_apply,SpinOperators.actEquiv_symm_apply,costEquiv_apply,one_layer_insertion]
  have hd : (-(γ:ℂ)) • initialDirection n+(-(γ:ℂ)) • initialDirection n=
      (-(2*γ):ℂ) • initialDirection n := by module
  rw [hd]
  rfl

 
def initializationWord (γ δ β : ℝ) : List Gate :=
  [.mixer β,.cost (-γ),.mixer δ,.cost γ]

theorem initialization_op (n : ℕ) (γ δ β : ℝ) (x : Level (n+2)) :
    (ordinary (initializationWord γ δ β) (n+2)).op x=
      SpinOperators.act (R β)
        (WZ ((γ:ℂ) • (ordinary [.mixer δ,.cost γ] (n+1)).insertion)
          (SpinOperators.act (R δ) (WZ (-(γ:ℂ) • initialDirection (n+1)) x))) := by
  change SpinOperators.act (R β)
    (WZ ((-((-γ:ℝ):ℂ)) • (ordinary [.mixer δ,.cost γ] (n+1)).insertion)
      (SpinOperators.act (R δ) (WZ (-(γ:ℂ) • initialDirection (n+1)) x)))=_
  simp only [Complex.ofReal_neg,neg_neg]

end PointedTree

namespace CoherentFock
variable {E : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E]
@[simp] theorem W_vacuum (d : E) : W d (coherent 0)=coherent d := by simp
@[simp] theorem kernel_zero_left (d : E) : kernel 0 d=(Real.exp (-‖d‖^2/2):ℂ) := by
  simp [kernel_eq,Complex.ofReal_exp]
end CoherentFock

namespace PointedTree
open CoherentFock RootSpin Complex
variable {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H]

theorem inv_sqrt_two_sq : (((Real.sqrt 2)⁻¹:ℝ):ℂ)^2=1/2 := by
  rw [← Complex.ofReal_pow,inv_pow,Real.sq_sqrt (by norm_num)]
  norm_num

def spinPair (x y : H) : SpinOperators.Double H :=
  WithLp.toLp 2 (fun i => if i=0 then x else y)

@[simp] theorem spinPair_zero (x y : H) : spinPair x y 0=x := by rfl
@[simp] theorem spinPair_one (x y : H) : spinPair x y 1=y := by rfl

theorem inner_spinPair (x y u v : H) :
    ⟪spinPair x y,spinPair u v⟫_ℂ=⟪x,u⟫_ℂ+⟪y,v⟫_ℂ := by
  rw [PiLp.inner_apply,Fin.sum_univ_two]
  rfl

def spinCoefficient : ℂ := (((Real.sqrt 2)⁻¹:ℝ):ℂ)
@[simp] theorem spinCoefficient_conj : conj spinCoefficient=spinCoefficient := by
  simp [spinCoefficient]
@[simp] theorem spinCoefficient_sq : spinCoefficient^2=1/2 := inv_sqrt_two_sq

theorem plusEmbedding_pair (x : H) :
    plusEmbedding x=spinPair (spinCoefficient • x) (spinCoefficient • x) := by
  ext i
  fin_cases i <;> rfl

theorem rootZ_vac_pair : SpinOperators.act Z (vacuum H)=
    spinPair (spinCoefficient • coherent (0:H)) (-(spinCoefficient • coherent (0:H))) := by
  ext i
  fin_cases i <;> simp [Z,spinPair,vacuum_apply,spinCoefficient]

theorem rootY_WZ_vac_pair (d : H) : SpinOperators.act Y (WZ d (vacuum H))=
    spinPair ((-I*spinCoefficient) • coherent (-d)) ((I*spinCoefficient) • coherent d) := by
  ext i
  fin_cases i <;> simp [Y,spinPair,WZ_apply,vacuum_apply,spinCoefficient,smul_smul]

theorem inner_rootZ_vac_creation (v : H) :
    ⟪SpinOperators.act Z (vacuum H),plusEmbedding (creationVacuum v)⟫_ℂ=0 := by
  rw [rootZ_vac_pair,plusEmbedding_pair,inner_spinPair,inner_neg_left]
  exact add_neg_cancel _

theorem inner_rootZ_vac_rootY_WZ (d : H) :
    ⟪SpinOperators.act Z (vacuum H),SpinOperators.act Y (WZ d (vacuum H))⟫_ℂ=
      -I*(Real.exp (-‖d‖^2/2):ℂ) := by
  rw [rootZ_vac_pair,rootY_WZ_vac_pair,inner_spinPair]
  simp only [inner_neg_left,inner_smul_left,inner_smul_right,spinCoefficient_conj,    inner_coherent,kernel_zero_left,norm_neg]
  linear_combination -2*I*(Real.exp (-‖d‖^2/2):ℂ)*spinCoefficient_sq

theorem inner_rootY_WZ_creation (d v : H) :
    ⟪SpinOperators.act Y (WZ d (vacuum H)),plusEmbedding (creationVacuum v)⟫_ℂ=
      -(Real.exp (-‖d‖^2/2):ℂ)*⟪d,v⟫_ℂ := by
  rw [rootY_WZ_vac_pair,plusEmbedding_pair,inner_spinPair]
  simp only [creationVacuum,inner_smul_left,inner_smul_right,    inner_coherent_oneParticle,inner_neg_left,norm_neg,map_neg,map_mul,Complex.conj_I,    spinCoefficient_conj]
  linear_combination -2*(Real.exp (-‖d‖^2/2):ℂ)*⟪d,v⟫_ℂ*spinCoefficient_sq +
    2*spinCoefficient^2*(Real.exp (-‖d‖^2/2):ℂ)*⟪d,v⟫_ℂ*Complex.I_sq

end PointedTree

namespace PointedTree
open CoherentFock RootSpin Complex

 
def highDirection (n : ℕ) (γ : ℝ) : Mode (n+1) :=
  (ordinary [.mixer (Real.pi/4),.cost γ] (n+1)).insertion

@[simp] theorem highDirection_coe (n : ℕ) (γ : ℝ) :
    (highDirection n γ : Level (n+1))=
      SpinOperators.act Y (WZ ((-2*γ:ℝ) • initialDirection n) (vac (n+1))) := by
  unfold highDirection
  rw [ordinary_one_insertion]
  have hpi : 2*(Real.pi/4)=Real.pi/2 := by ring
  simp only [hpi,Real.cos_pi_div_two,Real.sin_pi_div_two,Complex.ofReal_zero,    Complex.ofReal_one,zero_smul,one_smul,zero_add]
  have hd : (-(2*γ):ℂ) • initialDirection n = (-2*γ:ℝ) • initialDirection n := by
    rw [← Complex.coe_smul]
    apply congrArg (fun z : ℂ => z • initialDirection n)
    push_cast
    ring
  rw [hd]

@[simp] theorem highDirection_norm (n : ℕ) (γ : ℝ) : ‖highDirection n γ‖=1 :=
  EvenUnitary.norm_insertion _

@[simp] theorem highDirection_empty (n : ℕ) (γ : ℝ) :
    centeredMap (empty (n+1)) (highDirection n γ)=highDirection (n+1) γ := by
  apply Subtype.ext
  rw [centeredMap_coe,highDirection_coe,highDirection_coe]
  change (empty (n+1)).toLinearIsometry (root (n+1) Y _) = root (n+2) Y _
  rw [root_empty,cost_empty,empty_vac]
  have hd : centeredMap (empty n) ((-2*γ:ℝ) • initialDirection n)=
      (-2*γ:ℝ) • initialDirection (n+1) := by
    calc
      _ = (-2*γ:ℝ) • centeredMap (empty n) (initialDirection n) :=
        (centeredMap (empty n)).map_smul_of_tower _ _
      _ = _ := by rw [initialDirection_empty]
  rw [hd]

theorem initial_inner_highDirection (n : ℕ) (γ : ℝ) :
    ⟪initialDirection (n+1),highDirection n γ⟫_ℂ=
      -I*(Real.exp (-2*γ^2):ℂ) := by
  change ⟪(initialDirection (n+1):Level (n+1)),(highDirection n γ:Level (n+1))⟫_ℂ=_
  rw [initialDirection_coe,highDirection_coe]
  change ⟪SpinOperators.act Z (vacuum (Mode n)),SpinOperators.act Y (WZ _ (vacuum (Mode n)))⟫_ℂ=_
  rw [inner_rootZ_vac_rootY_WZ]
  have hn : ‖(-2*γ:ℝ) • initialDirection n‖^2=4*γ^2 := by
    rw [norm_smul,initialDirection_norm,mul_one,Real.norm_eq_abs,sq_abs]
    ring
  rw [hn]
  congr 3
  ring

end PointedTree

namespace PointedTree
open CoherentFock RootSpin Complex

theorem ordinary_one_mode (n : ℕ) (γ β : ℝ) :
    (ordinary [.mixer β,.cost γ] (n+1)).insertion=
      (Real.cos (2*β):ℂ) • initialDirection (n+1)+
        (Real.sin (2*β):ℂ) • highDirection n γ := by
  apply Subtype.ext
  rw [ordinary_one_insertion]
  change _ = (Real.cos (2*β):ℂ) • (initialDirection (n+1):Level (n+1))+
    (Real.sin (2*β):ℂ) • (highDirection n γ:Level (n+1))
  rw [highDirection_coe]
  have hd : (-(2*γ):ℂ) • initialDirection n=(-2*γ:ℝ) • initialDirection n := by
    rw [← Complex.coe_smul]
    apply congrArg (fun z : ℂ => z • initialDirection n)
    push_cast
    ring
  rw [hd]

theorem inner_highDirection_creation (n : ℕ) (γ : ℝ) (v : Mode n) :
    ⟪(highDirection n γ:Level (n+1)),plusEmbedding (creationVacuum v)⟫_ℂ=
      (2*γ*Real.exp (-2*γ^2):ℂ)*⟪initialDirection n,v⟫_ℂ := by
  rw [highDirection_coe]
  change ⟪SpinOperators.act Y (WZ ((-2*γ:ℝ) • initialDirection n)
    (vacuum (Mode n))),plusEmbedding (creationVacuum v)⟫_ℂ=_
  rw [inner_rootY_WZ_creation]
  have hi : ⟪(-2*γ:ℝ) • initialDirection n,v⟫_ℂ=
      ((-2*γ:ℝ):ℂ)*⟪initialDirection n,v⟫_ℂ := by
    rw [← Complex.coe_smul,inner_smul_left,Complex.conj_ofReal]
  rw [hi]
  have hn : ‖(-2*γ:ℝ) • initialDirection n‖^2=4*γ^2 := by
    rw [norm_smul,initialDirection_norm,mul_one,Real.norm_eq_abs,sq_abs]
    ring
  rw [hn,show -(4*γ^2)/2= -2*γ^2 by ring]
  push_cast
  ring

theorem inner_initial_rootShift (n : ℕ) (v : Mode n) :
    ⟪initialDirection (n+1),rootShift n v⟫_ℂ=0 := by
  change ⟪(initialDirection (n+1):Level (n+1)),(rootShift n v:Level (n+1))⟫_ℂ=0
  rw [initialDirection_coe,rootShift_coe]
  exact inner_rootZ_vac_creation v

theorem inner_highDirection_rootShift (n : ℕ) (γ : ℝ) (v : Mode n) :
    ⟪highDirection n γ,rootShift n v⟫_ℂ=
      (2*γ*Real.exp (-2*γ^2):ℂ)*⟪initialDirection n,v⟫_ℂ :=
  inner_highDirection_creation n γ v

@[simp] theorem inner_initialDirection_self (n : ℕ) :
    ⟪initialDirection n,initialDirection n⟫_ℂ=1 := by
  rw [inner_self_eq_norm_sq_to_K,initialDirection_norm]
  norm_num

 

theorem treeEnergy_one (n : ℕ) (γ β : ℝ) :
    treeEnergy (n+1) (ordinary [.mixer β,.cost γ] (n+1)).insertion=
      γ*Real.sin (4*β)*Real.exp (-2*γ^2) := by
  rw [ordinary_one_mode]
  unfold treeEnergy
  rw [map_add,map_smul,map_smul,initialDirection_empty,highDirection_empty,    inner_add_left,inner_smul_left,inner_smul_left,inner_initial_rootShift,    inner_highDirection_rootShift,inner_add_right,inner_smul_right,inner_smul_right,    inner_initialDirection_self,initial_inner_highDirection]
  simp only [Complex.conj_ofReal,mul_zero,zero_add]
  have hs : Real.sin (4*β)=2*Real.sin (2*β)*Real.cos (2*β) := by
    rw [show 4*β=2*(2*β) by ring]
    exact Real.sin_two_mul (2*β)
  rw [hs]
  simp only [Complex.mul_re,Complex.add_re,Complex.ofReal_re,Complex.one_re,    Complex.neg_re,Complex.I_re,Complex.ofReal_im,Complex.add_im,Complex.mul_im,    Complex.neg_im,Complex.I_im,Complex.one_im,Complex.re_ofNat,Complex.im_ofNat]
  ring

theorem ordinaryValue_one (γ β : ℝ) :
    ordinaryValue [.mixer β,.cost γ]=γ*Real.sin (4*β)*Real.exp (-2*γ^2) := by
  exact treeEnergy_one 1 γ β

end PointedTree

open Filter Topology

namespace SeedInitialization

def amplitude (t : ℝ) : ℝ := t⁻¹
def delta (t : ℝ) : ℝ := Real.arcsin (amplitude t)
def gamma (b t : ℝ) : ℝ := b*t

theorem amplitude_pos {t : ℝ} (ht : 1 ≤ t) : 0 < amplitude t :=
  inv_pos.mpr (lt_of_lt_of_le zero_lt_one ht)
theorem amplitude_le_one {t : ℝ} (ht : 1 ≤ t) : amplitude t ≤ 1 := by
  exact inv_le_one_of_one_le₀ ht

theorem sin_delta {t : ℝ} (ht : 1 ≤ t) : Real.sin (delta t)=amplitude t := by
  exact Real.sin_arcsin (by linarith [amplitude_pos ht]) (amplitude_le_one ht)

theorem cos_delta (t : ℝ) : Real.cos (delta t)=Real.sqrt (1-(amplitude t)^2) :=
  Real.cos_arcsin _

theorem cos_two_delta {t : ℝ} (ht : 1 ≤ t) :
    Real.cos (2*delta t)=1-2*(amplitude t)^2 := by
  rw [Real.cos_two_mul',sin_delta ht]
  have h := Real.sin_sq_add_cos_sq (delta t)
  rw [sin_delta ht] at h
  linarith

theorem sin_two_delta {t : ℝ} (ht : 1 ≤ t) :
    Real.sin (2*delta t)=2*amplitude t*Real.sqrt (1-(amplitude t)^2) := by
  rw [Real.sin_two_mul,sin_delta ht,cos_delta]

theorem gamma_cos_error {t : ℝ} (ht : 1 ≤ t) (b : ℝ) :
    gamma b t*(Real.cos (2*delta t)-1)= -2*b*amplitude t := by
  rw [cos_two_delta ht]
  unfold gamma amplitude
  field_simp
  ring

theorem gamma_sin {t : ℝ} (ht : 1 ≤ t) (b : ℝ) :
    gamma b t*Real.sin (2*delta t)=2*b*Real.sqrt (1-(amplitude t)^2) := by
  rw [sin_two_delta ht]
  unfold gamma amplitude
  have hz : t≠0 := ne_of_gt (lt_of_lt_of_le zero_lt_one ht)
  field_simp

theorem tendsto_amplitude : Tendsto amplitude atTop (𝓝 0) := tendsto_inv_atTop_zero

theorem tendsto_delta : Tendsto delta atTop (𝓝 0) := by
  change Tendsto (fun t => Real.arcsin (amplitude t)) atTop (𝓝 0)
  simpa [delta,Function.comp_def] using Real.continuous_arcsin.continuousAt.tendsto.comp tendsto_amplitude

theorem tendsto_cos_delta : Tendsto (fun t => Real.cos (delta t)) atTop (𝓝 1) := by
  simpa only [Function.comp_def,Real.cos_zero,Real.sin_zero,mul_zero] using Real.continuous_cos.continuousAt.tendsto.comp tendsto_delta

theorem tendsto_cos_two_delta : Tendsto (fun t => Real.cos (2*delta t)) atTop (𝓝 1) := by
  simpa only [Function.comp_def,Real.cos_zero,Real.sin_zero,mul_zero] using Real.continuous_cos.continuousAt.tendsto.comp (tendsto_delta.const_mul 2)

theorem tendsto_sin_two_delta : Tendsto (fun t => Real.sin (2*delta t)) atTop (𝓝 0) := by
  simpa only [Function.comp_def,Real.cos_zero,Real.sin_zero,mul_zero] using Real.continuous_sin.continuousAt.tendsto.comp (tendsto_delta.const_mul 2)

theorem tendsto_gamma_cos_error (b : ℝ) :
    Tendsto (fun t => gamma b t*(Real.cos (2*delta t)-1)) atTop (𝓝 0) := by
  apply Tendsto.congr' (f₁ := fun t => -2*b*amplitude t)  · filter_upwards [eventually_ge_atTop (1:ℝ)] with t ht
    exact (gamma_cos_error ht b).symm
  · simpa using tendsto_amplitude.const_mul (-2*b)

theorem tendsto_gamma_sin (b : ℝ) :
    Tendsto (fun t => gamma b t*Real.sin (2*delta t)) atTop (𝓝 (2*b)) := by
  apply Tendsto.congr' (f₁ := fun t => 2*b*Real.cos (delta t))
  · filter_upwards [eventually_ge_atTop (1:ℝ)] with t ht
    rw [gamma_sin ht,cos_delta]
  · simpa using tendsto_cos_delta.const_mul (2*b)

theorem tendsto_gamma (b : ℝ) (hb : 0 < b) : Tendsto (gamma b) atTop atTop :=
  tendsto_id.const_mul_atTop hb

theorem tendsto_gamma_sq_exp (b : ℝ) (hb : 0 < b) :
    Tendsto (fun t => (gamma b t)^2*Real.exp (-2*(gamma b t)^2)) atTop (𝓝 0) := by
  have hx := ((tendsto_pow_atTop (by norm_num : (2:ℕ)≠0)).comp (tendsto_gamma b hb)).const_mul_atTop
    (by norm_num : (0:ℝ)<2)
  have h := (Real.tendsto_pow_mul_exp_neg_atTop_nhds_zero 1).comp hx
  convert! h.div_const 2 using 1
  · funext t
    simp only [Function.comp_def,pow_one]
    rw [show -(2*(gamma b t)^2)= -2*(gamma b t)^2 by ring]
    ring
  · norm_num

def phaseAngle (b t : ℝ) : ℝ :=
  (gamma b t)^2 * Real.sin (2*delta t) * Real.exp (-2*(gamma b t)^2)

theorem tendsto_phaseAngle (b : ℝ) (hb : 0 < b) :
    Tendsto (phaseAngle b) atTop (𝓝 0) := by
  convert! (tendsto_gamma_sq_exp b hb).mul tendsto_sin_two_delta using 1
  · funext t
    unfold phaseAngle
    ring
  · norm_num

end SeedInitialization

namespace UnitarySplit
variable {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H]

theorem inverse (U O S : H ≃ₗᵢ[ℂ] H) (a b : ℂ)
    (h : ∀ x, U x=a • O x+b • S x) (y : H) :
    U.symm y=star a • O.symm y+star b • S.symm y := by
  apply ext_inner_left ℂ
  intro x
  have hU : ⟪x,U.symm y⟫_ℂ=⟪U x,y⟫_ℂ := by
    rw [← U.inner_map_map x (U.symm y),U.apply_symm_apply]
  have hO : ⟪x,O.symm y⟫_ℂ=⟪O x,y⟫_ℂ := by
    rw [← O.inner_map_map x (O.symm y),O.apply_symm_apply]
  have hS : ⟪x,S.symm y⟫_ℂ=⟪S x,y⟫_ℂ := by
    rw [← S.inner_map_map x (S.symm y),S.apply_symm_apply]
  rw [hU,h,inner_add_left,inner_smul_left,inner_smul_left,
    inner_add_right,inner_smul_right,inner_smul_right,hO,hS]
  rfl
end UnitarySplit

namespace SeedInitialization
open CoherentFock RootSpin Complex PointedTree
variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E]

def initialMap (γ δ β : ℝ) (v e : E) : SpinSpace E ≃ₗᵢ[ℂ] SpinSpace E :=
  (costEquiv ((-γ) • e)).trans ((SpinOperators.actEquiv (R δ) (R_unitary δ)).trans
    ((costEquiv (γ • v)).trans (SpinOperators.actEquiv (R β) (R_unitary β))))

def ordinaryMap (γ β : ℝ) (v e : E) : SpinSpace E ≃ₗᵢ[ℂ] SpinSpace E :=
  (costEquiv (γ • (v-e))).trans (SpinOperators.actEquiv (R β) (R_unitary β))

def specialMap (γ β : ℝ) (v e : E) : SpinSpace E ≃ₗᵢ[ℂ] SpinSpace E :=
  (costEquiv ((-γ) • (v+e))).trans ((SpinOperators.actEquiv X X_unitary).trans
    (SpinOperators.actEquiv (R β) (R_unitary β)))

def ordinaryCoefficient (γ δ : ℝ) (v e : E) : ℂ :=
  (Real.cos δ:ℂ)*phase (γ • v) ((-γ) • e)
def specialCoefficient (γ δ : ℝ) (v e : E) : ℂ :=
  (-I*(Real.sin δ:ℂ))*phase ((-γ) • v) ((-γ) • e)
def specialPhase (γ : ℝ) (v e : E) : ℂ :=
  -I*phase ((-γ) • v) ((-γ) • e)

@[simp] theorem initialMap_apply (γ δ β : ℝ) (v e : E) (x : SpinSpace E) :
    initialMap γ δ β v e x=SpinOperators.act (R β)
      (WZ (γ • v) (SpinOperators.act (R δ) (WZ ((-γ) • e) x))) := rfl
@[simp] theorem ordinaryMap_apply (γ β : ℝ) (v e : E) (x : SpinSpace E) :
    ordinaryMap γ β v e x=SpinOperators.act (R β) (WZ (γ • (v-e)) x) := rfl
@[simp] theorem specialMap_apply (γ β : ℝ) (v e : E) (x : SpinSpace E) :
    specialMap γ β v e x=SpinOperators.act (R β)
      (SpinOperators.act X (WZ ((-γ) • (v+e)) x)) := rfl

 
theorem exact_split (γ δ β : ℝ) (v e : E) (x : SpinSpace E) :
    initialMap γ δ β v e x=
      ordinaryCoefficient γ δ v e • ordinaryMap γ β v e x+
      specialCoefficient γ δ v e • specialMap γ β v e x := by
  rw [initialMap_apply,ordinaryMap_apply,specialMap_apply]
  have h := congrArg (fun A : SpinSpace E →L[ℂ] SpinSpace E => A x)
    (CoherentFock.initialization_split γ δ v e)
  change WZ (γ • v) (SpinOperators.act (R δ) (WZ ((-γ) • e) x))=_ at h
  rw [h]
  simp only [add_apply,smul_apply,
    ContinuousLinearMap.comp_apply,map_add,map_smul]
  rfl

@[simp] theorem norm_specialPhase (γ : ℝ) (v e : E) : ‖specialPhase γ v e‖=1 := by
  simp [specialPhase]

@[simp] theorem norm_special_component (γ δ β : ℝ) (v e : E) (x : SpinSpace E) :
    ‖specialCoefficient γ δ v e • specialMap γ β v e x‖=|Real.sin δ| * ‖x‖ := by
  rw [norm_smul,LinearIsometryEquiv.norm_map]
  simp only [specialCoefficient,norm_mul,norm_neg,Complex.norm_I,Complex.norm_real,
    norm_phase,one_mul,mul_one,Real.norm_eq_abs]

 

def address (γ δ : ℝ) (v e : E) : SpinSpace E :=
  (initialMap γ δ (Real.pi/4) v e).symm
    (SpinOperators.act Z (specialPhase γ v e • specialMap γ (Real.pi/4) v e (vacuum E)))

@[simp] theorem norm_address (γ δ : ℝ) (v e : E) : ‖address γ δ v e‖=1 := by
  unfold address
  rw [LinearIsometryEquiv.norm_map,SpinOperators.norm_act Z_unitary,
    norm_smul,norm_specialPhase,LinearIsometryEquiv.norm_map,norm_vacuum]
  norm_num

theorem address_exact_normalization (γ δ : ℝ) (v e : E) :
    (Real.sin δ:ℂ) • address γ δ v e=
      (initialMap γ δ (Real.pi/4) v e).symm
        (SpinOperators.act Z (specialCoefficient γ δ v e •
          specialMap γ (Real.pi/4) v e (vacuum E))) := by
  unfold address
  rw [← map_smul,← map_smul,smul_smul]
  congr 3
  unfold specialCoefficient specialPhase
  ring

end SeedInitialization

namespace RootSpin
@[simp] theorem Y_mul_X : Y*X=(-Complex.I) • Z := by
  ext i j
  fin_cases i <;> fin_cases j <;> simp [Y,X,Z,Matrix.mul_apply,Fin.sum_univ_two]

theorem R_quarter_conjugate_Z : (R (Real.pi/4)).conjTranspose*Z*R (Real.pi/4)=Y := by
  rw [R_conjugate_Z,show 2*(Real.pi/4)=Real.pi/2 by ring]
  simp only [Real.cos_pi_div_two,Real.sin_pi_div_two,Complex.ofReal_zero,
    Complex.ofReal_one,zero_smul,one_smul,zero_add]
end RootSpin

end

end OAI