src/HOL/IMP/Hoare.ML
changeset 1696 e84bff5c519b
parent 1486 7b95d7b49f7a
child 1730 1c7f793fc374
equal deleted inserted replaced
1695:0f9b9eda2a2c 1696:e84bff5c519b
    23 by(eres_inst_tac [("x","a")] allE 1);
    23 by(eres_inst_tac [("x","a")] allE 1);
    24 by (safe_tac comp_cs);
    24 by (safe_tac comp_cs);
    25   by(ALLGOALS Asm_full_simp_tac);
    25   by(ALLGOALS Asm_full_simp_tac);
    26 qed_spec_mp "hoare_sound";
    26 qed_spec_mp "hoare_sound";
    27 
    27 
    28 goalw Hoare.thy [swp_def] "swp Skip Q = Q";
    28 goalw Hoare.thy [swp_def] "swp SKIP Q = Q";
    29 by(Simp_tac 1);
    29 by(Simp_tac 1);
    30 br ext 1;
    30 br ext 1;
    31 by(fast_tac HOL_cs 1);
    31 by(fast_tac HOL_cs 1);
    32 qed "swp_Skip";
    32 qed "swp_SKIP";
    33 
    33 
    34 goalw Hoare.thy [swp_def] "swp (x:=a) Q = (%s.Q(s[A a s/x]))";
    34 goalw Hoare.thy [swp_def] "swp (x:=a) Q = (%s.Q(s[a s/x]))";
    35 by(Simp_tac 1);
    35 by(Simp_tac 1);
    36 br ext 1;
    36 br ext 1;
    37 by(fast_tac HOL_cs 1);
    37 by(fast_tac HOL_cs 1);
    38 qed "swp_Ass";
    38 qed "swp_Ass";
    39 
    39 
    42 br ext 1;
    42 br ext 1;
    43 by(fast_tac comp_cs 1);
    43 by(fast_tac comp_cs 1);
    44 qed "swp_Semi";
    44 qed "swp_Semi";
    45 
    45 
    46 goalw Hoare.thy [swp_def]
    46 goalw Hoare.thy [swp_def]
    47   "swp (IF b THEN c ELSE d) Q = (%s. (B b s --> swp c Q s) & \
    47   "swp (IF b THEN c ELSE d) Q = (%s. (b s --> swp c Q s) & \
    48 \                                    (~B b s --> swp d Q s))";
    48 \                                    (~b s --> swp d Q s))";
    49 by(Simp_tac 1);
    49 by(Simp_tac 1);
    50 br ext 1;
    50 br ext 1;
    51 by(fast_tac comp_cs 1);
    51 by(fast_tac comp_cs 1);
    52 qed "swp_If";
    52 qed "swp_If";
    53 
    53 
    54 goalw Hoare.thy [swp_def]
    54 goalw Hoare.thy [swp_def]
    55   "!!s. B b s ==> swp (WHILE b DO c) Q s = swp (c;WHILE b DO c) Q s";
    55   "!!s. b s ==> swp (WHILE b DO c) Q s = swp (c;WHILE b DO c) Q s";
    56 by(stac C_While_If 1);
    56 by(stac C_While_If 1);
    57 by(Asm_simp_tac 1);
    57 by(Asm_simp_tac 1);
    58 qed "swp_While_True";
    58 qed "swp_While_True";
    59 
    59 
    60 goalw Hoare.thy [swp_def] "!!s. ~B b s ==> swp (WHILE b DO c) Q s = Q s";
    60 goalw Hoare.thy [swp_def] "!!s. ~b s ==> swp (WHILE b DO c) Q s = Q s";
    61 by(stac C_While_If 1);
    61 by(stac C_While_If 1);
    62 by(Asm_simp_tac 1);
    62 by(Asm_simp_tac 1);
    63 by(fast_tac HOL_cs 1);
    63 by(fast_tac HOL_cs 1);
    64 qed "swp_While_False";
    64 qed "swp_While_False";
    65 
    65 
    66 Addsimps [swp_Skip,swp_Ass,swp_Semi,swp_If,swp_While_True,swp_While_False];
    66 Addsimps [swp_SKIP,swp_Ass,swp_Semi,swp_If,swp_While_True,swp_While_False];
    67 
    67 
    68 Delsimps [C_while];
    68 Delsimps [C_while];
    69 
       
    70 goalw Hoare.thy [hoare_valid_def,swp_def]
       
    71   "!!c. |= {P}c{Q} ==> !s. P s --> swp c Q s";
       
    72 by(fast_tac HOL_cs 1);
       
    73 qed "swp_is_weakest";
       
    74 
    69 
    75 goal Hoare.thy "!Q. |- {swp c Q} c {Q}";
    70 goal Hoare.thy "!Q. |- {swp c Q} c {Q}";
    76 by(com.induct_tac "c" 1);
    71 by(com.induct_tac "c" 1);
    77 by(ALLGOALS Simp_tac);
    72 by(ALLGOALS Simp_tac);
    78     by(fast_tac (HOL_cs addIs [hoare.skip]) 1);
    73     by(fast_tac (HOL_cs addIs [hoare.skip]) 1);
    86  br hoare.conseq 1;
    81  br hoare.conseq 1;
    87    by(fast_tac HOL_cs 2);
    82    by(fast_tac HOL_cs 2);
    88   by(fast_tac HOL_cs 2);
    83   by(fast_tac HOL_cs 2);
    89  by(fast_tac HOL_cs 1);
    84  by(fast_tac HOL_cs 1);
    90 br hoare.conseq 1;
    85 br hoare.conseq 1;
    91   br hoare.While 2;
       
    92   be thin_rl 1;
    86   be thin_rl 1;
    93   by(fast_tac HOL_cs 1);
    87   by(fast_tac HOL_cs 1);
       
    88  br hoare.While 1;
    94  br hoare.conseq 1;
    89  br hoare.conseq 1;
    95    be thin_rl 3;
    90    be thin_rl 3;
    96    br allI 3;
    91    br allI 3;
    97    br impI 3;
    92    br impI 3;
    98    ba 3;
    93    ba 3;
   105 qed_spec_mp "swp_is_pre";
   100 qed_spec_mp "swp_is_pre";
   106 
   101 
   107 goal Hoare.thy "!!c. |= {P}c{Q} ==> |- {P}c{Q}";
   102 goal Hoare.thy "!!c. |= {P}c{Q} ==> |- {P}c{Q}";
   108 br (swp_is_pre RSN (2,hoare.conseq)) 1;
   103 br (swp_is_pre RSN (2,hoare.conseq)) 1;
   109  by(fast_tac HOL_cs 2);
   104  by(fast_tac HOL_cs 2);
   110 be swp_is_weakest 1;
   105 by(rewrite_goals_tac [hoare_valid_def,swp_def]);
       
   106 by(fast_tac HOL_cs 1);
   111 qed "hoare_relative_complete";
   107 qed "hoare_relative_complete";