| author | wenzelm |
| Sat, 08 Jul 2006 12:54:28 +0200 | |
| changeset 20042 | 2308529f8e8d |
| parent 20012 | b62836400a33 |
| child 20049 | f48c4a3a34bc |
| permissions | -rw-r--r-- |
| 5819 | 1 |
(* Title: Pure/Isar/proof_context.ML |
2 |
ID: $Id$ |
|
3 |
Author: Markus Wenzel, TU Muenchen |
|
4 |
||
| 19001 | 5 |
The key concept of Isar proof contexts: elevates primitive local |
6 |
reasoning Gamma |- phi to a structured concept, with generic context |
|
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
7 |
elements. |
| 5819 | 8 |
*) |
9 |
||
10 |
signature PROOF_CONTEXT = |
|
11 |
sig |
|
| 17756 | 12 |
type context (*= Context.proof*) |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
13 |
type export |
| 5819 | 14 |
val theory_of: context -> theory |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
15 |
val init: theory -> context |
| 19387 | 16 |
val full_name: context -> bstring -> string |
| 19663 | 17 |
val consts_of: context -> Consts.T |
| 19543 | 18 |
val set_syntax_mode: string * bool -> context -> context |
19 |
val restore_syntax_mode: context -> context -> context |
|
| 17451 | 20 |
val assms_of: context -> term list |
| 7557 | 21 |
val prems_of: context -> thm list |
|
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
22 |
val fact_index_of: context -> FactIndex.T |
| 17072 | 23 |
val transfer: theory -> context -> context |
| 19019 | 24 |
val map_theory: (theory -> theory) -> context -> context |
| 14828 | 25 |
val pretty_term: context -> term -> Pretty.T |
26 |
val pretty_typ: context -> typ -> Pretty.T |
|
27 |
val pretty_sort: context -> sort -> Pretty.T |
|
| 19411 | 28 |
val pretty_classrel: context -> class list -> Pretty.T |
29 |
val pretty_arity: context -> arity -> Pretty.T |
|
| 14828 | 30 |
val pp: context -> Pretty.pp |
31 |
val pretty_thm: context -> thm -> Pretty.T |
|
32 |
val pretty_thms: context -> thm list -> Pretty.T |
|
33 |
val pretty_fact: context -> string * thm list -> Pretty.T |
|
| 17072 | 34 |
val pretty_proof: context -> Proofterm.proof -> Pretty.T |
35 |
val pretty_proof_of: context -> bool -> thm -> Pretty.T |
|
|
17360
fa1f262dbc4e
added add_view, export_view (supercedes adhoc view arguments);
wenzelm
parents:
17221
diff
changeset
|
36 |
val string_of_typ: context -> typ -> string |
| 14828 | 37 |
val string_of_term: context -> term -> string |
|
17860
b4cf247ea0d2
note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents:
17756
diff
changeset
|
38 |
val string_of_thm: context -> thm -> string |
| 5819 | 39 |
val read_typ: context -> string -> typ |
| 16348 | 40 |
val read_typ_syntax: context -> string -> typ |
41 |
val read_typ_abbrev: context -> string -> typ |
|
| 5819 | 42 |
val cert_typ: context -> typ -> typ |
| 16348 | 43 |
val cert_typ_syntax: context -> typ -> typ |
44 |
val cert_typ_abbrev: context -> typ -> typ |
|
| 10583 | 45 |
val get_skolem: context -> string -> string |
| 18255 | 46 |
val revert_skolem: context -> string -> string |
| 9133 | 47 |
val extern_skolem: context -> term -> term |
|
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
48 |
val read_termTs: context -> (string -> bool) -> (indexname -> typ option) |
|
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
49 |
-> (indexname -> sort option) -> string list -> (string * typ) list |
|
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
50 |
-> term list * (indexname * typ) list |
|
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
51 |
val read_termTs_schematic: context -> (string -> bool) -> (indexname -> typ option) |
|
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
52 |
-> (indexname -> sort option) -> string list -> (string * typ) list |
|
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
53 |
-> term list * (indexname * typ) list |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
54 |
val read_term_legacy: context -> string -> term |
| 5819 | 55 |
val read_term: context -> string -> term |
56 |
val read_prop: context -> string -> term |
|
| 11925 | 57 |
val read_prop_schematic: context -> string -> term |
| 8096 | 58 |
val read_term_pats: typ -> context -> string list -> term list |
59 |
val read_prop_pats: context -> string list -> term list |
|
| 5819 | 60 |
val cert_term: context -> term -> term |
61 |
val cert_prop: context -> term -> term |
|
| 8096 | 62 |
val cert_term_pats: typ -> context -> term list -> term list |
63 |
val cert_prop_pats: context -> term list -> term list |
|
| 18770 | 64 |
val infer_type: context -> string -> typ |
65 |
val inferred_param: string -> context -> (string * typ) * context |
|
66 |
val inferred_fixes: context -> (string * typ) list * context |
|
| 15703 | 67 |
val read_tyname: context -> string -> typ |
68 |
val read_const: context -> string -> term |
|
|
19916
3bbb9cc5d4f1
export: simultaneous facts, refer to Variable.export;
wenzelm
parents:
19897
diff
changeset
|
69 |
val goal_exports: context -> context -> thm list -> thm list Seq.seq |
|
3bbb9cc5d4f1
export: simultaneous facts, refer to Variable.export;
wenzelm
parents:
19897
diff
changeset
|
70 |
val exports: context -> context -> thm list -> thm list Seq.seq |
|
3bbb9cc5d4f1
export: simultaneous facts, refer to Variable.export;
wenzelm
parents:
19897
diff
changeset
|
71 |
val export: context -> context -> thm list -> thm list |
|
3bbb9cc5d4f1
export: simultaneous facts, refer to Variable.export;
wenzelm
parents:
19897
diff
changeset
|
72 |
val export_standard: context -> context -> thm list -> thm list |
| 10810 | 73 |
val add_binds: (indexname * string option) list -> context -> context |
74 |
val add_binds_i: (indexname * term option) list -> context -> context |
|
| 12147 | 75 |
val auto_bind_goal: term list -> context -> context |
76 |
val auto_bind_facts: term list -> context -> context |
|
| 18310 | 77 |
val match_bind: bool -> (string list * string) list -> context -> term list * context |
78 |
val match_bind_i: bool -> (term list * term) list -> context -> term list * context |
|
| 19585 | 79 |
val read_propp: context * (string * string list) list list |
80 |
-> context * (term * term list) list list |
|
81 |
val cert_propp: context * (term * term list) list list |
|
82 |
-> context * (term * term list) list list |
|
83 |
val read_propp_schematic: context * (string * string list) list list |
|
84 |
-> context * (term * term list) list list |
|
85 |
val cert_propp_schematic: context * (term * term list) list list |
|
86 |
-> context * (term * term list) list list |
|
87 |
val bind_propp: context * (string * string list) list list |
|
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
88 |
-> context * (term list list * (context -> context)) |
| 19585 | 89 |
val bind_propp_i: context * (term * term list) list list |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
90 |
-> context * (term list list * (context -> context)) |
| 19585 | 91 |
val bind_propp_schematic: context * (string * string list) list list |
| 10554 | 92 |
-> context * (term list list * (context -> context)) |
| 19585 | 93 |
val bind_propp_schematic_i: context * (term * term list) list list |
| 10554 | 94 |
-> context * (term list list * (context -> context)) |
| 18042 | 95 |
val fact_tac: thm list -> int -> tactic |
96 |
val some_fact_tac: context -> int -> tactic |
|
|
15456
956d6acacf89
Specific theorems in a named list of theorems can now be referred to
berghofe
parents:
15452
diff
changeset
|
97 |
val get_thm: context -> thmref -> thm |
|
956d6acacf89
Specific theorems in a named list of theorems can now be referred to
berghofe
parents:
15452
diff
changeset
|
98 |
val get_thm_closure: context -> thmref -> thm |
|
956d6acacf89
Specific theorems in a named list of theorems can now be referred to
berghofe
parents:
15452
diff
changeset
|
99 |
val get_thms: context -> thmref -> thm list |
|
956d6acacf89
Specific theorems in a named list of theorems can now be referred to
berghofe
parents:
15452
diff
changeset
|
100 |
val get_thms_closure: context -> thmref -> thm list |
|
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
101 |
val valid_thms: context -> string * thm list -> bool |
|
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
102 |
val lthms_containing: context -> FactIndex.spec -> (string * thm list) list |
| 19019 | 103 |
val no_base_names: context -> context |
| 16147 | 104 |
val qualified_names: context -> context |
|
19062
0fd52e819c24
replaced qualified_force_prefix to sticky_prefix;
wenzelm
parents:
19033
diff
changeset
|
105 |
val sticky_prefix: string -> context -> context |
| 16147 | 106 |
val restore_naming: context -> context -> context |
|
13425
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
107 |
val hide_thms: bool -> string list -> context -> context |
|
19079
9a7678a0736d
added put_thms_internal: local_naming, no fact index;
wenzelm
parents:
19062
diff
changeset
|
108 |
val put_thms: bool -> string * thm list option -> context -> context |
|
9a7678a0736d
added put_thms_internal: local_naming, no fact index;
wenzelm
parents:
19062
diff
changeset
|
109 |
val put_thms_internal: string * thm list option -> context -> context |
| 14564 | 110 |
val note_thmss: |
| 18728 | 111 |
((bstring * attribute list) * (thmref * attribute list) list) list -> |
|
17860
b4cf247ea0d2
note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents:
17756
diff
changeset
|
112 |
context -> (bstring * thm list) list * context |
| 14564 | 113 |
val note_thmss_i: |
| 18728 | 114 |
((bstring * attribute list) * (thm list * attribute list) list) list -> |
|
17860
b4cf247ea0d2
note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents:
17756
diff
changeset
|
115 |
context -> (bstring * thm list) list * context |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
116 |
val read_vars: (string * string option * mixfix) list -> context -> |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
117 |
(string * typ option * mixfix) list * context |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
118 |
val cert_vars: (string * typ option * mixfix) list -> context -> |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
119 |
(string * typ option * mixfix) list * context |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
120 |
val read_vars_legacy: (string * string option * mixfix) list -> context -> |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
121 |
(string * typ option * mixfix) list * context |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
122 |
val cert_vars_legacy: (string * typ option * mixfix) list -> context -> |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
123 |
(string * typ option * mixfix) list * context |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
124 |
val add_fixes: (string * string option * mixfix) list -> context -> string list * context |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
125 |
val add_fixes_i: (string * typ option * mixfix) list -> context -> string list * context |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
126 |
val add_fixes_legacy: (string * typ option * mixfix) list -> context -> string list * context |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
127 |
val fix_frees: term -> context -> context |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
128 |
val auto_fixes: context * (term list list * 'a) -> context * (term list list * 'a) |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
129 |
val bind_fixes: string list -> context -> (term -> term) * context |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
130 |
val add_assms: export -> |
| 19585 | 131 |
((string * attribute list) * (string * string list) list) list -> |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
132 |
context -> (bstring * thm list) list * context |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
133 |
val add_assms_i: export -> |
| 19585 | 134 |
((string * attribute list) * (term * term list) list) list -> |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
135 |
context -> (bstring * thm list) list * context |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
136 |
val assume_export: export |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
137 |
val presume_export: export |
|
17360
fa1f262dbc4e
added add_view, export_view (supercedes adhoc view arguments);
wenzelm
parents:
17221
diff
changeset
|
138 |
val add_view: context -> cterm list -> context -> context |
| 18042 | 139 |
val export_view: cterm list -> context -> context -> thm -> thm |
| 18609 | 140 |
val add_cases: bool -> (string * RuleCases.T option) list -> context -> context |
141 |
val apply_case: RuleCases.T -> context -> (string * term list) list * context |
|
| 16147 | 142 |
val get_case: context -> string -> string option list -> RuleCases.T |
| 19371 | 143 |
val expand_abbrevs: bool -> context -> context |
| 19663 | 144 |
val add_const_syntax: string * bool -> (string * mixfix) list -> context -> context |
| 19681 | 145 |
val add_abbrevs: string * bool -> ((bstring * mixfix) * term) list -> context -> context |
| 10810 | 146 |
val verbose: bool ref |
147 |
val setmp_verbose: ('a -> 'b) -> 'a -> 'b
|
|
|
12072
4281198fb8cd
local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents:
12066
diff
changeset
|
148 |
val print_syntax: context -> unit |
| 10810 | 149 |
val print_binds: context -> unit |
| 12057 | 150 |
val print_lthms: context -> unit |
| 10810 | 151 |
val print_cases: context -> unit |
152 |
val prems_limit: int ref |
|
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
153 |
val pretty_ctxt: context -> Pretty.T list |
| 10810 | 154 |
val pretty_context: context -> Pretty.T list |
| 18809 | 155 |
val debug: bool ref |
156 |
val pprint_context: context -> pprint_args -> unit |
|
| 5819 | 157 |
end; |
158 |
||
| 16540 | 159 |
structure ProofContext: PROOF_CONTEXT = |
| 5819 | 160 |
struct |
161 |
||
| 16540 | 162 |
type context = Context.proof; |
| 5819 | 163 |
|
| 16540 | 164 |
val theory_of = Context.theory_of_proof; |
| 19001 | 165 |
val tsig_of = Sign.tsig_of o theory_of; |
166 |
||
| 16540 | 167 |
val init = Context.init_proof; |
| 12057 | 168 |
|
| 7270 | 169 |
|
| 5819 | 170 |
|
| 16540 | 171 |
(** Isar proof context information **) |
| 5819 | 172 |
|
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
173 |
type export = bool -> cterm list -> thm -> thm Seq.seq; |
| 5819 | 174 |
|
| 16540 | 175 |
datatype ctxt = |
176 |
Ctxt of |
|
| 19001 | 177 |
{naming: NameSpace.naming, (*local naming conventions*)
|
178 |
syntax: LocalSyntax.T, (*local syntax*) |
|
|
19033
24e251657e56
consts: maintain thy version for efficient transfer;
wenzelm
parents:
19019
diff
changeset
|
179 |
consts: Consts.T * Consts.T, (*global/local consts*) |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
180 |
assms: |
| 19001 | 181 |
((cterm list * export) list * (*assumes and views: A ==> _*) |
182 |
(string * thm list) list), (*prems: A |- A*) |
|
183 |
thms: thm list NameSpace.table * FactIndex.T, (*local thms*) |
|
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
184 |
cases: (string * (RuleCases.T * bool)) list}; (*local contexts*) |
| 5819 | 185 |
|
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
186 |
fun make_ctxt (naming, syntax, consts, assms, thms, cases) = |
|
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
187 |
Ctxt {naming = naming, syntax = syntax, consts = consts, assms = assms,
|
|
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
188 |
thms = thms, cases = cases}; |
| 5819 | 189 |
|
|
19079
9a7678a0736d
added put_thms_internal: local_naming, no fact index;
wenzelm
parents:
19062
diff
changeset
|
190 |
val local_naming = NameSpace.default_naming |> NameSpace.add_path "local"; |
|
9a7678a0736d
added put_thms_internal: local_naming, no fact index;
wenzelm
parents:
19062
diff
changeset
|
191 |
|
| 16540 | 192 |
structure ContextData = ProofDataFun |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
193 |
( |
| 16540 | 194 |
val name = "Isar/context"; |
195 |
type T = ctxt; |
|
196 |
fun init thy = |
|
|
19079
9a7678a0736d
added put_thms_internal: local_naming, no fact index;
wenzelm
parents:
19062
diff
changeset
|
197 |
make_ctxt (local_naming, LocalSyntax.init thy, |
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
198 |
(Sign.consts_of thy, Sign.consts_of thy), ([], []), |
|
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
199 |
(NameSpace.empty_table, FactIndex.empty), []); |
| 16540 | 200 |
fun print _ _ = (); |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
201 |
); |
| 5819 | 202 |
|
| 18708 | 203 |
val _ = Context.add_setup ContextData.init; |
| 5819 | 204 |
|
| 16540 | 205 |
fun rep_context ctxt = ContextData.get ctxt |> (fn Ctxt args => args); |
| 5819 | 206 |
|
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
207 |
fun map_context f = |
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
208 |
ContextData.map (fn Ctxt {naming, syntax, consts, assms, thms, cases} =>
|
|
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
209 |
make_ctxt (f (naming, syntax, consts, assms, thms, cases))); |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
210 |
|
| 19001 | 211 |
fun map_naming f = |
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
212 |
map_context (fn (naming, syntax, consts, assms, thms, cases) => |
|
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
213 |
(f naming, syntax, consts, assms, thms, cases)); |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
214 |
|
| 19001 | 215 |
fun map_syntax f = |
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
216 |
map_context (fn (naming, syntax, consts, assms, thms, cases) => |
|
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
217 |
(naming, f syntax, consts, assms, thms, cases)); |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
218 |
|
| 19001 | 219 |
fun map_consts f = |
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
220 |
map_context (fn (naming, syntax, consts, assms, thms, cases) => |
|
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
221 |
(naming, syntax, f consts, assms, thms, cases)); |
| 18971 | 222 |
|
| 19001 | 223 |
fun map_assms f = |
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
224 |
map_context (fn (naming, syntax, consts, assms, thms, cases) => |
|
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
225 |
(naming, syntax, consts, f assms, thms, cases)); |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
226 |
|
| 19001 | 227 |
fun map_thms f = |
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
228 |
map_context (fn (naming, syntax, consts, assms, thms, cases) => |
|
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
229 |
(naming, syntax, consts, assms, f thms, cases)); |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
230 |
|
| 19001 | 231 |
fun map_cases f = |
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
232 |
map_context (fn (naming, syntax, consts, assms, thms, cases) => |
|
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
233 |
(naming, syntax, consts, assms, thms, f cases)); |
| 19001 | 234 |
|
235 |
val naming_of = #naming o rep_context; |
|
| 19387 | 236 |
val full_name = NameSpace.full o naming_of; |
| 5819 | 237 |
|
| 16540 | 238 |
val syntax_of = #syntax o rep_context; |
| 19001 | 239 |
val syn_of = LocalSyntax.syn_of o syntax_of; |
| 19543 | 240 |
val set_syntax_mode = map_syntax o LocalSyntax.set_mode; |
241 |
val restore_syntax_mode = map_syntax o LocalSyntax.restore_mode o syntax_of; |
|
| 19001 | 242 |
|
|
19033
24e251657e56
consts: maintain thy version for efficient transfer;
wenzelm
parents:
19019
diff
changeset
|
243 |
val consts_of = #2 o #consts o rep_context; |
| 5819 | 244 |
|
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
245 |
val assumptions_of = #1 o #assms o rep_context; |
|
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19422
diff
changeset
|
246 |
val assms_of = map Thm.term_of o maps #1 o assumptions_of; |
|
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19422
diff
changeset
|
247 |
val prems_of = maps #2 o #2 o #assms o rep_context; |
| 5819 | 248 |
|
| 16540 | 249 |
val thms_of = #thms o rep_context; |
| 19001 | 250 |
val fact_index_of = #2 o thms_of; |
| 16540 | 251 |
|
252 |
val cases_of = #cases o rep_context; |
|
| 5819 | 253 |
|
254 |
||
| 19001 | 255 |
(* transfer *) |
| 12093 | 256 |
|
| 19001 | 257 |
fun transfer_syntax thy = |
258 |
map_syntax (LocalSyntax.rebuild thy) #> |
|
|
19033
24e251657e56
consts: maintain thy version for efficient transfer;
wenzelm
parents:
19019
diff
changeset
|
259 |
map_consts (fn consts as (global_consts, local_consts) => |
|
24e251657e56
consts: maintain thy version for efficient transfer;
wenzelm
parents:
19019
diff
changeset
|
260 |
let val thy_consts = Sign.consts_of thy in |
|
24e251657e56
consts: maintain thy version for efficient transfer;
wenzelm
parents:
19019
diff
changeset
|
261 |
if Consts.eq_consts (thy_consts, global_consts) then consts |
|
24e251657e56
consts: maintain thy version for efficient transfer;
wenzelm
parents:
19019
diff
changeset
|
262 |
else (thy_consts, Consts.merge (thy_consts, local_consts)) |
|
24e251657e56
consts: maintain thy version for efficient transfer;
wenzelm
parents:
19019
diff
changeset
|
263 |
end); |
| 17072 | 264 |
|
| 19001 | 265 |
fun transfer thy = Context.transfer_proof thy #> transfer_syntax thy; |
| 17072 | 266 |
|
| 19019 | 267 |
fun map_theory f ctxt = transfer (f (theory_of ctxt)) ctxt; |
268 |
||
| 12093 | 269 |
|
270 |
||
| 14828 | 271 |
(** pretty printing **) |
272 |
||
| 19310 | 273 |
local |
274 |
||
| 19371 | 275 |
fun rewrite_term thy rews t = |
276 |
if can Term.type_of t then Pattern.rewrite_term thy rews [] t |
|
277 |
else (warning "Printing ill-typed term -- cannot expand abbreviations"; t); |
|
278 |
||
| 19001 | 279 |
fun pretty_term' abbrevs ctxt t = |
| 18971 | 280 |
let |
| 19001 | 281 |
val thy = theory_of ctxt; |
282 |
val syntax = syntax_of ctxt; |
|
| 18971 | 283 |
val consts = consts_of ctxt; |
| 19001 | 284 |
val t' = t |
| 19371 | 285 |
|> K abbrevs ? rewrite_term thy (Consts.abbrevs_of consts (! print_mode @ [""])) |
286 |
|> Sign.extern_term (Consts.extern_early consts) thy |
|
287 |
|> LocalSyntax.extern_term syntax; |
|
288 |
in |
|
289 |
Sign.pretty_term' (Context.Proof ctxt) (LocalSyntax.syn_of syntax) (Consts.extern consts) t' |
|
290 |
end; |
|
| 18971 | 291 |
|
| 19310 | 292 |
in |
293 |
||
| 19001 | 294 |
val pretty_term = pretty_term' true; |
| 19310 | 295 |
val pretty_term_no_abbrevs = pretty_term' false; |
296 |
||
297 |
end; |
|
298 |
||
| 16458 | 299 |
fun pretty_typ ctxt T = Sign.pretty_typ (theory_of ctxt) T; |
300 |
fun pretty_sort ctxt S = Sign.pretty_sort (theory_of ctxt) S; |
|
301 |
fun pretty_classrel ctxt cs = Sign.pretty_classrel (theory_of ctxt) cs; |
|
302 |
fun pretty_arity ctxt ar = Sign.pretty_arity (theory_of ctxt) ar; |
|
| 14828 | 303 |
|
|
14974
b1ecb7859c99
avoid premature evaluation of syn_of (wastes time in conjunction with pp);
wenzelm
parents:
14901
diff
changeset
|
304 |
fun pp ctxt = Pretty.pp (pretty_term ctxt, pretty_typ ctxt, pretty_sort ctxt, |
|
b1ecb7859c99
avoid premature evaluation of syn_of (wastes time in conjunction with pp);
wenzelm
parents:
14901
diff
changeset
|
305 |
pretty_classrel ctxt, pretty_arity ctxt); |
| 14828 | 306 |
|
| 17451 | 307 |
fun pretty_thm ctxt th = |
308 |
Display.pretty_thm_aux (pp ctxt) false true (assms_of ctxt) th; |
|
| 14828 | 309 |
|
310 |
fun pretty_thms ctxt [th] = pretty_thm ctxt th |
|
311 |
| pretty_thms ctxt ths = Pretty.blk (0, Pretty.fbreaks (map (pretty_thm ctxt) ths)); |
|
312 |
||
313 |
fun pretty_fact ctxt ("", ths) = pretty_thms ctxt ths
|
|
314 |
| pretty_fact ctxt (a, [th]) = |
|
315 |
Pretty.block [Pretty.str (a ^ ":"), Pretty.brk 1, pretty_thm ctxt th] |
|
316 |
| pretty_fact ctxt (a, ths) = |
|
317 |
Pretty.block (Pretty.fbreaks (Pretty.str (a ^ ":") :: map (pretty_thm ctxt) ths)); |
|
318 |
||
| 17072 | 319 |
fun pretty_proof ctxt prf = |
| 19310 | 320 |
pretty_term_no_abbrevs (ctxt |> transfer_syntax (ProofSyntax.proof_syntax prf (theory_of ctxt))) |
| 17072 | 321 |
(ProofSyntax.term_of_proof prf); |
322 |
||
323 |
fun pretty_proof_of ctxt full th = |
|
324 |
pretty_proof ctxt (ProofSyntax.proof_of full th); |
|
325 |
||
|
17860
b4cf247ea0d2
note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents:
17756
diff
changeset
|
326 |
val string_of_typ = Pretty.string_of oo pretty_typ; |
|
b4cf247ea0d2
note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents:
17756
diff
changeset
|
327 |
val string_of_term = Pretty.string_of oo pretty_term; |
|
b4cf247ea0d2
note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents:
17756
diff
changeset
|
328 |
val string_of_thm = Pretty.string_of oo pretty_thm; |
|
b4cf247ea0d2
note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents:
17756
diff
changeset
|
329 |
|
| 14828 | 330 |
|
331 |
||
| 5819 | 332 |
(** prepare types **) |
333 |
||
| 9504 | 334 |
local |
335 |
||
336 |
fun read_typ_aux read ctxt s = |
|
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
337 |
read (syn_of ctxt) (Context.Proof ctxt) (Variable.def_sort ctxt) s; |
| 5819 | 338 |
|
| 10554 | 339 |
fun cert_typ_aux cert ctxt raw_T = |
| 18678 | 340 |
cert (theory_of ctxt) raw_T handle TYPE (msg, _, _) => error msg; |
| 9504 | 341 |
|
342 |
in |
|
343 |
||
| 16348 | 344 |
val read_typ = read_typ_aux Sign.read_typ'; |
345 |
val read_typ_syntax = read_typ_aux Sign.read_typ_syntax'; |
|
346 |
val read_typ_abbrev = read_typ_aux Sign.read_typ_abbrev'; |
|
347 |
val cert_typ = cert_typ_aux Sign.certify_typ; |
|
348 |
val cert_typ_syntax = cert_typ_aux Sign.certify_typ_syntax; |
|
349 |
val cert_typ_abbrev = cert_typ_aux Sign.certify_typ_abbrev; |
|
| 9504 | 350 |
|
351 |
end; |
|
352 |
||
| 5819 | 353 |
|
| 7679 | 354 |
(* internalize Skolem constants *) |
355 |
||
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
356 |
val lookup_skolem = AList.lookup (op =) o Variable.fixes_of; |
| 18187 | 357 |
fun get_skolem ctxt x = the_default x (lookup_skolem ctxt x); |
| 7679 | 358 |
|
| 18678 | 359 |
fun no_skolem internal x = |
|
19916
3bbb9cc5d4f1
export: simultaneous facts, refer to Variable.export;
wenzelm
parents:
19897
diff
changeset
|
360 |
if can Term.dest_skolem x then |
| 18678 | 361 |
error ("Illegal reference to internal Skolem constant: " ^ quote x)
|
|
19916
3bbb9cc5d4f1
export: simultaneous facts, refer to Variable.export;
wenzelm
parents:
19897
diff
changeset
|
362 |
else if not internal andalso can Term.dest_internal x then |
| 18678 | 363 |
error ("Illegal reference to internal variable: " ^ quote x)
|
| 7679 | 364 |
else x; |
365 |
||
|
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
366 |
fun intern_skolem ctxt internal = |
| 7679 | 367 |
let |
368 |
fun intern (t as Free (x, T)) = |
|
|
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
369 |
if internal x then t |
|
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
370 |
else |
| 18678 | 371 |
(case lookup_skolem ctxt (no_skolem false x) of |
| 15531 | 372 |
SOME x' => Free (x', T) |
373 |
| NONE => t) |
|
| 7679 | 374 |
| intern (t $ u) = intern t $ intern u |
375 |
| intern (Abs (x, T, t)) = Abs (x, T, intern t) |
|
376 |
| intern a = a; |
|
377 |
in intern end; |
|
378 |
||
379 |
||
| 18187 | 380 |
(* externalize Skolem constants -- approximation only! *) |
381 |
||
| 18255 | 382 |
fun rev_skolem ctxt = |
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
383 |
let val rev_fixes = map Library.swap (Variable.fixes_of ctxt) |
| 18187 | 384 |
in AList.lookup (op =) rev_fixes end; |
| 9133 | 385 |
|
| 18255 | 386 |
fun revert_skolem ctxt x = |
387 |
(case rev_skolem ctxt x of |
|
388 |
SOME x' => x' |
|
|
19916
3bbb9cc5d4f1
export: simultaneous facts, refer to Variable.export;
wenzelm
parents:
19897
diff
changeset
|
389 |
| NONE => perhaps (try Term.dest_skolem) x); |
| 18255 | 390 |
|
| 9133 | 391 |
fun extern_skolem ctxt = |
392 |
let |
|
| 18255 | 393 |
val revert = rev_skolem ctxt; |
| 9133 | 394 |
fun extern (t as Free (x, T)) = |
| 18187 | 395 |
(case revert x of |
396 |
SOME x' => Free (if lookup_skolem ctxt x' = SOME x then x' else NameSpace.hidden x', T) |
|
397 |
| NONE => t) |
|
| 9133 | 398 |
| extern (t $ u) = extern t $ extern u |
399 |
| extern (Abs (x, T, t)) = Abs (x, T, extern t) |
|
400 |
| extern a = a; |
|
401 |
in extern end |
|
402 |
||
| 8096 | 403 |
|
| 18187 | 404 |
|
| 5819 | 405 |
(** prepare terms and propositions **) |
406 |
||
407 |
(* |
|
| 16501 | 408 |
(1) read / certify wrt. theory of context |
| 5819 | 409 |
(2) intern Skolem constants |
410 |
(3) expand term bindings |
|
411 |
*) |
|
412 |
||
413 |
||
| 16501 | 414 |
(* read wrt. theory *) (*exception ERROR*) |
| 5819 | 415 |
|
| 18857 | 416 |
fun read_def_termTs freeze pp syn ctxt (types, sorts, used) sTs = |
| 18971 | 417 |
Sign.read_def_terms' pp (Sign.is_logtype (theory_of ctxt)) syn (consts_of ctxt) |
| 18857 | 418 |
(Context.Proof ctxt) (types, sorts) used freeze sTs; |
| 5874 | 419 |
|
| 18857 | 420 |
fun read_def_termT freeze pp syn ctxt defaults sT = |
421 |
apfst hd (read_def_termTs freeze pp syn ctxt defaults [sT]); |
|
| 14828 | 422 |
|
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
423 |
fun read_term_thy freeze pp syn thy defaults s = |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
424 |
#1 (read_def_termT freeze pp syn thy defaults (s, TypeInfer.logicT)); |
| 5874 | 425 |
|
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
426 |
fun read_prop_thy freeze pp syn thy defaults s = |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
427 |
#1 (read_def_termT freeze pp syn thy defaults (s, propT)); |
|
12072
4281198fb8cd
local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents:
12066
diff
changeset
|
428 |
|
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
429 |
fun read_terms_thy freeze pp syn thy defaults = |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
430 |
#1 o read_def_termTs freeze pp syn thy defaults o map (rpair TypeInfer.logicT); |
|
12072
4281198fb8cd
local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents:
12066
diff
changeset
|
431 |
|
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
432 |
fun read_props_thy freeze pp syn thy defaults = |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
433 |
#1 o read_def_termTs freeze pp syn thy defaults o map (rpair propT); |
| 5819 | 434 |
|
435 |
||
| 19001 | 436 |
(* local abbreviations *) |
| 5819 | 437 |
|
| 19371 | 438 |
fun certify_consts ctxt = |
| 19001 | 439 |
Consts.certify (pp ctxt) (tsig_of ctxt) (consts_of ctxt); |
440 |
||
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
441 |
fun reject_schematic (Var (xi, _)) = |
|
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
442 |
error ("Unbound schematic variable: " ^ Syntax.string_of_vname xi)
|
|
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
443 |
| reject_schematic (Abs (_, _, t)) = reject_schematic t |
|
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
444 |
| reject_schematic (t $ u) = (reject_schematic t; reject_schematic u) |
|
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
445 |
| reject_schematic _ = (); |
| 5819 | 446 |
|
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
447 |
fun expand_binds ctxt schematic = |
|
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
448 |
Variable.expand_binds ctxt #> (if schematic then I else tap reject_schematic); |
| 5819 | 449 |
|
450 |
||
| 6550 | 451 |
(* dummy patterns *) |
452 |
||
| 18310 | 453 |
val prepare_dummies = |
454 |
let val next = ref 1 in |
|
455 |
fn t => |
|
456 |
let val (i, u) = Term.replace_dummy_patterns (! next, t) |
|
457 |
in next := i; u end |
|
458 |
end; |
|
| 6762 | 459 |
|
| 18678 | 460 |
fun reject_dummies t = Term.no_dummy_patterns t |
461 |
handle TERM _ => error "Illegal dummy pattern(s) in term"; |
|
| 6550 | 462 |
|
463 |
||
| 5819 | 464 |
(* read terms *) |
465 |
||
| 10554 | 466 |
local |
467 |
||
| 15531 | 468 |
fun append_env e1 e2 x = (case e2 x of NONE => e1 x | some => some); |
|
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
469 |
|
|
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
470 |
fun gen_read' read app pattern schematic |
|
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
471 |
ctxt internal more_types more_sorts more_used s = |
|
14174
f3cafd2929d5
Methods rule_tac etc support static (Isar) contexts.
ballarin
parents:
13629
diff
changeset
|
472 |
let |
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
473 |
val types = append_env (Variable.def_type ctxt pattern) more_types; |
|
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
474 |
val sorts = append_env (Variable.def_sort ctxt) more_sorts; |
|
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
475 |
val used = Variable.used_types ctxt @ more_used; |
|
14174
f3cafd2929d5
Methods rule_tac etc support static (Isar) contexts.
ballarin
parents:
13629
diff
changeset
|
476 |
in |
| 18857 | 477 |
(read (pp ctxt) (syn_of ctxt) ctxt (types, sorts, used) s |
| 18678 | 478 |
handle TERM (msg, _) => error msg) |
|
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
479 |
|> app (intern_skolem ctxt internal) |
| 19371 | 480 |
|> app (certify_consts ctxt) |
| 19001 | 481 |
|> app (if pattern then I else expand_binds ctxt schematic) |
| 18678 | 482 |
|> app (if pattern then prepare_dummies else reject_dummies) |
|
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
483 |
end; |
|
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
484 |
|
|
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
485 |
fun gen_read read app pattern schematic ctxt = |
|
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
486 |
gen_read' read app pattern schematic ctxt (K false) (K NONE) (K NONE) []; |
|
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
487 |
|
| 10554 | 488 |
in |
489 |
||
|
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
490 |
val read_termTs = gen_read' (read_def_termTs false) (apfst o map) false false; |
|
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
491 |
val read_termTs_schematic = gen_read' (read_def_termTs false) (apfst o map) false true; |
| 8096 | 492 |
|
|
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
493 |
fun read_term_pats T ctxt = |
|
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
494 |
#1 o gen_read (read_def_termTs false) (apfst o map) true false ctxt o map (rpair T); |
| 8096 | 495 |
val read_prop_pats = read_term_pats propT; |
496 |
||
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
497 |
fun read_term_legacy ctxt = |
| 16458 | 498 |
gen_read' (read_term_thy true) I false false ctxt (K true) (K NONE) (K NONE) []; |
|
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
499 |
|
| 19143 | 500 |
val read_term = gen_read (read_term_thy true) I false false; |
501 |
val read_prop = gen_read (read_prop_thy true) I false false; |
|
502 |
val read_prop_schematic = gen_read (read_prop_thy true) I false true; |
|
503 |
val read_terms = gen_read (read_terms_thy true) map false false; |
|
504 |
fun read_props schematic = gen_read (read_props_thy true) map false schematic; |
|
| 5819 | 505 |
|
| 10554 | 506 |
end; |
507 |
||
| 5819 | 508 |
|
509 |
(* certify terms *) |
|
510 |
||
| 10554 | 511 |
local |
512 |
||
| 18971 | 513 |
fun gen_cert prop pattern schematic ctxt t = t |
| 19371 | 514 |
|> certify_consts ctxt |
| 19001 | 515 |
|> (if pattern then I else expand_binds ctxt schematic) |
| 19371 | 516 |
|> (fn t' => #1 (Sign.certify' false prop (pp ctxt) (consts_of ctxt) (theory_of ctxt) t') |
| 18678 | 517 |
handle TYPE (msg, _, _) => error msg |
518 |
| TERM (msg, _) => error msg); |
|
| 16501 | 519 |
|
| 10554 | 520 |
in |
| 8096 | 521 |
|
| 18971 | 522 |
val cert_term = gen_cert false false false; |
523 |
val cert_prop = gen_cert true false false; |
|
524 |
val cert_props = map oo gen_cert true false; |
|
| 10554 | 525 |
|
| 18971 | 526 |
fun cert_term_pats _ = map o gen_cert false true false; |
527 |
val cert_prop_pats = map o gen_cert true true false; |
|
| 10554 | 528 |
|
529 |
end; |
|
| 5819 | 530 |
|
531 |
||
| 18770 | 532 |
(* inferred types of parameters *) |
533 |
||
534 |
fun infer_type ctxt x = |
|
535 |
(case try (fn () => |
|
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
536 |
Sign.infer_types (pp ctxt) (theory_of ctxt) (consts_of ctxt) (Variable.def_type ctxt false) |
|
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
537 |
(Variable.def_sort ctxt) (Variable.used_types ctxt) true |
|
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
538 |
([Free (x, dummyT)], TypeInfer.logicT)) () of |
| 18770 | 539 |
SOME (Free (_, T), _) => T |
540 |
| _ => error ("Failed to infer type of fixed variable " ^ quote x));
|
|
541 |
||
542 |
fun inferred_param x ctxt = |
|
| 18619 | 543 |
let val T = infer_type ctxt x |
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
544 |
in ((x, T), ctxt |> Variable.declare_syntax (Free (x, T))) end; |
| 18619 | 545 |
|
| 18770 | 546 |
fun inferred_fixes ctxt = |
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
547 |
fold_map inferred_param (rev (Variable.fixed_names_of ctxt)) ctxt; |
| 5819 | 548 |
|
549 |
||
| 15703 | 550 |
(* type and constant names *) |
551 |
||
552 |
fun read_tyname ctxt c = |
|
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
553 |
if member (op =) (Variable.used_types ctxt) c then |
|
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
554 |
TFree (c, the_default (Sign.defaultS (theory_of ctxt)) (Variable.def_sort ctxt (c, ~1))) |
| 16458 | 555 |
else Sign.read_tyname (theory_of ctxt) c; |
| 15703 | 556 |
|
557 |
fun read_const ctxt c = |
|
558 |
(case lookup_skolem ctxt c of |
|
559 |
SOME c' => Free (c', dummyT) |
|
| 18971 | 560 |
| NONE => Consts.read_const (consts_of ctxt) c); |
| 15703 | 561 |
|
562 |
||
| 9553 | 563 |
|
564 |
(** export theorems **) |
|
|
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
565 |
|
| 18042 | 566 |
fun common_exports is_goal inner outer = |
|
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
567 |
let |
| 12057 | 568 |
val asms = Library.drop (length (assumptions_of outer), assumptions_of inner); |
|
19916
3bbb9cc5d4f1
export: simultaneous facts, refer to Variable.export;
wenzelm
parents:
19897
diff
changeset
|
569 |
val exp_asms = rev (map (fn (cprops, exp) => exp is_goal cprops) asms); |
| 16948 | 570 |
in |
|
19916
3bbb9cc5d4f1
export: simultaneous facts, refer to Variable.export;
wenzelm
parents:
19897
diff
changeset
|
571 |
map Goal.norm_hhf_protect |
|
3bbb9cc5d4f1
export: simultaneous facts, refer to Variable.export;
wenzelm
parents:
19897
diff
changeset
|
572 |
#> Seq.map_list (Seq.EVERY exp_asms) |
|
3bbb9cc5d4f1
export: simultaneous facts, refer to Variable.export;
wenzelm
parents:
19897
diff
changeset
|
573 |
#> Seq.map (Variable.export inner outer) |
|
3bbb9cc5d4f1
export: simultaneous facts, refer to Variable.export;
wenzelm
parents:
19897
diff
changeset
|
574 |
#> Seq.map (map Goal.norm_hhf_protect) |
| 11816 | 575 |
end; |
|
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
576 |
|
| 19847 | 577 |
val goal_exports = common_exports true; |
578 |
val exports = common_exports false; |
|
579 |
||
|
19916
3bbb9cc5d4f1
export: simultaneous facts, refer to Variable.export;
wenzelm
parents:
19897
diff
changeset
|
580 |
fun export inner outer ths = |
|
3bbb9cc5d4f1
export: simultaneous facts, refer to Variable.export;
wenzelm
parents:
19897
diff
changeset
|
581 |
(case Seq.pull (common_exports false inner outer ths) of |
|
3bbb9cc5d4f1
export: simultaneous facts, refer to Variable.export;
wenzelm
parents:
19897
diff
changeset
|
582 |
SOME (ths', _) => ths' |
|
3bbb9cc5d4f1
export: simultaneous facts, refer to Variable.export;
wenzelm
parents:
19897
diff
changeset
|
583 |
| NONE => raise THM ("Failed to export theorems", 0, ths));
|
| 12704 | 584 |
|
| 19847 | 585 |
fun export_standard inner outer = |
|
19916
3bbb9cc5d4f1
export: simultaneous facts, refer to Variable.export;
wenzelm
parents:
19897
diff
changeset
|
586 |
export inner outer #> map Drule.local_standard; |
| 7925 | 587 |
|
| 5819 | 588 |
|
|
15758
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
589 |
|
| 5819 | 590 |
(** bindings **) |
591 |
||
| 8096 | 592 |
(* simult_matches *) |
593 |
||
| 19867 | 594 |
fun simult_matches ctxt (t, pats) = |
595 |
(case Seq.pull (Unify.matchers (theory_of ctxt) (map (rpair t) pats)) of |
|
596 |
NONE => error "Pattern match failed!" |
|
597 |
| SOME (env, _) => map (apsnd snd) (Envir.alist_of env)); |
|
| 8096 | 598 |
|
599 |
||
600 |
(* add_binds(_i) *) |
|
| 5819 | 601 |
|
| 7925 | 602 |
local |
603 |
||
|
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
604 |
fun gen_bind prep (xi as (x, _), raw_t) ctxt = |
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
605 |
ctxt |> Variable.add_binds [(xi, Option.map (prep ctxt) raw_t)]; |
| 5819 | 606 |
|
| 10810 | 607 |
in |
608 |
||
| 15531 | 609 |
fun drop_schematic (b as (xi, SOME t)) = if null (Term.term_vars t) then b else (xi, NONE) |
| 10554 | 610 |
| drop_schematic b = b; |
611 |
||
|
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
612 |
val add_binds = fold (gen_bind read_term); |
|
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
613 |
val add_binds_i = fold (gen_bind cert_term); |
|
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
614 |
|
| 16458 | 615 |
fun auto_bind f ts ctxt = ctxt |> add_binds_i (map drop_schematic (f (theory_of ctxt) ts)); |
| 12147 | 616 |
val auto_bind_goal = auto_bind AutoBind.goal; |
617 |
val auto_bind_facts = auto_bind AutoBind.facts; |
|
| 7925 | 618 |
|
619 |
end; |
|
| 5819 | 620 |
|
621 |
||
| 8096 | 622 |
(* match_bind(_i) *) |
| 5819 | 623 |
|
| 8096 | 624 |
local |
625 |
||
|
17860
b4cf247ea0d2
note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents:
17756
diff
changeset
|
626 |
fun prep_bind prep_pats (raw_pats, t) ctxt = |
| 5819 | 627 |
let |
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
628 |
val ctxt' = Variable.declare_term t ctxt; |
| 19585 | 629 |
val pats = prep_pats (Term.fastype_of t) ctxt' raw_pats; |
630 |
val binds = simult_matches ctxt' (t, pats); |
|
|
17860
b4cf247ea0d2
note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents:
17756
diff
changeset
|
631 |
in (binds, ctxt') end; |
| 7670 | 632 |
|
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
633 |
fun gen_binds prep_terms prep_pats gen raw_binds ctxt = |
|
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
634 |
let |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
635 |
val ts = prep_terms ctxt (map snd raw_binds); |
|
17860
b4cf247ea0d2
note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents:
17756
diff
changeset
|
636 |
val (binds, ctxt') = |
|
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19422
diff
changeset
|
637 |
apfst flat (fold_map (prep_bind prep_pats) (map fst raw_binds ~~ ts) ctxt); |
|
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
638 |
val binds' = |
|
19916
3bbb9cc5d4f1
export: simultaneous facts, refer to Variable.export;
wenzelm
parents:
19897
diff
changeset
|
639 |
if gen then map #1 binds ~~ Variable.exportT_terms ctxt' ctxt (map #2 binds) |
|
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
640 |
else binds; |
| 15531 | 641 |
val binds'' = map (apsnd SOME) binds'; |
| 18310 | 642 |
val ctxt'' = |
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
643 |
tap (Variable.warn_extra_tfrees ctxt) |
| 18310 | 644 |
(if gen then |
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
645 |
ctxt (*sic!*) |> fold Variable.declare_term (map #2 binds') |> add_binds_i binds'' |
| 18310 | 646 |
else ctxt' |> add_binds_i binds''); |
647 |
in (ts, ctxt'') end; |
|
| 8096 | 648 |
|
649 |
in |
|
| 5935 | 650 |
|
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
651 |
val match_bind = gen_binds read_terms read_term_pats; |
|
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
652 |
val match_bind_i = gen_binds (map o cert_term) cert_term_pats; |
| 8096 | 653 |
|
654 |
end; |
|
| 5935 | 655 |
|
656 |
||
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
657 |
(* propositions with patterns *) |
| 5935 | 658 |
|
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
659 |
local |
| 8096 | 660 |
|
| 10554 | 661 |
fun prep_propp schematic prep_props prep_pats (context, args) = |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
662 |
let |
| 19585 | 663 |
fun prep (_, raw_pats) (ctxt, prop :: props) = |
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
664 |
let val ctxt' = Variable.declare_term prop ctxt |
| 19585 | 665 |
in ((prop, prep_pats ctxt' raw_pats), (ctxt', props)) end |
|
17860
b4cf247ea0d2
note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents:
17756
diff
changeset
|
666 |
| prep _ _ = sys_error "prep_propp"; |
|
b4cf247ea0d2
note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents:
17756
diff
changeset
|
667 |
val (propp, (context', _)) = (fold_map o fold_map) prep args |
|
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19422
diff
changeset
|
668 |
(context, prep_props schematic context (maps (map fst) args)); |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
669 |
in (context', propp) end; |
| 5935 | 670 |
|
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
671 |
fun gen_bind_propp prepp (ctxt, raw_args) = |
| 8096 | 672 |
let |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
673 |
val (ctxt', args) = prepp (ctxt, raw_args); |
| 19585 | 674 |
val binds = flat (flat (map (map (simult_matches ctxt')) args)); |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
675 |
val propss = map (map #1) args; |
|
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
676 |
|
| 10554 | 677 |
(*generalize result: context evaluated now, binds added later*) |
|
19916
3bbb9cc5d4f1
export: simultaneous facts, refer to Variable.export;
wenzelm
parents:
19897
diff
changeset
|
678 |
val gen = Variable.exportT_terms ctxt' ctxt; |
| 15531 | 679 |
fun gen_binds c = c |> add_binds_i (map #1 binds ~~ map SOME (gen (map #2 binds))); |
680 |
in (ctxt' |> add_binds_i (map (apsnd SOME) binds), (propss, gen_binds)) end; |
|
| 8096 | 681 |
|
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
682 |
in |
|
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
683 |
|
| 11925 | 684 |
val read_propp = prep_propp false read_props read_prop_pats; |
685 |
val cert_propp = prep_propp false cert_props cert_prop_pats; |
|
| 10554 | 686 |
val read_propp_schematic = prep_propp true read_props read_prop_pats; |
687 |
val cert_propp_schematic = prep_propp true cert_props cert_prop_pats; |
|
688 |
||
| 11925 | 689 |
val bind_propp = gen_bind_propp read_propp; |
690 |
val bind_propp_i = gen_bind_propp cert_propp; |
|
691 |
val bind_propp_schematic = gen_bind_propp read_propp_schematic; |
|
| 10554 | 692 |
val bind_propp_schematic_i = gen_bind_propp cert_propp_schematic; |
| 6789 | 693 |
|
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
694 |
end; |
|
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
695 |
|
| 6789 | 696 |
|
| 5819 | 697 |
|
698 |
(** theorems **) |
|
699 |
||
| 18042 | 700 |
(* fact_tac *) |
701 |
||
| 18122 | 702 |
fun comp_incr_tac [] _ st = no_tac st |
703 |
| comp_incr_tac (th :: ths) i st = |
|
704 |
(Goal.compose_hhf_tac (Drule.incr_indexes st th) i APPEND comp_incr_tac ths i) st; |
|
| 18042 | 705 |
|
| 18122 | 706 |
fun fact_tac facts = Tactic.norm_hhf_tac THEN' comp_incr_tac facts; |
707 |
||
708 |
fun some_fact_tac ctxt = SUBGOAL (fn (goal, i) => |
|
| 18042 | 709 |
let |
| 19001 | 710 |
val index = fact_index_of ctxt; |
| 18042 | 711 |
val facts = FactIndex.could_unify index (Term.strip_all_body goal); |
712 |
in fact_tac facts i end); |
|
713 |
||
714 |
||
| 6091 | 715 |
(* get_thm(s) *) |
| 5819 | 716 |
|
| 18042 | 717 |
fun retrieve_thms _ pick ctxt (Fact s) = |
| 16501 | 718 |
let |
| 18042 | 719 |
val thy = theory_of ctxt; |
720 |
val th = Goal.prove thy [] [] (read_prop ctxt s) (K (ALLGOALS (some_fact_tac ctxt))) |
|
| 18678 | 721 |
handle ERROR msg => cat_error msg "Failed to retrieve literal fact."; |
| 18042 | 722 |
in pick "" [th] end |
723 |
| retrieve_thms from_thy pick ctxt xthmref = |
|
724 |
let |
|
725 |
val thy = theory_of ctxt; |
|
| 19001 | 726 |
val (space, tab) = #1 (thms_of ctxt); |
| 16501 | 727 |
val thmref = PureThy.map_name_of_thmref (NameSpace.intern space) xthmref; |
728 |
val name = PureThy.name_of_thmref thmref; |
|
729 |
in |
|
| 17412 | 730 |
(case Symtab.lookup tab name of |
| 16540 | 731 |
SOME ths => map (Thm.transfer thy) (PureThy.select_thm thmref ths) |
732 |
| NONE => from_thy thy xthmref) |> pick name |
|
| 18042 | 733 |
end; |
| 5819 | 734 |
|
| 9566 | 735 |
val get_thm = retrieve_thms PureThy.get_thms PureThy.single_thm; |
736 |
val get_thm_closure = retrieve_thms PureThy.get_thms_closure PureThy.single_thm; |
|
737 |
val get_thms = retrieve_thms PureThy.get_thms (K I); |
|
738 |
val get_thms_closure = retrieve_thms PureThy.get_thms_closure (K I); |
|
| 5819 | 739 |
|
740 |
||
|
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
741 |
(* valid_thms *) |
|
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
742 |
|
|
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
743 |
fun valid_thms ctxt (name, ths) = |
| 18678 | 744 |
(case try (fn () => get_thms ctxt (Name name)) () of |
|
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
745 |
NONE => false |
| 16147 | 746 |
| SOME ths' => Thm.eq_thms (ths, ths')); |
|
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
747 |
|
|
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
748 |
|
|
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
749 |
(* lthms_containing *) |
|
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
750 |
|
|
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
751 |
fun lthms_containing ctxt spec = |
|
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
752 |
FactIndex.find (fact_index_of ctxt) spec |
| 18043 | 753 |
|> map ((not o valid_thms ctxt) ? apfst (fn name => |
| 18042 | 754 |
NameSpace.hidden (if name = "" then "unnamed" else name))); |
|
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
755 |
|
|
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
756 |
|
|
13425
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
757 |
(* name space operations *) |
|
12309
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
758 |
|
|
19062
0fd52e819c24
replaced qualified_force_prefix to sticky_prefix;
wenzelm
parents:
19033
diff
changeset
|
759 |
val no_base_names = map_naming NameSpace.no_base_names; |
| 16147 | 760 |
val qualified_names = map_naming NameSpace.qualified_names; |
|
19062
0fd52e819c24
replaced qualified_force_prefix to sticky_prefix;
wenzelm
parents:
19033
diff
changeset
|
761 |
val sticky_prefix = map_naming o NameSpace.sticky_prefix; |
|
0fd52e819c24
replaced qualified_force_prefix to sticky_prefix;
wenzelm
parents:
19033
diff
changeset
|
762 |
val restore_naming = map_naming o K o naming_of; |
|
12309
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
763 |
|
| 19001 | 764 |
fun hide_thms fully names = map_thms (fn ((space, tab), index) => |
765 |
((fold (NameSpace.hide fully) names space, tab), index)); |
|
|
13425
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
766 |
|
|
12309
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
767 |
|
|
17360
fa1f262dbc4e
added add_view, export_view (supercedes adhoc view arguments);
wenzelm
parents:
17221
diff
changeset
|
768 |
(* put_thms *) |
| 5819 | 769 |
|
|
19079
9a7678a0736d
added put_thms_internal: local_naming, no fact index;
wenzelm
parents:
19062
diff
changeset
|
770 |
fun put_thms _ ("", NONE) ctxt = ctxt
|
| 19143 | 771 |
| put_thms do_index ("", SOME ths) ctxt = ctxt |> map_thms (fn (facts, index) =>
|
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
772 |
let |
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
773 |
val index' = FactIndex.add_local do_index (Variable.is_declared ctxt) ("", ths) index;
|
| 19001 | 774 |
in (facts, index') end) |
|
19079
9a7678a0736d
added put_thms_internal: local_naming, no fact index;
wenzelm
parents:
19062
diff
changeset
|
775 |
| put_thms _ (bname, NONE) ctxt = ctxt |> map_thms (fn ((space, tab), index) => |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
776 |
let |
| 19387 | 777 |
val name = full_name ctxt bname; |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
778 |
val tab' = Symtab.delete_safe name tab; |
| 19001 | 779 |
in ((space, tab'), index) end) |
|
19079
9a7678a0736d
added put_thms_internal: local_naming, no fact index;
wenzelm
parents:
19062
diff
changeset
|
780 |
| put_thms do_index (bname, SOME ths) ctxt = ctxt |> map_thms (fn ((space, tab), index) => |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
781 |
let |
| 19387 | 782 |
val name = full_name ctxt bname; |
| 19001 | 783 |
val space' = NameSpace.declare (naming_of ctxt) name space; |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
784 |
val tab' = Symtab.update (name, ths) tab; |
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
785 |
val index' = FactIndex.add_local do_index (Variable.is_declared ctxt) (name, ths) index; |
| 19001 | 786 |
in ((space', tab'), index') end); |
| 5819 | 787 |
|
|
19079
9a7678a0736d
added put_thms_internal: local_naming, no fact index;
wenzelm
parents:
19062
diff
changeset
|
788 |
fun put_thms_internal thms ctxt = |
|
9a7678a0736d
added put_thms_internal: local_naming, no fact index;
wenzelm
parents:
19062
diff
changeset
|
789 |
ctxt |> map_naming (K local_naming) |> put_thms false thms |> restore_naming ctxt; |
|
9a7678a0736d
added put_thms_internal: local_naming, no fact index;
wenzelm
parents:
19062
diff
changeset
|
790 |
|
| 7606 | 791 |
|
| 14564 | 792 |
(* note_thmss *) |
| 5819 | 793 |
|
| 12711 | 794 |
local |
| 16147 | 795 |
|
|
17860
b4cf247ea0d2
note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents:
17756
diff
changeset
|
796 |
fun gen_note_thmss get = fold_map (fn ((name, more_attrs), ths_attrs) => fn ctxt => |
| 5819 | 797 |
let |
|
17360
fa1f262dbc4e
added add_view, export_view (supercedes adhoc view arguments);
wenzelm
parents:
17221
diff
changeset
|
798 |
fun app (th, attrs) (ct, ths) = |
| 18728 | 799 |
let val (ct', th') = foldl_map (Thm.proof_attributes (attrs @ more_attrs)) (ct, get ctxt th) |
| 12711 | 800 |
in (ct', th' :: ths) end; |
|
17360
fa1f262dbc4e
added add_view, export_view (supercedes adhoc view arguments);
wenzelm
parents:
17221
diff
changeset
|
801 |
val (ctxt', rev_thms) = fold app ths_attrs (ctxt, []); |
|
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19422
diff
changeset
|
802 |
val thms = flat (rev rev_thms); |
|
19079
9a7678a0736d
added put_thms_internal: local_naming, no fact index;
wenzelm
parents:
19062
diff
changeset
|
803 |
in ((name, thms), ctxt' |> put_thms true (name, SOME thms)) end); |
| 12711 | 804 |
|
805 |
in |
|
806 |
||
| 16147 | 807 |
val note_thmss = gen_note_thmss get_thms; |
808 |
val note_thmss_i = gen_note_thmss (K I); |
|
| 15696 | 809 |
|
810 |
val note_thmss_accesses = gen_note_thmss get_thms; |
|
811 |
val note_thmss_accesses_i = gen_note_thmss (K I); |
|
| 12711 | 812 |
|
813 |
end; |
|
| 9196 | 814 |
|
| 5819 | 815 |
|
816 |
||
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
817 |
(** parameters **) |
|
17360
fa1f262dbc4e
added add_view, export_view (supercedes adhoc view arguments);
wenzelm
parents:
17221
diff
changeset
|
818 |
|
| 8096 | 819 |
(* variables *) |
820 |
||
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
821 |
fun declare_var (x, opt_T, mx) ctxt = |
|
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
822 |
let val T = (case opt_T of SOME T => T | NONE => TypeInfer.mixfixT mx) |
|
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
823 |
in ((x, T, mx), ctxt |> Variable.declare_syntax (Free (x, T))) end; |
|
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
824 |
|
| 10381 | 825 |
local |
826 |
||
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
827 |
fun prep_vars prep_typ internal legacy = |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
828 |
fold_map (fn (raw_x, raw_T, raw_mx) => fn ctxt => |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
829 |
let |
| 19371 | 830 |
val (x, mx) = Syntax.const_mixfix raw_x raw_mx; |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
831 |
val _ = |
| 18678 | 832 |
if not legacy andalso not (Syntax.is_identifier (no_skolem internal x)) then |
833 |
error ("Illegal variable name: " ^ quote x)
|
|
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
834 |
else (); |
| 12504 | 835 |
|
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
836 |
fun cond_tvars T = |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
837 |
if internal then T |
| 18678 | 838 |
else Type.no_tvars T handle TYPE (msg, _, _) => error msg; |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
839 |
val opt_T = Option.map (cond_tvars o prep_typ ctxt) raw_T; |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
840 |
val var = (x, opt_T, mx); |
| 19001 | 841 |
in (var, ctxt |> declare_var var |> #2) end); |
| 8096 | 842 |
|
| 10381 | 843 |
in |
844 |
||
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
845 |
val read_vars = prep_vars read_typ false false; |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
846 |
val cert_vars = prep_vars cert_typ true false; |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
847 |
val read_vars_legacy = prep_vars read_typ true true; |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
848 |
val cert_vars_legacy = prep_vars cert_typ true true; |
| 8096 | 849 |
|
| 10381 | 850 |
end; |
851 |
||
| 8096 | 852 |
|
| 19681 | 853 |
(* authentic constants *) |
| 19663 | 854 |
|
855 |
fun add_const_syntax prmode args ctxt = |
|
856 |
ctxt |> map_syntax |
|
857 |
(LocalSyntax.add_modesyntax (theory_of ctxt) prmode |
|
858 |
(map (pair false o Consts.syntax (consts_of ctxt)) args)); |
|
859 |
||
| 19681 | 860 |
fun context_const_ast_tr context [Syntax.Variable c] = |
861 |
let |
|
862 |
val consts = Context.cases Sign.consts_of consts_of context; |
|
863 |
val c' = Consts.intern consts c; |
|
864 |
val _ = Consts.constraint consts c' handle TYPE (msg, _, _) => error msg; |
|
865 |
in Syntax.Constant (Syntax.constN ^ c') end |
|
866 |
| context_const_ast_tr _ asts = raise Syntax.AST ("const_ast_tr", asts);
|
|
867 |
||
868 |
val _ = Context.add_setup |
|
869 |
(Sign.add_syntax |
|
870 |
[("_context_const", "id => 'a", Delimfix "CONST _"),
|
|
871 |
("_context_const", "longid => 'a", Delimfix "CONST _")] #>
|
|
872 |
Sign.add_advanced_trfuns ([("_context_const", context_const_ast_tr)], [], [], []));
|
|
873 |
||
| 19663 | 874 |
|
| 19001 | 875 |
(* abbreviations *) |
876 |
||
| 19371 | 877 |
val expand_abbrevs = map_consts o apsnd o Consts.expand_abbrevs; |
878 |
||
| 19681 | 879 |
fun add_abbrevs prmode = fold (fn ((raw_c, raw_mx), raw_t) => fn ctxt => |
| 19001 | 880 |
let |
| 19663 | 881 |
val ([(c, _, mx)], _) = cert_vars [(raw_c, NONE, raw_mx)] ctxt; |
|
19673
853f5a3cc06e
always preserve authentic consts -- removed Syntax.mixfix_const;
wenzelm
parents:
19663
diff
changeset
|
882 |
val c' = Syntax.constN ^ full_name ctxt c; |
|
20008
8d9d770e1f06
add_abbrevs/polymorphic: Variable.exportT_terms avoids over-generalization;
wenzelm
parents:
19916
diff
changeset
|
883 |
val t0 = cert_term (ctxt |> expand_abbrevs false) raw_t; |
|
8d9d770e1f06
add_abbrevs/polymorphic: Variable.exportT_terms avoids over-generalization;
wenzelm
parents:
19916
diff
changeset
|
884 |
val [t] = Variable.exportT_terms (Variable.declare_term t0 ctxt) ctxt [t0]; |
| 19019 | 885 |
val T = Term.fastype_of t; |
| 19001 | 886 |
val _ = |
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
887 |
if null (Variable.hidden_polymorphism t T) then () |
| 19001 | 888 |
else error ("Extra type variables on rhs of abbreviation: " ^ quote c);
|
889 |
in |
|
890 |
ctxt |
|
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
891 |
|> Variable.declare_term t |
|
19673
853f5a3cc06e
always preserve authentic consts -- removed Syntax.mixfix_const;
wenzelm
parents:
19663
diff
changeset
|
892 |
|> map_consts (apsnd |
| 19681 | 893 |
(Consts.abbreviate (pp ctxt) (tsig_of ctxt) (naming_of ctxt) (#1 prmode) ((c, t), true))) |
| 19663 | 894 |
|> map_syntax (LocalSyntax.add_modesyntax (theory_of ctxt) prmode [(false, (c', T, mx))]) |
| 19001 | 895 |
end); |
896 |
||
897 |
||
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
898 |
(* fixes *) |
| 5819 | 899 |
|
| 8096 | 900 |
local |
901 |
||
| 19001 | 902 |
fun prep_mixfix (x, T, mx) = |
| 19019 | 903 |
if mx <> NoSyn andalso mx <> Structure andalso |
|
19916
3bbb9cc5d4f1
export: simultaneous facts, refer to Variable.export;
wenzelm
parents:
19897
diff
changeset
|
904 |
(can Term.dest_internal x orelse can Term.dest_skolem x) then |
| 19001 | 905 |
error ("Illegal mixfix syntax for internal/skolem constant " ^ quote x)
|
906 |
else (true, (x, T, mx)); |
|
907 |
||
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
908 |
fun no_dups _ [] = () |
| 18900 | 909 |
| no_dups ctxt dups = error ("Duplicate fixed variable(s): " ^ commas_quote dups);
|
| 11925 | 910 |
|
| 18844 | 911 |
fun gen_fixes prep raw_vars ctxt = |
| 8096 | 912 |
let |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
913 |
val (vars, ctxt') = prep raw_vars ctxt; |
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
914 |
val (xs', ctxt'') = Variable.add_fixes (map #1 vars) ctxt'; |
| 8096 | 915 |
in |
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
916 |
ctxt'' |
| 19001 | 917 |
|> fold_map declare_var (map2 (fn x' => fn (_, T, mx) => (x', T, mx)) xs' vars) |
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
918 |
|-> (map_syntax o LocalSyntax.add_syntax (theory_of ctxt) o map prep_mixfix) |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
919 |
|> pair xs' |
| 8096 | 920 |
end; |
| 5819 | 921 |
|
| 8096 | 922 |
in |
| 7679 | 923 |
|
| 18844 | 924 |
val add_fixes = gen_fixes read_vars; |
925 |
val add_fixes_i = gen_fixes cert_vars; |
|
926 |
val add_fixes_legacy = gen_fixes cert_vars_legacy; |
|
| 8096 | 927 |
|
928 |
end; |
|
| 5819 | 929 |
|
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
930 |
|
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
931 |
(* fixes vs. frees *) |
| 12016 | 932 |
|
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
933 |
fun fix_frees t ctxt = |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
934 |
let |
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
935 |
fun add (Free (x, T)) = |
|
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
936 |
if Variable.is_fixed ctxt x then I else insert (op =) (x, SOME T, NoSyn) |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
937 |
| add _ = I; |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
938 |
val fixes = rev (fold_aterms add t []); |
| 18809 | 939 |
in |
940 |
ctxt |
|
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
941 |
|> Variable.declare_term t |
|
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
942 |
|> Variable.set_body false |
| 18809 | 943 |
|> (snd o add_fixes_i fixes) |
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
944 |
|> Variable.restore_body ctxt |
| 18809 | 945 |
end; |
| 6895 | 946 |
|
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
947 |
fun auto_fixes (arg as (ctxt, (propss, x))) = |
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
948 |
if Variable.is_body ctxt then arg |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
949 |
else ((fold o fold) fix_frees propss ctxt, (propss, x)); |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
950 |
|
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
951 |
fun bind_fixes xs ctxt = |
|
9291
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
952 |
let |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
953 |
val (_, ctxt') = ctxt |> add_fixes_i (map (fn x => (x, NONE, NoSyn)) xs); |
|
9291
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
954 |
fun bind (t as Free (x, T)) = |
| 18340 | 955 |
if member (op =) xs x then |
| 15531 | 956 |
(case lookup_skolem ctxt' x of SOME x' => Free (x', T) | NONE => t) |
|
9291
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
957 |
else t |
|
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
958 |
| bind (t $ u) = bind t $ bind u |
|
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
959 |
| bind (Abs (x, T, t)) = Abs (x, T, bind t) |
|
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
960 |
| bind a = a; |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
961 |
in (bind, ctxt') end; |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
962 |
|
|
9291
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
963 |
|
|
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
964 |
|
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
965 |
(** assumptions **) |
| 18187 | 966 |
|
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
967 |
(* generic assms *) |
| 18187 | 968 |
|
969 |
local |
|
970 |
||
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
971 |
fun gen_assm ((name, attrs), props) ctxt = |
| 18187 | 972 |
let |
973 |
val cprops = map (Thm.cterm_of (theory_of ctxt)) props; |
|
974 |
val asms = map (Goal.norm_hhf o Thm.assume) cprops; |
|
975 |
||
976 |
val ths = map (fn th => ([th], [])) asms; |
|
977 |
val ([(_, thms)], ctxt') = |
|
978 |
ctxt |
|
979 |
|> auto_bind_facts props |
|
980 |
|> note_thmss_i [((name, attrs), ths)]; |
|
981 |
in ((cprops, (name, asms), (name, thms)), ctxt') end; |
|
982 |
||
983 |
fun gen_assms prepp exp args ctxt = |
|
984 |
let |
|
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
985 |
val (propss, ctxt1) = swap (prepp (ctxt, map snd args)); |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
986 |
val (results, ctxt2) = fold_map gen_assm (map fst args ~~ propss) ctxt1; |
| 18187 | 987 |
|
|
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19422
diff
changeset
|
988 |
val new_asms = maps #1 results; |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
989 |
val new_prems = map #2 results; |
| 18809 | 990 |
val ctxt3 = ctxt2 |
991 |
|> map_assms (fn (asms, prems) => (asms @ [(new_asms, exp)], prems @ new_prems)) |
|
992 |
val ctxt4 = ctxt3 |
|
|
19079
9a7678a0736d
added put_thms_internal: local_naming, no fact index;
wenzelm
parents:
19062
diff
changeset
|
993 |
|> put_thms_internal (AutoBind.premsN, SOME (prems_of ctxt3)); |
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
994 |
in (map #3 results, tap (Variable.warn_extra_tfrees ctxt) ctxt4) end; |
| 18187 | 995 |
|
996 |
in |
|
997 |
||
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
998 |
val add_assms = gen_assms (apsnd #1 o bind_propp); |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
999 |
val add_assms_i = gen_assms (apsnd #1 o bind_propp_i); |
| 18187 | 1000 |
|
1001 |
end; |
|
1002 |
||
1003 |
||
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1004 |
(* basic assumptions *) |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1005 |
|
| 18879 | 1006 |
(* |
1007 |
[A] |
|
| 18971 | 1008 |
: |
| 18879 | 1009 |
B |
1010 |
-------- |
|
1011 |
#A ==> B |
|
1012 |
*) |
|
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1013 |
fun assume_export true = Seq.single oo Drule.implies_intr_protected |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1014 |
| assume_export false = Seq.single oo Drule.implies_intr_list; |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1015 |
|
| 18879 | 1016 |
(* |
1017 |
[A] |
|
| 18971 | 1018 |
: |
| 18879 | 1019 |
B |
1020 |
------- |
|
1021 |
A ==> B |
|
1022 |
*) |
|
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1023 |
fun presume_export _ = assume_export false; |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1024 |
|
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1025 |
|
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1026 |
(* additional views *) |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1027 |
|
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1028 |
fun add_view outer view = map_assms (fn (asms, prems) => |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1029 |
let |
| 19019 | 1030 |
val (asms1, asms2) = chop (length (assumptions_of outer)) asms; |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1031 |
val asms' = asms1 @ [(view, assume_export)] @ asms2; |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1032 |
in (asms', prems) end); |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1033 |
|
|
19916
3bbb9cc5d4f1
export: simultaneous facts, refer to Variable.export;
wenzelm
parents:
19897
diff
changeset
|
1034 |
fun export_view view inner outer = singleton (export_standard (add_view outer view inner) outer); |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1035 |
|
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1036 |
|
| 5819 | 1037 |
|
|
8373
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1038 |
(** cases **) |
|
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1039 |
|
| 16147 | 1040 |
local |
1041 |
||
| 16668 | 1042 |
fun rem_case name = remove (fn (x: string, (y, _)) => x = y) name; |
| 16147 | 1043 |
|
| 18476 | 1044 |
fun add_case _ ("", _) cases = cases
|
1045 |
| add_case _ (name, NONE) cases = rem_case name cases |
|
1046 |
| add_case is_proper (name, SOME c) cases = (name, (c, is_proper)) :: rem_case name cases; |
|
| 16147 | 1047 |
|
| 18678 | 1048 |
fun prep_case name fxs c = |
| 18609 | 1049 |
let |
1050 |
fun replace (opt_x :: xs) ((y, T) :: ys) = (the_default y opt_x, T) :: replace xs ys |
|
1051 |
| replace [] ys = ys |
|
| 18678 | 1052 |
| replace (_ :: _) [] = error ("Too many parameters for case " ^ quote name);
|
| 18609 | 1053 |
val RuleCases.Case {fixes, assumes, binds, cases} = c;
|
1054 |
val fixes' = replace fxs fixes; |
|
1055 |
val binds' = map drop_schematic binds; |
|
1056 |
in |
|
1057 |
if null (fold (Term.add_tvarsT o snd) fixes []) andalso |
|
1058 |
null (fold (fold Term.add_vars o snd) assumes []) then |
|
1059 |
RuleCases.Case {fixes = fixes', assumes = assumes, binds = binds', cases = cases}
|
|
| 18678 | 1060 |
else error ("Illegal schematic variable(s) in case " ^ quote name)
|
| 18609 | 1061 |
end; |
1062 |
||
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1063 |
fun fix (x, T) ctxt = |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1064 |
let |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1065 |
val (bind, ctxt') = bind_fixes [x] ctxt; |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1066 |
val t = bind (Free (x, T)); |
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
1067 |
in (t, ctxt' |> Variable.declare_syntax t) end; |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1068 |
|
| 16147 | 1069 |
in |
1070 |
||
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1071 |
fun add_cases is_proper = map_cases o fold (add_case is_proper); |
| 18609 | 1072 |
|
1073 |
fun case_result c ctxt = |
|
1074 |
let |
|
1075 |
val RuleCases.Case {fixes, ...} = c;
|
|
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1076 |
val (ts, ctxt') = ctxt |> fold_map fix fixes; |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1077 |
val RuleCases.Case {assumes, binds, cases, ...} = RuleCases.apply ts c;
|
| 18609 | 1078 |
in |
1079 |
ctxt' |
|
|
18699
f3bfe81b6e58
case_result: drop_schematic, i.e. be permissive about illegal binds;
wenzelm
parents:
18678
diff
changeset
|
1080 |
|> add_binds_i (map drop_schematic binds) |
| 18609 | 1081 |
|> add_cases true (map (apsnd SOME) cases) |
1082 |
|> pair (assumes, (binds, cases)) |
|
1083 |
end; |
|
1084 |
||
1085 |
val apply_case = apfst fst oo case_result; |
|
1086 |
||
| 16540 | 1087 |
fun get_case ctxt name xs = |
| 17184 | 1088 |
(case AList.lookup (op =) (cases_of ctxt) name of |
| 18678 | 1089 |
NONE => error ("Unknown case: " ^ quote name)
|
1090 |
| SOME (c, _) => prep_case name xs c); |
|
|
8373
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1091 |
|
| 16147 | 1092 |
end; |
|
8373
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1093 |
|
|
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1094 |
|
|
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1095 |
|
| 10810 | 1096 |
(** print context information **) |
1097 |
||
1098 |
val verbose = ref false; |
|
1099 |
fun verb f x = if ! verbose then f (x ()) else []; |
|
1100 |
||
1101 |
fun setmp_verbose f x = Library.setmp verbose true f x; |
|
1102 |
||
1103 |
||
|
12072
4281198fb8cd
local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents:
12066
diff
changeset
|
1104 |
(* local syntax *) |
|
4281198fb8cd
local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents:
12066
diff
changeset
|
1105 |
|
| 12093 | 1106 |
val print_syntax = Syntax.print_syntax o syn_of; |
|
12072
4281198fb8cd
local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents:
12066
diff
changeset
|
1107 |
|
|
4281198fb8cd
local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents:
12066
diff
changeset
|
1108 |
|
| 18971 | 1109 |
(* local consts *) |
1110 |
||
1111 |
fun pretty_consts ctxt = |
|
1112 |
let |
|
|
19033
24e251657e56
consts: maintain thy version for efficient transfer;
wenzelm
parents:
19019
diff
changeset
|
1113 |
val ((_, globals), (space, consts)) = |
|
24e251657e56
consts: maintain thy version for efficient transfer;
wenzelm
parents:
19019
diff
changeset
|
1114 |
pairself (#constants o Consts.dest) (#consts (rep_context ctxt)); |
| 18971 | 1115 |
fun local_abbrev (_, (_, NONE)) = I |
1116 |
| local_abbrev (c, (T, SOME t)) = |
|
1117 |
if Symtab.defined globals c then I else cons (c, Logic.mk_equals (Const (c, T), t)); |
|
1118 |
val abbrevs = NameSpace.extern_table (space, Symtab.make (Symtab.fold local_abbrev consts [])); |
|
1119 |
in |
|
1120 |
if null abbrevs andalso not (! verbose) then [] |
|
| 19310 | 1121 |
else [Pretty.big_list "abbreviations:" (map (pretty_term_no_abbrevs ctxt o #2) abbrevs)] |
| 18971 | 1122 |
end; |
1123 |
||
1124 |
||
| 10810 | 1125 |
(* term bindings *) |
1126 |
||
| 16540 | 1127 |
fun pretty_binds ctxt = |
| 10810 | 1128 |
let |
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
1129 |
val binds = Variable.binds_of ctxt; |
| 19310 | 1130 |
fun prt_bind (xi, (T, t)) = pretty_term_no_abbrevs ctxt (Logic.mk_equals (Var (xi, T), t)); |
| 10810 | 1131 |
in |
|
15758
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
1132 |
if Vartab.is_empty binds andalso not (! verbose) then [] |
|
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
1133 |
else [Pretty.big_list "term bindings:" (map prt_bind (Vartab.dest binds))] |
| 10810 | 1134 |
end; |
1135 |
||
1136 |
val print_binds = Pretty.writeln o Pretty.chunks o pretty_binds; |
|
1137 |
||
1138 |
||
1139 |
(* local theorems *) |
|
1140 |
||
| 16540 | 1141 |
fun pretty_lthms ctxt = |
| 20012 | 1142 |
let |
1143 |
val props = FactIndex.props (fact_index_of ctxt); |
|
1144 |
val facts = |
|
1145 |
(if null props then I else cons ("unnamed", props))
|
|
1146 |
(NameSpace.extern_table (#1 (thms_of ctxt))); |
|
1147 |
in |
|
1148 |
if null facts andalso not (! verbose) then [] |
|
1149 |
else [Pretty.big_list "facts:" (map (pretty_fact ctxt) facts)] |
|
1150 |
end; |
|
| 10810 | 1151 |
|
| 12057 | 1152 |
val print_lthms = Pretty.writeln o Pretty.chunks o pretty_lthms; |
| 10810 | 1153 |
|
1154 |
||
1155 |
(* local contexts *) |
|
1156 |
||
| 16540 | 1157 |
fun pretty_cases ctxt = |
| 10810 | 1158 |
let |
| 12057 | 1159 |
val prt_term = pretty_term ctxt; |
1160 |
||
| 10810 | 1161 |
fun prt_let (xi, t) = Pretty.block |
| 10818 | 1162 |
[Pretty.quote (prt_term (Var (xi, Term.fastype_of t))), Pretty.str " =", Pretty.brk 1, |
| 10810 | 1163 |
Pretty.quote (prt_term t)]; |
1164 |
||
|
13425
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
1165 |
fun prt_asm (a, ts) = Pretty.block (Pretty.breaks |
|
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
1166 |
((if a = "" then [] else [Pretty.str (a ^ ":")]) @ map (Pretty.quote o prt_term) ts)); |
|
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
1167 |
|
| 10810 | 1168 |
fun prt_sect _ _ _ [] = [] |
1169 |
| prt_sect s sep prt xs = [Pretty.block (Pretty.breaks (Pretty.str s :: |
|
|
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19422
diff
changeset
|
1170 |
flat (Library.separate sep (map (Library.single o prt) xs))))]; |
| 10810 | 1171 |
|
| 18609 | 1172 |
fun prt_case (name, (fixes, (asms, (lets, cs)))) = Pretty.block (Pretty.fbreaks |
| 10810 | 1173 |
(Pretty.str (name ^ ":") :: |
| 11915 | 1174 |
prt_sect "fix" [] (Pretty.str o fst) fixes @ |
| 10810 | 1175 |
prt_sect "let" [Pretty.str "and"] prt_let |
|
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19422
diff
changeset
|
1176 |
(map_filter (fn (xi, SOME t) => SOME (xi, t) | _ => NONE) lets) @ |
|
13425
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
1177 |
(if forall (null o #2) asms then [] |
| 18609 | 1178 |
else prt_sect "assume" [Pretty.str "and"] prt_asm asms) @ |
1179 |
prt_sect "subcases:" [] (Pretty.str o fst) cs)); |
|
| 16540 | 1180 |
|
| 18476 | 1181 |
fun add_case (_, (_, false)) = I |
| 18609 | 1182 |
| add_case (name, (c as RuleCases.Case {fixes, ...}, true)) =
|
1183 |
cons (name, (fixes, #1 (case_result c ctxt))); |
|
| 18476 | 1184 |
val cases = fold add_case (cases_of ctxt) []; |
| 10810 | 1185 |
in |
1186 |
if null cases andalso not (! verbose) then [] |
|
| 18476 | 1187 |
else [Pretty.big_list "cases:" (map prt_case cases)] |
| 10810 | 1188 |
end; |
1189 |
||
1190 |
val print_cases = Pretty.writeln o Pretty.chunks o pretty_cases; |
|
1191 |
||
1192 |
||
| 12057 | 1193 |
(* core context *) |
| 10810 | 1194 |
|
1195 |
val prems_limit = ref 10; |
|
1196 |
||
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1197 |
fun pretty_ctxt ctxt = |
| 10810 | 1198 |
let |
| 12057 | 1199 |
val prt_term = pretty_term ctxt; |
1200 |
||
| 12093 | 1201 |
(*structures*) |
| 19001 | 1202 |
val structs = LocalSyntax.structs_of (syntax_of ctxt); |
| 12093 | 1203 |
val prt_structs = if null structs then [] |
1204 |
else [Pretty.block (Pretty.str "structures:" :: Pretty.brk 1 :: |
|
1205 |
Pretty.commas (map Pretty.str structs))]; |
|
1206 |
||
| 12057 | 1207 |
(*fixes*) |
1208 |
fun prt_fix (x, x') = |
|
1209 |
if x = x' then Pretty.str x |
|
1210 |
else Pretty.block [Pretty.str x, Pretty.str " =", Pretty.brk 1, prt_term (Syntax.free x')]; |
|
| 18340 | 1211 |
val fixes = |
|
19916
3bbb9cc5d4f1
export: simultaneous facts, refer to Variable.export;
wenzelm
parents:
19897
diff
changeset
|
1212 |
rev (filter_out ((can Term.dest_internal orf member (op =) structs) o #1) |
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
1213 |
(Variable.fixes_of ctxt)); |
| 12093 | 1214 |
val prt_fixes = if null fixes then [] |
1215 |
else [Pretty.block (Pretty.str "fixed variables:" :: Pretty.brk 1 :: |
|
1216 |
Pretty.commas (map prt_fix fixes))]; |
|
| 12057 | 1217 |
|
1218 |
(*prems*) |
|
| 10810 | 1219 |
val limit = ! prems_limit; |
1220 |
val prems = prems_of ctxt; |
|
1221 |
val len = length prems; |
|
| 12093 | 1222 |
val prt_prems = if null prems then [] |
1223 |
else [Pretty.big_list "prems:" ((if len <= limit then [] else [Pretty.str "..."]) @ |
|
1224 |
map (pretty_thm ctxt) (Library.drop (len - limit, prems)))]; |
|
1225 |
||
1226 |
in prt_structs @ prt_fixes @ prt_prems end; |
|
| 10810 | 1227 |
|
1228 |
||
1229 |
(* main context *) |
|
1230 |
||
| 16540 | 1231 |
fun pretty_context ctxt = |
| 10810 | 1232 |
let |
| 12057 | 1233 |
val prt_term = pretty_term ctxt; |
1234 |
val prt_typ = pretty_typ ctxt; |
|
1235 |
val prt_sort = pretty_sort ctxt; |
|
| 10810 | 1236 |
|
1237 |
(*theory*) |
|
| 12057 | 1238 |
val pretty_thy = Pretty.block |
| 17384 | 1239 |
[Pretty.str "theory:", Pretty.brk 1, Context.pretty_thy (theory_of ctxt)]; |
| 10810 | 1240 |
|
1241 |
(*defaults*) |
|
1242 |
fun prt_atom prt prtT (x, X) = Pretty.block |
|
1243 |
[prt x, Pretty.str " ::", Pretty.brk 1, prtT X]; |
|
1244 |
||
1245 |
fun prt_var (x, ~1) = prt_term (Syntax.free x) |
|
1246 |
| prt_var xi = prt_term (Syntax.var xi); |
|
1247 |
||
1248 |
fun prt_varT (x, ~1) = prt_typ (TFree (x, [])) |
|
1249 |
| prt_varT xi = prt_typ (TVar (xi, [])); |
|
1250 |
||
1251 |
val prt_defT = prt_atom prt_var prt_typ; |
|
1252 |
val prt_defS = prt_atom prt_varT prt_sort; |
|
| 16540 | 1253 |
|
|
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
1254 |
val (types, sorts, used, _) = Variable.defaults_of ctxt; |
| 10810 | 1255 |
in |
| 18609 | 1256 |
verb single (K pretty_thy) @ |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1257 |
pretty_ctxt ctxt @ |
| 18971 | 1258 |
verb pretty_consts (K ctxt) @ |
| 10810 | 1259 |
verb pretty_binds (K ctxt) @ |
| 12057 | 1260 |
verb pretty_lthms (K ctxt) @ |
| 10810 | 1261 |
verb pretty_cases (K ctxt) @ |
| 18609 | 1262 |
verb single (fn () => Pretty.big_list "type constraints:" (map prt_defT (Vartab.dest types))) @ |
1263 |
verb single (fn () => Pretty.big_list "default sorts:" (map prt_defS (Vartab.dest sorts))) @ |
|
| 18809 | 1264 |
verb single (fn () => Pretty.strs ("used type variable names:" :: rev used))
|
| 10810 | 1265 |
end; |
1266 |
||
| 18809 | 1267 |
|
1268 |
(* toplevel pretty printing *) |
|
1269 |
||
1270 |
val debug = ref false; |
|
1271 |
||
1272 |
fun pprint_context ctxt = Pretty.pprint |
|
1273 |
(if ! debug then Pretty.quote (Pretty.big_list "proof context:" (pretty_context ctxt)) |
|
1274 |
else Pretty.str "<context>"); |
|
1275 |
||
| 5819 | 1276 |
end; |