Theory Nonground_Term_Typing
theory Nonground_Term_Typing
imports
Term_Typing
Typed_Functional_Substitution
Functional_Substitution_Typing
Nonground_Term
begin
locale base_typed_properties =
explicitly_typed_subst_stability +
explicitly_replaceable_π± +
explicitly_typed_renaming +
explicitly_typed_grounding_functional_substitution
locale base_typing_properties =
base_functional_substitution_typing +
typed: base_typed_properties +
welltyped: base_typed_properties where typed = welltyped
locale base_inhabited_typing_properties =
base_typing_properties +
typed: inhabited_explicitly_typed_functional_substitution +
welltyped: inhabited_explicitly_typed_functional_substitution where typed = welltyped
locale nonground_term_typing =
"term": nonground_term +
fixes β± :: "('f, 'ty) fun_types"
begin
inductive typed :: "('v, 'ty) var_types β ('f,'v) term β 'ty β bool"
for π± where
Var: "π± x = Ο βΉ typed π± (Var x) Ο"
| Fun: "β± f = (Οs, Ο) βΉ typed π± (Fun f ts) Ο"
textβΉNote: Implicitly implies that every function symbol has a fixed arityβΊ
inductive welltyped :: "('v, 'ty) var_types β ('f,'v) term β 'ty β bool"
for π± where
Var: "π± x = Ο βΉ welltyped π± (Var x) Ο"
| Fun: "β± f = (Οs, Ο) βΉ list_all2 (welltyped π±) ts Οs βΉ welltyped π± (Fun f ts) Ο"
sublocale "term": explicit_typing "typed (π± :: ('v, 'ty) var_types)" "welltyped π±"
proof unfold_locales
show "right_unique (typed π±)"
proof (rule right_uniqueI)
fix t Οβ©1 Οβ©2
assume "typed π± t Οβ©1" and "typed π± t Οβ©2"
thus "Οβ©1 = Οβ©2"
by (auto elim!: typed.cases)
qed
next
show "right_unique (welltyped π±)"
proof (rule right_uniqueI)
fix t Οβ©1 Οβ©2
assume "welltyped π± t Οβ©1" and "welltyped π± t Οβ©2"
thus "Οβ©1 = Οβ©2"
by (auto elim!: welltyped.cases)
qed
next
fix t Ο
assume "welltyped π± t Ο"
then show "typed π± t Ο"
by (metis (full_types) typed.simps welltyped.cases)
qed
sublocale "term": term_typing where
typed = "typed (π± :: 'v β 'ty)" and welltyped = "welltyped π±" and Fun = Fun
proof unfold_locales
fix t t' c Ο Ο'
assume
t_type: "welltyped π± t Ο'" and
t'_type: "welltyped π± t' Ο'" and
c_type: "welltyped π± cβ¨tβ© Ο"
from c_type show "welltyped π± cβ¨t'β© Ο"
proof (induction c arbitrary: Ο)
case Hole
then show ?case
using t_type t'_type
by auto
next
case (More f ss1 c ss2)
have "welltyped π± (Fun f (ss1 @ cβ¨tβ© # ss2)) Ο"
using More.prems
by simp
hence "welltyped π± (Fun f (ss1 @ cβ¨t'β© # ss2)) Ο"
proof (cases π± "Fun f (ss1 @ cβ¨tβ© # ss2)" Ο rule: welltyped.cases)
case (Fun Οs)
show ?thesis
proof (rule welltyped.Fun)
show "β± f = (Οs, Ο)"
using βΉβ± f = (Οs, Ο)βΊ .
next
show "list_all2 (welltyped π±) (ss1 @ cβ¨t'β© # ss2) Οs"
using βΉlist_all2 (welltyped π±) (ss1 @ cβ¨tβ© # ss2) ΟsβΊ
using More.IH
by (smt (verit, del_insts) list_all2_Cons1 list_all2_append1 list_all2_lengthD)
qed
qed
thus ?case
by simp
qed
next
fix t t' c Ο Ο'
assume
t_type: "typed π± t Ο'" and
t'_type: "typed π± t' Ο'" and
c_type: "typed π± cβ¨tβ© Ο"
from c_type show "typed π± cβ¨t'β© Ο"
proof (induction c arbitrary: Ο)
case Hole
then show ?case
using t'_type t_type
by auto
next
case (More f ss1 c ss2)
have "typed π± (Fun f (ss1 @ cβ¨tβ© # ss2)) Ο"
using More.prems
by simp
hence "typed π± (Fun f (ss1 @ cβ¨t'β© # ss2)) Ο"
proof (cases π± "Fun f (ss1 @ cβ¨tβ© # ss2)" Ο rule: typed.cases)
case (Fun Οs)
then show ?thesis
by (simp add: typed.simps)
qed
thus ?case
by simp
qed
next
fix f ts Ο
assume "welltyped π± (Fun f ts) Ο"
then show "βtβset ts. term.is_welltyped π± t"
by (cases rule: welltyped.cases) (metis in_set_conv_nth list_all2_conv_all_nth)
next
fix t
show "term.is_typed π± t"
by (metis term.exhaust prod.exhaust typed.simps)
qed
sublocale "term": base_typing_properties where
id_subst = "Var :: 'v β ('f, 'v) term" and comp_subst = "(β)" and subst = "(β
t)" and
vars = term.vars and welltyped = welltyped and typed = typed and to_ground = term.to_ground and
from_ground = term.from_ground
proof(unfold_locales; (intro typed.Var welltyped.Var refl)?)
fix Ο and π± and t :: "('f, 'v) term" and Ο
assume is_typed_on: "βx β term.vars t. typed π± (Ο x) (π± x)"
show "typed π± (t β
t Ο) Ο β· typed π± t Ο"
proof(rule iffI)
assume "typed π± t Ο"
then show "typed π± (t β
t Ο) Ο"
using is_typed_on
by(induction rule: typed.induct)(auto simp: typed.Fun)
next
assume "typed π± (t β
t Ο) Ο"
then show "typed π± t Ο"
using is_typed_on
by(induction t)(auto simp: typed.simps)
qed
next
fix Ο and π± and t :: "('f, 'v) term" and Ο
assume is_welltyped_on: "βx β term.vars t. welltyped π± (Ο x) (π± x)"
show "welltyped π± (t β
t Ο) Ο β· welltyped π± t Ο"
proof(rule iffI)
assume "welltyped π± t Ο"
then show "welltyped π± (t β
t Ο) Ο"
using is_welltyped_on
by(induction rule: welltyped.induct)
(auto simp: list.rel_mono_strong list_all2_map1 welltyped.simps)
next
assume "welltyped π± (t β
t Ο) Ο"
then show "welltyped π± t Ο"
using is_welltyped_on
proof(induction "t β
t Ο" Ο arbitrary: t rule: welltyped.induct)
case (Var x Ο)
then obtain x' where t: "t = Var x'"
by (metis subst_apply_eq_Var)
have "welltyped π± t (π± x')"
unfolding t
by (simp add: welltyped.Var)
moreover have "welltyped π± t (π± x)"
using Var
unfolding t
by (simp add: welltyped.simps)
ultimately have π±_x': "Ο = π± x'"
using Var.hyps
by blast
show ?case
unfolding t π±_x'
by (simp add: welltyped.Var)
next
case (Fun f Οs Ο ts)
then show ?case
by (cases t) (simp_all add: list.rel_mono_strong list_all2_map1 welltyped.simps)
qed
qed
next
fix t :: "('f, 'v) term" and π± π±' Ο
assume "typed π± t Ο" "βxβterm.vars t. π± x = π±' x"
then show "typed π±' t Ο"
by (cases rule: typed.cases) (simp_all add: typed.simps)
next
fix t :: "('f, 'v) term" and π± π±' Ο
assume "welltyped π± t Ο" "βxβterm.vars t. π± x = π±' x"
then show "welltyped π±' t Ο"
by (induction rule: welltyped.induct) (simp_all add: welltyped.simps list.rel_mono_strong)
next
fix π± π±' :: "('v, 'ty) var_types" and t :: "('f, 'v) term" and Ο :: "('f, 'v) subst" and Ο
assume renaming: "term_subst.is_renaming Ο" and π±: "βxβterm.vars t. π± x = π±' (term.rename Ο x)"
show "typed π±' (t β
t Ο) Ο β· typed π± t Ο"
proof(intro iffI)
assume "typed π±' (t β
t Ο) Ο"
with π± show "typed π± t Ο"
proof(induction t arbitrary: Ο)
case (Var x)
have "π±' (term.rename Ο x) = Ο"
using Var term.id_subst_rename[OF renaming]
by (metis eval_term.simps(1) term.typed.right_uniqueD typed.Var)
then have "π± x = Ο"
by (simp add: renaming Var.prems)
then show ?case
by(rule typed.Var)
next
case (Fun f ts)
then show ?case
by (simp add: typed.simps)
qed
next
assume "typed π± t Ο"
then show "typed π±' (t β
t Ο) Ο"
using π±
proof(induction rule: typed.induct)
case (Var x Ο)
have "π±' (term.rename Ο x) = Ο"
using Var.hyps Var.prems
by auto
then show ?case
by (metis eval_term.simps(1) renaming term.id_subst_rename typed.Var)
next
case (Fun f Οs Ο ts)
then show ?case
by (simp add: typed.simps)
qed
qed
next
fix π± π±' :: "('v, 'ty) var_types" and t :: "('f, 'v) term" and Ο :: "('f, 'v) subst" and Ο
assume
renaming: "term_subst.is_renaming Ο" and
π±: "βxβterm.vars t. π± x = π±' (term.rename Ο x)"
then show "welltyped π±' (t β
t Ο) Ο β· welltyped π± t Ο"
proof(intro iffI)
assume "welltyped π±' (t β
t Ο) Ο"
with π± show "welltyped π± t Ο"
proof(induction t arbitrary: Ο)
case (Var x)
then have "π±' (term.rename Ο x) = Ο"
using renaming term.id_subst_rename[OF renaming]
by (metis eval_term.simps(1) term.typed.right_uniqueD term.typed_if_welltyped typed.Var)
then have "π± x = Ο"
by (simp add: Var.prems(1))
then show ?case
by(rule welltyped.Var)
next
case (Fun f ts)
then have "welltyped π±' (Fun f (map (Ξ»s. s β
t Ο) ts)) Ο"
by auto
then obtain Οs where Οs:
"list_all2 (welltyped π±') (map (Ξ»s. s β
t Ο) ts) Οs" "β± f = (Οs, Ο)"
using welltyped.simps
by blast
show ?case
proof(rule welltyped.Fun[OF Οs(2)])
show "list_all2 (welltyped π±) ts Οs"
using Οs(1) Fun.IH
by (smt (verit, ccfv_SIG) Fun.prems(1) eval_term.simps(2) in_set_conv_nth length_map
list_all2_conv_all_nth nth_map term.set_intros(4))
qed
qed
next
assume "welltyped π± t Ο"
then show "welltyped π±' (t β
t Ο) Ο"
using π±
proof(induction rule: welltyped.induct)
case (Var x Ο)
then have "π±' (term.rename Ο x) = Ο"
by simp
then show ?case
using term.id_subst_rename[OF renaming]
by (metis eval_term.simps(1) welltyped.Var)
next
case (Fun f Οs Ο ts)
have "list_all2 (welltyped π±') (map (Ξ»s. s β
t Ο) ts) Οs"
using Fun
by(auto simp: list.rel_mono_strong list_all2_map1)
then show ?case
by (simp add: Fun.hyps welltyped.simps)
qed
qed
qed
end
locale nonground_term_inhabited_typing =
nonground_term_typing where β± = β± for β± :: "('f, 'ty) fun_types" +
assumes types_inhabited: "βΟ. βf. β± f = ([], Ο)"
begin
sublocale base_inhabited_typing_properties where
id_subst = "Var :: 'v β ('f, 'v) term" and comp_subst = "(β)" and subst = "(β
t)" and
vars = term.vars and welltyped = welltyped and typed = typed and to_ground = term.to_ground and
from_ground = term.from_ground
proof unfold_locales
fix π± :: "('v, 'ty) var_types" and Ο
obtain f where f: "β± f = ([], Ο)"
using types_inhabited
by blast
show "βt. term.is_ground t β§ welltyped π± t Ο"
proof(rule exI[of _ "Fun f []"], intro conjI welltyped.Fun)
show "term.is_ground (Fun f [])"
by simp
next
show "β± f = ([], Ο)"
by(rule f)
next
show "list_all2 (welltyped π±) [] []"
by simp
qed
then show "βt. term.is_ground t β§ typed π± t Ο"
using term.typed_if_welltyped
by blast
qed
end
end