author | wenzelm |
Thu, 05 Jul 2007 00:06:25 +0200 | |
changeset 23586 | 7d6b1d800dc4 |
parent 23566 | b65692d4adcd |
child 23602 | 361e9c3a5e3a |
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 |
23586 | 17 |
val dest_judgment: cterm -> cterm |
23566
b65692d4adcd
replaced HOLogic.Trueprop_conv by ObjectLogic.judgment_conv;
wenzelm
parents:
23540
diff
changeset
|
18 |
val judgment_conv: conv -> conv |
19261 | 19 |
val is_elim: thm -> bool |
18728 | 20 |
val declare_atomize: attribute |
21 |
val declare_rulify: attribute |
|
16449 | 22 |
val atomize_term: theory -> term -> term |
18783 | 23 |
val atomize_cterm: cterm -> thm |
14743 | 24 |
val atomize_thm: thm -> thm |
11897 | 25 |
val atomize_tac: int -> tactic |
12829 | 26 |
val full_atomize_tac: int -> tactic |
11897 | 27 |
val atomize_goal: int -> thm -> thm |
18807 | 28 |
val rulify_term: theory -> term -> term |
29 |
val rulify_tac: int -> tactic |
|
11897 | 30 |
val rulify: thm -> thm |
31 |
val rulify_no_asm: thm -> thm |
|
18728 | 32 |
val rule_format: attribute |
33 |
val rule_format_no_asm: attribute |
|
11897 | 34 |
end; |
35 |
||
36 |
structure ObjectLogic: OBJECT_LOGIC = |
|
37 |
struct |
|
38 |
||
39 |
||
18825 | 40 |
(** theory data **) |
11897 | 41 |
|
16449 | 42 |
structure ObjectLogicData = TheoryDataFun |
22846 | 43 |
( |
11897 | 44 |
type T = string option * (thm list * thm list); |
22846 | 45 |
val empty = (NONE, ([], [])); |
11897 | 46 |
val copy = I; |
16449 | 47 |
val extend = I; |
11897 | 48 |
|
15531 | 49 |
fun merge_judgment (SOME x, SOME y) = |
23586 | 50 |
if (x: string) = y then SOME x else error "Attempt to merge different object-logics" |
15973 | 51 |
| merge_judgment (j1, j2) = if is_some j1 then j1 else j2; |
11897 | 52 |
|
16449 | 53 |
fun merge _ ((judgment1, (atomize1, rulify1)), (judgment2, (atomize2, rulify2))) = |
11897 | 54 |
(merge_judgment (judgment1, judgment2), |
55 |
(Drule.merge_rules (atomize1, atomize2), Drule.merge_rules (rulify1, rulify2))); |
|
22846 | 56 |
); |
15801 | 57 |
|
11897 | 58 |
|
59 |
||
60 |
(** generic treatment of judgments -- with a single argument only **) |
|
61 |
||
18825 | 62 |
(* add judgment *) |
11897 | 63 |
|
64 |
local |
|
65 |
||
15531 | 66 |
fun new_judgment name (NONE, rules) = (SOME name, rules) |
67 |
| new_judgment _ (SOME _, _) = error "Attempt to redeclare object-logic judgment"; |
|
11897 | 68 |
|
16449 | 69 |
fun gen_add_judgment add_consts (bname, T, mx) thy = |
70 |
let val c = Sign.full_name thy (Syntax.const_name bname mx) in |
|
14226 | 71 |
thy |
16449 | 72 |
|> add_consts [(bname, T, mx)] |
73 |
|> (fn thy' => Theory.add_finals_i false [(Const (c, Sign.the_const_type thy' c))] thy') |
|
74 |
|> ObjectLogicData.map (new_judgment c) |
|
14226 | 75 |
end; |
11897 | 76 |
|
77 |
in |
|
78 |
||
22796 | 79 |
val add_judgment = gen_add_judgment Sign.add_consts; |
80 |
val add_judgment_i = gen_add_judgment Sign.add_consts_i; |
|
11897 | 81 |
|
82 |
end; |
|
83 |
||
84 |
||
23566
b65692d4adcd
replaced HOLogic.Trueprop_conv by ObjectLogic.judgment_conv;
wenzelm
parents:
23540
diff
changeset
|
85 |
(* judgments *) |
11897 | 86 |
|
16449 | 87 |
fun judgment_name thy = |
88 |
(case ObjectLogicData.get thy of |
|
15531 | 89 |
(SOME name, _) => name |
11897 | 90 |
| _ => raise TERM ("Unknown object-logic judgment", [])); |
91 |
||
16449 | 92 |
fun is_judgment thy (Const (c, _) $ _) = c = judgment_name thy |
11897 | 93 |
| is_judgment _ _ = false; |
94 |
||
16449 | 95 |
fun drop_judgment thy (Abs (x, T, t)) = Abs (x, T, drop_judgment thy t) |
96 |
| drop_judgment thy (tm as (Const (c, _) $ t)) = |
|
97 |
if (c = judgment_name thy handle TERM _ => false) then t else tm |
|
11897 | 98 |
| drop_judgment _ tm = tm; |
99 |
||
16449 | 100 |
fun fixed_judgment thy x = |
11897 | 101 |
let (*be robust wrt. low-level errors*) |
16449 | 102 |
val c = judgment_name thy; |
14854 | 103 |
val aT = TFree ("'a", []); |
11897 | 104 |
val T = |
18939 | 105 |
the_default (aT --> propT) (Sign.const_type thy c) |
11897 | 106 |
|> Term.map_type_tvar (fn ((x, _), S) => TFree (x, S)); |
107 |
val U = Term.domain_type T handle Match => aT; |
|
108 |
in Const (c, T) $ Free (x, U) end; |
|
109 |
||
18121 | 110 |
fun ensure_propT thy t = |
13376 | 111 |
let val T = Term.fastype_of t |
16449 | 112 |
in if T = propT then t else Const (judgment_name thy, T --> propT) $ t end; |
13376 | 113 |
|
23586 | 114 |
fun dest_judgment ct = |
115 |
if is_judgment (Thm.theory_of_cterm ct) (Thm.term_of ct) |
|
116 |
then Thm.dest_arg ct |
|
117 |
else raise CTERM ("dest_judgment", [ct]); |
|
118 |
||
23566
b65692d4adcd
replaced HOLogic.Trueprop_conv by ObjectLogic.judgment_conv;
wenzelm
parents:
23540
diff
changeset
|
119 |
fun judgment_conv cv ct = |
b65692d4adcd
replaced HOLogic.Trueprop_conv by ObjectLogic.judgment_conv;
wenzelm
parents:
23540
diff
changeset
|
120 |
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
|
121 |
then Conv.arg_conv cv ct |
b65692d4adcd
replaced HOLogic.Trueprop_conv by ObjectLogic.judgment_conv;
wenzelm
parents:
23540
diff
changeset
|
122 |
else raise CTERM ("judgment_conv", [ct]); |
b65692d4adcd
replaced HOLogic.Trueprop_conv by ObjectLogic.judgment_conv;
wenzelm
parents:
23540
diff
changeset
|
123 |
|
11897 | 124 |
|
19261 | 125 |
(* elimination rules *) |
126 |
||
127 |
fun is_elim rule = |
|
128 |
let |
|
129 |
val thy = Thm.theory_of_thm rule; |
|
130 |
val concl = Thm.concl_of rule; |
|
131 |
in |
|
132 |
Term.is_Var (drop_judgment thy concl) andalso |
|
133 |
exists (fn prem => concl aconv Logic.strip_assums_concl prem) (Thm.prems_of rule) |
|
134 |
end; |
|
135 |
||
136 |
||
11897 | 137 |
|
138 |
(** treatment of meta-level connectives **) |
|
139 |
||
140 |
(* maintain rules *) |
|
141 |
||
16449 | 142 |
val get_atomize = #1 o #2 o ObjectLogicData.get; |
143 |
val get_rulify = #2 o #2 o ObjectLogicData.get; |
|
11897 | 144 |
|
22846 | 145 |
val add_atomize = ObjectLogicData.map o apsnd o apfst o Drule.add_rule; |
146 |
val add_rulify = ObjectLogicData.map o apsnd o apsnd o Drule.add_rule; |
|
11897 | 147 |
|
22846 | 148 |
val declare_atomize = Thm.declaration_attribute (fn th => Context.mapping (add_atomize th) I); |
149 |
val declare_rulify = Thm.declaration_attribute (fn th => Context.mapping (add_rulify th) I); |
|
150 |
||
151 |
val _ = Context.add_setup (add_rulify Drule.norm_hhf_eq); |
|
11897 | 152 |
|
153 |
||
154 |
(* atomize *) |
|
155 |
||
23540 | 156 |
fun rewrite_prems_tac rews = |
23586 | 157 |
CONVERSION (Conv.forall_conv ~1 (Conv.prems_conv ~1 (MetaSimplifier.rewrite true rews))); |
11897 | 158 |
|
16449 | 159 |
fun atomize_term thy = |
160 |
drop_judgment thy o MetaSimplifier.rewrite_term thy (get_atomize thy) []; |
|
12729 | 161 |
|
21708 | 162 |
fun atomize_cterm ct = MetaSimplifier.rewrite true (get_atomize (Thm.theory_of_cterm ct)) ct; |
17902 | 163 |
fun atomize_thm th = rewrite_rule (get_atomize (Thm.theory_of_thm th)) th; |
14743 | 164 |
|
11897 | 165 |
fun atomize_tac i st = |
12807 | 166 |
if Logic.has_meta_prems (Thm.prop_of st) i then |
16449 | 167 |
(rewrite_prems_tac (get_atomize (Thm.theory_of_thm st)) i) st |
11897 | 168 |
else all_tac st; |
169 |
||
12829 | 170 |
fun full_atomize_tac i st = |
23540 | 171 |
MetaSimplifier.rewrite_goal_tac (get_atomize (Thm.theory_of_thm st)) i st; |
12829 | 172 |
|
11897 | 173 |
fun atomize_goal i st = |
15531 | 174 |
(case Seq.pull (atomize_tac i st) of NONE => st | SOME (st', _) => st'); |
11897 | 175 |
|
176 |
||
177 |
(* rulify *) |
|
178 |
||
18807 | 179 |
fun rulify_term thy = MetaSimplifier.rewrite_term thy (get_rulify thy) []; |
23540 | 180 |
fun rulify_tac i st = MetaSimplifier.rewrite_goal_tac (get_rulify (Thm.theory_of_thm st)) i st; |
18807 | 181 |
|
11897 | 182 |
fun gen_rulify full thm = |
21708 | 183 |
MetaSimplifier.simplify full (get_rulify (Thm.theory_of_thm thm)) thm |
20912 | 184 |
|> Drule.gen_all |> Thm.strip_shyps |> Drule.zero_var_indexes; |
11897 | 185 |
|
186 |
val rulify = gen_rulify true; |
|
187 |
val rulify_no_asm = gen_rulify false; |
|
188 |
||
18728 | 189 |
fun rule_format x = Thm.rule_attribute (fn _ => rulify) x; |
190 |
fun rule_format_no_asm x = Thm.rule_attribute (fn _ => rulify_no_asm) x; |
|
11897 | 191 |
|
192 |
end; |