(*<*) theory Propositional_Logic imports Abstract_Completeness begin (*>*) section \Toy instantiation: Propositional Logic\ datatype fmla = Atom nat | Neg fmla | Conj fmla fmla primrec max_depth where "max_depth (Atom _) = 0" | "max_depth (Neg \) = Suc (max_depth \)" | "max_depth (Conj \ \) = Suc (max (max_depth \) (max_depth \))" lemma max_depth_0: "max_depth \ = 0 = (\n. \ = Atom n)" by (cases \) auto lemma max_depth_Suc: "max_depth \ = Suc n = ((\\. \ = Neg \ \ max_depth \ = n) \ (\\1 \2. \ = Conj \1 \2 \ max (max_depth \1) (max_depth \2) = n))" by (cases \) auto abbreviation "atoms \ smap Atom nats" abbreviation "depth1 \ sinterleave (smap Neg atoms) (smap (case_prod Conj) (sproduct atoms atoms))" abbreviation "sinterleaves \ fold sinterleave" fun extendLevel where "extendLevel (belowN, N) = (let Next = sinterleaves (map (smap (case_prod Conj)) [sproduct belowN N, sproduct N belowN, sproduct N N]) (smap Neg N) in (sinterleave belowN N, Next))" lemma extendLevel_step: "\sset belowN = {\. max_depth \ < n}; sset N = {\. max_depth \ = n}; st = (belowN, N)\ \ \belowNext Next. extendLevel st = (belowNext, Next) \ sset belowNext = {\. max_depth \ < Suc n} \ sset Next = {\. max_depth \ = Suc n}" by (auto simp: sset_sinterleave sset_sproduct stream.set_map image_iff max_depth_Suc) lemma sset_atoms: "sset atoms = {\. max_depth \ < 1}" by (auto simp: stream.set_map max_depth_0) lemma sset_depth1: "sset depth1 = {\. max_depth \ = 1}" by (auto simp: sset_sinterleave sset_sproduct stream.set_map max_depth_Suc max_depth_0 max_def image_iff) lemma extendLevel_Nsteps: "\sset belowN = {\. max_depth \ < n}; sset N = {\. max_depth \ = n}\ \ \belowNext Next. (extendLevel ^^ m) (belowN, N) = (belowNext, Next) \ sset belowNext = {\. max_depth \ < n + m} \ sset Next = {\. max_depth \ = n + m}" proof (induction m arbitrary: belowN N n) case (Suc m) then obtain belowNext Next where "(extendLevel ^^ m) (belowN, N) = (belowNext, Next)" "sset belowNext = {\. max_depth \ < n + m}" "sset Next = {\. max_depth \ = n + m}" by blast thus ?case unfolding funpow.simps o_apply add_Suc_right by (intro extendLevel_step[of belowNext _ Next]) qed simp corollary extendLevel: "\belowNext Next. (extendLevel ^^ m) (atoms, depth1) = (belowNext, Next) \ sset belowNext = {\. max_depth \ < 1 + m} \ sset Next = {\. max_depth \ = 1 + m}" by (rule extendLevel_Nsteps) (auto simp: sset_atoms sset_depth1) definition "fmlas = sinterleave atoms (smerge (smap snd (siterate extendLevel (atoms, depth1))))" lemma fmlas_UNIV: "sset fmlas = (UNIV :: fmla set)" proof (intro equalityI subsetI UNIV_I) fix \ show "\ \ sset fmlas" proof (cases "max_depth \") case 0 thus ?thesis unfolding fmlas_def sset_sinterleave stream.set_map by (intro UnI1) (auto simp: max_depth_0) next case (Suc m) thus ?thesis using extendLevel[of m] unfolding fmlas_def sset_smerge sset_siterate sset_sinterleave stream.set_map by (intro UnI2) (auto, metis (mono_tags) mem_Collect_eq) qed qed datatype rule = Idle | Ax nat | NegL fmla | NegR fmla | ConjL fmla fmla | ConjR fmla fmla abbreviation "mkRules f \ smap f fmlas" abbreviation "mkRulePairs f \ smap (case_prod f) (sproduct fmlas fmlas)" definition rules where "rules = Idle ## sinterleaves [mkRules NegL, mkRules NegR, mkRulePairs ConjL, mkRulePairs ConjR] (smap Ax nats)" lemma rules_UNIV: "sset rules = (UNIV :: rule set)" unfolding rules_def by (auto simp: sset_sinterleave sset_sproduct stream.set_map fmlas_UNIV image_iff) (metis rule.exhaust) type_synonym state = "fmla fset * fmla fset" fun eff' :: "rule \ state \ state fset option" where "eff' Idle (\, \) = Some {|(\, \)|}" | "eff' (Ax n) (\, \) = (if Atom n |\| \ \ Atom n |\| \ then Some {||} else None)" | "eff' (NegL \) (\, \) = (if Neg \ |\| \ then Some {|(\ |-| {| Neg \ |}, finsert \ \)|} else None)" | "eff' (NegR \) (\, \) = (if Neg \ |\| \ then Some {|(finsert \ \, \ |-| {| Neg \ |})|} else None)" | "eff' (ConjL \ \) (\, \) = (if Conj \ \ |\| \ then Some {|(finsert \ (finsert \ (\ |-| {| Conj \ \ |})), \)|} else None)" | "eff' (ConjR \ \) (\, \) = (if Conj \ \ |\| \ then Some {|(\, finsert \ (\ |-| {| Conj \ \ |})), (\, finsert \ (\ |-| {| Conj \ \ |}))|} else None)" abbreviation "Disj \ \ \ Neg (Conj (Neg \) (Neg \))" abbreviation "Imp \ \ \ Disj (Neg \) \" abbreviation "Iff \ \ \ Conj (Imp \ \) (Imp \ \)" definition "thm1 \ ({|Conj (Atom 0) (Neg (Atom 0))|}, {||})" declare Stream.smember_code [code del] lemma [code]: "Stream.smember x (y ## s) = (x = y \ Stream.smember x s)" unfolding Stream.smember_def by auto interpretation RuleSystem "\r s ss. eff' r s = Some ss" rules UNIV by unfold_locales (auto simp: rules_UNIV intro: exI[of _ Idle]) interpretation PersistentRuleSystem "\r s ss. eff' r s = Some ss" rules UNIV proof (unfold_locales, unfold enabled_def per_def rules_UNIV, clarsimp) fix r \ \ ss r' \' \' ss' assume "r' \ r" "eff' r (\, \) = Some ss" "eff' r' (\, \) = Some ss'" "(\', \') |\| ss'" then show "\sl. eff' r (\', \') = Some sl" by (cases r r' rule: rule.exhaust[case_product rule.exhaust]) (auto split: if_splits) qed definition "rho \ i.fenum rules" definition "propTree \ i.mkTree eff' rho" export_code propTree thm1 in Haskell module_name PropInstance (* file "." *) (*<*) end (*>*)