author | ballarin |
Thu, 07 Jul 2005 15:52:31 +0200 | |
changeset 16736 | 1e792b32abef |
parent 16605 | 4590c1f79050 |
child 16849 | a6cdb1ade955 |
permissions | -rw-r--r-- |
5830 | 1 |
(* Title: Pure/Isar/isar_thy.ML |
2 |
ID: $Id$ |
|
3 |
Author: Markus Wenzel, TU Muenchen |
|
4 |
||
6371 | 5 |
Pure/Isar derived theory operations. |
5830 | 6 |
*) |
7 |
||
8 |
signature ISAR_THY = |
|
9 |
sig |
|
16372 | 10 |
val hide_names: string * xstring list -> theory -> theory |
11 |
val hide_names_i: string * string list -> theory -> theory |
|
15703 | 12 |
val add_axioms: ((bstring * string) * Attrib.src list) list -> theory -> theory |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
13 |
val add_axioms_i: ((bstring * term) * theory attribute list) list -> theory -> theory |
15703 | 14 |
val add_defs: bool * ((bstring * string) * Attrib.src list) list -> theory -> theory |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
15 |
val add_defs_i: bool * ((bstring * term) * theory attribute list) list -> theory -> theory |
15703 | 16 |
val theorems: string -> |
17 |
((bstring * Attrib.src list) * (thmref * Attrib.src list) list) list |
|
12713
c9e3e34dbc45
clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents:
12705
diff
changeset
|
18 |
-> theory -> theory * (string * thm list) list |
c9e3e34dbc45
clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents:
12705
diff
changeset
|
19 |
val theorems_i: string -> |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
20 |
((bstring * theory attribute list) * (thm list * theory attribute list) list) list |
12713
c9e3e34dbc45
clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents:
12705
diff
changeset
|
21 |
-> theory -> theory * (string * thm list) list |
c9e3e34dbc45
clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents:
12705
diff
changeset
|
22 |
val locale_theorems: string -> xstring -> |
15703 | 23 |
((bstring * Attrib.src list) * (thmref * Attrib.src list) list) list |
12713
c9e3e34dbc45
clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents:
12705
diff
changeset
|
24 |
-> theory -> theory * (bstring * thm list) list |
c9e3e34dbc45
clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents:
12705
diff
changeset
|
25 |
val locale_theorems_i: string -> string -> |
15703 | 26 |
((bstring * Attrib.src list) * (thm list * Attrib.src list) list) list -> |
27 |
theory -> theory * (string * thm list) list |
|
12713
c9e3e34dbc45
clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents:
12705
diff
changeset
|
28 |
val smart_theorems: string -> xstring option -> |
15703 | 29 |
((bstring * Attrib.src list) * (thmref * Attrib.src list) list) list |
12713
c9e3e34dbc45
clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents:
12705
diff
changeset
|
30 |
-> theory -> theory * (string * thm list) list |
15703 | 31 |
val declare_theorems: xstring option -> |
32 |
(thmref * Attrib.src list) list -> theory -> theory |
|
33 |
val apply_theorems: (thmref * Attrib.src list) list -> theory -> theory * thm list |
|
12713
c9e3e34dbc45
clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents:
12705
diff
changeset
|
34 |
val apply_theorems_i: (thm list * theory attribute list) list -> theory -> theory * thm list |
15703 | 35 |
val have_facts: ((string * Attrib.src list) * (thmref * Attrib.src list) list) list |
10464 | 36 |
-> ProofHistory.T -> ProofHistory.T |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
37 |
val have_facts_i: ((string * Proof.context attribute list) * |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
38 |
(thm * Proof.context attribute list) list) list -> ProofHistory.T -> ProofHistory.T |
15703 | 39 |
val from_facts: (thmref * Attrib.src list) list list -> ProofHistory.T -> ProofHistory.T |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
40 |
val from_facts_i: (thm * Proof.context attribute list) list list |
6728
b51b25db7bc6
added formal comment arguments almost everywhere (still ignored);
wenzelm
parents:
6688
diff
changeset
|
41 |
-> ProofHistory.T -> ProofHistory.T |
15703 | 42 |
val with_facts: (thmref * Attrib.src list) list list -> ProofHistory.T -> ProofHistory.T |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
43 |
val with_facts_i: (thm * Proof.context attribute list) list list |
6879 | 44 |
-> ProofHistory.T -> ProofHistory.T |
15703 | 45 |
val using_facts: (thmref * Attrib.src list) list list |
46 |
-> ProofHistory.T -> ProofHistory.T |
|
12929 | 47 |
val using_facts_i: (thm * Proof.context attribute list) list list |
48 |
-> ProofHistory.T -> ProofHistory.T |
|
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
49 |
val chain: ProofHistory.T -> ProofHistory.T |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
50 |
val fix: (string list * string option) list -> ProofHistory.T -> ProofHistory.T |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
51 |
val fix_i: (string list * typ option) list -> ProofHistory.T -> ProofHistory.T |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
52 |
val let_bind: (string list * string) list -> ProofHistory.T -> ProofHistory.T |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
53 |
val let_bind_i: (term list * term) list -> ProofHistory.T -> ProofHistory.T |
15703 | 54 |
val invoke_case: string * string option list * Attrib.src list -> ProofHistory.T -> ProofHistory.T |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
55 |
val invoke_case_i: string * string option list * Proof.context attribute list |
11793
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11764
diff
changeset
|
56 |
-> ProofHistory.T -> ProofHistory.T |
15703 | 57 |
val theorem: string -> (bstring * Attrib.src list) * (string * (string list * string list)) |
12141 | 58 |
-> bool -> theory -> ProofHistory.T |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
59 |
val theorem_i: string -> (bstring * theory attribute list) * |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
60 |
(term * (term list * term list)) -> bool -> theory -> ProofHistory.T |
15703 | 61 |
val multi_theorem: string -> (theory -> theory) -> |
15696 | 62 |
(cterm list -> Proof.context -> Proof.context -> thm -> thm) -> |
15703 | 63 |
bstring * Attrib.src list -> Locale.element Locale.elem_expr list -> |
64 |
((bstring * Attrib.src list) * (string * (string list * string list)) list) list |
|
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
65 |
-> bool -> theory -> ProofHistory.T |
15703 | 66 |
val multi_theorem_i: string -> (theory -> theory) -> |
15696 | 67 |
(cterm list -> Proof.context -> Proof.context -> thm -> thm) -> |
15703 | 68 |
bstring * theory attribute list -> Locale.element_i Locale.elem_expr list |
12957 | 69 |
-> ((bstring * theory attribute list) * (term * (term list * term list)) list) list |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
70 |
-> bool -> theory -> ProofHistory.T |
12957 | 71 |
val locale_multi_theorem: string -> xstring |
15703 | 72 |
-> bstring * Attrib.src list -> Locale.element Locale.elem_expr list |
73 |
-> ((bstring * Attrib.src list) * (string * (string list * string list)) list) list |
|
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
74 |
-> bool -> theory -> ProofHistory.T |
15703 | 75 |
val locale_multi_theorem_i: string -> string -> bstring * Attrib.src list |
76 |
-> Locale.element_i Locale.elem_expr list |
|
77 |
-> ((bstring * Attrib.src list) * (term * (term list * term list)) list) list |
|
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
78 |
-> bool -> theory -> ProofHistory.T |
15531 | 79 |
val smart_multi_theorem: string -> xstring option |
15703 | 80 |
-> bstring * Attrib.src list -> Locale.element Locale.elem_expr list |
81 |
-> ((bstring * Attrib.src list) * (string * (string list * string list)) list) list |
|
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
82 |
-> bool -> theory -> ProofHistory.T |
15703 | 83 |
val assume: ((string * Attrib.src list) * (string * (string list * string list)) list) list |
12141 | 84 |
-> ProofHistory.T -> ProofHistory.T |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
85 |
val assume_i: |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
86 |
((string * Proof.context attribute list) * (term * (term list * term list)) list) list |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
87 |
-> ProofHistory.T -> ProofHistory.T |
15703 | 88 |
val presume: ((string * Attrib.src list) * (string * (string list * string list)) list) list |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
89 |
-> ProofHistory.T -> ProofHistory.T |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
90 |
val presume_i: |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
91 |
((string * Proof.context attribute list) * (term * (term list * term list)) list) list |
12141 | 92 |
-> ProofHistory.T -> ProofHistory.T |
15703 | 93 |
val have: ((string * Attrib.src list) * |
94 |
(string * (string list * string list)) list) list -> ProofHistory.T -> ProofHistory.T |
|
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
95 |
val have_i: ((string * Proof.context attribute list) * |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
96 |
(term * (term list * term list)) list) list -> ProofHistory.T -> ProofHistory.T |
15703 | 97 |
val hence: ((string * Attrib.src list) * |
98 |
(string * (string list * string list)) list) list -> ProofHistory.T -> ProofHistory.T |
|
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
99 |
val hence_i: ((string * Proof.context attribute list) * |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
100 |
(term * (term list * term list)) list) list -> ProofHistory.T -> ProofHistory.T |
15703 | 101 |
val show: ((string * Attrib.src list) * |
102 |
(string * (string list * string list)) list) list |
|
12141 | 103 |
-> bool -> ProofHistory.T -> ProofHistory.T |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
104 |
val show_i: ((string * Proof.context attribute list) * |
15703 | 105 |
(term * (term list * term list)) list) list |
106 |
-> bool -> ProofHistory.T -> ProofHistory.T |
|
107 |
val thus: ((string * Attrib.src list) * |
|
108 |
(string * (string list * string list)) list) list |
|
12141 | 109 |
-> bool -> ProofHistory.T -> ProofHistory.T |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
110 |
val thus_i: ((string * Proof.context attribute list) |
15703 | 111 |
* (term * (term list * term list)) list) list |
112 |
-> bool -> ProofHistory.T -> ProofHistory.T |
|
113 |
val local_def: (string * Attrib.src list) * (string * (string * string list)) |
|
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
114 |
-> ProofHistory.T -> ProofHistory.T |
15703 | 115 |
val local_def_i: (string * Attrib.src list) * (string * (term * term list)) |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
116 |
-> ProofHistory.T -> ProofHistory.T |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
117 |
val obtain: (string list * string option) list |
15703 | 118 |
* ((string * Attrib.src list) * (string * (string list * string list)) list) list |
12969 | 119 |
-> Toplevel.transition -> Toplevel.transition |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
120 |
val obtain_i: (string list * typ option) list |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
121 |
* ((string * Proof.context attribute list) * (term * (term list * term list)) list) list |
12969 | 122 |
-> Toplevel.transition -> Toplevel.transition |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
123 |
val begin_block: ProofHistory.T -> ProofHistory.T |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
124 |
val next_block: ProofHistory.T -> ProofHistory.T |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
125 |
val end_block: ProofHistory.T -> ProofHistory.T |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
126 |
val defer: int option -> ProofHistory.T -> ProofHistory.T |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
127 |
val prefer: int -> ProofHistory.T -> ProofHistory.T |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
128 |
val apply: Method.text -> ProofHistory.T -> ProofHistory.T |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
129 |
val apply_end: Method.text -> ProofHistory.T -> ProofHistory.T |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
130 |
val proof: Method.text option -> ProofHistory.T -> ProofHistory.T |
16605
4590c1f79050
added print_mode three_buffersN and corresponding cond_print;
wenzelm
parents:
16529
diff
changeset
|
131 |
val three_buffersN: string |
4590c1f79050
added print_mode three_buffersN and corresponding cond_print;
wenzelm
parents:
16529
diff
changeset
|
132 |
val cond_print: Toplevel.transition -> Toplevel.transition |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
133 |
val qed: Method.text option -> Toplevel.transition -> Toplevel.transition |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
134 |
val terminal_proof: Method.text * Method.text option |
6937 | 135 |
-> Toplevel.transition -> Toplevel.transition |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
136 |
val default_proof: Toplevel.transition -> Toplevel.transition |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
137 |
val immediate_proof: Toplevel.transition -> Toplevel.transition |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
138 |
val done_proof: Toplevel.transition -> Toplevel.transition |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
139 |
val skip_proof: Toplevel.transition -> Toplevel.transition |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
140 |
val forget_proof: Toplevel.transition -> Toplevel.transition |
15703 | 141 |
val get_thmss: (thmref * Attrib.src list) list -> Proof.state -> thm list |
142 |
val also: (thmref * Attrib.src list) list option -> Toplevel.transition -> Toplevel.transition |
|
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
143 |
val also_i: thm list option -> Toplevel.transition -> Toplevel.transition |
15703 | 144 |
val finally: (thmref * Attrib.src list) list option -> Toplevel.transition -> Toplevel.transition |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
145 |
val finally_i: thm list option -> Toplevel.transition -> Toplevel.transition |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
146 |
val moreover: Toplevel.transition -> Toplevel.transition |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
147 |
val ultimately: Toplevel.transition -> Toplevel.transition |
14649
8ad41d25c152
removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents:
14598
diff
changeset
|
148 |
val parse_ast_translation: bool * string -> theory -> theory |
8ad41d25c152
removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents:
14598
diff
changeset
|
149 |
val parse_translation: bool * string -> theory -> theory |
8ad41d25c152
removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents:
14598
diff
changeset
|
150 |
val print_translation: bool * string -> theory -> theory |
8ad41d25c152
removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents:
14598
diff
changeset
|
151 |
val typed_print_translation: bool * string -> theory -> theory |
8ad41d25c152
removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents:
14598
diff
changeset
|
152 |
val print_ast_translation: bool * string -> theory -> theory |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
153 |
val token_translation: string -> theory -> theory |
15801 | 154 |
val generic_setup: string -> theory -> theory |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
155 |
val method_setup: bstring * string * string -> theory -> theory |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
156 |
val add_oracle: bstring * string -> theory -> theory |
15703 | 157 |
val add_locale: bool * bstring * Locale.expr * Locale.element list -> theory -> theory |
158 |
val register_globally: |
|
159 |
((string * Attrib.src list) * Locale.expr) * string option list -> |
|
160 |
bool -> theory -> ProofHistory.T |
|
16736
1e792b32abef
Preparations for interpretation of locales in locales.
ballarin
parents:
16605
diff
changeset
|
161 |
val register_in_locale: |
1e792b32abef
Preparations for interpretation of locales in locales.
ballarin
parents:
16605
diff
changeset
|
162 |
string * Locale.expr -> bool -> theory -> ProofHistory.T |
15703 | 163 |
val register_locally: |
164 |
((string * Attrib.src list) * Locale.expr) * string option list -> |
|
165 |
ProofHistory.T -> ProofHistory.T |
|
6331 | 166 |
val begin_theory: string -> string list -> (string * bool) list -> theory |
167 |
val end_theory: theory -> theory |
|
7932 | 168 |
val kill_theory: string -> unit |
6246 | 169 |
val theory: string * string list * (string * bool) list |
170 |
-> Toplevel.transition -> Toplevel.transition |
|
7960 | 171 |
val init_context: ('a -> unit) -> 'a -> Toplevel.transition -> Toplevel.transition |
6246 | 172 |
val context: string -> Toplevel.transition -> Toplevel.transition |
5830 | 173 |
end; |
174 |
||
175 |
structure IsarThy: ISAR_THY = |
|
176 |
struct |
|
177 |
||
178 |
(** derived theory and proof operations **) |
|
179 |
||
8724 | 180 |
(* name spaces *) |
181 |
||
8885 | 182 |
local |
183 |
||
184 |
val kinds = |
|
16372 | 185 |
[("class", (Sign.intern_class, can o Sign.certify_class, Theory.hide_classes_i)), |
186 |
("type", (Sign.intern_type, Sign.declared_tyname, Theory.hide_types_i)), |
|
187 |
("const", (Sign.intern_const, Sign.declared_const, Theory.hide_consts_i))]; |
|
8724 | 188 |
|
16372 | 189 |
fun gen_hide int (kind, xnames) thy = |
190 |
(case assoc_string (kinds, kind) of |
|
191 |
SOME (intern, check, hide) => |
|
8885 | 192 |
let |
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16372
diff
changeset
|
193 |
val names = if int then map (intern thy) xnames else xnames; |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16372
diff
changeset
|
194 |
val bads = filter_out (check thy) names; |
8885 | 195 |
in |
16372 | 196 |
if null bads then hide true names thy |
8885 | 197 |
else error ("Attempt to hide undeclared item(s): " ^ commas_quote bads) |
198 |
end |
|
15531 | 199 |
| NONE => error ("Bad name space specification: " ^ quote kind)); |
8885 | 200 |
|
201 |
in |
|
202 |
||
16372 | 203 |
val hide_names = gen_hide true; |
204 |
val hide_names_i = gen_hide false; |
|
8885 | 205 |
|
206 |
end; |
|
8724 | 207 |
|
208 |
||
5830 | 209 |
(* axioms and defs *) |
210 |
||
5915 | 211 |
fun add_axms f args thy = |
212 |
f (map (fn (x, srcs) => (x, map (Attrib.global_attribute thy) srcs)) args) thy; |
|
213 |
||
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
214 |
val add_axioms = add_axms (#1 oo PureThy.add_axioms); |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
215 |
val add_axioms_i = #1 oo PureThy.add_axioms_i; |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
216 |
fun add_defs (x, args) = add_axms (#1 oo PureThy.add_defs x) args; |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
217 |
fun add_defs_i (x, args) = (#1 oo PureThy.add_defs_i x) args; |
6371 | 218 |
|
219 |
||
12713
c9e3e34dbc45
clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents:
12705
diff
changeset
|
220 |
(* attributes *) |
c9e3e34dbc45
clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents:
12705
diff
changeset
|
221 |
|
c9e3e34dbc45
clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents:
12705
diff
changeset
|
222 |
local |
c9e3e34dbc45
clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents:
12705
diff
changeset
|
223 |
|
c9e3e34dbc45
clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents:
12705
diff
changeset
|
224 |
fun prep_attribs f = map (fn ((name, more_srcs), th_srcs) => |
c9e3e34dbc45
clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents:
12705
diff
changeset
|
225 |
((name, map f more_srcs), map (apsnd (map f)) th_srcs)); |
c9e3e34dbc45
clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents:
12705
diff
changeset
|
226 |
|
c9e3e34dbc45
clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents:
12705
diff
changeset
|
227 |
in |
c9e3e34dbc45
clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents:
12705
diff
changeset
|
228 |
|
c9e3e34dbc45
clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents:
12705
diff
changeset
|
229 |
fun global_attribs thy = prep_attribs (Attrib.global_attribute thy); |
c9e3e34dbc45
clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents:
12705
diff
changeset
|
230 |
fun local_attribs thy = prep_attribs (Attrib.local_attribute thy); |
c9e3e34dbc45
clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents:
12705
diff
changeset
|
231 |
|
c9e3e34dbc45
clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents:
12705
diff
changeset
|
232 |
end; |
c9e3e34dbc45
clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents:
12705
diff
changeset
|
233 |
|
c9e3e34dbc45
clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents:
12705
diff
changeset
|
234 |
|
5915 | 235 |
(* theorems *) |
236 |
||
12705 | 237 |
local |
238 |
||
12713
c9e3e34dbc45
clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents:
12705
diff
changeset
|
239 |
fun present_thmss kind (thy, named_thmss) = |
13529 | 240 |
(conditional (kind <> "" andalso kind <> Drule.internalK) (fn () => |
15531 | 241 |
Context.setmp (SOME thy) (Present.results (kind ^ "s")) named_thmss); |
13529 | 242 |
(thy, named_thmss)); |
5915 | 243 |
|
12705 | 244 |
in |
245 |
||
14564 | 246 |
fun theorems_i k = present_thmss k oo PureThy.note_thmss_i (Drule.kind k); |
247 |
fun locale_theorems_i k loc = present_thmss k oo Locale.note_thmss_i k loc; |
|
5915 | 248 |
|
12713
c9e3e34dbc45
clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents:
12705
diff
changeset
|
249 |
fun theorems k args thy = thy |
14564 | 250 |
|> PureThy.note_thmss (Drule.kind k) (global_attribs thy args) |
12713
c9e3e34dbc45
clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents:
12705
diff
changeset
|
251 |
|> present_thmss k; |
c9e3e34dbc45
clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents:
12705
diff
changeset
|
252 |
|
c9e3e34dbc45
clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents:
12705
diff
changeset
|
253 |
fun locale_theorems k loc args thy = thy |
15703 | 254 |
|> Locale.note_thmss k loc args |
12713
c9e3e34dbc45
clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents:
12705
diff
changeset
|
255 |
|> present_thmss k; |
6371 | 256 |
|
12713
c9e3e34dbc45
clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents:
12705
diff
changeset
|
257 |
fun smart_theorems k opt_loc args thy = thy |
c9e3e34dbc45
clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents:
12705
diff
changeset
|
258 |
|> (case opt_loc of |
15531 | 259 |
NONE => PureThy.note_thmss (Drule.kind k) (global_attribs thy args) |
15703 | 260 |
| SOME loc => Locale.note_thmss k loc args) |
12713
c9e3e34dbc45
clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents:
12705
diff
changeset
|
261 |
|> present_thmss k; |
9590 | 262 |
|
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
263 |
fun declare_theorems opt_loc args = #1 o smart_theorems "" opt_loc [(("", []), args)]; |
9590 | 264 |
|
15570 | 265 |
fun apply_theorems args = apsnd (List.concat o map snd) o theorems "" [(("", []), args)]; |
266 |
fun apply_theorems_i args = apsnd (List.concat o map snd) o theorems_i "" [(("", []), args)]; |
|
6371 | 267 |
|
12705 | 268 |
end; |
269 |
||
5915 | 270 |
|
12713
c9e3e34dbc45
clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents:
12705
diff
changeset
|
271 |
(* facts and forward chaining *) |
6371 | 272 |
|
12713
c9e3e34dbc45
clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents:
12705
diff
changeset
|
273 |
fun local_thmss f args state = f (local_attribs (Proof.theory_of state) args) state; |
c9e3e34dbc45
clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents:
12705
diff
changeset
|
274 |
fun local_thmss_i f args = f (map (fn ((name, more_atts), th_atts) => |
c9e3e34dbc45
clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents:
12705
diff
changeset
|
275 |
((name, more_atts), map (apfst single) th_atts)) args); |
6371 | 276 |
|
12713
c9e3e34dbc45
clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents:
12705
diff
changeset
|
277 |
fun chain_thmss f args = ProofHistory.apply (Proof.chain o f (map (pair ("", [])) args)); |
6879 | 278 |
|
14564 | 279 |
val have_facts = ProofHistory.apply o local_thmss Proof.note_thmss; |
280 |
val have_facts_i = ProofHistory.apply o local_thmss_i Proof.note_thmss_i; |
|
281 |
val from_facts = chain_thmss (local_thmss Proof.note_thmss); |
|
282 |
val from_facts_i = chain_thmss (local_thmss_i Proof.note_thmss_i); |
|
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
283 |
val with_facts = chain_thmss (local_thmss Proof.with_thmss); |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
284 |
val with_facts_i = chain_thmss (local_thmss_i Proof.with_thmss_i); |
12929 | 285 |
|
286 |
fun using_facts args = ProofHistory.apply (fn state => |
|
287 |
Proof.using_thmss (map (map (apsnd (map |
|
288 |
(Attrib.local_attribute (Proof.theory_of state))))) args) state); |
|
289 |
||
290 |
val using_facts_i = ProofHistory.apply o Proof.using_thmss_i o map (map (apfst single)); |
|
291 |
||
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
292 |
val chain = ProofHistory.apply Proof.chain; |
5830 | 293 |
|
14649
8ad41d25c152
removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents:
14598
diff
changeset
|
294 |
|
5830 | 295 |
(* context *) |
296 |
||
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
297 |
val fix = ProofHistory.apply o Proof.fix; |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
298 |
val fix_i = ProofHistory.apply o Proof.fix_i; |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
299 |
val let_bind = ProofHistory.apply o Proof.let_bind; |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
300 |
val let_bind_i = ProofHistory.apply o Proof.let_bind_i; |
8450 | 301 |
|
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
302 |
fun invoke_case (name, xs, src) = ProofHistory.apply (fn state => |
14649
8ad41d25c152
removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents:
14598
diff
changeset
|
303 |
Proof.invoke_case (name, xs, |
8ad41d25c152
removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents:
14598
diff
changeset
|
304 |
map (Attrib.local_attribute (Proof.theory_of state)) src) state); |
8ad41d25c152
removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents:
14598
diff
changeset
|
305 |
|
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
306 |
val invoke_case_i = ProofHistory.apply o Proof.invoke_case; |
5830 | 307 |
|
308 |
||
10935 | 309 |
(* local results *) |
310 |
||
311 |
local |
|
312 |
||
12244 | 313 |
fun prt_facts ctxt = |
15570 | 314 |
List.concat o (separate [Pretty.fbrk, Pretty.str "and "]) o |
13276 | 315 |
map (single o ProofContext.pretty_fact ctxt); |
12244 | 316 |
|
317 |
fun pretty_results ctxt ((kind, ""), facts) = |
|
318 |
Pretty.block (Pretty.str kind :: Pretty.brk 1 :: prt_facts ctxt facts) |
|
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16372
diff
changeset
|
319 |
| pretty_results ctxt ((kind, name), [fact]) = Pretty.blk (1, |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16372
diff
changeset
|
320 |
[Pretty.str (kind ^ " " ^ name ^ ":"), Pretty.fbrk, ProofContext.pretty_fact ctxt fact]) |
12244 | 321 |
| pretty_results ctxt ((kind, name), facts) = Pretty.blk (1, |
322 |
[Pretty.str (kind ^ " " ^ name ^ ":"), Pretty.fbrk, |
|
323 |
Pretty.blk (1, Pretty.str "(" :: prt_facts ctxt facts @ [Pretty.str ")"])]); |
|
10935 | 324 |
|
12055 | 325 |
fun pretty_rule s ctxt thm = |
10935 | 326 |
Pretty.block [Pretty.str (s ^ " to solve goal by exported rule:"), |
12055 | 327 |
Pretty.fbrk, ProofContext.pretty_thm ctxt thm]; |
10935 | 328 |
|
329 |
in |
|
330 |
||
12244 | 331 |
val print_result = Pretty.writeln oo pretty_results; |
332 |
fun print_result' ctxt (k, res) = print_result ctxt ((k, ""), res); |
|
10935 | 333 |
|
16529 | 334 |
fun cond_print_result_rule true = |
335 |
(print_result', priority oo (Pretty.string_of oo pretty_rule "Successful attempt")) |
|
336 |
| cond_print_result_rule false = (K (K ()), K (K ())); |
|
10935 | 337 |
|
338 |
fun proof'' f = Toplevel.proof' (f o cond_print_result_rule); |
|
339 |
||
340 |
fun check_goal false state = state |
|
341 |
| check_goal true state = |
|
342 |
let |
|
15531 | 343 |
val rule = ref (NONE: thm option); |
13529 | 344 |
fun fail exn = |
10935 | 345 |
(["Problem! Local statement will fail to solve any pending goal"] @ |
15531 | 346 |
(case exn of NONE => [] | SOME e => [Toplevel.exn_message e]) @ |
347 |
(case ! rule of NONE => [] | SOME thm => |
|
12055 | 348 |
[Pretty.string_of (pretty_rule "Failed attempt" (Proof.context_of state) thm)])) |
13529 | 349 |
|> cat_lines |> error; |
10935 | 350 |
val check = |
12055 | 351 |
(fn () => Seq.pull (SkipProof.local_skip_proof (K (K ()), |
15531 | 352 |
fn _ => fn thm => rule := SOME thm) true state)) |
14836 | 353 |
|> setmp proofs 0 |
354 |
|> transform_error; |
|
15531 | 355 |
val result = (check (), NONE) handle Interrupt => raise Interrupt | e => (NONE, SOME e); |
356 |
in (case result of (SOME _, NONE) => () | (_, exn) => fail exn); state end; |
|
12244 | 357 |
|
10935 | 358 |
end; |
359 |
||
360 |
||
5830 | 361 |
(* statements *) |
362 |
||
7271 | 363 |
local |
364 |
||
12141 | 365 |
fun global_attributes thy ((name, src), s) = ((name, map (Attrib.global_attribute thy) src), s); |
12697 | 366 |
fun local_attributes thy ((name, src), s) = ((name, map (Attrib.local_attribute thy) src), s); |
367 |
fun local_attributes' state = local_attributes (Proof.theory_of state); |
|
6371 | 368 |
|
12141 | 369 |
fun global_statement f args int thy = |
370 |
ProofHistory.init (Toplevel.undo_limit int) (f (map (global_attributes thy) args) thy); |
|
371 |
fun global_statement_i f args int thy = ProofHistory.init (Toplevel.undo_limit int) (f args thy); |
|
10935 | 372 |
|
12141 | 373 |
fun local_statement' f g args int = ProofHistory.apply (fn state => |
12697 | 374 |
f (map (local_attributes' state) args) int (g state)); |
12141 | 375 |
fun local_statement_i' f g args int = ProofHistory.apply (f args int o g); |
376 |
fun local_statement f g args = local_statement' (K o f) g args (); |
|
377 |
fun local_statement_i f g args = local_statement_i' (K o f) g args (); |
|
7271 | 378 |
|
12701
77ac6d8451ea
export multi_theorem(_i), locale_multi_theorem(_i);
wenzelm
parents:
12697
diff
changeset
|
379 |
in |
77ac6d8451ea
export multi_theorem(_i), locale_multi_theorem(_i);
wenzelm
parents:
12697
diff
changeset
|
380 |
|
15703 | 381 |
fun multi_theorem k after_qed export a elems concl int thy = |
382 |
global_statement (Proof.multi_theorem k after_qed export NONE |
|
383 |
(apsnd (map (Attrib.global_attribute thy)) a) |
|
384 |
(map (Locale.intern_attrib_elem_expr thy) elems)) concl int thy; |
|
12697 | 385 |
|
15703 | 386 |
fun multi_theorem_i k after_qed export a = |
387 |
global_statement_i o Proof.multi_theorem_i k after_qed export NONE a; |
|
12697 | 388 |
|
12957 | 389 |
fun locale_multi_theorem k locale (name, atts) elems concl int thy = |
15703 | 390 |
global_statement (Proof.multi_theorem k I ProofContext.export_standard |
391 |
(SOME (locale, |
|
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16372
diff
changeset
|
392 |
(map (Attrib.intern_src thy) atts, |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16372
diff
changeset
|
393 |
map (map (Attrib.intern_src thy) o snd o fst) concl))) |
15703 | 394 |
(name, []) |
395 |
(map (Locale.intern_attrib_elem_expr thy) elems)) |
|
396 |
(map (apfst (apsnd (K []))) concl) int thy; |
|
12697 | 397 |
|
12957 | 398 |
fun locale_multi_theorem_i k locale (name, atts) elems concl = |
15696 | 399 |
global_statement_i (Proof.multi_theorem_i k I ProofContext.export_standard |
400 |
(SOME (locale, (atts, map (snd o fst) concl))) |
|
12957 | 401 |
(name, []) elems) (map (apfst (apsnd (K []))) concl); |
12697 | 402 |
|
15703 | 403 |
fun theorem k (a, t) = |
404 |
multi_theorem k I ProofContext.export_standard a [] [(("", []), [t])]; |
|
405 |
||
406 |
fun theorem_i k (a, t) = |
|
407 |
multi_theorem_i k I ProofContext.export_standard a [] [(("", []), [t])]; |
|
11742 | 408 |
|
15696 | 409 |
fun smart_multi_theorem k NONE a elems = |
410 |
multi_theorem k I ProofContext.export_standard a elems |
|
411 |
| smart_multi_theorem k (SOME locale) a elems = |
|
412 |
locale_multi_theorem k locale a elems; |
|
11742 | 413 |
|
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
414 |
val assume = local_statement Proof.assume I; |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
415 |
val assume_i = local_statement_i Proof.assume_i I; |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
416 |
val presume = local_statement Proof.presume I; |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
417 |
val presume_i = local_statement_i Proof.presume_i I; |
12969 | 418 |
val have = local_statement (Proof.have Seq.single true) I; |
419 |
val have_i = local_statement_i (Proof.have_i Seq.single true) I; |
|
420 |
val hence = local_statement (Proof.have Seq.single true) Proof.chain; |
|
421 |
val hence_i = local_statement_i (Proof.have_i Seq.single true) Proof.chain; |
|
422 |
val show = local_statement' (Proof.show check_goal Seq.single true) I; |
|
423 |
val show_i = local_statement_i' (Proof.show_i check_goal Seq.single true) I; |
|
424 |
val thus = local_statement' (Proof.show check_goal Seq.single true) Proof.chain; |
|
425 |
val thus_i = local_statement_i' (Proof.show_i check_goal Seq.single true) Proof.chain; |
|
12141 | 426 |
|
427 |
fun gen_def f ((name, srcs), def) = ProofHistory.apply (fn state => |
|
428 |
f name (map (Attrib.local_attribute (Proof.theory_of state)) srcs) def state); |
|
429 |
||
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
430 |
val local_def = gen_def Proof.def; |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
431 |
val local_def_i = gen_def Proof.def_i; |
5830 | 432 |
|
12969 | 433 |
fun obtain (xs, asms) = proof'' (ProofHistory.applys o (fn print => fn state => |
434 |
Obtain.obtain xs (map (local_attributes' state) asms) print state)); |
|
11890 | 435 |
|
12969 | 436 |
fun obtain_i (xs, asms) = proof'' (ProofHistory.applys o Obtain.obtain_i xs asms); |
11890 | 437 |
|
7271 | 438 |
end; |
439 |
||
5830 | 440 |
|
441 |
(* blocks *) |
|
442 |
||
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
443 |
val begin_block = ProofHistory.apply Proof.begin_block; |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
444 |
val next_block = ProofHistory.apply Proof.next_block; |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
445 |
val end_block = ProofHistory.applys Proof.end_block; |
5830 | 446 |
|
447 |
||
8165 | 448 |
(* shuffle state *) |
449 |
||
8236 | 450 |
fun shuffle meth i = Method.refine (Method.Basic (K (meth i))) o Proof.assert_no_chain; |
8204 | 451 |
|
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
452 |
fun defer i = ProofHistory.applys (shuffle Method.defer i); |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
453 |
fun prefer i = ProofHistory.applys (shuffle Method.prefer i); |
8165 | 454 |
|
455 |
||
5830 | 456 |
(* backward steps *) |
457 |
||
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
458 |
fun apply m = ProofHistory.applys |
8881 | 459 |
(Seq.map (Proof.goal_facts (K [])) o Method.refine m o Proof.assert_backward); |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
460 |
fun apply_end m = ProofHistory.applys (Method.refine_end m o Proof.assert_forward); |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
461 |
val proof = ProofHistory.applys o Method.proof; |
6404 | 462 |
|
463 |
||
464 |
(* local endings *) |
|
465 |
||
16605
4590c1f79050
added print_mode three_buffersN and corresponding cond_print;
wenzelm
parents:
16529
diff
changeset
|
466 |
val three_buffersN = "three_buffers"; |
4590c1f79050
added print_mode three_buffersN and corresponding cond_print;
wenzelm
parents:
16529
diff
changeset
|
467 |
val cond_print = Toplevel.print' three_buffersN; |
4590c1f79050
added print_mode three_buffersN and corresponding cond_print;
wenzelm
parents:
16529
diff
changeset
|
468 |
|
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
469 |
val local_qed = proof'' o (ProofHistory.applys oo Method.local_qed true); |
15237
250e9be7a09d
Some changes to allow skipping of proof scripts.
berghofe
parents:
15206
diff
changeset
|
470 |
val skip_local_qed = |
250e9be7a09d
Some changes to allow skipping of proof scripts.
berghofe
parents:
15206
diff
changeset
|
471 |
Toplevel.skip_proof (History.apply (fn i => if i > 1 then i - 1 else raise Toplevel.UNDEF)); |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
472 |
val local_terminal_proof = proof'' o (ProofHistory.applys oo Method.local_terminal_proof); |
8966 | 473 |
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
|
474 |
val local_immediate_proof = proof'' (ProofHistory.applys o Method.local_immediate_proof); |
8966 | 475 |
val local_done_proof = proof'' (ProofHistory.applys o Method.local_done_proof); |
12318
72348ff7d4a0
skip_proof: do not require quick_and_dirty in interactive mode;
wenzelm
parents:
12271
diff
changeset
|
476 |
val local_skip_proof = Toplevel.proof' (fn int => |
72348ff7d4a0
skip_proof: do not require quick_and_dirty in interactive mode;
wenzelm
parents:
12271
diff
changeset
|
477 |
ProofHistory.applys (SkipProof.local_skip_proof (cond_print_result_rule int) int)); |
6404 | 478 |
|
479 |
||
480 |
(* global endings *) |
|
481 |
||
16143
ee6f7e6fc196
improved naming of complex theorems in presentation;
wenzelm
parents:
15979
diff
changeset
|
482 |
fun name_results "" res = res |
ee6f7e6fc196
improved naming of complex theorems in presentation;
wenzelm
parents:
15979
diff
changeset
|
483 |
| name_results name res = |
ee6f7e6fc196
improved naming of complex theorems in presentation;
wenzelm
parents:
15979
diff
changeset
|
484 |
let |
ee6f7e6fc196
improved naming of complex theorems in presentation;
wenzelm
parents:
15979
diff
changeset
|
485 |
val n = length (List.concat (map #2 res)); |
ee6f7e6fc196
improved naming of complex theorems in presentation;
wenzelm
parents:
15979
diff
changeset
|
486 |
fun name_res (i, (a, ths)) = |
ee6f7e6fc196
improved naming of complex theorems in presentation;
wenzelm
parents:
15979
diff
changeset
|
487 |
let |
ee6f7e6fc196
improved naming of complex theorems in presentation;
wenzelm
parents:
15979
diff
changeset
|
488 |
val m = length ths; |
ee6f7e6fc196
improved naming of complex theorems in presentation;
wenzelm
parents:
15979
diff
changeset
|
489 |
val j = i + m; |
ee6f7e6fc196
improved naming of complex theorems in presentation;
wenzelm
parents:
15979
diff
changeset
|
490 |
in |
ee6f7e6fc196
improved naming of complex theorems in presentation;
wenzelm
parents:
15979
diff
changeset
|
491 |
if a <> "" then (j, (a, ths)) |
ee6f7e6fc196
improved naming of complex theorems in presentation;
wenzelm
parents:
15979
diff
changeset
|
492 |
else if m = n then (j, (name, ths)) |
ee6f7e6fc196
improved naming of complex theorems in presentation;
wenzelm
parents:
15979
diff
changeset
|
493 |
else if m = 1 then |
16498 | 494 |
(j, (PureThy.string_of_thmref (NameSelection (name, [Single i])), ths)) |
495 |
else (j, (PureThy.string_of_thmref (NameSelection (name, [FromTo (i, j - 1)])), ths)) |
|
16143
ee6f7e6fc196
improved naming of complex theorems in presentation;
wenzelm
parents:
15979
diff
changeset
|
496 |
end; |
ee6f7e6fc196
improved naming of complex theorems in presentation;
wenzelm
parents:
15979
diff
changeset
|
497 |
in #2 (foldl_map name_res (1, res)) end; |
ee6f7e6fc196
improved naming of complex theorems in presentation;
wenzelm
parents:
15979
diff
changeset
|
498 |
|
12318
72348ff7d4a0
skip_proof: do not require quick_and_dirty in interactive mode;
wenzelm
parents:
12271
diff
changeset
|
499 |
fun global_result finish = Toplevel.proof_to_theory' (fn int => fn prf => |
6404 | 500 |
let |
501 |
val state = ProofHistory.current prf; |
|
502 |
val _ = if Proof.at_bottom state then () else raise Toplevel.UNDEF; |
|
12318
72348ff7d4a0
skip_proof: do not require quick_and_dirty in interactive mode;
wenzelm
parents:
12271
diff
changeset
|
503 |
val (thy, ((kind, name), res)) = finish int state; |
11742 | 504 |
in |
505 |
if kind = "" orelse kind = Drule.internalK then () |
|
12244 | 506 |
else (print_result (Proof.context_of state) ((kind, name), res); |
16143
ee6f7e6fc196
improved naming of complex theorems in presentation;
wenzelm
parents:
15979
diff
changeset
|
507 |
Context.setmp (SOME thy) (Present.results kind) (name_results name res)); |
11742 | 508 |
thy |
509 |
end); |
|
6404 | 510 |
|
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
511 |
fun global_qed m = global_result (K (Method.global_qed true m)); |
15237
250e9be7a09d
Some changes to allow skipping of proof scripts.
berghofe
parents:
15206
diff
changeset
|
512 |
val skip_global_qed = Toplevel.skip_proof_to_theory (equal 1 o History.current); |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
513 |
fun global_terminal_proof m = global_result (K (Method.global_terminal_proof m)); |
12318
72348ff7d4a0
skip_proof: do not require quick_and_dirty in interactive mode;
wenzelm
parents:
12271
diff
changeset
|
514 |
val global_default_proof = global_result (K Method.global_default_proof); |
72348ff7d4a0
skip_proof: do not require quick_and_dirty in interactive mode;
wenzelm
parents:
12271
diff
changeset
|
515 |
val global_immediate_proof = global_result (K Method.global_immediate_proof); |
6888
d0c68ebdabc5
skip_proof feature 'sorry' (for quick_and_dirty mode only);
wenzelm
parents:
6885
diff
changeset
|
516 |
val global_skip_proof = global_result SkipProof.global_skip_proof; |
12318
72348ff7d4a0
skip_proof: do not require quick_and_dirty in interactive mode;
wenzelm
parents:
12271
diff
changeset
|
517 |
val global_done_proof = global_result (K Method.global_done_proof); |
6404 | 518 |
|
519 |
||
520 |
(* common endings *) |
|
521 |
||
15237
250e9be7a09d
Some changes to allow skipping of proof scripts.
berghofe
parents:
15206
diff
changeset
|
522 |
fun qed meth = local_qed meth o global_qed meth o skip_local_qed o skip_global_qed; |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
523 |
fun terminal_proof meths = local_terminal_proof meths o global_terminal_proof meths; |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
524 |
val default_proof = local_default_proof o global_default_proof; |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
525 |
val immediate_proof = local_immediate_proof o global_immediate_proof; |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
526 |
val done_proof = local_done_proof o global_done_proof; |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
527 |
val skip_proof = local_skip_proof o global_skip_proof; |
15237
250e9be7a09d
Some changes to allow skipping of proof scripts.
berghofe
parents:
15206
diff
changeset
|
528 |
val forget_proof = Toplevel.proof_to_theory (Proof.theory_of o ProofHistory.current) o |
250e9be7a09d
Some changes to allow skipping of proof scripts.
berghofe
parents:
15206
diff
changeset
|
529 |
Toplevel.skip_proof_to_theory (K true); |
8210 | 530 |
|
5830 | 531 |
|
6774 | 532 |
(* calculational proof commands *) |
533 |
||
6879 | 534 |
local |
535 |
||
12055 | 536 |
fun cond_print_calc int ctxt thms = |
537 |
if int then |
|
538 |
Pretty.writeln (Pretty.big_list "calculation:" (map (ProofContext.pretty_thm ctxt) thms)) |
|
6774 | 539 |
else (); |
540 |
||
541 |
fun proof''' f = Toplevel.proof' (f o cond_print_calc); |
|
542 |
||
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
543 |
fun gen_calc get f args prt state = |
15570 | 544 |
f (Option.map (fn srcs => get srcs state) args) prt state; |
6879 | 545 |
|
546 |
in |
|
547 |
||
14564 | 548 |
fun get_thmss srcs = Proof.the_facts o local_thmss Proof.note_thmss [(("", []), srcs)]; |
7012 | 549 |
fun get_thmss_i thms _ = thms; |
550 |
||
6879 | 551 |
fun also x = proof''' (ProofHistory.applys o gen_calc get_thmss Calculation.also x); |
552 |
fun also_i x = proof''' (ProofHistory.applys o gen_calc get_thmss_i Calculation.also x); |
|
553 |
fun finally x = proof''' (ProofHistory.applys o gen_calc get_thmss Calculation.finally x); |
|
554 |
fun finally_i x = proof''' (ProofHistory.applys o gen_calc get_thmss_i Calculation.finally x); |
|
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
555 |
val moreover = proof''' (ProofHistory.apply o Calculation.moreover); |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
556 |
val ultimately = proof''' (ProofHistory.apply o Calculation.ultimately); |
6879 | 557 |
|
558 |
end; |
|
6774 | 559 |
|
560 |
||
5830 | 561 |
(* translation functions *) |
562 |
||
14649
8ad41d25c152
removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents:
14598
diff
changeset
|
563 |
fun advancedT false = "" |
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16372
diff
changeset
|
564 |
| advancedT true = "theory -> "; |
5830 | 565 |
|
14649
8ad41d25c152
removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents:
14598
diff
changeset
|
566 |
fun advancedN false = "" |
8ad41d25c152
removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents:
14598
diff
changeset
|
567 |
| advancedN true = "advanced_"; |
8ad41d25c152
removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents:
14598
diff
changeset
|
568 |
|
8ad41d25c152
removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents:
14598
diff
changeset
|
569 |
fun parse_ast_translation (a, txt) = |
8ad41d25c152
removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents:
14598
diff
changeset
|
570 |
txt |> Context.use_let ("val parse_ast_translation: (string * (" ^ advancedT a ^ |
8ad41d25c152
removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents:
14598
diff
changeset
|
571 |
"Syntax.ast list -> Syntax.ast)) list") |
8ad41d25c152
removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents:
14598
diff
changeset
|
572 |
("Theory.add_" ^ advancedN a ^ "trfuns (parse_ast_translation, [], [], [])"); |
5830 | 573 |
|
14649
8ad41d25c152
removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents:
14598
diff
changeset
|
574 |
fun parse_translation (a, txt) = |
8ad41d25c152
removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents:
14598
diff
changeset
|
575 |
txt |> Context.use_let ("val parse_translation: (string * (" ^ advancedT a ^ |
8ad41d25c152
removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents:
14598
diff
changeset
|
576 |
"term list -> term)) list") |
8ad41d25c152
removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents:
14598
diff
changeset
|
577 |
("Theory.add_" ^ advancedN a ^ "trfuns ([], parse_translation, [], [])"); |
8ad41d25c152
removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents:
14598
diff
changeset
|
578 |
|
8ad41d25c152
removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents:
14598
diff
changeset
|
579 |
fun print_translation (a, txt) = |
8ad41d25c152
removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents:
14598
diff
changeset
|
580 |
txt |> Context.use_let ("val print_translation: (string * (" ^ advancedT a ^ |
8ad41d25c152
removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents:
14598
diff
changeset
|
581 |
"term list -> term)) list") |
8ad41d25c152
removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents:
14598
diff
changeset
|
582 |
("Theory.add_" ^ advancedN a ^ "trfuns ([], [], print_translation, [])"); |
5830 | 583 |
|
14649
8ad41d25c152
removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents:
14598
diff
changeset
|
584 |
fun print_ast_translation (a, txt) = |
8ad41d25c152
removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents:
14598
diff
changeset
|
585 |
txt |> Context.use_let ("val print_ast_translation: (string * (" ^ advancedT a ^ |
8ad41d25c152
removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents:
14598
diff
changeset
|
586 |
"Syntax.ast list -> Syntax.ast)) list") |
8ad41d25c152
removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents:
14598
diff
changeset
|
587 |
("Theory.add_" ^ advancedN a ^ "trfuns ([], [], [], print_ast_translation)"); |
5830 | 588 |
|
14649
8ad41d25c152
removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents:
14598
diff
changeset
|
589 |
fun typed_print_translation (a, txt) = |
8ad41d25c152
removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents:
14598
diff
changeset
|
590 |
txt |> Context.use_let ("val typed_print_translation: (string * (" ^ advancedT a ^ |
8ad41d25c152
removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents:
14598
diff
changeset
|
591 |
"bool -> typ -> term list -> term)) list") |
8ad41d25c152
removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents:
14598
diff
changeset
|
592 |
("Theory.add_" ^ advancedN a ^ "trfunsT typed_print_translation"); |
5830 | 593 |
|
594 |
val token_translation = |
|
11717
d808005e6e08
Fixed erroneous type constraint in token_translation function.
berghofe
parents:
11048
diff
changeset
|
595 |
Context.use_let "val token_translation: (string * string * (string -> string * real)) list" |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
596 |
"Theory.add_tokentrfuns token_translation"; |
5830 | 597 |
|
598 |
||
15801 | 599 |
(* generic_setup *) |
600 |
||
601 |
val generic_setup = |
|
602 |
Context.use_let "val setup: (theory -> theory) list" "Library.apply setup"; |
|
603 |
||
604 |
||
605 |
(* method_setup *) |
|
9193
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
606 |
|
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
607 |
fun method_setup (name, txt, cmt) = |
9193
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
608 |
Context.use_let |
16498 | 609 |
"val thm = PureThy.get_thm_closure (Context.the_context ()) o PureThy.Name;\n\ |
610 |
\val thms = PureThy.get_thms_closure (Context.the_context ()) o PureThy.Name;\n\ |
|
15703 | 611 |
\val method: bstring * (Method.src -> Proof.context -> Proof.method) * string" |
15829 | 612 |
"Method.add_method method" |
14598
7009f59711e3
Replaced quote by Library.quote, since quote now refers to Symbol.quote
berghofe
parents:
14564
diff
changeset
|
613 |
("(" ^ Library.quote name ^ ", " ^ txt ^ ", " ^ Library.quote cmt ^ ")"); |
9193
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
614 |
|
4f4936582889
have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents:
9032
diff
changeset
|
615 |
|
5830 | 616 |
(* add_oracle *) |
617 |
||
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12848
diff
changeset
|
618 |
fun add_oracle (name, txt) = |
8349
611342539639
moved use_mltext, use_mltext_theory, use_let, use_setup to context.ML;
wenzelm
parents:
8236
diff
changeset
|
619 |
Context.use_let |
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16372
diff
changeset
|
620 |
"val oracle: bstring * (theory * Object.T -> term)" |
5830 | 621 |
"Theory.add_oracle oracle" |
14598
7009f59711e3
Replaced quote by Library.quote, since quote now refers to Symbol.quote
berghofe
parents:
14564
diff
changeset
|
622 |
("(" ^ Library.quote name ^ ", " ^ txt ^ ")"); |
5830 | 623 |
|
624 |
||
12062 | 625 |
(* add_locale *) |
626 |
||
13393 | 627 |
fun add_locale (do_pred, name, import, body) thy = |
15703 | 628 |
Locale.add_locale do_pred name import body thy; |
629 |
||
630 |
||
631 |
(* registration of locale interpretations *) |
|
632 |
||
633 |
fun register_globally (((prfx, atts), expr), insts) int thy = |
|
634 |
let |
|
635 |
val (thy', propss, activate) = |
|
636 |
Locale.prep_global_registration (prfx, atts) expr insts thy; |
|
637 |
fun witness id (thy, thm) = let |
|
638 |
val thm' = Drule.freeze_all thm; |
|
639 |
in |
|
640 |
(Locale.add_global_witness id thm' thy, thm') |
|
641 |
end; |
|
642 |
in |
|
643 |
multi_theorem_i Drule.internalK activate ProofContext.export_plain |
|
644 |
("", []) [] |
|
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16372
diff
changeset
|
645 |
(map (fn ((n, ps), props) => |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16372
diff
changeset
|
646 |
((NameSpace.base n, [witness (n, map Logic.varify ps)]), |
15703 | 647 |
map (fn prop => (prop, ([], []))) props)) propss) int thy' |
648 |
end; |
|
649 |
||
16736
1e792b32abef
Preparations for interpretation of locales in locales.
ballarin
parents:
16605
diff
changeset
|
650 |
fun register_in_locale (target, expr) int thy = |
1e792b32abef
Preparations for interpretation of locales in locales.
ballarin
parents:
16605
diff
changeset
|
651 |
let |
1e792b32abef
Preparations for interpretation of locales in locales.
ballarin
parents:
16605
diff
changeset
|
652 |
val target = Locale.intern thy target; |
1e792b32abef
Preparations for interpretation of locales in locales.
ballarin
parents:
16605
diff
changeset
|
653 |
in |
1e792b32abef
Preparations for interpretation of locales in locales.
ballarin
parents:
16605
diff
changeset
|
654 |
locale_multi_theorem_i Drule.internalK target ("",[]) [] |
1e792b32abef
Preparations for interpretation of locales in locales.
ballarin
parents:
16605
diff
changeset
|
655 |
[] (*concl*) int thy |
1e792b32abef
Preparations for interpretation of locales in locales.
ballarin
parents:
16605
diff
changeset
|
656 |
end; |
1e792b32abef
Preparations for interpretation of locales in locales.
ballarin
parents:
16605
diff
changeset
|
657 |
|
15703 | 658 |
fun register_locally (((prfx, atts), expr), insts) = |
659 |
ProofHistory.apply (fn state => |
|
660 |
let |
|
661 |
val ctxt = Proof.context_of state; |
|
662 |
val (ctxt', propss, activate) = |
|
663 |
Locale.prep_local_registration (prfx, atts) expr insts ctxt; |
|
664 |
fun witness id (ctxt, thm) = (Locale.add_local_witness id thm ctxt, thm); |
|
665 |
in |
|
666 |
state |
|
667 |
|> Proof.map_context (fn _ => ctxt') |
|
668 |
|> Proof.have_i (Seq.single o Proof.map_context activate) true |
|
669 |
(map (fn (id as (n, _), props) => ((NameSpace.base n, [witness id]), |
|
670 |
map (fn prop => (prop, ([], []))) props)) propss) |
|
671 |
end); |
|
672 |
||
12062 | 673 |
|
6688 | 674 |
(* theory init and exit *) |
5830 | 675 |
|
8804 | 676 |
fun gen_begin_theory upd name parents files = |
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16372
diff
changeset
|
677 |
let |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16372
diff
changeset
|
678 |
val ml_filename = Path.pack (ThyLoad.ml_path name); |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16372
diff
changeset
|
679 |
(* FIXME unreliable test -- better make ThyInfo manage dependencies properly *) |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16372
diff
changeset
|
680 |
val _ = conditional (exists (equal ml_filename o #1) files) (fn () => |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16372
diff
changeset
|
681 |
error ((quote ml_filename) ^ " not allowed in files section for theory " ^ name)); |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16372
diff
changeset
|
682 |
in |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16372
diff
changeset
|
683 |
ThyInfo.begin_theory Present.begin_theory upd name parents |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16372
diff
changeset
|
684 |
(map (apfst Path.unpack) files) |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16372
diff
changeset
|
685 |
end; |
5830 | 686 |
|
8804 | 687 |
val begin_theory = gen_begin_theory false; |
7909 | 688 |
|
689 |
fun end_theory thy = |
|
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16372
diff
changeset
|
690 |
if ThyInfo.check_known_thy (Context.theory_name thy) then ThyInfo.end_theory thy |
7909 | 691 |
else thy; |
692 |
||
7932 | 693 |
val kill_theory = ThyInfo.if_known_thy ThyInfo.remove_thy; |
6688 | 694 |
|
7103 | 695 |
|
8804 | 696 |
fun bg_theory (name, parents, files) int = gen_begin_theory int name parents files; |
6331 | 697 |
fun en_theory thy = (end_theory thy; ()); |
698 |
||
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16372
diff
changeset
|
699 |
fun theory spec = |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16372
diff
changeset
|
700 |
Toplevel.init_theory (bg_theory spec) en_theory (kill_theory o Context.theory_name); |
6246 | 701 |
|
702 |
||
703 |
(* context switch *) |
|
704 |
||
7960 | 705 |
fun fetch_context f x = |
15531 | 706 |
(case Context.pass NONE f x of |
707 |
((), NONE) => raise Toplevel.UNDEF |
|
708 |
| ((), SOME thy) => thy); |
|
7960 | 709 |
|
710 |
fun init_context f x = Toplevel.init_theory (fn _ => fetch_context f x) (K ()) (K ()); |
|
7953 | 711 |
|
712 |
val context = init_context (ThyInfo.quiet_update_thy true); |
|
6246 | 713 |
|
5830 | 714 |
end; |