author | wenzelm |
Fri, 13 Jan 2006 01:13:16 +0100 | |
changeset 18672 | ac1a048ca7dd |
parent 18619 | fa61df848dea |
child 18678 | dd0c569fa43d |
permissions | -rw-r--r-- |
5819 | 1 |
(* Title: Pure/Isar/proof_context.ML |
2 |
ID: $Id$ |
|
3 |
Author: Markus Wenzel, TU Muenchen |
|
4 |
||
15758
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
5 |
The key concept of Isar proof contexts. |
5819 | 6 |
*) |
7 |
||
14707 | 8 |
val show_structs = ref false; |
9 |
||
5819 | 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 |
exception CONTEXT of string * context |
15 |
val theory_of: context -> theory |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
16 |
val init: theory -> context |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
17 |
val set_body: bool -> context -> context |
17451 | 18 |
val assms_of: context -> term list |
7557 | 19 |
val prems_of: context -> thm list |
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
20 |
val fact_index_of: context -> FactIndex.T |
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
21 |
val is_fixed: context -> string -> bool |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
22 |
val is_known: context -> string -> bool |
17072 | 23 |
val transfer: theory -> context -> context |
14828 | 24 |
val pretty_term: context -> term -> Pretty.T |
25 |
val pretty_typ: context -> typ -> Pretty.T |
|
26 |
val pretty_sort: context -> sort -> Pretty.T |
|
27 |
val pp: context -> Pretty.pp |
|
28 |
val pretty_thm: context -> thm -> Pretty.T |
|
29 |
val pretty_thms: context -> thm list -> Pretty.T |
|
30 |
val pretty_fact: context -> string * thm list -> Pretty.T |
|
17072 | 31 |
val pretty_proof: context -> Proofterm.proof -> Pretty.T |
32 |
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
|
33 |
val string_of_typ: context -> typ -> string |
14828 | 34 |
val string_of_term: context -> term -> string |
17860
b4cf247ea0d2
note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents:
17756
diff
changeset
|
35 |
val string_of_thm: context -> thm -> string |
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
36 |
val used_types: context -> string list |
12414 | 37 |
val default_type: context -> string -> typ option |
18619 | 38 |
val infer_type: context -> string -> typ |
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 |
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
58 |
val read_terms: context -> string list -> term list |
8096 | 59 |
val read_term_pats: typ -> context -> string list -> term list |
60 |
val read_prop_pats: context -> string list -> term list |
|
5819 | 61 |
val cert_term: context -> term -> term |
62 |
val cert_prop: context -> term -> term |
|
8096 | 63 |
val cert_term_pats: typ -> context -> term list -> term list |
64 |
val cert_prop_pats: context -> term list -> term list |
|
5819 | 65 |
val declare_term: term -> context -> context |
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
66 |
val inferred_type: string -> context -> (string * typ) * context |
15703 | 67 |
val read_tyname: context -> string -> typ |
68 |
val read_const: context -> string -> term |
|
7925 | 69 |
val warn_extra_tfrees: context -> context -> context |
12550
32843ad8160a
generalize type variables properly: start with occurrences in objects
wenzelm
parents:
12530
diff
changeset
|
70 |
val generalize: context -> context -> term list -> term list |
18042 | 71 |
val export: context -> context -> thm -> thm |
72 |
val exports: context -> context -> thm -> thm Seq.seq |
|
73 |
val goal_exports: context -> context -> thm -> thm Seq.seq |
|
10810 | 74 |
val drop_schematic: indexname * term option -> indexname * term option |
75 |
val add_binds: (indexname * string option) list -> context -> context |
|
76 |
val add_binds_i: (indexname * term option) list -> context -> context |
|
12147 | 77 |
val auto_bind_goal: term list -> context -> context |
78 |
val auto_bind_facts: term list -> context -> context |
|
18310 | 79 |
val match_bind: bool -> (string list * string) list -> context -> term list * context |
80 |
val match_bind_i: bool -> (term list * term) list -> context -> term list * context |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
81 |
val read_propp: context * (string * (string list * string list)) list list |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
82 |
-> context * (term * (term list * term list)) list list |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
83 |
val cert_propp: context * (term * (term list * term list)) list list |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
84 |
-> context * (term * (term list * term list)) list list |
10554 | 85 |
val read_propp_schematic: context * (string * (string list * string list)) list list |
86 |
-> context * (term * (term list * term list)) list list |
|
87 |
val cert_propp_schematic: context * (term * (term list * term list)) list list |
|
88 |
-> context * (term * (term list * term list)) list list |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
89 |
val bind_propp: context * (string * (string list * string list)) list list |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
90 |
-> context * (term list list * (context -> context)) |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
91 |
val bind_propp_i: context * (term * (term list * term list)) list list |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
92 |
-> context * (term list list * (context -> context)) |
10554 | 93 |
val bind_propp_schematic: context * (string * (string list * string list)) list list |
94 |
-> context * (term list list * (context -> context)) |
|
95 |
val bind_propp_schematic_i: context * (term * (term list * term list)) list list |
|
96 |
-> context * (term list list * (context -> context)) |
|
18042 | 97 |
val fact_tac: thm list -> int -> tactic |
98 |
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
|
99 |
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
|
100 |
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
|
101 |
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
|
102 |
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
|
103 |
val valid_thms: context -> string * thm list -> bool |
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
104 |
val lthms_containing: context -> FactIndex.spec -> (string * thm list) list |
16348 | 105 |
val extern_thm: context -> string -> xstring |
16147 | 106 |
val qualified_names: context -> context |
107 |
val no_base_names: context -> context |
|
108 |
val custom_accesses: (string list -> string list list) -> context -> context |
|
109 |
val restore_naming: context -> context -> context |
|
13425
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
110 |
val hide_thms: bool -> string list -> context -> context |
17360
fa1f262dbc4e
added add_view, export_view (supercedes adhoc view arguments);
wenzelm
parents:
17221
diff
changeset
|
111 |
val put_thms: string * thm list option -> context -> context |
14564 | 112 |
val note_thmss: |
16147 | 113 |
((bstring * context attribute list) * (thmref * context attribute list) list) list -> |
17860
b4cf247ea0d2
note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents:
17756
diff
changeset
|
114 |
context -> (bstring * thm list) list * context |
14564 | 115 |
val note_thmss_i: |
16147 | 116 |
((bstring * context attribute list) * (thm list * context attribute list) list) list -> |
17860
b4cf247ea0d2
note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents:
17756
diff
changeset
|
117 |
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
|
118 |
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
|
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 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
|
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 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
|
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 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
|
125 |
(string * typ option * mixfix) list * context |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
126 |
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
|
127 |
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
|
128 |
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
|
129 |
val fix_frees: term -> context -> context |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
130 |
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
|
131 |
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
|
132 |
val add_assms: export -> |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
133 |
((string * context attribute list) * (string * (string list * string list)) list) list -> |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
134 |
context -> (bstring * thm list) list * context |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
135 |
val add_assms_i: export -> |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
136 |
((string * context attribute list) * (term * (term list * term list)) list) list -> |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
137 |
context -> (bstring * thm list) list * context |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
138 |
val assume_export: export |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
139 |
val presume_export: export |
17360
fa1f262dbc4e
added add_view, export_view (supercedes adhoc view arguments);
wenzelm
parents:
17221
diff
changeset
|
140 |
val add_view: context -> cterm list -> context -> context |
18042 | 141 |
val export_view: cterm list -> context -> context -> thm -> thm |
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
142 |
val mk_def: context -> (string * term) list -> term list |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
143 |
val cert_def: context -> term -> string * term |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
144 |
val def_export: export |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
145 |
val add_def: string * term -> context -> ((string * typ) * thm) * context |
18609 | 146 |
val add_cases: bool -> (string * RuleCases.T option) list -> context -> context |
147 |
val apply_case: RuleCases.T -> context -> (string * term list) list * context |
|
16147 | 148 |
val get_case: context -> string -> string option list -> RuleCases.T |
10810 | 149 |
val verbose: bool ref |
150 |
val setmp_verbose: ('a -> 'b) -> 'a -> 'b |
|
12072
4281198fb8cd
local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents:
12066
diff
changeset
|
151 |
val print_syntax: context -> unit |
10810 | 152 |
val print_binds: context -> unit |
12057 | 153 |
val print_lthms: context -> unit |
10810 | 154 |
val print_cases: context -> unit |
155 |
val prems_limit: int ref |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
156 |
val pretty_ctxt: context -> Pretty.T list |
10810 | 157 |
val pretty_context: context -> Pretty.T list |
5819 | 158 |
end; |
159 |
||
16540 | 160 |
structure ProofContext: PROOF_CONTEXT = |
5819 | 161 |
struct |
162 |
||
16540 | 163 |
type context = Context.proof; |
17072 | 164 |
exception CONTEXT = Context.PROOF; |
5819 | 165 |
|
16540 | 166 |
val theory_of = Context.theory_of_proof; |
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 |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
177 |
{syntax: (*global/local syntax, structs, mixfixed*) |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
178 |
(Syntax.syntax * Syntax.syntax * (Syntax.syntax -> Syntax.syntax)) * |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
179 |
string list * string list, |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
180 |
fixes: bool * (string * string) list, (*fixes: !!x. _ with proof body flag*) |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
181 |
assms: |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
182 |
((cterm list * export) list * (*assumes and views: A ==> _*) |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
183 |
(string * thm list) list), (*prems: A |- A*) |
18476 | 184 |
binds: (term * typ) Vartab.table, (*term bindings*) |
185 |
thms: NameSpace.naming * (*local thms*) |
|
16540 | 186 |
thm list NameSpace.table * FactIndex.T, |
18476 | 187 |
cases: (string * (RuleCases.T * bool)) list, (*local contexts*) |
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
188 |
defaults: |
18476 | 189 |
typ Vartab.table * (*type constraints*) |
190 |
sort Vartab.table * (*default sorts*) |
|
191 |
string list * (*used type variables*) |
|
192 |
term list Symtab.table}; (*type variable occurrences*) |
|
5819 | 193 |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
194 |
fun make_ctxt (syntax, fixes, assms, binds, thms, cases, defaults) = |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
195 |
Ctxt {syntax = syntax, fixes = fixes, assms = assms, binds = binds, |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
196 |
thms = thms, cases = cases, defaults = defaults}; |
5819 | 197 |
|
16540 | 198 |
structure ContextData = ProofDataFun |
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
199 |
( |
16540 | 200 |
val name = "Isar/context"; |
201 |
type T = ctxt; |
|
202 |
fun init thy = |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
203 |
make_ctxt (((Sign.syn_of thy, Sign.syn_of thy, I), [], []), (false, []), ([], []), |
17072 | 204 |
Vartab.empty, (NameSpace.default_naming, NameSpace.empty_table, FactIndex.empty), [], |
16540 | 205 |
(Vartab.empty, Vartab.empty, [], Symtab.empty)); |
206 |
fun print _ _ = (); |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
207 |
); |
5819 | 208 |
|
16540 | 209 |
val _ = Context.add_setup [ContextData.init]; |
5819 | 210 |
|
16540 | 211 |
fun rep_context ctxt = ContextData.get ctxt |> (fn Ctxt args => args); |
5819 | 212 |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
213 |
fun map_context f = |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
214 |
ContextData.map (fn Ctxt {syntax, fixes, assms, binds, thms, cases, defaults} => |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
215 |
make_ctxt (f (syntax, fixes, assms, binds, thms, cases, defaults))); |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
216 |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
217 |
fun map_syntax f = map_context (fn (syntax, fixes, assms, binds, thms, cases, defaults) => |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
218 |
(f syntax, fixes, assms, binds, thms, cases, defaults)); |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
219 |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
220 |
fun map_fixes f = map_context (fn (syntax, fixes, assms, binds, thms, cases, defaults) => |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
221 |
(syntax, f fixes, assms, binds, thms, cases, defaults)); |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
222 |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
223 |
fun map_assms f = map_context (fn (syntax, fixes, assms, binds, thms, cases, defaults) => |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
224 |
(syntax, fixes, f assms, binds, thms, cases, defaults)); |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
225 |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
226 |
fun map_binds f = map_context (fn (syntax, fixes, assms, binds, thms, cases, defaults) => |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
227 |
(syntax, fixes, assms, f binds, thms, cases, defaults)); |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
228 |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
229 |
fun map_thms f = map_context (fn (syntax, fixes, assms, binds, thms, cases, defaults) => |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
230 |
(syntax, fixes, assms, binds, f thms, cases, defaults)); |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
231 |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
232 |
fun map_naming f = map_thms (fn (naming, table, index) => (f naming, table, index)); |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
233 |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
234 |
fun map_cases f = map_context (fn (syntax, fixes, assms, binds, thms, cases, defaults) => |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
235 |
(syntax, fixes, assms, binds, thms, f cases, defaults)); |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
236 |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
237 |
fun map_defaults f = map_context (fn (syntax, fixes, assms, binds, thms, cases, defaults) => |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
238 |
(syntax, fixes, assms, binds, thms, cases, f defaults)); |
5819 | 239 |
|
16540 | 240 |
val syntax_of = #syntax o rep_context; |
5819 | 241 |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
242 |
val is_body = #1 o #fixes o rep_context; |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
243 |
fun set_body b = map_fixes (fn (_, fixes) => (b, fixes)); |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
244 |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
245 |
val fixes_of = #2 o #fixes o rep_context; |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
246 |
val fixed_names_of = map #2 o fixes_of; |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
247 |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
248 |
val assumptions_of = #1 o #assms o rep_context; |
17451 | 249 |
val assms_of = map Thm.term_of o List.concat o map #1 o assumptions_of; |
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
250 |
val prems_of = List.concat o map #2 o #2 o #assms o rep_context; |
5819 | 251 |
|
17860
b4cf247ea0d2
note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents:
17756
diff
changeset
|
252 |
val binds_of = #binds o rep_context; |
5819 | 253 |
|
16540 | 254 |
val thms_of = #thms o rep_context; |
255 |
val fact_index_of = #3 o thms_of; |
|
256 |
||
257 |
val cases_of = #cases o rep_context; |
|
5819 | 258 |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
259 |
val defaults_of = #defaults o rep_context; |
16540 | 260 |
val type_occs_of = #4 o defaults_of; |
5819 | 261 |
|
16540 | 262 |
fun is_fixed ctxt x = exists (equal x o #2) (fixes_of ctxt); |
16894 | 263 |
fun is_known ctxt x = Vartab.defined (#1 (defaults_of ctxt)) (x, ~1) orelse is_fixed ctxt x; |
5819 | 264 |
|
265 |
||
8096 | 266 |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
267 |
(** syntax **) |
12093 | 268 |
|
14697 | 269 |
(* translation functions *) |
14665
d2e5df3d1201
index syntax: support for general expressions (input only);
wenzelm
parents:
14643
diff
changeset
|
270 |
|
12100 | 271 |
fun context_tr' ctxt = |
272 |
let |
|
273 |
val (_, structs, mixfixed) = syntax_of ctxt; |
|
274 |
||
275 |
fun tr' (t $ u) = tr' t $ tr' u |
|
276 |
| tr' (Abs (x, T, t)) = Abs (x, T, tr' t) |
|
277 |
| tr' (t as Free (x, T)) = |
|
14697 | 278 |
let val i = Library.find_index_eq x structs + 1 in |
18340 | 279 |
if i = 0 andalso member (op =) mixfixed x then Const (Syntax.fixedN ^ x, T) |
14707 | 280 |
else if i = 1 andalso not (! show_structs) then |
281 |
Syntax.const "_struct" $ Syntax.const "_indexdefault" |
|
12100 | 282 |
else t |
283 |
end |
|
284 |
| tr' a = a; |
|
285 |
in tr' end; |
|
286 |
||
287 |
||
12576
9fd10052c3f7
added add_fixes: derives mssing type scheme from mixfix;
wenzelm
parents:
12550
diff
changeset
|
288 |
(* add syntax *) |
9fd10052c3f7
added add_fixes: derives mssing type scheme from mixfix;
wenzelm
parents:
12550
diff
changeset
|
289 |
|
12093 | 290 |
local |
291 |
||
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
292 |
fun check_mixfix ctxt (x, _, mx) = |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
293 |
if mx <> NoSyn andalso mx <> Structure andalso |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
294 |
(can Syntax.dest_internal x orelse can Syntax.dest_skolem x) then |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
295 |
raise CONTEXT ("Illegal mixfix syntax for internal/skolem constant " ^ quote x, ctxt) |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
296 |
else (); |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
297 |
|
18340 | 298 |
fun mixfix x NONE mx = (Syntax.fixedN ^ x, TypeInfer.mixfixT mx, Syntax.fix_mixfix x mx) |
299 |
| mixfix x (SOME T) mx = (Syntax.fixedN ^ x, T, Syntax.fix_mixfix x mx); |
|
12093 | 300 |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
301 |
fun prep_mixfix (_, _, Structure) = NONE |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
302 |
| prep_mixfix (x, opt_T, mx) = SOME (mixfix x opt_T mx); |
12093 | 303 |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
304 |
fun prep_mixfix' (_, _, Structure) = NONE |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
305 |
| prep_mixfix' (x, _, NoSyn) = NONE |
15531 | 306 |
| prep_mixfix' (x, opt_T, _) = SOME (x, mixfix x opt_T (Syntax.literal x)); |
12093 | 307 |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
308 |
fun prep_struct (x, _, Structure) = SOME x |
15531 | 309 |
| prep_struct _ = NONE; |
12093 | 310 |
|
15750 | 311 |
fun mk trs = map Syntax.mk_trfun trs; |
312 |
||
17072 | 313 |
fun extend_syntax thy extend (global_syn, syn, mk_syn) = |
314 |
let |
|
315 |
val thy_syn = Sign.syn_of thy; |
|
316 |
val mk_syn' = extend o mk_syn; |
|
317 |
val (global_syn', syn') = |
|
318 |
if Syntax.eq_syntax (global_syn, thy_syn) |
|
319 |
then (global_syn, extend syn) |
|
320 |
else (thy_syn, mk_syn' thy_syn); (*potentially expensive*) |
|
321 |
in (global_syn', syn', mk_syn') end; |
|
322 |
||
12093 | 323 |
in |
324 |
||
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
325 |
fun add_syntax decls ctxt = ctxt |> map_syntax (fn syntax => |
17072 | 326 |
let |
327 |
val (syns, structs, mixfixed) = syntax; |
|
328 |
val thy = theory_of ctxt; |
|
329 |
||
330 |
val is_logtype = Sign.is_logtype thy; |
|
331 |
val structs' = structs @ List.mapPartial prep_struct decls; |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
332 |
val mxs = List.mapPartial (tap (check_mixfix ctxt) #> prep_mixfix) decls; |
17072 | 333 |
val (fixed, mxs_output) = Library.split_list (List.mapPartial prep_mixfix' decls); |
12093 | 334 |
|
17072 | 335 |
val extend = |
336 |
Syntax.extend_const_gram is_logtype ("", false) mxs_output |
|
18340 | 337 |
#> Syntax.extend_const_gram is_logtype ("", true) mxs; |
17072 | 338 |
val syns' = extend_syntax thy extend syns; |
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
339 |
in (syns', structs', fixed @ mixfixed) end); |
17072 | 340 |
|
341 |
fun syn_of' thy ctxt = |
|
16540 | 342 |
let |
17072 | 343 |
val (syns, structs, _) = syntax_of ctxt; |
16540 | 344 |
val (atrs, trs, trs', atrs') = Syntax.struct_trfuns structs; |
17072 | 345 |
val extend = Syntax.extend_trfuns (mk atrs, mk trs, mk trs', mk atrs'); |
346 |
in #2 (extend_syntax thy extend syns) end; |
|
347 |
||
348 |
fun syn_of ctxt = syn_of' (theory_of ctxt) ctxt; |
|
14697 | 349 |
|
12093 | 350 |
end; |
351 |
||
17072 | 352 |
fun transfer thy = add_syntax [] o Context.transfer_proof thy; |
353 |
||
12093 | 354 |
|
355 |
||
14828 | 356 |
(** pretty printing **) |
357 |
||
17072 | 358 |
fun pretty_term' thy ctxt t = Sign.pretty_term' (syn_of' thy ctxt) thy (context_tr' ctxt t); |
359 |
fun pretty_term ctxt t = pretty_term' (theory_of ctxt) ctxt (context_tr' ctxt t); |
|
16458 | 360 |
fun pretty_typ ctxt T = Sign.pretty_typ (theory_of ctxt) T; |
361 |
fun pretty_sort ctxt S = Sign.pretty_sort (theory_of ctxt) S; |
|
362 |
fun pretty_classrel ctxt cs = Sign.pretty_classrel (theory_of ctxt) cs; |
|
363 |
fun pretty_arity ctxt ar = Sign.pretty_arity (theory_of ctxt) ar; |
|
14828 | 364 |
|
14974
b1ecb7859c99
avoid premature evaluation of syn_of (wastes time in conjunction with pp);
wenzelm
parents:
14901
diff
changeset
|
365 |
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
|
366 |
pretty_classrel ctxt, pretty_arity ctxt); |
14828 | 367 |
|
17451 | 368 |
fun pretty_thm ctxt th = |
369 |
Display.pretty_thm_aux (pp ctxt) false true (assms_of ctxt) th; |
|
14828 | 370 |
|
371 |
fun pretty_thms ctxt [th] = pretty_thm ctxt th |
|
372 |
| pretty_thms ctxt ths = Pretty.blk (0, Pretty.fbreaks (map (pretty_thm ctxt) ths)); |
|
373 |
||
374 |
fun pretty_fact ctxt ("", ths) = pretty_thms ctxt ths |
|
375 |
| pretty_fact ctxt (a, [th]) = |
|
376 |
Pretty.block [Pretty.str (a ^ ":"), Pretty.brk 1, pretty_thm ctxt th] |
|
377 |
| pretty_fact ctxt (a, ths) = |
|
378 |
Pretty.block (Pretty.fbreaks (Pretty.str (a ^ ":") :: map (pretty_thm ctxt) ths)); |
|
379 |
||
17072 | 380 |
fun pretty_proof ctxt prf = |
381 |
pretty_term' (ProofSyntax.proof_syntax prf (theory_of ctxt)) ctxt |
|
382 |
(ProofSyntax.term_of_proof prf); |
|
383 |
||
384 |
fun pretty_proof_of ctxt full th = |
|
385 |
pretty_proof ctxt (ProofSyntax.proof_of full th); |
|
386 |
||
17860
b4cf247ea0d2
note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents:
17756
diff
changeset
|
387 |
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
|
388 |
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
|
389 |
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
|
390 |
|
14828 | 391 |
|
392 |
||
7663 | 393 |
(** default sorts and types **) |
394 |
||
17412 | 395 |
val def_sort = Vartab.lookup o #2 o defaults_of; |
7663 | 396 |
|
16540 | 397 |
fun def_type ctxt pattern xi = |
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
398 |
let val {binds, defaults = (types, _, _, _), ...} = rep_context ctxt in |
17412 | 399 |
(case Vartab.lookup types xi of |
16540 | 400 |
NONE => |
401 |
if pattern then NONE |
|
17412 | 402 |
else Vartab.lookup binds xi |> Option.map (TypeInfer.polymorphicT o #2) |
16540 | 403 |
| some => some) |
404 |
end; |
|
7663 | 405 |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
406 |
val used_types = #3 o defaults_of; |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
407 |
|
17412 | 408 |
fun default_type ctxt x = Vartab.lookup (#1 (defaults_of ctxt)) (x, ~1); |
12414 | 409 |
|
18619 | 410 |
fun infer_type ctxt x = |
411 |
(case try (transform_error (fn () => |
|
412 |
Sign.infer_types (pp ctxt) (theory_of ctxt) (def_type ctxt false) (def_sort ctxt) |
|
413 |
(used_types ctxt) true ([Free (x, dummyT)], TypeInfer.logicT))) () of |
|
414 |
SOME (Free (_, T), _) => T |
|
415 |
| _ => raise CONTEXT ("Failed to infer type of fixed variable " ^ quote x, ctxt)); |
|
416 |
||
7663 | 417 |
|
5819 | 418 |
|
419 |
(** prepare types **) |
|
420 |
||
9504 | 421 |
local |
422 |
||
423 |
fun read_typ_aux read ctxt s = |
|
16458 | 424 |
transform_error (read (syn_of ctxt) (theory_of ctxt, def_sort ctxt)) s |
7663 | 425 |
handle ERROR_MESSAGE msg => raise CONTEXT (msg, ctxt); |
5819 | 426 |
|
10554 | 427 |
fun cert_typ_aux cert ctxt raw_T = |
16458 | 428 |
cert (theory_of ctxt) raw_T |
10554 | 429 |
handle TYPE (msg, _, _) => raise CONTEXT (msg, ctxt); |
9504 | 430 |
|
431 |
in |
|
432 |
||
16348 | 433 |
val read_typ = read_typ_aux Sign.read_typ'; |
434 |
val read_typ_syntax = read_typ_aux Sign.read_typ_syntax'; |
|
435 |
val read_typ_abbrev = read_typ_aux Sign.read_typ_abbrev'; |
|
436 |
val cert_typ = cert_typ_aux Sign.certify_typ; |
|
437 |
val cert_typ_syntax = cert_typ_aux Sign.certify_typ_syntax; |
|
438 |
val cert_typ_abbrev = cert_typ_aux Sign.certify_typ_abbrev; |
|
9504 | 439 |
|
440 |
end; |
|
441 |
||
5819 | 442 |
|
7679 | 443 |
(* internalize Skolem constants *) |
444 |
||
17184 | 445 |
val lookup_skolem = AList.lookup (op =) o fixes_of; |
18187 | 446 |
fun get_skolem ctxt x = the_default x (lookup_skolem ctxt x); |
7679 | 447 |
|
12504 | 448 |
fun no_skolem internal ctxt x = |
9291
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
449 |
if can Syntax.dest_skolem x then |
7679 | 450 |
raise CONTEXT ("Illegal reference to internal Skolem constant: " ^ quote x, ctxt) |
12504 | 451 |
else if not internal andalso can Syntax.dest_internal x then |
9291
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
452 |
raise CONTEXT ("Illegal reference to internal variable: " ^ quote x, ctxt) |
7679 | 453 |
else x; |
454 |
||
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
455 |
fun intern_skolem ctxt internal = |
7679 | 456 |
let |
457 |
fun intern (t as Free (x, T)) = |
|
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
458 |
if internal x then t |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
459 |
else |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
460 |
(case lookup_skolem ctxt (no_skolem false ctxt x) of |
15531 | 461 |
SOME x' => Free (x', T) |
462 |
| NONE => t) |
|
7679 | 463 |
| intern (t $ u) = intern t $ intern u |
464 |
| intern (Abs (x, T, t)) = Abs (x, T, intern t) |
|
465 |
| intern a = a; |
|
466 |
in intern end; |
|
467 |
||
468 |
||
18187 | 469 |
(* externalize Skolem constants -- approximation only! *) |
470 |
||
18255 | 471 |
fun rev_skolem ctxt = |
18187 | 472 |
let val rev_fixes = map Library.swap (fixes_of ctxt) |
473 |
in AList.lookup (op =) rev_fixes end; |
|
9133 | 474 |
|
18255 | 475 |
fun revert_skolem ctxt x = |
476 |
(case rev_skolem ctxt x of |
|
477 |
SOME x' => x' |
|
18375 | 478 |
| NONE => perhaps (try Syntax.dest_skolem) x); |
18255 | 479 |
|
9133 | 480 |
fun extern_skolem ctxt = |
481 |
let |
|
18255 | 482 |
val revert = rev_skolem ctxt; |
9133 | 483 |
fun extern (t as Free (x, T)) = |
18187 | 484 |
(case revert x of |
485 |
SOME x' => Free (if lookup_skolem ctxt x' = SOME x then x' else NameSpace.hidden x', T) |
|
486 |
| NONE => t) |
|
9133 | 487 |
| extern (t $ u) = extern t $ extern u |
488 |
| extern (Abs (x, T, t)) = Abs (x, T, extern t) |
|
489 |
| extern a = a; |
|
490 |
in extern end |
|
491 |
||
8096 | 492 |
|
18187 | 493 |
|
5819 | 494 |
(** prepare terms and propositions **) |
495 |
||
496 |
(* |
|
16501 | 497 |
(1) read / certify wrt. theory of context |
5819 | 498 |
(2) intern Skolem constants |
499 |
(3) expand term bindings |
|
500 |
*) |
|
501 |
||
502 |
||
16501 | 503 |
(* read wrt. theory *) (*exception ERROR*) |
5819 | 504 |
|
16458 | 505 |
fun read_def_termTs freeze pp syn thy (types, sorts, used) sTs = |
506 |
Sign.read_def_terms' pp (Sign.is_logtype thy) syn (thy, types, sorts) used freeze sTs; |
|
5874 | 507 |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
508 |
fun read_def_termT freeze pp syn thy defaults sT = |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
509 |
apfst hd (read_def_termTs freeze pp syn thy defaults [sT]); |
14828 | 510 |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
511 |
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
|
512 |
#1 (read_def_termT freeze pp syn thy defaults (s, TypeInfer.logicT)); |
5874 | 513 |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
514 |
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
|
515 |
#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
|
516 |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
517 |
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
|
518 |
#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
|
519 |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
520 |
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
|
521 |
#1 o read_def_termTs freeze pp syn thy defaults o map (rpair propT); |
5819 | 522 |
|
523 |
||
524 |
(* norm_term *) |
|
525 |
||
526 |
(*beta normal form for terms (not eta normal form), chase variables in |
|
527 |
bindings environment (code taken from Pure/envir.ML)*) |
|
528 |
||
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
529 |
fun unifyT ctxt (T, U) = |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
530 |
let val maxidx = Int.max (Term.maxidx_of_typ T, Term.maxidx_of_typ U) |
16948 | 531 |
in #1 (Sign.typ_unify (theory_of ctxt) (T, U) (Vartab.empty, maxidx)) end; |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
532 |
|
16540 | 533 |
fun norm_term ctxt schematic = |
5819 | 534 |
let |
535 |
(*raised when norm has no effect on a term, to do sharing instead of copying*) |
|
536 |
exception SAME; |
|
537 |
||
16540 | 538 |
val binds = binds_of ctxt; |
5819 | 539 |
fun norm (t as Var (xi, T)) = |
17412 | 540 |
(case Vartab.lookup binds xi of |
15758
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
541 |
SOME (u, U) => |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
542 |
let |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
543 |
val env = unifyT ctxt (T, U) handle Type.TUNIFY => |
14174
f3cafd2929d5
Methods rule_tac etc support static (Isar) contexts.
ballarin
parents:
13629
diff
changeset
|
544 |
raise TYPE ("norm_term: ill-typed variable assignment", [T, U], [t, u]); |
15798
016f3be5a5ec
Adapted to new interface of instantiation and unification / matching functions.
berghofe
parents:
15758
diff
changeset
|
545 |
val u' = Envir.subst_TVars env u; |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
546 |
in norm u' handle SAME => u' end |
15758
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
547 |
| NONE => |
10554 | 548 |
if schematic then raise SAME |
549 |
else raise CONTEXT ("Unbound schematic variable: " ^ Syntax.string_of_vname xi, ctxt)) |
|
5819 | 550 |
| norm (Abs (a, T, body)) = Abs (a, T, norm body) |
551 |
| norm (Abs (_, _, body) $ t) = normh (subst_bound (t, body)) |
|
552 |
| norm (f $ t) = |
|
553 |
((case norm f of |
|
554 |
Abs (_, _, body) => normh (subst_bound (t, body)) |
|
555 |
| nf => nf $ (norm t handle SAME => t)) handle SAME => f $ norm t) |
|
556 |
| norm _ = raise SAME |
|
557 |
and normh t = norm t handle SAME => t |
|
558 |
in normh end; |
|
559 |
||
560 |
||
6550 | 561 |
(* dummy patterns *) |
562 |
||
18310 | 563 |
val prepare_dummies = |
564 |
let val next = ref 1 in |
|
565 |
fn t => |
|
566 |
let val (i, u) = Term.replace_dummy_patterns (! next, t) |
|
567 |
in next := i; u end |
|
568 |
end; |
|
6762 | 569 |
|
9540 | 570 |
fun reject_dummies ctxt t = Term.no_dummy_patterns t |
571 |
handle TERM _ => raise CONTEXT ("Illegal dummy pattern(s) in term", ctxt); |
|
6550 | 572 |
|
573 |
||
5819 | 574 |
(* read terms *) |
575 |
||
10554 | 576 |
local |
577 |
||
15531 | 578 |
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
|
579 |
|
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
580 |
fun gen_read' read app pattern schematic |
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
581 |
ctxt internal more_types more_sorts more_used s = |
14174
f3cafd2929d5
Methods rule_tac etc support static (Isar) contexts.
ballarin
parents:
13629
diff
changeset
|
582 |
let |
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
583 |
val types = append_env (def_type ctxt pattern) more_types; |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
584 |
val sorts = append_env (def_sort ctxt) more_sorts; |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
585 |
val used = used_types ctxt @ more_used; |
14174
f3cafd2929d5
Methods rule_tac etc support static (Isar) contexts.
ballarin
parents:
13629
diff
changeset
|
586 |
in |
16458 | 587 |
(transform_error (read (pp ctxt) (syn_of ctxt) (theory_of ctxt) (types, sorts, used)) s |
14174
f3cafd2929d5
Methods rule_tac etc support static (Isar) contexts.
ballarin
parents:
13629
diff
changeset
|
588 |
handle TERM (msg, _) => raise CONTEXT (msg, ctxt) |
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
589 |
| ERROR_MESSAGE msg => raise CONTEXT (msg, ctxt)) |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
590 |
|> app (intern_skolem ctxt internal) |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
591 |
|> app (if pattern then I else norm_term ctxt schematic) |
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
592 |
|> app (if pattern then prepare_dummies else reject_dummies ctxt) |
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
593 |
end; |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
594 |
|
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
595 |
fun gen_read read app pattern schematic ctxt = |
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
596 |
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
|
597 |
|
10554 | 598 |
in |
599 |
||
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
600 |
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
|
601 |
val read_termTs_schematic = gen_read' (read_def_termTs false) (apfst o map) false true; |
8096 | 602 |
|
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
603 |
fun read_term_pats T ctxt = |
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
604 |
#1 o gen_read (read_def_termTs false) (apfst o map) true false ctxt o map (rpair T); |
8096 | 605 |
val read_prop_pats = read_term_pats propT; |
606 |
||
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
607 |
fun read_term_legacy ctxt = |
16458 | 608 |
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
|
609 |
|
16458 | 610 |
val read_term = gen_read (read_term_thy true) I false false; |
611 |
val read_prop = gen_read (read_prop_thy true) I false false; |
|
612 |
val read_prop_schematic = gen_read (read_prop_thy true) I false true; |
|
613 |
val read_terms = gen_read (read_terms_thy true) map false false; |
|
614 |
fun read_props schematic = gen_read (read_props_thy true) map false schematic; |
|
5819 | 615 |
|
10554 | 616 |
end; |
617 |
||
5819 | 618 |
|
619 |
(* certify terms *) |
|
620 |
||
10554 | 621 |
local |
622 |
||
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
623 |
fun gen_cert cert pattern schematic ctxt t = t |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
624 |
|> (if pattern then I else norm_term ctxt schematic) |
16458 | 625 |
|> (fn t' => cert (pp ctxt) (theory_of ctxt) t' |
16501 | 626 |
handle TYPE (msg, _, _) => raise CONTEXT (msg, ctxt) |
627 |
| TERM (msg, _) => raise CONTEXT (msg, ctxt)); |
|
628 |
||
629 |
val certify_term = #1 ooo Sign.certify_term; |
|
630 |
val certify_prop = #1 ooo Sign.certify_prop; |
|
5819 | 631 |
|
10554 | 632 |
in |
8096 | 633 |
|
16501 | 634 |
val cert_term = gen_cert certify_term false false; |
635 |
val cert_prop = gen_cert certify_prop false false; |
|
636 |
val cert_props = map oo gen_cert certify_prop false; |
|
10554 | 637 |
|
16501 | 638 |
fun cert_term_pats _ = map o gen_cert certify_term true false; |
639 |
val cert_prop_pats = map o gen_cert certify_prop true false; |
|
10554 | 640 |
|
641 |
end; |
|
5819 | 642 |
|
643 |
||
644 |
(* declare terms *) |
|
645 |
||
10381 | 646 |
local |
647 |
||
16861 | 648 |
val ins_types = fold_aterms |
17412 | 649 |
(fn Free (x, T) => Vartab.update ((x, ~1), T) |
650 |
| Var v => Vartab.update v |
|
16861 | 651 |
| _ => I); |
5819 | 652 |
|
16861 | 653 |
val ins_sorts = fold_types (fold_atyps |
17412 | 654 |
(fn TFree (x, S) => Vartab.update ((x, ~1), S) |
655 |
| TVar v => Vartab.update v |
|
16861 | 656 |
| _ => I)); |
5819 | 657 |
|
16861 | 658 |
val ins_used = fold_term_types (fn t => |
659 |
fold_atyps (fn TFree (x, _) => insert (op =) x | _ => I)); |
|
12291 | 660 |
|
16861 | 661 |
val ins_occs = fold_term_types (fn t => |
17412 | 662 |
fold_atyps (fn TFree (x, _) => Symtab.update_multi (x, t) | _ => I)); |
5819 | 663 |
|
16861 | 664 |
fun ins_skolem def_ty = fold_rev (fn (x, x') => |
665 |
(case def_ty x' of |
|
17412 | 666 |
SOME T => Vartab.update ((x, ~1), T) |
16861 | 667 |
| NONE => I)); |
5994 | 668 |
|
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
669 |
in |
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
670 |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
671 |
fun declare_syntax t = |
18340 | 672 |
map_defaults (fn (types, sorts, used, occ) => (ins_types t types, sorts, used, occ)) |
673 |
#> map_defaults (fn (types, sorts, used, occ) => (types, ins_sorts t sorts, used, occ)) |
|
674 |
#> map_defaults (fn (types, sorts, used, occ) => (types, sorts, ins_used t used, occ)); |
|
10381 | 675 |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
676 |
fun declare_var (x, opt_T, mx) = |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
677 |
declare_syntax (Free (x, case opt_T of SOME T => T | NONE => TypeInfer.mixfixT mx)); |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
678 |
|
16540 | 679 |
fun declare_term t ctxt = |
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
680 |
ctxt |
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
681 |
|> declare_syntax t |
16861 | 682 |
|> map_defaults (fn (types, sorts, used, occ) => (types, sorts, used, ins_occs t occ)) |
12291 | 683 |
|> map_defaults (fn (types, sorts, used, occ) => |
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
684 |
(ins_skolem (fn x => Vartab.lookup types (x, ~1)) (fixes_of ctxt) types, sorts, used, occ)); |
5819 | 685 |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
686 |
fun inferred_type x ctxt = |
18619 | 687 |
let val T = infer_type ctxt x |
688 |
in ((x, T), ctxt |> declare_term (Free (x, T))) end; |
|
689 |
||
10381 | 690 |
end; |
5819 | 691 |
|
692 |
||
15703 | 693 |
(* type and constant names *) |
694 |
||
695 |
fun read_tyname ctxt c = |
|
18340 | 696 |
if member (op =) (used_types ctxt) c then |
18187 | 697 |
TFree (c, the_default (Sign.defaultS (theory_of ctxt)) (def_sort ctxt (c, ~1))) |
16458 | 698 |
else Sign.read_tyname (theory_of ctxt) c; |
15703 | 699 |
|
700 |
fun read_const ctxt c = |
|
701 |
(case lookup_skolem ctxt c of |
|
702 |
SOME c' => Free (c', dummyT) |
|
16458 | 703 |
| NONE => Sign.read_const (theory_of ctxt) c); |
15703 | 704 |
|
705 |
||
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
706 |
|
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
707 |
(** Hindley-Milner polymorphism **) |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
708 |
|
7925 | 709 |
(* warn_extra_tfrees *) |
710 |
||
16540 | 711 |
fun warn_extra_tfrees ctxt1 ctxt2 = |
12130
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
712 |
let |
17451 | 713 |
fun occs_typ a (Type (_, Ts)) = exists (occs_typ a) Ts |
714 |
| occs_typ a (TFree (b, _)) = a = b |
|
715 |
| occs_typ _ (TVar _) = false; |
|
716 |
fun occs_free a (Free (x, _)) = |
|
717 |
(case def_type ctxt1 false (x, ~1) of |
|
718 |
SOME T => if occs_typ a T then I else cons (a, x) |
|
719 |
| NONE => cons (a, x)) |
|
720 |
| occs_free _ _ = I; |
|
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
721 |
|
17451 | 722 |
val occs1 = type_occs_of ctxt1 and occs2 = type_occs_of ctxt2; |
723 |
val extras = Symtab.fold (fn (a, ts) => |
|
724 |
if Symtab.defined occs1 a then I else fold (occs_free a) ts) occs2 []; |
|
18428 | 725 |
val tfrees = map #1 extras |> sort_distinct string_ord; |
726 |
val frees = map #2 extras |> sort_distinct string_ord; |
|
12130
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
727 |
in |
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
728 |
if null extras then () |
17451 | 729 |
else warning ("Introduced fixed type variable(s): " ^ commas tfrees ^ " in " ^ |
17860
b4cf247ea0d2
note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents:
17756
diff
changeset
|
730 |
space_implode " or " (map (string_of_term ctxt2 o Syntax.free) frees)); |
12130
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
731 |
ctxt2 |
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
732 |
end; |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
733 |
|
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
734 |
|
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
735 |
(* generalize type variables *) |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
736 |
|
12550
32843ad8160a
generalize type variables properly: start with occurrences in objects
wenzelm
parents:
12530
diff
changeset
|
737 |
fun generalize_tfrees inner outer = |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
738 |
let |
12057 | 739 |
val extra_fixes = fixed_names_of inner \\ fixed_names_of outer; |
18340 | 740 |
fun still_fixed (Free (x, _)) = not (member (op =) extra_fixes x) |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
741 |
| still_fixed _ = false; |
16540 | 742 |
val occs_inner = type_occs_of inner; |
743 |
val occs_outer = type_occs_of outer; |
|
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
744 |
fun add a gen = |
16894 | 745 |
if Symtab.defined occs_outer a orelse |
17412 | 746 |
exists still_fixed (Symtab.lookup_multi occs_inner a) |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
747 |
then gen else a :: gen; |
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
748 |
in fn tfrees => fold add tfrees [] end; |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
749 |
|
12550
32843ad8160a
generalize type variables properly: start with occurrences in objects
wenzelm
parents:
12530
diff
changeset
|
750 |
fun generalize inner outer ts = |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
751 |
let |
18187 | 752 |
val tfrees = generalize_tfrees inner outer (map #1 (fold Term.add_tfrees ts [])); |
18340 | 753 |
fun gen (x, S) = if member (op =) tfrees x then TVar ((x, 0), S) else TFree (x, S); |
12550
32843ad8160a
generalize type variables properly: start with occurrences in objects
wenzelm
parents:
12530
diff
changeset
|
754 |
in map (Term.map_term_types (Term.map_type_tfree gen)) ts end; |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
755 |
|
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
756 |
|
9553 | 757 |
|
758 |
(** export theorems **) |
|
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
759 |
|
18042 | 760 |
fun common_exports is_goal inner outer = |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
761 |
let |
12550
32843ad8160a
generalize type variables properly: start with occurrences in objects
wenzelm
parents:
12530
diff
changeset
|
762 |
val gen = generalize_tfrees inner outer; |
12057 | 763 |
val fixes = fixed_names_of inner \\ fixed_names_of outer; |
764 |
val asms = Library.drop (length (assumptions_of outer), assumptions_of inner); |
|
11816 | 765 |
val exp_asms = map (fn (cprops, exp) => exp is_goal cprops) asms; |
16948 | 766 |
in |
18255 | 767 |
Goal.norm_hhf_protect |
16948 | 768 |
#> Seq.EVERY (rev exp_asms) |
769 |
#> Seq.map (fn rule => |
|
11816 | 770 |
let |
16992 | 771 |
val thy = Thm.theory_of_thm rule; |
772 |
val prop = Thm.full_prop_of rule; |
|
18152 | 773 |
val frees = map (Thm.cterm_of thy) (List.mapPartial (Term.find_free prop) fixes); |
12550
32843ad8160a
generalize type variables properly: start with occurrences in objects
wenzelm
parents:
12530
diff
changeset
|
774 |
val tfrees = gen (Term.add_term_tfree_names (prop, [])); |
11816 | 775 |
in |
776 |
rule |
|
777 |
|> Drule.forall_intr_list frees |
|
18255 | 778 |
|> Goal.norm_hhf_protect |
18138 | 779 |
|> Drule.tvars_intr_list tfrees |> #2 |
11816 | 780 |
end) |
781 |
end; |
|
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
782 |
|
18122 | 783 |
fun export inner outer = |
784 |
let val exp = common_exports false inner outer in |
|
13378 | 785 |
fn th => |
18122 | 786 |
(case Seq.pull (exp th) of |
15531 | 787 |
SOME (th', _) => th' |> Drule.local_standard |
16850 | 788 |
| NONE => sys_error "Failed to export theorem") |
13378 | 789 |
end; |
12704 | 790 |
|
18122 | 791 |
val exports = common_exports false; |
792 |
val goal_exports = common_exports true; |
|
7925 | 793 |
|
5819 | 794 |
|
15758
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
795 |
|
5819 | 796 |
(** bindings **) |
797 |
||
15758
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
798 |
(* delete_update_binds *) |
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
799 |
|
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
800 |
local |
5819 | 801 |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
802 |
val del_bind = map_binds o Vartab.delete_safe; |
7606 | 803 |
|
15758
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
804 |
fun upd_bind ((x, i), t) = |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
805 |
let |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
806 |
val T = Term.fastype_of t; |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
807 |
val t' = |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
808 |
if null (Term.term_tvars t \\ Term.typ_tvars T) then t |
8637 | 809 |
else Var ((x ^ "_has_extra_type_vars_on_rhs", i), T); |
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
810 |
in declare_term t' #> map_binds (Vartab.update ((x, i), (t', T))) end; |
5819 | 811 |
|
15758
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
812 |
fun del_upd_bind (xi, NONE) = del_bind xi |
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
813 |
| del_upd_bind (xi, SOME t) = upd_bind (xi, t); |
7606 | 814 |
|
15758
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
815 |
in |
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
816 |
|
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
817 |
val delete_update_binds = fold del_upd_bind; |
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
818 |
|
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
819 |
end; |
7606 | 820 |
|
5819 | 821 |
|
8096 | 822 |
(* simult_matches *) |
823 |
||
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
824 |
fun simult_matches ctxt [] = [] |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
825 |
| simult_matches ctxt pairs = |
8096 | 826 |
let |
10554 | 827 |
fun fail () = raise CONTEXT ("Pattern match failed!", ctxt); |
828 |
||
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
829 |
val maxidx = fold (fn (t1, t2) => fn i => |
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
830 |
Int.max (Int.max (Term.maxidx_of_term t1, Term.maxidx_of_term t2), i)) pairs ~1; |
16458 | 831 |
val envs = Unify.smash_unifiers (theory_of ctxt, Envir.empty maxidx, |
10554 | 832 |
map swap pairs); (*prefer assignment of variables from patterns*) |
833 |
val env = |
|
8096 | 834 |
(case Seq.pull envs of |
15531 | 835 |
NONE => fail () |
836 |
| SOME (env, _) => env); (*ignore further results*) |
|
12309
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
837 |
val domain = |
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
838 |
filter_out Term.is_replaced_dummy_pattern (map #1 (Drule.vars_of_terms (map #1 pairs))); |
10554 | 839 |
val _ = (*may not assign variables from text*) |
12309
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
840 |
if null (map #1 (Envir.alist_of env) inter (map #1 (Drule.vars_of_terms (map #2 pairs)))) |
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
841 |
then () else fail (); |
16948 | 842 |
fun norm_bind (xi, (_, t)) = |
18310 | 843 |
if member (op =) domain xi then SOME (xi, Envir.norm_term env t) else NONE; |
15570 | 844 |
in List.mapPartial norm_bind (Envir.alist_of env) end; |
8096 | 845 |
|
846 |
||
847 |
(* add_binds(_i) *) |
|
5819 | 848 |
|
7925 | 849 |
local |
850 |
||
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
851 |
fun gen_bind prep (xi as (x, _), raw_t) ctxt = |
15570 | 852 |
ctxt |> delete_update_binds [(xi, Option.map (prep ctxt) raw_t)]; |
5819 | 853 |
|
10810 | 854 |
in |
855 |
||
15531 | 856 |
fun drop_schematic (b as (xi, SOME t)) = if null (Term.term_vars t) then b else (xi, NONE) |
10554 | 857 |
| drop_schematic b = b; |
858 |
||
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
859 |
val add_binds = fold (gen_bind read_term); |
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
860 |
val add_binds_i = fold (gen_bind cert_term); |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
861 |
|
16458 | 862 |
fun auto_bind f ts ctxt = ctxt |> add_binds_i (map drop_schematic (f (theory_of ctxt) ts)); |
12147 | 863 |
val auto_bind_goal = auto_bind AutoBind.goal; |
864 |
val auto_bind_facts = auto_bind AutoBind.facts; |
|
7925 | 865 |
|
866 |
end; |
|
5819 | 867 |
|
868 |
||
8096 | 869 |
(* match_bind(_i) *) |
5819 | 870 |
|
8096 | 871 |
local |
872 |
||
17860
b4cf247ea0d2
note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents:
17756
diff
changeset
|
873 |
fun prep_bind prep_pats (raw_pats, t) ctxt = |
5819 | 874 |
let |
8096 | 875 |
val ctxt' = declare_term t ctxt; |
876 |
val pats = prep_pats (fastype_of t) ctxt' raw_pats; |
|
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
877 |
val binds = simult_matches ctxt' (map (rpair t) pats); |
17860
b4cf247ea0d2
note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents:
17756
diff
changeset
|
878 |
in (binds, ctxt') end; |
7670 | 879 |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
880 |
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
|
881 |
let |
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
882 |
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
|
883 |
val (binds, ctxt') = |
b4cf247ea0d2
note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents:
17756
diff
changeset
|
884 |
apfst List.concat (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
|
885 |
val binds' = |
12550
32843ad8160a
generalize type variables properly: start with occurrences in objects
wenzelm
parents:
12530
diff
changeset
|
886 |
if gen then map #1 binds ~~ generalize ctxt' ctxt (map #2 binds) |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
887 |
else binds; |
15531 | 888 |
val binds'' = map (apsnd SOME) binds'; |
18310 | 889 |
val ctxt'' = |
890 |
warn_extra_tfrees ctxt |
|
891 |
(if gen then |
|
892 |
ctxt (*sic!*) |> fold declare_term (map #2 binds') |> add_binds_i binds'' |
|
893 |
else ctxt' |> add_binds_i binds''); |
|
894 |
in (ts, ctxt'') end; |
|
8096 | 895 |
|
896 |
in |
|
5935 | 897 |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
898 |
val match_bind = gen_binds read_terms read_term_pats; |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
899 |
val match_bind_i = gen_binds (map o cert_term) cert_term_pats; |
8096 | 900 |
|
901 |
end; |
|
5935 | 902 |
|
903 |
||
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
904 |
(* propositions with patterns *) |
5935 | 905 |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
906 |
local |
8096 | 907 |
|
10554 | 908 |
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
|
909 |
let |
17860
b4cf247ea0d2
note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents:
17756
diff
changeset
|
910 |
fun prep (_, (raw_pats1, raw_pats2)) (ctxt, prop :: props) = |
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
911 |
let |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
912 |
val ctxt' = declare_term prop ctxt; |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
913 |
val pats = prep_pats ctxt' (raw_pats1 @ raw_pats2); (*simultaneous type inference!*) |
17860
b4cf247ea0d2
note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents:
17756
diff
changeset
|
914 |
in ((prop, splitAt (length raw_pats1, pats)), (ctxt', props)) end |
b4cf247ea0d2
note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents:
17756
diff
changeset
|
915 |
| prep _ _ = sys_error "prep_propp"; |
b4cf247ea0d2
note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents:
17756
diff
changeset
|
916 |
val (propp, (context', _)) = (fold_map o fold_map) prep args |
b4cf247ea0d2
note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents:
17756
diff
changeset
|
917 |
(context, prep_props schematic context (List.concat (map (map fst) args))); |
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
918 |
in (context', propp) end; |
5935 | 919 |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
920 |
fun matches ctxt (prop, (pats1, pats2)) = |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
921 |
simult_matches ctxt (map (rpair prop) pats1 @ map (rpair (Logic.strip_imp_concl prop)) pats2); |
8096 | 922 |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
923 |
fun gen_bind_propp prepp (ctxt, raw_args) = |
8096 | 924 |
let |
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
925 |
val (ctxt', args) = prepp (ctxt, raw_args); |
15570 | 926 |
val binds = List.concat (List.concat (map (map (matches ctxt')) args)); |
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
927 |
val propss = map (map #1) args; |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
928 |
|
10554 | 929 |
(*generalize result: context evaluated now, binds added later*) |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
930 |
val gen = generalize ctxt' ctxt; |
15531 | 931 |
fun gen_binds c = c |> add_binds_i (map #1 binds ~~ map SOME (gen (map #2 binds))); |
932 |
in (ctxt' |> add_binds_i (map (apsnd SOME) binds), (propss, gen_binds)) end; |
|
8096 | 933 |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
934 |
in |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
935 |
|
11925 | 936 |
val read_propp = prep_propp false read_props read_prop_pats; |
937 |
val cert_propp = prep_propp false cert_props cert_prop_pats; |
|
10554 | 938 |
val read_propp_schematic = prep_propp true read_props read_prop_pats; |
939 |
val cert_propp_schematic = prep_propp true cert_props cert_prop_pats; |
|
940 |
||
11925 | 941 |
val bind_propp = gen_bind_propp read_propp; |
942 |
val bind_propp_i = gen_bind_propp cert_propp; |
|
943 |
val bind_propp_schematic = gen_bind_propp read_propp_schematic; |
|
10554 | 944 |
val bind_propp_schematic_i = gen_bind_propp cert_propp_schematic; |
6789 | 945 |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
946 |
end; |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
947 |
|
6789 | 948 |
|
5819 | 949 |
|
950 |
(** theorems **) |
|
951 |
||
18042 | 952 |
(* fact_tac *) |
953 |
||
18122 | 954 |
fun comp_incr_tac [] _ st = no_tac st |
955 |
| comp_incr_tac (th :: ths) i st = |
|
956 |
(Goal.compose_hhf_tac (Drule.incr_indexes st th) i APPEND comp_incr_tac ths i) st; |
|
18042 | 957 |
|
18122 | 958 |
fun fact_tac facts = Tactic.norm_hhf_tac THEN' comp_incr_tac facts; |
959 |
||
960 |
fun some_fact_tac ctxt = SUBGOAL (fn (goal, i) => |
|
18042 | 961 |
let |
962 |
val (_, _, index) = thms_of ctxt; |
|
963 |
val facts = FactIndex.could_unify index (Term.strip_all_body goal); |
|
964 |
in fact_tac facts i end); |
|
965 |
||
966 |
||
6091 | 967 |
(* get_thm(s) *) |
5819 | 968 |
|
18042 | 969 |
fun retrieve_thms _ pick ctxt (Fact s) = |
16501 | 970 |
let |
18042 | 971 |
val thy = theory_of ctxt; |
972 |
val th = Goal.prove thy [] [] (read_prop ctxt s) (K (ALLGOALS (some_fact_tac ctxt))) |
|
973 |
handle ERROR_MESSAGE msg => |
|
974 |
raise CONTEXT (msg ^ "\nFailed to retrieve literal fact.", ctxt); |
|
975 |
in pick "" [th] end |
|
976 |
| retrieve_thms from_thy pick ctxt xthmref = |
|
977 |
let |
|
978 |
val thy = theory_of ctxt; |
|
979 |
val (_, (space, tab), _) = thms_of ctxt; |
|
16501 | 980 |
val thmref = PureThy.map_name_of_thmref (NameSpace.intern space) xthmref; |
981 |
val name = PureThy.name_of_thmref thmref; |
|
982 |
in |
|
17412 | 983 |
(case Symtab.lookup tab name of |
16540 | 984 |
SOME ths => map (Thm.transfer thy) (PureThy.select_thm thmref ths) |
985 |
| NONE => from_thy thy xthmref) |> pick name |
|
18042 | 986 |
end; |
5819 | 987 |
|
9566 | 988 |
val get_thm = retrieve_thms PureThy.get_thms PureThy.single_thm; |
989 |
val get_thm_closure = retrieve_thms PureThy.get_thms_closure PureThy.single_thm; |
|
990 |
val get_thms = retrieve_thms PureThy.get_thms (K I); |
|
991 |
val get_thms_closure = retrieve_thms PureThy.get_thms_closure (K I); |
|
5819 | 992 |
|
993 |
||
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
994 |
(* valid_thms *) |
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
995 |
|
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
996 |
fun valid_thms ctxt (name, ths) = |
16501 | 997 |
(case try (transform_error (fn () => get_thms ctxt (Name name))) () of |
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
998 |
NONE => false |
16147 | 999 |
| SOME ths' => Thm.eq_thms (ths, ths')); |
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
1000 |
|
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
1001 |
|
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
1002 |
(* lthms_containing *) |
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
1003 |
|
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
1004 |
fun lthms_containing ctxt spec = |
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
1005 |
FactIndex.find (fact_index_of ctxt) spec |
18043 | 1006 |
|> map ((not o valid_thms ctxt) ? apfst (fn name => |
18042 | 1007 |
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
|
1008 |
|
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
1009 |
|
13425
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
1010 |
(* name space operations *) |
12309
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
1011 |
|
16540 | 1012 |
val extern_thm = NameSpace.extern o #1 o #2 o thms_of; |
12309
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
1013 |
|
16147 | 1014 |
val qualified_names = map_naming NameSpace.qualified_names; |
1015 |
val no_base_names = map_naming NameSpace.no_base_names; |
|
1016 |
val custom_accesses = map_naming o NameSpace.custom_accesses; |
|
16540 | 1017 |
val restore_naming = map_naming o K o #1 o thms_of; |
12309
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
1018 |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1019 |
fun hide_thms fully names = map_thms (fn (naming, (space, tab), index) => |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1020 |
(naming, (fold (NameSpace.hide fully) names space, tab), index)); |
13425
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
1021 |
|
12309
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
1022 |
|
17360
fa1f262dbc4e
added add_view, export_view (supercedes adhoc view arguments);
wenzelm
parents:
17221
diff
changeset
|
1023 |
(* put_thms *) |
5819 | 1024 |
|
18042 | 1025 |
fun put_thms ("", NONE) ctxt = ctxt |
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1026 |
| put_thms ("", SOME ths) ctxt = ctxt |> map_thms (fn (naming, facts, index) => |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1027 |
let |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1028 |
val index' = FactIndex.add_local (is_known ctxt) ("", ths) index; |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1029 |
in (naming, facts, index') end) |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1030 |
| put_thms (bname, NONE) ctxt = ctxt |> map_thms (fn (naming, (space, tab), index) => |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1031 |
let |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1032 |
val name = NameSpace.full naming bname; |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1033 |
val tab' = Symtab.delete_safe name tab; |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1034 |
in (naming, (space, tab'), index) end) |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1035 |
| put_thms (bname, SOME ths) ctxt = ctxt |> map_thms (fn (naming, (space, tab), index) => |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1036 |
let |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1037 |
val name = NameSpace.full naming bname; |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1038 |
val space' = NameSpace.declare naming name space; |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1039 |
val tab' = Symtab.update (name, ths) tab; |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1040 |
val index' = FactIndex.add_local (is_known ctxt) (name, ths) index; |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1041 |
in (naming, (space', tab'), index') end); |
5819 | 1042 |
|
7606 | 1043 |
|
14564 | 1044 |
(* note_thmss *) |
5819 | 1045 |
|
12711 | 1046 |
local |
16147 | 1047 |
|
17860
b4cf247ea0d2
note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents:
17756
diff
changeset
|
1048 |
fun gen_note_thmss get = fold_map (fn ((name, more_attrs), ths_attrs) => fn ctxt => |
5819 | 1049 |
let |
17360
fa1f262dbc4e
added add_view, export_view (supercedes adhoc view arguments);
wenzelm
parents:
17221
diff
changeset
|
1050 |
fun app (th, attrs) (ct, ths) = |
18418
bf448d999b7e
re-arranged tuples (theory * 'a) to ('a * theory) in Pure
haftmann
parents:
18375
diff
changeset
|
1051 |
let val (ct', th') = Thm.applys_attributes (attrs @ more_attrs) (ct, get ctxt th) |
12711 | 1052 |
in (ct', th' :: ths) end; |
17360
fa1f262dbc4e
added add_view, export_view (supercedes adhoc view arguments);
wenzelm
parents:
17221
diff
changeset
|
1053 |
val (ctxt', rev_thms) = fold app ths_attrs (ctxt, []); |
15570 | 1054 |
val thms = List.concat (rev rev_thms); |
17860
b4cf247ea0d2
note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents:
17756
diff
changeset
|
1055 |
in ((name, thms), ctxt' |> put_thms (name, SOME thms)) end); |
12711 | 1056 |
|
1057 |
in |
|
1058 |
||
16147 | 1059 |
val note_thmss = gen_note_thmss get_thms; |
1060 |
val note_thmss_i = gen_note_thmss (K I); |
|
15696 | 1061 |
|
1062 |
val note_thmss_accesses = gen_note_thmss get_thms; |
|
1063 |
val note_thmss_accesses_i = gen_note_thmss (K I); |
|
12711 | 1064 |
|
1065 |
end; |
|
9196 | 1066 |
|
5819 | 1067 |
|
1068 |
||
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1069 |
(** parameters **) |
17360
fa1f262dbc4e
added add_view, export_view (supercedes adhoc view arguments);
wenzelm
parents:
17221
diff
changeset
|
1070 |
|
8096 | 1071 |
(* variables *) |
1072 |
||
10381 | 1073 |
local |
1074 |
||
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1075 |
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
|
1076 |
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
|
1077 |
let |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1078 |
val x = Syntax.const_name raw_x raw_mx; |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1079 |
val mx = Syntax.fix_mixfix raw_x raw_mx; |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1080 |
val _ = |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1081 |
if not legacy andalso not (Syntax.is_identifier (no_skolem internal ctxt x)) then |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1082 |
raise CONTEXT ("Illegal variable name: " ^ quote x, ctxt) |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1083 |
else (); |
12504 | 1084 |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1085 |
fun cond_tvars T = |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1086 |
if internal then T |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1087 |
else Type.no_tvars T handle TYPE (msg, _, _) => raise CONTEXT (msg, ctxt); |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1088 |
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
|
1089 |
val var = (x, opt_T, mx); |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1090 |
in (var, ctxt |> declare_var var) end); |
8096 | 1091 |
|
10381 | 1092 |
in |
1093 |
||
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1094 |
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
|
1095 |
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
|
1096 |
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
|
1097 |
val cert_vars_legacy = prep_vars cert_typ true true; |
8096 | 1098 |
|
10381 | 1099 |
end; |
1100 |
||
8096 | 1101 |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1102 |
(* fixes *) |
5819 | 1103 |
|
8096 | 1104 |
local |
1105 |
||
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1106 |
fun no_dups _ [] = () |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1107 |
| no_dups ctxt dups = raise CONTEXT ("Duplicate variable(s): " ^ commas_quote dups, ctxt); |
11925 | 1108 |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1109 |
fun gen_fixes prep raw_vars ctxt = |
8096 | 1110 |
let |
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1111 |
val (ys, zs) = split_list (fixes_of ctxt); |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1112 |
val (vars, ctxt') = prep raw_vars ctxt; |
12130
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
1113 |
val xs = map #1 vars; |
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1114 |
val _ = no_dups ctxt (duplicates xs); |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1115 |
val xs' = |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1116 |
if is_body ctxt then Term.variantlist (map Syntax.skolem xs, zs) |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1117 |
else (no_dups ctxt (xs inter_string ys); no_dups ctxt (xs inter_string zs); xs); |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1118 |
val vars' = map2 (fn x' => fn (_, T, mx) => (x', T, mx)) xs' vars; |
8096 | 1119 |
in |
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1120 |
ctxt' |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1121 |
|> map_fixes (fn (b, fixes) => (b, rev (xs ~~ xs') @ fixes)) |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1122 |
|> add_syntax vars' |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1123 |
|> fold declare_var vars' |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1124 |
|> pair xs' |
8096 | 1125 |
end; |
5819 | 1126 |
|
8096 | 1127 |
in |
7679 | 1128 |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1129 |
val add_fixes = gen_fixes read_vars; |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1130 |
val add_fixes_i = gen_fixes cert_vars; |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1131 |
val add_fixes_legacy = gen_fixes cert_vars_legacy; |
8096 | 1132 |
|
1133 |
end; |
|
5819 | 1134 |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1135 |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1136 |
(* fixes vs. frees *) |
12016 | 1137 |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1138 |
fun fix_frees t ctxt = |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1139 |
let |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1140 |
fun add (Free (x, T)) = if is_fixed ctxt x then I else insert (op =) (x, SOME T, NoSyn) |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1141 |
| add _ = I; |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1142 |
val fixes = rev (fold_aterms add t []); |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1143 |
in snd (add_fixes_i fixes ctxt) end; |
6895 | 1144 |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1145 |
fun auto_fixes (arg as (ctxt, (propss, x))) = |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1146 |
if is_body ctxt then arg |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1147 |
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
|
1148 |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1149 |
fun bind_fixes xs ctxt = |
9291
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1150 |
let |
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1151 |
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
|
1152 |
fun bind (t as Free (x, T)) = |
18340 | 1153 |
if member (op =) xs x then |
15531 | 1154 |
(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
|
1155 |
else t |
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1156 |
| bind (t $ u) = bind t $ bind u |
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1157 |
| 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
|
1158 |
| bind a = a; |
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1159 |
in (bind, ctxt') end; |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1160 |
|
9291
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1161 |
|
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1162 |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1163 |
(** assumptions **) |
18187 | 1164 |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1165 |
(* generic assms *) |
18187 | 1166 |
|
1167 |
local |
|
1168 |
||
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1169 |
fun gen_assm ((name, attrs), props) ctxt = |
18187 | 1170 |
let |
1171 |
val cprops = map (Thm.cterm_of (theory_of ctxt)) props; |
|
1172 |
val asms = map (Goal.norm_hhf o Thm.assume) cprops; |
|
1173 |
||
1174 |
val ths = map (fn th => ([th], [])) asms; |
|
1175 |
val ([(_, thms)], ctxt') = |
|
1176 |
ctxt |
|
1177 |
|> auto_bind_facts props |
|
1178 |
|> note_thmss_i [((name, attrs), ths)]; |
|
1179 |
in ((cprops, (name, asms), (name, thms)), ctxt') end; |
|
1180 |
||
1181 |
fun gen_assms prepp exp args ctxt = |
|
1182 |
let |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1183 |
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
|
1184 |
val (results, ctxt2) = fold_map gen_assm (map fst args ~~ propss) ctxt1; |
18187 | 1185 |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1186 |
val new_asms = List.concat (map #1 results); |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1187 |
val new_prems = map #2 results; |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1188 |
val ctxt3 = ctxt2 |> map_assms (fn (asms, prems) => (asms @ [(new_asms, exp)], prems @ new_prems)) |
18187 | 1189 |
val ctxt4 = ctxt3 |> put_thms ("prems", SOME (prems_of ctxt3)); |
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1190 |
in (map #3 results, warn_extra_tfrees ctxt ctxt4) end; |
18187 | 1191 |
|
1192 |
in |
|
1193 |
||
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1194 |
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
|
1195 |
val add_assms_i = gen_assms (apsnd #1 o bind_propp_i); |
18187 | 1196 |
|
1197 |
end; |
|
1198 |
||
1199 |
||
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1200 |
(* basic assumptions *) |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1201 |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1202 |
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
|
1203 |
| 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
|
1204 |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1205 |
fun presume_export _ = assume_export false; |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1206 |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1207 |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1208 |
(* additional views *) |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1209 |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1210 |
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
|
1211 |
let |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1212 |
val (asms1, asms2) = splitAt (length (assumptions_of outer), asms); |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1213 |
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
|
1214 |
in (asms', prems) end); |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1215 |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1216 |
fun export_view view inner outer = export (add_view outer view inner) outer; |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1217 |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1218 |
|
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1219 |
(* definitions *) |
18187 | 1220 |
|
18310 | 1221 |
fun mk_def ctxt args = |
1222 |
let |
|
1223 |
val (xs, rhss) = split_list args; |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1224 |
val (bind, _) = bind_fixes xs ctxt; |
18310 | 1225 |
val lhss = map (fn (x, rhs) => bind (Free (x, Term.fastype_of rhs))) args; |
1226 |
in map Logic.mk_equals (lhss ~~ rhss) end; |
|
18187 | 1227 |
|
1228 |
fun cert_def ctxt eq = |
|
1229 |
let |
|
1230 |
fun err msg = raise CONTEXT (msg ^ |
|
1231 |
"\nThe error(s) above occurred in local definition: " ^ string_of_term ctxt eq, ctxt); |
|
1232 |
val (lhs, rhs) = Logic.dest_equals (Term.strip_all_body eq) |
|
1233 |
handle TERM _ => err "Not a meta-equality (==)"; |
|
18340 | 1234 |
val (f, xs) = Term.strip_comb (Pattern.beta_eta_contract lhs); |
18187 | 1235 |
val (c, _) = Term.dest_Free f handle TERM _ => |
1236 |
err "Head of lhs must be a free/fixed variable"; |
|
1237 |
||
1238 |
fun is_free (Free (x, _)) = not (is_fixed ctxt x) |
|
1239 |
| is_free _ = false; |
|
1240 |
val extra_frees = List.filter is_free (term_frees rhs) \\ xs; |
|
1241 |
in |
|
1242 |
conditional (not (forall (is_Bound orf is_free) xs andalso null (duplicates xs))) (fn () => |
|
1243 |
err "Arguments of lhs must be distinct free/bound variables"); |
|
1244 |
conditional (f mem Term.term_frees rhs) (fn () => |
|
1245 |
err "Element to be defined occurs on rhs"); |
|
1246 |
conditional (not (null extra_frees)) (fn () => |
|
1247 |
err ("Extra free variables on rhs: " ^ commas_quote (map (#1 o dest_Free) extra_frees))); |
|
1248 |
(c, Term.list_all_free (List.mapPartial (try Term.dest_Free) xs, eq)) |
|
1249 |
end; |
|
1250 |
||
1251 |
fun head_of_def cprop = |
|
1252 |
#1 (Term.strip_comb (#1 (Logic.dest_equals (Term.strip_all_body (Thm.term_of cprop))))) |
|
1253 |
|> Thm.cterm_of (Thm.theory_of_cterm cprop); |
|
1254 |
||
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1255 |
fun def_export _ cprops thm = |
18187 | 1256 |
thm |
1257 |
|> Drule.implies_intr_list cprops |
|
1258 |
|> Drule.forall_intr_list (map head_of_def cprops) |
|
1259 |
|> Drule.forall_elim_vars 0 |
|
1260 |
|> RANGE (replicate (length cprops) (Tactic.rtac Drule.reflexive_thm)) 1; |
|
1261 |
||
1262 |
fun add_def (x, t) ctxt = |
|
1263 |
let |
|
18310 | 1264 |
val [eq] = mk_def ctxt [(x, t)]; |
18187 | 1265 |
val x' = Term.dest_Free (fst (Logic.dest_equals eq)); |
1266 |
in |
|
1267 |
ctxt |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1268 |
|> add_fixes_i [(x, NONE, NoSyn)] |> snd |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1269 |
|> add_assms_i def_export [(("", []), [(eq, ([], []))])] |
18187 | 1270 |
|>> (fn [(_, [th])] => (x', th)) |
1271 |
end; |
|
1272 |
||
1273 |
||
5819 | 1274 |
|
8373
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1275 |
(** cases **) |
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1276 |
|
16147 | 1277 |
local |
1278 |
||
16668 | 1279 |
fun rem_case name = remove (fn (x: string, (y, _)) => x = y) name; |
16147 | 1280 |
|
18476 | 1281 |
fun add_case _ ("", _) cases = cases |
1282 |
| add_case _ (name, NONE) cases = rem_case name cases |
|
1283 |
| add_case is_proper (name, SOME c) cases = (name, (c, is_proper)) :: rem_case name cases; |
|
16147 | 1284 |
|
18609 | 1285 |
fun prep_case ctxt name fxs c = |
1286 |
let |
|
1287 |
fun replace (opt_x :: xs) ((y, T) :: ys) = (the_default y opt_x, T) :: replace xs ys |
|
1288 |
| replace [] ys = ys |
|
1289 |
| replace (_ :: _) [] = raise CONTEXT ("Too many parameters for case " ^ quote name, ctxt); |
|
1290 |
val RuleCases.Case {fixes, assumes, binds, cases} = c; |
|
1291 |
val fixes' = replace fxs fixes; |
|
1292 |
val binds' = map drop_schematic binds; |
|
1293 |
in |
|
1294 |
if null (fold (Term.add_tvarsT o snd) fixes []) andalso |
|
1295 |
null (fold (fold Term.add_vars o snd) assumes []) then |
|
1296 |
RuleCases.Case {fixes = fixes', assumes = assumes, binds = binds', cases = cases} |
|
1297 |
else raise CONTEXT ("Illegal schematic variable(s) in case " ^ quote name, ctxt) |
|
1298 |
end; |
|
1299 |
||
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1300 |
fun fix (x, T) ctxt = |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1301 |
let |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1302 |
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
|
1303 |
val t = bind (Free (x, T)); |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1304 |
in (t, ctxt' |> declare_syntax t) end; |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1305 |
|
16147 | 1306 |
in |
1307 |
||
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1308 |
fun add_cases is_proper = map_cases o fold (add_case is_proper); |
18609 | 1309 |
|
1310 |
fun case_result c ctxt = |
|
1311 |
let |
|
1312 |
val RuleCases.Case {fixes, ...} = c; |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1313 |
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
|
1314 |
val RuleCases.Case {assumes, binds, cases, ...} = RuleCases.apply ts c; |
18609 | 1315 |
in |
1316 |
ctxt' |
|
1317 |
|> add_binds_i binds |
|
1318 |
|> add_cases true (map (apsnd SOME) cases) |
|
1319 |
|> pair (assumes, (binds, cases)) |
|
1320 |
end; |
|
1321 |
||
1322 |
val apply_case = apfst fst oo case_result; |
|
1323 |
||
16540 | 1324 |
fun get_case ctxt name xs = |
17184 | 1325 |
(case AList.lookup (op =) (cases_of ctxt) name of |
15531 | 1326 |
NONE => raise CONTEXT ("Unknown case: " ^ quote name, ctxt) |
18476 | 1327 |
| SOME (c, _) => prep_case ctxt name xs c); |
8373
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1328 |
|
16147 | 1329 |
end; |
8373
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1330 |
|
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1331 |
|
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1332 |
|
10810 | 1333 |
(** print context information **) |
1334 |
||
1335 |
val verbose = ref false; |
|
1336 |
fun verb f x = if ! verbose then f (x ()) else []; |
|
1337 |
||
1338 |
fun setmp_verbose f x = Library.setmp verbose true f x; |
|
1339 |
||
1340 |
fun pretty_items prt name items = |
|
1341 |
let |
|
1342 |
fun prt_itms (name, [x]) = Pretty.block [Pretty.str (name ^ ":"), Pretty.brk 1, prt x] |
|
1343 |
| prt_itms (name, xs) = Pretty.big_list (name ^ ":") (map prt xs); |
|
1344 |
in |
|
1345 |
if null items andalso not (! verbose) then [] |
|
1346 |
else [Pretty.big_list name (map prt_itms items)] |
|
1347 |
end; |
|
1348 |
||
1349 |
||
12072
4281198fb8cd
local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents:
12066
diff
changeset
|
1350 |
(* local syntax *) |
4281198fb8cd
local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents:
12066
diff
changeset
|
1351 |
|
12093 | 1352 |
val print_syntax = Syntax.print_syntax o syn_of; |
12072
4281198fb8cd
local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents:
12066
diff
changeset
|
1353 |
|
4281198fb8cd
local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents:
12066
diff
changeset
|
1354 |
|
10810 | 1355 |
(* term bindings *) |
1356 |
||
16540 | 1357 |
fun pretty_binds ctxt = |
10810 | 1358 |
let |
16540 | 1359 |
val binds = binds_of ctxt; |
12057 | 1360 |
fun prt_bind (xi, (t, T)) = pretty_term ctxt (Logic.mk_equals (Var (xi, T), t)); |
10810 | 1361 |
in |
15758
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
1362 |
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
|
1363 |
else [Pretty.big_list "term bindings:" (map prt_bind (Vartab.dest binds))] |
10810 | 1364 |
end; |
1365 |
||
1366 |
val print_binds = Pretty.writeln o Pretty.chunks o pretty_binds; |
|
1367 |
||
1368 |
||
1369 |
(* local theorems *) |
|
1370 |
||
16540 | 1371 |
fun pretty_lthms ctxt = |
1372 |
pretty_items (pretty_thm ctxt) "facts:" (NameSpace.extern_table (#2 (thms_of ctxt))); |
|
10810 | 1373 |
|
12057 | 1374 |
val print_lthms = Pretty.writeln o Pretty.chunks o pretty_lthms; |
10810 | 1375 |
|
1376 |
||
1377 |
(* local contexts *) |
|
1378 |
||
16540 | 1379 |
fun pretty_cases ctxt = |
10810 | 1380 |
let |
12057 | 1381 |
val prt_term = pretty_term ctxt; |
1382 |
||
10810 | 1383 |
fun prt_let (xi, t) = Pretty.block |
10818 | 1384 |
[Pretty.quote (prt_term (Var (xi, Term.fastype_of t))), Pretty.str " =", Pretty.brk 1, |
10810 | 1385 |
Pretty.quote (prt_term t)]; |
1386 |
||
13425
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
1387 |
fun prt_asm (a, ts) = Pretty.block (Pretty.breaks |
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
1388 |
((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
|
1389 |
|
10810 | 1390 |
fun prt_sect _ _ _ [] = [] |
1391 |
| prt_sect s sep prt xs = [Pretty.block (Pretty.breaks (Pretty.str s :: |
|
15570 | 1392 |
List.concat (Library.separate sep (map (Library.single o prt) xs))))]; |
10810 | 1393 |
|
18609 | 1394 |
fun prt_case (name, (fixes, (asms, (lets, cs)))) = Pretty.block (Pretty.fbreaks |
10810 | 1395 |
(Pretty.str (name ^ ":") :: |
11915 | 1396 |
prt_sect "fix" [] (Pretty.str o fst) fixes @ |
10810 | 1397 |
prt_sect "let" [Pretty.str "and"] prt_let |
15570 | 1398 |
(List.mapPartial (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
|
1399 |
(if forall (null o #2) asms then [] |
18609 | 1400 |
else prt_sect "assume" [Pretty.str "and"] prt_asm asms) @ |
1401 |
prt_sect "subcases:" [] (Pretty.str o fst) cs)); |
|
16540 | 1402 |
|
18476 | 1403 |
fun add_case (_, (_, false)) = I |
18609 | 1404 |
| add_case (name, (c as RuleCases.Case {fixes, ...}, true)) = |
1405 |
cons (name, (fixes, #1 (case_result c ctxt))); |
|
18476 | 1406 |
val cases = fold add_case (cases_of ctxt) []; |
10810 | 1407 |
in |
1408 |
if null cases andalso not (! verbose) then [] |
|
18476 | 1409 |
else [Pretty.big_list "cases:" (map prt_case cases)] |
10810 | 1410 |
end; |
1411 |
||
1412 |
val print_cases = Pretty.writeln o Pretty.chunks o pretty_cases; |
|
1413 |
||
1414 |
||
12057 | 1415 |
(* core context *) |
10810 | 1416 |
|
1417 |
val prems_limit = ref 10; |
|
1418 |
||
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1419 |
fun pretty_ctxt ctxt = |
10810 | 1420 |
let |
12057 | 1421 |
val prt_term = pretty_term ctxt; |
1422 |
||
12093 | 1423 |
(*structures*) |
1424 |
val (_, structs, _) = syntax_of ctxt; |
|
1425 |
val prt_structs = if null structs then [] |
|
1426 |
else [Pretty.block (Pretty.str "structures:" :: Pretty.brk 1 :: |
|
1427 |
Pretty.commas (map Pretty.str structs))]; |
|
1428 |
||
12057 | 1429 |
(*fixes*) |
1430 |
fun prt_fix (x, x') = |
|
1431 |
if x = x' then Pretty.str x |
|
1432 |
else Pretty.block [Pretty.str x, Pretty.str " =", Pretty.brk 1, prt_term (Syntax.free x')]; |
|
18340 | 1433 |
val fixes = |
1434 |
rev (filter_out ((can Syntax.dest_internal orf member (op =) structs) o #1) (fixes_of ctxt)); |
|
12093 | 1435 |
val prt_fixes = if null fixes then [] |
1436 |
else [Pretty.block (Pretty.str "fixed variables:" :: Pretty.brk 1 :: |
|
1437 |
Pretty.commas (map prt_fix fixes))]; |
|
12057 | 1438 |
|
1439 |
(*prems*) |
|
10810 | 1440 |
val limit = ! prems_limit; |
1441 |
val prems = prems_of ctxt; |
|
1442 |
val len = length prems; |
|
12093 | 1443 |
val prt_prems = if null prems then [] |
1444 |
else [Pretty.big_list "prems:" ((if len <= limit then [] else [Pretty.str "..."]) @ |
|
1445 |
map (pretty_thm ctxt) (Library.drop (len - limit, prems)))]; |
|
1446 |
||
1447 |
in prt_structs @ prt_fixes @ prt_prems end; |
|
10810 | 1448 |
|
1449 |
||
1450 |
(* main context *) |
|
1451 |
||
16540 | 1452 |
fun pretty_context ctxt = |
10810 | 1453 |
let |
12057 | 1454 |
val prt_term = pretty_term ctxt; |
1455 |
val prt_typ = pretty_typ ctxt; |
|
1456 |
val prt_sort = pretty_sort ctxt; |
|
10810 | 1457 |
|
1458 |
(*theory*) |
|
12057 | 1459 |
val pretty_thy = Pretty.block |
17384 | 1460 |
[Pretty.str "theory:", Pretty.brk 1, Context.pretty_thy (theory_of ctxt)]; |
10810 | 1461 |
|
1462 |
(*defaults*) |
|
1463 |
fun prt_atom prt prtT (x, X) = Pretty.block |
|
1464 |
[prt x, Pretty.str " ::", Pretty.brk 1, prtT X]; |
|
1465 |
||
1466 |
fun prt_var (x, ~1) = prt_term (Syntax.free x) |
|
1467 |
| prt_var xi = prt_term (Syntax.var xi); |
|
1468 |
||
1469 |
fun prt_varT (x, ~1) = prt_typ (TFree (x, [])) |
|
1470 |
| prt_varT xi = prt_typ (TVar (xi, [])); |
|
1471 |
||
1472 |
val prt_defT = prt_atom prt_var prt_typ; |
|
1473 |
val prt_defS = prt_atom prt_varT prt_sort; |
|
16540 | 1474 |
|
1475 |
val (types, sorts, used, _) = defaults_of ctxt; |
|
10810 | 1476 |
in |
18609 | 1477 |
verb single (K pretty_thy) @ |
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1478 |
pretty_ctxt ctxt @ |
10810 | 1479 |
verb pretty_binds (K ctxt) @ |
12057 | 1480 |
verb pretty_lthms (K ctxt) @ |
10810 | 1481 |
verb pretty_cases (K ctxt) @ |
18609 | 1482 |
verb single (fn () => Pretty.big_list "type constraints:" (map prt_defT (Vartab.dest types))) @ |
1483 |
verb single (fn () => Pretty.big_list "default sorts:" (map prt_defS (Vartab.dest sorts))) @ |
|
1484 |
verb single (fn () => Pretty.strs ("used type variable names:" :: used)) |
|
10810 | 1485 |
end; |
1486 |
||
5819 | 1487 |
end; |