diff -r eed7ca453573 -r 3c9a0985e6be src/CCL/Term.thy --- a/src/CCL/Term.thy Mon Jan 11 07:44:20 2016 +0100 +++ b/src/CCL/Term.thy Mon Jan 11 21:16:38 2016 +0100 @@ -9,48 +9,69 @@ imports CCL begin -consts +definition one :: "i" + where "one == true" - one :: "i" +definition "if" :: "[i,i,i]\i" ("(3if _/ then _/ else _)" [0,0,60] 60) + where "if b then t else u == case(b, t, u, \ x y. bot, \v. bot)" - "if" :: "[i,i,i]\i" ("(3if _/ then _/ else _)" [0,0,60] 60) +definition inl :: "i\i" + where "inl(a) == " - inl :: "i\i" - inr :: "i\i" - "when" :: "[i,i\i,i\i]\i" +definition inr :: "i\i" + where "inr(b) == " + +definition split :: "[i,[i,i]\i]\i" + where "split(t,f) == case(t, bot, bot, f, \u. bot)" - split :: "[i,[i,i]\i]\i" - fst :: "i\i" - snd :: "i\i" - thd :: "i\i" +definition "when" :: "[i,i\i,i\i]\i" + where "when(t,f,g) == split(t, \b x. if b then f(x) else g(x))" + +definition fst :: "i\i" + where "fst(t) == split(t, \x y. x)" - zero :: "i" - succ :: "i\i" - ncase :: "[i,i,i\i]\i" - nrec :: "[i,i,[i,i]\i]\i" +definition snd :: "i\i" + where "snd(t) == split(t, \x y. y)" + +definition thd :: "i\i" + where "thd(t) == split(t, \x p. split(p, \y z. z))" + +definition zero :: "i" + where "zero == inl(one)" - nil :: "i" ("([])") - cons :: "[i,i]\i" (infixr "$" 80) - lcase :: "[i,i,[i,i]\i]\i" - lrec :: "[i,i,[i,i,i]\i]\i" +definition succ :: "i\i" + where "succ(n) == inr(n)" + +definition ncase :: "[i,i,i\i]\i" + where "ncase(n,b,c) == when(n, \x. b, \y. c(y))" - "let" :: "[i,i\i]\i" - letrec :: "[[i,i\i]\i,(i\i)\i]\i" - letrec2 :: "[[i,i,i\i\i]\i,(i\i\i)\i]\i" - letrec3 :: "[[i,i,i,i\i\i\i]\i,(i\i\i\i)\i]\i" + +no_syntax + "_Let" :: "[letbinds, 'a] => 'a" ("(let (_)/ in (_))" 10) + +definition "let" :: "[i,i\i]\i" + where "let(t, f) == case(t,f(true),f(false), \x y. f(), \u. f(lam x. u(x)))" syntax - "_let" :: "[id,i,i]\i" ("(3let _ be _/ in _)" - [0,0,60] 60) + "_Let" :: "[letbinds, 'a] => 'a" ("(let (_)/ in (_))" 10) - "_letrec" :: "[id,id,i,i]\i" ("(3letrec _ _ be _/ in _)" - [0,0,0,60] 60) +definition letrec :: "[[i,i\i]\i,(i\i)\i]\i" + where "letrec(h, b) == b(\x. fix(\f. lam x. h(x,\y. f`y))`x)" + +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'())), \g'. f(\x y. g'()))" - "_letrec2" :: "[id,id,id,i,i]\i" ("(3letrec _ _ _ be _/ in _)" - [0,0,0,0,60] 60) +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'(>)))), + \g'. f(\x y z. g'(>)))" - "_letrec3" :: "[id,id,id,id,i,i]\i" ("(3letrec _ _ _ _ be _/ in _)" - [0,0,0,0,0,60] 60) +syntax + "_let" :: "[id,i,i]\i" ("(3let _ be _/ in _)" [0,0,60] 60) + "_letrec" :: "[id,id,i,i]\i" ("(3letrec _ _ be _/ in _)" [0,0,0,60] 60) + "_letrec2" :: "[id,id,id,i,i]\i" ("(3letrec _ _ _ be _/ in _)" [0,0,0,0,60] 60) + "_letrec3" :: "[id,id,id,id,i,i]\i" ("(3letrec _ _ _ _ be _/ in _)" [0,0,0,0,0,60] 60) ML \ (** Quantifier translations: variable binding **) @@ -107,42 +128,24 @@ (@{const_syntax letrec3}, K letrec3_tr')] \ -consts - napply :: "[i\i,i,i]\i" ("(_ ^ _ ` _)" [56,56,56] 56) + +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)" + +definition nil :: "i" ("([])") + where "[] == inl(one)" -defs - one_def: "one == true" - if_def: "if b then t else u == case(b, t, u, \ x y. bot, \v. bot)" - inl_def: "inl(a) == " - inr_def: "inr(b) == " - when_def: "when(t,f,g) == split(t, \b x. if b then f(x) else g(x))" - split_def: "split(t,f) == case(t, bot, bot, f, \u. bot)" - fst_def: "fst(t) == split(t, \x y. x)" - snd_def: "snd(t) == split(t, \x y. y)" - thd_def: "thd(t) == split(t, \x p. split(p, \y z. z))" - zero_def: "zero == inl(one)" - succ_def: "succ(n) == inr(n)" - ncase_def: "ncase(n,b,c) == when(n, \x. b, \y. c(y))" - nrec_def: " nrec(n,b,c) == letrec g x be ncase(x, b, \y. c(y,g(y))) in g(n)" - nil_def: "[] == inl(one)" - cons_def: "h$t == inr()" - lcase_def: "lcase(l,b,c) == when(l, \x. b, \y. split(y,c))" - lrec_def: "lrec(l,b,c) == letrec g x be lcase(x, b, \h t. c(h,t,g(t))) in g(l)" +definition cons :: "[i,i]\i" (infixr "$" 80) + where "h$t == inr()" + +definition lcase :: "[i,i,[i,i]\i]\i" + where "lcase(l,b,c) == when(l, \x. b, \y. split(y,c))" - let_def: "let x be t in f(x) == case(t,f(true),f(false), \x y. f(), \u. f(lam x. u(x)))" - letrec_def: - "letrec g x be h(x,g) in b(g) == b(\x. fix(\f. lam x. h(x,\y. f`y))`x)" +definition lrec :: "[i,i,[i,i,i]\i]\i" + where "lrec(l,b,c) == letrec g x be lcase(x, b, \h t. c(h,t,g(t))) in g(l)" - letrec2_def: "letrec g x y be h(x,y,g) in f(g)== - letrec g' p be split(p,\x y. h(x,y,\u v. g'())) - in f(\x y. g'())" - - letrec3_def: "letrec g x y z be h(x,y,z,g) in f(g) == - letrec g' p be split(p,\x xs. split(xs,\y z. h(x,y,z,\u v w. g'(>)))) - in f(\x y z. g'(>))" - - napply_def: "f ^n` a == nrec(n,a,\x g. f(g))" - +definition napply :: "[i\i,i,i]\i" ("(_ ^ _ ` _)" [56,56,56] 56) + where "f ^n` a == nrec(n,a,\x g. f(g))" lemmas simp_can_defs = one_def inl_def inr_def and simp_ncan_defs = if_def when_def split_def fst_def snd_def thd_def