src/HOL/Hoare/hoare_tac.ML
changeset 60754 02924903a6fd
parent 55661 ec14796cd140
child 61125 4c68426800de
equal deleted inserted replaced
60753:80ca4a065a48 60754:02924903a6fd
   130 (*****************************************************************************)
   130 (*****************************************************************************)
   131 
   131 
   132 fun set_to_pred_tac ctxt var_names = SUBGOAL (fn (_, i) =>
   132 fun set_to_pred_tac ctxt var_names = SUBGOAL (fn (_, i) =>
   133   before_set2pred_simp_tac ctxt i THEN_MAYBE
   133   before_set2pred_simp_tac ctxt i THEN_MAYBE
   134   EVERY [
   134   EVERY [
   135     rtac subsetI i,
   135     resolve_tac ctxt [subsetI] i,
   136     rtac CollectI i,
   136     resolve_tac ctxt [CollectI] i,
   137     dtac CollectD i,
   137     dresolve_tac ctxt [CollectD] i,
   138     TRY (split_all_tac ctxt i) THEN_MAYBE
   138     TRY (split_all_tac ctxt i) THEN_MAYBE
   139      (rename_tac var_names i THEN
   139      (rename_tac var_names i THEN
   140       full_simp_tac (put_simpset HOL_basic_ss ctxt addsimps [@{thm split_conv}]) i)]);
   140       full_simp_tac (put_simpset HOL_basic_ss ctxt addsimps [@{thm split_conv}]) i)]);
   141 
   141 
   142 (*******************************************************************************)
   142 (*******************************************************************************)
   146 (** and transforms any other into predicates, applying then                   **)
   146 (** and transforms any other into predicates, applying then                   **)
   147 (** the tactic chosen by the user, which may solve the subgoal completely.    **)
   147 (** the tactic chosen by the user, which may solve the subgoal completely.    **)
   148 (*******************************************************************************)
   148 (*******************************************************************************)
   149 
   149 
   150 fun max_simp_tac ctxt var_names tac =
   150 fun max_simp_tac ctxt var_names tac =
   151   FIRST' [rtac subset_refl, set_to_pred_tac ctxt var_names THEN_MAYBE' tac];
   151   FIRST' [resolve_tac ctxt [subset_refl],
       
   152     set_to_pred_tac ctxt var_names THEN_MAYBE' tac];
   152 
   153 
   153 fun basic_simp_tac ctxt var_names tac =
   154 fun basic_simp_tac ctxt var_names tac =
   154   simp_tac
   155   simp_tac
   155     (put_simpset HOL_basic_ss ctxt
   156     (put_simpset HOL_basic_ss ctxt
   156       addsimps [mem_Collect_eq, @{thm split_conv}] addsimprocs [Record.simproc])
   157       addsimps [mem_Collect_eq, @{thm split_conv}] addsimprocs [Record.simproc])
   161 
   162 
   162 fun hoare_rule_tac ctxt (vars, Mlem) tac =
   163 fun hoare_rule_tac ctxt (vars, Mlem) tac =
   163   let
   164   let
   164     val var_names = map (fst o dest_Free) vars;
   165     val var_names = map (fst o dest_Free) vars;
   165     fun wlp_tac i =
   166     fun wlp_tac i =
   166       rtac @{thm SeqRule} i THEN rule_tac false (i + 1)
   167       resolve_tac ctxt @{thms SeqRule} i THEN rule_tac false (i + 1)
   167     and rule_tac pre_cond i st = st |> (*abstraction over st prevents looping*)
   168     and rule_tac pre_cond i st = st |> (*abstraction over st prevents looping*)
   168       ((wlp_tac i THEN rule_tac pre_cond i)
   169       ((wlp_tac i THEN rule_tac pre_cond i)
   169         ORELSE
   170         ORELSE
   170         (FIRST [
   171         (FIRST [
   171           rtac @{thm SkipRule} i,
   172           resolve_tac ctxt @{thms SkipRule} i,
   172           rtac @{thm AbortRule} i,
   173           resolve_tac ctxt @{thms AbortRule} i,
   173           EVERY [
   174           EVERY [
   174             rtac @{thm BasicRule} i,
   175             resolve_tac ctxt @{thms BasicRule} i,
   175             rtac Mlem i,
   176             resolve_tac ctxt [Mlem] i,
   176             split_simp_tac ctxt i],
   177             split_simp_tac ctxt i],
   177           EVERY [
   178           EVERY [
   178             rtac @{thm CondRule} i,
   179             resolve_tac ctxt @{thms CondRule} i,
   179             rule_tac false (i + 2),
   180             rule_tac false (i + 2),
   180             rule_tac false (i + 1)],
   181             rule_tac false (i + 1)],
   181           EVERY [
   182           EVERY [
   182             rtac @{thm WhileRule} i,
   183             resolve_tac ctxt @{thms WhileRule} i,
   183             basic_simp_tac ctxt var_names tac (i + 2),
   184             basic_simp_tac ctxt var_names tac (i + 2),
   184             rule_tac true (i + 1)]]
   185             rule_tac true (i + 1)]]
   185          THEN (if pre_cond then basic_simp_tac ctxt var_names tac i else rtac subset_refl i)));
   186          THEN (
       
   187            if pre_cond then basic_simp_tac ctxt var_names tac i
       
   188            else resolve_tac ctxt [subset_refl] i)));
   186   in rule_tac end;
   189   in rule_tac end;
   187 
   190 
   188 
   191 
   189 (** tac is the tactic the user chooses to solve or simplify **)
   192 (** tac is the tactic the user chooses to solve or simplify **)
   190 (** the final verification conditions                       **)
   193 (** the final verification conditions                       **)