author | wenzelm |
Mon, 22 Oct 2001 18:07:30 +0200 | |
changeset 11896 | 1ff33f896720 |
parent 11890 | 28e42a90bea8 |
child 11932 | c1c4890a1ecb |
permissions | -rw-r--r-- |
5830 | 1 |
(* Title: Pure/Isar/isar_thy.ML |
2 |
ID: $Id$ |
|
3 |
Author: Markus Wenzel, TU Muenchen |
|
8804 | 4 |
License: GPL (GNU GENERAL PUBLIC LICENSE) |
5830 | 5 |
|
6371 | 6 |
Pure/Isar derived theory operations. |
5830 | 7 |
*) |
8 |
||
9 |
signature ISAR_THY = |
|
10 |
sig |
|
7734 | 11 |
val add_header: Comment.text -> Toplevel.transition -> Toplevel.transition |
6552 | 12 |
val add_chapter: Comment.text -> theory -> theory |
13 |
val add_section: Comment.text -> theory -> theory |
|
14 |
val add_subsection: Comment.text -> theory -> theory |
|
15 |
val add_subsubsection: Comment.text -> theory -> theory |
|
7172 | 16 |
val add_text: Comment.text -> theory -> theory |
7862 | 17 |
val add_text_raw: Comment.text -> theory -> theory |
7172 | 18 |
val add_sect: Comment.text -> ProofHistory.T -> ProofHistory.T |
19 |
val add_subsect: Comment.text -> ProofHistory.T -> ProofHistory.T |
|
20 |
val add_subsubsect: Comment.text -> ProofHistory.T -> ProofHistory.T |
|
21 |
val add_txt: Comment.text -> ProofHistory.T -> ProofHistory.T |
|
7862 | 22 |
val add_txt_raw: Comment.text -> ProofHistory.T -> ProofHistory.T |
8724 | 23 |
val global_path: Comment.text -> theory -> theory |
24 |
val local_path: Comment.text -> theory -> theory |
|
25 |
val hide_space: (string * xstring list) * Comment.text -> theory -> theory |
|
26 |
val hide_space_i: (string * string list) * Comment.text -> theory -> theory |
|
6728
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
27 |
val add_classes: (bclass * xclass list) list * Comment.text -> theory -> theory |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
28 |
val add_classes_i: (bclass * class list) list * Comment.text -> theory -> theory |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
29 |
val add_classrel: (xclass * xclass) * Comment.text -> theory -> theory |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
30 |
val add_classrel_i: (class * class) * Comment.text -> theory -> theory |
8897 | 31 |
val add_defsort: string * Comment.text -> theory -> theory |
6728
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
32 |
val add_defsort_i: sort * Comment.text -> theory -> theory |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
33 |
val add_nonterminals: (bstring * Comment.text) list -> theory -> theory |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
34 |
val add_tyabbrs: ((bstring * string list * string * mixfix) * Comment.text) list |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
35 |
-> theory -> theory |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
36 |
val add_tyabbrs_i: ((bstring * string list * typ * mixfix) * Comment.text) list |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
37 |
-> theory -> theory |
8897 | 38 |
val add_arities: ((xstring * string list * string) * Comment.text) list -> theory -> theory |
6728
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
39 |
val add_arities_i: ((string * sort list * sort) * Comment.text) list -> theory -> theory |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
40 |
val add_typedecl: (bstring * string list * mixfix) * Comment.text -> theory -> theory |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
41 |
val add_consts: ((bstring * string * mixfix) * Comment.text) list -> theory -> theory |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
42 |
val add_consts_i: ((bstring * typ * mixfix) * Comment.text) list -> theory -> theory |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
43 |
val add_modesyntax: string * bool -> ((bstring * string * mixfix) * Comment.text) list |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
44 |
-> theory -> theory |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
45 |
val add_modesyntax_i: string * bool -> ((bstring * typ * mixfix) * Comment.text) list |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
46 |
-> theory -> theory |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
47 |
val add_trrules: ((xstring * string) Syntax.trrule * Comment.text) list -> theory -> theory |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
48 |
val add_trrules_i: (Syntax.ast Syntax.trrule * Comment.text) list -> theory -> theory |
8227 | 49 |
val add_judgment: (bstring * string * mixfix) * Comment.text -> theory -> theory |
50 |
val add_judgment_i: (bstring * typ * mixfix) * Comment.text -> theory -> theory |
|
6728
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
51 |
val add_axioms: (((bstring * string) * Args.src list) * Comment.text) list -> theory -> theory |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
52 |
val add_axioms_i: (((bstring * term) * theory attribute list) * Comment.text) list |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
53 |
-> theory -> theory |
9318 | 54 |
val add_defs: bool * (((bstring * string) * Args.src list) * Comment.text) list |
55 |
-> theory -> theory |
|
56 |
val add_defs_i: bool * (((bstring * term) * theory attribute list) * Comment.text) list |
|
6728
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
57 |
-> theory -> theory |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
58 |
val add_constdefs: (((bstring * string * mixfix) * Comment.text) * (string * Comment.text)) list |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
59 |
-> theory -> theory |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
60 |
val add_constdefs_i: (((bstring * typ * mixfix) * Comment.text) * (term * Comment.text)) list |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
61 |
-> theory -> theory |
6371 | 62 |
val apply_theorems: (xstring * Args.src list) list -> theory -> theory * thm list |
63 |
val apply_theorems_i: (thm * theory attribute list) list -> theory -> theory * thm list |
|
9590 | 64 |
val declare_theorems: (xstring * Args.src list) list * Comment.text -> theory -> theory |
65 |
val declare_theorems_i: (thm * theory attribute list) list * Comment.text -> theory -> theory |
|
11742 | 66 |
val have_theorems: string -> |
10464 | 67 |
(((bstring * Args.src list) * (xstring * Args.src list) list) * Comment.text) list |
6371 | 68 |
-> theory -> theory |
11742 | 69 |
val have_theorems_i: string -> |
70 |
(((bstring * theory attribute list) * (thm * theory attribute list) list) |
|
9193
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
71 |
* Comment.text) list -> theory -> theory |
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
72 |
val have_facts: (((string * Args.src list) * (string * Args.src list) list) * Comment.text) list |
5915 | 73 |
-> ProofHistory.T -> ProofHistory.T |
9193
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
74 |
val have_facts_i: (((string * Proof.context attribute list) * |
10464 | 75 |
(thm * Proof.context attribute list) list) * Comment.text) list |
76 |
-> ProofHistory.T -> ProofHistory.T |
|
77 |
val from_facts: ((string * Args.src list) list * Comment.text) list |
|
78 |
-> ProofHistory.T -> ProofHistory.T |
|
9193
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
79 |
val from_facts_i: ((thm * Proof.context attribute list) list * Comment.text) list |
6728
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
80 |
-> ProofHistory.T -> ProofHistory.T |
10464 | 81 |
val with_facts: ((string * Args.src list) list * Comment.text) list |
82 |
-> ProofHistory.T -> ProofHistory.T |
|
9193
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
83 |
val with_facts_i: ((thm * Proof.context attribute list) list * Comment.text) list |
6879 | 84 |
-> ProofHistory.T -> ProofHistory.T |
6728
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
85 |
val chain: Comment.text -> ProofHistory.T -> ProofHistory.T |
7417 | 86 |
val fix: ((string list * string option) * Comment.text) list -> ProofHistory.T -> ProofHistory.T |
7666 | 87 |
val fix_i: ((string list * typ option) * Comment.text) list -> ProofHistory.T -> ProofHistory.T |
8615 | 88 |
val let_bind: ((string list * string) * Comment.text) list -> ProofHistory.T -> ProofHistory.T |
89 |
val let_bind_i: ((term list * term) * Comment.text) list -> ProofHistory.T -> ProofHistory.T |
|
11793
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11764
diff
changeset
|
90 |
val invoke_case: (string * string option list * Args.src list) * Comment.text |
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11764
diff
changeset
|
91 |
-> ProofHistory.T -> ProofHistory.T |
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11764
diff
changeset
|
92 |
val invoke_case_i: (string * string option list * Proof.context attribute list) * Comment.text |
8450 | 93 |
-> ProofHistory.T -> ProofHistory.T |
11742 | 94 |
val theorem: string -> ((bstring * Args.src list) * (string * (string list * string list))) |
6937 | 95 |
* Comment.text -> bool -> theory -> ProofHistory.T |
11742 | 96 |
val theorem_i: string -> ((bstring * theory attribute list) * (term * (term list * term list))) |
6937 | 97 |
* Comment.text -> bool -> theory -> ProofHistory.T |
10464 | 98 |
val assume: (((string * Args.src list) * (string * (string list * string list)) list) |
7271 | 99 |
* Comment.text) list -> ProofHistory.T -> ProofHistory.T |
10464 | 100 |
val assume_i: (((string * Proof.context attribute list) * (term * (term list * term list)) list) |
7271 | 101 |
* Comment.text) list -> ProofHistory.T -> ProofHistory.T |
10464 | 102 |
val presume: (((string * Args.src list) * (string * (string list * string list)) list) |
7271 | 103 |
* Comment.text) list -> ProofHistory.T -> ProofHistory.T |
10464 | 104 |
val presume_i: (((string * Proof.context attribute list) * (term * (term list * term list)) list) |
7271 | 105 |
* Comment.text) list -> ProofHistory.T -> ProofHistory.T |
10464 | 106 |
val local_def: ((string * Args.src list) * (string * (string * string list))) |
6952 | 107 |
* Comment.text -> ProofHistory.T -> ProofHistory.T |
10464 | 108 |
val local_def_i: ((string * Args.src list) * (string * (term * term list))) |
6952 | 109 |
* Comment.text -> ProofHistory.T -> ProofHistory.T |
10464 | 110 |
val show: ((string * Args.src list) * (string * (string list * string list))) |
10935 | 111 |
* Comment.text -> bool -> ProofHistory.T -> ProofHistory.T |
10464 | 112 |
val show_i: ((string * Proof.context attribute list) * (term * (term list * term list))) |
10935 | 113 |
* Comment.text -> bool -> ProofHistory.T -> ProofHistory.T |
10464 | 114 |
val have: ((string * Args.src list) * (string * (string list * string list))) |
6937 | 115 |
* Comment.text -> ProofHistory.T -> ProofHistory.T |
10464 | 116 |
val have_i: ((string * Proof.context attribute list) * (term * (term list * term list))) |
6937 | 117 |
* Comment.text -> ProofHistory.T -> ProofHistory.T |
10464 | 118 |
val thus: ((string * Args.src list) * (string * (string list * string list))) |
10935 | 119 |
* Comment.text -> bool -> ProofHistory.T -> ProofHistory.T |
10464 | 120 |
val thus_i: ((string * Proof.context attribute list) * (term * (term list * term list))) |
10935 | 121 |
* Comment.text -> bool -> ProofHistory.T -> ProofHistory.T |
10464 | 122 |
val hence: ((string * Args.src list) * (string * (string list * string list))) |
6937 | 123 |
* Comment.text -> ProofHistory.T -> ProofHistory.T |
10464 | 124 |
val hence_i: ((string * Proof.context attribute list) * (term * (term list * term list))) |
6937 | 125 |
* Comment.text -> ProofHistory.T -> ProofHistory.T |
11890 | 126 |
val obtain: ((string list * string option) * Comment.text) list |
127 |
* (((string * Args.src list) * (string * (string list * string list)) list) |
|
128 |
* Comment.text) list -> ProofHistory.T -> ProofHistory.T |
|
129 |
val obtain_i: ((string list * typ option) * Comment.text) list |
|
130 |
* (((string * Proof.context attribute list) * (term * (term list * term list)) list) |
|
131 |
* Comment.text) list -> ProofHistory.T -> ProofHistory.T |
|
9032 | 132 |
val begin_block: Comment.text -> ProofHistory.T -> ProofHistory.T |
133 |
val next_block: Comment.text -> ProofHistory.T -> ProofHistory.T |
|
134 |
val end_block: Comment.text -> ProofHistory.T -> ProofHistory.T |
|
8681 | 135 |
val defer: int option * Comment.text -> ProofHistory.T -> ProofHistory.T |
136 |
val prefer: int * Comment.text -> ProofHistory.T -> ProofHistory.T |
|
137 |
val apply: Method.text * Comment.text -> ProofHistory.T -> ProofHistory.T |
|
138 |
val apply_end: Method.text * Comment.text -> ProofHistory.T -> ProofHistory.T |
|
7002 | 139 |
val proof: (Comment.interest * (Method.text * Comment.interest) option) * Comment.text |
6728
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
140 |
-> ProofHistory.T -> ProofHistory.T |
7002 | 141 |
val qed: (Method.text * Comment.interest) option * Comment.text |
6937 | 142 |
-> Toplevel.transition -> Toplevel.transition |
7002 | 143 |
val terminal_proof: ((Method.text * Comment.interest) * (Method.text * Comment.interest) option) |
144 |
* Comment.text -> Toplevel.transition -> Toplevel.transition |
|
8966 | 145 |
val default_proof: Comment.text -> Toplevel.transition -> Toplevel.transition |
7002 | 146 |
val immediate_proof: Comment.text -> Toplevel.transition -> Toplevel.transition |
8966 | 147 |
val done_proof: Comment.text -> Toplevel.transition -> Toplevel.transition |
7002 | 148 |
val skip_proof: Comment.text -> Toplevel.transition -> Toplevel.transition |
8210 | 149 |
val forget_proof: Comment.text -> Toplevel.transition -> Toplevel.transition |
7012 | 150 |
val get_thmss: (string * Args.src list) list -> Proof.state -> thm list |
6879 | 151 |
val also: ((string * Args.src list) list * Comment.interest) option * Comment.text |
152 |
-> Toplevel.transition -> Toplevel.transition |
|
153 |
val also_i: (thm list * Comment.interest) option * Comment.text |
|
154 |
-> Toplevel.transition -> Toplevel.transition |
|
155 |
val finally: ((string * Args.src list) list * Comment.interest) option * Comment.text |
|
156 |
-> Toplevel.transition -> Toplevel.transition |
|
157 |
val finally_i: (thm list * Comment.interest) option * Comment.text |
|
158 |
-> Toplevel.transition -> Toplevel.transition |
|
8562 | 159 |
val moreover: Comment.text -> Toplevel.transition -> Toplevel.transition |
8588 | 160 |
val ultimately: Comment.text -> Toplevel.transition -> Toplevel.transition |
9273 | 161 |
val parse_ast_translation: string * Comment.text -> theory -> theory |
162 |
val parse_translation: string * Comment.text -> theory -> theory |
|
163 |
val print_translation: string * Comment.text -> theory -> theory |
|
164 |
val typed_print_translation: string * Comment.text -> theory -> theory |
|
165 |
val print_ast_translation: string * Comment.text -> theory -> theory |
|
166 |
val token_translation: string * Comment.text -> theory -> theory |
|
9193
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
167 |
val method_setup: (bstring * string * string) * Comment.text -> theory -> theory |
6728
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
168 |
val add_oracle: (bstring * string) * Comment.text -> theory -> theory |
6331 | 169 |
val begin_theory: string -> string list -> (string * bool) list -> theory |
170 |
val end_theory: theory -> theory |
|
7932 | 171 |
val kill_theory: string -> unit |
6246 | 172 |
val theory: string * string list * (string * bool) list |
173 |
-> Toplevel.transition -> Toplevel.transition |
|
7960 | 174 |
val init_context: ('a -> unit) -> 'a -> Toplevel.transition -> Toplevel.transition |
6246 | 175 |
val context: string -> Toplevel.transition -> Toplevel.transition |
5830 | 176 |
end; |
177 |
||
178 |
structure IsarThy: ISAR_THY = |
|
179 |
struct |
|
180 |
||
181 |
||
182 |
(** derived theory and proof operations **) |
|
183 |
||
8090 | 184 |
(* markup commands *) |
5959 | 185 |
|
7734 | 186 |
fun add_header comment = |
187 |
Toplevel.keep (fn state => if Toplevel.is_toplevel state then () else raise Toplevel.UNDEF); |
|
188 |
||
8090 | 189 |
fun add_text _ x = x; |
8079 | 190 |
fun add_text_raw _ x = x; |
7633 | 191 |
|
8090 | 192 |
fun add_heading add present txt thy = |
7633 | 193 |
(Context.setmp (Some thy) present (Comment.string_of txt); add txt thy); |
194 |
||
8090 | 195 |
val add_chapter = add_heading add_text Present.section; |
196 |
val add_section = add_heading add_text Present.section; |
|
197 |
val add_subsection = add_heading add_text Present.subsection; |
|
198 |
val add_subsubsection = add_heading add_text Present.subsubsection; |
|
5959 | 199 |
|
8090 | 200 |
fun add_txt (_: Comment.text) = ProofHistory.apply I; |
201 |
val add_txt_raw = add_txt; |
|
7332 | 202 |
val add_sect = add_txt; |
203 |
val add_subsect = add_txt; |
|
204 |
val add_subsubsect = add_txt; |
|
7172 | 205 |
|
5959 | 206 |
|
8724 | 207 |
(* name spaces *) |
208 |
||
209 |
fun global_path comment_ignore = PureThy.global_path; |
|
210 |
fun local_path comment_ignore = PureThy.local_path; |
|
211 |
||
8885 | 212 |
local |
213 |
||
214 |
val kinds = |
|
10449
088aa7bd3154
hide_space(_i): use Sign.certify_tycon, Sign.certify_tyabbr, Sign.certify_const;
wenzelm
parents:
9903
diff
changeset
|
215 |
[(Sign.classK, can o Sign.certify_class), |
8885 | 216 |
(Sign.typeK, fn sg => fn c => |
10449
088aa7bd3154
hide_space(_i): use Sign.certify_tycon, Sign.certify_tyabbr, Sign.certify_const;
wenzelm
parents:
9903
diff
changeset
|
217 |
can (Sign.certify_tycon sg) c orelse can (Sign.certify_tyabbr sg) c), |
088aa7bd3154
hide_space(_i): use Sign.certify_tycon, Sign.certify_tyabbr, Sign.certify_const;
wenzelm
parents:
9903
diff
changeset
|
218 |
(Sign.constK, can o Sign.certify_const)]; |
8724 | 219 |
|
8885 | 220 |
fun gen_hide intern ((kind, xnames), comment_ignore) thy = |
221 |
(case assoc (kinds, kind) of |
|
222 |
Some check => |
|
223 |
let |
|
224 |
val sg = Theory.sign_of thy; |
|
225 |
val names = map (intern sg kind) xnames; |
|
226 |
val bads = filter_out (check sg) names; |
|
227 |
in |
|
228 |
if null bads then Theory.hide_space_i (kind, names) thy |
|
229 |
else error ("Attempt to hide undeclared item(s): " ^ commas_quote bads) |
|
230 |
end |
|
231 |
| None => error ("Bad name space specification: " ^ quote kind)); |
|
232 |
||
233 |
in |
|
234 |
||
235 |
fun hide_space x = gen_hide Sign.intern x; |
|
236 |
fun hide_space_i x = gen_hide (K (K I)) x; |
|
237 |
||
238 |
end; |
|
8724 | 239 |
|
240 |
||
6728
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
241 |
(* signature and syntax *) |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
242 |
|
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
243 |
val add_classes = Theory.add_classes o Comment.ignore; |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
244 |
val add_classes_i = Theory.add_classes_i o Comment.ignore; |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
245 |
val add_classrel = Theory.add_classrel o single o Comment.ignore; |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
246 |
val add_classrel_i = Theory.add_classrel_i o single o Comment.ignore; |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
247 |
val add_defsort = Theory.add_defsort o Comment.ignore; |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
248 |
val add_defsort_i = Theory.add_defsort_i o Comment.ignore; |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
249 |
val add_nonterminals = Theory.add_nonterminals o map Comment.ignore; |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
250 |
val add_tyabbrs = Theory.add_tyabbrs o map Comment.ignore; |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
251 |
val add_tyabbrs_i = Theory.add_tyabbrs_i o map Comment.ignore; |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
252 |
val add_arities = Theory.add_arities o map Comment.ignore; |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
253 |
val add_arities_i = Theory.add_arities_i o map Comment.ignore; |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
254 |
val add_typedecl = PureThy.add_typedecls o single o Comment.ignore; |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
255 |
val add_consts = Theory.add_consts o map Comment.ignore; |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
256 |
val add_consts_i = Theory.add_consts_i o map Comment.ignore; |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
257 |
fun add_modesyntax mode = Theory.add_modesyntax mode o map Comment.ignore; |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
258 |
fun add_modesyntax_i mode = Theory.add_modesyntax_i mode o map Comment.ignore; |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
259 |
val add_trrules = Theory.add_trrules o map Comment.ignore; |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
260 |
val add_trrules_i = Theory.add_trrules_i o map Comment.ignore; |
11764 | 261 |
val add_judgment = ObjectLogic.add_judgment o Comment.ignore; |
262 |
val add_judgment_i = ObjectLogic.add_judgment_i o Comment.ignore; |
|
6728
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
263 |
|
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
264 |
|
5830 | 265 |
(* axioms and defs *) |
266 |
||
5915 | 267 |
fun add_axms f args thy = |
268 |
f (map (fn (x, srcs) => (x, map (Attrib.global_attribute thy) srcs)) args) thy; |
|
269 |
||
8428 | 270 |
val add_axioms = add_axms (#1 oo PureThy.add_axioms) o map Comment.ignore; |
271 |
val add_axioms_i = (#1 oo PureThy.add_axioms_i) o map Comment.ignore; |
|
9318 | 272 |
fun add_defs (x, args) = add_axms (#1 oo PureThy.add_defs x) (map Comment.ignore args); |
273 |
fun add_defs_i (x, args) = (#1 oo PureThy.add_defs_i x) (map Comment.ignore args); |
|
6371 | 274 |
|
275 |
||
276 |
(* constdefs *) |
|
277 |
||
278 |
fun gen_add_constdefs consts defs args thy = |
|
279 |
thy |
|
6728
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
280 |
|> consts (map (Comment.ignore o fst) args) |
9318 | 281 |
|> defs (false, map (fn (((c, _, mx), _), (s, _)) => |
6728
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
282 |
(((Thm.def_name (Syntax.const_name c mx), s), []), Comment.none)) args); |
6371 | 283 |
|
6728
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
284 |
fun add_constdefs args = gen_add_constdefs Theory.add_consts add_defs args; |
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
285 |
fun add_constdefs_i args = gen_add_constdefs Theory.add_consts_i add_defs_i args; |
5915 | 286 |
|
287 |
||
288 |
(* theorems *) |
|
289 |
||
9193
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
290 |
fun prep_thmss get attrib = map (fn ((name, more_srcs), th_srcs) => |
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
291 |
((name, map attrib more_srcs), map (fn (s, srcs) => (get s, map attrib srcs)) th_srcs)); |
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
292 |
|
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
293 |
fun flat_unnamed (x, ys) = (x, flat (map snd ys)); |
11742 | 294 |
fun cond_kind k = if k = "" then [] else [Drule.kind k]; |
5915 | 295 |
|
9193
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
296 |
fun global_have_thmss kind f args thy = |
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
297 |
let |
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
298 |
val args' = prep_thmss (PureThy.get_thms thy) (Attrib.global_attribute thy) args |
11742 | 299 |
val (thy', named_thmss) = f (cond_kind kind) args' thy; |
300 |
fun present (name, thms) = Present.results (kind ^ "s") name thms; |
|
9193
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
301 |
in |
11742 | 302 |
if kind = "" orelse kind = Drule.internalK then () |
9193
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
303 |
else Context.setmp (Some thy') (fn () => seq present named_thmss) (); |
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
304 |
(thy', named_thmss) |
7572 | 305 |
end; |
5915 | 306 |
|
9193
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
307 |
fun local_have_thmss f args state = |
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
308 |
let |
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
309 |
val args' = prep_thmss (ProofContext.get_thms (Proof.context_of state)) |
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
310 |
(Attrib.local_attribute (Proof.theory_of state)) args; |
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
311 |
in f args' state end; |
6371 | 312 |
|
9193
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
313 |
fun gen_have_thmss_i f args = f (map (fn ((name, more_atts), th_atts) => |
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
314 |
((name, more_atts), map (apfst single) th_atts)) args); |
5915 | 315 |
|
9590 | 316 |
fun apply_theorems th_srcs = |
11742 | 317 |
flat_unnamed o global_have_thmss "" PureThy.have_thmss [(("", []), th_srcs)]; |
9590 | 318 |
fun apply_theorems_i th_srcs = |
319 |
flat_unnamed o gen_have_thmss_i (PureThy.have_thmss []) [(("", []), th_srcs)]; |
|
320 |
||
321 |
val declare_theorems = #1 oo (apply_theorems o Comment.ignore); |
|
322 |
val declare_theorems_i = #1 oo (apply_theorems_i o Comment.ignore); |
|
323 |
||
11742 | 324 |
fun have_theorems kind = |
325 |
#1 oo (global_have_thmss kind PureThy.have_thmss o map Comment.ignore); |
|
326 |
fun have_theorems_i kind = |
|
327 |
#1 oo (gen_have_thmss_i (PureThy.have_thmss (cond_kind kind)) o map Comment.ignore); |
|
9590 | 328 |
|
9193
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
329 |
val have_facts = ProofHistory.apply o local_have_thmss Proof.have_thmss o map Comment.ignore; |
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
330 |
val have_facts_i = ProofHistory.apply o gen_have_thmss_i Proof.have_thmss o map Comment.ignore; |
6371 | 331 |
|
5915 | 332 |
|
6371 | 333 |
(* forward chaining *) |
334 |
||
9193
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
335 |
fun gen_from_facts f args = ProofHistory.apply (Proof.chain o f (map (pair ("", [])) args)); |
6371 | 336 |
|
9193
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
337 |
val from_facts = gen_from_facts (local_have_thmss Proof.have_thmss) o map Comment.ignore; |
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
338 |
val from_facts_i = gen_from_facts (gen_have_thmss_i Proof.have_thmss) o map Comment.ignore; |
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
339 |
val with_facts = gen_from_facts (local_have_thmss Proof.with_thmss) o map Comment.ignore; |
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
340 |
val with_facts_i = gen_from_facts (gen_have_thmss_i Proof.with_thmss) o map Comment.ignore; |
6879 | 341 |
|
6728
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
342 |
fun chain comment_ignore = ProofHistory.apply Proof.chain; |
5830 | 343 |
|
344 |
||
345 |
(* context *) |
|
346 |
||
7417 | 347 |
val fix = ProofHistory.apply o Proof.fix o map Comment.ignore; |
348 |
val fix_i = ProofHistory.apply o Proof.fix_i o map Comment.ignore; |
|
8615 | 349 |
val let_bind = ProofHistory.apply o Proof.let_bind o map Comment.ignore; |
350 |
val let_bind_i = ProofHistory.apply o Proof.let_bind_i o map Comment.ignore; |
|
8450 | 351 |
|
11793
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11764
diff
changeset
|
352 |
fun invoke_case ((name, xs, src), comment_ignore) = ProofHistory.apply (fn state => |
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11764
diff
changeset
|
353 |
Proof.invoke_case (name, xs, map (Attrib.local_attribute (Proof.theory_of state)) src) state); |
8450 | 354 |
val invoke_case_i = ProofHistory.apply o Proof.invoke_case o Comment.ignore; |
5830 | 355 |
|
356 |
||
10935 | 357 |
(* local results *) |
358 |
||
359 |
local |
|
360 |
||
361 |
fun pretty_result {kind, name, thm} = |
|
362 |
Pretty.block [Pretty.str (kind ^ (if name = "" then "" else " " ^ name) ^ ":"), |
|
363 |
Pretty.fbrk, Proof.pretty_thm thm]; |
|
364 |
||
365 |
fun pretty_rule s thm = |
|
366 |
Pretty.block [Pretty.str (s ^ " to solve goal by exported rule:"), |
|
367 |
Pretty.fbrk, Proof.pretty_thm thm]; |
|
368 |
||
369 |
in |
|
370 |
||
371 |
val print_result = Pretty.writeln o pretty_result; |
|
372 |
||
373 |
fun cond_print_result_rule int = |
|
11048 | 374 |
if int then (print_result, priority o Pretty.string_of o pretty_rule "Attempt") |
10935 | 375 |
else (K (), K ()); |
376 |
||
377 |
fun proof'' f = Toplevel.proof' (f o cond_print_result_rule); |
|
378 |
||
379 |
fun check_goal false state = state |
|
380 |
| check_goal true state = |
|
381 |
let |
|
382 |
val rule = ref (None: thm option); |
|
383 |
fun warn exn = |
|
384 |
(["Problem! Local statement will fail to solve any pending goal"] @ |
|
385 |
(case exn of None => [] | Some e => [Toplevel.exn_message e]) @ |
|
386 |
(case ! rule of None => [] | Some thm => |
|
387 |
[Pretty.string_of (pretty_rule "Failed attempt" thm)])) |
|
388 |
|> cat_lines |> warning; |
|
389 |
val check = |
|
390 |
(fn () => Seq.pull (SkipProof.local_skip_proof (K (), fn thm => rule := Some thm) state)) |
|
391 |
|> Library.setmp quick_and_dirty true |
|
392 |
|> Library.transform_error; |
|
393 |
val result = (check (), None) handle Interrupt => raise Interrupt | e => (None, Some e); |
|
394 |
in (case result of (Some _, None) => () | (_, exn) => warn exn); state end; |
|
395 |
||
396 |
end; |
|
397 |
||
398 |
||
5830 | 399 |
(* statements *) |
400 |
||
7271 | 401 |
local |
402 |
||
10935 | 403 |
fun local_statement' f g ((name, src), s) int = ProofHistory.apply (fn state => |
404 |
f name (map (Attrib.local_attribute (Proof.theory_of state)) src) s int (g state)); |
|
6371 | 405 |
|
10935 | 406 |
fun local_statement_i' f g ((name, atts), t) int = |
407 |
ProofHistory.apply (f name atts t int o g); |
|
408 |
||
409 |
fun local_statement f g args = local_statement' (K ooo f) g args (); |
|
410 |
fun local_statement_i f g args = local_statement_i' (K ooo f) g args (); |
|
5830 | 411 |
|
10464 | 412 |
fun multi_local_attribute state ((name, src), s) = |
413 |
((name, map (Attrib.local_attribute (Proof.theory_of state)) src), s); |
|
8090 | 414 |
|
7271 | 415 |
fun multi_statement f args = ProofHistory.apply (fn state => |
7678 | 416 |
f (map (multi_local_attribute state) args) state); |
7271 | 417 |
|
418 |
fun multi_statement_i f args = ProofHistory.apply (f args); |
|
419 |
||
420 |
in |
|
421 |
||
11742 | 422 |
fun theorem k (((name, src), s), comment_ignore) int thy = |
423 |
ProofHistory.init (Toplevel.undo_limit int) |
|
424 |
(Proof.theorem k name (map (Attrib.global_attribute thy) src) s thy); |
|
425 |
||
426 |
fun theorem_i k (((name, atts), t), comment_ignore) int thy = |
|
427 |
ProofHistory.init (Toplevel.undo_limit int) (Proof.theorem_i k name atts t thy); |
|
428 |
||
7271 | 429 |
val assume = multi_statement Proof.assume o map Comment.ignore; |
430 |
val assume_i = multi_statement_i Proof.assume_i o map Comment.ignore; |
|
431 |
val presume = multi_statement Proof.presume o map Comment.ignore; |
|
432 |
val presume_i = multi_statement_i Proof.presume_i o map Comment.ignore; |
|
11890 | 433 |
val local_def = local_statement Proof.def I o Comment.ignore; |
434 |
val local_def_i = local_statement Proof.def_i I o Comment.ignore; |
|
10935 | 435 |
val show = local_statement' (Proof.show check_goal Seq.single) I o Comment.ignore; |
436 |
val show_i = local_statement_i' (Proof.show_i check_goal Seq.single) I o Comment.ignore; |
|
7176 | 437 |
val have = local_statement (Proof.have Seq.single) I o Comment.ignore; |
438 |
val have_i = local_statement_i (Proof.have_i Seq.single) I o Comment.ignore; |
|
10935 | 439 |
val thus = local_statement' (Proof.show check_goal Seq.single) Proof.chain o Comment.ignore; |
440 |
val thus_i = local_statement_i' (Proof.show_i check_goal Seq.single) Proof.chain o Comment.ignore; |
|
7176 | 441 |
val hence = local_statement (Proof.have Seq.single) Proof.chain o Comment.ignore; |
442 |
val hence_i = local_statement_i (Proof.have_i Seq.single) Proof.chain o Comment.ignore; |
|
5830 | 443 |
|
11890 | 444 |
fun obtain (xs, asms) = ProofHistory.applys (fn state => |
445 |
Obtain.obtain (map Comment.ignore xs) |
|
446 |
(map (multi_local_attribute state) (map Comment.ignore asms)) state); |
|
447 |
||
448 |
fun obtain_i (xs, asms) = ProofHistory.applys (fn state => |
|
449 |
Obtain.obtain_i (map Comment.ignore xs) (map Comment.ignore asms) state); |
|
450 |
||
7271 | 451 |
end; |
452 |
||
5830 | 453 |
|
454 |
(* blocks *) |
|
455 |
||
9032 | 456 |
fun begin_block comment_ignore = ProofHistory.apply Proof.begin_block; |
457 |
fun next_block comment_ignore = ProofHistory.apply Proof.next_block; |
|
458 |
fun end_block comment_ignore = ProofHistory.applys Proof.end_block; |
|
5830 | 459 |
|
460 |
||
8165 | 461 |
(* shuffle state *) |
462 |
||
8236 | 463 |
fun shuffle meth i = Method.refine (Method.Basic (K (meth i))) o Proof.assert_no_chain; |
8204 | 464 |
|
8681 | 465 |
fun defer (i, comment_ignore) = ProofHistory.applys (shuffle Method.defer i); |
466 |
fun prefer (i, comment_ignore) = ProofHistory.applys (shuffle Method.prefer i); |
|
8165 | 467 |
|
468 |
||
5830 | 469 |
(* backward steps *) |
470 |
||
8881 | 471 |
fun apply (m, comment_ignore) = ProofHistory.applys |
472 |
(Seq.map (Proof.goal_facts (K [])) o Method.refine m o Proof.assert_backward); |
|
473 |
||
474 |
fun apply_end (m, comment_ignore) = ProofHistory.applys |
|
475 |
(Method.refine_end m o Proof.assert_forward); |
|
6728
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
476 |
|
7002 | 477 |
val proof = ProofHistory.applys o Method.proof o |
478 |
apsome Comment.ignore_interest o Comment.ignore_interest' o Comment.ignore; |
|
6404 | 479 |
|
480 |
||
481 |
(* local endings *) |
|
482 |
||
6728
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
483 |
val local_qed = |
8966 | 484 |
proof'' o (ProofHistory.applys oo Method.local_qed true) o apsome Comment.ignore_interest; |
6728
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
485 |
|
6937 | 486 |
fun ignore_interests (x, y) = (Comment.ignore_interest x, apsome Comment.ignore_interest y); |
487 |
||
6688 | 488 |
val local_terminal_proof = |
6937 | 489 |
proof'' o (ProofHistory.applys oo Method.local_terminal_proof) o ignore_interests; |
6728
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
490 |
|
8966 | 491 |
val local_default_proof = proof'' (ProofHistory.applys o Method.local_default_proof); |
6904
4125d6b6d8f9
removed proof history nesting commands (not useful);
wenzelm
parents:
6890
diff
changeset
|
492 |
val local_immediate_proof = proof'' (ProofHistory.applys o Method.local_immediate_proof); |
4125d6b6d8f9
removed proof history nesting commands (not useful);
wenzelm
parents:
6890
diff
changeset
|
493 |
val local_skip_proof = proof'' (ProofHistory.applys o SkipProof.local_skip_proof); |
8966 | 494 |
val local_done_proof = proof'' (ProofHistory.applys o Method.local_done_proof); |
6404 | 495 |
|
496 |
||
497 |
(* global endings *) |
|
498 |
||
499 |
fun global_result finish = Toplevel.proof_to_theory (fn prf => |
|
500 |
let |
|
501 |
val state = ProofHistory.current prf; |
|
502 |
val _ = if Proof.at_bottom state then () else raise Toplevel.UNDEF; |
|
7572 | 503 |
val (thy, res as {kind, name, thm}) = finish state; |
11742 | 504 |
in |
505 |
if kind = "" orelse kind = Drule.internalK then () |
|
506 |
else (print_result res; Context.setmp (Some thy) (Present.result kind name) thm); |
|
507 |
thy |
|
508 |
end); |
|
6404 | 509 |
|
8966 | 510 |
val global_qed = global_result o Method.global_qed true o apsome Comment.ignore_interest; |
6937 | 511 |
val global_terminal_proof = global_result o Method.global_terminal_proof o ignore_interests; |
8966 | 512 |
val global_default_proof = global_result Method.global_default_proof; |
6404 | 513 |
val global_immediate_proof = global_result Method.global_immediate_proof; |
6888
d0c68ebdabc5
skip_proof feature 'sorry' (for quick_and_dirty mode only);
wenzelm
parents:
6885
diff
changeset
|
514 |
val global_skip_proof = global_result SkipProof.global_skip_proof; |
8966 | 515 |
val global_done_proof = global_result Method.global_done_proof; |
6404 | 516 |
|
517 |
||
518 |
(* common endings *) |
|
519 |
||
7002 | 520 |
fun qed (meth, comment) = local_qed meth o global_qed meth; |
521 |
fun terminal_proof (meths, comment) = local_terminal_proof meths o global_terminal_proof meths; |
|
8966 | 522 |
fun default_proof comment = local_default_proof o global_default_proof; |
7002 | 523 |
fun immediate_proof comment = local_immediate_proof o global_immediate_proof; |
8966 | 524 |
fun done_proof comment = local_done_proof o global_done_proof; |
7002 | 525 |
fun skip_proof comment = local_skip_proof o global_skip_proof; |
5830 | 526 |
|
8210 | 527 |
fun forget_proof comment = Toplevel.proof_to_theory (Proof.theory_of o ProofHistory.current); |
528 |
||
5830 | 529 |
|
6774 | 530 |
(* calculational proof commands *) |
531 |
||
6879 | 532 |
local |
533 |
||
7417 | 534 |
fun cond_print_calc int thms = |
535 |
if int then Pretty.writeln (Pretty.big_list "calculation:" (map Proof.pretty_thm thms)) |
|
6774 | 536 |
else (); |
537 |
||
538 |
fun proof''' f = Toplevel.proof' (f o cond_print_calc); |
|
539 |
||
6879 | 540 |
fun gen_calc get f (args, _) prt state = |
541 |
f (apsome (fn (srcs, _) => get srcs state) args) prt state; |
|
542 |
||
543 |
in |
|
544 |
||
9193
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
545 |
fun get_thmss srcs = Proof.the_facts o local_have_thmss Proof.have_thmss [(("", []), srcs)]; |
7012 | 546 |
fun get_thmss_i thms _ = thms; |
547 |
||
6879 | 548 |
fun also x = proof''' (ProofHistory.applys o gen_calc get_thmss Calculation.also x); |
549 |
fun also_i x = proof''' (ProofHistory.applys o gen_calc get_thmss_i Calculation.also x); |
|
550 |
fun finally x = proof''' (ProofHistory.applys o gen_calc get_thmss Calculation.finally x); |
|
551 |
fun finally_i x = proof''' (ProofHistory.applys o gen_calc get_thmss_i Calculation.finally x); |
|
8562 | 552 |
fun moreover comment = proof''' (ProofHistory.apply o Calculation.moreover); |
8588 | 553 |
fun ultimately comment = proof''' (ProofHistory.apply o Calculation.ultimately); |
6879 | 554 |
|
555 |
end; |
|
6774 | 556 |
|
557 |
||
5830 | 558 |
(* translation functions *) |
559 |
||
560 |
val parse_ast_translation = |
|
9590 | 561 |
Context.use_let "val parse_ast_translation: (string * (Syntax.ast list -> Syntax.ast)) list" |
9273 | 562 |
"Theory.add_trfuns (parse_ast_translation, [], [], [])" o Comment.ignore; |
5830 | 563 |
|
564 |
val parse_translation = |
|
9590 | 565 |
Context.use_let "val parse_translation: (string * (term list -> term)) list" |
9273 | 566 |
"Theory.add_trfuns ([], parse_translation, [], [])" o Comment.ignore; |
5830 | 567 |
|
568 |
val print_translation = |
|
9590 | 569 |
Context.use_let "val print_translation: (string * (term list -> term)) list" |
9273 | 570 |
"Theory.add_trfuns ([], [], print_translation, [])" o Comment.ignore; |
5830 | 571 |
|
572 |
val print_ast_translation = |
|
9590 | 573 |
Context.use_let "val print_ast_translation: (string * (Syntax.ast list -> Syntax.ast)) list" |
9273 | 574 |
"Theory.add_trfuns ([], [], [], print_ast_translation)" o Comment.ignore; |
5830 | 575 |
|
576 |
val typed_print_translation = |
|
9590 | 577 |
Context.use_let "val typed_print_translation: (string * (bool -> typ -> term list -> term)) list" |
9273 | 578 |
"Theory.add_trfunsT typed_print_translation" o Comment.ignore; |
5830 | 579 |
|
580 |
val token_translation = |
|
11717
d808005e6e08
Fixed erroneous type constraint in token_translation function.
berghofe
parents:
11048
diff
changeset
|
581 |
Context.use_let "val token_translation: (string * string * (string -> string * real)) list" |
9273 | 582 |
"Theory.add_tokentrfuns token_translation" o Comment.ignore; |
5830 | 583 |
|
584 |
||
9193
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
585 |
(* add method *) |
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
586 |
|
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
587 |
fun method_setup ((name, txt, cmt), comment_ignore) = |
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
588 |
Context.use_let |
9810 | 589 |
"val thm = PureThy.get_thm_closure (Context.the_context ());\n\ |
590 |
\val thms = PureThy.get_thms_closure (Context.the_context ());\n\ |
|
591 |
\val method: bstring * (Args.src -> Proof.context -> Proof.method) * string" |
|
9193
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
592 |
"PureIsar.Method.add_method method" |
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
593 |
("(" ^ quote name ^ ", " ^ txt ^ ", " ^ quote cmt ^ ")"); |
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
594 |
|
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
595 |
|
5830 | 596 |
(* add_oracle *) |
597 |
||
6728
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
598 |
fun add_oracle ((name, txt), comment_ignore) = |
8349
611342539639
moved use_mltext, use_mltext_theory, use_let, use_setup to context.ML;
wenzelm
parents:
8236
diff
changeset
|
599 |
Context.use_let |
9590 | 600 |
"val oracle: bstring * (Sign.sg * Object.T -> term)" |
5830 | 601 |
"Theory.add_oracle oracle" |
602 |
("(" ^ quote name ^ ", " ^ txt ^ ")"); |
|
603 |
||
604 |
||
6688 | 605 |
(* theory init and exit *) |
5830 | 606 |
|
8804 | 607 |
fun gen_begin_theory upd name parents files = |
608 |
ThyInfo.begin_theory Present.begin_theory upd name parents (map (apfst Path.unpack) files); |
|
5830 | 609 |
|
8804 | 610 |
val begin_theory = gen_begin_theory false; |
7909 | 611 |
|
612 |
fun end_theory thy = |
|
7932 | 613 |
if ThyInfo.check_known_thy (PureThy.get_name thy) then ThyInfo.end_theory thy |
7909 | 614 |
else thy; |
615 |
||
7932 | 616 |
val kill_theory = ThyInfo.if_known_thy ThyInfo.remove_thy; |
6688 | 617 |
|
7103 | 618 |
|
8804 | 619 |
fun bg_theory (name, parents, files) int = gen_begin_theory int name parents files; |
6331 | 620 |
fun en_theory thy = (end_theory thy; ()); |
621 |
||
7932 | 622 |
fun theory spec = Toplevel.init_theory (bg_theory spec) en_theory (kill_theory o PureThy.get_name); |
6246 | 623 |
|
624 |
||
625 |
(* context switch *) |
|
626 |
||
7960 | 627 |
fun fetch_context f x = |
628 |
(case Context.pass None f x of |
|
629 |
((), None) => raise Toplevel.UNDEF |
|
630 |
| ((), Some thy) => thy); |
|
631 |
||
632 |
fun init_context f x = Toplevel.init_theory (fn _ => fetch_context f x) (K ()) (K ()); |
|
7953 | 633 |
|
634 |
val context = init_context (ThyInfo.quiet_update_thy true); |
|
6246 | 635 |
|
5830 | 636 |
|
637 |
end; |