author | kuncar |
Mon, 24 Feb 2014 18:12:39 +0100 | |
changeset 55721 | 1c2cfc06c96a |
parent 54742 | 7a86358a3c0b |
child 56239 | 17df7145a871 |
permissions | -rw-r--r-- |
11897 | 1 |
(* Title: Pure/Isar/object_logic.ML |
2 |
Author: Markus Wenzel, TU Muenchen |
|
3 |
||
4 |
Specifics about common object-logics. |
|
5 |
*) |
|
6 |
||
7 |
signature OBJECT_LOGIC = |
|
8 |
sig |
|
25497 | 9 |
val get_base_sort: theory -> sort option |
10 |
val add_base_sort: sort -> theory -> theory |
|
30344
10a67c5ddddb
more uniform handling of binding in targets and derived elements;
wenzelm
parents:
29606
diff
changeset
|
11 |
val add_judgment: binding * typ * mixfix -> theory -> theory |
10a67c5ddddb
more uniform handling of binding in targets and derived elements;
wenzelm
parents:
29606
diff
changeset
|
12 |
val add_judgment_cmd: binding * string * mixfix -> theory -> theory |
16449 | 13 |
val judgment_name: theory -> string |
14 |
val is_judgment: theory -> term -> bool |
|
15 |
val drop_judgment: theory -> term -> term |
|
16 |
val fixed_judgment: theory -> string -> term |
|
18121 | 17 |
val ensure_propT: theory -> term -> term |
23586 | 18 |
val dest_judgment: cterm -> cterm |
23566
b65692d4adcd
replaced HOLogic.Trueprop_conv by ObjectLogic.judgment_conv;
wenzelm
parents:
23540
diff
changeset
|
19 |
val judgment_conv: conv -> conv |
41581
72a02e3dec7e
clarified pretty_statement: more robust treatment of fixes and conclusion of elimination (e.g. for classical rule);
wenzelm
parents:
41493
diff
changeset
|
20 |
val elim_concl: thm -> term option |
18728 | 21 |
val declare_atomize: attribute |
22 |
val declare_rulify: attribute |
|
16449 | 23 |
val atomize_term: theory -> term -> term |
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
53171
diff
changeset
|
24 |
val atomize: Proof.context -> conv |
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
53171
diff
changeset
|
25 |
val atomize_prems: Proof.context -> conv |
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
53171
diff
changeset
|
26 |
val atomize_prems_tac: Proof.context -> int -> tactic |
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
53171
diff
changeset
|
27 |
val full_atomize_tac: Proof.context -> int -> tactic |
18807 | 28 |
val rulify_term: theory -> term -> term |
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
53171
diff
changeset
|
29 |
val rulify_tac: Proof.context -> int -> tactic |
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
53171
diff
changeset
|
30 |
val rulify: Proof.context -> thm -> thm |
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
53171
diff
changeset
|
31 |
val rulify_no_asm: Proof.context -> thm -> thm |
18728 | 32 |
val rule_format: attribute |
33 |
val rule_format_no_asm: attribute |
|
11897 | 34 |
end; |
35 |
||
35625 | 36 |
structure Object_Logic: OBJECT_LOGIC = |
11897 | 37 |
struct |
38 |
||
25497 | 39 |
(** theory data **) |
11897 | 40 |
|
25497 | 41 |
datatype data = Data of |
42 |
{base_sort: sort option, |
|
43 |
judgment: string option, |
|
44 |
atomize_rulify: thm list * thm list}; |
|
45 |
||
46 |
fun make_data (base_sort, judgment, atomize_rulify) = |
|
47 |
Data {base_sort = base_sort, judgment = judgment, atomize_rulify = atomize_rulify}; |
|
11897 | 48 |
|
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
36610
diff
changeset
|
49 |
structure Data = Theory_Data |
22846 | 50 |
( |
25497 | 51 |
type T = data; |
52 |
val empty = make_data (NONE, NONE, ([], [])); |
|
16449 | 53 |
val extend = I; |
11897 | 54 |
|
25497 | 55 |
fun merge_opt eq (SOME x, SOME y) = |
56 |
if eq (x, y) then SOME x else error "Attempt to merge different object-logics" |
|
41493 | 57 |
| merge_opt _ data = merge_options data; |
11897 | 58 |
|
33522 | 59 |
fun merge |
25497 | 60 |
(Data {base_sort = base_sort1, judgment = judgment1, atomize_rulify = (atomize1, rulify1)}, |
61 |
Data {base_sort = base_sort2, judgment = judgment2, atomize_rulify = (atomize2, rulify2)}) = |
|
62 |
make_data (merge_opt (op =) (base_sort1, base_sort2), merge_opt (op =) (judgment1, judgment2), |
|
24039
273698405054
renamed Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents:
23602
diff
changeset
|
63 |
(Thm.merge_thms (atomize1, atomize2), Thm.merge_thms (rulify1, rulify2))); |
22846 | 64 |
); |
15801 | 65 |
|
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
36610
diff
changeset
|
66 |
fun map_data f = Data.map (fn (Data {base_sort, judgment, atomize_rulify}) => |
25497 | 67 |
make_data (f (base_sort, judgment, atomize_rulify))); |
68 |
||
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
36610
diff
changeset
|
69 |
fun get_data thy = Data.get thy |> (fn Data args => args); |
25497 | 70 |
|
11897 | 71 |
|
72 |
||
73 |
(** generic treatment of judgments -- with a single argument only **) |
|
74 |
||
25497 | 75 |
(* base_sort *) |
76 |
||
77 |
val get_base_sort = #base_sort o get_data; |
|
78 |
||
79 |
fun add_base_sort S = map_data (fn (base_sort, judgment, atomize_rulify) => |
|
80 |
if is_some base_sort then error "Attempt to redeclare object-logic base sort" |
|
81 |
else (SOME S, judgment, atomize_rulify)); |
|
82 |
||
83 |
||
18825 | 84 |
(* add judgment *) |
11897 | 85 |
|
86 |
local |
|
87 |
||
30344
10a67c5ddddb
more uniform handling of binding in targets and derived elements;
wenzelm
parents:
29606
diff
changeset
|
88 |
fun gen_add_judgment add_consts (b, T, mx) thy = |
35129 | 89 |
let val c = Sign.full_name thy b in |
14226 | 90 |
thy |
30344
10a67c5ddddb
more uniform handling of binding in targets and derived elements;
wenzelm
parents:
29606
diff
changeset
|
91 |
|> add_consts [(b, T, mx)] |
42375
774df7c59508
report Name_Space.declare/define, relatively to context;
wenzelm
parents:
42360
diff
changeset
|
92 |
|> (fn thy' => Theory.add_deps_global c (c, Sign.the_const_type thy' c) [] thy') |
25497 | 93 |
|> map_data (fn (base_sort, judgment, atomize_rulify) => |
94 |
if is_some judgment then error "Attempt to redeclare object-logic judgment" |
|
95 |
else (base_sort, SOME c, atomize_rulify)) |
|
14226 | 96 |
end; |
11897 | 97 |
|
98 |
in |
|
99 |
||
30344
10a67c5ddddb
more uniform handling of binding in targets and derived elements;
wenzelm
parents:
29606
diff
changeset
|
100 |
val add_judgment = gen_add_judgment Sign.add_consts_i; |
10a67c5ddddb
more uniform handling of binding in targets and derived elements;
wenzelm
parents:
29606
diff
changeset
|
101 |
val add_judgment_cmd = gen_add_judgment Sign.add_consts; |
11897 | 102 |
|
103 |
end; |
|
104 |
||
105 |
||
23566
b65692d4adcd
replaced HOLogic.Trueprop_conv by ObjectLogic.judgment_conv;
wenzelm
parents:
23540
diff
changeset
|
106 |
(* judgments *) |
11897 | 107 |
|
16449 | 108 |
fun judgment_name thy = |
25497 | 109 |
(case #judgment (get_data thy) of |
110 |
SOME name => name |
|
11897 | 111 |
| _ => raise TERM ("Unknown object-logic judgment", [])); |
112 |
||
16449 | 113 |
fun is_judgment thy (Const (c, _) $ _) = c = judgment_name thy |
11897 | 114 |
| is_judgment _ _ = false; |
115 |
||
16449 | 116 |
fun drop_judgment thy (Abs (x, T, t)) = Abs (x, T, drop_judgment thy t) |
117 |
| drop_judgment thy (tm as (Const (c, _) $ t)) = |
|
118 |
if (c = judgment_name thy handle TERM _ => false) then t else tm |
|
11897 | 119 |
| drop_judgment _ tm = tm; |
120 |
||
16449 | 121 |
fun fixed_judgment thy x = |
11897 | 122 |
let (*be robust wrt. low-level errors*) |
16449 | 123 |
val c = judgment_name thy; |
24848 | 124 |
val aT = TFree (Name.aT, []); |
11897 | 125 |
val T = |
18939 | 126 |
the_default (aT --> propT) (Sign.const_type thy c) |
11897 | 127 |
|> Term.map_type_tvar (fn ((x, _), S) => TFree (x, S)); |
128 |
val U = Term.domain_type T handle Match => aT; |
|
129 |
in Const (c, T) $ Free (x, U) end; |
|
130 |
||
18121 | 131 |
fun ensure_propT thy t = |
13376 | 132 |
let val T = Term.fastype_of t |
16449 | 133 |
in if T = propT then t else Const (judgment_name thy, T --> propT) $ t end; |
13376 | 134 |
|
23586 | 135 |
fun dest_judgment ct = |
136 |
if is_judgment (Thm.theory_of_cterm ct) (Thm.term_of ct) |
|
137 |
then Thm.dest_arg ct |
|
138 |
else raise CTERM ("dest_judgment", [ct]); |
|
139 |
||
23566
b65692d4adcd
replaced HOLogic.Trueprop_conv by ObjectLogic.judgment_conv;
wenzelm
parents:
23540
diff
changeset
|
140 |
fun judgment_conv cv ct = |
b65692d4adcd
replaced HOLogic.Trueprop_conv by ObjectLogic.judgment_conv;
wenzelm
parents:
23540
diff
changeset
|
141 |
if is_judgment (Thm.theory_of_cterm ct) (Thm.term_of ct) |
b65692d4adcd
replaced HOLogic.Trueprop_conv by ObjectLogic.judgment_conv;
wenzelm
parents:
23540
diff
changeset
|
142 |
then Conv.arg_conv cv ct |
b65692d4adcd
replaced HOLogic.Trueprop_conv by ObjectLogic.judgment_conv;
wenzelm
parents:
23540
diff
changeset
|
143 |
else raise CTERM ("judgment_conv", [ct]); |
b65692d4adcd
replaced HOLogic.Trueprop_conv by ObjectLogic.judgment_conv;
wenzelm
parents:
23540
diff
changeset
|
144 |
|
11897 | 145 |
|
19261 | 146 |
(* elimination rules *) |
147 |
||
41581
72a02e3dec7e
clarified pretty_statement: more robust treatment of fixes and conclusion of elimination (e.g. for classical rule);
wenzelm
parents:
41493
diff
changeset
|
148 |
fun elim_concl rule = |
19261 | 149 |
let |
150 |
val thy = Thm.theory_of_thm rule; |
|
151 |
val concl = Thm.concl_of rule; |
|
41581
72a02e3dec7e
clarified pretty_statement: more robust treatment of fixes and conclusion of elimination (e.g. for classical rule);
wenzelm
parents:
41493
diff
changeset
|
152 |
val C = drop_judgment thy concl; |
19261 | 153 |
in |
41581
72a02e3dec7e
clarified pretty_statement: more robust treatment of fixes and conclusion of elimination (e.g. for classical rule);
wenzelm
parents:
41493
diff
changeset
|
154 |
if Term.is_Var C andalso |
19261 | 155 |
exists (fn prem => concl aconv Logic.strip_assums_concl prem) (Thm.prems_of rule) |
41581
72a02e3dec7e
clarified pretty_statement: more robust treatment of fixes and conclusion of elimination (e.g. for classical rule);
wenzelm
parents:
41493
diff
changeset
|
156 |
then SOME C else NONE |
19261 | 157 |
end; |
158 |
||
159 |
||
11897 | 160 |
|
161 |
(** treatment of meta-level connectives **) |
|
162 |
||
163 |
(* maintain rules *) |
|
164 |
||
25497 | 165 |
val get_atomize = #1 o #atomize_rulify o get_data; |
166 |
val get_rulify = #2 o #atomize_rulify o get_data; |
|
11897 | 167 |
|
25497 | 168 |
fun add_atomize th = map_data (fn (base_sort, judgment, (atomize, rulify)) => |
169 |
(base_sort, judgment, (Thm.add_thm th atomize, rulify))); |
|
170 |
||
171 |
fun add_rulify th = map_data (fn (base_sort, judgment, (atomize, rulify)) => |
|
172 |
(base_sort, judgment, (atomize, Thm.add_thm th rulify))); |
|
11897 | 173 |
|
22846 | 174 |
val declare_atomize = Thm.declaration_attribute (fn th => Context.mapping (add_atomize th) I); |
175 |
val declare_rulify = Thm.declaration_attribute (fn th => Context.mapping (add_rulify th) I); |
|
176 |
||
53171 | 177 |
val _ = Theory.setup (fold add_rulify Drule.norm_hhf_eqs); |
11897 | 178 |
|
179 |
||
180 |
(* atomize *) |
|
181 |
||
16449 | 182 |
fun atomize_term thy = |
41228
e1fce873b814
renamed structure MetaSimplifier to raw_Simplifer, to emphasize its meaning;
wenzelm
parents:
37216
diff
changeset
|
183 |
drop_judgment thy o Raw_Simplifier.rewrite_term thy (get_atomize thy) []; |
12729 | 184 |
|
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
53171
diff
changeset
|
185 |
fun atomize ctxt = |
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
53171
diff
changeset
|
186 |
Raw_Simplifier.rewrite ctxt true (get_atomize (Proof_Context.theory_of ctxt)); |
14743 | 187 |
|
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
53171
diff
changeset
|
188 |
fun atomize_prems ctxt ct = |
23602
361e9c3a5e3a
tuned interfaces: atomize, atomize_prems, atomize_prems_tac;
wenzelm
parents:
23586
diff
changeset
|
189 |
if Logic.has_meta_prems (Thm.term_of ct) then |
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
53171
diff
changeset
|
190 |
Conv.params_conv ~1 (Conv.prems_conv ~1 o atomize) ctxt ct |
23602
361e9c3a5e3a
tuned interfaces: atomize, atomize_prems, atomize_prems_tac;
wenzelm
parents:
23586
diff
changeset
|
191 |
else Conv.all_conv ct; |
11897 | 192 |
|
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
53171
diff
changeset
|
193 |
val atomize_prems_tac = CONVERSION o atomize_prems; |
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
53171
diff
changeset
|
194 |
val full_atomize_tac = CONVERSION o atomize; |
11897 | 195 |
|
196 |
||
197 |
(* rulify *) |
|
198 |
||
41228
e1fce873b814
renamed structure MetaSimplifier to raw_Simplifer, to emphasize its meaning;
wenzelm
parents:
37216
diff
changeset
|
199 |
fun rulify_term thy = Raw_Simplifier.rewrite_term thy (get_rulify thy) []; |
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
53171
diff
changeset
|
200 |
fun rulify_tac ctxt = rewrite_goal_tac ctxt (get_rulify (Proof_Context.theory_of ctxt)); |
18807 | 201 |
|
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
53171
diff
changeset
|
202 |
fun gen_rulify full ctxt = |
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
53171
diff
changeset
|
203 |
Conv.fconv_rule (Raw_Simplifier.rewrite ctxt full (get_rulify (Proof_Context.theory_of ctxt))) |
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
53171
diff
changeset
|
204 |
#> Drule.gen_all #> Thm.strip_shyps #> Drule.zero_var_indexes; |
11897 | 205 |
|
206 |
val rulify = gen_rulify true; |
|
207 |
val rulify_no_asm = gen_rulify false; |
|
208 |
||
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
53171
diff
changeset
|
209 |
val rule_format = Thm.rule_attribute (rulify o Context.proof_of); |
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
53171
diff
changeset
|
210 |
val rule_format_no_asm = Thm.rule_attribute (rulify_no_asm o Context.proof_of); |
11897 | 211 |
|
212 |
end; |