src/HOL/simpdata.ML
changeset 15531 08c8dad8e399
parent 15423 761a4f8e6ad6
child 15570 8d8c70b41bab
equal deleted inserted replaced
15530:6f43714517ee 15531:08c8dad8e399
    94 (*** make simplification procedures for quantifier elimination ***)
    94 (*** make simplification procedures for quantifier elimination ***)
    95 
    95 
    96 structure Quantifier1 = Quantifier1Fun
    96 structure Quantifier1 = Quantifier1Fun
    97 (struct
    97 (struct
    98   (*abstract syntax*)
    98   (*abstract syntax*)
    99   fun dest_eq((c as Const("op =",_)) $ s $ t) = Some(c,s,t)
    99   fun dest_eq((c as Const("op =",_)) $ s $ t) = SOME(c,s,t)
   100     | dest_eq _ = None;
   100     | dest_eq _ = NONE;
   101   fun dest_conj((c as Const("op &",_)) $ s $ t) = Some(c,s,t)
   101   fun dest_conj((c as Const("op &",_)) $ s $ t) = SOME(c,s,t)
   102     | dest_conj _ = None;
   102     | dest_conj _ = NONE;
   103   fun dest_imp((c as Const("op -->",_)) $ s $ t) = Some(c,s,t)
   103   fun dest_imp((c as Const("op -->",_)) $ s $ t) = SOME(c,s,t)
   104     | dest_imp _ = None;
   104     | dest_imp _ = NONE;
   105   val conj = HOLogic.conj
   105   val conj = HOLogic.conj
   106   val imp  = HOLogic.imp
   106   val imp  = HOLogic.imp
   107   (*rules*)
   107   (*rules*)
   108   val iff_reflection = eq_reflection
   108   val iff_reflection = eq_reflection
   109   val iffI = iffI
   109   val iffI = iffI
   148 in
   148 in
   149 val let_simproc =
   149 val let_simproc =
   150   Simplifier.simproc (Theory.sign_of (the_context ())) "let_simp" ["Let x f"] 
   150   Simplifier.simproc (Theory.sign_of (the_context ())) "let_simp" ["Let x f"] 
   151    (fn sg => fn ss => fn t =>
   151    (fn sg => fn ss => fn t =>
   152       (case t of (Const ("Let",_)$x$f) => (* x and f are already in normal form *)
   152       (case t of (Const ("Let",_)$x$f) => (* x and f are already in normal form *)
   153          if not (!use_let_simproc) then None
   153          if not (!use_let_simproc) then NONE
   154          else if is_Free x orelse is_Bound x orelse is_Const x 
   154          else if is_Free x orelse is_Bound x orelse is_Const x 
   155          then Some Let_def  
   155          then SOME Let_def  
   156          else
   156          else
   157           let
   157           let
   158              val n = case f of (Abs (x,_,_)) => x | _ => "x";
   158              val n = case f of (Abs (x,_,_)) => x | _ => "x";
   159              val cx = cterm_of sg x;
   159              val cx = cterm_of sg x;
   160              val {T=xT,...} = rep_cterm cx;
   160              val {T=xT,...} = rep_cterm cx;
   164              val g' = abstract_over (x,g);
   164              val g' = abstract_over (x,g);
   165            in (if (g aconv g') 
   165            in (if (g aconv g') 
   166                then
   166                then
   167                   let
   167                   let
   168                     val rl = cterm_instantiate [(f_Let_unfold,cf)] Let_unfold;
   168                     val rl = cterm_instantiate [(f_Let_unfold,cf)] Let_unfold;
   169                   in Some (rl OF [fx_g]) end 
   169                   in SOME (rl OF [fx_g]) end 
   170                else if betapply (f,x) aconv g then None (* avoid identity conversion *)
   170                else if betapply (f,x) aconv g then NONE (* avoid identity conversion *)
   171                else let 
   171                else let 
   172                      val abs_g'= Abs (n,xT,g');
   172                      val abs_g'= Abs (n,xT,g');
   173                      val g'x = abs_g'$x;
   173                      val g'x = abs_g'$x;
   174                      val g_g'x = symmetric (beta_conversion false (cterm_of sg g'x));
   174                      val g_g'x = symmetric (beta_conversion false (cterm_of sg g'x));
   175                      val rl = cterm_instantiate
   175                      val rl = cterm_instantiate
   176                                [(f_Let_folded,cterm_of sg f),
   176                                [(f_Let_folded,cterm_of sg f),
   177                                 (g_Let_folded,cterm_of sg abs_g')]
   177                                 (g_Let_folded,cterm_of sg abs_g')]
   178                                Let_folded; 
   178                                Let_folded; 
   179                    in Some (rl OF [transitive fx_g g_g'x]) end)
   179                    in SOME (rl OF [transitive fx_g g_g'x]) end)
   180            end
   180            end
   181         | _ => None))
   181         | _ => NONE))
   182 end
   182 end
   183 
   183 
   184 (*** Case splitting ***)
   184 (*** Case splitting ***)
   185 
   185 
   186 (*Make meta-equalities.  The operator below is Trueprop*)
   186 (*Make meta-equalities.  The operator below is Trueprop*)
   194     |   _$(Const("Not",_)$_)    => th RS Eq_FalseI
   194     |   _$(Const("Not",_)$_)    => th RS Eq_FalseI
   195     |   _                       => th RS Eq_TrueI;
   195     |   _                       => th RS Eq_TrueI;
   196 (* Expects Trueprop(.) if not == *)
   196 (* Expects Trueprop(.) if not == *)
   197 
   197 
   198 fun mk_eq_True r =
   198 fun mk_eq_True r =
   199   Some (r RS meta_eq_to_obj_eq RS Eq_TrueI) handle Thm.THM _ => None;
   199   SOME (r RS meta_eq_to_obj_eq RS Eq_TrueI) handle Thm.THM _ => NONE;
   200 
   200 
   201 (*Congruence rules for = (instead of ==)*)
   201 (*Congruence rules for = (instead of ==)*)
   202 fun mk_meta_cong rl =
   202 fun mk_meta_cong rl =
   203   zero_var_indexes(mk_meta_eq(replicate (nprems_of rl) meta_eq_to_obj_eq MRS rl))
   203   zero_var_indexes(mk_meta_eq(replicate (nprems_of rl) meta_eq_to_obj_eq MRS rl))
   204   handle THM _ =>
   204   handle THM _ =>
   251         (case concl_of th of
   251         (case concl_of th of
   252            Const("Trueprop",_) $ p =>
   252            Const("Trueprop",_) $ p =>
   253              (case head_of p of
   253              (case head_of p of
   254                 Const(a,_) =>
   254                 Const(a,_) =>
   255                   (case assoc(pairs,a) of
   255                   (case assoc(pairs,a) of
   256                      Some(rls) => flat (map atoms ([th] RL rls))
   256                      SOME(rls) => flat (map atoms ([th] RL rls))
   257                    | None => [th])
   257                    | NONE => [th])
   258               | _ => [th])
   258               | _ => [th])
   259          | _ => [th])
   259          | _ => [th])
   260   in atoms end;
   260   in atoms end;
   261 
   261 
   262 fun mksimps pairs =
   262 fun mksimps pairs =