author | wenzelm |
Sun, 04 Dec 2016 18:53:55 +0100 | |
changeset 64537 | 693389d87139 |
parent 64398 | 5076725247fa |
child 67522 | 9e712280cc37 |
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; |
64398
5076725247fa
more robust printing of names in the context of outer syntax;
wenzelm
parents:
63395
diff
changeset
|
130 |
val prt_name = Proof_Context.pretty_name ctxt; |
19259 | 131 |
|
132 |
fun prt_show (a, ts) = |
|
60242
3a8501876dba
tuned output -- avoid empty quites and extra breaks;
wenzelm
parents:
59970
diff
changeset
|
133 |
Pretty.block (Pretty.breaks (prt_binding a ":" @ prt_terms (map fst ts))); |
19259 | 134 |
|
60448 | 135 |
fun prt_var (x, SOME T, _) = Pretty.block |
64398
5076725247fa
more robust printing of names in the context of outer syntax;
wenzelm
parents:
63395
diff
changeset
|
136 |
[prt_name (Binding.name_of x), Pretty.str " ::", Pretty.brk 1, prt_typ T] |
5076725247fa
more robust printing of names in the context of outer syntax;
wenzelm
parents:
63395
diff
changeset
|
137 |
| prt_var (x, NONE, _) = prt_name (Binding.name_of x); |
55763 | 138 |
val prt_vars = separate (Pretty.keyword2 "and") o map prt_var; |
19259 | 139 |
|
60448 | 140 |
fun prt_obtain (_, ([], props)) = Pretty.block (Pretty.breaks (prt_terms props)) |
141 |
| prt_obtain (_, (vars, props)) = Pretty.block (Pretty.breaks |
|
142 |
(prt_vars vars @ [Pretty.keyword2 "where"] @ prt_terms props)); |
|
19259 | 143 |
in |
19267 | 144 |
fn Shows shows => pretty_items "shows" "and" (map prt_show shows) |
145 |
| Obtains obtains => pretty_items "obtains" "|" (map prt_obtain obtains) |
|
19259 | 146 |
end; |
147 |
||
18894 | 148 |
|
19259 | 149 |
(* pretty_ctxt *) |
150 |
||
59385 | 151 |
fun gen_pretty_ctxt show_attribs ctxt = |
19259 | 152 |
let |
24920 | 153 |
val prt_typ = Pretty.quote o Syntax.pretty_typ ctxt; |
154 |
val prt_term = Pretty.quote o Syntax.pretty_term ctxt; |
|
62094 | 155 |
val prt_thm = Pretty.cartouche o Thm.pretty_thm ctxt; |
64398
5076725247fa
more robust printing of names in the context of outer syntax;
wenzelm
parents:
63395
diff
changeset
|
156 |
val prt_name = Proof_Context.pretty_name ctxt; |
59385 | 157 |
|
60242
3a8501876dba
tuned output -- avoid empty quites and extra breaks;
wenzelm
parents:
59970
diff
changeset
|
158 |
fun prt_binding (b, atts) = |
3a8501876dba
tuned output -- avoid empty quites and extra breaks;
wenzelm
parents:
59970
diff
changeset
|
159 |
Attrib.pretty_binding ctxt (b, if show_attribs then atts else []); |
59385 | 160 |
|
161 |
fun prt_fact (ths, atts) = |
|
162 |
if not show_attribs orelse null atts then map prt_thm ths |
|
163 |
else |
|
164 |
Pretty.enclose "(" ")" (Pretty.breaks (map prt_thm ths)) :: |
|
165 |
Attrib.pretty_attribs ctxt atts; |
|
19259 | 166 |
|
19267 | 167 |
fun prt_mixfix NoSyn = [] |
42287
d98eb048a2e4
discontinued special treatment of structure Mixfix;
wenzelm
parents:
41581
diff
changeset
|
168 |
| prt_mixfix mx = [Pretty.brk 2, Mixfix.pretty_mixfix mx]; |
19267 | 169 |
|
64398
5076725247fa
more robust printing of names in the context of outer syntax;
wenzelm
parents:
63395
diff
changeset
|
170 |
fun prt_fix (x, SOME T, mx) = Pretty.block (prt_name (Binding.name_of x) :: Pretty.str " ::" :: |
28079
955c42c8a5e4
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27865
diff
changeset
|
171 |
Pretty.brk 1 :: prt_typ T :: Pretty.brk 1 :: prt_mixfix mx) |
64398
5076725247fa
more robust printing of names in the context of outer syntax;
wenzelm
parents:
63395
diff
changeset
|
172 |
| prt_fix (x, NONE, mx) = Pretty.block (prt_name (Binding.name_of x) :: |
28079
955c42c8a5e4
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27865
diff
changeset
|
173 |
Pretty.brk 1 :: prt_mixfix mx); |
28965 | 174 |
fun prt_constrain (x, T) = prt_fix (Binding.name x, SOME T, NoSyn); |
18894 | 175 |
|
19259 | 176 |
fun prt_asm (a, ts) = |
60242
3a8501876dba
tuned output -- avoid empty quites and extra breaks;
wenzelm
parents:
59970
diff
changeset
|
177 |
Pretty.block (Pretty.breaks (prt_binding a ":" @ map (prt_term o fst) ts)); |
19259 | 178 |
fun prt_def (a, (t, _)) = |
60242
3a8501876dba
tuned output -- avoid empty quites and extra breaks;
wenzelm
parents:
59970
diff
changeset
|
179 |
Pretty.block (Pretty.breaks (prt_binding a ":" @ [prt_term t])); |
19259 | 180 |
|
181 |
fun prt_note (a, ths) = |
|
60242
3a8501876dba
tuned output -- avoid empty quites and extra breaks;
wenzelm
parents:
59970
diff
changeset
|
182 |
Pretty.block (Pretty.breaks (flat (prt_binding a " =" :: map prt_fact ths))); |
19259 | 183 |
in |
19267 | 184 |
fn Fixes fixes => pretty_items "fixes" "and" (map prt_fix fixes) |
185 |
| Constrains xs => pretty_items "constrains" "and" (map prt_constrain xs) |
|
186 |
| Assumes asms => pretty_items "assumes" "and" (map prt_asm asms) |
|
187 |
| Defines defs => pretty_items "defines" "and" (map prt_def defs) |
|
21440 | 188 |
| Notes ("", facts) => pretty_items "notes" "and" (map prt_note facts) |
189 |
| Notes (kind, facts) => pretty_items ("notes " ^ kind) "and" (map prt_note facts) |
|
19259 | 190 |
end; |
18894 | 191 |
|
59385 | 192 |
val pretty_ctxt = gen_pretty_ctxt true; |
193 |
val pretty_ctxt_no_attribs = gen_pretty_ctxt false; |
|
194 |
||
19267 | 195 |
|
196 |
(* pretty_statement *) |
|
197 |
||
198 |
local |
|
199 |
||
59970 | 200 |
fun standard_elim ctxt th = |
201 |
(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
|
202 |
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
|
203 |
let |
72a02e3dec7e
clarified pretty_statement: more robust treatment of fixes and conclusion of elimination (e.g. for classical rule);
wenzelm
parents:
41425
diff
changeset
|
204 |
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
|
205 |
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
|
206 |
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
|
207 |
| 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
|
208 |
|
64398
5076725247fa
more robust printing of names in the context of outer syntax;
wenzelm
parents:
63395
diff
changeset
|
209 |
fun thm_name ctxt kind th prts = |
19267 | 210 |
let val head = |
27865
27a8ad9612a3
moved basic thm operations from structure PureThy to Thm (cf. more_thm.ML);
wenzelm
parents:
26721
diff
changeset
|
211 |
if Thm.has_name_hint th then |
64398
5076725247fa
more robust printing of names in the context of outer syntax;
wenzelm
parents:
63395
diff
changeset
|
212 |
Pretty.block [Pretty.keyword1 kind, Pretty.brk 1, |
5076725247fa
more robust printing of names in the context of outer syntax;
wenzelm
parents:
63395
diff
changeset
|
213 |
Proof_Context.pretty_name ctxt (Long_Name.base_name (Thm.get_name_hint th)), Pretty.str ":"] |
55763 | 214 |
else Pretty.keyword1 kind |
19267 | 215 |
in Pretty.block (Pretty.fbreaks (head :: prts)) end; |
216 |
||
217 |
fun obtain prop ctxt = |
|
218 |
let |
|
60695
757549b4bbe6
Variable.focus etc.: optional bindings provided by user;
wenzelm
parents:
60642
diff
changeset
|
219 |
val ((ps, prop'), ctxt') = Variable.focus NONE prop ctxt; |
60448 | 220 |
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
|
221 |
val xs = map (fix o #2) ps; |
1af81b70cf09
clarified Variable.focus vs. Variable.focus_cterm -- eliminated clone;
wenzelm
parents:
42494
diff
changeset
|
222 |
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
|
223 |
in ((Binding.empty, (xs, As)), ctxt') end; |
19267 | 224 |
|
225 |
in |
|
226 |
||
227 |
fun pretty_statement ctxt kind raw_th = |
|
228 |
let |
|
59970 | 229 |
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
|
230 |
val ((_, [th']), ctxt') = Variable.import true [th] (Variable.set_body true ctxt); |
20150 | 231 |
val prop = Thm.prop_of th'; |
232 |
val (prems, concl) = Logic.strip_horn prop; |
|
59970 | 233 |
val concl_term = Object_Logic.drop_judgment ctxt concl; |
19267 | 234 |
|
62681
45b8dd2d3827
more accurate fixes (e.g. for notE, FalseE), amending baa589c574ff;
wenzelm
parents:
62680
diff
changeset
|
235 |
val (assumes, cases) = |
45b8dd2d3827
more accurate fixes (e.g. for notE, FalseE), amending baa589c574ff;
wenzelm
parents:
62680
diff
changeset
|
236 |
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
|
237 |
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
|
238 |
val fixes = |
45b8dd2d3827
more accurate fixes (e.g. for notE, FalseE), amending baa589c574ff;
wenzelm
parents:
62680
diff
changeset
|
239 |
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
|
240 |
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
|
241 |
then insert (op =) (Variable.revert_fixed ctxt' x, T) else I | _ => I) prop []); |
19267 | 242 |
in |
28965 | 243 |
pretty_ctxt ctxt' (Fixes (map (fn (x, T) => (Binding.name x, SOME T, NoSyn)) fixes)) @ |
63352 | 244 |
pretty_ctxt ctxt' (Assumes (map (fn t => (Binding.empty_atts, [(t, [])])) assumes)) @ |
245 |
(if null cases then pretty_stmt ctxt' (Shows [(Binding.empty_atts, [(concl, [])])]) |
|
26716
8690e75e1395
print_statement: reset body mode, i.e. invent global frees (no need for revert_skolem);
wenzelm
parents:
26628
diff
changeset
|
246 |
else |
42495
1af81b70cf09
clarified Variable.focus vs. Variable.focus_cterm -- eliminated clone;
wenzelm
parents:
42494
diff
changeset
|
247 |
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
|
248 |
in pretty_stmt ctxt'' (Obtains clauses) end) |
64398
5076725247fa
more robust printing of names in the context of outer syntax;
wenzelm
parents:
63395
diff
changeset
|
249 |
end |> thm_name ctxt kind raw_th; |
19267 | 250 |
|
18140
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
251 |
end; |
19267 | 252 |
|
19777 | 253 |
|
254 |
||
255 |
(** logical operations **) |
|
256 |
||
257 |
(* witnesses -- hypotheses as protected facts *) |
|
258 |
||
259 |
datatype witness = Witness of term * thm; |
|
260 |
||
29578 | 261 |
val mark_witness = Logic.protect; |
262 |
fun witness_prop (Witness (t, _)) = t; |
|
44058 | 263 |
fun witness_hyps (Witness (_, th)) = Thm.hyps_of th; |
19777 | 264 |
fun map_witness f (Witness witn) = Witness (f witn); |
265 |
||
45290 | 266 |
fun transform_witness phi = map_witness (fn (t, th) => (Morphism.term phi t, Morphism.thm phi th)); |
21481 | 267 |
|
20058 | 268 |
fun prove_witness ctxt t tac = |
52732 | 269 |
Witness (t, |
270 |
Thm.close_derivation |
|
58837 | 271 |
(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
|
272 |
(fn _ => resolve_tac ctxt [Drule.protectI] 1 THEN tac))); |
19777 | 273 |
|
29603 | 274 |
|
29578 | 275 |
local |
276 |
||
277 |
val refine_witness = |
|
61841
4d3527b94f2a
more general types Proof.method / context_tactic;
wenzelm
parents:
61814
diff
changeset
|
278 |
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
|
279 |
K (ALLGOALS (CONJUNCTS (ALLGOALS (CONJUNCTS (TRYALL (resolve_tac ctxt [Drule.protectI])))))))); |
25624 | 280 |
|
29578 | 281 |
fun gen_witness_proof proof after_qed wit_propss eq_props = |
282 |
let |
|
46896 | 283 |
val propss = |
284 |
(map o map) (fn prop => (mark_witness prop, [])) wit_propss @ |
|
285 |
[map (rpair []) eq_props]; |
|
29578 | 286 |
fun after_qed' thmss = |
29603 | 287 |
let val (wits, eqs) = split_last ((map o map) Thm.close_derivation thmss); |
29578 | 288 |
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
|
289 |
in proof after_qed' propss #> refine_witness end; |
29578 | 290 |
|
62680
646b84666a56
eliminated unused argument (see also 58110c1e02bc);
wenzelm
parents:
62094
diff
changeset
|
291 |
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
|
292 |
let |
9d37b2330ee3
clarified local after_qed: result is not exported yet;
wenzelm
parents:
60414
diff
changeset
|
293 |
fun after_qed' (result_ctxt, results) state' = |
9d37b2330ee3
clarified local after_qed: result is not exported yet;
wenzelm
parents:
60414
diff
changeset
|
294 |
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
|
295 |
in |
9d37b2330ee3
clarified local after_qed: result is not exported yet;
wenzelm
parents:
60414
diff
changeset
|
296 |
Proof.map_context (K goal_ctxt) #> |
60555
51a6997b1384
support 'when' statement, which corresponds to 'presume';
wenzelm
parents:
60461
diff
changeset
|
297 |
Proof.internal_goal (K (K ())) (Proof_Context.get_mode goal_ctxt) true cmd |
63352 | 298 |
NONE after_qed' [] [] (map (pair Binding.empty_atts) propp) #> snd |
60415
9d37b2330ee3
clarified local after_qed: result is not exported yet;
wenzelm
parents:
60414
diff
changeset
|
299 |
end; |
41425 | 300 |
|
29578 | 301 |
in |
302 |
||
303 |
fun witness_proof after_qed wit_propss = |
|
36323
655e2d74de3a
modernized naming conventions of main Isar proof elements;
wenzelm
parents:
35767
diff
changeset
|
304 |
gen_witness_proof (Proof.theorem NONE) (fn wits => fn _ => after_qed wits) |
29578 | 305 |
wit_propss []; |
306 |
||
36323
655e2d74de3a
modernized naming conventions of main Isar proof elements;
wenzelm
parents:
35767
diff
changeset
|
307 |
val witness_proof_eqs = gen_witness_proof (Proof.theorem NONE); |
29578 | 308 |
|
62680
646b84666a56
eliminated unused argument (see also 58110c1e02bc);
wenzelm
parents:
62094
diff
changeset
|
309 |
fun witness_local_proof after_qed cmd wit_propss goal_ctxt = |
646b84666a56
eliminated unused argument (see also 58110c1e02bc);
wenzelm
parents:
62094
diff
changeset
|
310 |
gen_witness_proof (proof_local cmd goal_ctxt) |
29578 | 311 |
(fn wits => fn _ => after_qed wits) wit_propss []; |
312 |
||
62680
646b84666a56
eliminated unused argument (see also 58110c1e02bc);
wenzelm
parents:
62094
diff
changeset
|
313 |
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
|
314 |
gen_witness_proof (proof_local cmd goal_ctxt) after_qed wit_propss eq_props; |
41425 | 315 |
|
29603 | 316 |
end; |
317 |
||
19777 | 318 |
|
25302 | 319 |
fun compose_witness (Witness (_, th)) r = |
320 |
let |
|
321 |
val th' = Goal.conclude th; |
|
322 |
val A = Thm.cprem_of r 1; |
|
25739 | 323 |
in |
324 |
Thm.implies_elim |
|
325 |
(Conv.gconv_rule Drule.beta_eta_conversion 1 r) |
|
326 |
(Conv.fconv_rule Drule.beta_eta_conversion |
|
327 |
(Thm.instantiate (Thm.match (Thm.cprop_of th', A)) th')) |
|
328 |
end; |
|
25302 | 329 |
|
54883
dd04a8b654fc
proper context for norm_hhf and derived operations;
wenzelm
parents:
54742
diff
changeset
|
330 |
fun conclude_witness ctxt (Witness (_, th)) = |
dd04a8b654fc
proper context for norm_hhf and derived operations;
wenzelm
parents:
54742
diff
changeset
|
331 |
Thm.close_derivation (Raw_Simplifier.norm_hhf_protect ctxt (Goal.conclude th)); |
19777 | 332 |
|
22658
263d42253f53
Experimental interpretation code for definitions.
ballarin
parents:
22568
diff
changeset
|
333 |
fun pretty_witness ctxt witn = |
24920 | 334 |
let val prt_term = Pretty.quote o Syntax.pretty_term ctxt in |
22658
263d42253f53
Experimental interpretation code for definitions.
ballarin
parents:
22568
diff
changeset
|
335 |
Pretty.block (prt_term (witness_prop witn) :: |
39166
19efc2af3e6c
turned show_hyps and show_tags into proper configuration option;
wenzelm
parents:
38709
diff
changeset
|
336 |
(if Config.get ctxt show_hyps then [Pretty.brk 2, Pretty.list "[" "]" |
22658
263d42253f53
Experimental interpretation code for definitions.
ballarin
parents:
22568
diff
changeset
|
337 |
(map prt_term (witness_hyps witn))] else [])) |
263d42253f53
Experimental interpretation code for definitions.
ballarin
parents:
22568
diff
changeset
|
338 |
end; |
263d42253f53
Experimental interpretation code for definitions.
ballarin
parents:
22568
diff
changeset
|
339 |
|
19777 | 340 |
|
341 |
(* derived rules *) |
|
342 |
||
20007 | 343 |
fun instantiate_tfrees thy subst th = |
19777 | 344 |
let |
20007 | 345 |
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
|
346 |
fun cert_inst (a, (S, T)) = (((a, idx), S), Thm.global_ctyp_of thy T); |
20007 | 347 |
|
348 |
fun add_inst (a, S) insts = |
|
349 |
if AList.defined (op =) insts a then insts |
|
350 |
else (case AList.lookup (op =) subst a of NONE => insts | SOME T => (a, (S, T)) :: insts); |
|
351 |
val insts = |
|
45346
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
352 |
(Term.fold_types o Term.fold_atyps) (fn TFree v => add_inst v | _ => I) |
20007 | 353 |
(Thm.full_prop_of th) []; |
19777 | 354 |
in |
20007 | 355 |
th |
356 |
|> Thm.generalize (map fst insts, []) idx |
|
357 |
|> Thm.instantiate (map cert_inst insts, []) |
|
19777 | 358 |
end; |
359 |
||
360 |
fun instantiate_frees thy subst = |
|
59621
291934bac95e
Thm.cterm_of and Thm.ctyp_of operate on local context;
wenzelm
parents:
59616
diff
changeset
|
361 |
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
|
362 |
Drule.forall_elim_list (map (Thm.global_cterm_of thy o snd) subst); |
19777 | 363 |
|
364 |
fun hyps_rule rule th = |
|
60949 | 365 |
let val hyps = Thm.chyps_of th in |
19777 | 366 |
Drule.implies_elim_list |
367 |
(rule (Drule.implies_intr_list hyps th)) |
|
21521 | 368 |
(map (Thm.assume o Drule.cterm_rule rule) hyps) |
19777 | 369 |
end; |
370 |
||
371 |
||
372 |
(* instantiate types *) |
|
373 |
||
45346
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
374 |
fun instT_type_same env = |
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
375 |
if Symtab.is_empty env then Same.same |
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
376 |
else |
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
377 |
Term_Subst.map_atypsT_same |
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
378 |
(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
|
379 |
| _ => raise Same.SAME); |
19777 | 380 |
|
45346
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
381 |
fun instT_term_same env = |
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
382 |
if Symtab.is_empty env then Same.same |
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
383 |
else Term_Subst.map_types_same (instT_type_same env); |
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
384 |
|
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
385 |
val instT_type = Same.commit o instT_type_same; |
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
386 |
val instT_term = Same.commit o instT_term_same; |
19777 | 387 |
|
45346
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
388 |
fun instT_subst env th = |
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
389 |
(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
|
390 |
(fn T as TFree (a, _) => |
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
391 |
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
|
392 |
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
|
393 |
| _ => I) th []; |
19777 | 394 |
|
395 |
fun instT_thm thy env th = |
|
396 |
if Symtab.is_empty env then th |
|
397 |
else |
|
398 |
let val subst = instT_subst env th |
|
399 |
in if null subst then th else th |> hyps_rule (instantiate_tfrees thy subst) end; |
|
400 |
||
22672
777af26d5713
inst(T)_morphism: avoid reference to static theory value;
wenzelm
parents:
22658
diff
changeset
|
401 |
fun instT_morphism thy env = |
54740 | 402 |
Morphism.morphism "Element.instT" |
52788 | 403 |
{binding = [], |
404 |
typ = [instT_type env], |
|
405 |
term = [instT_term env], |
|
52789 | 406 |
fact = [map (instT_thm thy env)]}; |
19777 | 407 |
|
408 |
||
409 |
(* instantiate types and terms *) |
|
410 |
||
411 |
fun inst_term (envT, env) = |
|
412 |
if Symtab.is_empty env then instT_term envT |
|
413 |
else |
|
45346
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
414 |
instT_term envT #> |
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
415 |
Same.commit (Term_Subst.map_aterms_same |
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
416 |
(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
|
417 |
| _ => raise Same.SAME)) #> |
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
418 |
Envir.beta_norm; |
19777 | 419 |
|
45349
7fb63b469cd2
more uniform instT_subst vs. inst_subst: compare variable names only;
wenzelm
parents:
45346
diff
changeset
|
420 |
fun inst_subst (envT, env) th = |
7fb63b469cd2
more uniform instT_subst vs. inst_subst: compare variable names only;
wenzelm
parents:
45346
diff
changeset
|
421 |
(Thm.fold_terms o Term.fold_aterms) |
7fb63b469cd2
more uniform instT_subst vs. inst_subst: compare variable names only;
wenzelm
parents:
45346
diff
changeset
|
422 |
(fn Free (x, T) => |
7fb63b469cd2
more uniform instT_subst vs. inst_subst: compare variable names only;
wenzelm
parents:
45346
diff
changeset
|
423 |
let |
7fb63b469cd2
more uniform instT_subst vs. inst_subst: compare variable names only;
wenzelm
parents:
45346
diff
changeset
|
424 |
val T' = instT_type envT T; |
7fb63b469cd2
more uniform instT_subst vs. inst_subst: compare variable names only;
wenzelm
parents:
45346
diff
changeset
|
425 |
val t = Free (x, T'); |
7fb63b469cd2
more uniform instT_subst vs. inst_subst: compare variable names only;
wenzelm
parents:
45346
diff
changeset
|
426 |
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
|
427 |
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
|
428 |
| _ => I) th []; |
7fb63b469cd2
more uniform instT_subst vs. inst_subst: compare variable names only;
wenzelm
parents:
45346
diff
changeset
|
429 |
|
19777 | 430 |
fun inst_thm thy (envT, env) th = |
431 |
if Symtab.is_empty env then instT_thm thy envT th |
|
432 |
else |
|
433 |
let |
|
434 |
val substT = instT_subst envT th; |
|
45349
7fb63b469cd2
more uniform instT_subst vs. inst_subst: compare variable names only;
wenzelm
parents:
45346
diff
changeset
|
435 |
val subst = inst_subst (envT, env) th; |
19777 | 436 |
in |
437 |
if null substT andalso null subst then th |
|
438 |
else th |> hyps_rule |
|
439 |
(instantiate_tfrees thy substT #> |
|
440 |
instantiate_frees thy subst #> |
|
22900 | 441 |
Conv.fconv_rule (Thm.beta_conversion true)) |
19777 | 442 |
end; |
443 |
||
45346
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
444 |
fun inst_morphism thy (envT, env) = |
54740 | 445 |
Morphism.morphism "Element.inst" |
52788 | 446 |
{binding = [], |
447 |
typ = [instT_type envT], |
|
448 |
term = [inst_term (envT, env)], |
|
52789 | 449 |
fact = [map (inst_thm thy (envT, env))]}; |
19777 | 450 |
|
451 |
||
452 |
(* satisfy hypotheses *) |
|
453 |
||
45346
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
454 |
fun satisfy_thm witns thm = |
439101d8eeec
some performance tuning via Term_Subst/Same.operation;
wenzelm
parents:
45345
diff
changeset
|
455 |
thm |> fold (fn hyp => |
19777 | 456 |
(case find_first (fn Witness (t, _) => Thm.term_of hyp aconv t) witns of |
457 |
NONE => I |
|
60949 | 458 |
| SOME w => Thm.implies_intr hyp #> compose_witness w)) (Thm.chyps_of thm); |
19777 | 459 |
|
54740 | 460 |
val satisfy_morphism = Morphism.thm_morphism "Element.satisfy" o satisfy_thm; |
20264 | 461 |
|
462 |
||
29525 | 463 |
(* rewriting with equalities *) |
464 |
||
46856 | 465 |
fun eq_morphism _ [] = NONE |
466 |
| 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
|
467 |
let |
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
54740
diff
changeset
|
468 |
(* FIXME proper context!? *) |
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
54740
diff
changeset
|
469 |
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
|
470 |
val phi = |
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
54740
diff
changeset
|
471 |
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
|
472 |
{binding = [], |
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
54740
diff
changeset
|
473 |
typ = [], |
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
54740
diff
changeset
|
474 |
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
|
475 |
fact = [map rewrite]}; |
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
54740
diff
changeset
|
476 |
in SOME phi end; |
29525 | 477 |
|
478 |
||
29218 | 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 |
(** activate in context **) |
28832 | 481 |
|
30775
71f777103225
added Element.init, which unifies former activate_elem in element.ML and init_elem in locale.ML;
wenzelm
parents:
30763
diff
changeset
|
482 |
(* init *) |
28832 | 483 |
|
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
|
484 |
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
|
485 |
| 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
|
486 |
| init (Assumes asms) = Context.map_proof (fn ctxt => |
28832 | 487 |
let |
47815 | 488 |
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
|
489 |
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
|
490 |
|> fold Variable.auto_fixes (maps (map #1 o #2) asms') |
60377 | 491 |
|> 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
|
492 |
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
|
493 |
| init (Defines defs) = Context.map_proof (fn ctxt => |
28832 | 494 |
let |
47815 | 495 |
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
|
496 |
val asms = defs' |> map (fn (b, (t, ps)) => |
63395 | 497 |
let val (_, t') = Local_Defs.cert_def ctxt (K []) t (* FIXME adapt ps? *) |
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
|
498 |
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
|
499 |
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
|
500 |
|> fold Variable.auto_fixes (map #1 asms) |
60377 | 501 |
|> 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
|
502 |
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
|
503 |
| 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
|
504 |
|
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 |
fun init' elem context = |
54993
625370769fc0
check_hyps for attribute application (still inactive, due to non-compliant tools);
wenzelm
parents:
54883
diff
changeset
|
506 |
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
|
507 |
|> 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
|
508 |
|> 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
|
509 |
|> 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
|
510 |
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
|
511 |
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
|
512 |
|
71f777103225
added Element.init, which unifies former activate_elem in element.ML and init_elem in locale.ML;
wenzelm
parents:
30763
diff
changeset
|
513 |
|
71f777103225
added Element.init, which unifies former activate_elem in element.ML and init_elem in locale.ML;
wenzelm
parents:
30763
diff
changeset
|
514 |
(* activate *) |
71f777103225
added Element.init, which unifies former activate_elem in element.ML and init_elem in locale.ML;
wenzelm
parents:
30763
diff
changeset
|
515 |
|
30777
9960ff945c52
simplified Element.activate(_i): singleton version;
wenzelm
parents:
30775
diff
changeset
|
516 |
fun activate_i elem ctxt = |
28832 | 517 |
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
|
518 |
val elem' = |
61814
1ca1142e1711
clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents:
61268
diff
changeset
|
519 |
(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
|
520 |
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
|
521 |
Defines (defs |> map (fn ((a, atts), (t, ps)) => |
63395 | 522 |
((Thm.def_binding_optional |
523 |
(Binding.name (#1 (#1 (Local_Defs.cert_def ctxt (K []) t)))) a, atts), |
|
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
|
524 |
(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
|
525 |
| e => e); |
30777
9960ff945c52
simplified Element.activate(_i): singleton version;
wenzelm
parents:
30775
diff
changeset
|
526 |
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
|
527 |
in ((map_ctxt_attrib o map) Token.closure elem', ctxt') end; |
28832 | 528 |
|
30777
9960ff945c52
simplified Element.activate(_i): singleton version;
wenzelm
parents:
30775
diff
changeset
|
529 |
fun activate raw_elem ctxt = |
9960ff945c52
simplified Element.activate(_i): singleton version;
wenzelm
parents:
30775
diff
changeset
|
530 |
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
|
531 |
{binding = I, |
29603 | 532 |
typ = I, |
533 |
term = I, |
|
534 |
pattern = I, |
|
42360 | 535 |
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
|
536 |
attrib = Attrib.check_src ctxt} |
30777
9960ff945c52
simplified Element.activate(_i): singleton version;
wenzelm
parents:
30775
diff
changeset
|
537 |
in activate_i elem ctxt end; |
28832 | 538 |
|
19267 | 539 |
end; |