src/HOL/Complex/ex/mirtac.ML
changeset 27456 52c7c42e7e27
parent 26939 1035c89b4c02
child 28290 4cc2b6046258
equal deleted inserted replaced
27455:58b695d10cdf 27456:52c7c42e7e27
    56 val nat_div_add_eq = @{thm "div_add1_eq"} RS sym;
    56 val nat_div_add_eq = @{thm "div_add1_eq"} RS sym;
    57 val int_div_add_eq = @{thm "zdiv_zadd1_eq"} RS sym;
    57 val int_div_add_eq = @{thm "zdiv_zadd1_eq"} RS sym;
    58 val ZDIVISION_BY_ZERO_MOD = @{thm "DIVISION_BY_ZERO"} RS conjunct2;
    58 val ZDIVISION_BY_ZERO_MOD = @{thm "DIVISION_BY_ZERO"} RS conjunct2;
    59 val ZDIVISION_BY_ZERO_DIV = @{thm "DIVISION_BY_ZERO"} RS conjunct1;
    59 val ZDIVISION_BY_ZERO_DIV = @{thm "DIVISION_BY_ZERO"} RS conjunct1;
    60 
    60 
    61 fun prepare_for_mir sg q fm = 
    61 fun prepare_for_mir thy q fm = 
    62   let
    62   let
    63     val ps = Logic.strip_params fm
    63     val ps = Logic.strip_params fm
    64     val hs = map HOLogic.dest_Trueprop (Logic.strip_assums_hyp fm)
    64     val hs = map HOLogic.dest_Trueprop (Logic.strip_assums_hyp fm)
    65     val c = HOLogic.dest_Trueprop (Logic.strip_assums_concl fm)
    65     val c = HOLogic.dest_Trueprop (Logic.strip_assums_concl fm)
    66     fun mk_all ((s, T), (P,n)) =
    66     fun mk_all ((s, T), (P,n)) =
    90 	THEN (simp_tac (HOL_basic_ss addsimps [@{thm "abs_ge_zero"}] addsimps simp_thms) i)
    90 	THEN (simp_tac (HOL_basic_ss addsimps [@{thm "abs_ge_zero"}] addsimps simp_thms) i)
    91 	THEN (REPEAT_DETERM (split_tac [@{thm "split_min"}, @{thm "split_max"},@{thm "abs_split"}] i))
    91 	THEN (REPEAT_DETERM (split_tac [@{thm "split_min"}, @{thm "split_max"},@{thm "abs_split"}] i))
    92 	THEN (fn st =>
    92 	THEN (fn st =>
    93   let
    93   let
    94     val g = List.nth (prems_of st, i - 1)
    94     val g = List.nth (prems_of st, i - 1)
    95     val sg = ProofContext.theory_of ctxt
    95     val thy = ProofContext.theory_of ctxt
    96     (* Transform the term*)
    96     (* Transform the term*)
    97     val (t,np,nh) = prepare_for_mir sg q g
    97     val (t,np,nh) = prepare_for_mir thy q g
    98     (* Some simpsets for dealing with mod div abs and nat*)
    98     (* Some simpsets for dealing with mod div abs and nat*)
    99     val mod_div_simpset = HOL_basic_ss 
    99     val mod_div_simpset = HOL_basic_ss 
   100 			addsimps [refl,nat_mod_add_eq, 
   100 			addsimps [refl,nat_mod_add_eq, 
   101 				  @{thm "mod_self"}, @{thm "zmod_self"},
   101 				  @{thm "mod_self"}, @{thm "zmod_self"},
   102 				  @{thm "zdiv_zero"},@{thm "zmod_zero"},@{thm "div_0"}, @{thm "mod_0"},
   102 				  @{thm "zdiv_zero"},@{thm "zmod_zero"},@{thm "div_0"}, @{thm "mod_0"},
   119     val simpset2 = HOL_basic_ss
   119     val simpset2 = HOL_basic_ss
   120       addsimps [@{thm "nat_0_le"}, @{thm "all_nat"}, @{thm "ex_nat"}, @{thm "number_of1"}, 
   120       addsimps [@{thm "nat_0_le"}, @{thm "all_nat"}, @{thm "ex_nat"}, @{thm "number_of1"}, 
   121                 @{thm "number_of2"}, @{thm "int_0"}, @{thm "int_1"}]
   121                 @{thm "number_of2"}, @{thm "int_0"}, @{thm "int_1"}]
   122       addcongs [@{thm "conj_le_cong"}, @{thm "imp_le_cong"}]
   122       addcongs [@{thm "conj_le_cong"}, @{thm "imp_le_cong"}]
   123     (* simp rules for elimination of abs *)
   123     (* simp rules for elimination of abs *)
   124     val ct = cterm_of sg (HOLogic.mk_Trueprop t)
   124     val ct = cterm_of thy (HOLogic.mk_Trueprop t)
   125     (* Theorem for the nat --> int transformation *)
   125     (* Theorem for the nat --> int transformation *)
   126     val pre_thm = Seq.hd (EVERY
   126     val pre_thm = Seq.hd (EVERY
   127       [simp_tac mod_div_simpset 1, simp_tac simpset0 1,
   127       [simp_tac mod_div_simpset 1, simp_tac simpset0 1,
   128        TRY (simp_tac simpset1 1), TRY (simp_tac simpset2 1), TRY (simp_tac mir_ss 1)]
   128        TRY (simp_tac simpset1 1), TRY (simp_tac simpset2 1), TRY (simp_tac mir_ss 1)]
   129       (trivial ct))
   129       (trivial ct))
   132     val (th, tac) = case (prop_of pre_thm) of
   132     val (th, tac) = case (prop_of pre_thm) of
   133         Const ("==>", _) $ (Const ("Trueprop", _) $ t1) $ _ =>
   133         Const ("==>", _) $ (Const ("Trueprop", _) $ t1) $ _ =>
   134     let val pth = 
   134     let val pth = 
   135           (* If quick_and_dirty then run without proof generation as oracle*)
   135           (* If quick_and_dirty then run without proof generation as oracle*)
   136              if !quick_and_dirty 
   136              if !quick_and_dirty 
   137              then mircfr_oracle sg (Pattern.eta_long [] t1)
   137              then mirfr_oracle thy (false, Pattern.eta_long [] t1)
   138 	     else mirlfr_oracle sg (Pattern.eta_long [] t1)
   138 	     else mirfr_oracle thy (true, Pattern.eta_long [] t1)
   139     in 
   139     in 
   140           (trace_msg ("calling procedure with term:\n" ^
   140           (trace_msg ("calling procedure with term:\n" ^
   141              Syntax.string_of_term ctxt t1);
   141              Syntax.string_of_term ctxt t1);
   142            ((pth RS iffD2) RS pre_thm,
   142            ((pth RS iffD2) RS pre_thm,
   143             assm_tac (i + 1) THEN (if q then I else TRY) (rtac TrueI i)))
   143             assm_tac (i + 1) THEN (if q then I else TRY) (rtac TrueI i)))
   144     end
   144     end
   145       | _ => (pre_thm, assm_tac i)
   145       | _ => (pre_thm, assm_tac i)
   146   in (rtac (((mp_step nh) o (spec_step np)) th) i 
   146   in (rtac (((mp_step nh) o (spec_step np)) th) i 
   147       THEN tac) st
   147       THEN tac) st
   148   end handle Subscript => no_tac st | ReflectedMir.MIR => no_tac st);
   148   end handle Subscript => no_tac st);
   149 
   149 
   150 fun mir_args meth =
   150 fun mir_args meth =
   151  let val parse_flag = 
   151  let val parse_flag = 
   152          Args.$$$ "no_quantify" >> (K (K false));
   152          Args.$$$ "no_quantify" >> (K (K false));
   153  in
   153  in