src/HOL/IMP/Transition.ML
author nipkow
Tue Apr 30 17:32:29 1996 +0200 (1996-04-30)
changeset 1707 e1a64a6c454d
parent 1701 a26fbeaaaabd
child 1730 1c7f793fc374
permissions -rw-r--r--
Added an equivalence proof which avoids the use of -n->
(with help from Ranan Fraer)
nipkow@1700
     1
(*  Title:      HOL/IMP/Transition.ML
nipkow@1700
     2
    ID:         $Id$
nipkow@1700
     3
    Author:     Tobias Nipkow & Robert Sandner, TUM
nipkow@1700
     4
    Copyright   1996 TUM
nipkow@1700
     5
nipkow@1700
     6
Equivalence of Natural and Transition semantics
nipkow@1700
     7
*)
nipkow@1700
     8
nipkow@1700
     9
open Transition;
nipkow@1700
    10
nipkow@1707
    11
section "Winskel's Proof";
nipkow@1707
    12
nipkow@1700
    13
val relpow_cs = rel_cs addSEs [rel_pow_0_E];
nipkow@1700
    14
nipkow@1700
    15
val evalc1_elim_cases = map (evalc1.mk_cases com.simps)
nipkow@1700
    16
   ["(SKIP,s) -1-> t", "(x:=a,s) -1-> t", "(c1;c2, s) -1-> t",
nipkow@1700
    17
    "(IF b THEN c1 ELSE c2, s) -1-> t", "(WHILE b DO c,s) -1-> t"];
nipkow@1700
    18
nipkow@1700
    19
val evalc1_cs = relpow_cs addIs (evalc.intrs@evalc1.intrs);
nipkow@1700
    20
nipkow@1701
    21
goal Transition.thy "!!c. (c,s) -0-> (SKIP,u) ==> c = SKIP & s = u";
nipkow@1700
    22
by(fast_tac evalc1_cs 1);
nipkow@1700
    23
val hlemma1 = result();
nipkow@1700
    24
nipkow@1701
    25
goal Transition.thy "!!s. (SKIP,s) -m-> (SKIP,t) ==> s = t & m = 0";
nipkow@1700
    26
be rel_pow_E2 1;
nipkow@1700
    27
by (Asm_full_simp_tac 1);
nipkow@1700
    28
by (eresolve_tac evalc1_elim_cases 1);
nipkow@1700
    29
val hlemma2 = result();
nipkow@1700
    30
nipkow@1700
    31
nipkow@1700
    32
goal Transition.thy
nipkow@1701
    33
  "!s t u c d. (c,s) -n-> (SKIP,t) --> (d,t) -*-> (SKIP,u) --> \
nipkow@1700
    34
\              (c;d, s) -*-> (SKIP, u)";
nipkow@1700
    35
by(nat_ind_tac "n" 1);
nipkow@1700
    36
 (* case n = 0 *)
nipkow@1700
    37
 by(fast_tac (evalc1_cs addIs [rtrancl_into_rtrancl2])1);
nipkow@1700
    38
(* induction step *)
nipkow@1700
    39
by (safe_tac (HOL_cs addSDs [rel_pow_Suc_D2]));
nipkow@1700
    40
by(split_all_tac 1);
nipkow@1700
    41
by(fast_tac (evalc1_cs addIs [rtrancl_into_rtrancl2]) 1);
nipkow@1700
    42
qed_spec_mp "lemma1";
nipkow@1700
    43
nipkow@1700
    44
nipkow@1700
    45
goal Transition.thy "!c s s1. <c,s> -c-> s1 --> (c,s) -*-> (SKIP,s1)";
nipkow@1700
    46
br evalc.mutual_induct 1;
nipkow@1700
    47
nipkow@1700
    48
(* SKIP *)
nipkow@1700
    49
br rtrancl_refl 1;
nipkow@1700
    50
nipkow@1700
    51
(* ASSIGN *)
nipkow@1700
    52
by (fast_tac (evalc1_cs addSIs [r_into_rtrancl]) 1);
nipkow@1700
    53
nipkow@1700
    54
(* SEMI *)
nipkow@1700
    55
by (fast_tac (set_cs addDs [rtrancl_imp_UN_rel_pow] addIs [lemma1]) 1);
nipkow@1700
    56
nipkow@1700
    57
(* IF *)
nipkow@1700
    58
by (fast_tac (evalc1_cs addIs [rtrancl_into_rtrancl2]) 1);
nipkow@1700
    59
by (fast_tac (evalc1_cs addIs [rtrancl_into_rtrancl2]) 1);
nipkow@1700
    60
nipkow@1700
    61
(* WHILE *)
nipkow@1700
    62
by (fast_tac (evalc1_cs addSIs [r_into_rtrancl]) 1);
nipkow@1700
    63
by (fast_tac (evalc1_cs addDs [rtrancl_imp_UN_rel_pow]
nipkow@1700
    64
                        addIs [rtrancl_into_rtrancl2,lemma1]) 1);
nipkow@1700
    65
nipkow@1700
    66
qed_spec_mp "evalc_impl_evalc1";
nipkow@1700
    67
nipkow@1700
    68
nipkow@1700
    69
goal Transition.thy
nipkow@1701
    70
  "!c d s u. (c;d,s) -n-> (SKIP,u) --> \
nipkow@1701
    71
\            (? t m. (c,s) -*-> (SKIP,t) & (d,t) -m-> (SKIP,u) & m <= n)";
nipkow@1700
    72
by(nat_ind_tac "n" 1);
nipkow@1700
    73
 (* case n = 0 *)
nipkow@1700
    74
 by (fast_tac (HOL_cs addSDs [hlemma1] addss !simpset) 1);
nipkow@1700
    75
(* induction step *)
nipkow@1700
    76
by (fast_tac (HOL_cs addSIs [rtrancl_refl,le_SucI,le_refl]
nipkow@1700
    77
                     addSDs [rel_pow_Suc_D2]
nipkow@1700
    78
                     addSEs (evalc1_elim_cases@
nipkow@1700
    79
                             [rel_pow_imp_rtrancl,rtrancl_into_rtrancl2])) 1);
nipkow@1700
    80
qed_spec_mp "lemma2";
nipkow@1700
    81
nipkow@1700
    82
goal Transition.thy "!s t. (c,s) -*-> (SKIP,t) --> <c,s> -c-> t";
nipkow@1700
    83
by (com.induct_tac "c" 1);
nipkow@1700
    84
by (safe_tac (evalc1_cs addSDs [rtrancl_imp_UN_rel_pow]));
nipkow@1700
    85
nipkow@1700
    86
(* SKIP *)
nipkow@1700
    87
by (fast_tac (evalc1_cs addSEs rel_pow_E2::evalc1_elim_cases) 1);
nipkow@1700
    88
nipkow@1700
    89
(* ASSIGN *)
nipkow@1700
    90
by (fast_tac (evalc1_cs addSDs [hlemma2]
nipkow@1700
    91
                        addSEs rel_pow_E2::evalc1_elim_cases
nipkow@1700
    92
                        addss !simpset) 1);
nipkow@1700
    93
nipkow@1700
    94
(* SEMI *)
nipkow@1700
    95
by (fast_tac (evalc1_cs addSDs [lemma2,rel_pow_imp_rtrancl]) 1);
nipkow@1700
    96
nipkow@1700
    97
(* IF *)
nipkow@1700
    98
be rel_pow_E2 1;
nipkow@1700
    99
by (Asm_full_simp_tac 1);
nipkow@1700
   100
by (fast_tac (evalc1_cs addSDs[rel_pow_imp_rtrancl]addEs evalc1_elim_cases) 1);
nipkow@1700
   101
nipkow@1700
   102
(* WHILE, induction on the length of the computation *)
nipkow@1700
   103
by(rotate_tac 1 1);
nipkow@1700
   104
by (etac rev_mp 1);
nipkow@1700
   105
by (res_inst_tac [("x","s")] spec 1);
nipkow@1700
   106
by(res_inst_tac [("n","n")] less_induct 1);
nipkow@1700
   107
by (strip_tac 1);
nipkow@1700
   108
be rel_pow_E2 1;
nipkow@1700
   109
 by (Asm_full_simp_tac 1);
nipkow@1700
   110
by (eresolve_tac evalc1_elim_cases 1);
nipkow@1700
   111
nipkow@1700
   112
(* WhileFalse *)
nipkow@1700
   113
 by (fast_tac (evalc1_cs addSDs [hlemma2]) 1);
nipkow@1700
   114
nipkow@1700
   115
(* WhileTrue *)
nipkow@1700
   116
by(fast_tac(evalc1_cs addSDs[lemma2,le_imp_less_or_eq,less_Suc_eq RS iffD2])1);
nipkow@1700
   117
nipkow@1700
   118
qed_spec_mp "evalc1_impl_evalc";
nipkow@1700
   119
nipkow@1700
   120
nipkow@1700
   121
(**** proof of the equivalence of evalc and evalc1 ****)
nipkow@1700
   122
nipkow@1700
   123
goal Transition.thy "((c, s) -*-> (SKIP, t)) = (<c,s> -c-> t)";
nipkow@1700
   124
by (fast_tac (HOL_cs addSEs [evalc1_impl_evalc,evalc_impl_evalc1]) 1);
nipkow@1700
   125
qed "evalc1_eq_evalc";
nipkow@1707
   126
nipkow@1707
   127
nipkow@1707
   128
section "A Proof Without -n->";
nipkow@1707
   129
nipkow@1707
   130
goal Transition.thy
nipkow@1707
   131
 "!!c1. (c1,s1) -*-> (SKIP,s2) ==> \
nipkow@1707
   132
\ (c2,s2) -*-> (c3,s3) --> (c1;c2,s1) -*-> (c3,s3)";
nipkow@1707
   133
be converse_rtrancl_induct2 1;
nipkow@1707
   134
by(fast_tac (evalc1_cs addIs [rtrancl_into_rtrancl2]) 1);
nipkow@1707
   135
by(fast_tac (evalc1_cs addIs [rtrancl_into_rtrancl2]) 1);
nipkow@1707
   136
qed_spec_mp "my_lemma1";
nipkow@1707
   137
nipkow@1707
   138
nipkow@1707
   139
goal Transition.thy "!c s s1. <c,s> -c-> s1 --> (c,s) -*-> (SKIP,s1)";
nipkow@1707
   140
br evalc.mutual_induct 1;
nipkow@1707
   141
nipkow@1707
   142
(* SKIP *)
nipkow@1707
   143
br rtrancl_refl 1;
nipkow@1707
   144
nipkow@1707
   145
(* ASSIGN *)
nipkow@1707
   146
by (fast_tac (evalc1_cs addSIs [r_into_rtrancl]) 1);
nipkow@1707
   147
nipkow@1707
   148
(* SEMI *)
nipkow@1707
   149
by (fast_tac (HOL_cs addIs [my_lemma1]) 1);
nipkow@1707
   150
nipkow@1707
   151
(* IF *)
nipkow@1707
   152
by (fast_tac (evalc1_cs addIs [rtrancl_into_rtrancl2]) 1);
nipkow@1707
   153
by (fast_tac (evalc1_cs addIs [rtrancl_into_rtrancl2]) 1);
nipkow@1707
   154
nipkow@1707
   155
(* WHILE *)
nipkow@1707
   156
by (fast_tac (evalc1_cs addSIs [r_into_rtrancl]) 1);
nipkow@1707
   157
by (fast_tac (evalc1_cs addIs [rtrancl_into_rtrancl2,my_lemma1]) 1);
nipkow@1707
   158
nipkow@1707
   159
qed_spec_mp "evalc_impl_evalc1";
nipkow@1707
   160
nipkow@1707
   161
(* The opposite direction is based on a Coq proof done by Ranan Fraer and
nipkow@1707
   162
   Yves Bertot. The following sketch is from an email by Ranan Fraer.
nipkow@1707
   163
*)
nipkow@1707
   164
(*
nipkow@1707
   165
First we've broke it into 2 lemmas:
nipkow@1707
   166
nipkow@1707
   167
Lemma 1
nipkow@1707
   168
((c,s) --> (SKIP,t)) => (<c,s> -c-> t)
nipkow@1707
   169
nipkow@1707
   170
This is a quick one, dealing with the cases skip, assignment
nipkow@1707
   171
and while_false.
nipkow@1707
   172
nipkow@1707
   173
Lemma 2
nipkow@1707
   174
((c,s) -*-> (c',s')) /\ <c',s'> -c'-> t
nipkow@1707
   175
  => 
nipkow@1707
   176
<c,s> -c-> t
nipkow@1707
   177
nipkow@1707
   178
This is proved by rule induction on the  -*-> relation
nipkow@1707
   179
and the induction step makes use of a third lemma: 
nipkow@1707
   180
nipkow@1707
   181
Lemma 3
nipkow@1707
   182
((c,s) --> (c',s')) /\ <c',s'> -c'-> t
nipkow@1707
   183
  => 
nipkow@1707
   184
<c,s> -c-> t
nipkow@1707
   185
nipkow@1707
   186
This captures the essence of the proof, as it shows that <c',s'> 
nipkow@1707
   187
behaves as the continuation of <c,s> with respect to the natural
nipkow@1707
   188
semantics.
nipkow@1707
   189
The proof of Lemma 3 goes by rule induction on the --> relation,
nipkow@1707
   190
dealing with the cases sequence1, sequence2, if_true, if_false and
nipkow@1707
   191
while_true. In particular in the case (sequence1) we make use again
nipkow@1707
   192
of Lemma 1.
nipkow@1707
   193
*)
nipkow@1707
   194
nipkow@1707
   195
nipkow@1707
   196
goal Transition.thy "!cs c' s'. (cs -1-> (c',s')) --> (!c s. cs = (c,s) \
nipkow@1707
   197
\                     --> (!t. <c',s'> -c-> t --> <c,s> -c-> t))";
nipkow@1707
   198
br evalc1.mutual_induct 1;
nipkow@1707
   199
by(ALLGOALS(fast_tac (evalc1_cs addEs (evalc_elim_cases@evalc1_elim_cases)
nipkow@1707
   200
                                addss !simpset)));
nipkow@1707
   201
val lemma = result();
nipkow@1707
   202
nipkow@1707
   203
val prems = goal Transition.thy
nipkow@1707
   204
 "[| ((c,s) -1-> (c',s')); <c',s'> -c-> t |] ==> <c,s> -c-> t";
nipkow@1707
   205
by(cut_facts_tac (lemma::prems) 1);
nipkow@1707
   206
by(fast_tac HOL_cs 1);
nipkow@1707
   207
qed "FB_lemma3";
nipkow@1707
   208
nipkow@1707
   209
val [major] = goal Transition.thy
nipkow@1707
   210
  "(c,s) -*-> (c',s') ==> <c',s'> -c-> t --> <c,s> -c-> t";
nipkow@1707
   211
br (major RS rtrancl_induct2) 1;
nipkow@1707
   212
by(fast_tac prod_cs 1);
nipkow@1707
   213
by(fast_tac (prod_cs addIs [FB_lemma3] addbefore (split_all_tac 1)) 1);
nipkow@1707
   214
qed_spec_mp "FB_lemma2";
nipkow@1707
   215
nipkow@1707
   216
goal Transition.thy "!!c. (c,s) -*-> (SKIP,t) ==> <c,s> -c-> t";
nipkow@1707
   217
by (fast_tac (evalc1_cs addEs [FB_lemma2]) 1);
nipkow@1707
   218
qed "evalc1_impl_evalc";