File size: 20,533 Bytes
97c3405
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import Mathlib
import OAI.Combinatorics.Chromatic.Shuffle.ShuffleProjection
import OAI.Combinatorics.Chromatic.Shuffle.FourColumns
import OAI.Combinatorics.Chromatic.Shuffle.FourKernelCancellation

namespace OAI

section
namespace ElementaryPositivity.RawShuffle
open MvPolynomial HahnSeries
open ElementaryPositivity.LaurentAtInfinity ElementaryPositivity.RectangularKernel
open scoped TensorProduct
variable {I : Type*} [Fintype I] [DecidableEq I]

noncomputable local instance kernelTensorRing (d e : I → ℕ) : CommRing (S d⊗[ℚ]S e) := inferInstance
noncomputable local instance kernelTensorDistrib (d e : I → ℕ) :
    DistribSMul (S d⊗[ℚ]S e) (S d⊗[ℚ]S e) where
  smul_add := mul_add
noncomputable local instance kernelTensorAlg (d e : I → ℕ) : Algebra ℚ (S d⊗[ℚ]S e) := inferInstance
noncomputable local instance kernelFourRing (d₁ e₁ d₂ e₂ : I → ℕ) :
    CommRing ((S d₁⊗[ℚ]S e₁)⊗[ℚ](S d₂⊗[ℚ]S e₂)) := inferInstance
noncomputable local instance kernelFourAlg (d₁ e₁ d₂ e₂ : I → ℕ) :
    Algebra ℚ ((S d₁⊗[ℚ]S e₁)⊗[ℚ](S d₂⊗[ℚ]S e₂)) := inferInstance

noncomputable local instance kernelTensorSelf (d e : I → ℕ) :
    Module (S d⊗[ℚ]S e) (S d⊗[ℚ]S e) := Semiring.toModule
noncomputable local instance kernelTensorNonUnital (d e : I → ℕ) :
    NonUnitalNonAssocSemiring (S d⊗[ℚ]S e) := (kernelTensorRing d e).toNonUnitalNonAssocSemiring
noncomputable local instance kernelFourNonUnital (d₁ e₁ d₂ e₂ : I → ℕ) :
    NonUnitalNonAssocSemiring ((S d₁⊗[ℚ]S e₁)⊗[ℚ](S d₂⊗[ℚ]S e₂)) :=
  (kernelFourRing d₁ e₁ d₂ e₂).toNonUnitalNonAssocSemiring

lemma realize_inverseKernelUnit_unit (a : I → I → ℕ) (d e : I → ℕ) :
    Units.map (mapRing (tensorValueAlg d e).toRingHom).toMonoidHom
      (SeparationInfinity.inverseKernelUnit a d e)=SeparationInfinity.rawInverseKernelUnit a d e := by
  apply Units.ext
  exact SeparationInfinity.realize_inverseKernelUnit a d e

lemma fourKernel_lift_naturality (a : I → I → ℕ) (d e d₁ e₁ d₂ e₂ : I → ℕ)
    (F : S d⊗[ℚ]S e →ₐ[ℚ] (S d₁⊗[ℚ]S e₁)⊗[ℚ](S d₂⊗[ℚ]S e₂))
    (r : CellVars d e → CellVars d₁ e₁⊕CellVars d₂ e₂)
    (h : ∀ x,fourValueAlg d₁ e₁ d₂ e₂ (F x)=rename r (tensorValue d e x)) :
    Units.map (mapRing (R:= (S d₁⊗[ℚ]S e₁)⊗[ℚ](S d₂⊗[ℚ]S e₂)) (S:=MvPolynomial (CellVars d₁ e₁⊕CellVars d₂ e₂) ℚ) (fourValueAlg d₁ e₁ d₂ e₂).toRingHom).toMonoidHom
      (Units.map (mapRing (R:=S d⊗[ℚ]S e) (S:= (S d₁⊗[ℚ]S e₁)⊗[ℚ](S d₂⊗[ℚ]S e₂)) F.toRingHom).toMonoidHom (SeparationInfinity.inverseKernelUnit a d e))=
    Units.map (mapRing (rename r).toRingHom).toMonoidHom (SeparationInfinity.rawInverseKernelUnit a d e) := by
  apply Units.ext
  apply HahnSeries.ext
  funext k
  change fourValueAlg d₁ e₁ d₂ e₂ (F ((SeparationInfinity.inverseKernelUnit a d e).val.coeff k))=
    rename r ((SeparationInfinity.rawInverseKernelUnit a d e).val.coeff k)
  rw [h]
  have hr := congrArg (fun x : LaurentSeries (MvPolynomial (CellVars d e) ℚ)=>x.coeff k)
    (SeparationInfinity.realize_inverseKernelUnit a d e)
  exact congrArg (rename r) hr

lemma fourKernel_restrictRows (a : I → I → ℕ) {d₁ e₁ d₂ e₂ : I → ℕ}
    (A : Cut d₁ e₁) (B : Cut d₂ e₂) :
    Units.map (mapRing (R:= (S d₁⊗[ℚ]S e₁)⊗[ℚ](S d₂⊗[ℚ]S e₂)) (S:=MvPolynomial (CellVars d₁ e₁⊕CellVars d₂ e₂) ℚ) (fourValueAlg d₁ e₁ d₂ e₂).toRingHom).toMonoidHom
      (Units.map (mapRing (R:=S (d₁+e₁)⊗[ℚ]S (d₂+e₂)) (S:= (S d₁⊗[ℚ]S e₁)⊗[ℚ](S d₂⊗[ℚ]S e₂)) (restrictRows d₁ e₁ d₂ e₂ A B).toRingHom).toMonoidHom
        (SeparationInfinity.inverseKernelUnit a (d₁+e₁) (d₂+e₂)))=
      fourTotalInverseUnit a d₁ e₁ d₂ e₂ := by
  rw [fourKernel_lift_naturality a _ _ _ _ _ _ _ _ (fourValue_restrictRows A B)]
  exact rowSplit_inverseKernel a A B

lemma fourKernel_firstColumn (a : I → I → ℕ) (d₁ e₁ d₂ e₂ : I → ℕ) :
    Units.map (mapRing (R:= (S d₁⊗[ℚ]S e₁)⊗[ℚ](S d₂⊗[ℚ]S e₂)) (S:=MvPolynomial (CellVars d₁ e₁⊕CellVars d₂ e₂) ℚ) (fourValueAlg d₁ e₁ d₂ e₂).toRingHom).toMonoidHom
      (Units.map (mapRing (R:=S d₁⊗[ℚ]S d₂) (S:= (S d₁⊗[ℚ]S e₁)⊗[ℚ](S d₂⊗[ℚ]S e₂)) (firstColumnAlg d₁ e₁ d₂ e₂).toRingHom).toMonoidHom
        (SeparationInfinity.inverseKernelUnit a d₁ d₂))=
      rectangular (SeparationInfinity.inverseExponent a)
        (fun i j x y=>fourAffine d₁ e₁ d₂ e₂ i j (.inl x) (.inl y)) := by
  refine Eq.trans (fourKernel_lift_naturality a d₁ d₂ d₁ e₁ d₂ e₂
    ( firstColumnAlg d₁ e₁ d₂ e₂ ) _ (fourValue_firstColumn d₁ e₁ d₂ e₂)) ?_
  have he : firstColumnVars d₁ e₁ d₂ e₂ =
      Sum.elim (Sum.inl ∘ Sum.inl) (Sum.inr ∘ Sum.inl) := by
    funext x; cases x <;> rfl
  rw [he]
  have h := rawKernel_rename (σ:=CellVars d₁ e₁⊕CellVars d₂ e₂) a d₁ d₂
    (Sum.inl ∘ Sum.inl) (Sum.inr ∘ Sum.inl)
  simpa only [fourAffine,fourForwardDifference,Function.comp_apply,
    Equiv.sigmaSumDistrib_apply,Sum.map_inl,Sum.map_inr,firstColumnVars,secondColumnVars,crossingColumnVars] using h

lemma fourKernel_secondColumn (a : I → I → ℕ) (d₁ e₁ d₂ e₂ : I → ℕ) :
    Units.map (mapRing (R:= (S d₁⊗[ℚ]S e₁)⊗[ℚ](S d₂⊗[ℚ]S e₂)) (S:=MvPolynomial (CellVars d₁ e₁⊕CellVars d₂ e₂) ℚ) (fourValueAlg d₁ e₁ d₂ e₂).toRingHom).toMonoidHom
      (Units.map (mapRing (R:=S e₁⊗[ℚ]S e₂) (S:= (S d₁⊗[ℚ]S e₁)⊗[ℚ](S d₂⊗[ℚ]S e₂)) (secondColumnAlg d₁ e₁ d₂ e₂).toRingHom).toMonoidHom
        (SeparationInfinity.inverseKernelUnit a e₁ e₂))=
      rectangular (SeparationInfinity.inverseExponent a)
        (fun i j x y=>fourAffine d₁ e₁ d₂ e₂ i j (.inr x) (.inr y)) := by
  refine Eq.trans (fourKernel_lift_naturality a e₁ e₂ d₁ e₁ d₂ e₂
    ( secondColumnAlg d₁ e₁ d₂ e₂ ) _ (fourValue_secondColumn d₁ e₁ d₂ e₂)) ?_
  have he : secondColumnVars d₁ e₁ d₂ e₂ =
      Sum.elim (Sum.inl ∘ Sum.inr) (Sum.inr ∘ Sum.inr) := by
    funext x; cases x <;> rfl
  rw [he]
  have h := rawKernel_rename (σ:=CellVars d₁ e₁⊕CellVars d₂ e₂) a e₁ e₂
    (Sum.inl ∘ Sum.inr) (Sum.inr ∘ Sum.inr)
  simpa only [fourAffine,fourForwardDifference,Function.comp_apply,
    Equiv.sigmaSumDistrib_apply,Sum.map_inl,Sum.map_inr,firstColumnVars,secondColumnVars,crossingColumnVars] using h

lemma fourKernel_crossingColumn (a : I → I → ℕ) (d₁ e₁ d₂ e₂ : I → ℕ) :
    Units.map (mapRing (R:= (S d₁⊗[ℚ]S e₁)⊗[ℚ](S d₂⊗[ℚ]S e₂)) (S:=MvPolynomial (CellVars d₁ e₁⊕CellVars d₂ e₂) ℚ) (fourValueAlg d₁ e₁ d₂ e₂).toRingHom).toMonoidHom
      (Units.map (mapRing (R:=S e₁⊗[ℚ]S d₂) (S:= (S d₁⊗[ℚ]S e₁)⊗[ℚ](S d₂⊗[ℚ]S e₂)) (crossingColumnAlg d₁ e₁ d₂ e₂).toRingHom).toMonoidHom
        (SeparationInfinity.inverseKernelUnit a e₁ d₂))=
      rectangular (SeparationInfinity.inverseExponent a)
        (fun i j x y=>fourAffine d₁ e₁ d₂ e₂ i j (.inr x) (.inl y)) := by
  refine Eq.trans (fourKernel_lift_naturality a e₁ d₂ d₁ e₁ d₂ e₂
    ( crossingColumnAlg d₁ e₁ d₂ e₂ ) _ (fourValue_crossingColumn d₁ e₁ d₂ e₂)) ?_
  have h := rawKernel_rename (σ:=CellVars d₁ e₁⊕CellVars d₂ e₂) a e₁ d₂
    (Sum.inl ∘ Sum.inr) (Sum.inr ∘ Sum.inl)
  simpa only [fourAffine,fourForwardDifference,Function.comp_apply,
    Equiv.sigmaSumDistrib_apply,Sum.map_inl,Sum.map_inr,firstColumnVars,secondColumnVars,crossingColumnVars] using h

lemma fourTensor_cross_realize (a : I → I → ℕ) (d₁ e₁ d₂ e₂ : I → ℕ) :
    mapRing (R:= (S d₁⊗[ℚ]S e₁)⊗[ℚ](S d₂⊗[ℚ]S e₂)) (S:=MvPolynomial (CellVars d₁ e₁⊕CellVars d₂ e₂) ℚ) (fourValueAlg d₁ e₁ d₂ e₂).toRingHom
      (polynomial (fourRelativeTaylor d₁ e₁ d₂ e₂ (fourCrossTensor a d₁ e₁ d₂ e₂)))=
      (fourCrossAffineUnit a d₁ e₁ d₂ e₂).val := by
  rw [polynomial_map,map_fourRelativeTaylor,fourValue_fourCrossTensor,polynomial_fourRelative_cross]

end ElementaryPositivity.RawShuffle

end
section
namespace ElementaryPositivity.RawShuffle
open MvPolynomial HahnSeries
open ElementaryPositivity.LaurentAtInfinity ElementaryPositivity.RectangularKernel
open scoped TensorProduct
variable {I : Type*} [Fintype I] [DecidableEq I]
noncomputable local instance cancelTensorRing (d e : I → ℕ) : CommRing (S d⊗[ℚ]S e) := inferInstance
noncomputable local instance cancelTensorDistrib (d e : I → ℕ) :
    DistribSMul (S d⊗[ℚ]S e) (S d⊗[ℚ]S e) where
  smul_add := mul_add
noncomputable local instance cancelTensorAlg (d e : I → ℕ) : Algebra ℚ (S d⊗[ℚ]S e) := inferInstance
noncomputable local instance cancelFourRing (d₁ e₁ d₂ e₂ : I → ℕ) :
    CommRing ((S d₁⊗[ℚ]S e₁)⊗[ℚ](S d₂⊗[ℚ]S e₂)) := inferInstance
noncomputable local instance cancelFourAlg (d₁ e₁ d₂ e₂ : I → ℕ) :
    Algebra ℚ ((S d₁⊗[ℚ]S e₁)⊗[ℚ](S d₂⊗[ℚ]S e₂)) := inferInstance

noncomputable def mappedInverseKernel {R : Type*} [CommRing R] [Algebra ℚ R]
    (a : I → I → ℕ) (d e : I → ℕ) (f : S d⊗[ℚ]S e →ₐ[ℚ] R) : (LaurentSeries R)ˣ :=
  Units.map (mapRing f.toRingHom).toMonoidHom (SeparationInfinity.inverseKernelUnit a d e)

noncomputable local instance cancelTensorSelf (d e : I → ℕ) :
    Module (S d⊗[ℚ]S e) (S d⊗[ℚ]S e) := Semiring.toModule
noncomputable local instance cancelTensorNonUnital (d e : I → ℕ) :
    NonUnitalNonAssocSemiring (S d⊗[ℚ]S e) := (cancelTensorRing d e).toNonUnitalNonAssocSemiring
noncomputable local instance cancelFourNonUnital (d₁ e₁ d₂ e₂ : I → ℕ) :
    NonUnitalNonAssocSemiring ((S d₁⊗[ℚ]S e₁)⊗[ℚ](S d₂⊗[ℚ]S e₂)) :=
  (cancelFourRing d₁ e₁ d₂ e₂).toNonUnitalNonAssocSemiring

noncomputable local instance cancelSeriesRing (d₁ e₁ d₂ e₂ : I → ℕ) :
    CommRing (LaurentSeries ((S d₁⊗[ℚ]S e₁)⊗[ℚ](S d₂⊗[ℚ]S e₂))) := inferInstance

noncomputable def fourRowsInverseUnit (a : I → I → ℕ) (d₁ e₁ d₂ e₂ : I → ℕ)
    (A : Cut d₁ e₁) (B : Cut d₂ e₂) : (LaurentSeries ((S d₁⊗[ℚ]S e₁)⊗[ℚ](S d₂⊗[ℚ]S e₂)))ˣ :=
  mappedInverseKernel a (d₁+e₁) (d₂+e₂) (restrictRows d₁ e₁ d₂ e₂ A B)

noncomputable def fourFirstInverseUnit (a : I → I → ℕ) (d₁ e₁ d₂ e₂ : I → ℕ) :
    (LaurentSeries ((S d₁⊗[ℚ]S e₁)⊗[ℚ](S d₂⊗[ℚ]S e₂)))ˣ :=
  mappedInverseKernel a d₁ d₂ (firstColumnAlg d₁ e₁ d₂ e₂)

noncomputable def fourSecondInverseUnit (a : I → I → ℕ) (d₁ e₁ d₂ e₂ : I → ℕ) :
    (LaurentSeries ((S d₁⊗[ℚ]S e₁)⊗[ℚ](S d₂⊗[ℚ]S e₂)))ˣ :=
  mappedInverseKernel a e₁ e₂ (secondColumnAlg d₁ e₁ d₂ e₂)

noncomputable def fourCrossingInverseUnit (a : I → I → ℕ) (d₁ e₁ d₂ e₂ : I → ℕ) :
    (LaurentSeries ((S d₁⊗[ℚ]S e₁)⊗[ℚ](S d₂⊗[ℚ]S e₂)))ˣ :=
  mappedInverseKernel a e₁ d₂ (crossingColumnAlg d₁ e₁ d₂ e₂)

lemma fourTotalInverseUnit_zero (d₁ e₁ d₂ e₂ : I → ℕ) :
    fourTotalInverseUnit (fun _ _ : I=>0) d₁ e₁ d₂ e₂=fourClearingUnit d₁ e₁ d₂ e₂ := by
  unfold fourTotalInverseUnit fourClearingUnit
  congr 1
  funext i j
  simp only [SeparationInfinity.inverseExponent,Nat.cast_zero,sub_zero]

noncomputable def fourSeriesValue (d₁ e₁ d₂ e₂ : I → ℕ) :
    LaurentSeries ((S d₁⊗[ℚ]S e₁)⊗[ℚ](S d₂⊗[ℚ]S e₂)) →+*
      LaurentSeries (MvPolynomial (CellVars d₁ e₁⊕CellVars d₂ e₂) ℚ) :=
  mapRing (fourValueAlg d₁ e₁ d₂ e₂).toRingHom

lemma fourSeriesValue_injective (d₁ e₁ d₂ e₂ : I → ℕ) :
    Function.Injective (fourSeriesValue d₁ e₁ d₂ e₂) :=
  mapRing_injective (fourValueAlg d₁ e₁ d₂ e₂).toRingHom (fourValue_injective d₁ e₁ d₂ e₂)

lemma fourSeriesValue_rows (a : I → I → ℕ) (d₁ e₁ d₂ e₂ : I → ℕ)
    (A : Cut d₁ e₁) (B : Cut d₂ e₂) :
    Units.map (fourSeriesValue d₁ e₁ d₂ e₂).toMonoidHom (fourRowsInverseUnit a d₁ e₁ d₂ e₂ A B)=
      fourTotalInverseUnit a d₁ e₁ d₂ e₂ := fourKernel_restrictRows a A B

lemma fourSeriesValue_first (a : I → I → ℕ) (d₁ e₁ d₂ e₂ : I → ℕ) :
    Units.map (fourSeriesValue d₁ e₁ d₂ e₂).toMonoidHom (fourFirstInverseUnit a d₁ e₁ d₂ e₂)=
      rectangular (SeparationInfinity.inverseExponent a)
        (fun i j x y=>fourAffine d₁ e₁ d₂ e₂ i j (.inl x) (.inl y)) :=
  fourKernel_firstColumn a d₁ e₁ d₂ e₂

lemma fourSeriesValue_second (a : I → I → ℕ) (d₁ e₁ d₂ e₂ : I → ℕ) :
    Units.map (fourSeriesValue d₁ e₁ d₂ e₂).toMonoidHom (fourSecondInverseUnit a d₁ e₁ d₂ e₂)=
      rectangular (SeparationInfinity.inverseExponent a)
        (fun i j x y=>fourAffine d₁ e₁ d₂ e₂ i j (.inr x) (.inr y)) :=
  fourKernel_secondColumn a d₁ e₁ d₂ e₂

lemma fourSeriesValue_crossing (a : I → I → ℕ) (d₁ e₁ d₂ e₂ : I → ℕ) :
    Units.map (fourSeriesValue d₁ e₁ d₂ e₂).toMonoidHom (fourCrossingInverseUnit a d₁ e₁ d₂ e₂)=
      rectangular (SeparationInfinity.inverseExponent a)
        (fun i j x y=>fourAffine d₁ e₁ d₂ e₂ i j (.inr x) (.inl y)) :=
  fourKernel_crossingColumn a d₁ e₁ d₂ e₂

lemma fourSeriesValue_cross (a : I → I → ℕ) (d₁ e₁ d₂ e₂ : I → ℕ) :
    fourSeriesValue d₁ e₁ d₂ e₂
      (polynomial (fourRelativeTaylor d₁ e₁ d₂ e₂ (fourCrossTensor a d₁ e₁ d₂ e₂)))=
      (fourCrossAffineUnit a d₁ e₁ d₂ e₂).val := fourTensor_cross_realize a d₁ e₁ d₂ e₂

lemma units_map_neg_one {R S : Type*} [Ring R] [Ring S] (f : R →+* S) :
    Units.map f.toMonoidHom (-1 : Rˣ)=(-1 : Sˣ) := by
  apply Units.ext
  change f (-1) = -1
  rw [map_neg,map_one]

lemma ring_map_unit_val {R S : Type*} [Ring R] [Ring S] (f : R →+* S) (u : Rˣ) :
    f u.val = (Units.map f.toMonoidHom u).val := rfl

lemma ring_map_inv_unit_val {R S : Type*} [Ring R] [Ring S] (f : R →+* S) (u : Rˣ) :
    f (u⁻¹).val = ((Units.map f.toMonoidHom u)⁻¹).val := rfl

lemma ring_map_signedUnits {R S : Type*} [CommRing R] [CommRing S]
    (f : R →+* S) (A B C D : Rˣ) (w : ℤ) :
    f (((-1)^w*(A*B*(C*D⁻¹))).val)=
    ((-1)^w*(Units.map f.toMonoidHom A*Units.map f.toMonoidHom B*
      (Units.map f.toMonoidHom C*(Units.map f.toMonoidHom D)⁻¹))).val := by
  rw [ring_map_unit_val]
  simp only [map_mul,map_inv,map_zpow,units_map_neg_one]

lemma unitKernelCancellation_lift {R S : Type*} [CommRing R] [CommRing S]
    (f : R →+* S) (hf : Function.Injective f)
    (K L A B C D : Rˣ) (P : R) (k l a b c d p : Sˣ)
    (hK : Units.map f.toMonoidHom K=k) (hL : Units.map f.toMonoidHom L=l)
    (hA : Units.map f.toMonoidHom A=a) (hB : Units.map f.toMonoidHom B=b)
    (hC : Units.map f.toMonoidHom C=c) (hD : Units.map f.toMonoidHom D=d)
    (hP : f P=p.val) (w : ℤ)
    (h : k*l⁻¹*p=(-1)^w*(a*b*(c*d⁻¹))) :
    K.val*(L⁻¹).val*P=((-1)^w*(A*B*(C*D⁻¹))).val := by
  apply hf
  rw [map_mul,map_mul,hP]
  simp only [ring_map_unit_val,map_mul,map_inv,map_zpow,units_map_neg_one,hK,hL,hA,hB,hC,hD]
  exact congrArg Units.val h

lemma unitKernelCancellation_lift2 {R S : Type*} [CommRing R] [CommRing S]
    (f : R →+* S) (hf : Function.Injective f)
    (K L A B C D : Rˣ) (P : R) (p : Sˣ) (hP : f P=p.val) (w : ℤ)
    (h : Units.map f.toMonoidHom K*(Units.map f.toMonoidHom L)⁻¹*p=
      (-1)^w*(Units.map f.toMonoidHom A*Units.map f.toMonoidHom B*
      (Units.map f.toMonoidHom C*(Units.map f.toMonoidHom D)⁻¹))) :
    K.val*(L⁻¹).val*P=((-1)^w*(A*B*(C*D⁻¹))).val :=
  unitKernelCancellation_lift f hf K L A B C D P _ _ _ _ _ _ p rfl rfl rfl rfl rfl rfl hP w h

lemma fourSeriesValue_rows_val (a : I → I → ℕ) (d₁ e₁ d₂ e₂ : I → ℕ)
    (A : Cut d₁ e₁) (B : Cut d₂ e₂) :
    fourSeriesValue d₁ e₁ d₂ e₂ (fourRowsInverseUnit a d₁ e₁ d₂ e₂ A B).val=
      (fourTotalInverseUnit a d₁ e₁ d₂ e₂).val :=
  congrArg Units.val (fourSeriesValue_rows a d₁ e₁ d₂ e₂ A B)

lemma fourSeriesValue_rows_inv_val (a : I → I → ℕ) (d₁ e₁ d₂ e₂ : I → ℕ)
    (A : Cut d₁ e₁) (B : Cut d₂ e₂) :
    fourSeriesValue d₁ e₁ d₂ e₂ ((fourRowsInverseUnit a d₁ e₁ d₂ e₂ A B)⁻¹).val=
      ((fourTotalInverseUnit a d₁ e₁ d₂ e₂)⁻¹).val :=
  congrArg (fun u=> (u⁻¹).val) (fourSeriesValue_rows a d₁ e₁ d₂ e₂ A B)

noncomputable def fourTensorKernelRHS (a : I → I → ℕ) (d₁ e₁ d₂ e₂ : I → ℕ) :
    (LaurentSeries ((S d₁⊗[ℚ]S e₁)⊗[ℚ](S d₂⊗[ℚ]S e₂)))ˣ :=
  (-1)^eulerForm a d₂ e₁ *
    (fourFirstInverseUnit a d₁ e₁ d₂ e₂ * fourSecondInverseUnit a d₁ e₁ d₂ e₂ *
      (fourCrossingInverseUnit a d₁ e₁ d₂ e₂ *
        (fourCrossingInverseUnit (fun i j=>a j i) d₁ e₁ d₂ e₂)⁻¹))

lemma fourSeriesValue_kernelRHS (a : I → I → ℕ) (d₁ e₁ d₂ e₂ : I → ℕ) :
    Units.map (fourSeriesValue d₁ e₁ d₂ e₂).toMonoidHom
      (fourTensorKernelRHS a d₁ e₁ d₂ e₂)=
    fourTotalInverseUnit a d₁ e₁ d₂ e₂ * (fourClearingUnit d₁ e₁ d₂ e₂)⁻¹ *
      fourCrossAffineUnit a d₁ e₁ d₂ e₂ := by
  apply Units.ext
  change fourSeriesValue d₁ e₁ d₂ e₂ (fourTensorKernelRHS a d₁ e₁ d₂ e₂).val = _
  unfold fourTensorKernelRHS
  rw [ring_map_signedUnits]
  apply congrArg Units.val
  refine Eq.trans ?_ (fourKernel_cancellation a d₁ e₁ d₂ e₂).symm
  apply congrArg ((-1)^eulerForm a d₂ e₁ * ·)
  exact congrArg₂ (· * ·)
    (congrArg₂ (· * ·) (fourSeriesValue_first a d₁ e₁ d₂ e₂)
      (fourSeriesValue_second a d₁ e₁ d₂ e₂))
    (congrArg₂ (· * ·) (fourSeriesValue_crossing a d₁ e₁ d₂ e₂)
      (congrArg Inv.inv (fourSeriesValue_crossing (fun i j=>a j i) d₁ e₁ d₂ e₂)))

lemma fourSeriesValue_kernelRHS_val (a : I → I → ℕ) (d₁ e₁ d₂ e₂ : I → ℕ) :
    fourSeriesValue d₁ e₁ d₂ e₂ (fourTensorKernelRHS a d₁ e₁ d₂ e₂).val=
    (fourTotalInverseUnit a d₁ e₁ d₂ e₂ * (fourClearingUnit d₁ e₁ d₂ e₂)⁻¹ *
      fourCrossAffineUnit a d₁ e₁ d₂ e₂).val :=
  congrArg Units.val (fourSeriesValue_kernelRHS a d₁ e₁ d₂ e₂)

lemma fourSeriesValue_kernelLHS (a : I → I → ℕ) (d₁ e₁ d₂ e₂ : I → ℕ)
    (A : Cut d₁ e₁) (B : Cut d₂ e₂) :
    fourSeriesValue d₁ e₁ d₂ e₂
      ((fourRowsInverseUnit a d₁ e₁ d₂ e₂ A B).val *
        ((fourRowsInverseUnit (fun _ _ : I=>0) d₁ e₁ d₂ e₂ A B)⁻¹).val *
        polynomial (fourRelativeTaylor d₁ e₁ d₂ e₂ (fourCrossTensor a d₁ e₁ d₂ e₂)))=
    (fourTotalInverseUnit a d₁ e₁ d₂ e₂ * (fourClearingUnit d₁ e₁ d₂ e₂)⁻¹ *
      fourCrossAffineUnit a d₁ e₁ d₂ e₂).val := by
  rw [(fourSeriesValue d₁ e₁ d₂ e₂).map_mul,(fourSeriesValue d₁ e₁ d₂ e₂).map_mul,
    fourSeriesValue_rows_val,fourSeriesValue_rows_inv_val,fourTotalInverseUnit_zero,fourSeriesValue_cross]
  rfl

lemma fourTensorKernel_cancellation (a : I → I → ℕ) (d₁ e₁ d₂ e₂ : I → ℕ)
    (A : Cut d₁ e₁) (B : Cut d₂ e₂) :
    (fourRowsInverseUnit a d₁ e₁ d₂ e₂ A B).val *
      ((fourRowsInverseUnit (fun _ _ : I=>0) d₁ e₁ d₂ e₂ A B)⁻¹).val *
      polynomial (fourRelativeTaylor d₁ e₁ d₂ e₂ (fourCrossTensor a d₁ e₁ d₂ e₂))=
    (((-1 : (LaurentSeries ((S d₁⊗[ℚ]S e₁)⊗[ℚ](S d₂⊗[ℚ]S e₂)))ˣ)^eulerForm a d₂ e₁) *
      (fourFirstInverseUnit a d₁ e₁ d₂ e₂ *
        fourSecondInverseUnit a d₁ e₁ d₂ e₂ *
        (fourCrossingInverseUnit a d₁ e₁ d₂ e₂ *
        (fourCrossingInverseUnit (fun i j=>a j i) d₁ e₁ d₂ e₂)⁻¹))).val := by
  apply fourSeriesValue_injective d₁ e₁ d₂ e₂
  exact (fourSeriesValue_kernelLHS a d₁ e₁ d₂ e₂ A B).trans
    (fourSeriesValue_kernelRHS_val a d₁ e₁ d₂ e₂).symm

end ElementaryPositivity.RawShuffle

end

end OAI