author | wenzelm |
Sat, 21 Jan 2006 23:02:20 +0100 | |
changeset 18729 | 216e31270509 |
parent 18708 | 4b3dadb4fe33 |
child 19734 | e9a06ce3a97a |
permissions | -rw-r--r-- |
17333 | 1 |
(* Title : HOL/Hyperreal/transfer.ML |
2 |
ID : $Id$ |
|
3 |
Author : Brian Huffman |
|
4 |
||
18729 | 5 |
Transfer principle tactic for nonstandard analysis. |
17333 | 6 |
*) |
7 |
||
18729 | 8 |
signature TRANSFER = |
17329 | 9 |
sig |
18729 | 10 |
val transfer_tac: Proof.context -> thm list -> int -> tactic |
17429
e8d6ed3aacfe
merged Transfer.thy and StarType.thy into StarDef.thy; renamed Ifun2_of to starfun2; cleaned up
huffman
parents:
17333
diff
changeset
|
11 |
val add_const: string -> theory -> theory |
18708 | 12 |
val setup: theory -> theory |
17329 | 13 |
end; |
14 |
||
18729 | 15 |
structure Transfer: TRANSFER = |
17329 | 16 |
struct |
17 |
||
18729 | 18 |
structure TransferData = GenericDataFun |
17329 | 19 |
(struct |
20 |
val name = "HOL/transfer"; |
|
21 |
type T = { |
|
22 |
intros: thm list, |
|
23 |
unfolds: thm list, |
|
24 |
refolds: thm list, |
|
25 |
consts: string list |
|
26 |
}; |
|
17429
e8d6ed3aacfe
merged Transfer.thy and StarType.thy into StarDef.thy; renamed Ifun2_of to starfun2; cleaned up
huffman
parents:
17333
diff
changeset
|
27 |
val empty = {intros = [], unfolds = [], refolds = [], consts = []}; |
17329 | 28 |
val extend = I; |
29 |
fun merge _ |
|
30 |
({intros = intros1, unfolds = unfolds1, |
|
31 |
refolds = refolds1, consts = consts1}, |
|
32 |
{intros = intros2, unfolds = unfolds2, |
|
33 |
refolds = refolds2, consts = consts2}) = |
|
34 |
{intros = Drule.merge_rules (intros1, intros2), |
|
35 |
unfolds = Drule.merge_rules (unfolds1, unfolds2), |
|
36 |
refolds = Drule.merge_rules (refolds1, refolds2), |
|
37 |
consts = merge_lists consts1 consts2}; |
|
38 |
fun print _ _ = (); |
|
39 |
end); |
|
40 |
||
41 |
val transfer_start = thm "transfer_start" |
|
42 |
||
17429
e8d6ed3aacfe
merged Transfer.thy and StarType.thy into StarDef.thy; renamed Ifun2_of to starfun2; cleaned up
huffman
parents:
17333
diff
changeset
|
43 |
fun unstar_typ (Type ("StarDef.star",[t])) = unstar_typ t |
17329 | 44 |
| unstar_typ (Type (a, Ts)) = Type (a, map unstar_typ Ts) |
45 |
| unstar_typ T = T |
|
46 |
||
47 |
fun unstar_term consts term = |
|
48 |
let |
|
17432 | 49 |
fun unstar (Const(a,T) $ t) = if (a mem consts) then (unstar t) |
17329 | 50 |
else (Const(a,unstar_typ T) $ unstar t) |
51 |
| unstar (f $ t) = unstar f $ unstar t |
|
52 |
| unstar (Const(a,T)) = Const(a,unstar_typ T) |
|
53 |
| unstar (Abs(a,T,t)) = Abs(a,unstar_typ T,unstar t) |
|
54 |
| unstar t = t |
|
55 |
in |
|
56 |
unstar term |
|
57 |
end |
|
58 |
||
59 |
val atomizers = map thm ["atomize_all", "atomize_imp", "atomize_eq"] |
|
60 |
||
18729 | 61 |
fun transfer_thm_of ctxt ths t = |
17329 | 62 |
let |
18729 | 63 |
val thy = ProofContext.theory_of ctxt; |
64 |
val {intros,unfolds,refolds,consts} = TransferData.get (Context.Proof ctxt) |
|
17329 | 65 |
val (_$_$t') = concl_of (Tactic.rewrite true unfolds (cterm_of thy t)) |
66 |
val u = unstar_term consts t' |
|
18729 | 67 |
val tac = |
68 |
rewrite_goals_tac (ths @ refolds @ unfolds) THEN |
|
69 |
rewrite_goals_tac atomizers THEN |
|
70 |
match_tac [transitive_thm] 1 THEN |
|
71 |
resolve_tac [transfer_start] 1 THEN |
|
72 |
REPEAT_ALL_NEW (resolve_tac intros) 1 THEN |
|
73 |
match_tac [reflexive_thm] 1 |
|
74 |
in Goal.prove thy [] [] (Logic.mk_equals (t,u)) (K tac) end |
|
17329 | 75 |
|
18729 | 76 |
fun transfer_tac ctxt ths = |
17329 | 77 |
SUBGOAL (fn (t,i) => |
78 |
(fn th => |
|
18729 | 79 |
let val tr = transfer_thm_of ctxt ths t |
80 |
in rewrite_goals_tac [tr] th end)) |
|
17329 | 81 |
|
82 |
local |
|
83 |
fun map_intros f = TransferData.map |
|
84 |
(fn {intros,unfolds,refolds,consts} => |
|
85 |
{intros=f intros, unfolds=unfolds, refolds=refolds, consts=consts}) |
|
86 |
||
87 |
fun map_unfolds f = TransferData.map |
|
88 |
(fn {intros,unfolds,refolds,consts} => |
|
89 |
{intros=intros, unfolds=f unfolds, refolds=refolds, consts=consts}) |
|
90 |
||
91 |
fun map_refolds f = TransferData.map |
|
92 |
(fn {intros,unfolds,refolds,consts} => |
|
93 |
{intros=intros, unfolds=unfolds, refolds=f refolds, consts=consts}) |
|
94 |
in |
|
18729 | 95 |
val intro_add = Thm.declaration_attribute (map_intros o Drule.add_rule); |
96 |
val intro_del = Thm.declaration_attribute (map_intros o Drule.del_rule); |
|
17329 | 97 |
|
18729 | 98 |
val unfold_add = Thm.declaration_attribute (map_unfolds o Drule.add_rule); |
99 |
val unfold_del = Thm.declaration_attribute (map_unfolds o Drule.del_rule); |
|
17329 | 100 |
|
18729 | 101 |
val refold_add = Thm.declaration_attribute (map_refolds o Drule.add_rule); |
102 |
val refold_del = Thm.declaration_attribute (map_refolds o Drule.del_rule); |
|
17329 | 103 |
end |
104 |
||
18729 | 105 |
fun add_const c = Context.theory_map (TransferData.map |
17429
e8d6ed3aacfe
merged Transfer.thy and StarType.thy into StarDef.thy; renamed Ifun2_of to starfun2; cleaned up
huffman
parents:
17333
diff
changeset
|
106 |
(fn {intros,unfolds,refolds,consts} => |
18729 | 107 |
{intros=intros, unfolds=unfolds, refolds=refolds, consts=c::consts})) |
17429
e8d6ed3aacfe
merged Transfer.thy and StarType.thy into StarDef.thy; renamed Ifun2_of to starfun2; cleaned up
huffman
parents:
17333
diff
changeset
|
108 |
|
18729 | 109 |
val transfer_method = Method.thms_ctxt_args (fn ths => fn ctxt => |
110 |
Method.SIMPLE_METHOD' HEADGOAL (transfer_tac ctxt ths)); |
|
17329 | 111 |
|
112 |
val setup = |
|
18708 | 113 |
TransferData.init #> |
114 |
Attrib.add_attributes |
|
18729 | 115 |
[("transfer_intro", Attrib.add_del_args intro_add intro_del, |
18708 | 116 |
"declaration of transfer introduction rule"), |
18729 | 117 |
("transfer_unfold", Attrib.add_del_args unfold_add unfold_del, |
18708 | 118 |
"declaration of transfer unfolding rule"), |
18729 | 119 |
("transfer_refold", Attrib.add_del_args refold_add refold_del, |
18708 | 120 |
"declaration of transfer refolding rule")] #> |
18729 | 121 |
Method.add_method ("transfer", transfer_method, "transfer principle"); |
17329 | 122 |
|
123 |
end; |