File size: 21,177 Bytes
b317718
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import OAI.Probability.InvariantIsing.Arrays.NSpinTensorBackwardPaths

namespace OAI

/-! Projected overlaps as products of actual backward site gradients. -/

noncomputable section

open MeasureTheory ProbabilityTheory IsingPerceptron
open scoped BigOperators NNReal ENNReal

namespace InvariantIsing

def rotationCoordinate {N : ℕ} (U : Rotation N) (a i : Fin N) : ℝ :=
  U (WithLp.toLp 2 (Pi.single i 1)) a

lemma rotation_apply_coordinates {N : ℕ} (U : Rotation N) (f : Fin N → ℝ) (a : Fin N) :
    U (WithLp.toLp 2 f) a = ∑ i, rotationCoordinate U a i * f i := by
  classical
  have hv : (WithLp.toLp 2 f : EuclideanSpace ℝ (Fin N)) =
      ∑ i : Fin N, f i • (WithLp.toLp 2 (Pi.single i 1) : EuclideanSpace ℝ (Fin N)) := by
    ext j
    change f j = WithLp.ofLp (∑ i : Fin N, f i •
      (WithLp.toLp 2 (Pi.single i 1) : EuclideanSpace ℝ (Fin N))) j
    rw [WithLp.ofLp_sum, Finset.sum_apply]
    simp [mul_ite]
  rw [hv, map_sum]
  change WithLp.ofLp (∑ i : Fin N, U (f i • WithLp.toLp 2 (Pi.single i 1))) a = _
  rw [WithLp.ofLp_sum, Finset.sum_apply]
  simp only [map_smul, WithLp.ofLp_smul, Pi.smul_apply, smul_eq_mul, rotationCoordinate, mul_comm]

def tensorBackwardProjectedMean {N m k : ℕ}
    (eig : Fin N → ℝ) (U : Rotation N) (c : Fin N → ℝ)
    (I : Fin m → Finset (Fin N)) (degree : Fin k → Fin m → ℕ) (amplitude : Fin k → ℝ)
    (n : ℕ) (b : ℕ → ℝ) (v : ℕ → SpinTensorIndex I degree → ℝ≥0)
    (i : ℕ) (z : SpinTensorIndex I degree → ℝ) (a : Fin N) : ℝ :=
  ∑ s, rotationCoordinate U a s * tensorBackwardCoordinateMean eig U c I degree amplitude n b v i z (Sum.inl s)

lemma tensorBackwardProjectedMean_eq {N m k : ℕ}
    (eig : Fin N → ℝ) (U : Rotation N) (c : Fin N → ℝ)
    (I : Fin m → Finset (Fin N)) (degree : Fin k → Fin m → ℕ) (amplitude : Fin k → ℝ)
    (n : ℕ) (b : ℕ → ℝ) (v : ℕ → SpinTensorIndex I degree → ℝ≥0)
    (i : ℕ) (z : SpinTensorIndex I degree → ℝ) (a : Fin N) :
    tensorBackwardProjectedMean eig U c I degree amplitude n b v i z a =
      U (WithLp.toLp 2 (fun s => tensorBackwardCoordinateMean eig U c I degree amplitude n b v i z (Sum.inl s))) a :=
  (rotation_apply_coordinates U _ a).symm

def tensorProjectedCoordinateCap {N m k : ℕ} (U : Rotation N)
    (I : Fin m → Finset (Fin N)) (degree : Fin k → Fin m → ℕ) (amplitude : Fin k → ℝ) (a : Fin N) : ℝ :=
  ∑ s, |rotationCoordinate U a s| * tensorFeatureCoordinateCap U I degree amplitude (Sum.inl s)

lemma measurable_tensorBackwardProjectedMean {N m k : ℕ} (hN : 0 < N)
    (eig : Fin N → ℝ) (U : Rotation N) (c : Fin N → ℝ)
    (I : Fin m → Finset (Fin N)) (degree : Fin k → Fin m → ℕ) (amplitude : Fin k → ℝ)
    (n : ℕ) (b : ℕ → ℝ) (v : ℕ → SpinTensorIndex I degree → ℝ≥0)
    (hb : CascadeExponents n b) (i : ℕ) (a : Fin N) :
    Measurable (fun z => tensorBackwardProjectedMean eig U c I degree amplitude n b v i z a) :=
  Finset.measurable_sum _ fun s _ =>
    (measurable_tensorBackwardCoordinateMean hN eig U c I degree amplitude n b v hb i (Sum.inl s)).const_mul _

lemma tensorBackwardProjectedMean_abs_le {N m k : ℕ} (hN : 0 < N)
    (eig : Fin N → ℝ) (U : Rotation N) (c : Fin N → ℝ)
    (I : Fin m → Finset (Fin N)) (degree : Fin k → Fin m → ℕ) (amplitude : Fin k → ℝ)
    (n : ℕ) (b : ℕ → ℝ) (v : ℕ → SpinTensorIndex I degree → ℝ≥0)
    (hb : CascadeExponents n b) (i : ℕ) (z : SpinTensorIndex I degree → ℝ) (a : Fin N) :
    |tensorBackwardProjectedMean eig U c I degree amplitude n b v i z a| ≤
      tensorProjectedCoordinateCap U I degree amplitude a := by
  unfold tensorBackwardProjectedMean tensorProjectedCoordinateCap
  apply (Finset.abs_sum_le_sum_abs _ _).trans
  apply Finset.sum_le_sum
  intro s _
  rw [abs_mul]
  exact mul_le_mul_of_nonneg_left
    (tensorBackwardCoordinateMean_abs_le hN eig U c I degree amplitude n b v hb i z (Sum.inl s)) (abs_nonneg _)

lemma integrable_tensorBackwardProjectedMean {N m k : ℕ} (hN : 0 < N)
    (eig : Fin N → ℝ) (U : Rotation N) (c : Fin N → ℝ)
    (I : Fin m → Finset (Fin N)) (degree : Fin k → Fin m → ℕ) (amplitude : Fin k → ℝ)
    (n : ℕ) (b : ℕ → ℝ) (v : ℕ → SpinTensorIndex I degree → ℝ≥0)
    (hb : CascadeExponents n b) (i : ℕ) (z : SpinTensorIndex I degree → ℝ) (a : Fin N)
    (μ : Measure (SpinTensorIndex I degree → ℝ)) [IsFiniteMeasure μ] :
    Integrable (fun x => tensorBackwardProjectedMean eig U c I degree amplitude n b v i (z + x) a) μ :=
  Integrable.of_bound
    ((measurable_tensorBackwardProjectedMean hN eig U c I degree amplitude n b v hb i a).comp
      (measurable_const.add measurable_id)).aestronglyMeasurable
    (tensorProjectedCoordinateCap U I degree amplitude a)
    (ae_of_all _ fun x => by simpa only [Real.norm_eq_abs] using
      tensorBackwardProjectedMean_abs_le hN eig U c I degree amplitude n b v hb i (z + x) a)

theorem tensorBackwardProjectedMean_step {N m k : ℕ} (hN : 0 < N)
    (eig : Fin N → ℝ) (U : Rotation N) (c : Fin N → ℝ)
    (I : Fin m → Finset (Fin N)) (degree : Fin k → Fin m → ℕ) (amplitude : Fin k → ℝ)
    (n : ℕ) (b : ℕ → ℝ) (v : ℕ → SpinTensorIndex I degree → ℝ≥0)
    (hb : CascadeExponents n b) (i : ℕ) (hi : i < n)
    (z : SpinTensorIndex I degree → ℝ) (a : Fin N) :
    tensorBackwardProjectedMean eig U c I degree amplitude n b v i z a =
      ∫ x, tensorBackwardProjectedMean eig U c I degree amplitude n b v (i + 1) (z + x) a
        ∂tensorAncestorMarkKernel eig U c I degree amplitude n b v i z := by
  let := tensorAncestorMarkKernel_markov hN eig U c I degree amplitude n b v hb i
  have hint (s : Fin N) : Integrable (fun x => rotationCoordinate U a s *
      tensorBackwardCoordinateMean eig U c I degree amplitude n b v (i + 1) (z + x) (Sum.inl s))
      (tensorAncestorMarkKernel eig U c I degree amplitude n b v i z) := by
    apply Integrable.const_mul
    apply Integrable.of_bound
      ((measurable_tensorBackwardCoordinateMean hN eig U c I degree amplitude n b v hb (i + 1) (Sum.inl s)).comp
        (measurable_const.add measurable_id)).aestronglyMeasurable
      (tensorFeatureCoordinateCap U I degree amplitude (Sum.inl s))
    exact ae_of_all _ fun x => by simpa only [Real.norm_eq_abs, Function.comp_apply, Pi.add_apply, id_eq] using
      tensorBackwardCoordinateMean_abs_le hN eig U c I degree amplitude n b v hb (i + 1) (z + x) (Sum.inl s)
  rw [tensorBackwardProjectedMean, show (fun x => tensorBackwardProjectedMean eig U c I degree amplitude n b v
      (i + 1) (z + x) a) = (fun x => ∑ s, rotationCoordinate U a s *
        tensorBackwardCoordinateMean eig U c I degree amplitude n b v (i + 1) (z + x) (Sum.inl s)) from rfl,
    integral_finsetSum _ (fun s _ => hint s)]
  apply Finset.sum_congr rfl
  intro s _
  rw [integral_const_mul, ← tensorBackwardCoordinateMean_step hN eig U c I degree amplitude n b v hb i hi z (Sum.inl s)]

lemma tensorBackwardProjectedMean_terminal {N m k : ℕ}
    (eig : Fin N → ℝ) (U : Rotation N) (c : Fin N → ℝ)
    (I : Fin m → Finset (Fin N)) (degree : Fin k → Fin m → ℕ) (amplitude : Fin k → ℝ)
    (n : ℕ) (b : ℕ → ℝ) (v : ℕ → SpinTensorIndex I degree → ℝ≥0)
    (z : SpinTensorIndex I degree → ℝ) (a : Fin N) :
    tensorBackwardProjectedMean eig U c I degree amplitude n b v n z a =
      tensorProjectedMagnetization eig U c I degree amplitude z a := by
  rw [tensorBackwardProjectedMean_eq, tensorProjectedMagnetization_eq]
  simp only [tensorBackwardCoordinateMean, Nat.sub_self, tensorCascadeCoordinateMean]

def tensorProjectedPairPayoff {N m k : ℕ}
    (eig : Fin N → ℝ) (U : Rotation N) (c : Fin N → ℝ)
    (I : Fin m → Finset (Fin N)) (degree : Fin k → Fin m → ℕ) (amplitude : Fin k → ℝ)
    (n : ℕ) (b : ℕ → ℝ) (v : ℕ → SpinTensorIndex I degree → ℝ≥0) (J : Finset (Fin N))
    (q : ℕ) (z₁ z₂ : SpinTensorIndex I degree → ℝ)
    (w : Fin q → (SpinTensorIndex I degree → ℝ) × (SpinTensorIndex I degree → ℝ)) : ℝ :=
  (N : ℝ)⁻¹ * ∑ a ∈ J,
    tensorBackwardProjectedMean eig U c I degree amplitude n b v n (z₁ + ∑ i, (w i).1) a *
      tensorBackwardProjectedMean eig U c I degree amplitude n b v n (z₂ + ∑ i, (w i).2) a

lemma tensorProjectedPairPayoff_cons {N m k : ℕ}
    (eig : Fin N → ℝ) (U : Rotation N) (c : Fin N → ℝ)
    (I : Fin m → Finset (Fin N)) (degree : Fin k → Fin m → ℕ) (amplitude : Fin k → ℝ)
    (n : ℕ) (b : ℕ → ℝ) (v : ℕ → SpinTensorIndex I degree → ℝ≥0) (J : Finset (Fin N))
    (q : ℕ) (z₁ z₂ a₁ a₂ : SpinTensorIndex I degree → ℝ)
    (w : Fin q → (SpinTensorIndex I degree → ℝ) × (SpinTensorIndex I degree → ℝ)) :
    tensorProjectedPairPayoff eig U c I degree amplitude n b v J (q + 1) z₁ z₂ (Fin.cons (a₁, a₂) w) =
      tensorProjectedPairPayoff eig U c I degree amplitude n b v J q (z₁ + a₁) (z₂ + a₂) w := by
  simp only [tensorProjectedPairPayoff, Fin.sum_univ_succ, Fin.cons_zero, Fin.cons_succ, add_assoc]

private lemma integral_pair_product_sum {A B C : Type*} [MeasurableSpace A] [MeasurableSpace B]
    (μ : Measure A) (ν : Measure B) (J : Finset C) (F : C → A → ℝ) (G : C → B → ℝ)
    (hF : ∀ a ∈ J, Integrable (F a) μ) (hG : ∀ a ∈ J, Integrable (G a) ν) (c : ℝ) :
    (∫ x, ∫ y, c * ∑ a ∈ J, F a x * G a y ∂ν ∂μ) =
      c * ∑ a ∈ J, (∫ x, F a x ∂μ) * ∫ y, G a y ∂ν := by
  have hi (x : A) : (∫ y, c * ∑ a ∈ J, F a x * G a y ∂ν) =
      c * ∑ a ∈ J, F a x * ∫ y, G a y ∂ν := by
    rw [integral_const_mul, integral_finsetSum _ (fun a ha => (hG a ha).const_mul (F a x))]
    simp_rw [integral_const_mul]
  simp_rw [hi]
  rw [integral_const_mul, integral_finsetSum _ (fun a ha => (hF a ha).mul_const _)]
  simp_rw [integral_mul_const]

theorem tensorAncestorPairPathMean_independent_projected {N m k : ℕ} (hN : 0 < N)
    (eig : Fin N → ℝ) (U : Rotation N) (c : Fin N → ℝ)
    (I : Fin m → Finset (Fin N)) (degree : Fin k → Fin m → ℕ) (amplitude : Fin k → ℝ)
    (n : ℕ) (b : ℕ → ℝ) (v : ℕ → SpinTensorIndex I degree → ℝ≥0)
    (hb : CascadeExponents n b) (J : Finset (Fin N)) (d q i : ℕ) (hqi : i + q = n) (hdi : d ≤ i)
    (z₁ z₂ : SpinTensorIndex I degree → ℝ) :
    tensorAncestorPairPathMean eig U c I degree amplitude n b v d q i z₁ z₂
      (tensorProjectedPairPayoff eig U c I degree amplitude n b v J q z₁ z₂) =
      (N : ℝ)⁻¹ * ∑ a ∈ J,
        tensorBackwardProjectedMean eig U c I degree amplitude n b v i z₁ a *
          tensorBackwardProjectedMean eig U c I degree amplitude n b v i z₂ a := by
  induction q generalizing i z₁ z₂ with
  | zero =>
    have hi : i = n := by omega
    subst i
    simp only [tensorAncestorPairPathMean, tensorProjectedPairPayoff, Finset.univ_eq_empty,
      Finset.sum_empty, add_zero]
  | succ q ih =>
    have hi : i < n := by omega
    let := tensorAncestorMarkKernel_markov hN eig U c I degree amplitude n b v hb i
    dsimp only [tensorAncestorPairPathMean]
    rw [ite_eq_right (by omega : ¬i < d)]
    calc
      _ = ∫ x, ∫ y, (N : ℝ)⁻¹ * ∑ a ∈ J,
          tensorBackwardProjectedMean eig U c I degree amplitude n b v (i + 1) (z₁ + x) a *
            tensorBackwardProjectedMean eig U c I degree amplitude n b v (i + 1) (z₂ + y) a
          ∂tensorAncestorMarkKernel eig U c I degree amplitude n b v i z₂
          ∂tensorAncestorMarkKernel eig U c I degree amplitude n b v i z₁ := by
        apply integral_congr_ae
        apply ae_of_all
        intro x
        apply integral_congr_ae
        apply ae_of_all
        intro y
        dsimp only
        have hP : (fun w => tensorProjectedPairPayoff eig U c I degree amplitude n b v J (q + 1)
            z₁ z₂ (Fin.cons (x, y) w)) =
            tensorProjectedPairPayoff eig U c I degree amplitude n b v J q (z₁ + x) (z₂ + y) :=
          funext (tensorProjectedPairPayoff_cons eig U c I degree amplitude n b v J q z₁ z₂ x y)
        rw [hP]
        exact ih (i + 1) (by omega) (by omega) (z₁ + x) (z₂ + y)
      _ = _ := by
        rw [integral_pair_product_sum]
        · congr 1
          apply Finset.sum_congr rfl
          intro a ha
          rw [← tensorBackwardProjectedMean_step hN eig U c I degree amplitude n b v hb i hi z₁ a,
            ← tensorBackwardProjectedMean_step hN eig U c I degree amplitude n b v hb i hi z₂ a]
        · intro a _
          exact integrable_tensorBackwardProjectedMean hN eig U c I degree amplitude n b v hb (i + 1) z₁ a _
        · intro a _
          exact integrable_tensorBackwardProjectedMean hN eig U c I degree amplitude n b v hb (i + 1) z₂ a _

def tensorSharedProjectedProduct {N m k : ℕ}
    (eig : Fin N → ℝ) (U : Rotation N) (c : Fin N → ℝ)
    (I : Fin m → Finset (Fin N)) (degree : Fin k → Fin m → ℕ) (amplitude : Fin k → ℝ)
    (n : ℕ) (b : ℕ → ℝ) (v : ℕ → SpinTensorIndex I degree → ℝ≥0)
    (J : Finset (Fin N)) (d : ℕ) :
    (q : ℕ) → ℕ → (SpinTensorIndex I degree → ℝ) → (SpinTensorIndex I degree → ℝ) → ℝ
  | 0, i, z₁, z₂ => (N : ℝ)⁻¹ * ∑ a ∈ J,
      tensorBackwardProjectedMean eig U c I degree amplitude n b v i z₁ a *
        tensorBackwardProjectedMean eig U c I degree amplitude n b v i z₂ a
  | q + 1, i, z₁, z₂ => if i < d then
      ∫ x, tensorSharedProjectedProduct eig U c I degree amplitude n b v J d q
        (i + 1) (z₁ + x) (z₂ + x) ∂tensorAncestorMarkKernel eig U c I degree amplitude n b v i z₁
    else (N : ℝ)⁻¹ * ∑ a ∈ J,
      tensorBackwardProjectedMean eig U c I degree amplitude n b v i z₁ a *
        tensorBackwardProjectedMean eig U c I degree amplitude n b v i z₂ a

lemma tensorSharedProjectedProduct_nonneg {N m k : ℕ}
    (eig : Fin N → ℝ) (U : Rotation N) (c : Fin N → ℝ)
    (I : Fin m → Finset (Fin N)) (degree : Fin k → Fin m → ℕ) (amplitude : Fin k → ℝ)
    (n : ℕ) (b : ℕ → ℝ) (v : ℕ → SpinTensorIndex I degree → ℝ≥0)
    (J : Finset (Fin N)) (d q i : ℕ) (z : SpinTensorIndex I degree → ℝ) :
    0 ≤ tensorSharedProjectedProduct eig U c I degree amplitude n b v J d q i z z := by
  induction q generalizing i z with
  | zero => exact mul_nonneg (by positivity) (Finset.sum_nonneg fun _ _ => mul_self_nonneg _)
  | succ q ih =>
    dsimp only [tensorSharedProjectedProduct]
    split_ifs
    · exact integral_nonneg fun a => ih (i + 1) (z + a)
    · exact mul_nonneg (by positivity) (Finset.sum_nonneg fun _ _ => mul_self_nonneg _)

theorem tensorAncestorPairPathMean_projected {N m k : ℕ} (hN : 0 < N)
    (eig : Fin N → ℝ) (U : Rotation N) (c : Fin N → ℝ)
    (I : Fin m → Finset (Fin N)) (degree : Fin k → Fin m → ℕ) (amplitude : Fin k → ℝ)
    (n : ℕ) (b : ℕ → ℝ) (v : ℕ → SpinTensorIndex I degree → ℝ≥0)
    (hb : CascadeExponents n b) (J : Finset (Fin N)) (d q i : ℕ) (hqi : i + q = n)
    (z₁ z₂ : SpinTensorIndex I degree → ℝ) :
    tensorAncestorPairPathMean eig U c I degree amplitude n b v d q i z₁ z₂
      (tensorProjectedPairPayoff eig U c I degree amplitude n b v J q z₁ z₂) =
      tensorSharedProjectedProduct eig U c I degree amplitude n b v J d q i z₁ z₂ := by
  induction q generalizing i z₁ z₂ with
  | zero =>
    have hi : i = n := by omega
    subst i
    simp only [tensorAncestorPairPathMean, tensorProjectedPairPayoff, tensorSharedProjectedProduct,
      Finset.univ_eq_empty, Finset.sum_empty, add_zero]
  | succ q ih =>
    by_cases hid : i < d
    · dsimp only [tensorAncestorPairPathMean, tensorSharedProjectedProduct]
      rw [ite_eq_left hid, ite_eq_left hid]
      apply integral_congr_ae
      apply ae_of_all
      intro a
      dsimp only
      have hP : (fun w => tensorProjectedPairPayoff eig U c I degree amplitude n b v J (q + 1)
          z₁ z₂ (Fin.cons (a, a) w)) =
          tensorProjectedPairPayoff eig U c I degree amplitude n b v J q (z₁ + a) (z₂ + a) :=
        funext (tensorProjectedPairPayoff_cons eig U c I degree amplitude n b v J q z₁ z₂ a a)
      rw [hP]
      exact ih (i + 1) (by omega) (z₁ + a) (z₂ + a)
    · rw [tensorSharedProjectedProduct, ite_eq_right hid]
      exact tensorAncestorPairPathMean_independent_projected hN eig U c I degree amplitude
        n b v hb J d (q + 1) i hqi (by omega) z₁ z₂

lemma tensorPairPathSpinMean_projectedPayoff {N m k : ℕ}
    (eig : Fin N → ℝ) (U : Rotation N) (c : Fin N → ℝ)
    (I : Fin m → Finset (Fin N)) (degree : Fin k → Fin m → ℕ) (amplitude : Fin k → ℝ)
    (n : ℕ) (b : ℕ → ℝ) (v : ℕ → SpinTensorIndex I degree → ℝ≥0)
    (J : Finset (Fin N)) (z : SpinTensorIndex I degree → ℝ)
    (w : Fin n → (SpinTensorIndex I degree → ℝ) × (SpinTensorIndex I degree → ℝ)) :
    tensorPairPathSpinMean eig U c I degree amplitude n (z, w)
      (fun σ => projectedOverlap U J (σ 0) (σ 1)) =
      tensorProjectedPairPayoff eig U c I degree amplitude n b v J n z z w := by
  rw [tensorPairPathSpinMean_overlap]
  simp only [tensorProjectedPairPayoff, tensorBackwardProjectedMean_terminal, tensorPairPathState,
    ite_true, ite_eq_right (show (1 : Fin 2) ≠ 0 by decide)]

/-- The actual projected-overlap test is the shared-path expectation of
products of projected backward gradients at the branching level. -/
theorem tensorProjectedOverlap_backward_identity (hpub : PanchenkoTalagrandTensorPairInput)
    {N m k : ℕ} (hN : 0 < N)
    (eig : Fin N → ℝ) (U : Rotation N) (c : Fin N → ℝ)
    (I : Fin m → Finset (Fin N)) (degree : Fin k → Fin m → ℕ) (amplitude : Fin k → ℝ)
    (n : ℕ) (b : ℕ → ℝ) (v : ℕ → SpinTensorIndex I degree → ℝ≥0)
    (hb : CascadeExponents n b) (J : Finset (Fin N)) (z : SpinTensorIndex I degree → ℝ)
    (ψ : ℕ → ℝ) {B : ℝ} (hB : 0 ≤ B) (hψ : ∀ d, |ψ d| ≤ B) :
    tensorSpinPairAverage eig U c I degree amplitude n b v z ψ
      (fun σ => projectedOverlap U J (σ 0) (σ 1)) =
      ∫ α : ℕ → LabeledLeaf n, ψ (labeledCommonDepth n (α 0) (α 1)) *
        tensorSharedProjectedProduct eig U c I degree amplitude n b v J
          (labeledCommonDepth n (α 0) (α 1)) n 0 z z ∂cascadeReplicaLaw n b := by
  rw [tensorProjectedOverlap_markov_identity hpub hN eig U c I degree amplitude n b v hb z J ψ hB hψ]
  apply integral_congr_ae
  apply ae_of_all
  intro α
  simp only [tensorPairSpinPathPayoff,
    tensorPairPathSpinMean_projectedPayoff eig U c I degree amplitude n b v J z]
  rw [tensorAncestorPairPathMean_const_mul,
    tensorAncestorPairPathMean_projected hN eig U c I degree amplitude n b v hb J _ n 0 (by omega)]

theorem tensorProjectedOverlap_nonneg (hpub : PanchenkoTalagrandTensorPairInput)
    {N m k : ℕ} (hN : 0 < N)
    (eig : Fin N → ℝ) (U : Rotation N) (c : Fin N → ℝ)
    (I : Fin m → Finset (Fin N)) (degree : Fin k → Fin m → ℕ) (amplitude : Fin k → ℝ)
    (n : ℕ) (b : ℕ → ℝ) (v : ℕ → SpinTensorIndex I degree → ℝ≥0)
    (hb : CascadeExponents n b) (J : Finset (Fin N)) (z : SpinTensorIndex I degree → ℝ)
    (ψ : ℕ → ℝ) {B : ℝ} (hB : 0 ≤ B) (hψ : ∀ d, |ψ d| ≤ B) (hψ0 : ∀ d, 0 ≤ ψ d) :
    0 ≤ tensorSpinPairAverage eig U c I degree amplitude n b v z ψ
      (fun σ => projectedOverlap U J (σ 0) (σ 1)) := by
  rw [tensorProjectedOverlap_backward_identity hpub hN eig U c I degree amplitude n b v hb J z ψ hB hψ]
  exact integral_nonneg fun α => mul_nonneg (hψ0 _)
    (tensorSharedProjectedProduct_nonneg eig U c I degree amplitude n b v J _ n 0 z)

theorem tensorRootedProjectedOverlap_backward_identity (hpub : PanchenkoTalagrandTensorPairInput)
    {N m k : ℕ} (hN : 0 < N)
    (eig : Fin N → ℝ) (U : Rotation N) (c : Fin N → ℝ)
    (I : Fin m → Finset (Fin N)) (degree : Fin k → Fin m → ℕ) (amplitude : Fin k → ℝ)
    (n : ℕ) (b : ℕ → ℝ) (v : ℕ → SpinTensorIndex I degree → ℝ≥0)
    (hb : CascadeExponents n b) (J : Finset (Fin N))
    (ψ : ℕ → ℝ) {B : ℝ} (hB : 0 ≤ B) (hψ : ∀ d, |ψ d| ≤ B) :
    (∫ z, tensorSpinPairAverage eig U c I degree amplitude n b (fun i => v (i + 1)) z ψ
      (fun σ => projectedOverlap U J (σ 0) (σ 1))
      ∂(tensorGaussianLaw I degree (v 0) : Measure (SpinTensorIndex I degree → ℝ))) =
      ∫ z, ∫ α : ℕ → LabeledLeaf n, ψ (labeledCommonDepth n (α 0) (α 1)) *
        tensorSharedProjectedProduct eig U c I degree amplitude n b (fun i => v (i + 1)) J
          (labeledCommonDepth n (α 0) (α 1)) n 0 z z ∂cascadeReplicaLaw n b
          ∂(tensorGaussianLaw I degree (v 0) : Measure (SpinTensorIndex I degree → ℝ)) := by
  apply integral_congr_ae
  exact ae_of_all _ fun z => tensorProjectedOverlap_backward_identity hpub hN eig U c I degree amplitude
    n b (fun i => v (i + 1)) hb J z ψ hB hψ

end InvariantIsing

end

end OAI