| 23489 |      1 | (*  Title:      HOL/Tools/Qelim/qelim.ML
 | 
| 23466 |      2 |     ID:         $Id$
 | 
| 23904 |      3 |     Author:     Amine Chaieb, TU Muenchen
 | 
| 23466 |      4 | 
 | 
| 23904 |      5 | Generic quantifier elimination conversions for HOL formulae.
 | 
| 23466 |      6 | *)
 | 
|  |      7 | 
 | 
|  |      8 | signature QELIM =
 | 
|  |      9 | sig
 | 
| 23904 |     10 |  val gen_qelim_conv: conv -> conv -> conv -> (cterm -> 'a -> 'a) -> 'a 
 | 
|  |     11 |                      -> ('a -> conv) -> ('a -> conv) -> ('a -> conv) -> conv
 | 
|  |     12 |  val standard_qelim_conv: (cterm list -> conv) -> (cterm list -> conv) 
 | 
|  |     13 |                           -> (cterm list -> conv) -> conv
 | 
| 23466 |     14 | end;
 | 
|  |     15 | 
 | 
| 23489 |     16 | structure Qelim: QELIM =
 | 
| 23466 |     17 | struct
 | 
|  |     18 | 
 | 
|  |     19 | open Conv;
 | 
|  |     20 | 
 | 
| 23489 |     21 | val all_not_ex = mk_meta_eq @{thm "all_not_ex"};
 | 
|  |     22 | 
 | 
| 23524 |     23 | fun gen_qelim_conv precv postcv simpex_conv ins env atcv ncv qcv =
 | 
| 23489 |     24 |  let
 | 
| 23466 |     25 |   fun conv env p =
 | 
| 23489 |     26 |    case (term_of p) of
 | 
| 23904 |     27 |     Const(s,T)$_$_ => 
 | 
|  |     28 |        if domain_type T = HOLogic.boolT
 | 
|  |     29 |           andalso s mem ["op &","op |","op -->","op ="]
 | 
|  |     30 |        then binop_conv (conv env) p 
 | 
|  |     31 |        else atcv env p
 | 
| 23466 |     32 |   | Const("Not",_)$_ => arg_conv (conv env) p
 | 
| 23489 |     33 |   | Const("Ex",_)$Abs(s,_,_) =>
 | 
|  |     34 |     let
 | 
| 23466 |     35 |      val (e,p0) = Thm.dest_comb p
 | 
|  |     36 |      val (x,p') = Thm.dest_abs (SOME s) p0
 | 
|  |     37 |      val env' = ins x env
 | 
|  |     38 |      val th = Thm.abstract_rule s x ((conv env' then_conv ncv env') p')
 | 
|  |     39 |                    |> Drule.arg_cong_rule e
 | 
|  |     40 |      val th' = simpex_conv (Thm.rhs_of th)
 | 
|  |     41 |      val (l,r) = Thm.dest_equals (cprop_of th')
 | 
| 23593 |     42 |     in if Thm.is_reflexive th' then Thm.transitive th (qcv env (Thm.rhs_of th))
 | 
| 23466 |     43 |        else Thm.transitive (Thm.transitive th th') (conv env r) end
 | 
| 23489 |     44 |   | Const("Ex",_)$ _ => (Thm.eta_long_conversion then_conv conv env) p
 | 
|  |     45 |   | Const("All",_)$_ =>
 | 
|  |     46 |     let
 | 
| 23466 |     47 |      val p = Thm.dest_arg p
 | 
|  |     48 |      val ([(_,T)],[]) = Thm.match (@{cpat "All"}, Thm.dest_fun p)
 | 
| 23489 |     49 |      val th = instantiate' [SOME T] [SOME p] all_not_ex
 | 
|  |     50 |     in transitive th (conv env (Thm.rhs_of th))
 | 
| 23466 |     51 |     end
 | 
|  |     52 |   | _ => atcv env p
 | 
|  |     53 |  in precv then_conv (conv env) then_conv postcv end
 | 
| 23489 |     54 | 
 | 
| 23904 |     55 | (* Instantiation of some parameter for most common cases *)
 | 
| 23489 |     56 | 
 | 
| 23904 |     57 | local
 | 
| 23489 |     58 | val pcv = Simplifier.rewrite
 | 
|  |     59 |                  (HOL_basic_ss addsimps (simp_thms @ ex_simps @ all_simps)
 | 
|  |     60 |                      @ [@{thm "all_not_ex"}, not_all, ex_disj_distrib]);
 | 
| 23466 |     61 | 
 | 
| 23904 |     62 | in fun standard_qelim_conv atcv ncv qcv p =
 | 
|  |     63 |       gen_qelim_conv pcv pcv pcv cons (Thm.add_cterm_frees p []) atcv ncv qcv p
 | 
|  |     64 | end;
 | 
| 23466 |     65 | 
 | 
|  |     66 | end;
 |