| author | wenzelm | 
| Tue, 21 Jul 2009 20:37:32 +0200 | |
| changeset 32104 | d1d98a02473e | 
| parent 32060 | b54cb3acbbe4 | 
| child 32105 | da419b0c1c1d | 
| permissions | -rw-r--r-- | 
| 3987 | 1 | (* Title: Pure/pure_thy.ML | 
| 2 | Author: Markus Wenzel, TU Muenchen | |
| 3 | ||
| 26430 | 4 | Theorem storage. Pure theory syntax and logical content. | 
| 3987 | 5 | *) | 
| 6 | ||
| 7 | signature PURE_THY = | |
| 8 | sig | |
| 27198 | 9 | val facts_of: theory -> Facts.T | 
| 26666 | 10 | val intern_fact: theory -> xstring -> string | 
| 26693 | 11 | val defined_fact: theory -> string -> bool | 
| 27198 | 12 | val hide_fact: bool -> string -> theory -> theory | 
| 29420 | 13 | val join_proofs: theory -> exn list | 
| 29433 
c42620170fa6
added cancel_proofs, based on task groups of "entered" proofs;
 wenzelm parents: 
29423diff
changeset | 14 | val cancel_proofs: theory -> unit | 
| 26683 | 15 | val get_fact: Context.generic -> theory -> Facts.ref -> thm list | 
| 26344 
04dacc6809b6
simplified get_thm(s): back to plain name argument;
 wenzelm parents: 
26336diff
changeset | 16 | val get_thms: theory -> xstring -> thm list | 
| 
04dacc6809b6
simplified get_thm(s): back to plain name argument;
 wenzelm parents: 
26336diff
changeset | 17 | val get_thm: theory -> xstring -> thm | 
| 16336 | 18 | val all_thms_of: theory -> (string * thm) list | 
| 21580 | 19 |   val map_facts: ('a -> 'b) -> ('c * ('a list * 'd) list) list -> ('c * ('b list * 'd) list) list
 | 
| 21567 | 20 |   val burrow_fact: ('a list -> 'b list) -> ('a list * 'c) list -> ('b list * 'c) list
 | 
| 21580 | 21 |   val burrow_facts: ('a list -> 'b list) ->
 | 
| 22 |     ('c * ('a list * 'd) list) list -> ('c * ('b list * 'd) list) list
 | |
| 23 | val name_multi: string -> 'a list -> (string * 'a) list | |
| 28076 | 24 | val name_thm: bool -> bool -> Position.T -> string -> thm -> thm | 
| 25 | val name_thms: bool -> bool -> Position.T -> string -> thm list -> thm list | |
| 26 | val name_thmss: bool -> Position.T -> string -> (thm list * 'a) list -> (thm list * 'a) list | |
| 29579 | 27 | val store_thms: binding * thm list -> theory -> thm list * theory | 
| 28 | val store_thm: binding * thm -> theory -> thm * theory | |
| 29 | val store_thm_open: binding * thm -> theory -> thm * theory | |
| 30 | val add_thms: ((binding * thm) * attribute list) list -> theory -> thm list * theory | |
| 31 | val add_thm: (binding * thm) * attribute list -> theory -> thm * theory | |
| 32 | val add_thmss: ((binding * thm list) * attribute list) list -> theory -> thm list list * theory | |
| 33 | val add_thms_dynamic: binding * (Context.generic -> thm list) -> theory -> theory | |
| 30853 | 34 | val note_thmss: string -> (Thm.binding * (thm list * attribute list) list) list | 
| 35 | -> theory -> (string * thm list) list * theory | |
| 36 | val note_thmss_grouped: string -> string -> (Thm.binding * (thm list * attribute list) list) list | |
| 37 | -> theory -> (string * thm list) list * theory | |
| 29579 | 38 | val add_axioms: ((binding * term) * attribute list) list -> theory -> thm list * theory | 
| 30337 
eb189f7e43a1
Theory.add_axioms/add_defs: replaced old bstring by binding;
 wenzelm parents: 
30242diff
changeset | 39 | val add_axioms_cmd: ((binding * string) * attribute list) list -> theory -> thm list * theory | 
| 29579 | 40 | val add_defs: bool -> ((binding * term) * attribute list) list -> | 
| 18377 | 41 | theory -> thm list * theory | 
| 29579 | 42 | val add_defs_unchecked: bool -> ((binding * term) * attribute list) list -> | 
| 43 | theory -> thm list * theory | |
| 30337 
eb189f7e43a1
Theory.add_axioms/add_defs: replaced old bstring by binding;
 wenzelm parents: 
30242diff
changeset | 44 | val add_defs_cmd: bool -> ((binding * string) * attribute list) list -> | 
| 18377 | 45 | theory -> thm list * theory | 
| 30337 
eb189f7e43a1
Theory.add_axioms/add_defs: replaced old bstring by binding;
 wenzelm parents: 
30242diff
changeset | 46 | val add_defs_unchecked_cmd: bool -> ((binding * string) * attribute list) list -> | 
| 19629 | 47 | theory -> thm list * theory | 
| 26959 
f8f2df3e4d83
theory Pure  provides regular application syntax by default;
 wenzelm parents: 
26693diff
changeset | 48 | val old_appl_syntax: theory -> bool | 
| 
f8f2df3e4d83
theory Pure  provides regular application syntax by default;
 wenzelm parents: 
26693diff
changeset | 49 | val old_appl_syntax_setup: theory -> theory | 
| 3987 | 50 | end; | 
| 51 | ||
| 52 | structure PureThy: PURE_THY = | |
| 53 | struct | |
| 54 | ||
| 55 | ||
| 27198 | 56 | (*** stored facts ***) | 
| 3987 | 57 | |
| 27198 | 58 | (** theory data **) | 
| 26282 
305d5ca4fa9d
replaced obsolete FactIndex.T by Facts.T (cumulative version, assumes that facts are only added to unfinished theories);
 wenzelm parents: 
26050diff
changeset | 59 | |
| 27198 | 60 | structure FactsData = TheoryDataFun | 
| 24713 | 61 | ( | 
| 32060 
b54cb3acbbe4
cancel_proofs: some attempts at reworking group management (based on body promises only);
 wenzelm parents: 
30853diff
changeset | 62 | type T = Facts.T * (unit lazy list * Task_Queue.group Inttab.table); | 
| 
b54cb3acbbe4
cancel_proofs: some attempts at reworking group management (based on body promises only);
 wenzelm parents: 
30853diff
changeset | 63 | val empty = (Facts.empty, ([], Inttab.empty)); | 
| 26488 
b497e3187ec7
eliminated destructive/critical theorem database;
 wenzelm parents: 
26471diff
changeset | 64 | val copy = I; | 
| 32060 
b54cb3acbbe4
cancel_proofs: some attempts at reworking group management (based on body promises only);
 wenzelm parents: 
30853diff
changeset | 65 | fun extend (facts, _) = (facts, ([], Inttab.empty)); | 
| 
b54cb3acbbe4
cancel_proofs: some attempts at reworking group management (based on body promises only);
 wenzelm parents: 
30853diff
changeset | 66 | fun merge _ ((facts1, _), (facts2, _)) = (Facts.merge (facts1, facts2), ([], Inttab.empty)); | 
| 24713 | 67 | ); | 
| 3987 | 68 | |
| 28841 
5556c7976837
added force_proofs (based on thms ever passed through enter_thms);
 wenzelm parents: 
28674diff
changeset | 69 | |
| 
5556c7976837
added force_proofs (based on thms ever passed through enter_thms);
 wenzelm parents: 
28674diff
changeset | 70 | (* facts *) | 
| 
5556c7976837
added force_proofs (based on thms ever passed through enter_thms);
 wenzelm parents: 
28674diff
changeset | 71 | |
| 
5556c7976837
added force_proofs (based on thms ever passed through enter_thms);
 wenzelm parents: 
28674diff
changeset | 72 | val facts_of = #1 o FactsData.get; | 
| 26666 | 73 | |
| 74 | val intern_fact = Facts.intern o facts_of; | |
| 26693 | 75 | val defined_fact = Facts.defined o facts_of; | 
| 16023 
66561f6814bd
added string_of_thmref, selections, fact_index_of, valid_thms;
 wenzelm parents: 
15975diff
changeset | 76 | |
| 28841 
5556c7976837
added force_proofs (based on thms ever passed through enter_thms);
 wenzelm parents: 
28674diff
changeset | 77 | fun hide_fact fully name = FactsData.map (apfst (Facts.hide fully name)); | 
| 
5556c7976837
added force_proofs (based on thms ever passed through enter_thms);
 wenzelm parents: 
28674diff
changeset | 78 | |
| 
5556c7976837
added force_proofs (based on thms ever passed through enter_thms);
 wenzelm parents: 
28674diff
changeset | 79 | |
| 
5556c7976837
added force_proofs (based on thms ever passed through enter_thms);
 wenzelm parents: 
28674diff
changeset | 80 | (* proofs *) | 
| 
5556c7976837
added force_proofs (based on thms ever passed through enter_thms);
 wenzelm parents: 
28674diff
changeset | 81 | |
| 29002 | 82 | fun lazy_proof thm = Lazy.lazy (fn () => Thm.join_proof thm); | 
| 28977 | 83 | |
| 29420 | 84 | fun join_proofs thy = | 
| 29433 
c42620170fa6
added cancel_proofs, based on task groups of "entered" proofs;
 wenzelm parents: 
29423diff
changeset | 85 | map_filter (Exn.get_exn o Lazy.force_result) (rev (#1 (#2 (FactsData.get thy)))); | 
| 
c42620170fa6
added cancel_proofs, based on task groups of "entered" proofs;
 wenzelm parents: 
29423diff
changeset | 86 | |
| 32060 
b54cb3acbbe4
cancel_proofs: some attempts at reworking group management (based on body promises only);
 wenzelm parents: 
30853diff
changeset | 87 | fun cancel_proofs thy = | 
| 
b54cb3acbbe4
cancel_proofs: some attempts at reworking group management (based on body promises only);
 wenzelm parents: 
30853diff
changeset | 88 | Inttab.fold (fn (_, group) => fn () => Future.cancel_group group) | 
| 
b54cb3acbbe4
cancel_proofs: some attempts at reworking group management (based on body promises only);
 wenzelm parents: 
30853diff
changeset | 89 | (#2 (#2 (FactsData.get thy))) (); | 
| 27198 | 90 | |
| 6367 | 91 | |
| 3987 | 92 | |
| 4022 
0770a19c48d3
added ignored_consts, thms_containing, add_store_axioms(_i),
 wenzelm parents: 
4013diff
changeset | 93 | (** retrieve theorems **) | 
| 3987 | 94 | |
| 27198 | 95 | fun get_fact context thy xthmref = | 
| 26683 | 96 | let | 
| 97 | val xname = Facts.name_of_ref xthmref; | |
| 98 | val pos = Facts.pos_of_ref xthmref; | |
| 27198 | 99 | |
| 100 | val name = intern_fact thy xname; | |
| 101 | val res = Facts.lookup context (facts_of thy) name; | |
| 102 | val _ = Theory.check_thy thy; | |
| 26683 | 103 | in | 
| 27198 | 104 | (case res of | 
| 105 |       NONE => error ("Unknown fact " ^ quote name ^ Position.str_of pos)
 | |
| 27739 | 106 | | SOME (static, ths) => | 
| 107 | (Position.report ((if static then Markup.fact else Markup.dynamic_fact) name) pos; | |
| 108 | Facts.select xthmref (map (Thm.transfer thy) ths))) | |
| 26683 | 109 | end; | 
| 26344 
04dacc6809b6
simplified get_thm(s): back to plain name argument;
 wenzelm parents: 
26336diff
changeset | 110 | |
| 26683 | 111 | fun get_thms thy = get_fact (Context.Theory thy) thy o Facts.named; | 
| 26344 
04dacc6809b6
simplified get_thm(s): back to plain name argument;
 wenzelm parents: 
26336diff
changeset | 112 | fun get_thm thy name = Facts.the_single name (get_thms thy name); | 
| 4783 | 113 | |
| 27198 | 114 | fun all_thms_of thy = | 
| 27865 
27a8ad9612a3
moved basic thm operations from structure PureThy to Thm (cf. more_thm.ML);
 wenzelm parents: 
27739diff
changeset | 115 | Facts.fold_static (fn (_, ths) => append (map (`(Thm.get_name_hint)) ths)) (facts_of thy) []; | 
| 16336 | 116 | |
| 4022 
0770a19c48d3
added ignored_consts, thms_containing, add_store_axioms(_i),
 wenzelm parents: 
4013diff
changeset | 117 | |
| 
0770a19c48d3
added ignored_consts, thms_containing, add_store_axioms(_i),
 wenzelm parents: 
4013diff
changeset | 118 | |
| 26488 
b497e3187ec7
eliminated destructive/critical theorem database;
 wenzelm parents: 
26471diff
changeset | 119 | (** store theorems **) | 
| 3987 | 120 | |
| 21580 | 121 | (* fact specifications *) | 
| 122 | ||
| 123 | fun map_facts f = map (apsnd (map (apfst (map f)))); | |
| 124 | fun burrow_fact f = split_list #>> burrow f #> op ~~; | |
| 125 | fun burrow_facts f = split_list ##> burrow (burrow_fact f) #> op ~~; | |
| 126 | ||
| 127 | ||
| 4853 | 128 | (* naming *) | 
| 129 | ||
| 18801 | 130 | fun name_multi name [x] = [(name, x)] | 
| 26457 | 131 | | name_multi "" xs = map (pair "") xs | 
| 132 | | name_multi name xs = map_index (fn (i, x) => (name ^ "_" ^ string_of_int (i + 1), x)) xs; | |
| 12235 
5fa04fc9b254
Further restructuring of theorem naming functions.
 berghofe parents: 
12138diff
changeset | 133 | |
| 28076 | 134 | fun name_thm pre official pos name thm = thm | 
| 21646 
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
 wenzelm parents: 
21606diff
changeset | 135 | |> (if Thm.get_name thm <> "" andalso pre orelse not official then I else Thm.put_name name) | 
| 27865 
27a8ad9612a3
moved basic thm operations from structure PureThy to Thm (cf. more_thm.ML);
 wenzelm parents: 
27739diff
changeset | 136 | |> (if Thm.has_name_hint thm andalso pre orelse name = "" then I else Thm.put_name_hint name) | 
| 28076 | 137 | |> Thm.default_position pos | 
| 27865 
27a8ad9612a3
moved basic thm operations from structure PureThy to Thm (cf. more_thm.ML);
 wenzelm parents: 
27739diff
changeset | 138 | |> Thm.default_position (Position.thread_data ()); | 
| 12872 
0855c3ab2047
Theorems are only "pre-named" if the do not already have names.
 berghofe parents: 
12711diff
changeset | 139 | |
| 28076 | 140 | fun name_thms pre official pos name xs = | 
| 141 | map (uncurry (name_thm pre official pos)) (name_multi name xs); | |
| 12235 
5fa04fc9b254
Further restructuring of theorem naming functions.
 berghofe parents: 
12138diff
changeset | 142 | |
| 28076 | 143 | fun name_thmss official pos name fact = | 
| 144 | burrow_fact (name_thms true official pos name) fact; | |
| 4853 | 145 | |
| 146 | ||
| 11998 | 147 | (* enter_thms *) | 
| 4853 | 148 | |
| 32060 
b54cb3acbbe4
cancel_proofs: some attempts at reworking group management (based on body promises only);
 wenzelm parents: 
30853diff
changeset | 149 | val pending_groups = | 
| 
b54cb3acbbe4
cancel_proofs: some attempts at reworking group management (based on body promises only);
 wenzelm parents: 
30853diff
changeset | 150 | Thm.promises_of #> fold (fn (_, future) => | 
| 
b54cb3acbbe4
cancel_proofs: some attempts at reworking group management (based on body promises only);
 wenzelm parents: 
30853diff
changeset | 151 | if Future.is_finished future then I | 
| 
b54cb3acbbe4
cancel_proofs: some attempts at reworking group management (based on body promises only);
 wenzelm parents: 
30853diff
changeset | 152 | else Inttab.update (`Task_Queue.group_id (Future.group_of future))); | 
| 
b54cb3acbbe4
cancel_proofs: some attempts at reworking group management (based on body promises only);
 wenzelm parents: 
30853diff
changeset | 153 | |
| 28841 
5556c7976837
added force_proofs (based on thms ever passed through enter_thms);
 wenzelm parents: 
28674diff
changeset | 154 | fun enter_proofs (thy, thms) = | 
| 29433 
c42620170fa6
added cancel_proofs, based on task groups of "entered" proofs;
 wenzelm parents: 
29423diff
changeset | 155 | (FactsData.map (apsnd (fn (proofs, groups) => | 
| 32060 
b54cb3acbbe4
cancel_proofs: some attempts at reworking group management (based on body promises only);
 wenzelm parents: 
30853diff
changeset | 156 | (fold (cons o lazy_proof) thms proofs, fold pending_groups thms groups))) thy, thms); | 
| 28841 
5556c7976837
added force_proofs (based on thms ever passed through enter_thms);
 wenzelm parents: 
28674diff
changeset | 157 | |
| 28861 | 158 | fun enter_thms pre_name post_name app_att (b, thms) thy = | 
| 28965 | 159 | if Binding.is_empty b | 
| 28861 | 160 | then swap (enter_proofs (app_att (thy, thms))) | 
| 30211 | 161 | else | 
| 162 | let | |
| 163 | val naming = Sign.naming_of thy; | |
| 164 | val name = NameSpace.full_name naming b; | |
| 165 | val (thy', thms') = | |
| 166 | enter_proofs (apsnd (post_name name) (app_att (thy, pre_name name thms))); | |
| 167 | val thms'' = map (Thm.transfer thy') thms'; | |
| 168 | val thy'' = thy' |> (FactsData.map o apfst) (Facts.add_global naming (b, thms'') #> snd); | |
| 169 | in (thms'', thy'') end; | |
| 26488 
b497e3187ec7
eliminated destructive/critical theorem database;
 wenzelm parents: 
26471diff
changeset | 170 | |
| 
b497e3187ec7
eliminated destructive/critical theorem database;
 wenzelm parents: 
26471diff
changeset | 171 | |
| 
b497e3187ec7
eliminated destructive/critical theorem database;
 wenzelm parents: 
26471diff
changeset | 172 | (* store_thm(s) *) | 
| 
b497e3187ec7
eliminated destructive/critical theorem database;
 wenzelm parents: 
26471diff
changeset | 173 | |
| 29579 | 174 | fun store_thms (b, thms) = enter_thms (name_thms true true Position.none) | 
| 175 | (name_thms false true Position.none) I (b, thms); | |
| 28076 | 176 | |
| 29579 | 177 | fun store_thm (b, th) = store_thms (b, [th]) #>> the_single; | 
| 26488 
b497e3187ec7
eliminated destructive/critical theorem database;
 wenzelm parents: 
26471diff
changeset | 178 | |
| 29579 | 179 | fun store_thm_open (b, th) = | 
| 28076 | 180 | enter_thms (name_thms true false Position.none) (name_thms false false Position.none) I | 
| 29579 | 181 | (b, [th]) #>> the_single; | 
| 3987 | 182 | |
| 16023 
66561f6814bd
added string_of_thmref, selections, fact_index_of, valid_thms;
 wenzelm parents: 
15975diff
changeset | 183 | |
| 6091 | 184 | (* add_thms(s) *) | 
| 4853 | 185 | |
| 29579 | 186 | fun add_thms_atts pre_name ((b, thms), atts) = | 
| 28076 | 187 | enter_thms pre_name (name_thms false true Position.none) | 
| 30190 | 188 | (Library.foldl_map (Thm.theory_attributes atts)) (b, thms); | 
| 4853 | 189 | |
| 18377 | 190 | fun gen_add_thmss pre_name = | 
| 191 | fold_map (add_thms_atts pre_name); | |
| 5907 | 192 | |
| 12235 
5fa04fc9b254
Further restructuring of theorem naming functions.
 berghofe parents: 
12138diff
changeset | 193 | fun gen_add_thms pre_name args = | 
| 18377 | 194 | apfst (map hd) o gen_add_thmss pre_name (map (apfst (apsnd single)) args); | 
| 12235 
5fa04fc9b254
Further restructuring of theorem naming functions.
 berghofe parents: 
12138diff
changeset | 195 | |
| 28076 | 196 | val add_thmss = gen_add_thmss (name_thms true true Position.none); | 
| 197 | val add_thms = gen_add_thms (name_thms true true Position.none); | |
| 27683 | 198 | val add_thm = yield_singleton add_thms; | 
| 5907 | 199 | |
| 200 | ||
| 26488 
b497e3187ec7
eliminated destructive/critical theorem database;
 wenzelm parents: 
26471diff
changeset | 201 | (* add_thms_dynamic *) | 
| 
b497e3187ec7
eliminated destructive/critical theorem database;
 wenzelm parents: 
26471diff
changeset | 202 | |
| 29579 | 203 | fun add_thms_dynamic (b, f) thy = thy | 
| 28864 | 204 | |> (FactsData.map o apfst) | 
| 29579 | 205 | (Facts.add_dynamic (Sign.naming_of thy) (b, f) #> snd); | 
| 26488 
b497e3187ec7
eliminated destructive/critical theorem database;
 wenzelm parents: 
26471diff
changeset | 206 | |
| 
b497e3187ec7
eliminated destructive/critical theorem database;
 wenzelm parents: 
26471diff
changeset | 207 | |
| 27728 | 208 | (* note_thmss *) | 
| 5907 | 209 | |
| 9192 | 210 | local | 
| 12711 | 211 | |
| 28861 | 212 | fun gen_note_thmss tag = fold_map (fn ((b, more_atts), ths_atts) => fn thy => | 
| 12711 | 213 | let | 
| 28941 | 214 | val pos = Binding.pos_of b; | 
| 28965 | 215 | val name = Sign.full_name thy b; | 
| 28076 | 216 | val _ = Position.report (Markup.fact_decl name) pos; | 
| 217 | ||
| 30190 | 218 | fun app (x, (ths, atts)) = Library.foldl_map (Thm.theory_attributes atts) (x, ths); | 
| 18418 
bf448d999b7e
re-arranged tuples (theory * 'a) to ('a * theory) in Pure
 haftmann parents: 
18377diff
changeset | 219 | val (thms, thy') = thy |> enter_thms | 
| 30190 | 220 | (name_thmss true pos) (name_thms false true pos) (apsnd flat o Library.foldl_map app) | 
| 28861 | 221 | (b, map (fn (ths, atts) => (ths, surround tag (atts @ more_atts))) ths_atts); | 
| 28076 | 222 | in ((name, thms), thy') end); | 
| 12711 | 223 | |
| 9192 | 224 | in | 
| 12711 | 225 | |
| 27865 
27a8ad9612a3
moved basic thm operations from structure PureThy to Thm (cf. more_thm.ML);
 wenzelm parents: 
27739diff
changeset | 226 | fun note_thmss k = gen_note_thmss (Thm.kind k); | 
| 
27a8ad9612a3
moved basic thm operations from structure PureThy to Thm (cf. more_thm.ML);
 wenzelm parents: 
27739diff
changeset | 227 | fun note_thmss_grouped k g = gen_note_thmss (Thm.kind k #> Thm.group g); | 
| 12711 | 228 | |
| 21438 | 229 | end; | 
| 230 | ||
| 5280 | 231 | |
| 4022 
0770a19c48d3
added ignored_consts, thms_containing, add_store_axioms(_i),
 wenzelm parents: 
4013diff
changeset | 232 | (* store axioms as theorems *) | 
| 
0770a19c48d3
added ignored_consts, thms_containing, add_store_axioms(_i),
 wenzelm parents: 
4013diff
changeset | 233 | |
| 4853 | 234 | local | 
| 29579 | 235 | fun get_ax thy (b, _) = Thm.axiom thy (Sign.full_name thy b); | 
| 26655 | 236 | fun get_axs thy named_axs = map (Thm.forall_elim_vars 0 o get_ax thy) named_axs; | 
| 30337 
eb189f7e43a1
Theory.add_axioms/add_defs: replaced old bstring by binding;
 wenzelm parents: 
30242diff
changeset | 237 | fun add_axm add = fold_map (fn ((b, ax), atts) => fn thy => | 
| 4853 | 238 | let | 
| 29579 | 239 | val named_ax = [(b, ax)]; | 
| 7753 | 240 | val thy' = add named_ax thy; | 
| 30337 
eb189f7e43a1
Theory.add_axioms/add_defs: replaced old bstring by binding;
 wenzelm parents: 
30242diff
changeset | 241 | val thm = hd (get_axs thy' named_ax); | 
| 
eb189f7e43a1
Theory.add_axioms/add_defs: replaced old bstring by binding;
 wenzelm parents: 
30242diff
changeset | 242 | in apfst hd (gen_add_thms (K I) [((b, thm), atts)] thy') end); | 
| 4853 | 243 | in | 
| 30337 
eb189f7e43a1
Theory.add_axioms/add_defs: replaced old bstring by binding;
 wenzelm parents: 
30242diff
changeset | 244 | val add_defs = add_axm o Theory.add_defs_i false; | 
| 
eb189f7e43a1
Theory.add_axioms/add_defs: replaced old bstring by binding;
 wenzelm parents: 
30242diff
changeset | 245 | val add_defs_unchecked = add_axm o Theory.add_defs_i true; | 
| 
eb189f7e43a1
Theory.add_axioms/add_defs: replaced old bstring by binding;
 wenzelm parents: 
30242diff
changeset | 246 | val add_axioms = add_axm Theory.add_axioms_i; | 
| 
eb189f7e43a1
Theory.add_axioms/add_defs: replaced old bstring by binding;
 wenzelm parents: 
30242diff
changeset | 247 | val add_defs_cmd = add_axm o Theory.add_defs false; | 
| 
eb189f7e43a1
Theory.add_axioms/add_defs: replaced old bstring by binding;
 wenzelm parents: 
30242diff
changeset | 248 | val add_defs_unchecked_cmd = add_axm o Theory.add_defs true; | 
| 
eb189f7e43a1
Theory.add_axioms/add_defs: replaced old bstring by binding;
 wenzelm parents: 
30242diff
changeset | 249 | val add_axioms_cmd = add_axm Theory.add_axioms; | 
| 4853 | 250 | end; | 
| 4022 
0770a19c48d3
added ignored_consts, thms_containing, add_store_axioms(_i),
 wenzelm parents: 
4013diff
changeset | 251 | |
| 
0770a19c48d3
added ignored_consts, thms_containing, add_store_axioms(_i),
 wenzelm parents: 
4013diff
changeset | 252 | |
| 3987 | 253 | |
| 26430 | 254 | (*** Pure theory syntax and logical content ***) | 
| 3987 | 255 | |
| 24243 | 256 | val typ = SimpleSyntax.read_typ; | 
| 257 | val term = SimpleSyntax.read_term; | |
| 258 | val prop = SimpleSyntax.read_prop; | |
| 259 | ||
| 28856 
5e009a80fe6d
Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
 wenzelm parents: 
28841diff
changeset | 260 | val typeT = Syntax.typeT; | 
| 
5e009a80fe6d
Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
 wenzelm parents: 
28841diff
changeset | 261 | val spropT = Syntax.spropT; | 
| 
5e009a80fe6d
Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
 wenzelm parents: 
28841diff
changeset | 262 | |
| 26959 
f8f2df3e4d83
theory Pure  provides regular application syntax by default;
 wenzelm parents: 
26693diff
changeset | 263 | |
| 
f8f2df3e4d83
theory Pure  provides regular application syntax by default;
 wenzelm parents: 
26693diff
changeset | 264 | (* application syntax variants *) | 
| 
f8f2df3e4d83
theory Pure  provides regular application syntax by default;
 wenzelm parents: 
26693diff
changeset | 265 | |
| 
f8f2df3e4d83
theory Pure  provides regular application syntax by default;
 wenzelm parents: 
26693diff
changeset | 266 | val appl_syntax = | 
| 
f8f2df3e4d83
theory Pure  provides regular application syntax by default;
 wenzelm parents: 
26693diff
changeset | 267 |  [("_appl", typ "('b => 'a) => args => logic", Mixfix ("(1_/(1'(_')))", [1000, 0], 1000)),
 | 
| 
f8f2df3e4d83
theory Pure  provides regular application syntax by default;
 wenzelm parents: 
26693diff
changeset | 268 |   ("_appl", typ "('b => 'a) => args => aprop", Mixfix ("(1_/(1'(_')))", [1000, 0], 1000))];
 | 
| 
f8f2df3e4d83
theory Pure  provides regular application syntax by default;
 wenzelm parents: 
26693diff
changeset | 269 | |
| 
f8f2df3e4d83
theory Pure  provides regular application syntax by default;
 wenzelm parents: 
26693diff
changeset | 270 | val applC_syntax = | 
| 
f8f2df3e4d83
theory Pure  provides regular application syntax by default;
 wenzelm parents: 
26693diff
changeset | 271 |  [("",       typ "'a => cargs",                  Delimfix "_"),
 | 
| 
f8f2df3e4d83
theory Pure  provides regular application syntax by default;
 wenzelm parents: 
26693diff
changeset | 272 |   ("_cargs", typ "'a => cargs => cargs",         Mixfix ("_/ _", [1000, 1000], 1000)),
 | 
| 
f8f2df3e4d83
theory Pure  provides regular application syntax by default;
 wenzelm parents: 
26693diff
changeset | 273 |   ("_applC", typ "('b => 'a) => cargs => logic", Mixfix ("(1_/ _)", [1000, 1000], 999)),
 | 
| 
f8f2df3e4d83
theory Pure  provides regular application syntax by default;
 wenzelm parents: 
26693diff
changeset | 274 |   ("_applC", typ "('b => 'a) => cargs => aprop", Mixfix ("(1_/ _)", [1000, 1000], 999))];
 | 
| 
f8f2df3e4d83
theory Pure  provides regular application syntax by default;
 wenzelm parents: 
26693diff
changeset | 275 | |
| 
f8f2df3e4d83
theory Pure  provides regular application syntax by default;
 wenzelm parents: 
26693diff
changeset | 276 | structure OldApplSyntax = TheoryDataFun | 
| 
f8f2df3e4d83
theory Pure  provides regular application syntax by default;
 wenzelm parents: 
26693diff
changeset | 277 | ( | 
| 
f8f2df3e4d83
theory Pure  provides regular application syntax by default;
 wenzelm parents: 
26693diff
changeset | 278 | type T = bool; | 
| 
f8f2df3e4d83
theory Pure  provides regular application syntax by default;
 wenzelm parents: 
26693diff
changeset | 279 | val empty = false; | 
| 
f8f2df3e4d83
theory Pure  provides regular application syntax by default;
 wenzelm parents: 
26693diff
changeset | 280 | val copy = I; | 
| 
f8f2df3e4d83
theory Pure  provides regular application syntax by default;
 wenzelm parents: 
26693diff
changeset | 281 | val extend = I; | 
| 
f8f2df3e4d83
theory Pure  provides regular application syntax by default;
 wenzelm parents: 
26693diff
changeset | 282 | fun merge _ (b1, b2) : T = | 
| 
f8f2df3e4d83
theory Pure  provides regular application syntax by default;
 wenzelm parents: 
26693diff
changeset | 283 | if b1 = b2 then b1 | 
| 
f8f2df3e4d83
theory Pure  provides regular application syntax by default;
 wenzelm parents: 
26693diff
changeset | 284 | else error "Cannot merge theories with different application syntax"; | 
| 
f8f2df3e4d83
theory Pure  provides regular application syntax by default;
 wenzelm parents: 
26693diff
changeset | 285 | ); | 
| 
f8f2df3e4d83
theory Pure  provides regular application syntax by default;
 wenzelm parents: 
26693diff
changeset | 286 | |
| 
f8f2df3e4d83
theory Pure  provides regular application syntax by default;
 wenzelm parents: 
26693diff
changeset | 287 | val old_appl_syntax = OldApplSyntax.get; | 
| 
f8f2df3e4d83
theory Pure  provides regular application syntax by default;
 wenzelm parents: 
26693diff
changeset | 288 | |
| 
f8f2df3e4d83
theory Pure  provides regular application syntax by default;
 wenzelm parents: 
26693diff
changeset | 289 | val old_appl_syntax_setup = | 
| 
f8f2df3e4d83
theory Pure  provides regular application syntax by default;
 wenzelm parents: 
26693diff
changeset | 290 | OldApplSyntax.put true #> | 
| 
f8f2df3e4d83
theory Pure  provides regular application syntax by default;
 wenzelm parents: 
26693diff
changeset | 291 | Sign.del_modesyntax_i Syntax.mode_default applC_syntax #> | 
| 
f8f2df3e4d83
theory Pure  provides regular application syntax by default;
 wenzelm parents: 
26693diff
changeset | 292 | Sign.add_syntax_i appl_syntax; | 
| 
f8f2df3e4d83
theory Pure  provides regular application syntax by default;
 wenzelm parents: 
26693diff
changeset | 293 | |
| 
f8f2df3e4d83
theory Pure  provides regular application syntax by default;
 wenzelm parents: 
26693diff
changeset | 294 | |
| 
f8f2df3e4d83
theory Pure  provides regular application syntax by default;
 wenzelm parents: 
26693diff
changeset | 295 | (* main content *) | 
| 
f8f2df3e4d83
theory Pure  provides regular application syntax by default;
 wenzelm parents: 
26693diff
changeset | 296 | |
| 26463 | 297 | val _ = Context.>> (Context.map_theory | 
| 26959 
f8f2df3e4d83
theory Pure  provides regular application syntax by default;
 wenzelm parents: 
26693diff
changeset | 298 | (OldApplSyntax.init #> | 
| 
f8f2df3e4d83
theory Pure  provides regular application syntax by default;
 wenzelm parents: 
26693diff
changeset | 299 | Sign.add_types | 
| 30344 
10a67c5ddddb
more uniform handling of binding in targets and derived elements;
 wenzelm parents: 
30337diff
changeset | 300 | [(Binding.name "fun", 2, NoSyn), | 
| 
10a67c5ddddb
more uniform handling of binding in targets and derived elements;
 wenzelm parents: 
30337diff
changeset | 301 | (Binding.name "prop", 0, NoSyn), | 
| 
10a67c5ddddb
more uniform handling of binding in targets and derived elements;
 wenzelm parents: 
30337diff
changeset | 302 | (Binding.name "itself", 1, NoSyn), | 
| 
10a67c5ddddb
more uniform handling of binding in targets and derived elements;
 wenzelm parents: 
30337diff
changeset | 303 | (Binding.name "dummy", 0, NoSyn)] | 
| 
10a67c5ddddb
more uniform handling of binding in targets and derived elements;
 wenzelm parents: 
30337diff
changeset | 304 | #> Sign.add_nonterminals (map Binding.name Syntax.basic_nonterms) | 
| 26430 | 305 | #> Sign.add_syntax_i | 
| 26436 | 306 |    [("_lambda",     typ "pttrns => 'a => logic",       Mixfix ("(3%_./ _)", [0, 3], 3)),
 | 
| 307 |     ("_abs",        typ "'a",                          NoSyn),
 | |
| 308 |     ("",            typ "'a => args",                  Delimfix "_"),
 | |
| 309 |     ("_args",       typ "'a => args => args",          Delimfix "_,/ _"),
 | |
| 310 |     ("",            typ "id => idt",                   Delimfix "_"),
 | |
| 311 |     ("_idtdummy",   typ "idt",                         Delimfix "'_"),
 | |
| 312 |     ("_idtyp",      typ "id => type => idt",           Mixfix ("_::_", [], 0)),
 | |
| 313 |     ("_idtypdummy", typ "type => idt",                 Mixfix ("'_()::_", [], 0)),
 | |
| 314 |     ("",            typ "idt => idt",                  Delimfix "'(_')"),
 | |
| 315 |     ("",            typ "idt => idts",                 Delimfix "_"),
 | |
| 316 |     ("_idts",       typ "idt => idts => idts",         Mixfix ("_/ _", [1, 0], 0)),
 | |
| 317 |     ("",            typ "idt => pttrn",                Delimfix "_"),
 | |
| 318 |     ("",            typ "pttrn => pttrns",             Delimfix "_"),
 | |
| 319 |     ("_pttrns",     typ "pttrn => pttrns => pttrns",   Mixfix ("_/ _", [1, 0], 0)),
 | |
| 28856 
5e009a80fe6d
Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
 wenzelm parents: 
28841diff
changeset | 320 |     ("",            typ "aprop => aprop",              Delimfix "'(_')"),
 | 
| 26436 | 321 |     ("",            typ "id => aprop",                 Delimfix "_"),
 | 
| 322 |     ("",            typ "longid => aprop",             Delimfix "_"),
 | |
| 323 |     ("",            typ "var => aprop",                Delimfix "_"),
 | |
| 324 |     ("_DDDOT",      typ "aprop",                       Delimfix "..."),
 | |
| 325 |     ("_aprop",      typ "aprop => prop",               Delimfix "PROP _"),
 | |
| 326 |     ("_asm",        typ "prop => asms",                Delimfix "_"),
 | |
| 327 |     ("_asms",       typ "prop => asms => asms",        Delimfix "_;/ _"),
 | |
| 328 |     ("_bigimpl",    typ "asms => prop => prop",        Mixfix ("((3[| _ |])/ ==> _)", [0, 1], 1)),
 | |
| 329 |     ("_ofclass",    typ "type => logic => prop",       Delimfix "(1OFCLASS/(1'(_,/ _')))"),
 | |
| 330 |     ("_mk_ofclass", typ "dummy",                       NoSyn),
 | |
| 331 |     ("_TYPE",       typ "type => logic",               Delimfix "(1TYPE/(1'(_')))"),
 | |
| 332 |     ("",            typ "id => logic",                 Delimfix "_"),
 | |
| 333 |     ("",            typ "longid => logic",             Delimfix "_"),
 | |
| 334 |     ("",            typ "var => logic",                Delimfix "_"),
 | |
| 335 |     ("_DDDOT",      typ "logic",                       Delimfix "..."),
 | |
| 336 |     ("_constify",   typ "num => num_const",            Delimfix "_"),
 | |
| 29156 
89f76a58a378
renamed terminal category "float" to "float_token", to avoid name
 wenzelm parents: 
29002diff
changeset | 337 |     ("_constify",   typ "float_token => float_const",  Delimfix "_"),
 | 
| 26436 | 338 |     ("_indexnum",   typ "num_const => index",          Delimfix "\\<^sub>_"),
 | 
| 339 |     ("_index",      typ "logic => index",              Delimfix "(00\\<^bsub>_\\<^esub>)"),
 | |
| 340 |     ("_indexdefault", typ "index",                     Delimfix ""),
 | |
| 341 |     ("_indexvar",   typ "index",                       Delimfix "'\\<index>"),
 | |
| 342 |     ("_struct",     typ "index => logic",              Mixfix ("\\<struct>_", [1000], 1000)),
 | |
| 343 |     ("==>",         typ "prop => prop => prop",        Delimfix "op ==>"),
 | |
| 28622 
1a0b845855ac
added const sort_constraint with syntax SORT_CONSTRAINT -- logically vacous;
 wenzelm parents: 
28076diff
changeset | 344 | (Term.dummy_patternN, typ "aprop", Delimfix "'_"), | 
| 28856 
5e009a80fe6d
Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
 wenzelm parents: 
28841diff
changeset | 345 |     ("_sort_constraint", typ "type => prop",           Delimfix "(1SORT'_CONSTRAINT/(1'(_')))"),
 | 
| 
5e009a80fe6d
Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
 wenzelm parents: 
28841diff
changeset | 346 |     ("Pure.term",   typ "logic => prop",               Delimfix "TERM _"),
 | 
| 
5e009a80fe6d
Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
 wenzelm parents: 
28841diff
changeset | 347 |     ("Pure.conjunction", typ "prop => prop => prop",   InfixrName ("&&&", 2))]
 | 
| 26959 
f8f2df3e4d83
theory Pure  provides regular application syntax by default;
 wenzelm parents: 
26693diff
changeset | 348 | #> Sign.add_syntax_i applC_syntax | 
| 26430 | 349 | #> Sign.add_modesyntax_i (Symbol.xsymbolsN, true) | 
| 24243 | 350 |    [("fun",      typ "type => type => type",   Mixfix ("(_/ \\<Rightarrow> _)", [1, 0], 0)),
 | 
| 351 |     ("_bracket", typ "types => type => type",  Mixfix ("([_]/ \\<Rightarrow> _)", [0, 0], 0)),
 | |
| 352 |     ("_ofsort",  typ "tid => sort => type",    Mixfix ("_\\<Colon>_", [1000, 0], 1000)),
 | |
| 28856 
5e009a80fe6d
Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
 wenzelm parents: 
28841diff
changeset | 353 |     ("_constrain", typ "logic => type => logic", Mixfix ("_\\<Colon>_", [4, 0], 3)),
 | 
| 
5e009a80fe6d
Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
 wenzelm parents: 
28841diff
changeset | 354 |     ("_constrain", [spropT, typeT] ---> spropT, Mixfix ("_\\<Colon>_", [4, 0], 3)),
 | 
| 24243 | 355 |     ("_idtyp",    typ "id => type => idt",     Mixfix ("_\\<Colon>_", [], 0)),
 | 
| 356 |     ("_idtypdummy", typ "type => idt",         Mixfix ("'_()\\<Colon>_", [], 0)),
 | |
| 357 |     ("_type_constraint_", typ "'a",            NoSyn),
 | |
| 358 |     ("_lambda",  typ "pttrns => 'a => logic",  Mixfix ("(3\\<lambda>_./ _)", [0, 3], 3)),
 | |
| 359 |     ("==",       typ "'a => 'a => prop",       InfixrName ("\\<equiv>", 2)),
 | |
| 360 |     ("all_binder", typ "idts => prop => prop", Mixfix ("(3\\<And>_./ _)", [0, 0], 0)),
 | |
| 361 |     ("==>",      typ "prop => prop => prop",   InfixrName ("\\<Longrightarrow>", 1)),
 | |
| 362 |     ("_DDDOT",   typ "aprop",                  Delimfix "\\<dots>"),
 | |
| 363 |     ("_bigimpl", typ "asms => prop => prop",   Mixfix ("((1\\<lbrakk>_\\<rbrakk>)/ \\<Longrightarrow> _)", [0, 1], 1)),
 | |
| 364 |     ("_DDDOT",   typ "logic",                  Delimfix "\\<dots>")]
 | |
| 26430 | 365 |   #> Sign.add_modesyntax_i ("", false)
 | 
| 28856 
5e009a80fe6d
Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
 wenzelm parents: 
28841diff
changeset | 366 |    [("prop", typ "prop => prop", Mixfix ("_", [0], 0))]
 | 
| 26430 | 367 |   #> Sign.add_modesyntax_i ("HTML", false)
 | 
| 24243 | 368 |    [("_lambda", typ "pttrns => 'a => logic", Mixfix ("(3\\<lambda>_./ _)", [0, 3], 3))]
 | 
| 26430 | 369 | #> Sign.add_consts_i | 
| 30344 
10a67c5ddddb
more uniform handling of binding in targets and derived elements;
 wenzelm parents: 
30337diff
changeset | 370 |    [(Binding.name "==", typ "'a => 'a => prop", InfixrName ("==", 2)),
 | 
| 
10a67c5ddddb
more uniform handling of binding in targets and derived elements;
 wenzelm parents: 
30337diff
changeset | 371 |     (Binding.name "==>", typ "prop => prop => prop", Mixfix ("(_/ ==> _)", [2, 1], 1)),
 | 
| 
10a67c5ddddb
more uniform handling of binding in targets and derived elements;
 wenzelm parents: 
30337diff
changeset | 372 |     (Binding.name "all", typ "('a => prop) => prop", Binder ("!!", 0, 0)),
 | 
| 
10a67c5ddddb
more uniform handling of binding in targets and derived elements;
 wenzelm parents: 
30337diff
changeset | 373 | (Binding.name "prop", typ "prop => prop", NoSyn), | 
| 
10a67c5ddddb
more uniform handling of binding in targets and derived elements;
 wenzelm parents: 
30337diff
changeset | 374 | (Binding.name "TYPE", typ "'a itself", NoSyn), | 
| 
10a67c5ddddb
more uniform handling of binding in targets and derived elements;
 wenzelm parents: 
30337diff
changeset | 375 | (Binding.name Term.dummy_patternN, typ "'a", Delimfix "'_")] | 
| 26430 | 376 |   #> Theory.add_deps "==" ("==", typ "'a => 'a => prop") []
 | 
| 377 |   #> Theory.add_deps "==>" ("==>", typ "prop => prop => prop") []
 | |
| 378 |   #> Theory.add_deps "all" ("all", typ "('a => prop) => prop") []
 | |
| 379 |   #> Theory.add_deps "TYPE" ("TYPE", typ "'a itself") []
 | |
| 380 | #> Theory.add_deps Term.dummy_patternN (Term.dummy_patternN, typ "'a") [] | |
| 381 | #> Sign.add_trfuns Syntax.pure_trfuns | |
| 382 | #> Sign.add_trfunsT Syntax.pure_trfunsT | |
| 383 | #> Sign.local_path | |
| 384 | #> Sign.add_consts_i | |
| 30344 
10a67c5ddddb
more uniform handling of binding in targets and derived elements;
 wenzelm parents: 
30337diff
changeset | 385 | [(Binding.name "term", typ "'a => prop", NoSyn), | 
| 
10a67c5ddddb
more uniform handling of binding in targets and derived elements;
 wenzelm parents: 
30337diff
changeset | 386 | (Binding.name "sort_constraint", typ "'a itself => prop", NoSyn), | 
| 
10a67c5ddddb
more uniform handling of binding in targets and derived elements;
 wenzelm parents: 
30337diff
changeset | 387 | (Binding.name "conjunction", typ "prop => prop => prop", NoSyn)] | 
| 27691 
ce171cbd4b93
PureThy: dropped note_thmss_qualified, dropped _i suffix
 haftmann parents: 
27683diff
changeset | 388 | #> (add_defs false o map Thm.no_attributes) | 
| 29579 | 389 | [(Binding.name "prop_def", prop "(CONST prop :: prop => prop) (A::prop) == A::prop"), | 
| 390 | (Binding.name "term_def", prop "(CONST Pure.term :: 'a => prop) (x::'a) == (!!A::prop. A ==> A)"), | |
| 391 | (Binding.name "sort_constraint_def", | |
| 28622 
1a0b845855ac
added const sort_constraint with syntax SORT_CONSTRAINT -- logically vacous;
 wenzelm parents: 
28076diff
changeset | 392 | prop "(CONST Pure.sort_constraint :: 'a itself => prop) (CONST TYPE :: 'a itself) ==\ | 
| 
1a0b845855ac
added const sort_constraint with syntax SORT_CONSTRAINT -- logically vacous;
 wenzelm parents: 
28076diff
changeset | 393 | \ (CONST Pure.term :: 'a itself => prop) (CONST TYPE :: 'a itself)"), | 
| 29579 | 394 | (Binding.name "conjunction_def", prop "(A &&& B) == (!!C::prop. (A ==> B ==> C) ==> C)")] #> snd | 
| 28622 
1a0b845855ac
added const sort_constraint with syntax SORT_CONSTRAINT -- logically vacous;
 wenzelm parents: 
28076diff
changeset | 395 | #> Sign.hide_const false "Pure.term" | 
| 
1a0b845855ac
added const sort_constraint with syntax SORT_CONSTRAINT -- logically vacous;
 wenzelm parents: 
28076diff
changeset | 396 | #> Sign.hide_const false "Pure.sort_constraint" | 
| 26666 | 397 | #> Sign.hide_const false "Pure.conjunction" | 
| 29579 | 398 | #> add_thmss [((Binding.name "nothing", []), [])] #> snd | 
| 30337 
eb189f7e43a1
Theory.add_axioms/add_defs: replaced old bstring by binding;
 wenzelm parents: 
30242diff
changeset | 399 | #> Theory.add_axioms_i (map (apfst Binding.name) Proofterm.equality_axms))); | 
| 3987 | 400 | |
| 401 | end; |