src/HOL/ex/predicate_compile.ML
changeset 31517 e8a64ab9fe99
parent 31515 62fc203eed88
child 31524 8abf99ab669c
equal deleted inserted replaced
31516:9801a92d52d7 31517:e8a64ab9fe99
    22   val code_pred_cmd: string -> Proof.context -> Proof.state
    22   val code_pred_cmd: string -> Proof.context -> Proof.state
    23 (*  val print_alternative_rules: theory -> theory (*FIXME diagnostic command?*) *)
    23 (*  val print_alternative_rules: theory -> theory (*FIXME diagnostic command?*) *)
    24   val do_proofs: bool ref
    24   val do_proofs: bool ref
    25   val analyze_compr: theory -> term -> term
    25   val analyze_compr: theory -> term -> term
    26   val eval_ref: (unit -> term Predicate.pred) option ref
    26   val eval_ref: (unit -> term Predicate.pred) option ref
    27  (* val extend : (key -> 'a * key list) -> key list -> 'a Graph.T -> 'a Graph.T *)
       
    28   val add_equations : string -> theory -> theory
    27   val add_equations : string -> theory -> theory
    29 end;
    28 end;
    30 
    29 
    31 structure Predicate_Compile : PREDICATE_COMPILE =
    30 structure Predicate_Compile : PREDICATE_COMPILE =
    32 struct
    31 struct
  1381     |> filter (is_inductive_predicate thy)
  1380     |> filter (is_inductive_predicate thy)
  1382   in
  1381   in
  1383     (data, keys)
  1382     (data, keys)
  1384   end;
  1383   end;
  1385 
  1384 
  1386 fun extend explore keys gr =
       
  1387   let
       
  1388     fun contains_node gr key = member (op =) (Graph.keys gr) key
       
  1389     fun extend' key gr =
       
  1390       let
       
  1391         val (node, preds) = explore key
       
  1392       in
       
  1393         gr |> (not (contains_node gr key)) ?
       
  1394           (Graph.new_node (key, node)
       
  1395           #> fold extend' preds
       
  1396           #> fold (Graph.add_edge o (pair key)) preds)
       
  1397       end
       
  1398   in fold extend' keys gr end
       
  1399 
       
  1400 fun mk_graph explore keys = extend explore keys Graph.empty
       
  1401 
       
  1402 fun add_equations name thy =
  1385 fun add_equations name thy =
  1403   let
  1386   let
  1404     val thy' = PredData.map (extend (dependencies_of thy) [name]) thy;
  1387     val thy' = PredData.map (Graph.extend (dependencies_of thy) [name]) thy;
  1405     (*val preds = Graph.all_preds (PredData.get thy') [name] |> filter_out (has_elim thy') *)
  1388     (*val preds = Graph.all_preds (PredData.get thy') [name] |> filter_out (has_elim thy') *)
  1406     fun strong_conn_of gr keys =
  1389     fun strong_conn_of gr keys =
  1407       Graph.strong_conn (Graph.subgraph (member (op =) (Graph.all_succs gr keys)) gr)
  1390       Graph.strong_conn (Graph.subgraph (member (op =) (Graph.all_succs gr keys)) gr)
  1408     val scc = strong_conn_of (PredData.get thy') [name]
  1391     val scc = strong_conn_of (PredData.get thy') [name]
  1409     val thy'' = fold_rev add_equations_of scc thy'
  1392     val thy'' = fold_rev add_equations_of scc thy'
  1425 fun generic_code_pred prep_const raw_const lthy =
  1408 fun generic_code_pred prep_const raw_const lthy =
  1426   let
  1409   let
  1427     val thy = (ProofContext.theory_of lthy)
  1410     val thy = (ProofContext.theory_of lthy)
  1428     val const = prep_const thy raw_const
  1411     val const = prep_const thy raw_const
  1429     val lthy' = lthy
  1412     val lthy' = lthy
  1430     val thy' = PredData.map (extend (dependencies_of thy) [const]) thy
  1413     val thy' = PredData.map (Graph.extend (dependencies_of thy) [const]) thy
  1431     val preds = Graph.all_preds (PredData.get thy') [const] |> filter_out (has_elim thy')
  1414     val preds = Graph.all_preds (PredData.get thy') [const] |> filter_out (has_elim thy')
  1432     val _ = Output.tracing ("preds: " ^ commas preds)
  1415     val _ = Output.tracing ("preds: " ^ commas preds)
  1433     (*
  1416     (*
  1434     fun mk_elim pred =
  1417     fun mk_elim pred =
  1435       let
  1418       let