@@ -60,23 +60,24 @@ open Chapter1 (dropWhile)
6060variable {a : Type }
6161
6262-- it may simplify the proofs
63- structure SymList' (α : Type ) where
64- lhs : List α
65- rhs : List α
63+ structure SymList' (a : Type ) where
64+ lhs : List a
65+ rhs : List a
6666 ok : (lhs.length = 0 → rhs.length ≤ 1 ) ∧
6767 (rhs.length = 0 → lhs.length ≤ 1 )
6868 deriving Repr
6969
70- structure SymList (α : Type ) where
71- lhs : List α
72- rhs : List α
70+ structure SymList (a : Type ) where
71+ lhs : List a
72+ rhs : List a
7373 ok : (lhs.isEmpty → rhs.isEmpty ∨ rhs.length = 1 ) ∧
7474 (rhs.isEmpty → lhs.isEmpty ∨ lhs.length = 1 )
7575 deriving Repr
7676
77+
7778def nil : SymList a := SymList.mk [] [] (by simp)
7879
79- instance {α : Type} : Inhabited (SymList α ) where
80+ instance : Inhabited (SymList a ) where
8081 default := nil
8182
8283def fromSL (sl : SymList a) : List a :=
@@ -111,7 +112,7 @@ def snocSL : a → SymList a → SymList a
111112| z, ⟨ a::as, bs, _ ⟩ => ⟨ (a::as), (z :: bs), by simp⟩
112113
113114
114- example {a : Type } (x : a) : snoc x ∘ fromSL = fromSL ∘ snocSL x := by
115+ example (x : a) : snoc x ∘ fromSL = fromSL ∘ snocSL x := by
115116 funext sl
116117 simp [Function.comp]
117118 have ⟨lhs, rhs, ok⟩ := sl
@@ -126,7 +127,7 @@ example {a : Type} (x : a) : snoc x ∘ fromSL = fromSL ∘ snocSL x := by
126127 | y :: ys => simp
127128
128129
129- def isEmpty {a : Type } (sl : SymList a) : Bool :=
130+ def isEmpty (sl : SymList a) : Bool :=
130131 sl.lhs.isEmpty ∧ sl.rhs.isEmpty
131132
132133theorem sl_empty_l_empty :
@@ -150,9 +151,9 @@ theorem sl_noempty_l_noempty :
150151 assumption
151152
152153
153- def lastSL {a : Type } (sl : SymList a) (ne : ¬ isEmpty sl) : a :=
154+ def lastSL (sl : SymList a) (ne : ¬ isEmpty sl) : a :=
154155 match sl with
155- | ⟨xs, ys, hp ⟩ =>
156+ | ⟨xs, ys, _ ⟩ =>
156157 if h₁ : ys.isEmpty then
157158 xs.head (by
158159 unfold isEmpty at ne; simp at ne
@@ -164,6 +165,11 @@ def lastSL {a : Type} (sl : SymList a) (ne : ¬ isEmpty sl) : a :=
164165 else
165166 ys.head (by simp at h₁ ; exact h₁)
166167
168+ def lastSL? : SymList a → Option a
169+ | ⟨[], [], _⟩ => none
170+ | ⟨x :: _, [], _⟩ => x
171+ | ⟨[], y :: _, _⟩ => y
172+ | ⟨_, y :: _, _⟩ => y
167173
168174example (sl : SymList a) (h : ¬ isEmpty sl)
169175 : (fromSL sl).getLast (sl_noempty_l_noempty sl h) = lastSL sl h := by
0 commit comments