(* Title: CCL/Term.thy Author: Martin Coen Copyright 1993 University of Cambridge
*)
section‹Definitions of usual program constructs in CCL›
theoryTerm imports CCL begin
definition one :: "i" where"one == true"
definition"if" :: "[i,i,i]\i"
(‹(‹indent=3 notation=‹mixfix ifthen else››if _/ then _/ else _)› [0,0,60] 60) where"if b then t else u == case(b, t, u, \ x y. bot, \v. bot)"
definition"let1" :: "[i,i\i]\i" where let_def: "let1(t, f) == case(t,f(true),f(false), \x y. f(), \u. f(lam x. u(x)))"
syntax"_let1" :: "[idt,i,i]\i"
(‹(‹indent=3 notation=‹mixfix let be in››let _ be _/ in _)› [0,0,60] 60)
syntax_consts "_let1" == let1 translations"let x be a in e" == "CONST let1(a, \x. e)"
definition letrec2 :: "[[i,i,i\i\i]\i,(i\i\i)\i]\i" where"letrec2 (h, f) ==
letrec (λp g'. split(p,\x y. h(x,y,\u v. g'(<u,v>))), λg'. f(\x y. g'(<x,y>)))"
definition letrec3 :: "[[i,i,i,i\i\i\i]\i,(i\i\i\i)\i]\i" where"letrec3 (h, f) ==
letrec (λp g'. split(p,\x xs. split(xs,\y z. h(x,y,z,\u v w. g'(<u,<v,w>>)))),
λg'. f(\x y z. g'(<x,<y,z>>)))"
syntax "_letrec" :: "[idt,idt,i,i]\i"
(‹(‹indent=3 notation=‹mixfix letrec be in››letrec _ _ be _/ in _)› [0,0,0,60] 60) "_letrec2" :: "[idt,idt,idt,i,i]\i"
(‹(‹indent=3 notation=‹mixfix letrec be in››letrec _ _ _ be _/ in _)› [0,0,0,0,60] 60) "_letrec3" :: "[idt,idt,idt,idt,i,i]\i"
(‹(‹indent=3 notation=‹mixfix letrec be in››letrec _ _ _ _ be _/ in _)› [0,0,0,0,0,60] 60)
syntax_consts "_letrec" == letrec and "_letrec2" == letrec2 and "_letrec3" == letrec3 parse_translation‹ let fun abs_tr t u = Syntax_Trans.abs_tr [t, u]; fun letrec_tr [f, x, a, b] = Syntax.const 🍋‹letrec› $ abs_tr x (abs_tr f a) $ abs_tr f b; fun letrec2_tr [f, x, y, a, b] = Syntax.const 🍋‹letrec2› $ abs_tr x (abs_tr y (abs_tr f a)) $ abs_tr f b; fun letrec3_tr [f, x, y, z, a, b] = Syntax.const 🍋‹letrec3› $ abs_tr x (abs_tr y (abs_tr z (abs_tr f a))) $ abs_tr f b; in
[(🍋‹_letrec›, K letrec_tr),
(🍋‹_letrec2›, K letrec2_tr),
(🍋‹_letrec3›, K letrec3_tr)] end › print_translation‹ let
val bound = Syntax_Trans.mark_bound_abs;
fun letrec_tr' [Abs(x,T,Abs(f,S,a)),Abs(ff,SS,b)] = let
val (f',b') = Syntax_Trans.print_abs(ff,SS,b)
val (_,a'') = Syntax_Trans.print_abs(f,S,a)
val (x',a') = Syntax_Trans.print_abs(x,T,a'') in Syntax.const 🍋‹_letrec› $ bound(f',SS) $ bound(x',T) $ a' $ b' end;
fun letrec2_tr' [Abs(x,T,Abs(y,U,Abs(f,S,a))),Abs(ff,SS,b)] = let
val (f',b') = Syntax_Trans.print_abs(ff,SS,b)
val ( _,a1) = Syntax_Trans.print_abs(f,S,a)
val (y',a2) = Syntax_Trans.print_abs(y,U,a1)
val (x',a') = Syntax_Trans.print_abs(x,T,a2) in Syntax.const 🍋‹_letrec2› $ bound(f',SS) $ bound(x',T) $ bound(y',U) $ a' $ b' end;
fun letrec3_tr' [Abs(x,T,Abs(y,U,Abs(z,V,Abs(f,S,a)))),Abs(ff,SS,b)] = let
val (f',b') = Syntax_Trans.print_abs(ff,SS,b)
val ( _,a1) = Syntax_Trans.print_abs(f,S,a)
val (z',a2) = Syntax_Trans.print_abs(z,V,a1)
val (y',a3) = Syntax_Trans.print_abs(y,U,a2)
val (x',a') = Syntax_Trans.print_abs(x,T,a3) in Syntax.const 🍋‹_letrec3› $
bound(f',SS) $ bound(x',T) $ bound(y',U) $ bound(z',V) $ a' $ b' end; in
[(🍋‹letrec›, K letrec_tr'),
(🍋‹letrec2›, K letrec2_tr'),
(🍋‹letrec3›, K letrec3_tr')] end ›
definition nrec :: "[i,i,[i,i]\i]\i" where"nrec(n,b,c) == letrec g x be ncase(x, b, \y. c(y,g(y))) in g(n)"
lemma letrecB: "letrec g x be h(x,g) in g(a) = h(a,\y. letrec g x be h(x,g) in g(y))" apply (unfold letrec_def) apply (rule fixB [THEN ssubst], rule applyB [THEN ssubst], rule refl) done
lemmas rawBs = caseBs applyB applyBbot
method_setup beta_rl = ‹
Scan.succeed (fn ctxt => let
val ctxt' = ctxt
|> Context_Position.set_visible false
|> Simplifier.add_simps @{thms rawBs}
|> Simplifier.set_loop (fn _ => stac ctxt @{thm letrecB}); in SIMPLE_METHOD' (CHANGED o simp_tac ctxt') end) ›
lemma ifBtrue: "if true then t else u = t" and ifBfalse: "if false then t else u = u" and ifBbot: "if bot then t else u = bot" unfolding data_defs by beta_rl+
lemma whenBinl: "when(inl(a),t,u) = t(a)" and whenBinr: "when(inr(a),t,u) = u(a)" and whenBbot: "when(bot,t,u) = bot" unfolding data_defs by beta_rl+
lemma splitB: "split(,h) = h(a,b)" and splitBbot: "split(bot,h) = bot" unfolding data_defs by beta_rl+
lemma fstB: "fst() = a" and fstBbot: "fst(bot) = bot" unfolding data_defs by beta_rl+
lemma sndB: "snd() = b" and sndBbot: "snd(bot) = bot" unfolding data_defs by beta_rl+
lemma thdB: "thd(>) = c" and thdBbot: "thd(bot) = bot" unfolding data_defs by beta_rl+
lemma ncaseBzero: "ncase(zero,t,u) = t" and ncaseBsucc: "ncase(succ(n),t,u) = u(n)" and ncaseBbot: "ncase(bot,t,u) = bot" unfolding data_defs by beta_rl+
lemma nrecBzero: "nrec(zero,t,u) = t" and nrecBsucc: "nrec(succ(n),t,u) = u(n,nrec(n,t,u))" and nrecBbot: "nrec(bot,t,u) = bot" unfolding data_defs by beta_rl+
lemma lcaseBnil: "lcase([],t,u) = t" and lcaseBcons: "lcase(x$xs,t,u) = u(x,xs)" and lcaseBbot: "lcase(bot,t,u) = bot" unfolding data_defs by beta_rl+
lemma lrecBnil: "lrec([],t,u) = t" and lrecBcons: "lrec(x$xs,t,u) = u(x,xs,lrec(xs,t,u))" and lrecBbot: "lrec(bot,t,u) = bot" unfolding data_defs by beta_rl+
lemma letrec2B: "letrec g x y be h(x,y,g) in g(p,q) = h(p,q,\u v. letrec g x y be h(x,y,g) in g(u,v))" unfolding data_defs letrec2_def by beta_rl+
lemma letrec3B: "letrec g x y z be h(x,y,z,g) in g(p,q,r) =
h(p,q,r,λu v w. letrec g x y z be h(x,y,z,g) in g(u,v,w))" unfolding data_defs letrec3_def by beta_rl+
lemma napplyBzero: "f^zero`a = a" and napplyBsucc: "f^succ(n)`a = f(f^n`a)" unfolding data_defs by beta_rl+
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.