src/CCL/Term.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:
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 5062
diff changeset
     1
(*  Title:      CCL/Term.ML
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     2
    ID:         $Id$
1459
d12da312eff4 expanded tabs
clasohm
parents: 1087
diff changeset
     3
    Author:     Martin Coen, Cambridge University Computer Laboratory
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     4
    Copyright   1993  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
val simp_can_defs = [one_def,inl_def,inr_def];
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     8
val simp_ncan_defs = [if_def,when_def,split_def,fst_def,snd_def,thd_def];
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     9
val simp_defs = simp_can_defs @ simp_ncan_defs;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    10
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    11
val ind_can_defs = [zero_def,succ_def,nil_def,cons_def];
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    12
val ind_ncan_defs = [ncase_def,nrec_def,lcase_def,lrec_def];
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    13
val ind_defs = ind_can_defs @ ind_ncan_defs;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    14
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    15
val data_defs = simp_defs @ ind_defs @ [napply_def];
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    16
val genrec_defs = [letrec_def,letrec2_def,letrec3_def];
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    17
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    18
(*** Beta Rules, including strictness ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    19
5062
fbdb0b541314 isatool fixgoal;
wenzelm
parents: 3837
diff changeset
    20
Goalw [let_def] "~ t=bot--> let x be t in f(x) = f(t)";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    21
by (res_inst_tac [("t","t")] term_case 1);
8
c3d2c6dcf3f0 Installation of new simplfier. Previously appeared to set up the old
lcp
parents: 0
diff changeset
    22
by (ALLGOALS(simp_tac(CCL_ss addsimps [caseBtrue,caseBfalse,caseBpair,caseBlam])));
1087
c1ccf6679a96 replaced store_thm by bind_thm
clasohm
parents: 757
diff changeset
    23
bind_thm("letB", result() RS mp);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    24
5062
fbdb0b541314 isatool fixgoal;
wenzelm
parents: 3837
diff changeset
    25
Goalw [let_def] "let x be bot in f(x) = bot";
642
0db578095e6a CCL/Gfp/coinduct2, coinduct3: modified proofs to suppress deep unification
lcp
parents: 289
diff changeset
    26
by (rtac caseBbot 1);
757
2ca12511676d added qed and qed_goal[w]
clasohm
parents: 642
diff changeset
    27
qed "letBabot";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    28
5062
fbdb0b541314 isatool fixgoal;
wenzelm
parents: 3837
diff changeset
    29
Goalw [let_def] "let x be t in bot = bot";
642
0db578095e6a CCL/Gfp/coinduct2, coinduct3: modified proofs to suppress deep unification
lcp
parents: 289
diff changeset
    30
by (resolve_tac ([caseBbot] RL [term_case]) 1);
8
c3d2c6dcf3f0 Installation of new simplfier. Previously appeared to set up the old
lcp
parents: 0
diff changeset
    31
by (ALLGOALS(simp_tac(CCL_ss addsimps [caseBtrue,caseBfalse,caseBpair,caseBlam])));
757
2ca12511676d added qed and qed_goal[w]
clasohm
parents: 642
diff changeset
    32
qed "letBbbot";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    33
5062
fbdb0b541314 isatool fixgoal;
wenzelm
parents: 3837
diff changeset
    34
Goalw [apply_def] "(lam x. b(x)) ` a = b(a)";
8
c3d2c6dcf3f0 Installation of new simplfier. Previously appeared to set up the old
lcp
parents: 0
diff changeset
    35
by (ALLGOALS(simp_tac(CCL_ss addsimps [caseBtrue,caseBfalse,caseBpair,caseBlam])));
757
2ca12511676d added qed and qed_goal[w]
clasohm
parents: 642
diff changeset
    36
qed "applyB";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    37
5062
fbdb0b541314 isatool fixgoal;
wenzelm
parents: 3837
diff changeset
    38
Goalw [apply_def] "bot ` a = bot";
642
0db578095e6a CCL/Gfp/coinduct2, coinduct3: modified proofs to suppress deep unification
lcp
parents: 289
diff changeset
    39
by (rtac caseBbot 1);
757
2ca12511676d added qed and qed_goal[w]
clasohm
parents: 642
diff changeset
    40
qed "applyBbot";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    41
5062
fbdb0b541314 isatool fixgoal;
wenzelm
parents: 3837
diff changeset
    42
Goalw [fix_def] "fix(f) = f(fix(f))";
642
0db578095e6a CCL/Gfp/coinduct2, coinduct3: modified proofs to suppress deep unification
lcp
parents: 289
diff changeset
    43
by (resolve_tac [applyB RS ssubst] 1 THEN rtac refl 1);
757
2ca12511676d added qed and qed_goal[w]
clasohm
parents: 642
diff changeset
    44
qed "fixB";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    45
5062
fbdb0b541314 isatool fixgoal;
wenzelm
parents: 3837
diff changeset
    46
Goalw [letrec_def]
3837
d7f033c74b38 fixed dots;
wenzelm
parents: 2035
diff changeset
    47
      "letrec g x be h(x,g) in g(a) = h(a,%y. letrec g x be h(x,g) in g(y))";
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 5062
diff changeset
    48
by (resolve_tac [fixB RS ssubst] 1 THEN
642
0db578095e6a CCL/Gfp/coinduct2, coinduct3: modified proofs to suppress deep unification
lcp
parents: 289
diff changeset
    49
    resolve_tac [applyB RS ssubst] 1 THEN rtac refl 1);
757
2ca12511676d added qed and qed_goal[w]
clasohm
parents: 642
diff changeset
    50
qed "letrecB";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    51
8
c3d2c6dcf3f0 Installation of new simplfier. Previously appeared to set up the old
lcp
parents: 0
diff changeset
    52
val rawBs = caseBs @ [applyB,applyBbot];
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    53
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 5062
diff changeset
    54
fun raw_mk_beta_rl defs s = prove_goalw (the_context ()) defs s
2035
e329b36d9136 Ran expandshort; used stac instead of ssubst
paulson
parents: 1459
diff changeset
    55
           (fn _ => [stac letrecB 1,
1459
d12da312eff4 expanded tabs
clasohm
parents: 1087
diff changeset
    56
                     simp_tac (CCL_ss addsimps rawBs) 1]);
8
c3d2c6dcf3f0 Installation of new simplfier. Previously appeared to set up the old
lcp
parents: 0
diff changeset
    57
fun mk_beta_rl s = raw_mk_beta_rl data_defs s;
c3d2c6dcf3f0 Installation of new simplfier. Previously appeared to set up the old
lcp
parents: 0
diff changeset
    58
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 5062
diff changeset
    59
fun raw_mk_beta_rl defs s = prove_goalw (the_context ()) defs s
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 5062
diff changeset
    60
           (fn _ => [simp_tac (CCL_ss addsimps rawBs
2035
e329b36d9136 Ran expandshort; used stac instead of ssubst
paulson
parents: 1459
diff changeset
    61
                               setloop (stac letrecB)) 1]);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    62
fun mk_beta_rl s = raw_mk_beta_rl data_defs s;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    63
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    64
val ifBtrue    = mk_beta_rl "if true then t else u = t";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    65
val ifBfalse   = mk_beta_rl "if false then t else u = u";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    66
val ifBbot     = mk_beta_rl "if bot then t else u = bot";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    67
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    68
val whenBinl   = mk_beta_rl "when(inl(a),t,u) = t(a)";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    69
val whenBinr   = mk_beta_rl "when(inr(a),t,u) = u(a)";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    70
val whenBbot   = mk_beta_rl "when(bot,t,u) = bot";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    71
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    72
val splitB     = mk_beta_rl "split(<a,b>,h) = h(a,b)";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    73
val splitBbot  = mk_beta_rl "split(bot,h) = bot";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    74
val fstB       = mk_beta_rl "fst(<a,b>) = a";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    75
val fstBbot    = mk_beta_rl "fst(bot) = bot";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    76
val sndB       = mk_beta_rl "snd(<a,b>) = b";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    77
val sndBbot    = mk_beta_rl "snd(bot) = bot";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    78
val thdB       = mk_beta_rl "thd(<a,<b,c>>) = c";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    79
val thdBbot    = mk_beta_rl "thd(bot) = bot";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    80
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    81
val ncaseBzero = mk_beta_rl "ncase(zero,t,u) = t";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    82
val ncaseBsucc = mk_beta_rl "ncase(succ(n),t,u) = u(n)";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    83
val ncaseBbot  = mk_beta_rl "ncase(bot,t,u) = bot";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    84
val nrecBzero  = mk_beta_rl "nrec(zero,t,u) = t";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    85
val nrecBsucc  = mk_beta_rl "nrec(succ(n),t,u) = u(n,nrec(n,t,u))";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    86
val nrecBbot   = mk_beta_rl "nrec(bot,t,u) = bot";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    87
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    88
val lcaseBnil  = mk_beta_rl "lcase([],t,u) = t";
289
78541329ff35 changed "." to "$" to eliminate ambiguity
clasohm
parents: 8
diff changeset
    89
val lcaseBcons = mk_beta_rl "lcase(x$xs,t,u) = u(x,xs)";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    90
val lcaseBbot  = mk_beta_rl "lcase(bot,t,u) = bot";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    91
val lrecBnil   = mk_beta_rl "lrec([],t,u) = t";
289
78541329ff35 changed "." to "$" to eliminate ambiguity
clasohm
parents: 8
diff changeset
    92
val lrecBcons  = mk_beta_rl "lrec(x$xs,t,u) = u(x,xs,lrec(xs,t,u))";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    93
val lrecBbot   = mk_beta_rl "lrec(bot,t,u) = bot";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    94
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    95
val letrec2B = raw_mk_beta_rl (data_defs @ [letrec2_def])
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    96
       "letrec g x y be h(x,y,g) in g(p,q) = \
3837
d7f033c74b38 fixed dots;
wenzelm
parents: 2035
diff changeset
    97
\                     h(p,q,%u v. letrec g x y be h(x,y,g) in g(u,v))";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    98
val letrec3B = raw_mk_beta_rl (data_defs @ [letrec3_def])
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    99
       "letrec g x y z be h(x,y,z,g) in g(p,q,r) = \
3837
d7f033c74b38 fixed dots;
wenzelm
parents: 2035
diff changeset
   100
\                     h(p,q,r,%u v w. letrec g x y z be h(x,y,z,g) in g(u,v,w))";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   101
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   102
val napplyBzero   = mk_beta_rl "f^zero`a = a";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   103
val napplyBsucc   = mk_beta_rl "f^succ(n)`a = f(f^n`a)";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   104
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   105
val termBs = [letB,applyB,applyBbot,splitB,splitBbot,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   106
              fstB,fstBbot,sndB,sndBbot,thdB,thdBbot,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   107
              ifBtrue,ifBfalse,ifBbot,whenBinl,whenBinr,whenBbot,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   108
              ncaseBzero,ncaseBsucc,ncaseBbot,nrecBzero,nrecBsucc,nrecBbot,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   109
              lcaseBnil,lcaseBcons,lcaseBbot,lrecBnil,lrecBcons,lrecBbot,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   110
              napplyBzero,napplyBsucc];
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   111
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   112
(*** Constructors are injective ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   113
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 5062
diff changeset
   114
val term_injs = map (mk_inj_rl (the_context ())
1459
d12da312eff4 expanded tabs
clasohm
parents: 1087
diff changeset
   115
                     [applyB,splitB,whenBinl,whenBinr,ncaseBsucc,lcaseBcons])
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   116
               ["(inl(a) = inl(a')) <-> (a=a')",
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   117
                "(inr(a) = inr(a')) <-> (a=a')",
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   118
                "(succ(a) = succ(a')) <-> (a=a')",
289
78541329ff35 changed "." to "$" to eliminate ambiguity
clasohm
parents: 8
diff changeset
   119
                "(a$b = a'$b') <-> (a=a' & b=b')"];
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   120
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   121
(*** Constructors are distinct ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   122
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 5062
diff changeset
   123
val term_dstncts = mkall_dstnct_thms (the_context ()) data_defs (ccl_injs @ term_injs)
289
78541329ff35 changed "." to "$" to eliminate ambiguity
clasohm
parents: 8
diff changeset
   124
                    [["bot","inl","inr"],["bot","zero","succ"],["bot","nil","op $"]];
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   125
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   126
(*** Rules for pre-order [= ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   127
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   128
local
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 5062
diff changeset
   129
  fun mk_thm s = prove_goalw (the_context ()) data_defs s (fn _ =>
8
c3d2c6dcf3f0 Installation of new simplfier. Previously appeared to set up the old
lcp
parents: 0
diff changeset
   130
                  [simp_tac (ccl_ss addsimps (ccl_porews)) 1]);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   131
in
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   132
  val term_porews = map mk_thm ["inl(a) [= inl(a') <-> a [= a'",
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   133
                                "inr(b) [= inr(b') <-> b [= b'",
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   134
                                "succ(n) [= succ(n') <-> n [= n'",
289
78541329ff35 changed "." to "$" to eliminate ambiguity
clasohm
parents: 8
diff changeset
   135
                                "x$xs [= x'$xs' <-> x [= x'  & xs [= xs'"];
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   136
end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   137
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   138
(*** Rewriting and Proving ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   139
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   140
val term_rews = termBs @ term_injs @ term_dstncts @ ccl_porews @ term_porews;
8
c3d2c6dcf3f0 Installation of new simplfier. Previously appeared to set up the old
lcp
parents: 0
diff changeset
   141
val term_ss = ccl_ss addsimps term_rews;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   142
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 5062
diff changeset
   143
val term_cs = ccl_cs addSEs (term_dstncts RL [notE])
8
c3d2c6dcf3f0 Installation of new simplfier. Previously appeared to set up the old
lcp
parents: 0
diff changeset
   144
                     addSDs (XH_to_Ds term_injs);