author | wenzelm |
Tue, 16 Jul 2002 18:41:18 +0200 | |
changeset 13376 | 59975b8417e2 |
parent 13334 | 27149d72bdff |
child 14226 | 7afe0e5bcc83 |
permissions | -rw-r--r-- |
11897 | 1 |
(* Title: Pure/Isar/object_logic.ML |
2 |
ID: $Id$ |
|
3 |
Author: Markus Wenzel, TU Muenchen |
|
4 |
License: GPL (GNU GENERAL PUBLIC LICENSE) |
|
5 |
||
6 |
Specifics about common object-logics. |
|
7 |
*) |
|
8 |
||
9 |
signature OBJECT_LOGIC = |
|
10 |
sig |
|
11 |
val add_judgment: bstring * string * mixfix -> theory -> theory |
|
12 |
val add_judgment_i: bstring * typ * mixfix -> theory -> theory |
|
13 |
val judgment_name: Sign.sg -> string |
|
14 |
val is_judgment: Sign.sg -> term -> bool |
|
15 |
val drop_judgment: Sign.sg -> term -> term |
|
16 |
val fixed_judgment: Sign.sg -> string -> term |
|
13376 | 17 |
val assert_propT: Sign.sg -> term -> term |
11897 | 18 |
val declare_atomize: theory attribute |
19 |
val declare_rulify: theory attribute |
|
12807 | 20 |
val atomize_term: Sign.sg -> term -> term |
13376 | 21 |
val atomize_rule: Sign.sg -> cterm -> 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 |
val setup: (theory -> theory) list |
|
30 |
end; |
|
31 |
||
32 |
structure ObjectLogic: OBJECT_LOGIC = |
|
33 |
struct |
|
34 |
||
35 |
||
36 |
(** object-logic theory data **) |
|
37 |
||
38 |
(* data kind 'Pure/object-logic' *) |
|
39 |
||
40 |
structure ObjectLogicDataArgs = |
|
41 |
struct |
|
42 |
val name = "Pure/object-logic"; |
|
43 |
type T = string option * (thm list * thm list); |
|
44 |
||
45 |
val empty = (None, ([], [Drule.norm_hhf_eq])); |
|
46 |
val copy = I; |
|
47 |
val prep_ext = I; |
|
48 |
||
49 |
fun merge_judgment (Some x, Some y) = |
|
50 |
if x = y then Some x else error "Attempt to merge different object-logics" |
|
51 |
| merge_judgment (j1, j2) = if is_some j1 then j1 else j2; |
|
52 |
||
53 |
fun merge ((judgment1, (atomize1, rulify1)), (judgment2, (atomize2, rulify2))) = |
|
54 |
(merge_judgment (judgment1, judgment2), |
|
55 |
(Drule.merge_rules (atomize1, atomize2), Drule.merge_rules (rulify1, rulify2))); |
|
56 |
||
57 |
fun print _ _ = (); |
|
58 |
end; |
|
59 |
||
60 |
structure ObjectLogicData = TheoryDataFun(ObjectLogicDataArgs); |
|
61 |
||
62 |
||
63 |
(** generic treatment of judgments -- with a single argument only **) |
|
64 |
||
65 |
(* add_judgment(_i) *) |
|
66 |
||
67 |
local |
|
68 |
||
69 |
fun new_judgment name (None, rules) = (Some name, rules) |
|
70 |
| new_judgment _ (Some _, _) = error "Attempt to redeclare object-logic judgment"; |
|
71 |
||
72 |
fun gen_add_judgment add_consts (name, T, syn) thy = |
|
73 |
thy |
|
74 |
|> add_consts [(name, T, syn)] |
|
75 |
|> ObjectLogicData.map (new_judgment (Sign.full_name (Theory.sign_of thy) name)); |
|
76 |
||
77 |
in |
|
78 |
||
79 |
val add_judgment = gen_add_judgment Theory.add_consts; |
|
80 |
val add_judgment_i = gen_add_judgment Theory.add_consts_i; |
|
81 |
||
82 |
end; |
|
83 |
||
84 |
||
85 |
(* term operations *) |
|
86 |
||
87 |
fun judgment_name sg = |
|
88 |
(case ObjectLogicData.get_sg sg of |
|
89 |
(Some name, _) => name |
|
90 |
| _ => raise TERM ("Unknown object-logic judgment", [])); |
|
91 |
||
92 |
fun is_judgment sg (Const (c, _) $ _) = c = judgment_name sg |
|
93 |
| is_judgment _ _ = false; |
|
94 |
||
95 |
fun drop_judgment sg (Abs (x, T, t)) = Abs (x, T, drop_judgment sg t) |
|
12479
ed46612ad7ec
drop_judgment: be graceful about undeclared judgment;
wenzelm
parents:
12371
diff
changeset
|
96 |
| drop_judgment sg (tm as (Const (c, _) $ t)) = |
ed46612ad7ec
drop_judgment: be graceful about undeclared judgment;
wenzelm
parents:
12371
diff
changeset
|
97 |
if (c = judgment_name sg handle TERM _ => false) then t else tm |
11897 | 98 |
| drop_judgment _ tm = tm; |
99 |
||
100 |
fun fixed_judgment sg x = |
|
101 |
let (*be robust wrt. low-level errors*) |
|
102 |
val c = judgment_name sg; |
|
103 |
val aT = TFree ("'a", logicS); |
|
104 |
val T = |
|
105 |
if_none (Sign.const_type sg c) (aT --> propT) |
|
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 |
||
13376 | 110 |
fun assert_propT sg t = |
111 |
let val T = Term.fastype_of t |
|
112 |
in if T = propT then t else Const (judgment_name sg, T --> propT) $ t end; |
|
113 |
||
11897 | 114 |
|
115 |
||
116 |
(** treatment of meta-level connectives **) |
|
117 |
||
118 |
(* maintain rules *) |
|
119 |
||
120 |
val get_atomize = #1 o #2 o ObjectLogicData.get_sg; |
|
121 |
val get_rulify = #2 o #2 o ObjectLogicData.get_sg; |
|
122 |
||
12371 | 123 |
val add_atomize = ObjectLogicData.map o Library.apsnd o Library.apfst o Drule.add_rule; |
124 |
val add_rulify = ObjectLogicData.map o Library.apsnd o Library.apsnd o Drule.add_rule; |
|
11897 | 125 |
|
12371 | 126 |
fun declare_atomize (thy, th) = (add_atomize th thy, th); |
127 |
fun declare_rulify (thy, th) = (add_rulify th thy, th); |
|
11897 | 128 |
|
129 |
||
130 |
(* atomize *) |
|
131 |
||
132 |
fun rewrite_prems_tac rews i = PRIMITIVE (MetaSimplifier.fconv_rule |
|
133 |
(MetaSimplifier.goals_conv (Library.equal i) |
|
134 |
(MetaSimplifier.forall_conv |
|
135 |
(MetaSimplifier.goals_conv (K true) (Tactic.rewrite true rews))))); |
|
136 |
||
12807 | 137 |
fun atomize_term sg = |
13197
0567f4fd1415
Changed interface of MetaSimplifier.rewrite_term.
berghofe
parents:
12829
diff
changeset
|
138 |
drop_judgment sg o MetaSimplifier.rewrite_term sg (get_atomize sg) []; |
12729 | 139 |
|
13376 | 140 |
fun atomize_rule sg = Tactic.rewrite true (get_atomize sg); |
141 |
||
11897 | 142 |
fun atomize_tac i st = |
12807 | 143 |
if Logic.has_meta_prems (Thm.prop_of st) i then |
11897 | 144 |
(rewrite_prems_tac (get_atomize (Thm.sign_of_thm st)) i) st |
145 |
else all_tac st; |
|
146 |
||
12829 | 147 |
fun full_atomize_tac i st = |
148 |
rewrite_goal_tac (get_atomize (Thm.sign_of_thm st)) i st; |
|
149 |
||
11897 | 150 |
fun atomize_goal i st = |
151 |
(case Seq.pull (atomize_tac i st) of None => st | Some (st', _) => st'); |
|
152 |
||
153 |
||
154 |
(* rulify *) |
|
155 |
||
156 |
fun gen_rulify full thm = |
|
157 |
Tactic.simplify full (get_rulify (Thm.sign_of_thm thm)) thm |
|
12725 | 158 |
|> Drule.gen_all |> Drule.strip_shyps_warning |> Drule.zero_var_indexes; |
11897 | 159 |
|
160 |
val rulify = gen_rulify true; |
|
161 |
val rulify_no_asm = gen_rulify false; |
|
162 |
||
163 |
fun rule_format x = Drule.rule_attribute (fn _ => rulify) x; |
|
164 |
fun rule_format_no_asm x = Drule.rule_attribute (fn _ => rulify_no_asm) x; |
|
165 |
||
166 |
||
167 |
||
168 |
(** theory setup **) |
|
169 |
||
170 |
val setup = [ObjectLogicData.init]; |
|
171 |
||
172 |
||
173 |
end; |