File size: 15,422 Bytes
f0f05de
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import OAI.Combinatorics.Automata.Corners

namespace OAI

namespace OneWayLiveness

namespace BRel
variable {H : Type*}

@[simp] lemma restrictedId_holds (F : Set H) (x y : H) :
    (restrictedId F).holds x y ↔ x = y ∧ x ∈ F := Iff.rfl
lemma restrictedId_idem (F : Set H) : restrictedId F * restrictedId F = restrictedId F := by
  ext x z; simp

lemma restrictedId_mul (F : Set H) (a : BRel H) (x y : H) :
    (restrictedId F * a).holds x y ↔ x ∈ F ∧ a.holds x y := by simp
lemma mul_restrictedId (F : Set H) (a : BRel H) (x y : H) :
    (a * restrictedId F).holds x y ↔ a.holds x y ∧ y ∈ F := by simp

lemma corner_supported {F : Set H} (z : Corner (restrictedId F) (restrictedId_idem F))
    {x y : H} (h : z.val.holds x y) : x ∈ F ∧ y ∈ F := by
  constructor
  · have h' : (restrictedId F * z.val).holds x y := by rw [z.left]; exact h
    exact ((restrictedId_mul F _ x y).mp h').1
  · have h' : (z.val * restrictedId F).holds x y := by rw [z.right]; exact h
    exact ((mul_restrictedId F _ x y).mp h').2

def restriction (F : Set H) : Corner (restrictedId F) (restrictedId_idem F) →* BRel F where
  toFun z := ⟨fun x y => z.val.holds x.val y.val⟩
  map_one' := by ext x y; change (x.val = y.val ∧ x.val ∈ F) ↔ x = y; simp [Subtype.ext_iff]
  map_mul' z w := by
    ext x y
    change (∃ k : H, z.val.holds x.val k ∧ w.val.holds k y.val) ↔
      ∃ k : F, z.val.holds x.val k.val ∧ w.val.holds k.val y.val
    constructor
    · rintro ⟨k, hz, hw⟩
      exact ⟨⟨k, (corner_supported z hz).2⟩, hz, hw⟩
    · rintro ⟨k, hz, hw⟩
      exact ⟨k.val, hz, hw⟩

def extend (F : Set H) (a : BRel F) : BRel H :=
  ⟨fun x y => ∃ hx : x ∈ F, ∃ hy : y ∈ F, a.holds ⟨x, hx⟩ ⟨y, hy⟩⟩

def extension (F : Set H) (a : BRel F) : Corner (restrictedId F) (restrictedId_idem F) :=
  ⟨extend F a, by ext x y; simp only [restrictedId_mul]; exact ⟨And.right, fun h => ⟨h.choose, h⟩⟩,
    by ext x y; simp only [mul_restrictedId]; exact ⟨And.left, fun h => ⟨h, h.choose_spec.choose⟩⟩⟩

def restrictionEquiv (F : Set H) : Corner (restrictedId F) (restrictedId_idem F) ≃* BRel F :=
  { restriction F with
    invFun := extension F
    left_inv := by
      intro z
      apply Corner.ext
      ext x y
      change (∃ hx : x ∈ F, ∃ hy : y ∈ F, z.val.holds x y) ↔ z.val.holds x y
      exact ⟨fun ⟨_, _, h⟩ => h, fun h => ⟨(corner_supported z h).1, (corner_supported z h).2, h⟩⟩
    right_inv := by
      intro a
      ext x y
      change (∃ hx : x.val ∈ F, ∃ hy : y.val ∈ F, a.holds ⟨x.val, hx⟩ ⟨y.val, hy⟩) ↔ a.holds x y
      simp }

/-- Restrict a relation corner with a split subidentity. -/
lemma relation_corner {P : BRel H} (hP : P * P = P) (F : Set H)
    (hF : restrictedId F * P * restrictedId F = restrictedId F) :
    let Q := P * restrictedId F * P
    ∃ hQ : Q * Q = Q, ∃ θ : Corner Q hQ ≃* BRel F,
      (∀ z x y, (θ z).holds x y ↔ z.val.holds x.val y.val) ∧ P * Q = Q ∧ Q * P = Q := by
  let E := restrictedId F
  have hE : E * E = E := restrictedId_idem F
  let u := P * E
  let v := E * P
  let Q := P * E * P
  have huv : u * v = Q := by dsimp [u, v, Q]; rw [← mul_assoc, mul_assoc P E E, hE]
  have hvu : v * u = E := by dsimp [u, v]; rw [mul_assoc E P, ← mul_assoc P P E, hP]; simpa only [E, mul_assoc] using hF
  have hu : u * E = u := by dsimp [u]; rw [mul_assoc, hE]
  have hv : E * v = v := by dsimp [v]; rw [← mul_assoc, hE]
  have hQ : Q * Q = Q := by
    rw [← huv, mul_assoc, ← mul_assoc v u, hvu, ← mul_assoc, hu]
  have hpq : P * Q = Q := by dsimp [Q]; rw [← mul_assoc, ← mul_assoc, hP]
  have hqp : Q * P = Q := by dsimp [Q]; rw [mul_assoc, hP]
  let θ := (Corner.equivOfSplit (he := hQ) (hf := hE) u v huv hvu hu hv).trans (restrictionEquiv F)
  refine ⟨hQ, θ, ?_, hpq, hqp⟩
  intro z x y
  change (v * z.val * u).holds x.val y.val ↔ z.val.holds x.val y.val
  have hpz : P * z.val = z.val := by
    calc
      _ = P * (Q * z.val) := by rw [z.left]
      _ = z.val := by rw [← mul_assoc, hpq, z.left]
  have hzp : z.val * P = z.val := by
    calc
      _ = (z.val * Q) * P := by rw [z.right]
      _ = z.val := by rw [mul_assoc, hqp, z.right]
  have heq : v * z.val * u = E * z.val * E := by
    dsimp [u, v]
    rw [mul_assoc E P, hpz, ← mul_assoc, mul_assoc E z.val P, hzp]
  rw [heq, mul_restrictedId, restrictedId_mul]
  simp
end BRel

namespace BRel
variable {H : Type*}
def permGraph (σ : Equiv.Perm H) : BRel H := ⟨fun x y => σ x = y⟩
@[simp] lemma permGraph_holds (σ : Equiv.Perm H) (x y : H) :
    (permGraph σ).holds x y ↔ σ x = y := Iff.rfl

def permUnit (σ : Equiv.Perm H) : (BRel H)ˣ where
  val := permGraph σ
  inv := permGraph σ.symm
  val_inv := by ext x y; simp
  inv_val := by ext x y; simp

/-- The identity with one extra pair. -/
def addEdge (x y : H) : BRel H := ⟨fun u v => u = v ∨ u = x ∧ v = y⟩
@[simp] lemma addEdge_holds (x y u v : H) :
    (addEdge x y).holds u v ↔ u = v ∨ u = x ∧ v = y := Iff.rfl
lemma addEdge_idem (x y : H) : addEdge x y * addEdge x y = addEdge x y := by
  ext u v
  simp only [mul_holds, addEdge_holds]
  aesop
lemma addEdge_ne_one {x y : H} (hxy : x ≠ y) : addEdge x y ≠ 1 := by
  intro he
  have hh : (addEdge x y).holds x y := Or.inr ⟨rfl, rfl⟩
  rw [he] at hh
  exact hxy hh

lemma conjugate_addEdge (σ : Equiv.Perm H) (x y : H) :
    (↑(permUnit σ)⁻¹ : BRel H) * addEdge x y * ↑(permUnit σ) = addEdge (σ x) (σ y) := by
  ext u v
  change (∃ k, (∃ j, σ.symm u = j ∧ (j = k ∨ j = x ∧ k = y)) ∧ σ k = v) ↔
    u = v ∨ u = σ x ∧ v = σ y
  constructor
  · rintro ⟨k, ⟨j, hj, hk⟩, hv⟩
    subst j
    rcases hk with hk | ⟨hx, rfl⟩
    · exact Or.inl (by rw [← hk, σ.apply_symm_apply] at hv; exact hv)
    · exact Or.inr ⟨(σ.symm_apply_eq).mp hx, hv.symm⟩
  · rintro (rfl | ⟨rfl, rfl⟩)
    · exact ⟨σ.symm u, ⟨σ.symm u, rfl, Or.inl rfl⟩, σ.apply_symm_apply u⟩
    · exact ⟨y, ⟨x, σ.symm_apply_apply x, Or.inr ⟨rfl, rfl⟩⟩, rfl⟩

lemma exists_perm_pair [Finite H] {x y u v : H} (hxy : x ≠ y) (huv : u ≠ v) :
    ∃ σ : Equiv.Perm H, σ x = u ∧ σ y = v := by
  let f : Bool → H := fun b => if b then y else x
  let g : Bool → H := fun b => if b then v else u
  have hf : Function.Injective f := by
    intro b c h
    cases b <;> cases c <;> simp_all [f, Ne.symm hxy]
  have hg : Function.Injective g := by
    intro b c h
    cases b <;> cases c <;> simp_all [g, Ne.symm huv]
  obtain ⟨σ, hσ⟩ := Equiv.Perm.exists_extending_pair f g hf hg
  exact ⟨σ, hσ false, hσ true⟩
end BRel

/-- Every target unit admits a unit lift (unitality included in the homomorphism). -/
def HasUnitLifts {M N : Type*} [Monoid M] [Monoid N] (f : M →* N) : Prop :=
  ∀ u : Nˣ, ∃ v : Mˣ, f (↑v) = (↑u)

lemma unit_image_inv {M N : Type*} [Monoid M] [Monoid N] (f : M →* N)
    (u : Mˣ) (v : Nˣ) (h : f (↑u) = (↑v)) : f (↑u⁻¹) = (↑v⁻¹) := by
  have he : Units.map f u = v := Units.ext h
  exact congrArg (fun w : Nˣ => (↑w⁻¹ : N)) he

lemma conjugate_lift {M H A : Type*} [Monoid M] [Finite H] [Fintype A]
    (ρ : M →* Pairing (A ⊕ A)) (f : M →* BRel H) (hl : HasUnitLifts f)
    (a : M) (ha : a * a = a) (x y : H) (hxy : x ≠ y) (hfa : f a = BRel.addEdge x y)
    (u v : H) (huv : u ≠ v) :
    ∃ b : M, b * b = b ∧ f b = BRel.addEdge u v ∧ Pairing.rank (ρ b) = Pairing.rank (ρ a) := by
  obtain ⟨σ, hx, hy⟩ := BRel.exists_perm_pair hxy huv
  obtain ⟨w, hw⟩ := hl (BRel.permUnit σ)
  refine ⟨(↑w⁻¹ : M) * a * (↑w : M), ?_, ?_, ?_⟩
  · calc
      _ = (↑w⁻¹ : M) * (a * ((↑w : M) * ↑w⁻¹) * a) * ↑w := by simp only [mul_assoc]
      _ = (↑w⁻¹ : M) * a * ↑w := by rw [Units.mul_inv, mul_one, ha]
  · rw [map_mul, map_mul, hw, unit_image_inv f w _ hw, hfa, BRel.conjugate_addEdge, hx, hy]
  · rw [map_mul, map_mul]
    change Pairing.rank (((Units.map ρ w⁻¹ : (Pairing (A ⊕ A))ˣ) : Pairing (A ⊕ A)) * ρ a *
      ((Units.map ρ w : (Pairing (A ⊕ A))ˣ) : Pairing (A ⊕ A))) = _
    rw [Pairing.rank_mul_unit, Pairing.rank_unit_mul]

/-- Disjoint source/target points and a separate intermediate hub. -/
structure RectangleFrame (H I J : Type*) where
  left : I → H
  right : J → H
  hub : H
  left_injective : Function.Injective left
  right_injective : Function.Injective right
  disjoint : ∀ i j, left i ≠ right j
  left_ne_hub : ∀ i, left i ≠ hub
  right_ne_hub : ∀ j, right j ≠ hub

namespace RectangleFrame
variable {H I J : Type*} (F : RectangleFrame H I J)
def base : BRel H := BRel.restrictedId {x | x ≠ F.hub}
def rel (E : Set (I × J)) : BRel H :=
  ⟨fun x y => (x = y ∧ x ≠ F.hub) ∨ ∃ p ∈ E, x = F.left p.1 ∧ y = F.right p.2⟩

@[simp] lemma rel_holds (E : Set (I × J)) (x y : H) :
    (F.rel E).holds x y ↔ (x = y ∧ x ≠ F.hub) ∨ ∃ p ∈ E, x = F.left p.1 ∧ y = F.right p.2 := Iff.rfl
lemma rel_empty : F.rel ∅ = F.base := by ext x y; simp [base]

lemma rel_mul (E D : Set (I × J)) : F.rel E * F.rel D = F.rel (E ∪ D) := by
  ext x y
  constructor
  · rintro ⟨k, (⟨hx, hn⟩ | ⟨p, hp, hx, hk⟩), hy⟩
    · subst k
      rcases hy with ⟨hxy, _⟩ | ⟨p, hp, hp1, hp2⟩
      · exact Or.inl ⟨hxy, hn⟩
      · exact Or.inr ⟨p, Or.inr hp, hp1, hp2⟩
    · rcases hy with ⟨hky, _⟩ | ⟨q, _hq, hq1, _hq2⟩
      · exact Or.inr ⟨p, Or.inl hp, hx, hky.symm.trans hk⟩
      · exact (F.disjoint q.1 p.2 (hq1.symm.trans hk)).elim
  · rintro (⟨rfl, hn⟩ | ⟨p, hp | hp, rfl, rfl⟩)
    · exact ⟨x, Or.inl ⟨rfl, hn⟩, Or.inl ⟨rfl, hn⟩⟩
    · exact ⟨F.right p.2, Or.inr ⟨p, hp, rfl, rfl⟩,
        Or.inl ⟨rfl, F.right_ne_hub p.2⟩⟩
    · exact ⟨F.left p.1, Or.inl ⟨rfl, F.left_ne_hub p.1⟩,
        Or.inr ⟨p, hp, rfl, rfl⟩⟩

lemma rel_idem (E : Set (I × J)) : F.rel E * F.rel E = F.rel E := by
  rw [rel_mul, Set.union_self]
lemma rel_absorb {E D : Set (I × J)} (h : E ⊆ D) :
    F.rel E * F.rel D = F.rel D ∧ F.rel D * F.rel E = F.rel D := by
  rw [rel_mul, rel_mul, Set.union_eq_right.mpr h, Set.union_eq_left.mpr h]
  exact ⟨rfl, rfl⟩

lemma generator_image (i : I) (j : J) :
    F.base * BRel.addEdge (F.left i) F.hub * BRel.addEdge F.hub (F.right j) * F.base =
      F.rel {(i,j)} := by
  have hl := F.left_ne_hub i
  have hr := F.right_ne_hub j
  have he : F.base * BRel.addEdge (F.left i) F.hub * BRel.addEdge F.hub (F.right j) * F.base =
      F.base * (BRel.addEdge (F.left i) F.hub * BRel.addEdge F.hub (F.right j)) * F.base := by
    simp only [mul_assoc]
  rw [he]
  ext x y
  simp only [base, BRel.mul_holds, BRel.addEdge_holds, rel_holds,
    Set.mem_singleton_iff, exists_eq_left]
  aesop

lemma restricted_old (E : Set (I × J)) (K : Set H)
    (hK : ∀ x ∈ K, x ≠ F.hub)
    (hE : ∀ p ∈ E, F.left p.1 ∉ K ∨ F.right p.2 ∉ K) :
    BRel.restrictedId K * F.rel E * BRel.restrictedId K = BRel.restrictedId K := by
  ext x y
  simp only [BRel.mul_restrictedId, BRel.restrictedId_mul, BRel.restrictedId_holds]
  constructor
  · rintro ⟨⟨hx, (⟨hxy, _⟩ | ⟨p, hp, rfl, rfl⟩)⟩, hy⟩
    · exact ⟨hxy, hx⟩
    · exact ((hE p hp).elim (fun h => h hx) (fun h => h hy)).elim
  · rintro ⟨rfl, hx⟩
    exact ⟨⟨hx, Or.inl ⟨rfl, hK x hx⟩⟩, hx⟩

lemma restricted_new (E : Set (I × J)) (K : Set H)
    (hK : ∀ x ∈ K, x ≠ F.hub)
    (hE : ∀ p ∈ E, F.left p.1 ∉ K ∨ F.right p.2 ∉ K)
    (i : I) (j : J) (hi : F.left i ∈ K) (hj : F.right j ∈ K) :
    let u : K := ⟨F.left i,hi⟩
    let v : K := ⟨F.right j,hj⟩
    ∀ x y : K, (F.rel (insert (i,j) E)).holds x.val y.val ↔ (BRel.addEdge u v).holds x y := by
  intro u v x y
  simp only [rel_holds, BRel.addEdge_holds]
  constructor
  · rintro (⟨hxy, _⟩ | ⟨p, hp, hx, hy⟩)
    · exact Or.inl (Subtype.ext hxy)
    · rcases hp with rfl | hp
      · exact Or.inr ⟨Subtype.ext hx, Subtype.ext hy⟩
      · exact ((hE p hp).elim (fun h => h (hx ▸ x.property)) (fun h => h (hy ▸ y.property))).elim
  · rintro (rfl | ⟨rfl, rfl⟩)
    · exact Or.inl ⟨rfl, hK x.val x.property⟩
    · exact Or.inr ⟨(i,j), Or.inl rfl, rfl, rfl⟩
end RectangleFrame

namespace Corner
variable {M : Type*} [Monoid M] {e : M} {he : e * e = e}

def flattenEquiv (q : Corner e he) (hq : q * q = q) :
    Corner q hq ≃* Corner q.val (val_idempotent q hq) where
  toFun z := ⟨z.val.val, congrArg Corner.val z.left, congrArg Corner.val z.right⟩
  invFun z :=
    ⟨⟨z.val, by
      calc
        e * z.val = e * (q.val * z.val) := by rw [z.left]
        _ = z.val := by rw [← mul_assoc, q.left, z.left], by
      calc
        z.val * e = (z.val * q.val) * e := by rw [z.right]
        _ = z.val := by rw [mul_assoc, q.right, z.right]⟩,
      Corner.ext z.left, Corner.ext z.right⟩
  left_inv z := Corner.ext (Corner.ext rfl)
  right_inv z := Corner.ext rfl
  map_mul' _ _ := Corner.ext rfl
end Corner

lemma HasUnitLifts.comp_equiv {M N P : Type*} [Monoid M] [Monoid N] [Monoid P]
    {f : M →* N} (hf : HasUnitLifts f) (e : N ≃* P) : HasUnitLifts (e.toMonoidHom.comp f) := by
  intro u
  obtain ⟨v, hv⟩ := hf (Units.map e.symm.toMonoidHom u)
  refine ⟨v, ?_⟩
  change e (f (↑v)) = (↑u)
  rw [hv]
  exact e.apply_symm_apply _

lemma min_rank_corner_unitLifts {M N A : Type*} [Monoid M] [Monoid N] [Finite M] [Fintype A]
    (ρ : M →* Pairing (A ⊕ A)) (hρ : Function.Injective ρ)
    (f : M →* N) (hs : Function.Surjective f)
    (e : M) (he : e * e = e) (q : N) (hq : q * q = q) (hf : f e = q)
    (hmin : ∀ z : M, z * z = z → f z = q → Pairing.rank (ρ e) ≤ Pairing.rank (ρ z)) :
    HasUnitLifts (Corner.mapTo (he := he) (hq := hq) f hf) := by
  intro u
  obtain ⟨y, hy⟩ := Corner.mapTo_surjective (he := he) (hq := hq) f hf hs (↑u)
  have hunit : IsUnit y := min_rank_corner_isUnit ρ hρ f e he q hq hf hmin y (hy ▸ u.isUnit)
  obtain ⟨v, rfl⟩ := hunit
  exact ⟨v, hy⟩

namespace BRel
variable {H : Type*}
lemma restricted_sandwich {P N : BRel H} (F : Set H)
    (hF : restrictedId F * P * restrictedId F = restrictedId F)
    (hPN : P * N = N) (hNP : N * P = N) :
    let Q := P * restrictedId F * P
    restrictedId F * (Q * N * Q) * restrictedId F = restrictedId F * N * restrictedId F := by
  let E := restrictedId F
  have hl : E * (P * E * P) = E * P := by rw [← mul_assoc, ← mul_assoc, hF]
  have hr : (P * E * P) * E = P * E := by rw [mul_assoc P E P, mul_assoc, hF]
  change E * ((P * E * P) * N * (P * E * P)) * E = E * N * E
  calc
    _ = (E * (P * E * P)) * N * ((P * E * P) * E) := by simp only [mul_assoc]
    _ = (E * P) * N * (P * E) := by rw [hl, hr]
    _ = E * (P * N * P) * E := by simp only [mul_assoc]
    _ = E * N * E := by rw [hPN, hNP]

lemma sandwich_holds_on {P N : BRel H} (F : Set H)
    (hF : restrictedId F * P * restrictedId F = restrictedId F)
    (hPN : P * N = N) (hNP : N * P = N) (x y : F) :
    ((P * restrictedId F * P) * N * (P * restrictedId F * P)).holds x.val y.val ↔
      N.holds x.val y.val := by
  have hh := congrArg (fun a : BRel H => a.holds x.val y.val) (restricted_sandwich F hF hPN hNP)
  simpa only [mul_restrictedId, restrictedId_mul, x.property, y.property,
    true_and, and_true, eq_iff_iff] using hh
end BRel

end OneWayLiveness

end OAI