| author | huffman | 
| Mon, 28 May 2007 03:45:41 +0200 | |
| changeset 23112 | 2bc882fbe51c | 
| parent 22903 | 95ad1a91ecef | 
| child 23189 | 4574ab8f3b21 | 
| permissions | -rw-r--r-- | 
| 19564 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 1 | (* Title: HOL/Tools/function_package/fundef_common.ML | 
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 2 | ID: $Id$ | 
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 3 | Author: Alexander Krauss, TU Muenchen | 
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 4 | |
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 5 | A package for general recursive function definitions. | 
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 6 | Common type definitions and other infrastructure. | 
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 7 | *) | 
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 8 | |
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 9 | structure FundefCommon = | 
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 10 | struct | 
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 11 | |
| 22498 
62cdd4b3e96b
made function syntax strict, requiring | to separate equations; cleanup
 krauss parents: 
22279diff
changeset | 12 | (* Profiling *) | 
| 21255 
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
 krauss parents: 
21237diff
changeset | 13 | val profile = ref false; | 
| 
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
 krauss parents: 
21237diff
changeset | 14 | |
| 
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
 krauss parents: 
21237diff
changeset | 15 | fun PROFILE msg = if !profile then timeap_msg msg else I | 
| 
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
 krauss parents: 
21237diff
changeset | 16 | |
| 22498 
62cdd4b3e96b
made function syntax strict, requiring | to separate equations; cleanup
 krauss parents: 
22279diff
changeset | 17 | |
| 
62cdd4b3e96b
made function syntax strict, requiring | to separate equations; cleanup
 krauss parents: 
22279diff
changeset | 18 | val acc_const_name = "Accessible_Part.acc" | 
| 20523 
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
 krauss parents: 
20289diff
changeset | 19 | fun mk_acc domT R = | 
| 22733 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 20 | Const (acc_const_name, (domT --> domT --> HOLogic.boolT) --> domT --> HOLogic.boolT) $ R | 
| 19564 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 21 | |
| 21319 
cf814e36f788
replaced "auto_term" by the simpler method "relation", which does not try
 krauss parents: 
21255diff
changeset | 22 | val function_name = suffix "C" | 
| 
cf814e36f788
replaced "auto_term" by the simpler method "relation", which does not try
 krauss parents: 
21255diff
changeset | 23 | val graph_name = suffix "_graph" | 
| 
cf814e36f788
replaced "auto_term" by the simpler method "relation", which does not try
 krauss parents: 
21255diff
changeset | 24 | val rel_name = suffix "_rel" | 
| 
cf814e36f788
replaced "auto_term" by the simpler method "relation", which does not try
 krauss parents: 
21255diff
changeset | 25 | val dom_name = suffix "_dom" | 
| 
cf814e36f788
replaced "auto_term" by the simpler method "relation", which does not try
 krauss parents: 
21255diff
changeset | 26 | |
| 19564 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 27 | type depgraph = int IntGraph.T | 
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 28 | |
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 29 | datatype ctx_tree | 
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 30 | = Leaf of term | 
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 31 | | Cong of (term * thm * depgraph * ((string * typ) list * thm list * ctx_tree) list) | 
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 32 | | RCall of (term * ctx_tree) | 
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 33 | |
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 34 | |
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 35 | |
| 19583 
c5fa77b03442
function-package: Changed record usage to make sml/nj happy...
 krauss parents: 
19564diff
changeset | 36 | datatype fundef_result = | 
| 
c5fa77b03442
function-package: Changed record usage to make sml/nj happy...
 krauss parents: 
19564diff
changeset | 37 | FundefResult of | 
| 19564 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 38 |      {
 | 
| 22733 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 39 | fs: term list, | 
| 20523 
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
 krauss parents: 
20289diff
changeset | 40 | G: term, | 
| 
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
 krauss parents: 
20289diff
changeset | 41 | R: term, | 
| 19770 
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
 krauss parents: 
19617diff
changeset | 42 | |
| 20523 
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
 krauss parents: 
20289diff
changeset | 43 | psimps : thm list, | 
| 22166 | 44 | trsimps : thm list option, | 
| 45 | ||
| 19770 
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
 krauss parents: 
19617diff
changeset | 46 | subset_pinducts : thm list, | 
| 
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
 krauss parents: 
19617diff
changeset | 47 | simple_pinducts : thm list, | 
| 
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
 krauss parents: 
19617diff
changeset | 48 | cases : thm, | 
| 
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
 krauss parents: 
19617diff
changeset | 49 | termination : thm, | 
| 22166 | 50 | domintros : thm list option | 
| 19770 
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
 krauss parents: 
19617diff
changeset | 51 | } | 
| 
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
 krauss parents: 
19617diff
changeset | 52 | |
| 22733 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 53 | |
| 21255 
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
 krauss parents: 
21237diff
changeset | 54 | datatype fundef_context_data = | 
| 
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
 krauss parents: 
21237diff
changeset | 55 | FundefCtxData of | 
| 
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
 krauss parents: 
21237diff
changeset | 56 |      {
 | 
| 22733 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 57 | defname : string, | 
| 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 58 | |
| 22166 | 59 | add_simps : string -> Attrib.src list -> thm list -> local_theory -> thm list * local_theory, | 
| 19770 
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
 krauss parents: 
19617diff
changeset | 60 | |
| 22733 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 61 | fs : term list, | 
| 21255 
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
 krauss parents: 
21237diff
changeset | 62 | R : term, | 
| 
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
 krauss parents: 
21237diff
changeset | 63 | |
| 
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
 krauss parents: 
21237diff
changeset | 64 | psimps: thm list, | 
| 
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
 krauss parents: 
21237diff
changeset | 65 | pinducts: thm list, | 
| 
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
 krauss parents: 
21237diff
changeset | 66 | termination: thm | 
| 
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
 krauss parents: 
21237diff
changeset | 67 | } | 
| 
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
 krauss parents: 
21237diff
changeset | 68 | |
| 22733 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 69 | fun morph_fundef_data phi (FundefCtxData {add_simps, fs, R, psimps, pinducts, termination, defname}) =
 | 
| 22623 | 70 | let | 
| 22733 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 71 | val term = Morphism.term phi val thm = Morphism.thm phi val fact = Morphism.fact phi | 
| 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 72 | val name = Morphism.name phi | 
| 22623 | 73 | in | 
| 22733 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 74 |       FundefCtxData { add_simps = add_simps (* contains no logical entities *), 
 | 
| 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 75 | fs = map term fs, R = term R, psimps = fact psimps, | 
| 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 76 | pinducts = fact pinducts, termination = thm termination, | 
| 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 77 | defname = name defname } | 
| 22623 | 78 | end | 
| 79 | ||
| 20523 
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
 krauss parents: 
20289diff
changeset | 80 | structure FundefData = GenericDataFun | 
| 22846 | 81 | ( | 
| 82 | type T = (term * fundef_context_data) NetRules.T; | |
| 22760 | 83 | val empty = NetRules.init | 
| 84 | (op aconv o pairself fst : (term * fundef_context_data) * (term * fundef_context_data) -> bool) | |
| 85 | fst; | |
| 19564 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 86 | val copy = I; | 
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 87 | val extend = I; | 
| 22733 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 88 | fun merge _ (tab1, tab2) = NetRules.merge (tab1, tab2) | 
| 22846 | 89 | ); | 
| 19564 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 90 | |
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 91 | |
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 92 | structure FundefCongs = GenericDataFun | 
| 22846 | 93 | ( | 
| 94 | type T = thm list | |
| 95 | val empty = [] | |
| 96 | val extend = I | |
| 97 | fun merge _ = Drule.merge_rules | |
| 98 | ); | |
| 19564 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 99 | |
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 100 | |
| 22733 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 101 | (* Generally useful?? *) | 
| 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 102 | fun lift_morphism thy f = | 
| 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 103 | let | 
| 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 104 | val term = Drule.term_rule thy f | 
| 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 105 | in | 
| 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 106 | Morphism.thm_morphism f $> Morphism.term_morphism term $> Morphism.typ_morphism (Logic.type_map term) | 
| 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 107 | end | 
| 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 108 | |
| 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 109 | fun import_fundef_data t ctxt = | 
| 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 110 | let | 
| 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 111 | val thy = Context.theory_of ctxt | 
| 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 112 | val ct = cterm_of thy t | 
| 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 113 | val inst_morph = lift_morphism thy o Thm.instantiate | 
| 19564 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 114 | |
| 22733 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 115 | fun match data = | 
| 22903 | 116 | SOME (morph_fundef_data (inst_morph (Thm.match (cterm_of thy (fst data), ct))) (snd data)) | 
| 22733 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 117 | handle Pattern.MATCH => NONE | 
| 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 118 | in | 
| 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 119 | get_first match (NetRules.retrieve (FundefData.get ctxt) t) | 
| 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 120 | end | 
| 19564 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 121 | |
| 22733 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 122 | fun import_last_fundef ctxt = | 
| 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 123 | case NetRules.rules (FundefData.get ctxt) of | 
| 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 124 | [] => NONE | 
| 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 125 | | (t, data) :: _ => | 
| 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 126 | let | 
| 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 127 | val ([t'], ctxt') = Variable.import_terms true [t] (Context.proof_of ctxt) | 
| 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 128 | in | 
| 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 129 | import_fundef_data t' (Context.Proof ctxt') | 
| 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 130 | end | 
| 19564 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 131 | |
| 22733 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 132 | val all_fundef_data = NetRules.rules o FundefData.get | 
| 21319 
cf814e36f788
replaced "auto_term" by the simpler method "relation", which does not try
 krauss parents: 
21255diff
changeset | 133 | |
| 19564 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 134 | val map_fundef_congs = FundefCongs.map | 
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 135 | val get_fundef_congs = FundefCongs.get | 
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 136 | |
| 20654 
d80502f0d701
1. Function package accepts a parameter (default "some_term"), which specifies the functions
 krauss parents: 
20523diff
changeset | 137 | |
| 21319 
cf814e36f788
replaced "auto_term" by the simpler method "relation", which does not try
 krauss parents: 
21255diff
changeset | 138 | |
| 22733 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 139 | structure TerminationRule = GenericDataFun | 
| 22846 | 140 | ( | 
| 141 | type T = thm list | |
| 142 | val empty = [] | |
| 143 | val extend = I | |
| 144 | fun merge _ = Drule.merge_rules | |
| 145 | ); | |
| 21319 
cf814e36f788
replaced "auto_term" by the simpler method "relation", which does not try
 krauss parents: 
21255diff
changeset | 146 | |
| 22733 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 147 | val get_termination_rules = TerminationRule.get | 
| 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 148 | val store_termination_rule = TerminationRule.map o cons | 
| 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 149 | val apply_termination_rule = resolve_tac o get_termination_rules o Context.Proof | 
| 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 150 | |
| 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 151 | fun add_fundef_data (data as FundefCtxData {fs, termination, ...}) =
 | 
| 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 152 | FundefData.map (fold (fn f => NetRules.insert (f, data)) fs) | 
| 
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
 krauss parents: 
22623diff
changeset | 153 | #> store_termination_rule termination | 
| 21319 
cf814e36f788
replaced "auto_term" by the simpler method "relation", which does not try
 krauss parents: 
21255diff
changeset | 154 | |
| 
cf814e36f788
replaced "auto_term" by the simpler method "relation", which does not try
 krauss parents: 
21255diff
changeset | 155 | |
| 
cf814e36f788
replaced "auto_term" by the simpler method "relation", which does not try
 krauss parents: 
21255diff
changeset | 156 | |
| 20654 
d80502f0d701
1. Function package accepts a parameter (default "some_term"), which specifies the functions
 krauss parents: 
20523diff
changeset | 157 | (* Configuration management *) | 
| 
d80502f0d701
1. Function package accepts a parameter (default "some_term"), which specifies the functions
 krauss parents: 
20523diff
changeset | 158 | datatype fundef_opt | 
| 
d80502f0d701
1. Function package accepts a parameter (default "some_term"), which specifies the functions
 krauss parents: 
20523diff
changeset | 159 | = Sequential | 
| 
d80502f0d701
1. Function package accepts a parameter (default "some_term"), which specifies the functions
 krauss parents: 
20523diff
changeset | 160 | | Default of string | 
| 
d80502f0d701
1. Function package accepts a parameter (default "some_term"), which specifies the functions
 krauss parents: 
20523diff
changeset | 161 | | Preprocessor of string | 
| 21051 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
20874diff
changeset | 162 | | Target of xstring | 
| 21319 
cf814e36f788
replaced "auto_term" by the simpler method "relation", which does not try
 krauss parents: 
21255diff
changeset | 163 | | DomIntros | 
| 22166 | 164 | | Tailrec | 
| 20654 
d80502f0d701
1. Function package accepts a parameter (default "some_term"), which specifies the functions
 krauss parents: 
20523diff
changeset | 165 | |
| 
d80502f0d701
1. Function package accepts a parameter (default "some_term"), which specifies the functions
 krauss parents: 
20523diff
changeset | 166 | datatype fundef_config | 
| 
d80502f0d701
1. Function package accepts a parameter (default "some_term"), which specifies the functions
 krauss parents: 
20523diff
changeset | 167 | = FundefConfig of | 
| 
d80502f0d701
1. Function package accepts a parameter (default "some_term"), which specifies the functions
 krauss parents: 
20523diff
changeset | 168 |    {
 | 
| 
d80502f0d701
1. Function package accepts a parameter (default "some_term"), which specifies the functions
 krauss parents: 
20523diff
changeset | 169 | sequential: bool, | 
| 
d80502f0d701
1. Function package accepts a parameter (default "some_term"), which specifies the functions
 krauss parents: 
20523diff
changeset | 170 | default: string, | 
| 21051 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
20874diff
changeset | 171 | preprocessor: string option, | 
| 21319 
cf814e36f788
replaced "auto_term" by the simpler method "relation", which does not try
 krauss parents: 
21255diff
changeset | 172 | target: xstring option, | 
| 22166 | 173 | domintros: bool, | 
| 174 | tailrec: bool | |
| 20654 
d80502f0d701
1. Function package accepts a parameter (default "some_term"), which specifies the functions
 krauss parents: 
20523diff
changeset | 175 | } | 
| 
d80502f0d701
1. Function package accepts a parameter (default "some_term"), which specifies the functions
 krauss parents: 
20523diff
changeset | 176 | |
| 
d80502f0d701
1. Function package accepts a parameter (default "some_term"), which specifies the functions
 krauss parents: 
20523diff
changeset | 177 | |
| 22166 | 178 | val default_config = FundefConfig { sequential=false, default="%x. arbitrary", preprocessor=NONE,
 | 
| 179 | target=NONE, domintros=false, tailrec=false } | |
| 180 | ||
| 181 | val fun_config = FundefConfig { sequential=true, default="%x. arbitrary", preprocessor=NONE, 
 | |
| 182 | target=NONE, domintros=false, tailrec=false } | |
| 20654 
d80502f0d701
1. Function package accepts a parameter (default "some_term"), which specifies the functions
 krauss parents: 
20523diff
changeset | 183 | |
| 22166 | 184 | fun apply_opt Sequential (FundefConfig {sequential, default, preprocessor, target, domintros,tailrec}) = 
 | 
| 185 |     FundefConfig {sequential=true, default=default, preprocessor=preprocessor, target=target, domintros=domintros, tailrec=tailrec }
 | |
| 186 |   | apply_opt (Default d) (FundefConfig {sequential, default, preprocessor, target, domintros,tailrec}) = 
 | |
| 187 |     FundefConfig {sequential=sequential, default=d, preprocessor=preprocessor, target=target, domintros=domintros, tailrec=tailrec }
 | |
| 188 |   | apply_opt (Preprocessor p) (FundefConfig {sequential, default, preprocessor, target, domintros,tailrec}) = 
 | |
| 189 |     FundefConfig {sequential=sequential, default=default, preprocessor=SOME p, target=target, domintros=domintros, tailrec=tailrec }
 | |
| 190 |   | apply_opt (Target t) (FundefConfig {sequential, default, preprocessor, target, domintros,tailrec }) =
 | |
| 191 |     FundefConfig {sequential=sequential, default=default, preprocessor=preprocessor, target=SOME t, domintros=domintros, tailrec=tailrec }
 | |
| 192 |   | apply_opt DomIntros (FundefConfig {sequential, default, preprocessor, target, domintros,tailrec }) =
 | |
| 193 |     FundefConfig {sequential=sequential, default=default, preprocessor=preprocessor, target=target, domintros=true,tailrec=tailrec }
 | |
| 194 |   | apply_opt Tailrec (FundefConfig {sequential, default, preprocessor, target, domintros,tailrec }) =
 | |
| 195 |     FundefConfig {sequential=sequential, default=default, preprocessor=preprocessor, target=target, domintros=domintros,tailrec=true } 
 | |
| 20654 
d80502f0d701
1. Function package accepts a parameter (default "some_term"), which specifies the functions
 krauss parents: 
20523diff
changeset | 196 | |
| 22498 
62cdd4b3e96b
made function syntax strict, requiring | to separate equations; cleanup
 krauss parents: 
22279diff
changeset | 197 | fun target_of (FundefConfig {target, ...}) = target
 | 
| 21051 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
20874diff
changeset | 198 | |
| 22498 
62cdd4b3e96b
made function syntax strict, requiring | to separate equations; cleanup
 krauss parents: 
22279diff
changeset | 199 | local | 
| 
62cdd4b3e96b
made function syntax strict, requiring | to separate equations; cleanup
 krauss parents: 
22279diff
changeset | 200 | structure P = OuterParse and K = OuterKeyword | 
| 20654 
d80502f0d701
1. Function package accepts a parameter (default "some_term"), which specifies the functions
 krauss parents: 
20523diff
changeset | 201 | |
| 22498 
62cdd4b3e96b
made function syntax strict, requiring | to separate equations; cleanup
 krauss parents: 
22279diff
changeset | 202 |   val opt_sequential = Scan.optional ((P.$$$ "(" |-- P.$$$ "sequential" --| P.$$$ ")") >> K true) false
 | 
| 
62cdd4b3e96b
made function syntax strict, requiring | to separate equations; cleanup
 krauss parents: 
22279diff
changeset | 203 | |
| 
62cdd4b3e96b
made function syntax strict, requiring | to separate equations; cleanup
 krauss parents: 
22279diff
changeset | 204 | val option_parser = (P.$$$ "sequential" >> K Sequential) | 
| 
62cdd4b3e96b
made function syntax strict, requiring | to separate equations; cleanup
 krauss parents: 
22279diff
changeset | 205 | || ((P.reserved "default" |-- P.term) >> Default) | 
| 
62cdd4b3e96b
made function syntax strict, requiring | to separate equations; cleanup
 krauss parents: 
22279diff
changeset | 206 | || (P.reserved "domintros" >> K DomIntros) | 
| 
62cdd4b3e96b
made function syntax strict, requiring | to separate equations; cleanup
 krauss parents: 
22279diff
changeset | 207 | || (P.reserved "tailrec" >> K Tailrec) | 
| 
62cdd4b3e96b
made function syntax strict, requiring | to separate equations; cleanup
 krauss parents: 
22279diff
changeset | 208 | || ((P.$$$ "in" |-- P.xname) >> Target) | 
| 20654 
d80502f0d701
1. Function package accepts a parameter (default "some_term"), which specifies the functions
 krauss parents: 
20523diff
changeset | 209 | |
| 22498 
62cdd4b3e96b
made function syntax strict, requiring | to separate equations; cleanup
 krauss parents: 
22279diff
changeset | 210 |   fun config_parser def = (Scan.optional (P.$$$ "(" |-- P.!!! (P.list1 (P.group "option" option_parser)) --| P.$$$ ")") [])
 | 
| 21051 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
20874diff
changeset | 211 | >> (fn opts => fold apply_opt opts def) | 
| 22166 | 212 | |
| 22498 
62cdd4b3e96b
made function syntax strict, requiring | to separate equations; cleanup
 krauss parents: 
22279diff
changeset | 213 | fun pipe_list1 s = P.enum1 "|" s | 
| 
62cdd4b3e96b
made function syntax strict, requiring | to separate equations; cleanup
 krauss parents: 
22279diff
changeset | 214 | |
| 
62cdd4b3e96b
made function syntax strict, requiring | to separate equations; cleanup
 krauss parents: 
22279diff
changeset | 215 |   val otherwise = P.$$$ "(" |-- P.$$$ "otherwise" --| P.$$$ ")"
 | 
| 
62cdd4b3e96b
made function syntax strict, requiring | to separate equations; cleanup
 krauss parents: 
22279diff
changeset | 216 | |
| 
62cdd4b3e96b
made function syntax strict, requiring | to separate equations; cleanup
 krauss parents: 
22279diff
changeset | 217 | fun pipe_error t = P.!!! (Scan.fail_with (K (cat_lines ["Equations must be separated by " ^ quote "|", quote t]))) | 
| 
62cdd4b3e96b
made function syntax strict, requiring | to separate equations; cleanup
 krauss parents: 
22279diff
changeset | 218 | |
| 
62cdd4b3e96b
made function syntax strict, requiring | to separate equations; cleanup
 krauss parents: 
22279diff
changeset | 219 | val statement_ow = SpecParse.opt_thm_name ":" -- (P.prop -- Scan.optional (otherwise >> K true) false) | 
| 
62cdd4b3e96b
made function syntax strict, requiring | to separate equations; cleanup
 krauss parents: 
22279diff
changeset | 220 |                      --| Scan.ahead ((P.term :-- pipe_error) || Scan.succeed ("",""))
 | 
| 
62cdd4b3e96b
made function syntax strict, requiring | to separate equations; cleanup
 krauss parents: 
22279diff
changeset | 221 | |
| 
62cdd4b3e96b
made function syntax strict, requiring | to separate equations; cleanup
 krauss parents: 
22279diff
changeset | 222 | val statements_ow = pipe_list1 statement_ow | 
| 
62cdd4b3e96b
made function syntax strict, requiring | to separate equations; cleanup
 krauss parents: 
22279diff
changeset | 223 | in | 
| 
62cdd4b3e96b
made function syntax strict, requiring | to separate equations; cleanup
 krauss parents: 
22279diff
changeset | 224 | fun fundef_parser default_cfg = config_parser default_cfg -- P.fixes --| P.$$$ "where" -- statements_ow | 
| 20654 
d80502f0d701
1. Function package accepts a parameter (default "some_term"), which specifies the functions
 krauss parents: 
20523diff
changeset | 225 | end | 
| 
d80502f0d701
1. Function package accepts a parameter (default "some_term"), which specifies the functions
 krauss parents: 
20523diff
changeset | 226 | |
| 19564 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 227 | end | 
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 228 | |
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 229 | (* Common Abbreviations *) | 
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 230 | |
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 231 | structure FundefAbbrev = | 
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 232 | struct | 
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 233 | |
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 234 | fun implies_elim_swp x y = implies_elim y x | 
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 235 | |
| 22498 
62cdd4b3e96b
made function syntax strict, requiring | to separate equations; cleanup
 krauss parents: 
22279diff
changeset | 236 | (* HOL abbreviations *) | 
| 19564 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 237 | val boolT = HOLogic.boolT | 
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 238 | val mk_prod = HOLogic.mk_prod | 
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 239 | val mk_eq = HOLogic.mk_eq | 
| 20523 
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
 krauss parents: 
20289diff
changeset | 240 | val eq_const = HOLogic.eq_const | 
| 19564 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 241 | val Trueprop = HOLogic.mk_Trueprop | 
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 242 | val mk_relT = HOLogic.mk_setT o HOLogic.mk_prodT | 
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 243 | |
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 244 | fun free_to_var (Free (v,T)) = Var ((v,0),T) | 
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 245 | | free_to_var _ = raise Match | 
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 246 | |
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 247 | fun var_to_free (Var ((v,_),T)) = Free (v,T) | 
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 248 | | var_to_free _ = raise Match | 
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 249 | |
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 250 | |
| 
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
 krauss parents: diff
changeset | 251 | end |