author | wenzelm |
Fri, 25 Nov 2005 18:58:41 +0100 | |
changeset 18254 | 4a081083b06e |
parent 18121 | 77b6d06ad99d |
child 18563 | 1df7022eac6f |
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 |
11897 | 17 |
val declare_atomize: theory attribute |
18 |
val declare_rulify: theory attribute |
|
16449 | 19 |
val atomize_term: theory -> term -> term |
17902 | 20 |
val atomize_cterm: theory -> 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 |
25 |
val rulify: thm -> thm |
|
26 |
val rulify_no_asm: thm -> thm |
|
27 |
val rule_format: 'a attribute |
|
28 |
val rule_format_no_asm: 'a attribute |
|
29 |
end; |
|
30 |
||
31 |
structure ObjectLogic: OBJECT_LOGIC = |
|
32 |
struct |
|
33 |
||
34 |
||
35 |
(** object-logic theory data **) |
|
36 |
||
37 |
(* data kind 'Pure/object-logic' *) |
|
38 |
||
16449 | 39 |
structure ObjectLogicData = TheoryDataFun |
40 |
(struct |
|
11897 | 41 |
val name = "Pure/object-logic"; |
42 |
type T = string option * (thm list * thm list); |
|
43 |
||
15531 | 44 |
val empty = (NONE, ([], [Drule.norm_hhf_eq])); |
11897 | 45 |
val copy = I; |
16449 | 46 |
val extend = I; |
11897 | 47 |
|
15531 | 48 |
fun merge_judgment (SOME x, SOME y) = |
49 |
if x = y then SOME x else error "Attempt to merge different object-logics" |
|
15973 | 50 |
| merge_judgment (j1, j2) = if is_some j1 then j1 else j2; |
11897 | 51 |
|
16449 | 52 |
fun merge _ ((judgment1, (atomize1, rulify1)), (judgment2, (atomize2, rulify2))) = |
11897 | 53 |
(merge_judgment (judgment1, judgment2), |
54 |
(Drule.merge_rules (atomize1, atomize2), Drule.merge_rules (rulify1, rulify2))); |
|
55 |
||
56 |
fun print _ _ = (); |
|
16449 | 57 |
end); |
11897 | 58 |
|
15801 | 59 |
val _ = Context.add_setup [ObjectLogicData.init]; |
60 |
||
11897 | 61 |
|
62 |
||
63 |
(** generic treatment of judgments -- with a single argument only **) |
|
64 |
||
65 |
(* add_judgment(_i) *) |
|
66 |
||
67 |
local |
|
68 |
||
15531 | 69 |
fun new_judgment name (NONE, rules) = (SOME name, rules) |
70 |
| new_judgment _ (SOME _, _) = error "Attempt to redeclare object-logic judgment"; |
|
11897 | 71 |
|
16449 | 72 |
fun gen_add_judgment add_consts (bname, T, mx) thy = |
73 |
let val c = Sign.full_name thy (Syntax.const_name bname mx) in |
|
14226 | 74 |
thy |
16449 | 75 |
|> add_consts [(bname, T, mx)] |
76 |
|> (fn thy' => Theory.add_finals_i false [(Const (c, Sign.the_const_type thy' c))] thy') |
|
77 |
|> ObjectLogicData.map (new_judgment c) |
|
14226 | 78 |
end; |
11897 | 79 |
|
80 |
in |
|
81 |
||
82 |
val add_judgment = gen_add_judgment Theory.add_consts; |
|
83 |
val add_judgment_i = gen_add_judgment Theory.add_consts_i; |
|
84 |
||
85 |
end; |
|
86 |
||
87 |
||
88 |
(* term operations *) |
|
89 |
||
16449 | 90 |
fun judgment_name thy = |
91 |
(case ObjectLogicData.get thy of |
|
15531 | 92 |
(SOME name, _) => name |
11897 | 93 |
| _ => raise TERM ("Unknown object-logic judgment", [])); |
94 |
||
16449 | 95 |
fun is_judgment thy (Const (c, _) $ _) = c = judgment_name thy |
11897 | 96 |
| is_judgment _ _ = false; |
97 |
||
16449 | 98 |
fun drop_judgment thy (Abs (x, T, t)) = Abs (x, T, drop_judgment thy t) |
99 |
| drop_judgment thy (tm as (Const (c, _) $ t)) = |
|
100 |
if (c = judgment_name thy handle TERM _ => false) then t else tm |
|
11897 | 101 |
| drop_judgment _ tm = tm; |
102 |
||
16449 | 103 |
fun fixed_judgment thy x = |
11897 | 104 |
let (*be robust wrt. low-level errors*) |
16449 | 105 |
val c = judgment_name thy; |
14854 | 106 |
val aT = TFree ("'a", []); |
11897 | 107 |
val T = |
16449 | 108 |
if_none (Sign.const_type thy c) (aT --> propT) |
11897 | 109 |
|> Term.map_type_tvar (fn ((x, _), S) => TFree (x, S)); |
110 |
val U = Term.domain_type T handle Match => aT; |
|
111 |
in Const (c, T) $ Free (x, U) end; |
|
112 |
||
18121 | 113 |
fun ensure_propT thy t = |
13376 | 114 |
let val T = Term.fastype_of t |
16449 | 115 |
in if T = propT then t else Const (judgment_name thy, T --> propT) $ t end; |
13376 | 116 |
|
11897 | 117 |
|
118 |
||
119 |
(** treatment of meta-level connectives **) |
|
120 |
||
121 |
(* maintain rules *) |
|
122 |
||
16449 | 123 |
val get_atomize = #1 o #2 o ObjectLogicData.get; |
124 |
val get_rulify = #2 o #2 o ObjectLogicData.get; |
|
11897 | 125 |
|
12371 | 126 |
val add_atomize = ObjectLogicData.map o Library.apsnd o Library.apfst o Drule.add_rule; |
127 |
val add_rulify = ObjectLogicData.map o Library.apsnd o Library.apsnd o Drule.add_rule; |
|
11897 | 128 |
|
12371 | 129 |
fun declare_atomize (thy, th) = (add_atomize th thy, th); |
130 |
fun declare_rulify (thy, th) = (add_rulify th thy, th); |
|
11897 | 131 |
|
132 |
||
133 |
(* atomize *) |
|
134 |
||
15001
fb2141a9f8c0
Moved conversion rules from MetaSimplifier to Drule. refl_implies removed
skalberg
parents:
14981
diff
changeset
|
135 |
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
|
136 |
(Drule.goals_conv (Library.equal i) |
18254 | 137 |
(Drule.forall_conv ~1 |
15001
fb2141a9f8c0
Moved conversion rules from MetaSimplifier to Drule. refl_implies removed
skalberg
parents:
14981
diff
changeset
|
138 |
(Drule.goals_conv (K true) (Tactic.rewrite true rews))))); |
11897 | 139 |
|
16449 | 140 |
fun atomize_term thy = |
141 |
drop_judgment thy o MetaSimplifier.rewrite_term thy (get_atomize thy) []; |
|
12729 | 142 |
|
17902 | 143 |
fun atomize_cterm thy = Tactic.rewrite true (get_atomize thy); |
144 |
fun atomize_thm th = rewrite_rule (get_atomize (Thm.theory_of_thm th)) th; |
|
14743 | 145 |
|
11897 | 146 |
fun atomize_tac i st = |
12807 | 147 |
if Logic.has_meta_prems (Thm.prop_of st) i then |
16449 | 148 |
(rewrite_prems_tac (get_atomize (Thm.theory_of_thm st)) i) st |
11897 | 149 |
else all_tac st; |
150 |
||
12829 | 151 |
fun full_atomize_tac i st = |
16449 | 152 |
rewrite_goal_tac (get_atomize (Thm.theory_of_thm st)) i st; |
12829 | 153 |
|
11897 | 154 |
fun atomize_goal i st = |
15531 | 155 |
(case Seq.pull (atomize_tac i st) of NONE => st | SOME (st', _) => st'); |
11897 | 156 |
|
157 |
||
158 |
(* rulify *) |
|
159 |
||
160 |
fun gen_rulify full thm = |
|
16449 | 161 |
Tactic.simplify full (get_rulify (Thm.theory_of_thm thm)) thm |
12725 | 162 |
|> Drule.gen_all |> Drule.strip_shyps_warning |> Drule.zero_var_indexes; |
11897 | 163 |
|
164 |
val rulify = gen_rulify true; |
|
165 |
val rulify_no_asm = gen_rulify false; |
|
166 |
||
167 |
fun rule_format x = Drule.rule_attribute (fn _ => rulify) x; |
|
168 |
fun rule_format_no_asm x = Drule.rule_attribute (fn _ => rulify_no_asm) x; |
|
169 |
||
170 |
||
171 |
end; |