definition wmap :: "[i==>i,i set] ==> i set" where"wmap(f,R) == {p. EX x y. p=∧ : R}"
definition lex :: "[i set,i set] => i set" (infixl‹**› 70) where"ra**rb == {p. EX a a' b b'. p = <,> ∧ ( : ra | (a=a' ∧ : rb))}"
definition NatPR :: "i set" where"NatPR == {p. EX x:Nat. p=}"
definition ListPR :: "i set ==> i set" where"ListPR(A) == {p. EX h:A. EX t:List(A). p=}"
lemma wfd_induct: assumes 1: "Wfd(R)" and 2: "∧x. ALL y. : R ⟶ P(y) ==> P(x)" shows"P(a)" apply (rule 1 [unfolded Wfd_def, rule_format, THEN CollectD]) using 2 apply blast done
lemma wfd_strengthen_lemma: assumes 1: "∧x y. : R ==> Q(x)" and 2: "ALL x. (ALL y. : R ⟶ y : P) ⟶ x : P" and 3: "∧x. Q(x) ==> x:P" shows"a:P" apply (rule 2 [rule_format]) using 1 3 apply blast done
method_setup wfd_strengthen = ‹ Scan.lift Parse.embedded_inner_syntax >> (fn s => fn ctxt => SIMPLE_METHOD' (fn i => Rule_Insts.res_inst_tac ctxt [((("Q", 0), Position.none), s)] [] @{thm wfd_strengthen_lemma} i THEN assume_tac ctxt (i + 1))) ›
(* 0-ary constructors do not need additional rules as they are handled *) (* correctly by applying SubtypeI *)
lemma Subtype_canTs: "∧a b A B P. a : {x:A. b:{y:B(a).P()}} ==> : {x:Sigma(A,B).P(x)}" "∧a A B P. a : {x:A. P(inl(x))} ==> inl(a) : {x:A+B. P(x)}" "∧b A B P. b : {x:B. P(inr(x))} ==> inr(b) : {x:A+B. P(x)}" "∧a P. a : {x:Nat. P(succ(x))} ==> succ(a) : {x:Nat. P(x)}" "∧h t A P. h : {x:A. t : {y:List(A).P(x$y)}} ==> h$t : {x:List(A).P(x)}" by (assumption | rule SubtypeI canTs icanTs | erule SubtypeE)+
lemma letT: "[f(t):B; ¬t=bot]==> let x be t in f(x) : B" apply (erule letB [THEN ssubst]) apply assumption done
lemma applyT2: "[a:A; f : Pi(A,B)]==> f ` a : B(a)" apply (erule applyT) apply assumption done
lemma rcall_lemma1: "[a:A; a:A ==> P(a)]==> a : {x:A. P(x)}" by blast
lemma rcall_lemma2: "[a:{x:A. Q(x)}; [a:A; Q(a)]==> P(a)]==> a : {x:A. P(x)}" by blast
ML ‹ local val type_rls = @{thms canTs} @ @{thms icanTs} @ @{thms applyT2} @ @{thms ncanTs} @ @{thms incanTs} @ @{thms precTs} @ @{thms letrecTs} @ @{thms letT} @ @{thms Subtype_canTs}; fun bvars 🍋‹Pure.all _ for ‹Abs(s,_,t)›\
| bvars _ l = l
fun get_bno l n 🍋‹Pure.all _ for ‹Abs(s,_,t)›\
| get_bno l n 🍋‹Trueprop for t› = get_bno l n t
| get_bno l n 🍋‹Ball _ for _ ‹Abs(s,_,t)›\› = get_bno (s::l) (n+1) t
| get_bno l n 🍋‹mem _ for t _› = get_bno l n t
| get_bno l n (t $ s) = get_bno l n t
| get_bno l n (Bound m) = (m-length(l),n)
(* Not a great way of identifying induction hypothesis! *) fun could_IH x = Term.could_unify(x,hd (Thm.take_prems_of 1 @{thm rcallT})) orelse Term.could_unify(x,hd (Thm.take_prems_of 1 @{thm rcall2T})) orelse Term.could_unify(x,hd (Thm.take_prems_of 1 @{thm rcall3T}))
fun IHinst tac rls = SUBGOAL (fn (Bi,i) => let val bvs = bvars Bi []
val ihs = filter could_IH (Logic.strip_assums_hyp Bi)
val rnames = map (fn x => let val (a,b) = get_bno [] 0 x in (nth bvs a, b) end) ihs fun try_IHs [] = no_tac
| try_IHs ((x,y)::xs) =
tac [((("g", 0), Position.none), x)] (nth rls (y - 1)) i ORELSE (try_IHs xs) in try_IHs rnames end)
fun is_rigid_prog t =
(case (Logic.strip_assums_concl t) of 🍋‹Trueprop for 🍋‹mem _ for a _›\Term.add_vars a [])
| _ => false)
in
fun rcall_tac ctxt i = letfun tac ps rl i = Rule_Insts.res_inst_tac ctxt ps [] rl i THEN assume_tac ctxt i in IHinst tac @{thms rcallTs} i end THEN eresolve_tac ctxt @{thms rcall_lemmas} i
fun raw_step_tac ctxt prems i =
assume_tac ctxt i ORELSE
resolve_tac ctxt (prems @ type_rls) i ORELSE
rcall_tac ctxt i ORELSE
ematch_tac ctxt @{thms SubtypeE} i ORELSE
match_tac ctxt @{thms SubtypeI} i
fun tc_step_tac ctxt prems = SUBGOAL (fn (Bi,i) => if is_rigid_prog Bi then raw_step_tac ctxt prems i else no_tac)
fun typechk_tac ctxt rls i = SELECT_GOAL (REPEAT_FIRST (tc_step_tac ctxt rls)) i
(*** Clean up Correctness Condictions ***)
fun clean_ccs_tac ctxt = letfun tac ps rl i = Rule_Insts.eres_inst_tac ctxt ps [] rl i THEN assume_tac ctxt i in
TRY (REPEAT_FIRST (IHinst tac @{thms hyprcallTs} ORELSE'
eresolve_tac ctxt ([asm_rl, @{thm SubtypeE}] @ @{thms rmIHs}) ORELSE'
hyp_subst_tac ctxt)) end
fun gen_ccs_tac ctxt rls i =
SELECT_GOAL (REPEAT_FIRST (tc_step_tac ctxt rls) THEN clean_ccs_tac ctxt) i
lemma letrecV: "h(t,λy. letrec g x be h(x,g) in g(y)) ---> c ==> letrec g x be h(x,g) in g(t) ---> c" apply (unfold letrec_def) apply (assumption | rule fixV applyV lamV)+ done
lemmas [eval] = letV letrecV fixV
lemma V_rls [eval]: "true ---> true" "false ---> false" "∧b c t u. [b--->true; t--->c]==> if b then t else u ---> c" "∧b c t u. [b--->false; u--->c]==> if b then t else u ---> c" "∧a b. --->" "∧a b c t h. [t --->; h(a,b) ---> c]==> split(t,h) ---> c" "zero ---> zero" "∧n. succ(n) ---> succ(n)" "∧c n t u. [n ---> zero; t ---> c]==> ncase(n,t,u) ---> c" "∧c n t u x. [n ---> succ(x); u(x) ---> c]==> ncase(n,t,u) ---> c" "∧c n t u. [n ---> zero; t ---> c]==> nrec(n,t,u) ---> c" "∧c n t u x. [n--->succ(x); u(x,nrec(x,t,u))--->c]==> nrec(n,t,u)--->c" "[] ---> []" "∧h t. h$t ---> h$t" "∧c l t u. [l ---> []; t ---> c]==> lcase(l,t,u) ---> c" "∧c l t u x xs. [l ---> x$xs; u(x,xs) ---> c]==> lcase(l,t,u) ---> c" "∧c l t u. [l ---> []; t ---> c]==> lrec(l,t,u) ---> c" "∧c l t u x xs. [l--->x$xs; u(x,xs,lrec(xs,t,u))--->c]==> lrec(l,t,u)--->c" unfolding data_defs by eval+
subsection‹Factorial›
schematic_goal "letrec f n be ncase(n,succ(zero),λx. nrec(n,zero,λy g. nrec(f(x),g,λz h. succ(h)))) in f(succ(succ(zero))) ---> ?a" by eval
schematic_goal "letrec f n be ncase(n,succ(zero),λx. nrec(n,zero,λy g. nrec(f(x),g,λz h. succ(h)))) in f(succ(succ(succ(zero)))) ---> ?a" by eval
subsection‹Less Than Or Equal›
schematic_goal "letrec f p be split(p,λm n. ncase(m,true,λx. ncase(n,false,λy. f()))) in f() ---> ?a" by eval
schematic_goal "letrec f p be split(p,λm n. ncase(m,true,λx. ncase(n,false,λy. f()))) in f() ---> ?a" by eval
schematic_goal "letrec f p be split(p,λm n. ncase(m,true,λx. ncase(n,false,λy. f()))) in f() ---> ?a" by eval
subsection‹Reverse›
schematic_goal "letrec id l be lcase(l,[],λx xs. x$id(xs)) in id(zero$succ(zero)$[]) ---> ?a" by eval
schematic_goal "letrec rev l be lcase(l,[],λx xs. lrec(rev(xs),x$[],λy ys g. y$g)) in rev(zero$succ(zero)$(succ((lam x. x)`succ(zero)))$([])) ---> ?a" by eval
end
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.17 Sekunden
(vorverarbeitet am 2026-04-26)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.