Theory Rhombus_HOL_Kernel
theory Rhombus_HOL_Kernel
imports Rhombus_HOL_Substitution
begin
section ‹Executable primitive rules›
text ‹Rhombus correspondence: kernel.rhm's ten primitive inference rules. Each branch mirrors the source; option replaces source exceptions.›
definition checked_thm :: "htheory ⇒ hterm list ⇒ hterm ⇒ stamp ⇒ hthm option" where
"checked_thm thy hs c st =
(let th = ⦇hyps = hs, concl = c, thm_stamp = st⦈
in if wf_thm thy th then Some th else None)"
definition checked_eq_thm ::
"htheory ⇒ hterm list ⇒ hterm ⇒ hterm ⇒ stamp ⇒ hthm option" where
"checked_eq_thm thy hs l r st =
(case mk_eq l r of None ⇒ None | Some eq ⇒ checked_thm thy hs eq st)"
definition refl :: "htheory ⇒ hterm ⇒ hthm option" where
"refl thy t = checked_eq_thm thy [] t t (thy_stamp thy)"
definition trans :: "htheory ⇒ hthm ⇒ hthm ⇒ hthm option" where
"trans thy a b =
(case (dest_eq (concl a), dest_eq (concl b),
combine_stamps (thm_stamp a) (thm_stamp b)) of
(Some (l, m), Some (m', r), Some st) ⇒
if m = m' then checked_eq_thm thy (hyp_union (hyps a) (hyps b)) l r st
else None
| _ ⇒ None)"
definition mk_comb_rule :: "htheory ⇒ hthm ⇒ hthm ⇒ hthm option" where
"mk_comb_rule thy fth xth =
(case (dest_eq (concl fth), dest_eq (concl xth),
combine_stamps (thm_stamp fth) (thm_stamp xth)) of
(Some (f, g), Some (x, y), Some st) ⇒
checked_eq_thm thy (hyp_union (hyps fth) (hyps xth))
(Comb f x) (Comb g y) st
| _ ⇒ None)"
definition abs_rule :: "htheory ⇒ hname ⇒ htype ⇒ hthm ⇒ hthm option" where
"abs_rule thy n ty th =
(case dest_eq (concl th) of
None ⇒ None
| Some (l, r) ⇒
if descends (thm_stamp th) (thy_stamp thy) ∧
check_term thy (FVar n ty) ∧
(∀h∈set (hyps th). ¬ vfree_in n ty h)
then checked_eq_thm thy (hyps th)
(Abs ty (abstract_fvar n ty l)) (Abs ty (abstract_fvar n ty r))
(thy_stamp thy)
else None)"
definition beta :: "htheory ⇒ hterm ⇒ hthm option" where
"beta thy t =
(case t of Comb (Abs aty body) arg ⇒
if check_term thy t then checked_eq_thm thy [] t (subst_bvar arg body)
(thy_stamp thy)
else None
| _ ⇒ None)"
definition assume_rule :: "htheory ⇒ hterm ⇒ hthm option" where
"assume_rule thy p =
(if check_prop thy p then checked_thm thy [p] p (thy_stamp thy) else None)"
definition eq_mp :: "htheory ⇒ hthm ⇒ hthm ⇒ hthm option" where
"eq_mp thy eqth th =
(case (dest_eq (concl eqth),
combine_stamps (thm_stamp eqth) (thm_stamp th)) of
(Some (p, q), Some st) ⇒
if p = concl th then
checked_thm thy (hyp_union (hyps eqth) (hyps th)) q st
else None
| _ ⇒ None)"
definition deduct_antisym_rule :: "htheory ⇒ hthm ⇒ hthm ⇒ hthm option" where
"deduct_antisym_rule thy a b =
(case combine_stamps (thm_stamp a) (thm_stamp b) of
None ⇒ None
| Some st ⇒ checked_eq_thm thy
(hyp_union (hyp_remove (concl b) (hyps a))
(hyp_remove (concl a) (hyps b)))
(concl a) (concl b) st)"
fun decode_term_subst ::
"(hterm × hterm) list ⇒ (hterm × (hname × htype)) list option" where
"decode_term_subst [] = Some []"
| "decode_term_subst ((rep, FVar n ty) # rest) =
map_option ((#) (rep, (n, ty))) (decode_term_subst rest)"
| "decode_term_subst ((_ , _) # _) = None"
definition inst :: "htheory ⇒ (hterm × hterm) list ⇒ hthm ⇒ hthm option" where
"inst thy raw th =
(case decode_term_subst raw of
None ⇒ None
| Some θ ⇒
if descends (thm_stamp th) (thy_stamp thy) ∧ wf_term_subst thy θ then
checked_thm thy (rehash_hyps (map (inst_fvar θ) (hyps th)))
(inst_fvar θ (concl th)) (thy_stamp thy)
else None)"
definition inst_type_rule ::
"htheory ⇒ (hname ⇒ htype option) ⇒ hthm ⇒ hthm option" where
"inst_type_rule thy θ th =
(if descends (thm_stamp th) (thy_stamp thy) ∧ type_subst_ok thy θ then
checked_thm thy (rehash_hyps (map (inst_type θ) (hyps th)))
(inst_type θ (concl th)) (thy_stamp thy)
else None)"
lemma type_subst_empty [simp]: "type_subst (λ_. None) ty = ty"
proof (induction ty)
case (TyApp n args)
then have "map (type_subst (λ_. None)) args = map id args"
by (intro map_cong) auto
then show ?case by simp
qed simp
lemma type_subst_ok_empty [simp]: "type_subst_ok thy (λ_. None)"
by (simp add: type_subst_ok_def)
section ‹Rule requests and declarative results›