src/CCL/eval.ML
author wenzelm
Tue, 14 Mar 2006 22:06:42 +0100
changeset 19271 967e6c2578f2
parent 17456 bcf7544875b2
permissions -rw-r--r--
turned string_of_mixfix into pretty_mixfix;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1459
d12da312eff4 expanded tabs
clasohm
parents: 757
diff changeset
     1
(*  Title:      92/CCL/eval
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     2
    ID:         $Id$
1459
d12da312eff4 expanded tabs
clasohm
parents: 757
diff changeset
     3
    Author:     Martin Coen, Cambridge University Computer Laboratory
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     4
    Copyright   1992  University of Cambridge
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     5
*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     6
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     7
(*** Evaluation ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     8
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     9
val EVal_rls = ref [trueV,falseV,pairV,lamV,caseVtrue,caseVfalse,caseVpair,caseVlam];
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    10
val eval_tac = DEPTH_SOLVE_1 (resolve_tac (!EVal_rls) 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    11
fun ceval_tac rls = DEPTH_SOLVE_1 (resolve_tac (!EVal_rls@rls) 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    12
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    13
val prems = goalw (the_context ()) [apply_def]
3837
d7f033c74b38 fixed dots;
wenzelm
parents: 1459
diff changeset
    14
   "[| f ---> lam x. b(x);  b(a) ---> c |] ==> f ` a ---> c";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    15
by (ceval_tac prems);
757
2ca12511676d added qed and qed_goal[w]
clasohm
parents: 642
diff changeset
    16
qed "applyV";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    17
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    18
EVal_rls := !EVal_rls @ [applyV];
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    19
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    20
val major::prems = goalw (the_context ()) [let_def]
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    21
   "[| t ---> a;  f(a) ---> c |] ==> let x be t in f(x) ---> c";
642
0db578095e6a CCL/Gfp/coinduct2, coinduct3: modified proofs to suppress deep unification
lcp
parents: 289
diff changeset
    22
by (rtac (major RS canonical) 1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    23
by (REPEAT (DEPTH_SOLVE_1 (resolve_tac ([major]@prems@(!EVal_rls)) 1 ORELSE
642
0db578095e6a CCL/Gfp/coinduct2, coinduct3: modified proofs to suppress deep unification
lcp
parents: 289
diff changeset
    24
                           etac substitute 1)));
757
2ca12511676d added qed and qed_goal[w]
clasohm
parents: 642
diff changeset
    25
qed "letV";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    26
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    27
val prems = goalw (the_context ()) [fix_def]
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    28
   "f(fix(f)) ---> c ==> fix(f) ---> c";
642
0db578095e6a CCL/Gfp/coinduct2, coinduct3: modified proofs to suppress deep unification
lcp
parents: 289
diff changeset
    29
by (rtac applyV 1);
0db578095e6a CCL/Gfp/coinduct2, coinduct3: modified proofs to suppress deep unification
lcp
parents: 289
diff changeset
    30
by (rtac lamV 1);
0db578095e6a CCL/Gfp/coinduct2, coinduct3: modified proofs to suppress deep unification
lcp
parents: 289
diff changeset
    31
by (resolve_tac prems 1);
757
2ca12511676d added qed and qed_goal[w]
clasohm
parents: 642
diff changeset
    32
qed "fixV";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    33
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    34
val prems = goalw (the_context ()) [letrec_def]
3837
d7f033c74b38 fixed dots;
wenzelm
parents: 1459
diff changeset
    35
    "h(t,%y. letrec g x be h(x,g) in g(y)) ---> c ==> \
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    36
\                  letrec g x be h(x,g) in g(t) ---> c";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    37
by (REPEAT (resolve_tac (prems @ [fixV,applyV,lamV]) 1));
757
2ca12511676d added qed and qed_goal[w]
clasohm
parents: 642
diff changeset
    38
qed "letrecV";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    39
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    40
EVal_rls := !EVal_rls @ [letV,letrecV,fixV];
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    41
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    42
fun mk_V_rl s = prove_goalw (the_context ()) data_defs s (fn prems => [ceval_tac prems]);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    43
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    44
val V_rls = map mk_V_rl
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    45
             ["true ---> true",
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    46
              "false ---> false",
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    47
              "[| b--->true;  t--->c |] ==> if b then t else u ---> c",
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    48
              "[| b--->false;  u--->c |] ==> if b then t else u ---> c",
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    49
              "<a,b> ---> <a,b>",
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    50
              "[| t ---> <a,b>;  h(a,b) ---> c |] ==> split(t,h) ---> c",
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    51
              "zero ---> zero",
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    52
              "succ(n) ---> succ(n)",
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    53
              "[| n ---> zero; t ---> c |] ==> ncase(n,t,u) ---> c",
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    54
              "[| n ---> succ(x); u(x) ---> c |] ==> ncase(n,t,u) ---> c",
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    55
              "[| n ---> zero; t ---> c |] ==> nrec(n,t,u) ---> c",
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    56
              "[| n--->succ(x); u(x,nrec(x,t,u))--->c |] ==> nrec(n,t,u)--->c",
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    57
              "[] ---> []",
289
78541329ff35 changed "." to "$" to eliminate ambiguity
clasohm
parents: 0
diff changeset
    58
              "h$t ---> h$t",
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    59
              "[| l ---> []; t ---> c |] ==> lcase(l,t,u) ---> c",
289
78541329ff35 changed "." to "$" to eliminate ambiguity
clasohm
parents: 0
diff changeset
    60
              "[| l ---> x$xs; u(x,xs) ---> c |] ==> lcase(l,t,u) ---> c",
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    61
              "[| l ---> []; t ---> c |] ==> lrec(l,t,u) ---> c",
289
78541329ff35 changed "." to "$" to eliminate ambiguity
clasohm
parents: 0
diff changeset
    62
              "[| l--->x$xs; u(x,xs,lrec(xs,t,u))--->c |] ==> lrec(l,t,u)--->c"];
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    63
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    64
EVal_rls := !EVal_rls @ V_rls;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    65
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    66
(* Factorial *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    67
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    68
val prems = goal (the_context ())
3837
d7f033c74b38 fixed dots;
wenzelm
parents: 1459
diff changeset
    69
    "letrec f n be ncase(n,succ(zero),%x. nrec(n,zero,%y g. nrec(f(x),g,%z h. succ(h)))) \
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    70
\              in f(succ(succ(zero))) ---> ?a";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    71
by (ceval_tac []);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    72
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    73
val prems = goal (the_context ())
3837
d7f033c74b38 fixed dots;
wenzelm
parents: 1459
diff changeset
    74
    "letrec f n be ncase(n,succ(zero),%x. nrec(n,zero,%y g. nrec(f(x),g,%z h. succ(h)))) \
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    75
\              in f(succ(succ(succ(zero)))) ---> ?a";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    76
by (ceval_tac []);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    77
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    78
(* Less Than Or Equal *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    79
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    80
fun isle x y = prove_goal (the_context ())
3837
d7f033c74b38 fixed dots;
wenzelm
parents: 1459
diff changeset
    81
    ("letrec f p be split(p,%m n. ncase(m,true,%x. ncase(n,false,%y. f(<x,y>)))) \
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    82
\              in f(<"^x^","^y^">) ---> ?a")
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    83
    (fn prems => [ceval_tac []]);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    84
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    85
isle "succ(zero)" "succ(zero)";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    86
isle "succ(zero)" "succ(succ(succ(succ(zero))))";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    87
isle "succ(succ(succ(succ(succ(zero)))))" "succ(succ(succ(succ(zero))))";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    88
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    89
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    90
(* Reverse *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    91
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    92
val prems = goal (the_context ())
3837
d7f033c74b38 fixed dots;
wenzelm
parents: 1459
diff changeset
    93
    "letrec id l be lcase(l,[],%x xs. x$id(xs)) \
289
78541329ff35 changed "." to "$" to eliminate ambiguity
clasohm
parents: 0
diff changeset
    94
\              in id(zero$succ(zero)$[]) ---> ?a";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    95
by (ceval_tac []);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    96
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    97
val prems = goal (the_context ())
3837
d7f033c74b38 fixed dots;
wenzelm
parents: 1459
diff changeset
    98
    "letrec rev l be lcase(l,[],%x xs. lrec(rev(xs),x$[],%y ys g. y$g)) \
d7f033c74b38 fixed dots;
wenzelm
parents: 1459
diff changeset
    99
\              in rev(zero$succ(zero)$(succ((lam x. x)`succ(zero)))$([])) ---> ?a";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   100
by (ceval_tac []);