(* Title: CCL/Term.thy Author: Martin Coen Copyright 1993 University of Cambridge
*)
section \<open>Definitions of usual program constructs in CCL\<close>
theoryTerm imports CCL begin
definition one :: "i" where"one == true"
definition"if" :: "[i,i,i]\i"
(\<open>(\<open>indent=3 notation=\<open>mixfix if then else\<close>\<close>if _/ then _/ else _)\<close> [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"
(\<open>(\<open>indent=3 notation=\<open>mixfix let be in\<close>\<close>let _ be _/ in _)\<close> [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 (\<lambda>p g'. split(p,\<lambda>x y. h(x,y,\<lambda>u v. g'(<u,v>))), \<lambda>g'. f(\<lambda>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 (\<lambda>p g'. split(p,\<lambda>x xs. split(xs,\<lambda>y z. h(x,y,z,\<lambda>u v w. g'(<u,<v,w>>)))), \<lambda>g'. f(\<lambda>x y z. g'(<x,<y,z>>)))"
syntax "_letrec" :: "[idt,idt,i,i]\i"
(\<open>(\<open>indent=3 notation=\<open>mixfix letrec be in\<close>\<close>letrec _ _ be _/ in _)\<close> [0,0,0,60] 60) "_letrec2" :: "[idt,idt,idt,i,i]\i"
(\<open>(\<open>indent=3 notation=\<open>mixfix letrec be in\<close>\<close>letrec _ _ _ be _/ in _)\<close> [0,0,0,0,60] 60) "_letrec3" :: "[idt,idt,idt,idt,i,i]\i"
(\<open>(\<open>indent=3 notation=\<open>mixfix letrec be in\<close>\<close>letrec _ _ _ _ be _/ in _)\<close> [0,0,0,0,0,60] 60)
syntax_consts "_letrec" == letrec and "_letrec2" == letrec2 and "_letrec3" == letrec3 parse_translation\<open> let fun abs_tr t u = Syntax_Trans.abs_tr [t, u]; fun letrec_tr [f, x, a, b] = Syntax.const \<^const_syntax>\<open>letrec\<close> $ abs_tr x (abs_tr f a) $ abs_tr f b; fun letrec2_tr [f, x, y, a, b] = Syntax.const \<^const_syntax>\<open>letrec2\<close> $ 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 \<^const_syntax>\<open>letrec3\<close> $ abs_tr x (abs_tr y (abs_tr z (abs_tr f a))) $ abs_tr f b; in
[(\<^syntax_const>\<open>_letrec\<close>, K letrec_tr),
(\<^syntax_const>\<open>_letrec2\<close>, K letrec2_tr),
(\<^syntax_const>\<open>_letrec3\<close>, K letrec3_tr)] end \<close> print_translation\<open> 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 \<^syntax_const>\<open>_letrec\<close> $ 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 \<^syntax_const>\<open>_letrec2\<close> $ 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 \<^syntax_const>\<open>_letrec3\<close> $
bound(f',SS) $ bound(x',T) $ bound(y',U) $ bound(z',V) $ a' $ b' end; in
[(\<^const_syntax>\<open>letrec\<close>, K letrec_tr'),
(\<^const_syntax>\<open>letrec2\<close>, K letrec2_tr'),
(\<^const_syntax>\<open>letrec3\<close>, K letrec3_tr')] end \<close>
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 = \<open>
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) \<close>
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,\<lambda>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 ist noch experimentell.