Skip to content

Commit 21c96ec

Browse files
prove derive_concat
1 parent 4468363 commit 21c96ec

File tree

2 files changed

+75
-5
lines changed

2 files changed

+75
-5
lines changed

Katydid/Regex/Calculus.lean

+66-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
-- Originally based on https://github.com/conal/paper-2021-language-derivatives/blob/main/Calculus.lagda
22

33
import Katydid.Regex.Language
4+
import Katydid.Std.Balistic
45

56
namespace Calculus
67

@@ -138,13 +139,74 @@ def derive_scalar {α: Type} {a: α} {s: Prop} {P: Lang α}:
138139
(derive (scalar s P) a) = (scalar s (derive P a)) :=
139140
rfl
140141

141-
def derive_concat {α: Type} {a: α} {P Q: Lang α} {w: List α}:
142-
(derive (concat P Q) a) w <-> (or (concat (derive P a) Q) (scalar (null P) (derive Q a))) w := by
142+
def derive_concat {α: Type} {x: α} {P Q: Lang α} {xs: List α}:
143+
(derive (concat P Q) x) xs <->
144+
(or (concat (derive P x) Q) (scalar (null P) (derive Q x))) xs := by
143145
refine Iff.intro ?toFun ?invFun
144146
case toFun =>
145-
sorry
147+
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
163+
balistic
164+
· guard_hyp hp: P []
165+
guard_hyp hq: Q (x :: xs)
166+
right
167+
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'
146174
case invFun =>
147-
sorry
175+
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)
148210

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

Katydid/Std/Balistic.lean

+9-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,15 @@ local elab "list_app_uncons" : tactic => newTactic do
328328
run `(tactic| cases $name:ident <;> rename_i $name:ident)
329329
run `(tactic| any_goals wreck_exists)
330330
run `(tactic| try all_goals wreck_conj)
331-
run `(tactic| all_goals simp [*])
331+
run `(tactic| try all_goals simp [*])
332+
return true
333+
| ~q($x :: $xs = $ys ++ $zs) =>
334+
applyIn name `(symm)
335+
applyIn name `(list_app_uncons)
336+
run `(tactic| cases $name:ident <;> rename_i $name:ident)
337+
run `(tactic| any_goals wreck_exists)
338+
run `(tactic| try all_goals wreck_conj)
339+
run `(tactic| try all_goals simp [*])
332340
return true
333341
| _ =>
334342
return false

0 commit comments

Comments
 (0)