src/HOL/Decision_Procs/ferrack_tac.ML
author nipkow
Tue Feb 23 16:25:08 2016 +0100 (2016-02-23)
changeset 62390 842917225d56
parent 61609 77b453bd616f
child 69597 ff784d5a5bfb
permissions -rw-r--r--
more canonical names
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
lp15@61609
    13
val ferrack_ss = let val ths = [@{thm of_int_eq_iff}, @{thm of_int_less_iff}, 
lp15@61609
    14
                                @{thm 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@58956
    50
        THEN' (REPEAT_DETERM o split_tac ctxt [@{thm split_min}, @{thm split_max}, @{thm abs_split}])
wenzelm@35233
    51
        THEN' SUBGOAL (fn (g, i) =>
chaieb@23264
    52
  let
chaieb@23264
    53
    (* Transform the term*)
wenzelm@55498
    54
    val (t,np,nh) = prepare_for_linr q g
chaieb@23264
    55
    (* Some simpsets for dealing with mod div abs and nat*)
wenzelm@51717
    56
    val simpset0 = put_simpset HOL_basic_ss ctxt addsimps comp_arith
wenzelm@59629
    57
    val ct = Thm.cterm_of ctxt (HOLogic.mk_Trueprop t)
chaieb@23264
    58
    (* Theorem for the nat --> int transformation *)
chaieb@23264
    59
   val pre_thm = Seq.hd (EVERY
chaieb@23264
    60
      [simp_tac simpset0 1,
wenzelm@51717
    61
       TRY (simp_tac (put_simpset ferrack_ss ctxt) 1)]
wenzelm@36945
    62
      (Thm.trivial ct))
wenzelm@58963
    63
    fun assm_tac i = REPEAT_DETERM_N nh (assume_tac ctxt i)
chaieb@23264
    64
    (* The result of the quantifier elimination *)
wenzelm@59582
    65
    val (th, tac) = case Thm.prop_of pre_thm of
wenzelm@56245
    66
        Const (@{const_name Pure.imp}, _) $ (Const (@{const_name Trueprop}, _) $ t1) $ _ =>
wenzelm@52131
    67
    let val pth = linr_oracle (ctxt, Envir.eta_long [] t1)
chaieb@23264
    68
    in 
wenzelm@55498
    69
       ((pth RS iffD2) RS pre_thm,
wenzelm@60754
    70
        assm_tac (i + 1) THEN (if q then I else TRY) (resolve_tac ctxt [TrueI] i))
chaieb@23264
    71
    end
chaieb@23264
    72
      | _ => (pre_thm, assm_tac i)
wenzelm@60754
    73
  in resolve_tac ctxt [(mp_step nh o spec_step np) th] i THEN tac end);
chaieb@23264
    74
huffman@23469
    75
end