src/HOL/Tools/Predicate_Compile/core_data.ML
changeset 80636 4041e7c8059d
parent 74561 8e6c973003c8
equal deleted inserted replaced
80635:27d5452d20fc 80636:4041e7c8059d
   272 
   272 
   273         val pos = Position.thread_data ()
   273         val pos = Position.thread_data ()
   274         fun is_intro_of intro =
   274         fun is_intro_of intro =
   275           let
   275           let
   276             val (const, _) = strip_comb (HOLogic.dest_Trueprop (Thm.concl_of intro))
   276             val (const, _) = strip_comb (HOLogic.dest_Trueprop (Thm.concl_of intro))
   277           in (fst (dest_Const const) = name) end;
   277           in dest_Const_name const = name end;
   278         val intros = map (preprocess_intro thy) (filter is_intro_of (#intrs result))
   278         val intros = map (preprocess_intro thy) (filter is_intro_of (#intrs result))
   279         val index = find_index (fn s => s = name) (#names (fst info))
   279         val index = find_index (fn s => s = name) (#names (fst info))
   280         val pre_elim = nth (#elims result) index
   280         val pre_elim = nth (#elims result) index
   281         val pred = nth (#preds result) index
   281         val pred = nth (#preds result) index
   282         val elim_t = mk_casesrule ctxt pred intros
   282         val elim_t = mk_casesrule ctxt pred intros
   308         (is_inductive_predicate ctxt c orelse is_registered ctxt c))
   308         (is_inductive_predicate ctxt c orelse is_registered ctxt c))
   309   end;
   309   end;
   310 
   310 
   311 fun add_intro (opt_case_name, thm) thy =
   311 fun add_intro (opt_case_name, thm) thy =
   312   let
   312   let
   313     val (name, _) = dest_Const (fst (strip_intro_concl thm))
   313     val name = dest_Const_name (fst (strip_intro_concl thm))
   314     fun cons_intro gr =
   314     fun cons_intro gr =
   315       (case try (Graph.get_node gr) name of
   315       (case try (Graph.get_node gr) name of
   316         SOME _ =>
   316         SOME _ =>
   317           Graph.map_node name (map_pred_data
   317           Graph.map_node name (map_pred_data
   318             (apsnd (apfst (apfst (apfst (fn intros => intros @ [(opt_case_name, thm)])))))) gr
   318             (apsnd (apfst (apfst (apfst (fn intros => intros @ [(opt_case_name, thm)])))))) gr
   323                 (((([(opt_case_name, thm)], NONE), false), no_compilation)))) gr)
   323                 (((([(opt_case_name, thm)], NONE), false), no_compilation)))) gr)
   324   in PredData.map cons_intro thy end
   324   in PredData.map cons_intro thy end
   325 
   325 
   326 fun set_elim thm =
   326 fun set_elim thm =
   327   let
   327   let
   328     val (name, _) =
   328     val name = dest_Const_name (fst (strip_comb (HOLogic.dest_Trueprop (hd (Thm.prems_of thm)))))
   329       dest_Const (fst (strip_comb (HOLogic.dest_Trueprop (hd (Thm.prems_of thm)))))
       
   330   in
   329   in
   331     PredData.map (Graph.map_node name (map_pred_data (apsnd (apfst (apfst (apsnd (K (SOME thm))))))))
   330     PredData.map (Graph.map_node name (map_pred_data (apsnd (apfst (apfst (apsnd (K (SOME thm))))))))
   332   end
   331   end
   333 
   332 
   334 fun register_predicate (constname, intros, elim) thy =
   333 fun register_predicate (constname, intros, elim) thy =
   344   end
   343   end
   345 
   344 
   346 fun register_intros (constname, pre_intros) thy =
   345 fun register_intros (constname, pre_intros) thy =
   347   let
   346   let
   348     val T = Sign.the_const_type thy constname
   347     val T = Sign.the_const_type thy constname
   349     fun constname_of_intro intr = fst (dest_Const (fst (strip_intro_concl intr)))
   348     fun constname_of_intro intr = dest_Const_name (fst (strip_intro_concl intr))
   350     val _ = if not (forall (fn intr => constname_of_intro intr = constname) pre_intros) then
   349     val _ = if not (forall (fn intr => constname_of_intro intr = constname) pre_intros) then
   351       error ("register_intros: Introduction rules of different constants are used\n" ^
   350       error ("register_intros: Introduction rules of different constants are used\n" ^
   352         "expected rules for " ^ constname ^ ", but received rules for " ^
   351         "expected rules for " ^ constname ^ ", but received rules for " ^
   353           commas (map constname_of_intro pre_intros))
   352           commas (map constname_of_intro pre_intros))
   354       else ()
   353       else ()