src/CCL/Term.thy
author wenzelm
Mon, 09 Oct 2006 02:20:10 +0200
changeset 20917 803c94363ccc
parent 20140 98acc6d0fab6
child 24790 3be1580de4cc
permissions -rw-r--r--
reorderd ML/lemmas (Why!?);
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
     1
(*  Title:      CCL/Term.thy
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     2
    ID:         $Id$
1474
3f7d67927fe2 expanded tabs
clasohm
parents: 1149
diff changeset
     3
    Author:     Martin Coen
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
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
     7
header {* Definitions of usual program constructs in CCL *}
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
     8
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
     9
theory Term
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
    10
imports CCL
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
    11
begin
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    12
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    13
consts
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    14
998
91d09e262799 Gave tighter priorities to if, napply and the let-forms to
lcp
parents: 610
diff changeset
    15
  one        :: "i"
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    16
19796
d86e7b1fc472 quoted "if";
wenzelm
parents: 17781
diff changeset
    17
  "if"       :: "[i,i,i]=>i"           ("(3if _/ then _/ else _)" [0,0,60] 60)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    18
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
    19
  inl        :: "i=>i"
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
    20
  inr        :: "i=>i"
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
    21
  when       :: "[i,i=>i,i=>i]=>i"
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    22
998
91d09e262799 Gave tighter priorities to if, napply and the let-forms to
lcp
parents: 610
diff changeset
    23
  split      :: "[i,[i,i]=>i]=>i"
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
    24
  fst        :: "i=>i"
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
    25
  snd        :: "i=>i"
998
91d09e262799 Gave tighter priorities to if, napply and the let-forms to
lcp
parents: 610
diff changeset
    26
  thd        :: "i=>i"
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    27
998
91d09e262799 Gave tighter priorities to if, napply and the let-forms to
lcp
parents: 610
diff changeset
    28
  zero       :: "i"
91d09e262799 Gave tighter priorities to if, napply and the let-forms to
lcp
parents: 610
diff changeset
    29
  succ       :: "i=>i"
91d09e262799 Gave tighter priorities to if, napply and the let-forms to
lcp
parents: 610
diff changeset
    30
  ncase      :: "[i,i,i=>i]=>i"
91d09e262799 Gave tighter priorities to if, napply and the let-forms to
lcp
parents: 610
diff changeset
    31
  nrec       :: "[i,i,[i,i]=>i]=>i"
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    32
998
91d09e262799 Gave tighter priorities to if, napply and the let-forms to
lcp
parents: 610
diff changeset
    33
  nil        :: "i"                        ("([])")
91d09e262799 Gave tighter priorities to if, napply and the let-forms to
lcp
parents: 610
diff changeset
    34
  "$"        :: "[i,i]=>i"                 (infixr 80)
91d09e262799 Gave tighter priorities to if, napply and the let-forms to
lcp
parents: 610
diff changeset
    35
  lcase      :: "[i,i,[i,i]=>i]=>i"
91d09e262799 Gave tighter priorities to if, napply and the let-forms to
lcp
parents: 610
diff changeset
    36
  lrec       :: "[i,i,[i,i,i]=>i]=>i"
91d09e262799 Gave tighter priorities to if, napply and the let-forms to
lcp
parents: 610
diff changeset
    37
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
    38
  "let"      :: "[i,i=>i]=>i"
998
91d09e262799 Gave tighter priorities to if, napply and the let-forms to
lcp
parents: 610
diff changeset
    39
  letrec     :: "[[i,i=>i]=>i,(i=>i)=>i]=>i"
91d09e262799 Gave tighter priorities to if, napply and the let-forms to
lcp
parents: 610
diff changeset
    40
  letrec2    :: "[[i,i,i=>i=>i]=>i,(i=>i=>i)=>i]=>i"
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
    41
  letrec3    :: "[[i,i,i,i=>i=>i=>i]=>i,(i=>i=>i=>i)=>i]=>i"
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    42
14765
bafb24c150c1 proper use of 'syntax';
wenzelm
parents: 3837
diff changeset
    43
syntax
998
91d09e262799 Gave tighter priorities to if, napply and the let-forms to
lcp
parents: 610
diff changeset
    44
  "@let"     :: "[idt,i,i]=>i"             ("(3let _ be _/ in _)"
1474
3f7d67927fe2 expanded tabs
clasohm
parents: 1149
diff changeset
    45
                        [0,0,60] 60)
998
91d09e262799 Gave tighter priorities to if, napply and the let-forms to
lcp
parents: 610
diff changeset
    46
91d09e262799 Gave tighter priorities to if, napply and the let-forms to
lcp
parents: 610
diff changeset
    47
  "@letrec"  :: "[idt,idt,i,i]=>i"         ("(3letrec _ _ be _/ in _)"
1474
3f7d67927fe2 expanded tabs
clasohm
parents: 1149
diff changeset
    48
                        [0,0,0,60] 60)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    49
998
91d09e262799 Gave tighter priorities to if, napply and the let-forms to
lcp
parents: 610
diff changeset
    50
  "@letrec2" :: "[idt,idt,idt,i,i]=>i"     ("(3letrec _ _ _ be _/ in _)"
1474
3f7d67927fe2 expanded tabs
clasohm
parents: 1149
diff changeset
    51
                        [0,0,0,0,60] 60)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    52
998
91d09e262799 Gave tighter priorities to if, napply and the let-forms to
lcp
parents: 610
diff changeset
    53
  "@letrec3" :: "[idt,idt,idt,idt,i,i]=>i" ("(3letrec _ _ _ _ be _/ in _)"
1474
3f7d67927fe2 expanded tabs
clasohm
parents: 1149
diff changeset
    54
                        [0,0,0,0,0,60] 60)
998
91d09e262799 Gave tighter priorities to if, napply and the let-forms to
lcp
parents: 610
diff changeset
    55
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
    56
ML {*
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    57
(** Quantifier translations: variable binding **)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    58
17781
32bb237158a5 print_translation: does not handle _idtdummy;
wenzelm
parents: 17456
diff changeset
    59
(* FIXME does not handle "_idtdummy" *)
2709
241fffc25284 added comment;
wenzelm
parents: 1474
diff changeset
    60
(* FIXME should use Syntax.mark_bound(T), Syntax.variant_abs' *)
241fffc25284 added comment;
wenzelm
parents: 1474
diff changeset
    61
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    62
fun let_tr [Free(id,T),a,b] = Const("let",dummyT) $ a $ absfree(id,T,b);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    63
fun let_tr' [a,Abs(id,T,b)] =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    64
     let val (id',b') = variant_abs(id,T,b)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    65
     in Const("@let",dummyT) $ Free(id',T) $ a $ b' end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    66
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
    67
fun letrec_tr [Free(f,S),Free(x,T),a,b] =
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    68
      Const("letrec",dummyT) $ absfree(x,T,absfree(f,S,a)) $ absfree(f,S,b);
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
    69
fun letrec2_tr [Free(f,S),Free(x,T),Free(y,U),a,b] =
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    70
      Const("letrec2",dummyT) $ absfree(x,T,absfree(y,U,absfree(f,S,a))) $ absfree(f,S,b);
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
    71
fun letrec3_tr [Free(f,S),Free(x,T),Free(y,U),Free(z,V),a,b] =
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    72
      Const("letrec3",dummyT) $ absfree(x,T,absfree(y,U,absfree(z,U,absfree(f,S,a)))) $ absfree(f,S,b);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    73
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    74
fun letrec_tr' [Abs(x,T,Abs(f,S,a)),Abs(ff,SS,b)] =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    75
     let val (f',b')  = variant_abs(ff,SS,b)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    76
         val (_,a'') = variant_abs(f,S,a)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    77
         val (x',a')  = variant_abs(x,T,a'')
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    78
     in Const("@letrec",dummyT) $ Free(f',SS) $ Free(x',T) $ a' $ b' end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    79
fun letrec2_tr' [Abs(x,T,Abs(y,U,Abs(f,S,a))),Abs(ff,SS,b)] =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    80
     let val (f',b') = variant_abs(ff,SS,b)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    81
         val ( _,a1) = variant_abs(f,S,a)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    82
         val (y',a2) = variant_abs(y,U,a1)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    83
         val (x',a') = variant_abs(x,T,a2)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    84
     in Const("@letrec2",dummyT) $ Free(f',SS) $ Free(x',T) $ Free(y',U) $ a' $ b'
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    85
      end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    86
fun letrec3_tr' [Abs(x,T,Abs(y,U,Abs(z,V,Abs(f,S,a)))),Abs(ff,SS,b)] =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    87
     let val (f',b') = variant_abs(ff,SS,b)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    88
         val ( _,a1) = variant_abs(f,S,a)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    89
         val (z',a2) = variant_abs(z,V,a1)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    90
         val (y',a3) = variant_abs(y,U,a2)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    91
         val (x',a') = variant_abs(x,T,a3)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    92
     in Const("@letrec3",dummyT) $ Free(f',SS) $ Free(x',T) $ Free(y',U) $ Free(z',V) $ a' $ b'
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    93
      end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    94
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
    95
*}
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
    96
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
    97
parse_translation {*
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
    98
  [("@let",       let_tr),
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
    99
   ("@letrec",    letrec_tr),
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   100
   ("@letrec2",   letrec2_tr),
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   101
   ("@letrec3",   letrec3_tr)] *}
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   102
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   103
print_translation {*
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   104
  [("let",       let_tr'),
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   105
   ("letrec",    letrec_tr'),
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   106
   ("letrec2",   letrec2_tr'),
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   107
   ("letrec3",   letrec3_tr')] *}
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   108
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   109
consts
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   110
  napply     :: "[i=>i,i,i]=>i"            ("(_ ^ _ ` _)" [56,56,56] 56)
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   111
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   112
axioms
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   113
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   114
  one_def:                    "one == true"
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   115
  if_def:     "if b then t else u  == case(b,t,u,% x y. bot,%v. bot)"
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   116
  inl_def:                 "inl(a) == <true,a>"
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   117
  inr_def:                 "inr(b) == <false,b>"
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   118
  when_def:           "when(t,f,g) == split(t,%b x. if b then f(x) else g(x))"
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   119
  split_def:           "split(t,f) == case(t,bot,bot,f,%u. bot)"
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   120
  fst_def:                 "fst(t) == split(t,%x y. x)"
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   121
  snd_def:                 "snd(t) == split(t,%x y. y)"
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   122
  thd_def:                 "thd(t) == split(t,%x p. split(p,%y z. z))"
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   123
  zero_def:                  "zero == inl(one)"
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   124
  succ_def:               "succ(n) == inr(n)"
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   125
  ncase_def:         "ncase(n,b,c) == when(n,%x. b,%y. c(y))"
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   126
  nrec_def:          " nrec(n,b,c) == letrec g x be ncase(x,b,%y. c(y,g(y))) in g(n)"
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   127
  nil_def:                     "[] == inl(one)"
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   128
  cons_def:                   "h$t == inr(<h,t>)"
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   129
  lcase_def:         "lcase(l,b,c) == when(l,%x. b,%y. split(y,c))"
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   130
  lrec_def:           "lrec(l,b,c) == letrec g x be lcase(x,b,%h t. c(h,t,g(t))) in g(l)"
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   131
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   132
  let_def:  "let x be t in f(x) == case(t,f(true),f(false),%x y. f(<x,y>),%u. f(lam x. u(x)))"
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   133
  letrec_def:
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   134
  "letrec g x be h(x,g) in b(g) == b(%x. fix(%f. lam x. h(x,%y. f`y))`x)"
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   135
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   136
  letrec2_def:  "letrec g x y be h(x,y,g) in f(g)==
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   137
               letrec g' p be split(p,%x y. h(x,y,%u v. g'(<u,v>)))
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   138
                          in f(%x y. g'(<x,y>))"
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   139
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   140
  letrec3_def:  "letrec g x y z be h(x,y,z,g) in f(g) ==
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   141
             letrec g' p be split(p,%x xs. split(xs,%y z. h(x,y,z,%u v w. g'(<u,<v,w>>))))
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   142
                          in f(%x y z. g'(<x,<y,z>>))"
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   143
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   144
  napply_def: "f ^n` a == nrec(n,a,%x g. f(g))"
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   145
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   146
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   147
lemmas simp_can_defs = one_def inl_def inr_def
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   148
  and simp_ncan_defs = if_def when_def split_def fst_def snd_def thd_def
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   149
lemmas simp_defs = simp_can_defs simp_ncan_defs
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   150
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   151
lemmas ind_can_defs = zero_def succ_def nil_def cons_def
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   152
  and ind_ncan_defs = ncase_def nrec_def lcase_def lrec_def
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   153
lemmas ind_defs = ind_can_defs ind_ncan_defs
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   154
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   155
lemmas data_defs = simp_defs ind_defs napply_def
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   156
  and genrec_defs = letrec_def letrec2_def letrec3_def
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   157
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   158
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   159
subsection {* Beta Rules, including strictness *}
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   160
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   161
lemma letB: "~ t=bot ==> let x be t in f(x) = f(t)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   162
  apply (unfold let_def)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   163
  apply (erule rev_mp)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   164
  apply (rule_tac t = "t" in term_case)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   165
      apply (simp_all add: caseBtrue caseBfalse caseBpair caseBlam)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   166
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   167
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   168
lemma letBabot: "let x be bot in f(x) = bot"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   169
  apply (unfold let_def)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   170
  apply (rule caseBbot)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   171
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   172
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   173
lemma letBbbot: "let x be t in bot = bot"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   174
  apply (unfold let_def)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   175
  apply (rule_tac t = t in term_case)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   176
      apply (rule caseBbot)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   177
     apply (simp_all add: caseBtrue caseBfalse caseBpair caseBlam)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   178
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   179
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   180
lemma applyB: "(lam x. b(x)) ` a = b(a)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   181
  apply (unfold apply_def)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   182
  apply (simp add: caseBtrue caseBfalse caseBpair caseBlam)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   183
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   184
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   185
lemma applyBbot: "bot ` a = bot"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   186
  apply (unfold apply_def)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   187
  apply (rule caseBbot)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   188
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   189
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   190
lemma fixB: "fix(f) = f(fix(f))"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   191
  apply (unfold fix_def)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   192
  apply (rule applyB [THEN ssubst], rule refl)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   193
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   194
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   195
lemma letrecB:
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   196
    "letrec g x be h(x,g) in g(a) = h(a,%y. letrec g x be h(x,g) in g(y))"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   197
  apply (unfold letrec_def)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   198
  apply (rule fixB [THEN ssubst], rule applyB [THEN ssubst], rule refl)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   199
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   200
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   201
lemmas rawBs = caseBs applyB applyBbot
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   202
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   203
ML {*
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   204
local
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   205
  val letrecB = thm "letrecB"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   206
  val rawBs = thms "rawBs"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   207
  val data_defs = thms "data_defs"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   208
in
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   209
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   210
fun raw_mk_beta_rl defs s = prove_goalw (the_context ()) defs s
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   211
           (fn _ => [stac letrecB 1,
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   212
                     simp_tac (simpset () addsimps rawBs) 1]);
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   213
fun mk_beta_rl s = raw_mk_beta_rl data_defs s;
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   214
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   215
fun raw_mk_beta_rl defs s = prove_goalw (the_context ()) defs s
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   216
           (fn _ => [simp_tac (simpset () addsimps rawBs
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   217
                               setloop (stac letrecB)) 1]);
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   218
fun mk_beta_rl s = raw_mk_beta_rl data_defs s;
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   219
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 14765
diff changeset
   220
end
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   221
*}
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   222
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   223
ML {*
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   224
bind_thm ("ifBtrue", mk_beta_rl "if true then t else u = t");
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   225
bind_thm ("ifBfalse", mk_beta_rl "if false then t else u = u");
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   226
bind_thm ("ifBbot", mk_beta_rl "if bot then t else u = bot");
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   227
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   228
bind_thm ("whenBinl", mk_beta_rl "when(inl(a),t,u) = t(a)");
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   229
bind_thm ("whenBinr", mk_beta_rl "when(inr(a),t,u) = u(a)");
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   230
bind_thm ("whenBbot", mk_beta_rl "when(bot,t,u) = bot");
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   231
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   232
bind_thm ("splitB", mk_beta_rl "split(<a,b>,h) = h(a,b)");
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   233
bind_thm ("splitBbot", mk_beta_rl "split(bot,h) = bot");
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   234
bind_thm ("fstB", mk_beta_rl "fst(<a,b>) = a");
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   235
bind_thm ("fstBbot", mk_beta_rl "fst(bot) = bot");
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   236
bind_thm ("sndB", mk_beta_rl "snd(<a,b>) = b");
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   237
bind_thm ("sndBbot", mk_beta_rl "snd(bot) = bot");
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   238
bind_thm ("thdB", mk_beta_rl "thd(<a,<b,c>>) = c");
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   239
bind_thm ("thdBbot", mk_beta_rl "thd(bot) = bot");
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   240
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   241
bind_thm ("ncaseBzero", mk_beta_rl "ncase(zero,t,u) = t");
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   242
bind_thm ("ncaseBsucc", mk_beta_rl "ncase(succ(n),t,u) = u(n)");
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   243
bind_thm ("ncaseBbot", mk_beta_rl "ncase(bot,t,u) = bot");
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   244
bind_thm ("nrecBzero", mk_beta_rl "nrec(zero,t,u) = t");
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   245
bind_thm ("nrecBsucc", mk_beta_rl "nrec(succ(n),t,u) = u(n,nrec(n,t,u))");
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   246
bind_thm ("nrecBbot", mk_beta_rl "nrec(bot,t,u) = bot");
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   247
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   248
bind_thm ("lcaseBnil", mk_beta_rl "lcase([],t,u) = t");
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   249
bind_thm ("lcaseBcons", mk_beta_rl "lcase(x$xs,t,u) = u(x,xs)");
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   250
bind_thm ("lcaseBbot", mk_beta_rl "lcase(bot,t,u) = bot");
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   251
bind_thm ("lrecBnil", mk_beta_rl "lrec([],t,u) = t");
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   252
bind_thm ("lrecBcons", mk_beta_rl "lrec(x$xs,t,u) = u(x,xs,lrec(xs,t,u))");
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   253
bind_thm ("lrecBbot", mk_beta_rl "lrec(bot,t,u) = bot");
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   254
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   255
bind_thm ("letrec2B", raw_mk_beta_rl (thms "data_defs" @ [thm "letrec2_def"])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   256
  "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))");
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   257
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   258
bind_thm ("letrec3B", raw_mk_beta_rl (thms "data_defs" @ [thm "letrec3_def"])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   259
  "letrec g x y z be h(x,y,z,g) in g(p,q,r) = h(p,q,r,%u v w. letrec g x y z be h(x,y,z,g) in g(u,v,w))");
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   260
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   261
bind_thm ("napplyBzero", mk_beta_rl "f^zero`a = a");
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   262
bind_thm ("napplyBsucc", mk_beta_rl "f^succ(n)`a = f(f^n`a)");
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   263
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   264
bind_thms ("termBs", [thm "letB", thm "applyB", thm "applyBbot", splitB,splitBbot,
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   265
  fstB,fstBbot,sndB,sndBbot,thdB,thdBbot,
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   266
  ifBtrue,ifBfalse,ifBbot,whenBinl,whenBinr,whenBbot,
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   267
  ncaseBzero,ncaseBsucc,ncaseBbot,nrecBzero,nrecBsucc,nrecBbot,
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   268
  lcaseBnil,lcaseBcons,lcaseBbot,lrecBnil,lrecBcons,lrecBbot,
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   269
  napplyBzero,napplyBsucc]);
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   270
*}
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   271
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   272
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   273
subsection {* Constructors are injective *}
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   274
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   275
ML {*
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   276
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   277
bind_thms ("term_injs", map (mk_inj_rl (the_context ())
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   278
  [thm "applyB", thm "splitB", thm "whenBinl", thm "whenBinr", thm "ncaseBsucc", thm "lcaseBcons"])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   279
    ["(inl(a) = inl(a')) <-> (a=a')",
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   280
     "(inr(a) = inr(a')) <-> (a=a')",
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   281
     "(succ(a) = succ(a')) <-> (a=a')",
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   282
     "(a$b = a'$b') <-> (a=a' & b=b')"])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   283
*}
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   284
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   285
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   286
subsection {* Constructors are distinct *}
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   287
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   288
ML {*
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   289
bind_thms ("term_dstncts",
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   290
  mkall_dstnct_thms (the_context ()) (thms "data_defs") (thms "ccl_injs" @ thms "term_injs")
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   291
    [["bot","inl","inr"], ["bot","zero","succ"], ["bot","nil","op $"]]);
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   292
*}
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   293
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   294
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   295
subsection {* Rules for pre-order @{text "[="} *}
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   296
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   297
ML {*
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   298
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   299
local
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   300
  fun mk_thm s = prove_goalw (the_context ()) (thms "data_defs") s (fn _ =>
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   301
    [simp_tac (simpset () addsimps (thms "ccl_porews")) 1])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   302
in
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   303
  val term_porews = map mk_thm ["inl(a) [= inl(a') <-> a [= a'",
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   304
                                "inr(b) [= inr(b') <-> b [= b'",
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   305
                                "succ(n) [= succ(n') <-> n [= n'",
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   306
                                "x$xs [= x'$xs' <-> x [= x'  & xs [= xs'"]
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   307
end;
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   308
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   309
bind_thms ("term_porews", term_porews);
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   310
*}
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   311
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   312
subsection {* Rewriting and Proving *}
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   313
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   314
ML {*
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   315
  bind_thms ("term_injDs", XH_to_Ds term_injs);
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   316
*}
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   317
20917
803c94363ccc reorderd ML/lemmas (Why!?);
wenzelm
parents: 20140
diff changeset
   318
lemmas term_rews = termBs term_injs term_dstncts ccl_porews term_porews
803c94363ccc reorderd ML/lemmas (Why!?);
wenzelm
parents: 20140
diff changeset
   319
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   320
lemmas [simp] = term_rews
20917
803c94363ccc reorderd ML/lemmas (Why!?);
wenzelm
parents: 20140
diff changeset
   321
lemmas [elim!] = term_dstncts [THEN notE]
803c94363ccc reorderd ML/lemmas (Why!?);
wenzelm
parents: 20140
diff changeset
   322
lemmas [dest!] = term_injDs
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   323
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 19796
diff changeset
   324
end