src/HOL/Decision_Procs/ferrack_tac.ML
author blanchet
Thu Sep 11 18:54:36 2014 +0200 (2014-09-11)
changeset 58306 117ba6cbe414
parent 56245 84fc7dfa3cd4
child 58956 a816aa3ff391
permissions -rw-r--r--
renamed 'rep_datatype' to 'old_rep_datatype' (HOL)
hoelzl@30439
     1
(*  Title:      HOL/Decision_Procs/ferrack_tac.ML
haftmann@29788
     2
    Author:     Amine Chaieb, TU Muenchen
haftmann@29788
     3
*)
haftmann@29788
     4
wenzelm@31302
     5
signature FERRACK_TAC =
wenzelm@31302
     6
sig
wenzelm@31302
     7
  val linr_tac: Proof.context -> bool -> int -> tactic
wenzelm@31302
     8
end
wenzelm@31302
     9
wenzelm@55498
    10
structure Ferrack_Tac: FERRACK_TAC =
chaieb@23264
    11
struct
chaieb@23264
    12
huffman@26075
    13
val ferrack_ss = let val ths = [@{thm real_of_int_inject}, @{thm real_of_int_less_iff}, 
wenzelm@32960
    14
                                @{thm real_of_int_le_iff}]
wenzelm@51717
    15
             in @{context} delsimps ths addsimps (map (fn th => th RS sym) ths)
wenzelm@51717
    16
             end |> simpset_of;
chaieb@23264
    17
huffman@47108
    18
val binarith = @{thms arith_simps}
huffman@47108
    19
val comp_arith = binarith @ @{thms simp_thms}
chaieb@23264
    20
wenzelm@55498
    21
fun prepare_for_linr q fm = 
chaieb@23264
    22
  let
chaieb@23264
    23
    val ps = Logic.strip_params fm
chaieb@23264
    24
    val hs = map HOLogic.dest_Trueprop (Logic.strip_assums_hyp fm)
chaieb@23264
    25
    val c = HOLogic.dest_Trueprop (Logic.strip_assums_concl fm)
chaieb@23264
    26
    fun mk_all ((s, T), (P,n)) =
wenzelm@42083
    27
      if Term.is_dependent P then
chaieb@23264
    28
        (HOLogic.all_const T $ Abs (s, T, P), n)
chaieb@23264
    29
      else (incr_boundvars ~1 P, n-1)
chaieb@23264
    30
    fun mk_all2 (v, t) = HOLogic.all_const (fastype_of v) $ lambda v t;
chaieb@23264
    31
      val rhs = hs
chaieb@23264
    32
(*    val (rhs,irhs) = List.partition (relevant (rev ps)) hs *)
chaieb@23264
    33
    val np = length ps
wenzelm@33004
    34
    val (fm',np) =  List.foldr (fn ((x, T), (fm,n)) => mk_all ((x, T), (fm,n)))
wenzelm@33004
    35
      (List.foldr HOLogic.mk_imp c rhs, np) ps
haftmann@27436
    36
    val (vs, _) = List.partition (fn t => q orelse (type_of t) = HOLogic.natT)
wenzelm@44121
    37
      (Misc_Legacy.term_frees fm' @ Misc_Legacy.term_vars fm');
wenzelm@33004
    38
    val fm2 = List.foldr mk_all2 fm' vs
chaieb@23264
    39
  in (fm2, np + length vs, length rhs) end;
chaieb@23264
    40
chaieb@23264
    41
(*Object quantifier to meta --*)
chaieb@23264
    42
fun spec_step n th = if (n=0) then th else (spec_step (n-1) th) RS spec ;
chaieb@23264
    43
chaieb@23264
    44
(* object implication to meta---*)
chaieb@23264
    45
fun mp_step n th = if (n=0) then th else (mp_step (n-1) th) RS mp;
chaieb@23264
    46
chaieb@23264
    47
wenzelm@35233
    48
fun linr_tac ctxt q =
wenzelm@54742
    49
    Object_Logic.atomize_prems_tac ctxt
wenzelm@35233
    50
        THEN' (REPEAT_DETERM o split_tac [@{thm split_min}, @{thm split_max}, @{thm abs_split}])
wenzelm@35233
    51
        THEN' SUBGOAL (fn (g, i) =>
chaieb@23264
    52
  let
wenzelm@42361
    53
    val thy = Proof_Context.theory_of ctxt
chaieb@23264
    54
    (* Transform the term*)
wenzelm@55498
    55
    val (t,np,nh) = prepare_for_linr q g
chaieb@23264
    56
    (* Some simpsets for dealing with mod div abs and nat*)
wenzelm@51717
    57
    val simpset0 = put_simpset HOL_basic_ss ctxt addsimps comp_arith
chaieb@23264
    58
    val ct = cterm_of thy (HOLogic.mk_Trueprop t)
chaieb@23264
    59
    (* Theorem for the nat --> int transformation *)
chaieb@23264
    60
   val pre_thm = Seq.hd (EVERY
chaieb@23264
    61
      [simp_tac simpset0 1,
wenzelm@51717
    62
       TRY (simp_tac (put_simpset ferrack_ss ctxt) 1)]
wenzelm@36945
    63
      (Thm.trivial ct))
chaieb@23264
    64
    fun assm_tac i = REPEAT_DETERM_N nh (assume_tac i)
chaieb@23264
    65
    (* The result of the quantifier elimination *)
wenzelm@35233
    66
    val (th, tac) = case prop_of pre_thm of
wenzelm@56245
    67
        Const (@{const_name Pure.imp}, _) $ (Const (@{const_name Trueprop}, _) $ t1) $ _ =>
wenzelm@52131
    68
    let val pth = linr_oracle (ctxt, Envir.eta_long [] t1)
chaieb@23264
    69
    in 
wenzelm@55498
    70
       ((pth RS iffD2) RS pre_thm,
wenzelm@55498
    71
        assm_tac (i + 1) THEN (if q then I else TRY) (rtac TrueI i))
chaieb@23264
    72
    end
chaieb@23264
    73
      | _ => (pre_thm, assm_tac i)
wenzelm@35233
    74
  in rtac ((mp_step nh o spec_step np) th) i THEN tac end);
chaieb@23264
    75
huffman@23469
    76
end