-
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
import Mathlib
structure SurBase where
l : List SurBase
r : List SurBase
-- 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⟩))
@[grind]
def SurBase.le (x : SurBase) (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]
-- structure Sur where
-- l : List Sur
-- r : List Sur
-- h : ∀ x ∈ l, ∀ y ∈ r, SurBase.le ⟨x.l, x.r⟩ ⟨y.l, y.r⟩
@[grind]
def SurBase.correct (x : SurBase) :=
(∀ a ∈ x.l, ∀ b ∈ x.r, a.le b) ∧ (∀ a ∈ x.l, a.correct) ∧ (∀ b ∈ x.r, b.correct)
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.correct }
@[grind]
def SurZero : Sur := ⟨⟨[], []⟩, by grind⟩
@[grind]
def SurOne : Sur := ⟨⟨[SurZero.val], []⟩, by grind⟩
@[grind]
def SurNegOne : Sur := ⟨⟨[], [SurZero.val]⟩, by grind⟩
example : SurZero.val.le SurOne.val := by
grind
example : SurNegOne.val.le SurOne.val := by
grind
example : SurZero.val.le SurZero.val := by
grind
example : SurOne.val.le SurOne.val := by
grind
lemma Sur_trans (x y z : Sur) (hxy : x.val.le y.val) (hyz : y.val.le z.val) : x.val.le z.val := by
by_contra hxz
unfold SurBase.le at hxy hyz hxz
simp at hxz
by_cases h : ∀ a ∈ x.val.l, ¬z.val.le a
· obtain ⟨k, hk⟩ := hxz h
have := Sur_trans ⟨k, by
have := z.property
unfold SurBase.correct at this
exact this.2.2 k hk.1⟩ x y
grind
· simp at h
obtain ⟨k, hk⟩ := h
have := Sur_trans y z ⟨k, by
have := x.property
unfold SurBase.correct at this
exact this.2.1 k hk.1⟩
grind
termination_by sizeOf x.val + sizeOf y.val + sizeOf z.val
decreasing_by
all_goals expose_names
· cases _ : z.val
have := List.sizeOf_lt_of_mem hk.1
grind [SurBase.mk.sizeOf_spec]
· cases _ : x.val
have := List.sizeOf_lt_of_mem hk.1
grind [SurBase.mk.sizeOf_spec]
lemma Sur_refl (x : Sur) : x.val.le x.val := by
by_contra hx
unfold 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