@@ -16,42 +16,42 @@ import Validator.Expr.Language
1616-- n = the number of non-terminals
1717abbrev Ref (n: Nat) := Fin n -- non-terminal
1818
19- abbrev Rule (n: Nat) (α: Type ) (Φ: (α: Type ) -> Type ) :=
20- Regex (Φ α × Ref n)
19+ abbrev Rule (n: Nat) (Φ: Type ) :=
20+ Regex (Φ × Ref n)
2121
22- abbrev Rules (n: Nat) (α: Type ) (Φ: (α: Type ) -> Type ) (l: Nat) :=
23- List.Vector (Rule n α Φ) l
22+ abbrev Rules (n: Nat) (Φ: Type ) (l: Nat) :=
23+ List.Vector (Rule n Φ) l
2424
2525def hashVector [Hashable α] (xs: List.Vector α n): UInt64 :=
2626 hash xs.toList
2727
2828instance (α: Type ) (n: Nat) [Hashable α] : Hashable (List.Vector α n) where
2929 hash := hashVector
3030
31- def hashRules {n: Nat} {α: Type } { Φ: (α: Type ) -> Type } {l: Nat} [Hashable α] [Hashable (Φ α) ] (xs: Rules n α Φ l): UInt64 :=
31+ def hashRules {n: Nat} {Φ: Type } {l: Nat} [Hashable Φ ] (xs: Rules n Φ l): UInt64 :=
3232 hash xs.toList
3333
34- instance (n: Nat) (α: Type ) ( Φ: (α: Type ) -> Type ) (l: Nat) [Hashable α] [Hashable (Φ α) ] : Hashable (Rules n α Φ l) where
34+ instance (n: Nat) (Φ: Type ) (l: Nat) [Hashable Φ ] : Hashable (Rules n Φ l) where
3535 hash := hashRules
3636
37- structure Grammar (n: Nat) (α: Type ) (Φ: (α: Type ) -> Type ) where
38- start: Rule n α Φ
39- prods: Vector (Rule n α Φ) n
37+ structure Grammar (n: Nat) (Φ: Type ) where
38+ start: Rule n Φ
39+ prods: Vector (Rule n Φ) n
4040
41- def Grammar.lookup {n: Nat} {α: Type } {Φ: (α: Type ) -> Type }
42- (g: Grammar n α Φ) (ref: Fin n): Rule n α Φ :=
41+ def Grammar.lookup {n: Nat} {Φ: Type }
42+ (g: Grammar n Φ) (ref: Fin n): Rule n Φ :=
4343 Vector.get g.prods ref
4444
45- def Grammar.singleton (x: Rule 0 α Φ): Grammar 0 α Φ :=
45+ def Grammar.singleton (x: Rule 0 Φ): Grammar 0 Φ :=
4646 Grammar.mk x #v[]
4747
48- def Grammar.emptyset : Grammar 0 α Φ :=
48+ def Grammar.emptyset : Grammar 0 Φ :=
4949 Grammar.mk Regex.emptyset #v[]
5050
51- def Grammar.emptystr : Grammar 0 α Φ :=
51+ def Grammar.emptystr : Grammar 0 Φ :=
5252 Grammar.mk Regex.emptystr #v[]
5353
54- example : Grammar 5 String Pred := Grammar.mk
54+ example : Grammar 5 ( Pred String) := Grammar.mk
5555 -- start := ("html", Html)
5656 (start := Regex.symbol (Pred.eq "html" , 0 ))
5757 -- production rules
@@ -72,7 +72,7 @@ example : Grammar 5 String Pred := Grammar.mk
7272 , Regex.emptystr
7373 ])
7474
75- def example_grammar : Grammar 1 Char Pred :=
75+ def example_grammar : Grammar 1 ( Pred Char) :=
7676 Grammar.mk
7777 (Regex.or Regex.emptystr (Regex.symbol (Pred.eq 'a' , 0 )))
7878 #v[Regex.emptystr]
@@ -91,7 +91,7 @@ theorem Rule.denote_decreasing {x: Hedge.Node α} {xs: Hedge α} (h: List.IsInfi
9191 simp +arith only at h
9292 omega
9393
94- def Rule.denote {α: Type } [BEq α] (g: Grammar n α Pred) (r: Rule n α Pred) (xs: Hedge α): Prop :=
94+ def Rule.denote {α: Type } [BEq α] (g: Grammar n ( Pred α)) (r: Rule n ( Pred α) ) (xs: Hedge α): Prop :=
9595 Regex.denote_infix r xs (fun (pred, ref) xs' =>
9696 match xs' with
9797 | Subtype.mk [x] _hx =>
@@ -102,10 +102,10 @@ def Rule.denote {α: Type} [BEq α] (g: Grammar n α Pred) (r: Rule n α Pred) (
102102 termination_by xs
103103 decreasing_by exact (Rule.denote_decreasing _hx)
104104
105- def Grammar.denote {α: Type } [BEq α] (g: Grammar n α Pred) (xs: Hedge α): Prop :=
105+ def Grammar.denote {α: Type } [BEq α] (g: Grammar n ( Pred α) ) (xs: Hedge α): Prop :=
106106 Rule.denote g g.start xs
107107
108- theorem simp_denote_rule' {α: Type } [BEq α] (g: Grammar n α Pred) (r: Rule n α Pred) (xs: Hedge α):
108+ theorem simp_denote_rule' {α: Type } [BEq α] (g: Grammar n ( Pred α)) (r: Rule n ( Pred α) ) (xs: Hedge α):
109109 (Regex.denote_infix r xs (fun (pred, ref) xs' =>
110110 match xs' with
111111 | Subtype.mk [x] _hx =>
@@ -133,7 +133,7 @@ theorem simp_denote_rule' {α: Type} [BEq α] (g: Grammar n α Pred) (r: Rule n
133133 | nil =>
134134 simp
135135
136- theorem simp_denote_rule {α: Type } [BEq α] (g: Grammar n α Pred) (r: Rule n α Pred) (xs: Hedge α):
136+ theorem simp_denote_rule {α: Type } [BEq α] (g: Grammar n ( Pred α)) (r: Rule n ( Pred α) ) (xs: Hedge α):
137137 Rule.denote g r xs =
138138 Regex.denote_infix r xs (fun (pred, ref) xs' =>
139139 ∃ label children, xs'.val = [Hedge.Node.mk label children] /\ Pred.eval pred label /\ Rule.denote g (g.lookup ref) children
@@ -156,22 +156,22 @@ theorem simp_denote_rule {α: Type} [BEq α] (g: Grammar n α Pred) (r: Rule n
156156 obtain ⟨label, children, hxs, h⟩ := h
157157 exists Hedge.Node.mk label children
158158
159- theorem Rule.denote_emptyset {α: Type } [BEq α] {g: Grammar n α Pred}:
159+ theorem Rule.denote_emptyset {α: Type } [BEq α] {g: Grammar n ( Pred α) }:
160160 Rule.denote g Regex.emptyset = Language.emptyset := by
161161 unfold Language.emptyset
162162 funext xs
163163 unfold Rule.denote
164164 simp [Regex.denote_infix_emptyset]
165165
166- theorem Rule.denote_emptystr {α: Type } [BEq α] {g: Grammar n α Pred}:
166+ theorem Rule.denote_emptystr {α: Type } [BEq α] {g: Grammar n ( Pred α) }:
167167 Rule.denote g Regex.emptystr = Language.emptystr := by
168168 unfold Language.emptystr
169169 funext xs
170170 unfold Rule.denote
171171 simp [Regex.denote_infix_emptystr]
172172
173173theorem denote_rule_symbol' {n: Nat} {α: Type } [BEq α]
174- {g: Grammar n α Pred} {pred: Pred α} {ref: Ref n} {xs: Hedge α}:
174+ {g: Grammar n ( Pred α) } {pred: Pred α} {ref: Ref n} {xs: Hedge α}:
175175 Rule.denote g (Regex.symbol (pred, ref)) xs
176176 <-> Language.tree (Pred.eval pred) (Rule.denote g (g.lookup ref)) xs := by
177177 cases xs with
@@ -218,14 +218,14 @@ theorem denote_rule_symbol' {n: Nat} {α: Type} [BEq α]
218218 apply And.intro hp hg
219219
220220theorem Rule.denote_symbol {n: Nat} {α: Type } [BEq α]
221- {g: Grammar n α Pred} {pred: Pred α} {ref: Ref n}:
221+ {g: Grammar n ( Pred α) } {pred: Pred α} {ref: Ref n}:
222222 Rule.denote g (Regex.symbol (pred, ref))
223223 = Language.tree (Pred.eval pred) (Rule.denote g (g.lookup ref)) := by
224224 funext xs
225225 rw [denote_rule_symbol']
226226
227227theorem Rule.denote_or {n: Nat} {α: Type } [BEq α]
228- {g: Grammar n α Pred} {p q: Rule n α Pred}:
228+ {g: Grammar n ( Pred α) } {p q: Rule n ( Pred α) }:
229229 Rule.denote g (Regex.or p q)
230230 = Language.or (Rule.denote g p) (Rule.denote g q) := by
231231 funext xs
@@ -234,7 +234,7 @@ theorem Rule.denote_or {n: Nat} {α: Type} [BEq α]
234234 simp [Regex.denote_infix_or]
235235
236236theorem Rule.denote_concat_n {n: Nat} {α: Type } [BEq α]
237- {g: Grammar n α Pred} {p q: Rule n α Pred}:
237+ {g: Grammar n ( Pred α) } {p q: Rule n ( Pred α) }:
238238 Rule.denote g (Regex.concat p q)
239239 = Language.concat_n (Rule.denote g p) (Rule.denote g q) := by
240240 funext xs
@@ -279,15 +279,15 @@ theorem Rule.denote_concat_n {n: Nat} {α: Type} [BEq α]
279279 simp
280280
281281theorem Rule.denote_concat {n: Nat} {α: Type } [BEq α]
282- {g: Grammar n α Pred} {p q: Rule n α Pred}:
282+ {g: Grammar n ( Pred α) } {p q: Rule n ( Pred α) }:
283283 Rule.denote g (Regex.concat p q)
284284 = Language.concat (Rule.denote g p) (Rule.denote g q) := by
285285 rw [Rule.denote_concat_n]
286286 funext xs
287287 rw [Language.concat_is_concat_n]
288288
289289theorem denote_rule_star_n' {n: Nat} {α: Type } [BEq α]
290- {g: Grammar n α Pred} {r: Rule n α Pred} (xs: Hedge α):
290+ {g: Grammar n ( Pred α) } {r: Rule n ( Pred α) } (xs: Hedge α):
291291 Rule.denote g (Regex.star r) xs
292292 <->
293293 Language.star_n (Rule.denote g r) xs := by
@@ -349,23 +349,23 @@ theorem denote_rule_star_n' {n: Nat} {α: Type} [BEq α]
349349 apply List.list_length_drop_lt_cons
350350
351351theorem Rule.denote_star_n {n: Nat} {α: Type } [BEq α]
352- {g: Grammar n α Pred} {r: Rule n α Pred}:
352+ {g: Grammar n ( Pred α) } {r: Rule n ( Pred α) }:
353353 Rule.denote g (Regex.star r)
354354 =
355355 Language.star_n (Rule.denote g r) := by
356356 funext xs
357357 rw [denote_rule_star_n']
358358
359359theorem Rule.denote_star {n: Nat} {α: Type } [BEq α]
360- {g: Grammar n α Pred} {r: Rule n α Pred}:
360+ {g: Grammar n ( Pred α) } {r: Rule n ( Pred α) }:
361361 Rule.denote g (Regex.star r)
362362 =
363363 Language.star (Rule.denote g r) := by
364364 funext xs
365365 rw [denote_rule_star_n']
366366 rw [Language.star_is_star_n]
367367
368- def Rule.denote_onlyif {α: Type } [BEq α] (condition: Prop ) [dcond: Decidable condition] (g: Grammar n α Pred) (x: Rule n α Pred):
368+ def Rule.denote_onlyif {α: Type } [BEq α] (condition: Prop ) [dcond: Decidable condition] (g: Grammar n ( Pred α)) (x: Rule n ( Pred α) ):
369369 denote g (Regex.onlyif condition x) = Language.onlyif condition (denote g x) := by
370370 unfold Language.onlyif
371371 unfold Regex.onlyif
@@ -382,13 +382,13 @@ def Rule.denote_onlyif {α: Type} [BEq α] (condition: Prop) [dcond: Decidable c
382382 intro hc'
383383 contradiction
384384
385- def Rule.nullable (r: Rule n α Φ): Bool :=
385+ def Rule.nullable (r: Rule n Φ): Bool :=
386386 Regex.nullable r
387387
388- def Grammar.nullable (g: Grammar n α Φ): Bool :=
388+ def Grammar.nullable (g: Grammar n Φ): Bool :=
389389 Rule.nullable g.start
390390
391- theorem Rule.null_commutes {α: Type } [BEq α] (g: Grammar n α Pred) (x: Rule n α Pred):
391+ theorem Rule.null_commutes {α: Type } [BEq α] (g: Grammar n ( Pred α)) (x: Rule n ( Pred α) ):
392392 ((Rule.nullable x) = true ) = Language.null (denote g x) := by
393393 induction x with
394394 | emptyset =>
0 commit comments