File size: 7,677 Bytes
7d9f027
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import Mathlib
import OAI.Probability.SKGap.Localization.Append

namespace OAI

section
noncomputable section
noncomputable section
open scoped BigOperators
noncomputable section
noncomputable section
noncomputable section
open scoped BigOperators
namespace SKGap.Noncrossing
namespace InverseDiagram

def blockDegree (bs : List Bool) : ℕ := (bs.map (fun b => if b then 1 else 2)).sum

def blockEnumerate : ℕ → List (List Bool)
  | 0 => [[]]
  | n+1 => (blockEnumerate n).map (true::·) ++
      (if n=0 then [] else (blockEnumerate (n-1)).map (false::·))
termination_by m => m

def Blocks (n : ℕ) := {bs : List Bool // blockDegree bs=n}

@[simp] lemma blockDegree_nil : blockDegree []=0 := rfl
@[simp] lemma blockDegree_true (bs : List Bool) :
    blockDegree (true::bs)=blockDegree bs+1 := by simp [blockDegree,add_comm]
@[simp] lemma blockDegree_false (bs : List Bool) :
    blockDegree (false::bs)=blockDegree bs+2 := by simp [blockDegree,add_comm]

lemma mem_blockEnumerate (bs : List Bool) (n : ℕ) :
    bs∈blockEnumerate n ↔ blockDegree bs=n := by
  induction n using Nat.strong_induction_on generalizing bs with
  | h n ih =>
    cases n with
    | zero =>
      cases bs with
      | nil => simp [blockEnumerate]
      | cons b bs => cases b <;> simp [blockEnumerate]
    | succ n =>
      rw [blockEnumerate]
      cases bs with
      | nil => split_ifs <;> simp
      | cons b bs =>
        cases b with
        | true =>
          have ht : ((true::bs)∈(blockEnumerate n).map (true::·) ++
            (if n=0 then [] else (blockEnumerate (n-1)).map (false::·))) ↔
              bs∈blockEnumerate n := by split_ifs <;> simp
          rw [ht,ih n (by omega) bs,blockDegree_true]
          omega
        | false =>
          by_cases hn : n=0
          · subst n; simp
          · have hf : ((false::bs)∈(blockEnumerate n).map (true::·) ++
                (if n=0 then [] else (blockEnumerate (n-1)).map (false::·))) ↔
                  bs∈blockEnumerate (n-1) := by simp [hn]
            rw [hf,ih (n-1) (by omega) bs,blockDegree_false]
            omega

lemma blockEnumerate_nodup (n : ℕ) : (blockEnumerate n).Nodup := by
  induction n using Nat.strong_induction_on with
  | h n ih =>
    cases n with
    | zero => simp [blockEnumerate]
    | succ n =>
      rw [blockEnumerate,List.nodup_append]
      refine ⟨(List.nodup_map_iff (by intro a b h; exact List.cons.inj h |>.2)).mpr
        (ih n (by omega)),?_,?_⟩
      · split_ifs
        · simp
        · exact (List.nodup_map_iff (by intro a b h; exact List.cons.inj h |>.2)).mpr
            (ih (n-1) (by omega))
      · split_ifs
        · simp
        · intro bs h1 cs h2 he
          obtain ⟨p,_,rfl⟩ := List.mem_map.mp h1
          obtain ⟨q,_,rfl⟩ := List.mem_map.mp h2
          cases he

instance blocksFintype (n : ℕ) : Fintype (Blocks n) :=
  Fintype.ofFinset (blockEnumerate n).toFinset (by
    intro bs
    simp only [List.mem_toFinset,mem_blockEnumerate]; rfl)

def LiteralPaired (n : ℕ) := Σ bs : Blocks n, Diagram.Paired (expandBlocks bs.val)
instance literalPairedFintype (n : ℕ) : Fintype (LiteralPaired n) :=
  inferInstanceAs (Fintype (Σ bs : Blocks n, Diagram.Paired (expandBlocks bs.val)))

def AtDegree (n : ℕ) := {d : InverseDiagram // d.degree=n}
instance atDegreeFintype (n : ℕ) : Fintype (AtDegree n) :=
  Fintype.ofFinset (enumerate n).toFinset (by
    intro d
    simp only [List.mem_toFinset,mem_enumerate]; rfl)

def toLiteral {n : ℕ} (d : AtDegree n) : LiteralPaired (2*n) :=
  ⟨⟨d.val.blocks,by
      simpa only [blockDegree,d.property] using d.val.blocks_degree⟩,
    ⟨d.val.toDiagram,d.val.toDiagram_word⟩⟩

lemma toLiteral_bijective (n : ℕ) : Function.Bijective (@toLiteral n) := by
  constructor
  · intro d e he
    apply Subtype.ext
    apply toDiagram_injective
    exact congrArg (fun z : LiteralPaired (2*n) => z.2.val) he
  · intro z
    obtain ⟨e,he,hed⟩ := toDiagram_surjective z.2.val z.1.val z.2.property
    have hn : e.degree=n := by
      have hh := e.blocks_degree
      rw [he] at hh
      change blockDegree z.1.val=2*e.degree at hh
      rw [z.1.property] at hh
      omega
    use ⟨e,hn⟩
    apply Sigma.ext
    · exact Subtype.ext he
    · apply (Subtype.heq_iff_coe_eq (fun d => ?_)).mpr hed
      change d.word=expandBlocks e.blocks ↔ d.word=expandBlocks z.1.val
      rw [he]

def literalEquiv (n : ℕ) : AtDegree n ≃ LiteralPaired (2*n) :=
  Equiv.ofBijective toLiteral (toLiteral_bijective n)

lemma literal_odd_empty (n : ℕ) : IsEmpty (LiteralPaired (2*n+1)) := by
  constructor
  intro z
  obtain ⟨e,he,hed⟩ := toDiagram_surjective z.2.val z.1.val z.2.property
  have hh := e.blocks_degree
  rw [he] at hh
  change blockDegree z.1.val=2*e.degree at hh
  rw [z.1.property] at hh
  omega

variable {ι : Type*} [Fintype ι]

def blockLabel (j : ℝ) (a : ι→ℝ) : Bool → ι→ℝ
  | true => a
  | false => fun i => -(j*average a)*a i

lemma toDiagram_value (j : ℝ) (a : ι→ℝ) (d : InverseDiagram) (i : ι) :
    (d.toDiagram.map (blockLabel j a)).value j i = d.value j a i := by
  induction d generalizing i with
  | empty => rfl
  | counterterm d ih => simp [toDiagram,Diagram.map,Diagram.value,blockLabel,value,ih]
  | arch u v iu iv =>
    simp only [toDiagram,Diagram.map,Diagram.map_append,Diagram.value,blockLabel,
      value,iv]
    have hm : Diagram.mean (fun k => (u.toDiagram.map (blockLabel j a)).value j k*a k) =
        average (fun k => a k*value j a u k) := by
      simp only [Diagram.mean,average]
      congr 1
      apply Finset.sum_congr rfl
      intro k _
      rw [iu]
      ring
    have hv : Diagram.value j ((u.toDiagram.map (blockLabel j a)).append (.diag a .nil)) =
        (fun k => (u.toDiagram.map (blockLabel j a)).value j k * a k) := by
      funext k
      simp only [Diagram.value_append,Diagram.value,mul_one]
    rw [hv,hm]
    ring

def literalCoefficient (j : ℝ) (a : ι→ℝ) (n : ℕ) (i : ι) : ℝ :=
  ∑ z : LiteralPaired n, (z.2.val.map (blockLabel j a)).value j i

lemma literalCoefficient_even (j : ℝ) (a : ι→ℝ) (n : ℕ) (i : ι) :
    literalCoefficient j a (2*n) i=coefficient j a n i := by
  have hh := Fintype.sum_equiv (literalEquiv n)
    (fun d => value j a d.val i)
    (fun z => (z.2.val.map (blockLabel j a)).value j i)
    (fun d => (toDiagram_value j a d.val i).symm)
  change _=literalCoefficient j a (2*n) i at hh
  rw [← hh]
  let : Fintype {d : InverseDiagram // d.degree=n} := atDegreeFintype n
  change (∑ d : {d : InverseDiagram // d.degree=n}, value j a d.val i) = _
  have hx := Finset.sum_subtype (p := fun d : InverseDiagram => d.degree=n)
    (F := atDegreeFintype n)
    (enumerate n).toFinset (by
      intro d; simpa only [List.mem_toFinset] using mem_enumerate d n)
    (fun d => value j a d i)
  exact hx.symm.trans (List.sum_toFinset _ (enumerate_nodup n))

lemma literalCoefficient_odd (j : ℝ) (a : ι→ℝ) (n : ℕ) (i : ι) :
    literalCoefficient j a (2*n+1) i=0 := by
  let := literal_odd_empty n
  exact Finset.sum_eq_zero (by intro z; exact isEmptyElim z)

theorem literalCoefficient_eq (j : ℝ) (a : ι→ℝ) (n : ℕ) (i : ι) :
    literalCoefficient j a n i = if n=0 then 1 else 0 := by
  obtain ⟨m,hm⟩|⟨m,hm⟩ := Nat.even_or_odd n
  · have he : n=2*m := by omega
    rw [he,literalCoefficient_even]
    by_cases h : m=0
    · subst m; simp
    · rw [coefficient_positive j a m (by omega)]
      simp [h]
  · have he : n=2*m+1 := by omega
    rw [he,literalCoefficient_odd]
    simp

end InverseDiagram
end SKGap.Noncrossing

noncomputable section
open scoped BigOperators

end
end
end
end
end
end
end

end OAI