src/HOL/Induct/Exp.ML
author paulson
Thu, 08 May 1997 12:22:01 +0200
changeset 3144 04b0d8941365
parent 3120 c58423c20740
child 3145 809a2c9902f7
permissions -rw-r--r--
New proofs about WHILE and VALOF
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
     1
(*  Title:      HOL/Induct/Exp
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
     2
    ID:         $Id$
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
     4
    Copyright   1997  University of Cambridge
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
     5
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
     6
Example of Mutual Induction via Iteratived Inductive Definitions: Expressions
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
     7
*)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
     8
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
     9
open Exp;
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    10
3144
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
    11
AddIs eval.intrs;
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
    12
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    13
val eval_elim_cases = map (eval.mk_cases exp.simps)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    14
   ["(N(n),sigma) -|-> (n',s')", "(X(x),sigma) -|-> (n,s')",
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    15
    "(Op f a1 a2,sigma)  -|-> (n,s')",
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    16
    "(VALOF c RESULTIS e, s) -|-> (n, s1)"
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    17
   ];
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    18
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    19
AddSEs eval_elim_cases;
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    20
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    21
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    22
(** Make the induction rule look nicer -- though eta_contract makes the new
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    23
    version look worse than it is...**)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    24
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    25
goal thy "{((e,s),(n,s')). P e s n s'} = \
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    26
\         Collect (split (%v. split (split P v)))";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    27
by (rtac Collect_cong 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    28
by (split_all_tac 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    29
by (Simp_tac 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    30
val split_lemma = result();
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    31
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    32
(*New induction rule.  Note the form of the VALOF induction hypothesis*)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    33
val major::prems = goal thy
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    34
  "[| (e,s) -|-> (n,s');                                         \
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    35
\     !!n s. P (N n) s n s;                                      \
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    36
\     !!s x. P (X x) s (s x) s;                                  \
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    37
\     !!e0 e1 f n0 n1 s s0 s1.                                   \
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    38
\        [| (e0,s) -|-> (n0,s0); P e0 s n0 s0;                   \
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    39
\           (e1,s0) -|-> (n1,s1); P e1 s0 n1 s1                  \
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    40
\        |] ==> P (Op f e0 e1) s (f n0 n1) s1;                   \
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    41
\     !!c e n s s0 s1.                                           \
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    42
\        [| (c,s) -[eval Int {((e,s),(n,s')). P e s n s'}]-> s0; \
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    43
\           (e,s0) -|-> (n,s1); P e s0 n s1 |]                   \
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    44
\        ==> P (VALOF c RESULTIS e) s n s1                       \
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    45
\  |] ==> P e s n s'";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    46
by (rtac (major RS eval.induct) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    47
by (blast_tac (!claset addIs prems) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    48
by (blast_tac (!claset addIs prems) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    49
by (blast_tac (!claset addIs prems) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    50
by (fast_tac (!claset addIs prems addss (!simpset addsimps [split_lemma])) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    51
qed "eval_induct";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    52
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    53
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    54
(*Lemma for Function_eval.  The major premise is that (c,s) executes to s1
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    55
  using eval restricted to its functional part.  Note that the execution
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    56
  (c,s) -[eval]-> s2 can use unrestricted eval!  The reason is that 
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    57
  the execution (c,s) -[eval Int {...}]-> s1 assures us that execution is
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    58
  functional on the argument (c,s).
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    59
*)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    60
goal thy
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    61
    "!!x. (c,s) -[eval Int {((e,s),(n,s')). Unique (e,s) (n,s') eval}]-> s1 \
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    62
\         ==> (ALL s2. (c,s) -[eval]-> s2 --> s2=s1)";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    63
by (etac exec.induct 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    64
by (ALLGOALS Full_simp_tac);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    65
by (Blast_tac 3);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    66
by (Blast_tac 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    67
by (rewtac Unique_def);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    68
by (Blast_tac 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    69
by (Blast_tac 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    70
by (Blast_tac 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    71
by (blast_tac (!claset addEs [exec_WHILE_case]) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    72
by (thin_tac "(?c,s2) -[?ev]-> s3" 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    73
by (Step_tac 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    74
by (etac exec_WHILE_case 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    75
by (ALLGOALS Fast_tac);         (*Blast_tac: proof fails*)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    76
qed "com_Unique";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    77
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    78
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    79
(*Expression evaluation is functional, or deterministic*)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    80
goal thy "Function eval";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    81
by (simp_tac (!simpset addsimps [Function_def]) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    82
by (REPEAT (rtac allI 1));
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    83
by (rtac impI 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    84
by (etac eval_induct 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    85
by (dtac com_Unique 4);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    86
by (ALLGOALS (full_simp_tac (!simpset addsimps [Unique_def])));
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    87
by (ALLGOALS Blast_tac);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    88
qed "Function_eval";
3144
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
    89
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
    90
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
    91
goal thy "!!x. (e,s) -|-> (v,s') ==> (e = N n) --> (v=n & s'=s)";
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
    92
by (etac eval.induct 1);
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
    93
by (ALLGOALS Asm_simp_tac);
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
    94
val lemma = result();
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
    95
bind_thm ("eval_N_E", refl RSN (2, lemma RS mp));
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
    96
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
    97
AddSEs [eval_N_E];
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
    98
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
    99
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   100
(*This theorem says that "WHILE TRUE DO c" cannot terminate*)
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   101
goal thy "!!x. (c', s) -[eval]-> t ==> (c' = WHILE (N 0) DO c) --> False";
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   102
by (etac exec.induct 1);
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   103
by (Auto_tac());
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   104
bind_thm ("while_true_E", refl RSN (2, result() RS mp));
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   105
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   106
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   107
(** Equivalence of IF e THEN c;;(WHILE e DO c) ELSE SKIP  and  WHILE e DO c **)
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   108
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   109
goal thy "!!x. (c',s) -[eval]-> t ==> \
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   110
\              (c' = WHILE e DO c) --> \
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   111
\              (IF e THEN c;;c' ELSE SKIP, s) -[eval]-> t";
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   112
by (etac exec.induct 1);
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   113
by (ALLGOALS Asm_full_simp_tac);
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   114
by (ALLGOALS Blast_tac); 
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   115
bind_thm ("while_if1", refl RSN (2, result() RS mp));
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   116
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   117
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   118
goal thy "!!x. (c',s) -[eval]-> t ==> \
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   119
\              (c' = IF e THEN c;;(WHILE e DO c) ELSE SKIP) --> \
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   120
\              (WHILE e DO c, s) -[eval]-> t";
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   121
by (etac exec.induct 1);
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   122
by (ALLGOALS Asm_full_simp_tac);
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   123
by (ALLGOALS Blast_tac); 
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   124
bind_thm ("while_if2", refl RSN (2, result() RS mp));
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   125
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   126
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   127
goal thy "((IF e THEN c;;(WHILE e DO c) ELSE SKIP, s) -[eval]-> t)  =  \
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   128
\         ((WHILE e DO c, s) -[eval]-> t)";
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   129
by (blast_tac (!claset addIs [while_if1, while_if2]) 1);
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   130
qed "while_if";
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   131
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   132
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   133
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   134
(** Equivalence of  VALOF c1 RESULTIS (VALOF c2 RESULTIS e)
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   135
               and  VALOF c1;;c2 RESULTIS e
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   136
 **)
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   137
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   138
goal thy "!!x. (e',s) -|-> (v,s') ==> \
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   139
\              (e' = VALOF c1 RESULTIS (VALOF c2 RESULTIS e)) --> \
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   140
\              (VALOF c1;;c2 RESULTIS e, s) -|-> (v,s')";
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   141
by (etac eval.induct 1);
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   142
by (ALLGOALS Asm_full_simp_tac);
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   143
(*The destruction rule below replaces (c,s)-[eval Int ...]->t by 
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   144
   (c,s)-[eval]->t.  The new induction rule might include this assumption*)
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   145
by (blast_tac (!claset addSDs [impOfSubs (Int_lower1 RS exec_mono)]) 1);
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   146
bind_thm ("valof_valof1", refl RSN (2, result() RS mp));
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   147
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   148
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   149
goal thy "!!x. (e',s) -|-> (v,s') ==> \
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   150
\              (e' = VALOF c1;;c2 RESULTIS e) --> \
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   151
\              (VALOF c1 RESULTIS (VALOF c2 RESULTIS e), s) -|-> (v,s')";
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   152
by (etac eval.induct 1);
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   153
by (ALLGOALS Asm_full_simp_tac);
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   154
by (blast_tac (!claset addSDs [impOfSubs (Int_lower1 RS exec_mono)]) 1);
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   155
bind_thm ("valof_valof2", refl RSN (2, result() RS mp));
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   156
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   157
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   158
goal thy "((VALOF c1 RESULTIS (VALOF c2 RESULTIS e), s) -|-> (v,s'))  =  \
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   159
\         ((VALOF c1;;c2 RESULTIS e, s) -|-> (v,s'))";
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   160
by (blast_tac (!claset addIs [valof_valof1, valof_valof2]) 1);
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   161
qed "valof_valof";
04b0d8941365 New proofs about WHILE and VALOF
paulson
parents: 3120
diff changeset
   162