-
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
import Mathlib
structure SurBase where
l : List SurBase
r : List SurBase
@[grind]
def SurBase.le (x y : SurBase) :=
(∀ a ∈ x.l, ¬le y a) ∧ (∀ b ∈ y.r, ¬le b x)
termination_by sizeOf x + sizeOf y
decreasing_by
all_goals
expose_names
cases x
cases y
have := List.sizeOf_lt_of_mem h
grind [SurBase.mk.sizeOf_spec]
@[grind]
def SurBase.valid (x : SurBase) :=
(∀ a ∈ x.l, ∀ b ∈ x.r, a.le b) ∧ (x.l.Nodup ∧ ∀ a ∈ x.l, a.valid) ∧ (x.r.Nodup ∧ ∀ b ∈ x.r, b.valid)
decreasing_by
all_goals
expose_names
cases x
have := List.sizeOf_lt_of_mem h
grind [SurBase.mk.sizeOf_spec]
def Sur := { x : SurBase // x.valid }
def Sur.valid (x : Sur) := by
have := x.property
unfold SurBase.valid at this
exact this
def Sur.l (x : Sur) : List Sur :=
x.val.l.attach.map fun ⟨a, b⟩ ↦ ⟨a, x.valid.2.1.2 a b⟩
def Sur.r (x : Sur) : List Sur :=
x.val.r.attach.map fun ⟨a, b⟩ ↦ ⟨a, x.valid.2.2.2 a b⟩
lemma sur_in_l {a x : Sur} : a ∈ x.l ↔ a.val ∈ x.val.l := by
simp [Sur.l]
constructor
· grind
· intro h
use a.val, h
rfl
lemma sur_in_r {a x : Sur} : a ∈ x.r ↔ a.val ∈ x.val.r := by
simp [Sur.r]
constructor
· grind
· intro h
use a.val, h
rfl
noncomputable instance : SizeOf Sur where
sizeOf x := sizeOf x.val
@[grind]
lemma sur_sizeOf {x : Sur} : sizeOf x = sizeOf x.val := by rfl
lemma list_sizeOf [SizeOf α] (l : List α) : sizeOf l = 1 + (l.map (1 + sizeOf ·)).sum := by
induction l
· trivial
· grind [List.cons.sizeOf_spec]
lemma sur_l_size {x : Sur} : sizeOf x.val.l = sizeOf x.l := by
simp [Sur.l, list_sizeOf, sur_sizeOf]
lemma sur_r_size {x : Sur} : sizeOf x.val.r = sizeOf x.r := by
simp [Sur.r, list_sizeOf, sur_sizeOf]
@[grind]
lemma sur_sizeOf_spec {x : Sur} : sizeOf x = 1 + sizeOf x.l + sizeOf x.r := by
cases _ : x.val
grind [SurBase.mk.sizeOf_spec, sur_l_size, sur_r_size]
@[grind]
def Sur.le (x y : Sur) :=
(∀ a ∈ x.l, ¬le y a) ∧ (∀ b ∈ y.r, ¬le b x)
termination_by sizeOf x + sizeOf y
decreasing_by
all_goals
rename_i h
have := List.sizeOf_lt_of_mem h
grind
instance : LE Sur where
le x y := x.le y
@[grind]
lemma sur_le {x y : Sur} : LE.le x y ↔ x.le y := by rfl
lemma sur_le_eq_surbase_le {x y : Sur} : x.val.le y.val ↔ x ≤ y := by
rw [sur_le, Sur.le, SurBase.le]
constructor
· intro h
constructor
· intro a ha
have := h.1 a.val (sur_in_l.mp ha)
contrapose this
rw [not_not] at this ⊢
exact sur_le_eq_surbase_le.mpr this
· intro b hb
have := h.2 b.val (sur_in_r.mp hb)
contrapose this
rw [not_not] at this ⊢
exact sur_le_eq_surbase_le.mpr this
· intro h
constructor
· intro a ha
have := h.1 ⟨a, x.valid.2.1.2 a ha⟩ (sur_in_l.mpr ha)
contrapose this
rw [not_not] at this ⊢
exact sur_le_eq_surbase_le.mp this
· intro b hb
have := h.2 ⟨b, y.valid.2.2.2 b hb⟩ (sur_in_r.mpr hb)
contrapose this
rw [not_not] at this ⊢
exact sur_le_eq_surbase_le.mp this
termination_by sizeOf x + sizeOf y
decreasing_by
· have := List.sizeOf_lt_of_mem ha
grind
· have := List.sizeOf_lt_of_mem hb
grind
· have := List.sizeOf_lt_of_mem ha
simp [sur_sizeOf]
cases _ : x.val
grind [SurBase.mk.sizeOf_spec]
· have := List.sizeOf_lt_of_mem hb
simp [sur_sizeOf]
cases _ : y.val
grind [SurBase.mk.sizeOf_spec]
lemma sur_valid (x : Sur) : ∀ a ∈ x.l, ∀ b ∈ x.r, a ≤ b := by
intro a ha b hb
exact sur_le_eq_surbase_le.mp <| x.valid.1 a.val (sur_in_l.mp ha) b.val (sur_in_r.mp hb)
abbrev Sur.Zero : Sur := ⟨⟨[], []⟩, by grind⟩
abbrev Sur.One : Sur := ⟨⟨[Sur.Zero.val], []⟩, by grind⟩
abbrev Sur.NegOne : Sur := ⟨⟨[], [Sur.Zero.val]⟩, by grind⟩
example : Sur.Zero ≤ Sur.One := by
rw [← sur_le_eq_surbase_le]
grind
example : Sur.NegOne ≤ Sur.One := by
rw [← sur_le_eq_surbase_le]
grind
example : Sur.Zero ≤ Sur.Zero := by
rw [← sur_le_eq_surbase_le]
grind
example : Sur.One ≤ Sur.One := by
rw [← sur_le_eq_surbase_le]
grind
theorem sur_trans (x y z : Sur) (hxy : x ≤ y) (hyz : y ≤ z) : x ≤ z := by
by_contra hxz
rw [sur_le, Sur.le] at hxy hyz hxz
simp at hxz
by_cases h : ∀ a ∈ x.l, ¬z ≤ a
· obtain ⟨k, hk⟩ := hxz h
have := sur_trans k x y
grind
· simp at h
obtain ⟨k, hk⟩ := h
have := sur_trans y z k
grind
termination_by sizeOf x + sizeOf y + sizeOf z
decreasing_by
all_goals
have := List.sizeOf_lt_of_mem hk.1
grind
lemma sur_sandwich (x : Sur) : ∀ a ∈ x.val.l, a.le l
lemma Sur.refl (x : Sur) : x ≤ x := by
by_contra hx
rw [sur_le, SurBase.le] at hx
simp at hx
by_cases h : ∀ a ∈ x.val.l, ¬x.val.le a
· obtain ⟨k, hk⟩ := hx h
grind
· simp at h
obtain ⟨k, hk⟩ := h
grind
-- have := x.property
-- unfold SurBase.correct at this
-- unfold SurBase.le
-- grind
-- abbrev SurBase.correct (x : SurBase) :=
-- ∀ a ∈ x.l, ∀ b ∈ x.r, a.le b
-- instance : LE SurBase where
-- le := SurBase.le
-- structure Sur extends SurBase where
-- h : SurBase.mk l r |>.correct
-- hl : ∀ x ∈ l, x.correct
-- hr : ∀ x ∈ r, x.correct
-- inductive Sur : SurBase → Prop where
-- | zero : Sur ⟨[], []⟩
-- | step : ∀ x, ∀ a ∈ x.l, ∀ b ∈ x.r, Sur a → Sur b → a ≤ b → Sur x
-- #print SurBase
-- structure le (x y : SurBase) where
-- blah : Prop := fun x y ↦ (∀ a ∈ x.l, ¬le y a) ∧ (∀ b ∈ y.r, ¬le b x)
-- end
-- h : ∀ x ∈ l, ∀ y ∈ r,
--match a, b with
-- | SurBase.mk xl xr _, ⟨yl, yr, _⟩ =>
-- (∀ a ∈ xl, ¬le ⟨yl, yr⟩ a) ∧ (∀ b ∈ yr, ¬le b ⟨xl, xr⟩))
-- structure Sur where
-- l : List Sur
-- r : List Sur
-- h : ∀ x ∈ l, ∀ y ∈ r, @SurBase.le [show SurBase Sur by grind] x y
-- import Mathlib
-- structure SurBase where
-- l : List SurBase
-- r : List SurBase
-- @[grind]
-- def SurBase.le (x y : SurBase) :=
-- (∀ a ∈ x.l, ¬le y a) ∧ (∀ b ∈ y.r, ¬le b x)
-- termination_by sizeOf x + sizeOf y
-- decreasing_by
-- all_goals
-- expose_names
-- cases x
-- cases y
-- have := List.sizeOf_lt_of_mem h
-- grind [SurBase.mk.sizeOf_spec]
-- @[grind]
-- def SurBase.valid (x : SurBase) :=
-- (∀ a ∈ x.l, ∀ b ∈ x.r, a.le b) ∧ (x.l.Nodup ∧ ∀ a ∈ x.l, a.valid) ∧ (x.r.Nodup ∧ ∀ b ∈ x.r, b.valid)
-- decreasing_by
-- all_goals
-- expose_names
-- cases x
-- have := List.sizeOf_lt_of_mem h
-- grind [SurBase.mk.sizeOf_spec]
-- def Sur := { x : SurBase // x.valid }
-- noncomputable instance : SizeOf Sur where
-- sizeOf x := sizeOf x.val
-- lemma sur_sizeOf {x : Sur} : sizeOf x = sizeOf x.val := by rfl
-- noncomputable instance : SizeOf (Finset Sur) where
-- sizeOf f := sizeOf f.toList
-- lemma finset_sur_sizeOf (f : Finset Sur) : sizeOf f = sizeOf f.toList := by rfl
-- def Sur.valid (x : Sur) := by
-- have := x.property
-- unfold SurBase.valid at this
-- exact this
-- def Sur.l (x : Sur) : Finset Sur :=
-- @Finset.mk SurBase x.val.l x.valid.2.1.1 |>.attach.map
-- ⟨fun ⟨a, b⟩ ↦ ⟨a, x.valid.2.1.2 a b⟩, by grind [Function.Injective]⟩
-- lemma sur_in_l {a x : Sur} : a ∈ x.l ↔ a.val ∈ x.val.l := by
-- simp [Sur.l]
-- constructor
-- · grind
-- · intro h
-- use a.val, h
-- rfl
-- example (x : Sur) : x.val.l = x.l.toList.map (·.val) := by
-- simp [Sur.l]
-- -- apply?
-- -- example (x : Sur) : x.val.l = x.l := by
-- -- simp [Sur.l, finset_sur_sizeOf, finset_sur_sizeOf]
-- -- have := x.valid.2.1.1
-- -- grind
-- def Sur.r (x : Sur) : Finset Sur :=
-- @Finset.mk SurBase x.val.r x.valid.2.2.1 |>.attach.map
-- ⟨fun ⟨a, b⟩ ↦ ⟨a, x.valid.2.2.2 a b⟩, by grind [Function.Injective]⟩
-- lemma sur_in_r {a x : Sur} : a ∈ x.r ↔ a.val ∈ x.val.r := by
-- simp [Sur.r]
-- constructor
-- · grind
-- · intro h
-- use a.val, h
-- rfl
-- lemma sur_sizeOf_spec (x : Sur) : sizeOf x = 1 + sizeOf x.l + sizeOf x.r := by
-- rw [sur_sizeOf]
-- cases _ : x.val
-- rw [SurBase.mk.sizeOf_spec]
-- sorry
-- #check SurBase.mk.sizeOf_spec
-- @[grind]
-- def Sur.le (x y : Sur) :=
-- (∀ a ∈ x.l, ¬le y a) ∧ (∀ b ∈ y.r, ¬le b x)
-- termination_by sizeOf x + sizeOf y
-- decreasing_by
-- · rename_i h
-- have := List.sizeOf_lt_of_mem h
-- --simp only [sur_sizeOf]
-- -- rename_i h
-- -- apply sur_in_l at h
-- sorry
-- · sorry
-- -- all_goals
-- -- expose_names
-- -- cases x
-- -- cases y
-- -- have := List.sizeOf_lt_of_mem h
-- -- grind [SurBase.mk.sizeOf_spec]
-- instance : LE Sur where
-- le x y := x.le y
-- @[grind]
-- lemma sur_le {x y : Sur} : LE.le x y ↔ x.le y := by rfl
-- lemma sur_le_eq_surbase_le {x y : Sur} : x.val.le y.val ↔ x ≤ y := by
-- rw [sur_le, Sur.le, SurBase.le]
-- constructor
-- · intro h
-- constructor
-- · intro a ha
-- have := h.1 a.val (sur_in_l.mp ha)
-- contrapose this
-- rw [not_not] at this ⊢
-- exact sur_le_eq_surbase_le.mpr this
-- · intro b hb
-- have := h.2 b.val (sur_in_r.mp hb)
-- contrapose this
-- rw [not_not] at this ⊢
-- exact sur_le_eq_surbase_le.mpr this
-- · intro h
-- constructor
-- · intro a ha
-- have := h.1 ⟨a, x.valid.2.1.2 a ha⟩ (sur_in_l.mpr ha)
-- contrapose this
-- rw [not_not] at this ⊢
-- exact sur_le_eq_surbase_le.mp this
-- · intro b hb
-- have := h.2 ⟨b, y.valid.2.2.2 b hb⟩ (sur_in_r.mpr hb)
-- contrapose this
-- rw [not_not] at this ⊢
-- exact sur_le_eq_surbase_le.mp this
-- termination_by sizeOf x + sizeOf y
-- decreasing_by
-- sorry
-- lemma sur_valid (x : Sur) : ∀ a ∈ x.l, ∀ b ∈ x.r, a ≤ b := by
-- intro a ha b hb
-- exact sur_le_eq_surbase_le.mp <| x.valid.1 a.val (sur_in_l.mp ha) b.val (sur_in_r.mp hb)
-- abbrev Sur.Zero : Sur := ⟨⟨[], []⟩, by grind⟩
-- abbrev Sur.One : Sur := ⟨⟨[Sur.Zero.val], []⟩, by grind⟩
-- abbrev Sur.NegOne : Sur := ⟨⟨[], [Sur.Zero.val]⟩, by grind⟩
-- example : Sur.Zero ≤ Sur.One := by grind
-- example : Sur.NegOne ≤ Sur.One := by grind
-- example : Sur.Zero ≤ Sur.Zero := by grind
-- example : Sur.One ≤ Sur.One := by grind
-- lemma sur_trans (x y z : Sur) (hxy : x ≤ y) (hyz : y ≤ z) : x ≤ z := by
-- by_contra hxz
-- rw [sur_le, Sur.le] at hxy hyz hxz
-- simp at hxz
-- by_cases h : ∀ a ∈ x.l, ¬z ≤ a
-- · obtain ⟨k, _⟩ := hxz h
-- have := sur_trans k x y
-- grind
-- · simp at h
-- obtain ⟨k, _⟩ := h
-- have := sur_trans y z k
-- grind
-- termination_by sizeOf x + sizeOf y + sizeOf z
-- decreasing_by
-- all_goals
-- sorry
-- -- cases _ : x.val
-- -- cases _ : z.val
-- -- have := List.sizeOf_lt_of_mem hk.1
-- -- grind [SurBase.mk.sizeOf_spec]
-- lemma sur_sandwich (x : Sur) : ∀ a ∈ x.val.l, a.le l
-- lemma Sur.refl (x : Sur) : x ≤ x := by
-- by_contra hx
-- rw [sur_le, SurBase.le] at hx
-- simp at hx
-- by_cases h : ∀ a ∈ x.val.l, ¬x.val.le a
-- · obtain ⟨k, hk⟩ := hx h
-- grind
-- · simp at h
-- obtain ⟨k, hk⟩ := h
-- grind
-- -- have := x.property
-- -- unfold SurBase.correct at this
-- -- unfold SurBase.le
-- -- grind
-- -- abbrev SurBase.correct (x : SurBase) :=
-- -- ∀ a ∈ x.l, ∀ b ∈ x.r, a.le b
-- -- instance : LE SurBase where
-- -- le := SurBase.le
-- -- structure Sur extends SurBase where
-- -- h : SurBase.mk l r |>.correct
-- -- hl : ∀ x ∈ l, x.correct
-- -- hr : ∀ x ∈ r, x.correct
-- -- inductive Sur : SurBase → Prop where
-- -- | zero : Sur ⟨[], []⟩
-- -- | step : ∀ x, ∀ a ∈ x.l, ∀ b ∈ x.r, Sur a → Sur b → a ≤ b → Sur x
-- -- #print SurBase
-- -- structure le (x y : SurBase) where
-- -- blah : Prop := fun x y ↦ (∀ a ∈ x.l, ¬le y a) ∧ (∀ b ∈ y.r, ¬le b x)
-- -- end
-- -- h : ∀ x ∈ l, ∀ y ∈ r,
-- --match a, b with
-- -- | SurBase.mk xl xr _, ⟨yl, yr, _⟩ =>
-- -- (∀ a ∈ xl, ¬le ⟨yl, yr⟩ a) ∧ (∀ b ∈ yr, ¬le b ⟨xl, xr⟩))
-- -- structure Sur where
-- -- l : List Sur
-- -- r : List Sur
-- -- h : ∀ x ∈ l, ∀ y ∈ r, @SurBase.le [show SurBase Sur by grind] x y