author | wenzelm |
Fri, 27 Jan 2006 19:03:13 +0100 | |
changeset 18807 | 80df0609d25f |
parent 18783 | 628e57610536 |
child 18825 | c13136d648e2 |
permissions | -rw-r--r-- |
11897 | 1 |
(* Title: Pure/Isar/object_logic.ML |
2 |
ID: $Id$ |
|
3 |
Author: Markus Wenzel, TU Muenchen |
|
4 |
||
5 |
Specifics about common object-logics. |
|
6 |
*) |
|
7 |
||
8 |
signature OBJECT_LOGIC = |
|
9 |
sig |
|
10 |
val add_judgment: bstring * string * mixfix -> theory -> theory |
|
11 |
val add_judgment_i: bstring * typ * mixfix -> theory -> theory |
|
16449 | 12 |
val judgment_name: theory -> string |
13 |
val is_judgment: theory -> term -> bool |
|
14 |
val drop_judgment: theory -> term -> term |
|
15 |
val fixed_judgment: theory -> string -> term |
|
18121 | 16 |
val ensure_propT: theory -> term -> term |
18728 | 17 |
val declare_atomize: attribute |
18 |
val declare_rulify: attribute |
|
16449 | 19 |
val atomize_term: theory -> term -> term |
18783 | 20 |
val atomize_cterm: cterm -> thm |
14743 | 21 |
val atomize_thm: thm -> thm |
11897 | 22 |
val atomize_tac: int -> tactic |
12829 | 23 |
val full_atomize_tac: int -> tactic |
11897 | 24 |
val atomize_goal: int -> thm -> thm |
18807 | 25 |
val unatomize_term: theory -> term -> term |
26 |
val unatomize_tac: int -> tactic |
|
27 |
val rulify_term: theory -> term -> term |
|
28 |
val rulify_tac: int -> tactic |
|
11897 | 29 |
val rulify: thm -> thm |
30 |
val rulify_no_asm: thm -> thm |
|
18728 | 31 |
val rule_format: attribute |
32 |
val rule_format_no_asm: attribute |
|
11897 | 33 |
end; |
34 |
||
35 |
structure ObjectLogic: OBJECT_LOGIC = |
|
36 |
struct |
|
37 |
||
38 |
||
39 |
(** object-logic theory data **) |
|
40 |
||
41 |
(* data kind 'Pure/object-logic' *) |
|
42 |
||
16449 | 43 |
structure ObjectLogicData = TheoryDataFun |
44 |
(struct |
|
18563 | 45 |
val name = "Pure/object_logic"; |
11897 | 46 |
type T = string option * (thm list * thm list); |
47 |
||
15531 | 48 |
val empty = (NONE, ([], [Drule.norm_hhf_eq])); |
11897 | 49 |
val copy = I; |
16449 | 50 |
val extend = I; |
11897 | 51 |
|
15531 | 52 |
fun merge_judgment (SOME x, SOME y) = |
53 |
if x = y then SOME x else error "Attempt to merge different object-logics" |
|
15973 | 54 |
| merge_judgment (j1, j2) = if is_some j1 then j1 else j2; |
11897 | 55 |
|
16449 | 56 |
fun merge _ ((judgment1, (atomize1, rulify1)), (judgment2, (atomize2, rulify2))) = |
11897 | 57 |
(merge_judgment (judgment1, judgment2), |
58 |
(Drule.merge_rules (atomize1, atomize2), Drule.merge_rules (rulify1, rulify2))); |
|
59 |
||
60 |
fun print _ _ = (); |
|
16449 | 61 |
end); |
11897 | 62 |
|
18708 | 63 |
val _ = Context.add_setup ObjectLogicData.init; |
15801 | 64 |
|
11897 | 65 |
|
66 |
||
67 |
(** generic treatment of judgments -- with a single argument only **) |
|
68 |
||
69 |
(* add_judgment(_i) *) |
|
70 |
||
71 |
local |
|
72 |
||
15531 | 73 |
fun new_judgment name (NONE, rules) = (SOME name, rules) |
74 |
| new_judgment _ (SOME _, _) = error "Attempt to redeclare object-logic judgment"; |
|
11897 | 75 |
|
16449 | 76 |
fun gen_add_judgment add_consts (bname, T, mx) thy = |
77 |
let val c = Sign.full_name thy (Syntax.const_name bname mx) in |
|
14226 | 78 |
thy |
16449 | 79 |
|> add_consts [(bname, T, mx)] |
80 |
|> (fn thy' => Theory.add_finals_i false [(Const (c, Sign.the_const_type thy' c))] thy') |
|
81 |
|> ObjectLogicData.map (new_judgment c) |
|
14226 | 82 |
end; |
11897 | 83 |
|
84 |
in |
|
85 |
||
86 |
val add_judgment = gen_add_judgment Theory.add_consts; |
|
87 |
val add_judgment_i = gen_add_judgment Theory.add_consts_i; |
|
88 |
||
89 |
end; |
|
90 |
||
91 |
||
92 |
(* term operations *) |
|
93 |
||
16449 | 94 |
fun judgment_name thy = |
95 |
(case ObjectLogicData.get thy of |
|
15531 | 96 |
(SOME name, _) => name |
11897 | 97 |
| _ => raise TERM ("Unknown object-logic judgment", [])); |
98 |
||
16449 | 99 |
fun is_judgment thy (Const (c, _) $ _) = c = judgment_name thy |
11897 | 100 |
| is_judgment _ _ = false; |
101 |
||
16449 | 102 |
fun drop_judgment thy (Abs (x, T, t)) = Abs (x, T, drop_judgment thy t) |
103 |
| drop_judgment thy (tm as (Const (c, _) $ t)) = |
|
104 |
if (c = judgment_name thy handle TERM _ => false) then t else tm |
|
11897 | 105 |
| drop_judgment _ tm = tm; |
106 |
||
16449 | 107 |
fun fixed_judgment thy x = |
11897 | 108 |
let (*be robust wrt. low-level errors*) |
16449 | 109 |
val c = judgment_name thy; |
14854 | 110 |
val aT = TFree ("'a", []); |
11897 | 111 |
val T = |
16449 | 112 |
if_none (Sign.const_type thy c) (aT --> propT) |
11897 | 113 |
|> Term.map_type_tvar (fn ((x, _), S) => TFree (x, S)); |
114 |
val U = Term.domain_type T handle Match => aT; |
|
115 |
in Const (c, T) $ Free (x, U) end; |
|
116 |
||
18121 | 117 |
fun ensure_propT thy t = |
13376 | 118 |
let val T = Term.fastype_of t |
16449 | 119 |
in if T = propT then t else Const (judgment_name thy, T --> propT) $ t end; |
13376 | 120 |
|
11897 | 121 |
|
122 |
||
123 |
(** treatment of meta-level connectives **) |
|
124 |
||
125 |
(* maintain rules *) |
|
126 |
||
16449 | 127 |
val get_atomize = #1 o #2 o ObjectLogicData.get; |
18807 | 128 |
val get_unatomize = map Thm.symmetric o get_atomize; |
16449 | 129 |
val get_rulify = #2 o #2 o ObjectLogicData.get; |
11897 | 130 |
|
18728 | 131 |
val declare_atomize = |
132 |
Thm.declaration_attribute (Context.map_theory o ObjectLogicData.map o |
|
133 |
Library.apsnd o Library.apfst o Drule.add_rule); |
|
11897 | 134 |
|
18728 | 135 |
val declare_rulify = |
136 |
Thm.declaration_attribute (Context.map_theory o ObjectLogicData.map o |
|
137 |
Library.apsnd o Library.apsnd o Drule.add_rule); |
|
11897 | 138 |
|
139 |
||
140 |
(* atomize *) |
|
141 |
||
15001
fb2141a9f8c0
Moved conversion rules from MetaSimplifier to Drule. refl_implies removed
skalberg
parents:
14981
diff
changeset
|
142 |
fun rewrite_prems_tac rews i = PRIMITIVE (Drule.fconv_rule |
fb2141a9f8c0
Moved conversion rules from MetaSimplifier to Drule. refl_implies removed
skalberg
parents:
14981
diff
changeset
|
143 |
(Drule.goals_conv (Library.equal i) |
18254 | 144 |
(Drule.forall_conv ~1 |
15001
fb2141a9f8c0
Moved conversion rules from MetaSimplifier to Drule. refl_implies removed
skalberg
parents:
14981
diff
changeset
|
145 |
(Drule.goals_conv (K true) (Tactic.rewrite true rews))))); |
11897 | 146 |
|
16449 | 147 |
fun atomize_term thy = |
148 |
drop_judgment thy o MetaSimplifier.rewrite_term thy (get_atomize thy) []; |
|
12729 | 149 |
|
18783 | 150 |
fun atomize_cterm ct = Tactic.rewrite true (get_atomize (Thm.theory_of_cterm ct)) ct; |
17902 | 151 |
fun atomize_thm th = rewrite_rule (get_atomize (Thm.theory_of_thm th)) th; |
14743 | 152 |
|
11897 | 153 |
fun atomize_tac i st = |
12807 | 154 |
if Logic.has_meta_prems (Thm.prop_of st) i then |
16449 | 155 |
(rewrite_prems_tac (get_atomize (Thm.theory_of_thm st)) i) st |
11897 | 156 |
else all_tac st; |
157 |
||
12829 | 158 |
fun full_atomize_tac i st = |
16449 | 159 |
rewrite_goal_tac (get_atomize (Thm.theory_of_thm st)) i st; |
12829 | 160 |
|
11897 | 161 |
fun atomize_goal i st = |
15531 | 162 |
(case Seq.pull (atomize_tac i st) of NONE => st | SOME (st', _) => st'); |
11897 | 163 |
|
164 |
||
18807 | 165 |
(* unatomize -- not necessarily the same as rulify *) |
18783 | 166 |
|
18807 | 167 |
fun unatomize_term thy = MetaSimplifier.rewrite_term thy (get_unatomize thy) []; |
168 |
fun unatomize_tac i st = rewrite_goal_tac (get_unatomize (Thm.theory_of_thm st)) i st; |
|
18783 | 169 |
|
170 |
||
11897 | 171 |
(* rulify *) |
172 |
||
18807 | 173 |
fun rulify_term thy = MetaSimplifier.rewrite_term thy (get_rulify thy) []; |
174 |
fun rulify_tac i st = rewrite_goal_tac (get_rulify (Thm.theory_of_thm st)) i st; |
|
175 |
||
11897 | 176 |
fun gen_rulify full thm = |
16449 | 177 |
Tactic.simplify full (get_rulify (Thm.theory_of_thm thm)) thm |
12725 | 178 |
|> Drule.gen_all |> Drule.strip_shyps_warning |> Drule.zero_var_indexes; |
11897 | 179 |
|
180 |
val rulify = gen_rulify true; |
|
181 |
val rulify_no_asm = gen_rulify false; |
|
182 |
||
18728 | 183 |
fun rule_format x = Thm.rule_attribute (fn _ => rulify) x; |
184 |
fun rule_format_no_asm x = Thm.rule_attribute (fn _ => rulify_no_asm) x; |
|
11897 | 185 |
|
186 |
||
187 |
end; |