Theory Messages
section ‹Protocol Messages as (First-Order) Terms›
theory Messages
imports Miscellaneous "First_Order_Terms.Term"
begin
subsection ‹Term-related definitions: subterms and free variables›
abbreviation "the_Fun ≡ un_Fun1"
lemmas the_Fun_def = un_Fun1_def
fun subterms::"('a,'b) term ⇒ ('a,'b) terms" where
"subterms (Var x) = {Var x}"
| "subterms (Fun f T) = {Fun f T} ∪ (⋃t ∈ set T. subterms t)"
abbreviation subtermeq (infix ‹⊑› 50) where "t' ⊑ t ≡ (t' ∈ subterms t)"
abbreviation subterm (infix ‹⊏› 50) where "t' ⊏ t ≡ (t' ⊑ t ∧ t' ≠ t)"
abbreviation "subterms⇩s⇩e⇩t M ≡ ⋃(subterms ` M)"
abbreviation subtermeqset (infix ‹⊑⇩s⇩e⇩t› 50) where "t ⊑⇩s⇩e⇩t M ≡ (t ∈ subterms⇩s⇩e⇩t M)"
abbreviation fv where "fv ≡ vars_term"
lemmas fv_simps = term.simps(17,18)
fun fv⇩s⇩e⇩t where "fv⇩s⇩e⇩t M = ⋃(fv ` M)"
abbreviation fv⇩p⇩a⇩i⇩r where "fv⇩p⇩a⇩i⇩r p ≡ case p of (t,t') ⇒ fv t ∪ fv t'"
fun fv⇩p⇩a⇩i⇩r⇩s where "fv⇩p⇩a⇩i⇩r⇩s F = ⋃(fv⇩p⇩a⇩i⇩r ` set F)"
abbreviation ground where "ground M ≡ fv⇩s⇩e⇩t M = {}"
subsection ‹Variants that return lists insteads of sets›
fun fv_list where
"fv_list (Var x) = [x]"
| "fv_list (Fun f T) = concat (map fv_list T)"
definition fv_list⇩p⇩a⇩i⇩r⇩s where
"fv_list⇩p⇩a⇩i⇩r⇩s F ≡ concat (map (λ(t,t'). fv_list t@fv_list t') F)"
fun subterms_list::"('a,'b) term ⇒ ('a,'b) term list" where
"subterms_list (Var x) = [Var x]"
| "subterms_list (Fun f T) = remdups (Fun f T#concat (map subterms_list T))"
lemma fv_list_is_fv: "fv t = set (fv_list t)"
by (induct t) auto
lemma fv_list⇩p⇩a⇩i⇩r⇩s_is_fv⇩p⇩a⇩i⇩r⇩s: "fv⇩p⇩a⇩i⇩r⇩s F = set (fv_list⇩p⇩a⇩i⇩r⇩s F)"
by (induct F) (auto simp add: fv_list_is_fv fv_list⇩p⇩a⇩i⇩r⇩s_def)
lemma subterms_list_is_subterms: "subterms t = set (subterms_list t)"
by (induct t) auto
subsection ‹The subterm relation defined as a function›
fun subterm_of where
"subterm_of t (Var y) = (t = Var y)"
| "subterm_of t (Fun f T) = (t = Fun f T ∨ list_ex (subterm_of t) T)"
lemma subterm_of_iff_subtermeq[code_unfold]: "t ⊑ t' = subterm_of t t'"
proof (induction t')
case (Fun f T) thus ?case
proof (cases "t = Fun f T")
case False thus ?thesis
using Fun.IH subterm_of.simps(2)[of t f T]
unfolding list_ex_iff by fastforce
qed simp
qed simp
lemma subterm_of_ex_set_iff_subtermeqset[code_unfold]: "t ⊑⇩s⇩e⇩t M = (∃t' ∈ M. subterm_of t t')"
using subterm_of_iff_subtermeq by blast
subsection ‹The subterm relation is a partial order on terms›