author | wenzelm |
Mon, 21 Mar 2016 20:22:07 +0100 | |
changeset 62681 | 45b8dd2d3827 |
parent 62680 | 646b84666a56 |
child 63352 | 4eaf35781b23 |
permissions | -rw-r--r-- |
18140
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
1 |
(* Title: Pure/Isar/element.ML |
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
3 |
|
19777 | 4 |
Explicit data structures for some Isar language elements, with derived |
5 |
logical operations. |
|
18140
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
6 |
*) |
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
7 |
|
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
8 |
signature ELEMENT = |
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
9 |
sig |
60448 | 10 |
type ('typ, 'term) obtain = binding * ((binding * 'typ option * mixfix) list * 'term list) |
11 |
type obtains = (string, string) obtain list |
|
12 |
type obtains_i = (typ, term) obtain list |
|
19259 | 13 |
datatype ('typ, 'term) stmt = |
28084
a05ca48ef263
type Attrib.binding abbreviates Name.binding without attributes;
wenzelm
parents:
28079
diff
changeset
|
14 |
Shows of (Attrib.binding * ('term * 'term list) list) list | |
60444 | 15 |
Obtains of ('typ, 'term) obtain list |
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
25739
diff
changeset
|
16 |
type statement = (string, string) stmt |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
25739
diff
changeset
|
17 |
type statement_i = (typ, term) stmt |
18140
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
18 |
datatype ('typ, 'term, 'fact) ctxt = |
29578 | 19 |
Fixes of (binding * 'typ option * mixfix) list | |
18140
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
20 |
Constrains of (string * 'typ) list | |
28084
a05ca48ef263
type Attrib.binding abbreviates Name.binding without attributes;
wenzelm
parents:
28079
diff
changeset
|
21 |
Assumes of (Attrib.binding * ('term * 'term list) list) list | |
a05ca48ef263
type Attrib.binding abbreviates Name.binding without attributes;
wenzelm
parents:
28079
diff
changeset
|
22 |
Defines of (Attrib.binding * ('term * 'term list)) list | |
58011
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
wenzelm
parents:
58002
diff
changeset
|
23 |
Notes of string * (Attrib.binding * ('fact * Token.src list) list) list |
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
25739
diff
changeset
|
24 |
type context = (string, string, Facts.ref) ctxt |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
25739
diff
changeset
|
25 |
type context_i = (typ, term, thm list) ctxt |
29603 | 26 |
val map_ctxt: {binding: binding -> binding, typ: 'typ -> 'a, term: 'term -> 'b, |
58011
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
wenzelm
parents:
58002
diff
changeset
|
27 |
pattern: 'term -> 'b, fact: 'fact -> 'c, attrib: Token.src -> Token.src} -> |
29603 | 28 |
('typ, 'term, 'fact) ctxt -> ('a, 'b, 'c) ctxt |
58011
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
wenzelm
parents:
58002
diff
changeset
|
29 |
val map_ctxt_attrib: (Token.src -> Token.src) -> |
21528 | 30 |
('typ, 'term, 'fact) ctxt -> ('typ, 'term, 'fact) ctxt |
45290 | 31 |
val transform_ctxt: morphism -> context_i -> context_i |
19777 | 32 |
val pretty_stmt: Proof.context -> statement_i -> Pretty.T list |
33 |
val pretty_ctxt: Proof.context -> context_i -> Pretty.T list |
|
59385 | 34 |
val pretty_ctxt_no_attribs: Proof.context -> context_i -> Pretty.T list |
19777 | 35 |
val pretty_statement: Proof.context -> string -> thm -> Pretty.T |
36 |
type witness |
|
29578 | 37 |
val prove_witness: Proof.context -> term -> tactic -> witness |
38 |
val witness_proof: (witness list list -> Proof.context -> Proof.context) -> |
|
39 |
term list list -> Proof.context -> Proof.state |
|
40 |
val witness_proof_eqs: (witness list list -> thm list -> Proof.context -> Proof.context) -> |
|
41 |
term list list -> term list -> Proof.context -> Proof.state |
|
42 |
val witness_local_proof: (witness list list -> Proof.state -> Proof.state) -> |
|
62680
646b84666a56
eliminated unused argument (see also 58110c1e02bc);
wenzelm
parents:
62094
diff
changeset
|
43 |
string -> term list list -> Proof.context -> Proof.state -> Proof.state |
38108 | 44 |
val witness_local_proof_eqs: (witness list list -> thm list -> Proof.state -> Proof.state) -> |
62680
646b84666a56
eliminated unused argument (see also 58110c1e02bc);
wenzelm
parents:
62094
diff
changeset
|
45 |
string -> term list list -> term list -> Proof.context -> Proof.state -> Proof.state |
45290 | 46 |
val transform_witness: morphism -> witness -> witness |
54883
dd04a8b654fc
proper context for norm_hhf and derived operations;
wenzelm
parents:
54742
diff
changeset
|
47 |
val conclude_witness: Proof.context -> witness -> thm |
22658
263d42253f53
Experimental interpretation code for definitions.
ballarin
parents:
22568
diff
changeset
|
48 |
val pretty_witness: Proof.context -> witness -> Pretty.T |
21481 | 49 |
val instT_morphism: theory -> typ Symtab.table -> morphism |
50 |
val inst_morphism: theory -> typ Symtab.table * term Symtab.table -> morphism |
|
51 |
val satisfy_morphism: witness list -> morphism |
|
36674
d95f39448121
eq_morphism is always optional: avoid trivial morphism for empty list of equations
haftmann
parents:
36323
diff
changeset
|
52 |
val eq_morphism: theory -> thm list -> morphism option |
30775
71f777103225
added Element.init, which unifies former activate_elem in element.ML and init_elem in locale.ML;
wenzelm
parents:
30763
diff
changeset
|
53 |
val init: context_i -> Context.generic -> Context.generic |
57864
7cf01ece66e4
clarified Element.init vs. Element.init' -- the latter also avoids redundant warnings due to declatations when preparing locale expressions / interpretations;
wenzelm
parents:
55997
diff
changeset
|
54 |
val init': context_i -> Context.generic -> Context.generic |
30777
9960ff945c52
simplified Element.activate(_i): singleton version;
wenzelm
parents:
30775
diff
changeset
|
55 |
val activate_i: context_i -> Proof.context -> context_i * Proof.context |
9960ff945c52
simplified Element.activate(_i): singleton version;
wenzelm
parents:
30775
diff
changeset
|
56 |
val activate: (typ, term, Facts.ref) ctxt -> Proof.context -> context_i * Proof.context |
18140
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
57 |
end; |
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
58 |
|
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
59 |
structure Element: ELEMENT = |
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
60 |
struct |
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
61 |
|
19777 | 62 |
(** language elements **) |
63 |
||
64 |
(* statement *) |
|
19259 | 65 |
|
60448 | 66 |
type ('typ, 'term) obtain = binding * ((binding * 'typ option * mixfix) list * 'term list); |
67 |
type obtains = (string, string) obtain list; |
|
68 |
type obtains_i = (typ, term) obtain list; |
|
69 |
||
19259 | 70 |
datatype ('typ, 'term) stmt = |
28084
a05ca48ef263
type Attrib.binding abbreviates Name.binding without attributes;
wenzelm
parents:
28079
diff
changeset
|
71 |
Shows of (Attrib.binding * ('term * 'term list) list) list | |
60444 | 72 |
Obtains of ('typ, 'term) obtain list; |
19259 | 73 |
|
74 |
type statement = (string, string) stmt; |
|
75 |
type statement_i = (typ, term) stmt; |
|
76 |
||
77 |
||
19777 | 78 |
(* context *) |
18140
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
79 |
|
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
80 |
datatype ('typ, 'term, 'fact) ctxt = |
29578 | 81 |
Fixes of (binding * 'typ option * mixfix) list | |
18140
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
82 |
Constrains of (string * 'typ) list | |
28084
a05ca48ef263
type Attrib.binding abbreviates Name.binding without attributes;
wenzelm
parents:
28079
diff
changeset
|
83 |
Assumes of (Attrib.binding * ('term * 'term list) list) list | |
a05ca48ef263
type Attrib.binding abbreviates Name.binding without attributes;
wenzelm
parents:
28079
diff
changeset
|
84 |
Defines of (Attrib.binding * ('term * 'term list)) list | |
58011
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
wenzelm
parents:
58002
diff
changeset
|
85 |
Notes of string * (Attrib.binding * ('fact * Token.src list) list) list; |
18140
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
86 |
|
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
25739
diff
changeset
|
87 |
type context = (string, string, Facts.ref) ctxt; |
18140
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
88 |
type context_i = (typ, term, thm list) ctxt; |
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
89 |
|
29603 | 90 |
fun map_ctxt {binding, typ, term, pattern, fact, attrib} = |
91 |
fn Fixes fixes => Fixes (fixes |> map (fn (x, T, mx) => (binding x, Option.map typ T, mx))) |
|
28079
955c42c8a5e4
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27865
diff
changeset
|
92 |
| Constrains xs => Constrains (xs |> map (fn (x, T) => |
42494 | 93 |
(Variable.check_name (binding (Binding.name x)), typ T))) |
18140
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
94 |
| Assumes asms => Assumes (asms |> map (fn ((a, atts), propps) => |
29603 | 95 |
((binding a, map attrib atts), propps |> map (fn (t, ps) => (term t, map pattern ps))))) |
18140
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
96 |
| Defines defs => Defines (defs |> map (fn ((a, atts), (t, ps)) => |
29603 | 97 |
((binding a, map attrib atts), (term t, map pattern ps)))) |
21440 | 98 |
| Notes (kind, facts) => Notes (kind, facts |> map (fn ((a, atts), bs) => |
28965 | 99 |
((binding a, map attrib atts), bs |> map (fn (ths, btts) => (fact ths, map attrib btts))))); |
18140
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
100 |
|
21528 | 101 |
fun map_ctxt_attrib attrib = |
29603 | 102 |
map_ctxt {binding = I, typ = I, term = I, pattern = I, fact = I, attrib = attrib}; |
21528 | 103 |
|
45290 | 104 |
fun transform_ctxt phi = map_ctxt |
28965 | 105 |
{binding = Morphism.binding phi, |
21481 | 106 |
typ = Morphism.typ phi, |
107 |
term = Morphism.term phi, |
|
29603 | 108 |
pattern = Morphism.term phi, |
21521 | 109 |
fact = Morphism.fact phi, |
61814
1ca1142e1711
clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents:
61268
diff
changeset
|
110 |
attrib = map (Token.transform phi)}; |
18140
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
111 |
|
19808 | 112 |
|
18894 | 113 |
|
19259 | 114 |
(** pretty printing **) |
115 |
||
19267 | 116 |
fun pretty_items _ _ [] = [] |
117 |
| pretty_items keyword sep (x :: ys) = |
|
55763 | 118 |
Pretty.block [Pretty.keyword2 keyword, Pretty.brk 1, x] :: |
119 |
map (fn y => Pretty.block [Pretty.str " ", Pretty.keyword2 sep, Pretty.brk 1, y]) ys; |
|
19259 | 120 |
|
121 |
||
122 |
(* pretty_stmt *) |
|
123 |
||
124 |
fun pretty_stmt ctxt = |
|
125 |
let |
|
24920 | 126 |
val prt_typ = Pretty.quote o Syntax.pretty_typ ctxt; |
127 |
val prt_term = Pretty.quote o Syntax.pretty_term ctxt; |
|
55763 | 128 |
val prt_terms = separate (Pretty.keyword2 "and") o map prt_term; |
60242
3a8501876dba
tuned output -- avoid empty quites and extra breaks;
wenzelm
parents:
59970
diff
changeset
|
129 |
val prt_binding = Attrib.pretty_binding ctxt; |
19259 | 130 |
|
131 |
fun prt_show (a, ts) = |
|
60242
3a8501876dba
tuned output -- avoid empty quites and extra breaks;
wenzelm
parents:
59970
diff
changeset
|
132 |
Pretty.block (Pretty.breaks (prt_binding a ":" @ prt_terms (map fst ts))); |
19259 | 133 |
|
60448 | 134 |
fun prt_var (x, SOME T, _) = Pretty.block |
30223
24d975352879
renamed Binding.name_pos to Binding.make, renamed Binding.base_name to Binding.name_of, renamed Binding.map_base to Binding.map_name, added mandatory flag to Binding.qualify;
wenzelm
parents:
30219
diff
changeset
|
135 |
[Pretty.str (Binding.name_of x ^ " ::"), Pretty.brk 1, prt_typ T] |
60448 | 136 |
| prt_var (x, NONE, _) = Pretty.str (Binding.name_of x); |
55763 | 137 |
val prt_vars = separate (Pretty.keyword2 "and") o map prt_var; |
19259 | 138 |
|
60448 | 139 |
fun prt_obtain (_, ([], props)) = Pretty.block (Pretty.breaks (prt_terms props)) |
140 |
| prt_obtain (_, (vars, props)) = Pretty.block (Pretty.breaks |
|
141 |
(prt_vars vars @ [Pretty.keyword2 "where"] @ prt_terms props)); |
|
19259 | 142 |
in |
19267 | 143 |
fn Shows shows => pretty_items "shows" "and" (map prt_show shows) |
144 |
| Obtains obtains => pretty_items "obtains" "|" (map prt_obtain obtains) |
|
19259 | 145 |
end; |
146 |
||
18894 | 147 |
|
19259 | 148 |
(* pretty_ctxt *) |
149 |
||
59385 | 150 |
fun gen_pretty_ctxt show_attribs ctxt = |
19259 | 151 |
let |
24920 | 152 |
val prt_typ = Pretty.quote o Syntax.pretty_typ ctxt; |
153 |
val prt_term = Pretty.quote o Syntax.pretty_term ctxt; |
|
62094 | 154 |
val prt_thm = Pretty.cartouche o Thm.pretty_thm ctxt; |
59385 | 155 |
|
60242
3a8501876dba
tuned output -- avoid empty quites and extra breaks;
wenzelm
parents:
59970
diff
changeset
|
156 |
fun prt_binding (b, atts) = |
3a8501876dba
tuned output -- avoid empty quites and extra breaks;
wenzelm
parents:
59970
diff
changeset
|
157 |
Attrib.pretty_binding ctxt (b, if show_attribs then atts else []); |
59385 | 158 |
|
159 |
fun prt_fact (ths, atts) = |
|
160 |
if not show_attribs orelse null atts then map prt_thm ths |
|
161 |
else |
|
162 |
Pretty.enclose "(" ")" (Pretty.breaks (map prt_thm ths)) :: |
|
163 |
Attrib.pretty_attribs ctxt atts; |
|
19259 | 164 |
|
19267 | 165 |
fun prt_mixfix NoSyn = [] |
42287
d98eb048a2e4
discontinued special treatment of structure Mixfix;
wenzelm
parents:
41581
diff
changeset
|
166 |
| prt_mixfix mx = [Pretty.brk 2, Mixfix.pretty_mixfix mx]; |
19267 | 167 |
|
30223
24d975352879
renamed Binding.name_pos to Binding.make, renamed Binding.base_name to Binding.name_of, renamed Binding.map_base to Binding.map_name, added mandatory flag to Binding.qualify;
wenzelm
parents:
30219
diff
changeset
|
168 |
fun prt_fix (x, SOME T, mx) = Pretty.block (Pretty.str (Binding.name_of x ^ " ::") :: |
28079
955c42c8a5e4
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27865
diff
changeset
|
169 |
Pretty.brk 1 :: prt_typ T :: Pretty.brk 1 :: prt_mixfix mx) |
30223
24d975352879
renamed Binding.name_pos to Binding.make, renamed Binding.base_name to Binding.name_of, renamed Binding.map_base to Binding.map_name, added mandatory flag to Binding.qualify;
wenzelm
parents:
30219
diff
changeset
|
170 |
| prt_fix (x, NONE, mx) = Pretty.block (Pretty.str (Binding.name_of x) :: |
28079
955c42c8a5e4
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27865
diff
changeset
|
171 |
Pretty.brk 1 :: prt_mixfix mx); |
28965 | 172 |
fun prt_constrain (x, T) = prt_fix (Binding.name x, SOME T, NoSyn); |
18894 | 173 |
|
19259 | 174 |
fun prt_asm (a, ts) = |
60242
3a8501876dba
tuned output -- avoid empty quites and extra breaks;
wenzelm
parents:
59970
diff
changeset
|
175 |
Pretty.block (Pretty.breaks (prt_binding a ":" @ map (prt_term o fst) ts)); |
19259 | 176 |
fun prt_def (a, (t, _)) = |
60242
3a8501876dba
tuned output -- avoid empty quites and extra breaks;
wenzelm
parents:
59970
diff
changeset
|
177 |
Pretty.block (Pretty.breaks (prt_binding a ":" @ [prt_term t])); |
19259 | 178 |
|
179 |
fun prt_note (a, ths) = |
|
60242
3a8501876dba
tuned output -- avoid empty quites and extra breaks;
wenzelm
parents:
59970
diff
changeset
|
180 |
Pretty.block (Pretty.breaks (flat (prt_binding a " =" :: map prt_fact ths))); |
19259 | 181 |
in |
19267 | 182 |
fn Fixes fixes => pretty_items "fixes" "and" (map prt_fix fixes) |
183 |
| Constrains xs => pretty_items "constrains" "and" (map prt_constrain xs) |
|
184 |
| Assumes asms => pretty_items "assumes" "and" (map prt_asm asms) |
|
185 |
| Defines defs => pretty_items "defines" "and" (map prt_def defs) |
|
21440 | 186 |
| Notes ("", facts) => pretty_items "notes" "and" (map prt_note facts) |
187 |
| Notes (kind, facts) => pretty_items ("notes " ^ kind) "and" (map prt_note facts) |
|
19259 | 188 |
end; |
18894 | 189 |
|
59385 | 190 |
val pretty_ctxt = gen_pretty_ctxt true; |
191 |
val pretty_ctxt_no_attribs = gen_pretty_ctxt false; |
|
192 |
||
19267 | 193 |
|
194 |
(* pretty_statement *) |
|
195 |
||
196 |
local |
|
197 |
||
59970 | 198 |
fun standard_elim ctxt th = |
199 |
(case Object_Logic.elim_concl ctxt th of |
|
41581
72a02e3dec7e
clarified pretty_statement: more robust treatment of fixes and conclusion of elimination (e.g. for classical rule);
wenzelm
parents:
41425
diff
changeset
|
200 |
SOME C => |
72a02e3dec7e
clarified pretty_statement: more robust treatment of fixes and conclusion of elimination (e.g. for classical rule);
wenzelm
parents:
41425
diff
changeset
|
201 |
let |
72a02e3dec7e
clarified pretty_statement: more robust treatment of fixes and conclusion of elimination (e.g. for classical rule);
wenzelm
parents:
41425
diff
changeset
|
202 |
val thesis = Var ((Auto_Bind.thesisN, Thm.maxidx_of th + 1), fastype_of C); |
60642
48dd1cefb4ae
simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents:
60555
diff
changeset
|
203 |
val th' = Thm.instantiate ([], [(Term.dest_Var C, Thm.cterm_of ctxt thesis)]) th; |
41581
72a02e3dec7e
clarified pretty_statement: more robust treatment of fixes and conclusion of elimination (e.g. for classical rule);
wenzelm
parents:
41425
diff
changeset
|
204 |
in (th', true) end |
72a02e3dec7e
clarified pretty_statement: more robust treatment of fixes and conclusion of elimination (e.g. for classical rule);
wenzelm
parents:
41425
diff
changeset
|
205 |
| NONE => (th, false)); |
72a02e3dec7e
clarified pretty_statement: more robust treatment of fixes and conclusion of elimination (e.g. for classical rule);
wenzelm
parents:
41425
diff
changeset
|
206 |
|
19267 | 207 |
fun thm_name kind th prts = |
208 |
let val head = |
|
27865
27a8ad9612a3
moved basic thm operations from structure PureThy to Thm (cf. more_thm.ML);
wenzelm
parents:
26721
diff
changeset
|
209 |
if Thm.has_name_hint th then |
55763 | 210 |
Pretty.block [Pretty.keyword1 kind, |
30364
577edc39b501
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
30280
diff
changeset
|
211 |
Pretty.brk 1, Pretty.str (Long_Name.base_name (Thm.get_name_hint th) ^ ":")] |
55763 | 212 |
else Pretty.keyword1 kind |
19267 | 213 |
in Pretty.block (Pretty.fbreaks (head :: prts)) end; |
214 |
||
215 |
fun obtain prop ctxt = |
|
216 |
let |
|
60695
757549b4bbe6
Variable.focus etc.: optional bindings provided by user;
wenzelm
parents:
60642
diff
changeset
|
217 |
val ((ps, prop'), ctxt') = Variable.focus NONE prop ctxt; |
60448 | 218 |
fun fix (x, T) = (Binding.name (Variable.revert_fixed ctxt' x), SOME T, NoSyn); |
42495
1af81b70cf09
clarified Variable.focus vs. Variable.focus_cterm -- eliminated clone;
wenzelm
parents:
42494
diff
changeset
|
219 |
val xs = map (fix o #2) ps; |
1af81b70cf09
clarified Variable.focus vs. Variable.focus_cterm -- eliminated clone;
wenzelm
parents:
42494
diff
changeset
|
220 |
val As = Logic.strip_imp_prems prop'; |
41581
72a02e3dec7e
clarified pretty_statement: more robust treatment of fixes and conclusion of elimination (e.g. for classical rule);
wenzelm
parents:
41425
diff
changeset
|
221 |
in ((Binding.empty, (xs, As)), ctxt') end; |
19267 | 222 |
|
223 |
in |
|
224 |
||
225 |
fun pretty_statement ctxt kind raw_th = |
|
226 |
let |
|
59970 | 227 |
val (th, is_elim) = standard_elim ctxt (Raw_Simplifier.norm_hhf ctxt raw_th); |
41581
72a02e3dec7e
clarified pretty_statement: more robust treatment of fixes and conclusion of elimination (e.g. for classical rule);
wenzelm
parents:
41425
diff
changeset
|
228 |
val ((_, [th']), ctxt') = Variable.import true [th] (Variable.set_body true ctxt); |
20150 | 229 |
val prop = Thm.prop_of th'; |
230 |
val (prems, concl) = Logic.strip_horn prop; |
|
59970 | 231 |
val concl_term = Object_Logic.drop_judgment ctxt concl; |
19267 | 232 |
|
62681
45b8dd2d3827
more accurate fixes (e.g. for notE, FalseE), amending baa589c574ff;
wenzelm
parents:
62680
diff
changeset
|
233 |
val (assumes, cases) = |
45b8dd2d3827
more accurate fixes (e.g. for notE, FalseE), amending baa589c574ff;
wenzelm
parents:
62680
diff
changeset
|
234 |
take_suffix (fn prem => is_elim andalso concl aconv Logic.strip_assums_concl prem) prems; |
45b8dd2d3827
more accurate fixes (e.g. for notE, FalseE), amending baa589c574ff;
wenzelm
parents:
62680
diff
changeset
|
235 |
val is_thesis = if null cases then K false else fn v => v aconv concl_term; |
45b8dd2d3827
more accurate fixes (e.g. for notE, FalseE), amending baa589c574ff;
wenzelm
parents:
62680
diff
changeset
|
236 |
val fixes = |
45b8dd2d3827
more accurate fixes (e.g. for notE, FalseE), amending baa589c574ff;
wenzelm
parents:
62680
diff
changeset
|
237 |
rev (fold_aterms (fn v as Free (x, T) => |
45b8dd2d3827
more accurate fixes (e.g. for notE, FalseE), amending baa589c574ff;
wenzelm
parents:
62680
diff
changeset
|
238 |
if Variable.is_newly_fixed ctxt' ctxt x andalso not (is_thesis v) |
45b8dd2d3827
more accurate fixes (e.g. for notE, FalseE), amending baa589c574ff;
wenzelm
parents:
62680
diff
changeset
|
239 |
then insert (op =) (Variable.revert_fixed ctxt' x, T) else I | _ => I) prop []); |
19267 | 240 |
in |
28965 | 241 |
pretty_ctxt ctxt' (Fixes (map (fn (x, T) => (Binding.name x, SOME T, NoSyn)) fixes)) @ |
242 |
pretty_ctxt ctxt' (Assumes (map (fn t => (Attrib.empty_binding, [(t, [])])) assumes)) @ |
|
243 |
(if null cases then pretty_stmt ctxt' (Shows [(Attrib.empty_binding, [(concl, [])])]) |
|
26716
8690e75e1395
print_statement: reset body mode, i.e. invent global frees (no need for revert_skolem);
wenzelm
parents:
26628
diff
changeset
|
244 |
else |
42495
1af81b70cf09
clarified Variable.focus vs. Variable.focus_cterm -- eliminated clone;
wenzelm
parents:
42494
diff
changeset
|
245 |
let val (clauses, ctxt'') = fold_map obtain cases ctxt' |
26716
8690e75e1395
print_statement: reset body mode, i.e. invent global frees (no need for revert_skolem);
wenzelm
parents:
26628
diff
changeset
|
246 |
in pretty_stmt ctxt'' (Obtains clauses) end) |
19267 | 247 |
end |> thm_name kind raw_th; |
248 |
||
18140
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
249 |
end; |
19267 | 250 |
|
19777 | 251 |
|
252 |
||
253 |
(** logical operations **) |
|
254 |
||
255 |
(* witnesses -- hypotheses as protected facts *) |
|
256 |
||
257 |
datatype witness = Witness of term * thm; |
|
258 |
||
29578 | 259 |
val mark_witness = Logic.protect; |
260 |
fun witness_prop (Witness (t, _)) = t; |
|
44058 | 261 |
fun witness_hyps (Witness (_, th)) = Thm.hyps_of th; |
19777 | 262 |
fun map_witness f (Witness witn) = Witness (f witn); |
263 |
||
45290 | 264 |
fun transform_witness phi = map_witness (fn (t, th) => (Morphism.term phi t, Morphism.thm phi th)); |
21481 | 265 |
|
20058 | 266 |
fun prove_witness ctxt t tac = |
52732 | 267 |
Witness (t, |
268 |
Thm.close_derivation |
|
58837 | 269 |
(Goal.prove ctxt [] [] (mark_witness t) |
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59385
diff
changeset
|
270 |
(fn _ => resolve_tac ctxt [Drule.protectI] 1 THEN tac))); |
19777 | 271 |
|
29603 | 272 |
|
29578 | 273 |
local |
274 |
||
275 |
val refine_witness = |
|
61841
4d3527b94f2a
more general types Proof.method / context_tactic;
wenzelm
parents:
61814
diff
changeset
|
276 |
Proof.refine_singleton (Method.Basic (fn ctxt => Method.CONTEXT_TACTIC o |
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59385
diff
changeset
|
277 |
K (ALLGOALS (CONJUNCTS (ALLGOALS (CONJUNCTS (TRYALL (resolve_tac ctxt [Drule.protectI])))))))); |
25624 | 278 |
|
29578 | 279 |
fun gen_witness_proof proof after_qed wit_propss eq_props = |
280 |
let |
|
46896 | 281 |
val propss = |
282 |
(map o map) (fn prop => (mark_witness prop, [])) wit_propss @ |
|
283 |
[map (rpair []) eq_props]; |
|
29578 | 284 |
fun after_qed' thmss = |
29603 | 285 |
let val (wits, eqs) = split_last ((map o map) Thm.close_derivation thmss); |
29578 | 286 |
in after_qed ((map2 o map2) (curry Witness) wit_propss wits) eqs end; |
61841
4d3527b94f2a
more general types Proof.method / context_tactic;
wenzelm
parents:
61814
diff
changeset
|
287 |
in proof after_qed' propss #> refine_witness end; |
29578 | 288 |
|
62680
646b84666a56
eliminated unused argument (see also 58110c1e02bc);
wenzelm
parents:
62094
diff
changeset
|
289 |
fun proof_local cmd goal_ctxt after_qed propp = |
60415
9d37b2330ee3
clarified local after_qed: result is not exported yet;
wenzelm
parents:
60414
diff
changeset
|
290 |
let |
9d37b2330ee3
clarified local after_qed: result is not exported yet;
wenzelm
parents:
60414
diff
changeset
|
291 |
fun after_qed' (result_ctxt, results) state' = |
9d37b2330ee3
clarified local after_qed: result is not exported yet;
wenzelm
parents:
60414
diff
changeset
|
292 |
after_qed (burrow (Proof_Context.export result_ctxt (Proof.context_of state')) results) state'; |
9d37b2330ee3
clarified local after_qed: result is not exported yet;
wenzelm
parents:
60414
diff
changeset
|
293 |
in |
9d37b2330ee3
clarified local after_qed: result is not exported yet;
wenzelm
parents:
60414
diff
changeset
|
294 |
Proof.map_context (K goal_ctxt) #> |
60555
51a6997b1384
support 'when' statement, which corresponds to 'presume';
wenzelm
parents:
60461
diff
changeset
|
295 |
Proof.internal_goal (K (K ())) (Proof_Context.get_mode goal_ctxt) true cmd |
60461 | 296 |
NONE after_qed' [] [] (map (pair Thm.empty_binding) propp) #> snd |
60415
9d37b2330ee3
clarified local after_qed: result is not exported yet;
wenzelm
parents:
60414
diff
changeset
|
297 |
end; |
41425 | 298 |
|
29578 | 299 |
in |
300 |
||
301 |
fun witness_proof after_qed wit_propss = |
|
36323
655e2d74de3a
modernized naming conventions of main Isar proof elements;
wenzelm
parents:
35767
diff
changeset
|
302 |
gen_witness_proof (Proof.theorem NONE) (fn wits => fn _ => after_qed wits) |
29578 | 303 |
wit_propss []; |
304 |
||
36323
655e2d74de3a
modernized naming conventions of main Isar proof elements;
wenzelm
parents:
35767
diff
changeset
|
305 |
val witness_proof_eqs = gen_witness_proof (Proof.theorem NONE); |
29578 | 306 |
|
62680
646b84666a56
eliminated unused argument (see also 58110c1e02bc);
wenzelm
parents:
62094
diff
changeset
|
307 |
fun witness_local_proof after_qed cmd wit_propss goal_ctxt = |
646b84666a56
eliminated unused argument (see also 58110c1e02bc);
wenzelm
parents:
62094
diff
changeset
|
308 |
gen_witness_proof (proof_local cmd goal_ctxt) |
29578 | 309 |
(fn wits => fn _ => after_qed wits) wit_propss []; |
310 |
||
62680
646b84666a56
eliminated unused argument (see also 58110c1e02bc);
wenzelm
parents:
62094
diff
changeset
|
311 |
fun witness_local_proof_eqs after_qed cmd wit_propss eq_props goal_ctxt = |
646b84666a56
eliminated unused argument (see also 58110c1e02bc);
wenzelm
parents:
62094
diff
changeset
|
312 |
gen_witness_proof (proof_local cmd goal_ctxt) after_qed wit_propss eq_props; |
41425 | 313 |
|
29603 | 314 |
end; |
315 |
||
19777 | 316 |
|
25302 | 317 |
fun compose_witness (Witness (_, th)) r = |
318 |
let |
|
319 |
val th' = Goal.conclude th; |
|
320 |
val A = Thm.cprem_of r 1; |
|
25739 | 321 |
in |
322 |
Thm.implies_elim |
|
323 |
(Conv.gconv_rule Drule.beta_eta_conversion 1 r) |
|
324 |
(Conv.fconv_rule Drule.beta_eta_conversion |
|
325 |
(Thm.instantiate (Thm.match (Thm.cprop_of th', A)) th')) |
|
326 |
end; |
|
25302 | 327 |
|
54883
dd04a8b654fc
proper context for norm_hhf and derived operations;
wenzelm
parents:
54742
diff
changeset
|
328 |
fun conclude_witness ctxt (Witness (_, th)) = |
dd04a8b654fc
proper context for norm_hhf and derived operations;
wenzelm
parents:
54742
diff
changeset
|
329 |
Thm.close_derivation (Raw_Simplifier.norm_hhf_protect ctxt (Goal.conclude th)); |
19777 | 330 |
|
22658
263d42253f53
Experimental interpretation code for definitions.
ballarin
parents:
22568
diff
changeset
|
331 |
fun pretty_witness ctxt witn = |
24920 | 332 |
let val prt_term = Pretty.quote o Syntax.pretty_term ctxt in |
22658
263d42253f53
Experimental interpretation code for definitions.
ballarin
parents:
22568
diff
changeset
|
333 |
Pretty.block (prt_term (witness_prop witn) :: |
39166
19efc2af3e6c
turned show_hyps and show_tags into proper configuration option;
wenzelm
parents:
38709
diff
changeset
|
334 |
(if Config.get ctxt show_hyps then [Pretty.brk 2, Pretty.list "[" "]" |
22658
263d42253f53
Experimental interpretation code for definitions.
ballarin
parents:
22568
diff
changeset
|
335 |
(map prt_term (witness_hyps witn))] else [])) |
263d42253f53
Experimental interpretation code for definitions.
ballarin
parents:
22568
diff
changeset
|
336 |
end; |
263d42253f53
Experimental interpretation code for definitions.
ballarin
parents:
22568
diff
changeset
|
337 |
|
19777 | 338 |
|
339 |
(* derived rules *) |
|
340 |
||
20007 | 341 |
fun instantiate_tfrees thy subst th = |
19777 | 342 |
let |
20007 | 343 |
val idx = Thm.maxidx_of th + 1; |
60642
48dd1cefb4ae
simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents:
60555
diff
changeset
|
344 |
fun cert_inst (a, (S, T)) = (((a, idx), S), Thm.global_ctyp_of thy T); |
20007 | 345 |
|
346 |
fun add_inst (a, S) insts = |
|
347 |
if AList.defined (op =) insts a then insts |
|
348 |
else (case AList.lookup (op =) subst a of NONE => insts | SOME T => (a, (S, T)) :: insts); |
|
349 |
val insts = |
|
45346
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
350 |
(Term.fold_types o Term.fold_atyps) (fn TFree v => add_inst v | _ => I) |
20007 | 351 |
(Thm.full_prop_of th) []; |
19777 | 352 |
in |
20007 | 353 |
th |
354 |
|> Thm.generalize (map fst insts, []) idx |
|
355 |
|> Thm.instantiate (map cert_inst insts, []) |
|
19777 | 356 |
end; |
357 |
||
358 |
fun instantiate_frees thy subst = |
|
59621
291934bac95e
Thm.cterm_of and Thm.ctyp_of operate on local context;
wenzelm
parents:
59616
diff
changeset
|
359 |
Drule.forall_intr_list (map (Thm.global_cterm_of thy o Free o fst) subst) #> |
291934bac95e
Thm.cterm_of and Thm.ctyp_of operate on local context;
wenzelm
parents:
59616
diff
changeset
|
360 |
Drule.forall_elim_list (map (Thm.global_cterm_of thy o snd) subst); |
19777 | 361 |
|
362 |
fun hyps_rule rule th = |
|
60949 | 363 |
let val hyps = Thm.chyps_of th in |
19777 | 364 |
Drule.implies_elim_list |
365 |
(rule (Drule.implies_intr_list hyps th)) |
|
21521 | 366 |
(map (Thm.assume o Drule.cterm_rule rule) hyps) |
19777 | 367 |
end; |
368 |
||
369 |
||
370 |
(* instantiate types *) |
|
371 |
||
45346
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
372 |
fun instT_type_same env = |
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
373 |
if Symtab.is_empty env then Same.same |
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
374 |
else |
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
375 |
Term_Subst.map_atypsT_same |
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
376 |
(fn TFree (a, _) => (case Symtab.lookup env a of SOME T => T | NONE => raise Same.SAME) |
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
377 |
| _ => raise Same.SAME); |
19777 | 378 |
|
45346
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
379 |
fun instT_term_same env = |
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
380 |
if Symtab.is_empty env then Same.same |
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
381 |
else Term_Subst.map_types_same (instT_type_same env); |
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
382 |
|
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
383 |
val instT_type = Same.commit o instT_type_same; |
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
384 |
val instT_term = Same.commit o instT_term_same; |
19777 | 385 |
|
45346
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
386 |
fun instT_subst env th = |
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
387 |
(Thm.fold_terms o Term.fold_types o Term.fold_atyps) |
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
388 |
(fn T as TFree (a, _) => |
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
389 |
let val T' = the_default T (Symtab.lookup env a) |
45349
7fb63b469cd2
more uniform instT_subst vs. inst_subst: compare variable names only;
wenzelm
parents:
45346
diff
changeset
|
390 |
in if T = T' then I else insert (eq_fst (op =)) (a, T') end |
45346
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
391 |
| _ => I) th []; |
19777 | 392 |
|
393 |
fun instT_thm thy env th = |
|
394 |
if Symtab.is_empty env then th |
|
395 |
else |
|
396 |
let val subst = instT_subst env th |
|
397 |
in if null subst then th else th |> hyps_rule (instantiate_tfrees thy subst) end; |
|
398 |
||
22672
777af26d5713
inst(T)_morphism: avoid reference to static theory value;
wenzelm
parents:
22658
diff
changeset
|
399 |
fun instT_morphism thy env = |
54740 | 400 |
Morphism.morphism "Element.instT" |
52788 | 401 |
{binding = [], |
402 |
typ = [instT_type env], |
|
403 |
term = [instT_term env], |
|
52789 | 404 |
fact = [map (instT_thm thy env)]}; |
19777 | 405 |
|
406 |
||
407 |
(* instantiate types and terms *) |
|
408 |
||
409 |
fun inst_term (envT, env) = |
|
410 |
if Symtab.is_empty env then instT_term envT |
|
411 |
else |
|
45346
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
412 |
instT_term envT #> |
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
413 |
Same.commit (Term_Subst.map_aterms_same |
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
414 |
(fn Free (x, _) => (case Symtab.lookup env x of SOME t => t | NONE => raise Same.SAME) |
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
415 |
| _ => raise Same.SAME)) #> |
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
416 |
Envir.beta_norm; |
19777 | 417 |
|
45349
7fb63b469cd2
more uniform instT_subst vs. inst_subst: compare variable names only;
wenzelm
parents:
45346
diff
changeset
|
418 |
fun inst_subst (envT, env) th = |
7fb63b469cd2
more uniform instT_subst vs. inst_subst: compare variable names only;
wenzelm
parents:
45346
diff
changeset
|
419 |
(Thm.fold_terms o Term.fold_aterms) |
7fb63b469cd2
more uniform instT_subst vs. inst_subst: compare variable names only;
wenzelm
parents:
45346
diff
changeset
|
420 |
(fn Free (x, T) => |
7fb63b469cd2
more uniform instT_subst vs. inst_subst: compare variable names only;
wenzelm
parents:
45346
diff
changeset
|
421 |
let |
7fb63b469cd2
more uniform instT_subst vs. inst_subst: compare variable names only;
wenzelm
parents:
45346
diff
changeset
|
422 |
val T' = instT_type envT T; |
7fb63b469cd2
more uniform instT_subst vs. inst_subst: compare variable names only;
wenzelm
parents:
45346
diff
changeset
|
423 |
val t = Free (x, T'); |
7fb63b469cd2
more uniform instT_subst vs. inst_subst: compare variable names only;
wenzelm
parents:
45346
diff
changeset
|
424 |
val t' = the_default t (Symtab.lookup env x); |
7fb63b469cd2
more uniform instT_subst vs. inst_subst: compare variable names only;
wenzelm
parents:
45346
diff
changeset
|
425 |
in if t aconv t' then I else insert (eq_fst (op =)) ((x, T'), t') end |
7fb63b469cd2
more uniform instT_subst vs. inst_subst: compare variable names only;
wenzelm
parents:
45346
diff
changeset
|
426 |
| _ => I) th []; |
7fb63b469cd2
more uniform instT_subst vs. inst_subst: compare variable names only;
wenzelm
parents:
45346
diff
changeset
|
427 |
|
19777 | 428 |
fun inst_thm thy (envT, env) th = |
429 |
if Symtab.is_empty env then instT_thm thy envT th |
|
430 |
else |
|
431 |
let |
|
432 |
val substT = instT_subst envT th; |
|
45349
7fb63b469cd2
more uniform instT_subst vs. inst_subst: compare variable names only;
wenzelm
parents:
45346
diff
changeset
|
433 |
val subst = inst_subst (envT, env) th; |
19777 | 434 |
in |
435 |
if null substT andalso null subst then th |
|
436 |
else th |> hyps_rule |
|
437 |
(instantiate_tfrees thy substT #> |
|
438 |
instantiate_frees thy subst #> |
|
22900 | 439 |
Conv.fconv_rule (Thm.beta_conversion true)) |
19777 | 440 |
end; |
441 |
||
45346
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
442 |
fun inst_morphism thy (envT, env) = |
54740 | 443 |
Morphism.morphism "Element.inst" |
52788 | 444 |
{binding = [], |
445 |
typ = [instT_type envT], |
|
446 |
term = [inst_term (envT, env)], |
|
52789 | 447 |
fact = [map (inst_thm thy (envT, env))]}; |
19777 | 448 |
|
449 |
||
450 |
(* satisfy hypotheses *) |
|
451 |
||
45346
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
452 |
fun satisfy_thm witns thm = |
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
453 |
thm |> fold (fn hyp => |
19777 | 454 |
(case find_first (fn Witness (t, _) => Thm.term_of hyp aconv t) witns of |
455 |
NONE => I |
|
60949 | 456 |
| SOME w => Thm.implies_intr hyp #> compose_witness w)) (Thm.chyps_of thm); |
19777 | 457 |
|
54740 | 458 |
val satisfy_morphism = Morphism.thm_morphism "Element.satisfy" o satisfy_thm; |
20264 | 459 |
|
460 |
||
29525 | 461 |
(* rewriting with equalities *) |
462 |
||
46856 | 463 |
fun eq_morphism _ [] = NONE |
464 |
| eq_morphism thy thms = |
|
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
54740
diff
changeset
|
465 |
let |
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
54740
diff
changeset
|
466 |
(* FIXME proper context!? *) |
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
54740
diff
changeset
|
467 |
fun rewrite th = rewrite_rule (Proof_Context.init_global (Thm.theory_of_thm th)) thms th; |
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
54740
diff
changeset
|
468 |
val phi = |
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
54740
diff
changeset
|
469 |
Morphism.morphism "Element.eq_morphism" |
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
54740
diff
changeset
|
470 |
{binding = [], |
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
54740
diff
changeset
|
471 |
typ = [], |
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
54740
diff
changeset
|
472 |
term = [Raw_Simplifier.rewrite_term thy thms []], |
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
54740
diff
changeset
|
473 |
fact = [map rewrite]}; |
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
54740
diff
changeset
|
474 |
in SOME phi end; |
29525 | 475 |
|
476 |
||
29218 | 477 |
|
30775
71f777103225
added Element.init, which unifies former activate_elem in element.ML and init_elem in locale.ML;
wenzelm
parents:
30763
diff
changeset
|
478 |
(** activate in context **) |
28832 | 479 |
|
30775
71f777103225
added Element.init, which unifies former activate_elem in element.ML and init_elem in locale.ML;
wenzelm
parents:
30763
diff
changeset
|
480 |
(* init *) |
28832 | 481 |
|
57864
7cf01ece66e4
clarified Element.init vs. Element.init' -- the latter also avoids redundant warnings due to declatations when preparing locale expressions / interpretations;
wenzelm
parents:
55997
diff
changeset
|
482 |
fun init (Fixes fixes) = Context.map_proof (Proof_Context.add_fixes fixes #> #2) |
7cf01ece66e4
clarified Element.init vs. Element.init' -- the latter also avoids redundant warnings due to declatations when preparing locale expressions / interpretations;
wenzelm
parents:
55997
diff
changeset
|
483 |
| init (Constrains _) = I |
7cf01ece66e4
clarified Element.init vs. Element.init' -- the latter also avoids redundant warnings due to declatations when preparing locale expressions / interpretations;
wenzelm
parents:
55997
diff
changeset
|
484 |
| init (Assumes asms) = Context.map_proof (fn ctxt => |
28832 | 485 |
let |
47815 | 486 |
val asms' = Attrib.map_specs (map (Attrib.attribute ctxt)) asms; |
30775
71f777103225
added Element.init, which unifies former activate_elem in element.ML and init_elem in locale.ML;
wenzelm
parents:
30763
diff
changeset
|
487 |
val (_, ctxt') = ctxt |
71f777103225
added Element.init, which unifies former activate_elem in element.ML and init_elem in locale.ML;
wenzelm
parents:
30763
diff
changeset
|
488 |
|> fold Variable.auto_fixes (maps (map #1 o #2) asms') |
60377 | 489 |
|> Proof_Context.add_assms Assumption.assume_export asms'; |
30775
71f777103225
added Element.init, which unifies former activate_elem in element.ML and init_elem in locale.ML;
wenzelm
parents:
30763
diff
changeset
|
490 |
in ctxt' end) |
57864
7cf01ece66e4
clarified Element.init vs. Element.init' -- the latter also avoids redundant warnings due to declatations when preparing locale expressions / interpretations;
wenzelm
parents:
55997
diff
changeset
|
491 |
| init (Defines defs) = Context.map_proof (fn ctxt => |
28832 | 492 |
let |
47815 | 493 |
val defs' = Attrib.map_specs (map (Attrib.attribute ctxt)) defs; |
49750
444cfaa331c9
clarified Element.init vs. Element.activate: refrain from hard-wiring Thm.def_binding_optional to avoid duplicate facts;
wenzelm
parents:
47815
diff
changeset
|
494 |
val asms = defs' |> map (fn (b, (t, ps)) => |
444cfaa331c9
clarified Element.init vs. Element.activate: refrain from hard-wiring Thm.def_binding_optional to avoid duplicate facts;
wenzelm
parents:
47815
diff
changeset
|
495 |
let val (_, t') = Local_Defs.cert_def ctxt t (* FIXME adapt ps? *) |
444cfaa331c9
clarified Element.init vs. Element.activate: refrain from hard-wiring Thm.def_binding_optional to avoid duplicate facts;
wenzelm
parents:
47815
diff
changeset
|
496 |
in (t', (b, [(t', ps)])) end); |
30775
71f777103225
added Element.init, which unifies former activate_elem in element.ML and init_elem in locale.ML;
wenzelm
parents:
30763
diff
changeset
|
497 |
val (_, ctxt') = ctxt |
71f777103225
added Element.init, which unifies former activate_elem in element.ML and init_elem in locale.ML;
wenzelm
parents:
30763
diff
changeset
|
498 |
|> fold Variable.auto_fixes (map #1 asms) |
60377 | 499 |
|> Proof_Context.add_assms Local_Defs.def_export (map #2 asms); |
30775
71f777103225
added Element.init, which unifies former activate_elem in element.ML and init_elem in locale.ML;
wenzelm
parents:
30763
diff
changeset
|
500 |
in ctxt' end) |
57864
7cf01ece66e4
clarified Element.init vs. Element.init' -- the latter also avoids redundant warnings due to declatations when preparing locale expressions / interpretations;
wenzelm
parents:
55997
diff
changeset
|
501 |
| init (Notes (kind, facts)) = Attrib.generic_notes kind facts #> #2; |
54993
625370769fc0
check_hyps for attribute application (still inactive, due to non-compliant tools);
wenzelm
parents:
54883
diff
changeset
|
502 |
|
57864
7cf01ece66e4
clarified Element.init vs. Element.init' -- the latter also avoids redundant warnings due to declatations when preparing locale expressions / interpretations;
wenzelm
parents:
55997
diff
changeset
|
503 |
fun init' elem context = |
54993
625370769fc0
check_hyps for attribute application (still inactive, due to non-compliant tools);
wenzelm
parents:
54883
diff
changeset
|
504 |
context |
57864
7cf01ece66e4
clarified Element.init vs. Element.init' -- the latter also avoids redundant warnings due to declatations when preparing locale expressions / interpretations;
wenzelm
parents:
55997
diff
changeset
|
505 |
|> Context.mapping I (Thm.unchecked_hyps #> Context_Position.not_really) |
7cf01ece66e4
clarified Element.init vs. Element.init' -- the latter also avoids redundant warnings due to declatations when preparing locale expressions / interpretations;
wenzelm
parents:
55997
diff
changeset
|
506 |
|> init elem |
7cf01ece66e4
clarified Element.init vs. Element.init' -- the latter also avoids redundant warnings due to declatations when preparing locale expressions / interpretations;
wenzelm
parents:
55997
diff
changeset
|
507 |
|> Context.mapping I (fn ctxt => |
7cf01ece66e4
clarified Element.init vs. Element.init' -- the latter also avoids redundant warnings due to declatations when preparing locale expressions / interpretations;
wenzelm
parents:
55997
diff
changeset
|
508 |
let val ctxt0 = Context.proof_of context |
7cf01ece66e4
clarified Element.init vs. Element.init' -- the latter also avoids redundant warnings due to declatations when preparing locale expressions / interpretations;
wenzelm
parents:
55997
diff
changeset
|
509 |
in ctxt |> Context_Position.restore_visible ctxt0 |> Thm.restore_hyps ctxt0 end); |
30775
71f777103225
added Element.init, which unifies former activate_elem in element.ML and init_elem in locale.ML;
wenzelm
parents:
30763
diff
changeset
|
510 |
|
71f777103225
added Element.init, which unifies former activate_elem in element.ML and init_elem in locale.ML;
wenzelm
parents:
30763
diff
changeset
|
511 |
|
71f777103225
added Element.init, which unifies former activate_elem in element.ML and init_elem in locale.ML;
wenzelm
parents:
30763
diff
changeset
|
512 |
(* activate *) |
71f777103225
added Element.init, which unifies former activate_elem in element.ML and init_elem in locale.ML;
wenzelm
parents:
30763
diff
changeset
|
513 |
|
30777
9960ff945c52
simplified Element.activate(_i): singleton version;
wenzelm
parents:
30775
diff
changeset
|
514 |
fun activate_i elem ctxt = |
28832 | 515 |
let |
49750
444cfaa331c9
clarified Element.init vs. Element.activate: refrain from hard-wiring Thm.def_binding_optional to avoid duplicate facts;
wenzelm
parents:
47815
diff
changeset
|
516 |
val elem' = |
61814
1ca1142e1711
clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents:
61268
diff
changeset
|
517 |
(case (map_ctxt_attrib o map) Token.init_assignable elem of |
49750
444cfaa331c9
clarified Element.init vs. Element.activate: refrain from hard-wiring Thm.def_binding_optional to avoid duplicate facts;
wenzelm
parents:
47815
diff
changeset
|
518 |
Defines defs => |
444cfaa331c9
clarified Element.init vs. Element.activate: refrain from hard-wiring Thm.def_binding_optional to avoid duplicate facts;
wenzelm
parents:
47815
diff
changeset
|
519 |
Defines (defs |> map (fn ((a, atts), (t, ps)) => |
444cfaa331c9
clarified Element.init vs. Element.activate: refrain from hard-wiring Thm.def_binding_optional to avoid duplicate facts;
wenzelm
parents:
47815
diff
changeset
|
520 |
((Thm.def_binding_optional (Binding.name (#1 (#1 (Local_Defs.cert_def ctxt t)))) a, atts), |
444cfaa331c9
clarified Element.init vs. Element.activate: refrain from hard-wiring Thm.def_binding_optional to avoid duplicate facts;
wenzelm
parents:
47815
diff
changeset
|
521 |
(t, ps)))) |
444cfaa331c9
clarified Element.init vs. Element.activate: refrain from hard-wiring Thm.def_binding_optional to avoid duplicate facts;
wenzelm
parents:
47815
diff
changeset
|
522 |
| e => e); |
30777
9960ff945c52
simplified Element.activate(_i): singleton version;
wenzelm
parents:
30775
diff
changeset
|
523 |
val ctxt' = Context.proof_map (init elem') ctxt; |
61814
1ca1142e1711
clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents:
61268
diff
changeset
|
524 |
in ((map_ctxt_attrib o map) Token.closure elem', ctxt') end; |
28832 | 525 |
|
30777
9960ff945c52
simplified Element.activate(_i): singleton version;
wenzelm
parents:
30775
diff
changeset
|
526 |
fun activate raw_elem ctxt = |
9960ff945c52
simplified Element.activate(_i): singleton version;
wenzelm
parents:
30775
diff
changeset
|
527 |
let val elem = raw_elem |> map_ctxt |
43842
f035d867fb41
Element.activate: leave check of binding where actually applied to the context -- allow internal qualifications, or non-identifier fact names like "assumes *: A" (see also 1183951365de);
wenzelm
parents:
43837
diff
changeset
|
528 |
{binding = I, |
29603 | 529 |
typ = I, |
530 |
term = I, |
|
531 |
pattern = I, |
|
42360 | 532 |
fact = Proof_Context.get_fact ctxt, |
55997
9dc5ce83202c
modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
wenzelm
parents:
55914
diff
changeset
|
533 |
attrib = Attrib.check_src ctxt} |
30777
9960ff945c52
simplified Element.activate(_i): singleton version;
wenzelm
parents:
30775
diff
changeset
|
534 |
in activate_i elem ctxt end; |
28832 | 535 |
|
19267 | 536 |
end; |