src/HOL/Tools/Predicate_Compile/predicate_compile_core.ML
changeset 39658 b3644e40f661
parent 39657 5e57675b7e40
child 39670 632bcdb80d88
equal deleted inserted replaced
39657:5e57675b7e40 39658:b3644e40f661
   625       (Trueprop_conv (Conv.try_conv (Conv.rewr_conv (Thm.symmetric @{thm Predicate.eq_is_eq})))))
   625       (Trueprop_conv (Conv.try_conv (Conv.rewr_conv (Thm.symmetric @{thm Predicate.eq_is_eq})))))
   626     (Thm.transfer thy rule)
   626     (Thm.transfer thy rule)
   627 
   627 
   628 fun preprocess_intro thy = expand_tuples thy #> preprocess_equality thy
   628 fun preprocess_intro thy = expand_tuples thy #> preprocess_equality thy
   629 
   629 
   630 fun preprocess_equality_elim ctxt elimrule =
   630 (* fetching introduction rules or registering introduction rules *)
   631   let
   631 
   632     fun replace_eqs (Const (@{const_name Trueprop}, _) $ (Const (@{const_name HOL.eq}, T) $ lhs $ rhs)) =
       
   633        HOLogic.mk_Trueprop (Const (@{const_name Predicate.eq}, T) $ lhs $ rhs)
       
   634      | replace_eqs t = t
       
   635     val thy = ProofContext.theory_of ctxt
       
   636     val ((_, [elimrule]), ctxt') = Variable.import false [elimrule] ctxt
       
   637     val prems = Thm.prems_of elimrule
       
   638     val nargs = length (snd (strip_comb (HOLogic.dest_Trueprop (hd prems))))
       
   639     fun preprocess_case t =
       
   640       let
       
   641         val params = Logic.strip_params t
       
   642         val (assums1, assums2) = chop nargs (Logic.strip_assums_hyp t)
       
   643         val assums_hyp' = assums1 @ (map replace_eqs assums2)
       
   644       in
       
   645         list_all (params, Logic.list_implies (assums_hyp', Logic.strip_assums_concl t))
       
   646       end
       
   647     val cases' = map preprocess_case (tl prems)
       
   648     val elimrule' = Logic.list_implies ((hd prems) :: cases', Thm.concl_of elimrule)
       
   649     val bigeq = (Thm.symmetric (Conv.implies_concl_conv
       
   650       (MetaSimplifier.rewrite true [@{thm Predicate.eq_is_eq}])
       
   651         (cterm_of thy elimrule')))
       
   652     val tac = (fn _ => Skip_Proof.cheat_tac thy)
       
   653     val eq = Goal.prove ctxt' [] [] (Logic.mk_equals ((Thm.prop_of elimrule), elimrule')) tac
       
   654   in
       
   655     Thm.equal_elim eq elimrule |> singleton (Variable.export ctxt' ctxt)
       
   656   end;
       
   657 
       
   658 fun preprocess_elim ctxt = expand_tuples_elim ctxt #> preprocess_equality_elim ctxt
       
   659   
       
   660 val no_compilation = ([], ([], []))
   632 val no_compilation = ([], ([], []))
   661 
   633 
   662 fun fetch_pred_data ctxt name =
   634 fun fetch_pred_data ctxt name =
   663   case try (Inductive.the_inductive ctxt) name of
   635   case try (Inductive.the_inductive ctxt) name of
   664     SOME (info as (_, result)) => 
   636     SOME (info as (_, result)) =>