src/CCL/eval.ML
author paulson
Thu, 04 Dec 2003 10:29:17 +0100
changeset 14272 5efbb548107d
parent 3837 d7f033c74b38
child 17456 bcf7544875b2
permissions -rw-r--r--
Tidying of the integer development; towards removing the abel_cancel simproc
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
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     8
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     9
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    10
(*** Evaluation ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    11
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    12
val EVal_rls = ref [trueV,falseV,pairV,lamV,caseVtrue,caseVfalse,caseVpair,caseVlam];
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    13
val eval_tac = DEPTH_SOLVE_1 (resolve_tac (!EVal_rls) 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    14
fun ceval_tac rls = DEPTH_SOLVE_1 (resolve_tac (!EVal_rls@rls) 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    15
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    16
val prems = goalw thy [apply_def]
3837
d7f033c74b38 fixed dots;
wenzelm
parents: 1459
diff changeset
    17
   "[| f ---> lam x. b(x);  b(a) ---> c |] ==> f ` a ---> c";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    18
by (ceval_tac prems);
757
2ca12511676d added qed and qed_goal[w]
clasohm
parents: 642
diff changeset
    19
qed "applyV";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    20
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    21
EVal_rls := !EVal_rls @ [applyV];
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    22
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    23
val major::prems = goalw thy [let_def]
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    24
   "[| 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
    25
by (rtac (major RS canonical) 1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    26
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
    27
                           etac substitute 1)));
757
2ca12511676d added qed and qed_goal[w]
clasohm
parents: 642
diff changeset
    28
qed "letV";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    29
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    30
val prems = goalw thy [fix_def]
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    31
   "f(fix(f)) ---> c ==> fix(f) ---> c";
642
0db578095e6a CCL/Gfp/coinduct2, coinduct3: modified proofs to suppress deep unification
lcp
parents: 289
diff changeset
    32
by (rtac applyV 1);
0db578095e6a CCL/Gfp/coinduct2, coinduct3: modified proofs to suppress deep unification
lcp
parents: 289
diff changeset
    33
by (rtac lamV 1);
0db578095e6a CCL/Gfp/coinduct2, coinduct3: modified proofs to suppress deep unification
lcp
parents: 289
diff changeset
    34
by (resolve_tac prems 1);
757
2ca12511676d added qed and qed_goal[w]
clasohm
parents: 642
diff changeset
    35
qed "fixV";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    36
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    37
val prems = goalw thy [letrec_def]
3837
d7f033c74b38 fixed dots;
wenzelm
parents: 1459
diff changeset
    38
    "h(t,%y. letrec g x be h(x,g) in g(y)) ---> c ==> \
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    39
\                  letrec g x be h(x,g) in g(t) ---> c";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    40
by (REPEAT (resolve_tac (prems @ [fixV,applyV,lamV]) 1));
757
2ca12511676d added qed and qed_goal[w]
clasohm
parents: 642
diff changeset
    41
qed "letrecV";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    42
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    43
EVal_rls := !EVal_rls @ [letV,letrecV,fixV];
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    44
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    45
fun mk_V_rl s = prove_goalw thy data_defs s (fn prems => [ceval_tac prems]);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    46
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    47
val V_rls = map mk_V_rl 
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    48
             ["true ---> true",
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    49
              "false ---> false",
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    50
              "[| b--->true;  t--->c |] ==> if b then t else u ---> c",
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    51
              "[| b--->false;  u--->c |] ==> if b then t else u ---> c",
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    52
              "<a,b> ---> <a,b>",
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    53
              "[| t ---> <a,b>;  h(a,b) ---> c |] ==> split(t,h) ---> c",
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    54
              "zero ---> zero",
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    55
              "succ(n) ---> succ(n)",
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    56
              "[| n ---> zero; t ---> c |] ==> ncase(n,t,u) ---> c",
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    57
              "[| n ---> succ(x); u(x) ---> c |] ==> ncase(n,t,u) ---> c",
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    58
              "[| n ---> zero; t ---> c |] ==> nrec(n,t,u) ---> c",
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    59
              "[| n--->succ(x); u(x,nrec(x,t,u))--->c |] ==> nrec(n,t,u)--->c",
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    60
              "[] ---> []",
289
78541329ff35 changed "." to "$" to eliminate ambiguity
clasohm
parents: 0
diff changeset
    61
              "h$t ---> h$t",
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    62
              "[| l ---> []; t ---> c |] ==> lcase(l,t,u) ---> c",
289
78541329ff35 changed "." to "$" to eliminate ambiguity
clasohm
parents: 0
diff changeset
    63
              "[| l ---> x$xs; u(x,xs) ---> c |] ==> lcase(l,t,u) ---> c",
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    64
              "[| l ---> []; t ---> c |] ==> lrec(l,t,u) ---> c",
289
78541329ff35 changed "." to "$" to eliminate ambiguity
clasohm
parents: 0
diff changeset
    65
              "[| l--->x$xs; u(x,xs,lrec(xs,t,u))--->c |] ==> lrec(l,t,u)--->c"];
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    66
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    67
EVal_rls := !EVal_rls @ V_rls;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    68
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    69
(* Factorial *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    70
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    71
val prems = goal thy
3837
d7f033c74b38 fixed dots;
wenzelm
parents: 1459
diff changeset
    72
    "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
    73
\              in f(succ(succ(zero))) ---> ?a";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    74
by (ceval_tac []);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    75
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    76
val prems = goal thy
3837
d7f033c74b38 fixed dots;
wenzelm
parents: 1459
diff changeset
    77
    "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
    78
\              in f(succ(succ(succ(zero)))) ---> ?a";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    79
by (ceval_tac []);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    80
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    81
(* Less Than Or Equal *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    82
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    83
fun isle x y = prove_goal thy 
3837
d7f033c74b38 fixed dots;
wenzelm
parents: 1459
diff changeset
    84
    ("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
    85
\              in f(<"^x^","^y^">) ---> ?a")
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    86
    (fn prems => [ceval_tac []]);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    87
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    88
isle "succ(zero)" "succ(zero)";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    89
isle "succ(zero)" "succ(succ(succ(succ(zero))))";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    90
isle "succ(succ(succ(succ(succ(zero)))))" "succ(succ(succ(succ(zero))))";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    91
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    92
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    93
(* Reverse *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    94
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    95
val prems = goal thy
3837
d7f033c74b38 fixed dots;
wenzelm
parents: 1459
diff changeset
    96
    "letrec id l be lcase(l,[],%x xs. x$id(xs)) \
289
78541329ff35 changed "." to "$" to eliminate ambiguity
clasohm
parents: 0
diff changeset
    97
\              in id(zero$succ(zero)$[]) ---> ?a";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    98
by (ceval_tac []);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    99
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   100
val prems = goal thy
3837
d7f033c74b38 fixed dots;
wenzelm
parents: 1459
diff changeset
   101
    "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
   102
\              in rev(zero$succ(zero)$(succ((lam x. x)`succ(zero)))$([])) ---> ?a";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   103
by (ceval_tac []);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   104