Commit 21c96ec 1 parent 4468363 commit 21c96ec Copy full SHA for 21c96ec
File tree 2 files changed +75
-5
lines changed
2 files changed +75
-5
lines changed Original file line number Diff line number Diff line change 1
1
-- Originally based on https://github.com/conal/paper-2021-language-derivatives/blob/main/Calculus.lagda
2
2
3
3
import Katydid.Regex.Language
4
+ import Katydid.Std.Balistic
4
5
5
6
namespace Calculus
6
7
@@ -138,13 +139,74 @@ def derive_scalar {α: Type} {a: α} {s: Prop} {P: Lang α}:
138
139
(derive (scalar s P) a) = (scalar s (derive P a)) :=
139
140
rfl
140
141
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
143
145
refine Iff.intro ?toFun ?invFun
144
146
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'
146
174
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)
148
210
149
211
def derive_star {α: Type } {a: α} {P: Lang α} {w: List α}:
150
212
(derive (star P) a) w <-> (concat (derive P a) (star P)) w := by
Original file line number Diff line number Diff line change @@ -328,7 +328,15 @@ local elab "list_app_uncons" : tactic => newTactic do
328
328
run `(tactic| cases $name:ident <;> rename_i $name:ident)
329
329
run `(tactic| any_goals wreck_exists)
330
330
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 [*])
332
340
return true
333
341
| _ =>
334
342
return false
You can’t perform that action at this time.
0 commit comments