@@ -3,7 +3,7 @@ import Validator.Std.List
33import Validator.Regex.Regex
44import Validator.Hedge.Grammar
55
6- namespace Hedge.Elem
6+ namespace Hedge.Grammar. Elem
77
88theorem decreasing_or_l {α: Type } {σ: Type } [SizeOf σ] (r1 r2: Regex σ) (xs: Hedge α):
99 Prod.Lex
@@ -148,11 +148,9 @@ def lift_symbol {x: Hedge.Node α}
148148 simp_all only [List.mem_flatMap, List.mem_cons, or_true]
149149 )
150150
151- -- denote_elem is an alternative version of Regex.denote that is later proven to be equivalent definitions.
152- -- The difference is that the denote_symbol function now has a relationship with the original input list, List.InfixOf.
153- -- This relationship is used for proving termination of regular expressions on trees.
151+ -- Hedge.Elem.Rule.denote_elem is an alternative version of Hedge.Grammar.Rule.denote.
154152-- The only other changes is that denote_elem contains unfolded versions of Language.or, Language.concat_n and Language.star_n.
155- def denote_elem
153+ def Rule. denote_elem
156154 {α: Type } {φ: Type }
157155 (G: Hedge.Grammar n φ)
158156 (r: Hedge.Grammar.Rule n φ) (xs: Hedge α)
@@ -189,3 +187,117 @@ def denote_elem
189187 · apply denote_elem_sizeOf_concat_right
190188 · apply denote_elem_sizeOf_star_left
191189 · apply denote_elem_sizeOf_star_right
190+
191+ def Rule.denote {α: Type } {φ: Type }
192+ (G: Hedge.Grammar n φ) (Φ: φ -> α -> Prop )
193+ (r: Hedge.Grammar.Rule n φ) (xs: Hedge α): Prop :=
194+ Rule.denote_elem G r xs (fun p x' => Φ p x'.val)
195+
196+ theorem denote_emptyset {α: Type } {φ: Type } (G: Hedge.Grammar n φ) (Φ: φ -> α -> Prop ):
197+ Rule.denote G Φ Regex.emptyset = Regex.Language.emptyset := by
198+ unfold Rule.denote
199+ simp only [Rule.denote_elem]
200+
201+ theorem denote_emptystr {α: Type } {φ: Type } (G: Hedge.Grammar n φ) (Φ: φ -> α -> Prop ):
202+ Rule.denote G Φ Regex.emptystr = Regex.Language.emptystr := by
203+ unfold Rule.denote
204+ simp only [Rule.denote_elem]
205+
206+ theorem denote_symbol {α: Type } {φ: Type } (G: Hedge.Grammar n φ) (Φ: φ -> α -> Prop ) [DecidableRel Φ] (s: Symbol n φ):
207+ Rule.denote G Φ (Regex.symbol s) = Hedge.Language.tree (fun a => Φ s.1 a) (Rule.denote G Φ (G.lookup s.2 )) := by
208+ unfold Rule.denote
209+ unfold Hedge.Language.tree
210+ funext xs
211+ simp only
212+ cases xs with
213+ | nil =>
214+ rw [Rule.denote_elem]
215+ simp only [List.ne_cons_self, decide_eq_true_eq, false_and, exists_const, exists_false]
216+ intro x Φ h
217+ contradiction
218+ | cons x xs =>
219+ cases xs with
220+ | nil =>
221+ rw [Rule.denote_elem]
222+ simp only [List.cons.injEq, and_true, decide_eq_true_eq]
223+ cases x with
224+ | mk label children =>
225+ simp only [Node.mk.injEq, ↓existsAndEq, and_true, exists_eq_left']
226+ simp only [LabelIn.self, Node.getLabel]
227+ simp_all only [eq_iff_iff, and_congr_right_iff]
228+ intro a
229+ obtain ⟨fst, snd⟩ := s
230+ simp_all only
231+ rfl
232+ | cons x' xs =>
233+ rw [Rule.denote_elem]
234+ simp
235+ intro x Φ h
236+ simp at h
237+
238+ theorem denote_or {α: Type } {φ: Type } (G: Hedge.Grammar n φ) (Φ: φ -> α -> Prop ) (r1 r2: Rule n φ):
239+ Rule.denote G Φ (Regex.or r1 r2) = Regex.Language.or (Rule.denote G Φ r1) (Rule.denote G Φ r2) := by
240+ unfold Rule.denote
241+ funext
242+ simp only [Rule.denote_elem, Regex.Language.or]
243+
244+ theorem denote_concat_n {α: Type } {φ: Type } (G: Hedge.Grammar n φ) (Φ: φ -> α -> Prop ) (p q: Rule n φ):
245+ Rule.denote G Φ (Regex.concat p q) = Regex.Language.concat_n (Rule.denote G Φ p) (Rule.denote G Φ q) := by
246+ unfold Rule.denote
247+ funext
248+ simp only [Rule.denote_elem]
249+ unfold Regex.Language.concat_n
250+ rfl
251+
252+ theorem unfold_denote_elem_star_n {α: Type } {φ: Type } (G: Hedge.Grammar n φ) (Φ: φ -> α -> Prop ) (r: Rule n φ) (xs: Hedge α):
253+ Rule.denote_elem G (Regex.star r) xs (fun p x' => Φ p x'.val)
254+ = (match xs with
255+ | [] => True
256+ | (x'::xs') =>
257+ ∃ (n: Fin xs.length),
258+ (Rule.denote_elem G r (List.take (n + 1 ) (x'::xs')) (denote_symbol_lift_take (n + 1 ) (fun p x' => Φ p x'.val)))
259+ /\ (Rule.denote_elem G (Regex.star r) (List.drop (n + 1 ) (x'::xs')) (denote_symbol_lift_drop (n + 1 ) (fun p x' => Φ p x'.val)))) := by
260+ cases xs with
261+ | nil =>
262+ simp [Rule.denote_elem]
263+ | cons x xs =>
264+ cases xs with
265+ | cons _ _ =>
266+ simp only [Rule.denote_elem]
267+ | nil =>
268+ simp only [Rule.denote_elem]
269+
270+ theorem denote_elem_star_n_iff {α: Type } {φ: Type } (G: Hedge.Grammar n φ) (Φ: φ -> α -> Prop ) (r: Rule n φ) (xs: Hedge α):
271+ Rule.denote_elem G (Regex.star r) xs (fun p x' => Φ p x'.val) <-> Regex.Language.star_n (fun xs' => Rule.denote_elem G r xs' (fun p x' => Φ p x'.val)) xs := by
272+ rw [<- eq_iff_iff]
273+ unfold Regex.Language.star_n
274+ rw [unfold_denote_elem_star_n]
275+ cases xs with
276+ | nil =>
277+ rfl
278+ | cons x xs =>
279+ simp only
280+ congr
281+ ext n
282+ rw [<- eq_iff_iff]
283+ unfold denote_symbol_lift_take
284+ unfold denote_symbol_lift_drop
285+ congr
286+ simp only
287+ simp only [LabelIn.mk]
288+ simp only [List.length_cons, List.drop_succ_cons, eq_iff_iff]
289+ rw [<- denote_elem_star_n_iff]
290+ termination_by xs.length
291+ decreasing_by
292+ obtain ⟨n, hn⟩ := n
293+ apply List.list_length_drop_lt_cons
294+
295+ theorem denote_star_n_iff {α: Type } {φ: Type } (G: Hedge.Grammar n φ) (Φ: φ -> α -> Prop ) (r: Rule n φ) (xs: Hedge α):
296+ Rule.denote G Φ (Regex.star r) xs <-> Regex.Language.star_n (Rule.denote G Φ r) xs := by
297+ unfold Rule.denote
298+ rw [denote_elem_star_n_iff]
299+
300+ theorem denote_star_n {α: Type } {φ: Type } (G: Hedge.Grammar n φ) (Φ: φ -> α -> Prop ) (r: Rule n φ):
301+ Rule.denote G Φ (Regex.star r) = Regex.Language.star_n (Rule.denote G Φ r) := by
302+ funext
303+ rw [denote_star_n_iff]
0 commit comments