Skip to content

Commit 2f859cc

Browse files
cleanup concat proof
1 parent 21c96ec commit 2f859cc

File tree

1 file changed

+38
-58
lines changed

1 file changed

+38
-58
lines changed

Katydid/Regex/Calculus.lean

+38-58
Original file line numberDiff line numberDiff line change
@@ -144,69 +144,49 @@ def derive_concat {α: Type} {x: α} {P Q: Lang α} {xs: List α}:
144144
(or (concat (derive P x) Q) (scalar (null P) (derive Q x))) xs := by
145145
refine Iff.intro ?toFun ?invFun
146146
case toFun =>
147+
simp only [Language.or, Language.concat, derive, derives, null, scalar]
147148
intro d
148-
guard_hyp d: derive (Language.concat P Q) x xs
149-
simp at d
150-
cases d with
151-
| intro xs' d =>
152-
cases d with
153-
| intro hp d =>
154-
cases d with
155-
| intro ys' d =>
156-
cases d with
157-
| intro hq hxs =>
158-
guard_hyp hp: P xs'
159-
guard_hyp hq: Q ys'
160-
guard_hyp hxs: x :: xs = xs' ++ ys'
161-
unfold scalar
162-
simp
149+
guard_hyp d: ∃ x_1 y, P x_1 ∧ Q y ∧ [x] ++ xs = x_1 ++ y
150+
guard_target = (∃ x_1 y, P ([x] ++ x_1) ∧ Q y ∧ xs = x_1 ++ y) ∨ P [] ∧ Q ([x] ++ xs)
151+
match d with
152+
| Exists.intro ps (Exists.intro qs (And.intro hp (And.intro hq hs))) =>
153+
guard_hyp hp : P ps
154+
guard_hyp hq : Q qs
155+
guard_hyp hs : [x] ++ xs = ps ++ qs
163156
balistic
164-
· guard_hyp hp: P []
165-
guard_hyp hq: Q (x :: xs)
166-
right
157+
· guard_hyp hp : P []
158+
guard_hyp hq : Q (x :: xs)
159+
refine Or.inr ?r
167160
guard_target = P [] ∧ Q (x :: xs)
168-
apply And.intro <;> assumption
169-
· left
170-
exists e
171-
apply And.intro
172-
exact hp
173-
exists ys'
161+
exact And.intro hp hq
162+
· guard_hyp hp : P (x :: e)
163+
guard_hyp hq : Q qs
164+
refine Or.inl ?l
165+
guard_target = ∃ x_1, P (x :: x_1) ∧ ∃ x, Q x ∧ e ++ qs = x_1 ++ x
166+
exact Exists.intro e (And.intro hp (Exists.intro qs (And.intro hq rfl)))
174167
case invFun =>
168+
simp only [Language.or, Language.concat, derive, derives, null, scalar]
175169
intro e
176-
guard_target = derive (Language.concat P Q) x xs
177-
cases e with
178-
| inl e =>
179-
guard_hyp e: Language.concat (derive P x) Q xs
180-
simp at e
181-
cases e with
182-
| intro xs' e =>
183-
cases e with
184-
| intro hp e =>
185-
cases e with
186-
| intro ys' hq =>
187-
cases hq with
188-
| intro hq hxs =>
189-
simp
190-
guard_hyp hp: P (x :: xs')
191-
guard_hyp hq: Q ys'
192-
guard_hyp hxs: xs = xs' ++ ys'
193-
exists (x :: xs')
194-
apply And.intro
195-
· exact hp
196-
· exists ys'
197-
apply And.intro
198-
· exact hq
199-
· congr
200-
| inr e =>
201-
unfold scalar at e
202-
guard_hyp e: null P ∧ derive Q x xs
203-
cases e with
204-
| intro hp hq =>
205-
simp
206-
exists []
207-
apply And.intro
208-
· exact hp
209-
· exists (x :: xs)
170+
guard_hyp e : (∃ x_1 y, P ([x] ++ x_1) ∧ Q y ∧ xs = x_1 ++ y) ∨ P [] ∧ Q ([x] ++ xs)
171+
guard_target = ∃ x_1 y, P x_1 ∧ Q y ∧ [x] ++ xs = x_1 ++ y
172+
match e with
173+
| Or.inl e =>
174+
guard_hyp e: ∃ x_1 y, P ([x] ++ x_1) ∧ Q y ∧ xs = x_1 ++ y
175+
guard_target = ∃ x_1 y, P x_1 ∧ Q y ∧ [x] ++ xs = x_1 ++ y
176+
match e with
177+
| Exists.intro ps (Exists.intro qs (And.intro hp (And.intro hq hs))) =>
178+
guard_hyp hp: P ([x] ++ ps)
179+
guard_hyp hq: Q qs
180+
guard_hyp hs: xs = ps ++ qs
181+
rw [hs]
182+
guard_target = ∃ x_1 y, P x_1 ∧ Q y ∧ [x] ++ (ps ++ qs) = x_1 ++ y
183+
exact Exists.intro ([x] ++ ps) (Exists.intro qs (And.intro hp (And.intro hq rfl)))
184+
| Or.inr e =>
185+
guard_hyp e : P [] ∧ Q ([x] ++ xs)
186+
guard_target = ∃ x_1 y, P x_1 ∧ Q y ∧ [x] ++ xs = x_1 ++ y
187+
match e with
188+
| And.intro hp hq =>
189+
exact Exists.intro [] (Exists.intro (x :: xs) (And.intro hp (And.intro hq rfl)))
210190

211191
def derive_star {α: Type} {a: α} {P: Lang α} {w: List α}:
212192
(derive (star P) a) w <-> (concat (derive P a) (star P)) w := by

0 commit comments

Comments
 (0)