src/HOL/HOLCF/ex/Hoare.thy
author wenzelm
Sat, 07 Apr 2012 16:41:59 +0200
changeset 47389 e8552cba702d
parent 45606 b1e1508643b1
child 48564 eaa36c0d620a
permissions -rw-r--r--
explicit checks stable_finished_theory/stable_command allow parallel asynchronous command transactions; tuned;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42151
4da4fc77664b tuned headers;
wenzelm
parents: 40774
diff changeset
     1
(*  Title:      HOL/HOLCF/ex/Hoare.thy
1479
21eb5e156d91 expanded tabs
clasohm
parents: 1168
diff changeset
     2
    Author:     Franz Regensburger
244
929fc2c63bd0 HOLCF examples
nipkow
parents:
diff changeset
     3
12036
wenzelm
parents: 10835
diff changeset
     4
Theory for an example by C.A.R. Hoare
244
929fc2c63bd0 HOLCF examples
nipkow
parents:
diff changeset
     5
17291
94f6113fe9ed converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
     6
p x = if b1 x
1168
74be52691d62 The curried version of HOLCF is now just called HOLCF. The old
regensbu
parents: 1150
diff changeset
     7
         then p (g x)
244
929fc2c63bd0 HOLCF examples
nipkow
parents:
diff changeset
     8
         else x fi
929fc2c63bd0 HOLCF examples
nipkow
parents:
diff changeset
     9
17291
94f6113fe9ed converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
    10
q x = if b1 x orelse b2 x
1168
74be52691d62 The curried version of HOLCF is now just called HOLCF. The old
regensbu
parents: 1150
diff changeset
    11
         then q (g x)
244
929fc2c63bd0 HOLCF examples
nipkow
parents:
diff changeset
    12
         else x fi
929fc2c63bd0 HOLCF examples
nipkow
parents:
diff changeset
    13
17291
94f6113fe9ed converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
    14
Prove: for all b1 b2 g .
94f6113fe9ed converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
    15
            q o p  = q
244
929fc2c63bd0 HOLCF examples
nipkow
parents:
diff changeset
    16
929fc2c63bd0 HOLCF examples
nipkow
parents:
diff changeset
    17
In order to get a nice notation we fix the functions b1,b2 and g in the
929fc2c63bd0 HOLCF examples
nipkow
parents:
diff changeset
    18
signature of this example
929fc2c63bd0 HOLCF examples
nipkow
parents:
diff changeset
    19
929fc2c63bd0 HOLCF examples
nipkow
parents:
diff changeset
    20
*)
929fc2c63bd0 HOLCF examples
nipkow
parents:
diff changeset
    21
17291
94f6113fe9ed converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
    22
theory Hoare
94f6113fe9ed converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
    23
imports HOLCF
94f6113fe9ed converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
    24
begin
244
929fc2c63bd0 HOLCF examples
nipkow
parents:
diff changeset
    25
25135
4f8176c940cf modernized specifications ('definition', 'axiomatization');
wenzelm
parents: 21404
diff changeset
    26
axiomatization
4f8176c940cf modernized specifications ('definition', 'axiomatization');
wenzelm
parents: 21404
diff changeset
    27
  b1 :: "'a -> tr" and
4f8176c940cf modernized specifications ('definition', 'axiomatization');
wenzelm
parents: 21404
diff changeset
    28
  b2 :: "'a -> tr" and
17291
94f6113fe9ed converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
    29
  g :: "'a -> 'a"
244
929fc2c63bd0 HOLCF examples
nipkow
parents:
diff changeset
    30
19763
wenzelm
parents: 19742
diff changeset
    31
definition
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 19763
diff changeset
    32
  p :: "'a -> 'a" where
40322
707eb30e8a53 make syntax of continuous if-then-else consistent with HOL if-then-else
huffman
parents: 40028
diff changeset
    33
  "p = fix$(LAM f. LAM x. If b1$x then f$(g$x) else x)"
244
929fc2c63bd0 HOLCF examples
nipkow
parents:
diff changeset
    34
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 19763
diff changeset
    35
definition
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 19763
diff changeset
    36
  q :: "'a -> 'a" where
40322
707eb30e8a53 make syntax of continuous if-then-else consistent with HOL if-then-else
huffman
parents: 40028
diff changeset
    37
  "q = fix$(LAM f. LAM x. If b1$x orelse b2$x then f$(g$x) else x)"
244
929fc2c63bd0 HOLCF examples
nipkow
parents:
diff changeset
    38
19742
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    39
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    40
(* --------- pure HOLCF logic, some little lemmas ------ *)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    41
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    42
lemma hoare_lemma2: "b~=TT ==> b=FF | b=UU"
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    43
apply (rule Exh_tr [THEN disjE])
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    44
apply blast+
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    45
done
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    46
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    47
lemma hoare_lemma3: " (ALL k. b1$(iterate k$g$x) = TT) | (EX k. b1$(iterate k$g$x)~=TT)"
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    48
apply blast
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    49
done
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    50
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    51
lemma hoare_lemma4: "(EX k. b1$(iterate k$g$x) ~= TT) ==>  
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    52
  EX k. b1$(iterate k$g$x) = FF | b1$(iterate k$g$x) = UU"
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    53
apply (erule exE)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    54
apply (rule exI)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    55
apply (rule hoare_lemma2)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    56
apply assumption
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    57
done
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    58
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    59
lemma hoare_lemma5: "[|(EX k. b1$(iterate k$g$x) ~= TT); 
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    60
    k=Least(%n. b1$(iterate n$g$x) ~= TT)|] ==>  
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    61
  b1$(iterate k$g$x)=FF | b1$(iterate k$g$x)=UU"
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    62
apply hypsubst
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    63
apply (rule hoare_lemma2)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    64
apply (erule exE)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    65
apply (erule LeastI)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    66
done
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    67
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    68
lemma hoare_lemma6: "b=UU ==> b~=TT"
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    69
apply hypsubst
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    70
apply (rule dist_eq_tr)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    71
done
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    72
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    73
lemma hoare_lemma7: "b=FF ==> b~=TT"
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    74
apply hypsubst
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    75
apply (rule dist_eq_tr)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    76
done
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    77
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    78
lemma hoare_lemma8: "[|(EX k. b1$(iterate k$g$x) ~= TT); 
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    79
    k=Least(%n. b1$(iterate n$g$x) ~= TT)|] ==>  
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    80
  ALL m. m < k --> b1$(iterate m$g$x)=TT"
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    81
apply hypsubst
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    82
apply (erule exE)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    83
apply (intro strip)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    84
apply (rule_tac p = "b1$ (iterate m$g$x) " in trE)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    85
prefer 2 apply (assumption)
26334
80ec6cf82d95 removed redundant Nat.less_irrefl;
wenzelm
parents: 25895
diff changeset
    86
apply (rule le_less_trans [THEN less_irrefl [THEN notE]])
19742
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    87
prefer 2 apply (assumption)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    88
apply (rule Least_le)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    89
apply (erule hoare_lemma6)
26334
80ec6cf82d95 removed redundant Nat.less_irrefl;
wenzelm
parents: 25895
diff changeset
    90
apply (rule le_less_trans [THEN less_irrefl [THEN notE]])
19742
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    91
prefer 2 apply (assumption)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    92
apply (rule Least_le)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    93
apply (erule hoare_lemma7)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    94
done
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    95
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    96
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    97
lemma hoare_lemma28: "f$(y::'a)=(UU::tr) ==> f$UU = UU"
40429
5f37c3964866 simplify some proofs
huffman
parents: 40322
diff changeset
    98
by (rule strictI)
19742
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
    99
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   100
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   101
(* ----- access to definitions ----- *)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   102
40322
707eb30e8a53 make syntax of continuous if-then-else consistent with HOL if-then-else
huffman
parents: 40028
diff changeset
   103
lemma p_def3: "p$x = If b1$x then p$(g$x) else x"
19742
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   104
apply (rule trans)
19763
wenzelm
parents: 19742
diff changeset
   105
apply (rule p_def [THEN eq_reflection, THEN fix_eq3])
19742
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   106
apply simp
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   107
done
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   108
40322
707eb30e8a53 make syntax of continuous if-then-else consistent with HOL if-then-else
huffman
parents: 40028
diff changeset
   109
lemma q_def3: "q$x = If b1$x orelse b2$x then q$(g$x) else x"
19742
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   110
apply (rule trans)
19763
wenzelm
parents: 19742
diff changeset
   111
apply (rule q_def [THEN eq_reflection, THEN fix_eq3])
19742
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   112
apply simp
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   113
done
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   114
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   115
(** --------- proofs about iterations of p and q ---------- **)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   116
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   117
lemma hoare_lemma9: "(ALL m. m< Suc k --> b1$(iterate m$g$x)=TT) --> 
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   118
   p$(iterate k$g$x)=p$x"
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   119
apply (induct_tac k)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   120
apply (simp (no_asm))
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   121
apply (simp (no_asm))
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   122
apply (intro strip)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   123
apply (rule_tac s = "p$ (iterate n$g$x) " in trans)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   124
apply (rule trans)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   125
apply (rule_tac [2] p_def3 [symmetric])
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   126
apply (rule_tac s = "TT" and t = "b1$ (iterate n$g$x) " in ssubst)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   127
apply (rule mp)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   128
apply (erule spec)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   129
apply (simp (no_asm) add: less_Suc_eq)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   130
apply simp
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   131
apply (erule mp)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   132
apply (intro strip)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   133
apply (rule mp)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   134
apply (erule spec)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   135
apply (erule less_trans)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   136
apply simp
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   137
done
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   138
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   139
lemma hoare_lemma24: "(ALL m. m< Suc k --> b1$(iterate m$g$x)=TT) -->  
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   140
  q$(iterate k$g$x)=q$x"
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   141
apply (induct_tac k)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   142
apply (simp (no_asm))
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   143
apply (simp (no_asm) add: less_Suc_eq)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   144
apply (intro strip)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   145
apply (rule_tac s = "q$ (iterate n$g$x) " in trans)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   146
apply (rule trans)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   147
apply (rule_tac [2] q_def3 [symmetric])
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   148
apply (rule_tac s = "TT" and t = "b1$ (iterate n$g$x) " in ssubst)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   149
apply blast
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   150
apply simp
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   151
apply (erule mp)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   152
apply (intro strip)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   153
apply (fast dest!: less_Suc_eq [THEN iffD1])
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   154
done
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   155
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   156
(* -------- results about p for case (EX k. b1$(iterate k$g$x)~=TT) ------- *)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   157
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   158
lemma hoare_lemma10:
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   159
  "EX k. b1$(iterate k$g$x) ~= TT
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   160
    ==> Suc k = (LEAST n. b1$(iterate n$g$x) ~= TT) ==> p$(iterate k$g$x) = p$x"
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   161
  by (rule hoare_lemma8 [THEN hoare_lemma9 [THEN mp]])
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   162
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   163
lemma hoare_lemma11: "(EX n. b1$(iterate n$g$x) ~= TT) ==> 
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   164
  k=(LEAST n. b1$(iterate n$g$x) ~= TT) & b1$(iterate k$g$x)=FF  
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   165
  --> p$x = iterate k$g$x"
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   166
apply (case_tac "k")
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   167
apply hypsubst
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   168
apply (simp (no_asm))
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   169
apply (intro strip)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   170
apply (erule conjE)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   171
apply (rule trans)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   172
apply (rule p_def3)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   173
apply simp
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   174
apply hypsubst
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   175
apply (intro strip)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   176
apply (erule conjE)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   177
apply (rule trans)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   178
apply (erule hoare_lemma10 [symmetric])
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   179
apply assumption
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   180
apply (rule trans)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   181
apply (rule p_def3)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   182
apply (rule_tac s = "TT" and t = "b1$ (iterate nat$g$x) " in ssubst)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   183
apply (rule hoare_lemma8 [THEN spec, THEN mp])
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   184
apply assumption
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   185
apply assumption
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   186
apply (simp (no_asm))
40028
9ee4e0ab2964 remove old uses of 'simp_tac HOLCF_ss'
huffman
parents: 40002
diff changeset
   187
apply (simp (no_asm))
19742
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   188
apply (rule trans)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   189
apply (rule p_def3)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   190
apply (simp (no_asm) del: iterate_Suc add: iterate_Suc [symmetric])
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   191
apply (erule_tac s = "FF" in ssubst)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   192
apply simp
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   193
done
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   194
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   195
lemma hoare_lemma12: "(EX n. b1$(iterate n$g$x) ~= TT) ==> 
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   196
  k=Least(%n. b1$(iterate n$g$x)~=TT) & b1$(iterate k$g$x)=UU  
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   197
  --> p$x = UU"
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   198
apply (case_tac "k")
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   199
apply hypsubst
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   200
apply (simp (no_asm))
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   201
apply (intro strip)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   202
apply (erule conjE)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   203
apply (rule trans)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   204
apply (rule p_def3)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   205
apply simp
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   206
apply hypsubst
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   207
apply (simp (no_asm))
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   208
apply (intro strip)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   209
apply (erule conjE)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   210
apply (rule trans)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   211
apply (rule hoare_lemma10 [symmetric])
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   212
apply assumption
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   213
apply assumption
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   214
apply (rule trans)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   215
apply (rule p_def3)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   216
apply (rule_tac s = "TT" and t = "b1$ (iterate nat$g$x) " in ssubst)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   217
apply (rule hoare_lemma8 [THEN spec, THEN mp])
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   218
apply assumption
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   219
apply assumption
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   220
apply (simp (no_asm))
40028
9ee4e0ab2964 remove old uses of 'simp_tac HOLCF_ss'
huffman
parents: 40002
diff changeset
   221
apply (simp)
19742
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   222
apply (rule trans)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   223
apply (rule p_def3)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   224
apply simp
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   225
done
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   226
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   227
(* -------- results about p for case  (ALL k. b1$(iterate k$g$x)=TT) ------- *)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   228
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   229
lemma fernpass_lemma: "(ALL k. b1$(iterate k$g$x)=TT) ==> ALL k. p$(iterate k$g$x) = UU"
19763
wenzelm
parents: 19742
diff changeset
   230
apply (rule p_def [THEN eq_reflection, THEN def_fix_ind])
35948
5e7909f0346b remove ancient continuity tactic
huffman
parents: 35174
diff changeset
   231
apply simp
5e7909f0346b remove ancient continuity tactic
huffman
parents: 35174
diff changeset
   232
apply simp
19742
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   233
apply (simp (no_asm))
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   234
apply (rule allI)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   235
apply (rule_tac s = "TT" and t = "b1$ (iterate k$g$x) " in ssubst)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   236
apply (erule spec)
40028
9ee4e0ab2964 remove old uses of 'simp_tac HOLCF_ss'
huffman
parents: 40002
diff changeset
   237
apply (simp)
19742
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   238
apply (rule iterate_Suc [THEN subst])
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   239
apply (erule spec)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   240
done
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   241
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   242
lemma hoare_lemma16: "(ALL k. b1$(iterate k$g$x)=TT) ==> p$x = UU"
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   243
apply (rule_tac F1 = "g" and t = "x" in iterate_0 [THEN subst])
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   244
apply (erule fernpass_lemma [THEN spec])
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   245
done
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   246
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   247
(* -------- results about q for case  (ALL k. b1$(iterate k$g$x)=TT) ------- *)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   248
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   249
lemma hoare_lemma17: "(ALL k. b1$(iterate k$g$x)=TT) ==> ALL k. q$(iterate k$g$x) = UU"
19763
wenzelm
parents: 19742
diff changeset
   250
apply (rule q_def [THEN eq_reflection, THEN def_fix_ind])
35948
5e7909f0346b remove ancient continuity tactic
huffman
parents: 35174
diff changeset
   251
apply simp
5e7909f0346b remove ancient continuity tactic
huffman
parents: 35174
diff changeset
   252
apply simp
19742
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   253
apply (rule allI)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   254
apply (simp (no_asm))
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   255
apply (rule_tac s = "TT" and t = "b1$ (iterate k$g$x) " in ssubst)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   256
apply (erule spec)
40028
9ee4e0ab2964 remove old uses of 'simp_tac HOLCF_ss'
huffman
parents: 40002
diff changeset
   257
apply (simp)
19742
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   258
apply (rule iterate_Suc [THEN subst])
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   259
apply (erule spec)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   260
done
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   261
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   262
lemma hoare_lemma18: "(ALL k. b1$(iterate k$g$x)=TT) ==> q$x = UU"
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   263
apply (rule_tac F1 = "g" and t = "x" in iterate_0 [THEN subst])
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   264
apply (erule hoare_lemma17 [THEN spec])
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   265
done
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   266
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   267
lemma hoare_lemma19:
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   268
  "(ALL k. (b1::'a->tr)$(iterate k$g$x)=TT) ==> b1$(UU::'a) = UU | (ALL y. b1$(y::'a)=TT)"
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   269
apply (rule flat_codom)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   270
apply (rule_tac t = "x1" in iterate_0 [THEN subst])
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   271
apply (erule spec)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   272
done
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   273
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   274
lemma hoare_lemma20: "(ALL y. b1$(y::'a)=TT) ==> ALL k. q$(iterate k$g$(x::'a)) = UU"
19763
wenzelm
parents: 19742
diff changeset
   275
apply (rule q_def [THEN eq_reflection, THEN def_fix_ind])
35948
5e7909f0346b remove ancient continuity tactic
huffman
parents: 35174
diff changeset
   276
apply simp
5e7909f0346b remove ancient continuity tactic
huffman
parents: 35174
diff changeset
   277
apply simp
19742
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   278
apply (rule allI)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   279
apply (simp (no_asm))
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   280
apply (rule_tac s = "TT" and t = "b1$ (iterate k$g$ (x::'a))" in ssubst)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   281
apply (erule spec)
40028
9ee4e0ab2964 remove old uses of 'simp_tac HOLCF_ss'
huffman
parents: 40002
diff changeset
   282
apply (simp)
19742
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   283
apply (rule iterate_Suc [THEN subst])
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   284
apply (erule spec)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   285
done
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   286
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   287
lemma hoare_lemma21: "(ALL y. b1$(y::'a)=TT) ==> q$(x::'a) = UU"
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   288
apply (rule_tac F1 = "g" and t = "x" in iterate_0 [THEN subst])
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   289
apply (erule hoare_lemma20 [THEN spec])
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   290
done
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   291
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   292
lemma hoare_lemma22: "b1$(UU::'a)=UU ==> q$(UU::'a) = UU"
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   293
apply (subst q_def3)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   294
apply simp
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   295
done
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   296
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   297
(* -------- results about q for case (EX k. b1$(iterate k$g$x) ~= TT) ------- *)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   298
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   299
lemma hoare_lemma25: "EX k. b1$(iterate k$g$x) ~= TT
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   300
  ==> Suc k = (LEAST n. b1$(iterate n$g$x) ~= TT) ==> q$(iterate k$g$x) = q$x"
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   301
  by (rule hoare_lemma8 [THEN hoare_lemma24 [THEN mp]])
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   302
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   303
lemma hoare_lemma26: "(EX n. b1$(iterate n$g$x)~=TT) ==> 
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   304
  k=Least(%n. b1$(iterate n$g$x) ~= TT) & b1$(iterate k$g$x) =FF  
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   305
  --> q$x = q$(iterate k$g$x)"
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   306
apply (case_tac "k")
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   307
apply hypsubst
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   308
apply (intro strip)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   309
apply (simp (no_asm))
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   310
apply hypsubst
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   311
apply (intro strip)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   312
apply (erule conjE)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   313
apply (rule trans)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   314
apply (rule hoare_lemma25 [symmetric])
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   315
apply assumption
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   316
apply assumption
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   317
apply (rule trans)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   318
apply (rule q_def3)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   319
apply (rule_tac s = "TT" and t = "b1$ (iterate nat$g$x) " in ssubst)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   320
apply (rule hoare_lemma8 [THEN spec, THEN mp])
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   321
apply assumption
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   322
apply assumption
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   323
apply (simp (no_asm))
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   324
apply (simp (no_asm))
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   325
done
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   326
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   327
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   328
lemma hoare_lemma27: "(EX n. b1$(iterate n$g$x) ~= TT) ==> 
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   329
  k=Least(%n. b1$(iterate n$g$x)~=TT) & b1$(iterate k$g$x)=UU  
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   330
  --> q$x = UU"
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   331
apply (case_tac "k")
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   332
apply hypsubst
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   333
apply (simp (no_asm))
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   334
apply (intro strip)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   335
apply (erule conjE)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   336
apply (subst q_def3)
40028
9ee4e0ab2964 remove old uses of 'simp_tac HOLCF_ss'
huffman
parents: 40002
diff changeset
   337
apply (simp)
19742
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   338
apply hypsubst
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   339
apply (simp (no_asm))
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   340
apply (intro strip)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   341
apply (erule conjE)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   342
apply (rule trans)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   343
apply (rule hoare_lemma25 [symmetric])
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   344
apply assumption
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   345
apply assumption
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   346
apply (rule trans)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   347
apply (rule q_def3)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   348
apply (rule_tac s = "TT" and t = "b1$ (iterate nat$g$x) " in ssubst)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   349
apply (rule hoare_lemma8 [THEN spec, THEN mp])
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   350
apply assumption
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   351
apply assumption
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   352
apply (simp (no_asm))
40028
9ee4e0ab2964 remove old uses of 'simp_tac HOLCF_ss'
huffman
parents: 40002
diff changeset
   353
apply (simp)
19742
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   354
apply (rule trans)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   355
apply (rule q_def3)
40028
9ee4e0ab2964 remove old uses of 'simp_tac HOLCF_ss'
huffman
parents: 40002
diff changeset
   356
apply (simp)
19742
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   357
done
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   358
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   359
(* ------- (ALL k. b1$(iterate k$g$x)=TT) ==> q o p = q   ----- *)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   360
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   361
lemma hoare_lemma23: "(ALL k. b1$(iterate k$g$x)=TT) ==> q$(p$x) = q$x"
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   362
apply (subst hoare_lemma16)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   363
apply assumption
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   364
apply (rule hoare_lemma19 [THEN disjE])
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   365
apply assumption
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   366
apply (simplesubst hoare_lemma18)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   367
apply assumption
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   368
apply (simplesubst hoare_lemma22)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   369
apply assumption
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   370
apply (rule refl)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   371
apply (simplesubst hoare_lemma21)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   372
apply assumption
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   373
apply (simplesubst hoare_lemma21)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   374
apply assumption
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   375
apply (rule refl)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   376
done
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   377
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   378
(* ------------  EX k. b1~(iterate k$g$x) ~= TT ==> q o p = q   ----- *)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   379
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   380
lemma hoare_lemma29: "EX k. b1$(iterate k$g$x) ~= TT ==> q$(p$x) = q$x"
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   381
apply (rule hoare_lemma5 [THEN disjE])
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   382
apply assumption
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   383
apply (rule refl)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   384
apply (subst hoare_lemma11 [THEN mp])
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   385
apply assumption
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   386
apply (rule conjI)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   387
apply (rule refl)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   388
apply assumption
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   389
apply (rule hoare_lemma26 [THEN mp, THEN subst])
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   390
apply assumption
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   391
apply (rule conjI)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   392
apply (rule refl)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   393
apply assumption
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   394
apply (rule refl)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   395
apply (subst hoare_lemma12 [THEN mp])
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   396
apply assumption
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   397
apply (rule conjI)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   398
apply (rule refl)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   399
apply assumption
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   400
apply (subst hoare_lemma22)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   401
apply (subst hoare_lemma28)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   402
apply assumption
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   403
apply (rule refl)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   404
apply (rule sym)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   405
apply (subst hoare_lemma27 [THEN mp])
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   406
apply assumption
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   407
apply (rule conjI)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   408
apply (rule refl)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   409
apply assumption
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   410
apply (rule refl)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   411
done
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   412
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   413
(* ------ the main proof q o p = q ------ *)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   414
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   415
theorem hoare_main: "q oo p = q"
40002
c5b5f7a3a3b1 new theorem names: fun_below_iff, fun_belowI, cfun_eq_iff, cfun_eqI, cfun_below_iff, cfun_belowI
huffman
parents: 35948
diff changeset
   416
apply (rule cfun_eqI)
19742
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   417
apply (subst cfcomp2)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   418
apply (rule hoare_lemma3 [THEN disjE])
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   419
apply (erule hoare_lemma23)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   420
apply (erule hoare_lemma29)
86f21beabafc removed legacy ML scripts;
wenzelm
parents: 17291
diff changeset
   421
done
17291
94f6113fe9ed converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
   422
244
929fc2c63bd0 HOLCF examples
nipkow
parents:
diff changeset
   423
end