equal
deleted
inserted
replaced
856 PureThy.add_defs false [((Binding.name (Long_Name.base_name mode_id ^ "_def"), def), [])] |
856 PureThy.add_defs false [((Binding.name (Long_Name.base_name mode_id ^ "_def"), def), [])] |
857 val (intro, elim) = create_intro_elim_rule nparams mode definition mode_id funT (Const (name, T)) thy' |
857 val (intro, elim) = create_intro_elim_rule nparams mode definition mode_id funT (Const (name, T)) thy' |
858 in thy' |> add_predfun name mode (mode_id, definition, intro, elim) |
858 in thy' |> add_predfun name mode (mode_id, definition, intro, elim) |
859 |> PureThy.store_thm (Binding.name (Long_Name.base_name mode_id ^ "I"), intro) |> snd |
859 |> PureThy.store_thm (Binding.name (Long_Name.base_name mode_id ^ "I"), intro) |> snd |
860 |> PureThy.store_thm (Binding.name (Long_Name.base_name mode_id ^ "E"), elim) |> snd |
860 |> PureThy.store_thm (Binding.name (Long_Name.base_name mode_id ^ "E"), elim) |> snd |
|
861 |> Theory.checkpoint |
861 end; |
862 end; |
862 in |
863 in |
863 fold create_definition modes thy |
864 fold create_definition modes thy |
864 end; |
865 end; |
865 |
866 |
1070 val index = find_index (fn s => s = pred) (#names (fst ind_result)) |
1071 val index = find_index (fn s => s = pred) (#names (fst ind_result)) |
1071 val (_, T) = dest_Const (nth (#preds (snd ind_result)) index) *) |
1072 val (_, T) = dest_Const (nth (#preds (snd ind_result)) index) *) |
1072 val nargs = length (binder_types T) - nparams_of thy pred |
1073 val nargs = length (binder_types T) - nparams_of thy pred |
1073 val pred_case_rule = singleton (ind_set_codegen_preproc thy) |
1074 val pred_case_rule = singleton (ind_set_codegen_preproc thy) |
1074 (preprocess_elim thy nargs (the_elim_of thy pred)) |
1075 (preprocess_elim thy nargs (the_elim_of thy pred)) |
1075 (* FIXME preprocessor |> Simplifier.full_simplify (HOL_basic_ss addsimps [@ {thm Predicate.memb_code}])*) |
1076 (* FIXME preprocessor |> Simplifier.full_simplify (HOL_basic_ss addsimps [@{thm Predicate.memb_code}])*) |
1076 in |
1077 in |
1077 REPEAT_DETERM (CHANGED (rewtac @{thm "split_paired_all"})) |
1078 REPEAT_DETERM (CHANGED (rewtac @{thm "split_paired_all"})) |
1078 THEN etac (predfun_elim_of thy pred mode) 1 |
1079 THEN etac (predfun_elim_of thy pred mode) 1 |
1079 THEN etac pred_case_rule 1 |
1080 THEN etac pred_case_rule 1 |
1080 THEN (EVERY (map |
1081 THEN (EVERY (map |
1363 prepare_intrs thy prednames |
1364 prepare_intrs thy prednames |
1364 val _ = tracing "Infering modes..." |
1365 val _ = tracing "Infering modes..." |
1365 val modes = infer_modes thy extra_modes arities param_vs clauses |
1366 val modes = infer_modes thy extra_modes arities param_vs clauses |
1366 val _ = print_modes modes |
1367 val _ = print_modes modes |
1367 val _ = tracing "Defining executable functions..." |
1368 val _ = tracing "Defining executable functions..." |
1368 val thy' = fold (create_definitions preds nparams) modes thy |
1369 val thy' = fold (create_definitions preds nparams) modes thy |> Theory.checkpoint |
1369 val clauses' = map (fn (s, cls) => (s, (the (AList.lookup (op =) preds s), cls))) clauses |
1370 val clauses' = map (fn (s, cls) => (s, (the (AList.lookup (op =) preds s), cls))) clauses |
1370 val _ = tracing "Compiling equations..." |
1371 val _ = tracing "Compiling equations..." |
1371 val ts = compile_preds thy' all_vs param_vs (extra_modes @ modes) clauses' |
1372 val ts = compile_preds thy' all_vs param_vs (extra_modes @ modes) clauses' |
1372 val _ = map (Output.tracing o (Syntax.string_of_term_global thy')) (flat ts) |
1373 val _ = map (Output.tracing o (Syntax.string_of_term_global thy')) (flat ts) |
1373 val pred_mode = |
1374 val pred_mode = |
1377 prove_preds thy' all_vs param_vs (extra_modes @ modes) clauses (pred_mode ~~ (flat ts)) |
1378 prove_preds thy' all_vs param_vs (extra_modes @ modes) clauses (pred_mode ~~ (flat ts)) |
1378 val thy'' = fold (fn (name, result_thms) => fn thy => snd (PureThy.add_thmss |
1379 val thy'' = fold (fn (name, result_thms) => fn thy => snd (PureThy.add_thmss |
1379 [((Binding.qualify true (Long_Name.base_name name) (Binding.name "equation"), result_thms), |
1380 [((Binding.qualify true (Long_Name.base_name name) (Binding.name "equation"), result_thms), |
1380 [Attrib.attribute_i thy Code.add_default_eqn_attrib])] thy)) |
1381 [Attrib.attribute_i thy Code.add_default_eqn_attrib])] thy)) |
1381 (arrange ((map (fn ((name, _), _) => name) pred_mode) ~~ result_thms)) thy' |
1382 (arrange ((map (fn ((name, _), _) => name) pred_mode) ~~ result_thms)) thy' |
|
1383 |> Theory.checkpoint |
1382 in |
1384 in |
1383 thy'' |
1385 thy'' |
1384 end |
1386 end |
1385 |
1387 |
1386 (* generation of case rules from user-given introduction rules *) |
1388 (* generation of case rules from user-given introduction rules *) |
1422 (data, keys) |
1424 (data, keys) |
1423 end; |
1425 end; |
1424 |
1426 |
1425 fun add_equations name thy = |
1427 fun add_equations name thy = |
1426 let |
1428 let |
1427 val thy' = PredData.map (Graph.extend (dependencies_of thy) name) thy; |
1429 val thy' = PredData.map (Graph.extend (dependencies_of thy) name) thy |> Theory.checkpoint; |
1428 (*val preds = Graph.all_preds (PredData.get thy') [name] |> filter_out (has_elim thy') *) |
1430 (*val preds = Graph.all_preds (PredData.get thy') [name] |> filter_out (has_elim thy') *) |
1429 fun strong_conn_of gr keys = |
1431 fun strong_conn_of gr keys = |
1430 Graph.strong_conn (Graph.subgraph (member (op =) (Graph.all_succs gr keys)) gr) |
1432 Graph.strong_conn (Graph.subgraph (member (op =) (Graph.all_succs gr keys)) gr) |
1431 val scc = strong_conn_of (PredData.get thy') [name] |
1433 val scc = strong_conn_of (PredData.get thy') [name] |
1432 val thy'' = fold_rev |
1434 val thy'' = fold_rev |
1433 (fn preds => fn thy => |
1435 (fn preds => fn thy => |
1434 if forall (null o modes_of thy) preds then add_equations_of preds thy else thy) |
1436 if forall (null o modes_of thy) preds then add_equations_of preds thy else thy) |
1435 scc thy' |
1437 scc thy' |> Theory.checkpoint |
1436 in thy'' end |
1438 in thy'' end |
1437 |
1439 |
1438 (** user interface **) |
1440 (** user interface **) |
1439 |
1441 |
1440 local |
1442 local |
1453 |
1455 |
1454 val thy = ProofContext.theory_of lthy |
1456 val thy = ProofContext.theory_of lthy |
1455 val const = prep_const thy raw_const |
1457 val const = prep_const thy raw_const |
1456 |
1458 |
1457 val lthy' = LocalTheory.theory (PredData.map (Graph.extend (dependencies_of thy) const)) lthy |
1459 val lthy' = LocalTheory.theory (PredData.map (Graph.extend (dependencies_of thy) const)) lthy |
|
1460 |> LocalTheory.checkpoint |
1458 val thy' = ProofContext.theory_of lthy' |
1461 val thy' = ProofContext.theory_of lthy' |
1459 val preds = Graph.all_preds (PredData.get thy') [const] |> filter_out (has_elim thy') |
1462 val preds = Graph.all_preds (PredData.get thy') [const] |> filter_out (has_elim thy') |
1460 |
1463 |
1461 fun mk_cases const = |
1464 fun mk_cases const = |
1462 let |
1465 let |
1465 in mk_casesrule lthy' nparams intros end |
1468 in mk_casesrule lthy' nparams intros end |
1466 val cases_rules = map mk_cases preds |
1469 val cases_rules = map mk_cases preds |
1467 fun after_qed thms = |
1470 fun after_qed thms = |
1468 LocalTheory.theory (fold set_elim (map the_single thms) #> add_equations const) |
1471 LocalTheory.theory (fold set_elim (map the_single thms) #> add_equations const) |
1469 in |
1472 in |
1470 Proof.theorem_i NONE after_qed (map (single o (rpair [])) cases_rules) lthy |
1473 Proof.theorem_i NONE after_qed (map (single o (rpair [])) cases_rules) lthy' |
1471 (* FIXME: expected the actual local_theory to be lthy'; but works with lthy ??*) |
|
1472 end; |
1474 end; |
1473 |
1475 |
1474 structure P = OuterParse |
1476 structure P = OuterParse |
1475 |
1477 |
1476 in |
1478 in |