1
1
-- A translation to Lean from Agda
2
2
-- https://github.com/conal/paper-2021-language-derivatives/blob/main/Calculus.lagda
3
3
4
- import Katydid.Std.Tipe
5
4
import Katydid.Conal.LanguageNotation
6
- import Katydid.Std.TDecidable
5
+ import Mathlib.Logic.Equiv.Defs -- ≃
7
6
open Lang
8
- open TDecidable
7
+ open List
8
+ open Char
9
+ open String
9
10
10
11
-- Print Parse
11
- set_option pp.all true
12
+ -- set_option pp.all true
12
13
open List
13
- def a_or_b := ({ 'a' } ⋃ { 'b' } )
14
+ def a_or_b := (char 'a' ⋃ char 'b' )
14
15
#print a_or_b
15
- def a_or_b_parse_a := a_or_b [ 'a' ]
16
+ def a_or_b_parse_a := a_or_b (toList "a" )
16
17
-- #eval a_or_b_parse_a
17
18
18
- def p : a_or_b [ 'a' ] -> Nat := by
19
+ def p : a_or_b (toList "a" ) -> Nat := by
19
20
intro x
20
21
cases x with
21
22
| inl xa =>
22
23
cases xa with
23
- | refl => exact 0
24
+ | mk eq =>
25
+ cases eq with
26
+ | refl =>
27
+ exact 0
24
28
| inr xb =>
25
- contradiction
29
+ cases xb with
30
+ | mk eq =>
31
+ contradiction
26
32
27
33
-- ν⇃ : Lang → Set ℓ -- “nullable”
28
34
-- ν⇃ P = P []
@@ -42,6 +48,7 @@ theorem nullable_emptySet:
42
48
∀ (α: Type ),
43
49
@ν α ∅ ≡ PEmpty := by
44
50
intro α
51
+ constructor
45
52
rfl
46
53
47
54
-- ν𝒰 : ν 𝒰 ≡ ⊤
@@ -50,6 +57,7 @@ theorem nullable_universal:
50
57
∀ (α: Type ),
51
58
@ν α 𝒰 ≡ PUnit := by
52
59
intro α
60
+ constructor
53
61
rfl
54
62
55
63
-- ν𝟏 : ν 𝟏 ↔ ⊤
@@ -60,39 +68,41 @@ theorem nullable_universal:
60
68
-- (λ { refl → refl })
61
69
theorem nullable_emptyStr :
62
70
∀ (α: Type ),
63
- @ν α ε ↔ PUnit := by
71
+ @ν α ε ≃ PUnit := by
64
72
intro α
65
- refine Tiso.intro ?a ?b ?c ?d
66
- intro
73
+ refine Equiv.mk ?a ?b ?c ?d
74
+ intro _
67
75
exact PUnit.unit
68
- intro
69
- exact trifle
70
- intro
71
- exact trifle
76
+ intro _
77
+ constructor
78
+ rfl
79
+ intro c
80
+ simp
81
+ constructor
82
+ intro _
72
83
simp
73
- intro x
74
- cases x with
75
- | _ => exact trifle
76
84
77
85
theorem nullable_emptyStr' :
78
86
∀ (α: Type ),
79
- @ν α ε ↔ PUnit :=
80
- fun _ => Tiso.intro
87
+ @ν α ε ≃ PUnit :=
88
+ fun _ => Equiv.mk
81
89
(fun _ => PUnit.unit)
82
- (fun _ => trifle )
90
+ (fun _ => by constructor; rfl )
83
91
(sorry )
84
92
(sorry )
85
93
86
94
-- ν` : ν (` c) ↔ ⊥
87
95
-- ν` = mk↔′ (λ ()) (λ ()) (λ ()) (λ ())
88
96
theorem nullable_char :
89
97
∀ (c: α),
90
- ν (char c) ↔ PEmpty := by
98
+ ν (char c) ≃ PEmpty := by
91
99
intro α
92
100
simp
93
- apply Tiso.intro
94
- intro
95
- contradiction
101
+ apply Equiv.mk
102
+ intro x
103
+ cases x with
104
+ | mk x =>
105
+ contradiction
96
106
intro
97
107
contradiction
98
108
sorry
@@ -104,42 +114,20 @@ theorem nullable_char':
104
114
intro
105
115
refine (fun x => ?c)
106
116
simp at x
107
- contradiction
117
+ cases x with
118
+ | mk x =>
119
+ contradiction
108
120
109
121
-- set_option pp.all true
110
122
-- #print nullable_char'
111
123
112
- theorem t : 1 ≡ 2 -> False := by
113
- intro
114
- contradiction
115
-
116
- theorem t'' : 1 = 2 -> False := by
117
- intro
118
- contradiction
119
-
120
- theorem t''' : 1 = 2 → False :=
121
- fun a => absurd a (of_decide_eq_false (Eq.refl (decide (1 = 2 ))))
122
-
123
- theorem t' : 1 ≡ 2 → False :=
124
- fun a =>
125
- (TEq.casesOn (motive := fun a_1 x => 2 = a_1 → HEq a x → False) a
126
- (fun h => Nat.noConfusion h fun n_eq => Nat.noConfusion n_eq) (Eq.refl 2 ) (HEq.refl a)).elim
127
-
128
- theorem nullable_char'''. {u_2, u_1} : {α : Type u_1} → (c : α) → ν.{u_1} (Lang.char.{u_1} c) → PEmpty.{u_2} :=
129
- fun {α : Type u_1} (c : α) (x : ν.{u_1} (Lang.char.{u_1} c)) =>
130
- False.elim.{u_2}
131
- (False.elim.{0 }
132
- (TEq.casesOn.{0 , u_1} (motive := fun (a : List.{u_1} α) (x_1 : TEq.{u_1} List.nil.{u_1} a) =>
133
- Eq.{u_1 + 1 } (List.cons.{u_1} c List.nil.{u_1}) a → HEq.{u_1 + 1 } x x_1 → False) x
134
- (fun (h : Eq.{u_1 + 1 } (List.cons.{u_1} c List.nil.{u_1}) List.nil.{u_1}) => List.noConfusion.{0 , u_1} h)
135
- (Eq.refl.{u_1 + 1 } (List.cons.{u_1} c List.nil.{u_1})) (HEq.refl.{u_1 + 1 } x)))
136
-
137
124
-- ν∪ : ν (P ∪ Q) ≡ (ν P ⊎ ν Q)
138
125
-- ν∪ = refl
139
126
theorem nullable_or :
140
127
∀ (P Q: Lang α),
141
128
ν (P ⋃ Q) ≡ (Sum (ν P) (ν Q)) := by
142
129
intro P Q
130
+ constructor
143
131
rfl
144
132
145
133
-- ν∩ : ν (P ∩ Q) ≡ (ν P × ν Q)
@@ -148,6 +136,7 @@ theorem nullable_and:
148
136
∀ (P Q: Lang α),
149
137
ν (P ⋂ Q) ≡ (Prod (ν P) (ν Q)) := by
150
138
intro P Q
139
+ constructor
151
140
rfl
152
141
153
142
-- ν· : ν (s · P) ≡ (s × ν P)
@@ -156,6 +145,7 @@ theorem nullable_scalar:
156
145
∀ (s: Type ) (P: Lang α),
157
146
ν (Lang.scalar s P) ≡ (Prod s (ν P)) := by
158
147
intro P Q
148
+ constructor
159
149
rfl
160
150
161
151
-- ν⋆ : ν (P ⋆ Q) ↔ (ν P × ν Q)
@@ -166,7 +156,7 @@ theorem nullable_scalar:
166
156
-- (λ { (([] , []) , refl , νP , νQ) → refl})
167
157
theorem nullable_concat :
168
158
∀ (P Q: Lang α),
169
- ν (P, Q) ↔ (Prod (ν Q) (ν P)) := by
159
+ ν (P, Q) ≃ (Prod (ν Q) (ν P)) := by
170
160
-- TODO
171
161
sorry
172
162
@@ -200,7 +190,7 @@ theorem nullable_concat:
200
190
-- ∎ where open ↔R
201
191
theorem nullable_star :
202
192
∀ (P: Lang α),
203
- ν (P *) ↔ List (ν P) := by
193
+ ν (P *) ≃ List (ν P) := by
204
194
-- TODO
205
195
sorry
206
196
@@ -210,6 +200,7 @@ theorem derivative_emptySet:
210
200
∀ (a: α),
211
201
(δ ∅ a) ≡ ∅ := by
212
202
intro a
203
+ constructor
213
204
rfl
214
205
215
206
-- δ𝒰 : δ 𝒰 a ≡ 𝒰
@@ -218,6 +209,7 @@ theorem derivative_universal:
218
209
∀ (a: α),
219
210
(δ 𝒰 a) ≡ 𝒰 := by
220
211
intro a
212
+ constructor
221
213
rfl
222
214
223
215
-- δ𝟏 : δ 𝟏 a ⟷ ∅
@@ -252,6 +244,7 @@ theorem derivative_or:
252
244
∀ (a: α) (P Q: Lang α),
253
245
(δ (P ⋃ Q) a) ≡ ((δ P a) ⋃ (δ Q a)) := by
254
246
intro a P Q
247
+ constructor
255
248
rfl
256
249
257
250
-- δ∩ : δ (P ∩ Q) a ≡ δ P a ∩ δ Q a
@@ -260,6 +253,7 @@ theorem derivative_and:
260
253
∀ (a: α) (P Q: Lang α),
261
254
(δ (P ⋂ Q) a) ≡ ((δ P a) ⋂ (δ Q a)) := by
262
255
intro a P Q
256
+ constructor
263
257
rfl
264
258
265
259
-- δ· : δ (s · P) a ≡ s · δ P a
@@ -268,6 +262,7 @@ theorem derivative_scalar:
268
262
∀ (a: α) (s: Type ) (P: Lang α),
269
263
(δ (Lang.scalar s P) a) ≡ (Lang.scalar s (δ P a)) := by
270
264
intro a s P
265
+ constructor
271
266
rfl
272
267
273
268
-- δ⋆ : δ (P ⋆ Q) a ⟷ ν P · δ Q a ∪ δ P a ⋆ Q
0 commit comments