author | wenzelm |
Sun, 09 Nov 2014 17:04:14 +0100 | |
changeset 58957 | c9e744ea8a38 |
parent 58825 | 2065f49da190 |
child 59498 | 50b60f501b05 |
permissions | -rw-r--r-- |
37744 | 1 |
(* Title: HOL/NSA/transfer.ML |
2 |
Author: Brian Huffman |
|
27468 | 3 |
|
4 |
Transfer principle tactic for nonstandard analysis. |
|
5 |
*) |
|
6 |
||
47328
9f11a3cd84b1
rename ML structure to avoid shadowing earlier name
huffman
parents:
42361
diff
changeset
|
7 |
signature TRANSFER_PRINCIPLE = |
27468 | 8 |
sig |
9 |
val transfer_tac: Proof.context -> thm list -> int -> tactic |
|
10 |
val add_const: string -> theory -> theory |
|
11 |
end; |
|
12 |
||
47328
9f11a3cd84b1
rename ML structure to avoid shadowing earlier name
huffman
parents:
42361
diff
changeset
|
13 |
structure Transfer_Principle: TRANSFER_PRINCIPLE = |
27468 | 14 |
struct |
15 |
||
33519 | 16 |
structure TransferData = Generic_Data |
27468 | 17 |
( |
18 |
type T = { |
|
19 |
intros: thm list, |
|
20 |
unfolds: thm list, |
|
21 |
refolds: thm list, |
|
22 |
consts: string list |
|
23 |
}; |
|
24 |
val empty = {intros = [], unfolds = [], refolds = [], consts = []}; |
|
25 |
val extend = I; |
|
33519 | 26 |
fun merge |
27468 | 27 |
({intros = intros1, unfolds = unfolds1, |
28 |
refolds = refolds1, consts = consts1}, |
|
29 |
{intros = intros2, unfolds = unfolds2, |
|
33519 | 30 |
refolds = refolds2, consts = consts2}) : T = |
27468 | 31 |
{intros = Thm.merge_thms (intros1, intros2), |
32 |
unfolds = Thm.merge_thms (unfolds1, unfolds2), |
|
33 |
refolds = Thm.merge_thms (refolds1, refolds2), |
|
33519 | 34 |
consts = Library.merge (op =) (consts1, consts2)}; |
27468 | 35 |
); |
36 |
||
56256 | 37 |
fun unstar_typ (Type (@{type_name star}, [t])) = unstar_typ t |
27468 | 38 |
| unstar_typ (Type (a, Ts)) = Type (a, map unstar_typ Ts) |
39 |
| unstar_typ T = T |
|
40 |
||
41 |
fun unstar_term consts term = |
|
42 |
let |
|
43 |
fun unstar (Const(a,T) $ t) = if member (op =) consts a then (unstar t) |
|
44 |
else (Const(a,unstar_typ T) $ unstar t) |
|
45 |
| unstar (f $ t) = unstar f $ unstar t |
|
46 |
| unstar (Const(a,T)) = Const(a,unstar_typ T) |
|
47 |
| unstar (Abs(a,T,t)) = Abs(a,unstar_typ T,unstar t) |
|
48 |
| unstar t = t |
|
49 |
in |
|
50 |
unstar term |
|
51 |
end |
|
52 |
||
53 |
fun transfer_thm_of ctxt ths t = |
|
54 |
let |
|
42361 | 55 |
val thy = Proof_Context.theory_of ctxt; |
27468 | 56 |
val {intros,unfolds,refolds,consts} = TransferData.get (Context.Proof ctxt); |
35624 | 57 |
val meta = Local_Defs.meta_rewrite_rule ctxt; |
27468 | 58 |
val ths' = map meta ths; |
59 |
val unfolds' = map meta unfolds and refolds' = map meta refolds; |
|
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
47432
diff
changeset
|
60 |
val (_$_$t') = concl_of (Raw_Simplifier.rewrite ctxt true unfolds' (cterm_of thy t)) |
27468 | 61 |
val u = unstar_term consts t' |
62 |
val tac = |
|
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
47432
diff
changeset
|
63 |
rewrite_goals_tac ctxt (ths' @ refolds' @ unfolds') THEN |
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
47432
diff
changeset
|
64 |
ALLGOALS (Object_Logic.full_atomize_tac ctxt) THEN |
58957 | 65 |
match_tac ctxt [transitive_thm] 1 THEN |
27468 | 66 |
resolve_tac [@{thm transfer_start}] 1 THEN |
67 |
REPEAT_ALL_NEW (resolve_tac intros) 1 THEN |
|
58957 | 68 |
match_tac ctxt [reflexive_thm] 1 |
27468 | 69 |
in Goal.prove ctxt [] [] (Logic.mk_equals (t,u)) (K tac) end |
70 |
||
71 |
fun transfer_tac ctxt ths = |
|
72 |
SUBGOAL (fn (t,i) => |
|
73 |
(fn th => |
|
74 |
let |
|
75 |
val tr = transfer_thm_of ctxt ths t |
|
76 |
val (_$l$r) = concl_of tr; |
|
77 |
val trs = if l aconv r then [] else [tr]; |
|
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
47432
diff
changeset
|
78 |
in rewrite_goals_tac ctxt trs th end)) |
27468 | 79 |
|
80 |
local |
|
81 |
||
82 |
fun map_intros f = TransferData.map |
|
83 |
(fn {intros,unfolds,refolds,consts} => |
|
84 |
{intros=f intros, unfolds=unfolds, refolds=refolds, consts=consts}) |
|
85 |
||
86 |
fun map_unfolds f = TransferData.map |
|
87 |
(fn {intros,unfolds,refolds,consts} => |
|
88 |
{intros=intros, unfolds=f unfolds, refolds=refolds, consts=consts}) |
|
89 |
||
90 |
fun map_refolds f = TransferData.map |
|
91 |
(fn {intros,unfolds,refolds,consts} => |
|
92 |
{intros=intros, unfolds=unfolds, refolds=f refolds, consts=consts}) |
|
93 |
in |
|
94 |
val intro_add = Thm.declaration_attribute (map_intros o Thm.add_thm); |
|
95 |
val intro_del = Thm.declaration_attribute (map_intros o Thm.del_thm); |
|
96 |
||
97 |
val unfold_add = Thm.declaration_attribute (map_unfolds o Thm.add_thm); |
|
98 |
val unfold_del = Thm.declaration_attribute (map_unfolds o Thm.del_thm); |
|
99 |
||
100 |
val refold_add = Thm.declaration_attribute (map_refolds o Thm.add_thm); |
|
101 |
val refold_del = Thm.declaration_attribute (map_refolds o Thm.del_thm); |
|
102 |
end |
|
103 |
||
104 |
fun add_const c = Context.theory_map (TransferData.map |
|
105 |
(fn {intros,unfolds,refolds,consts} => |
|
106 |
{intros=intros, unfolds=unfolds, refolds=refolds, consts=c::consts})) |
|
107 |
||
58825 | 108 |
val _ = |
109 |
Theory.setup |
|
110 |
(Attrib.setup @{binding transfer_intro} (Attrib.add_del intro_add intro_del) |
|
111 |
"declaration of transfer introduction rule" #> |
|
112 |
Attrib.setup @{binding transfer_unfold} (Attrib.add_del unfold_add unfold_del) |
|
113 |
"declaration of transfer unfolding rule" #> |
|
114 |
Attrib.setup @{binding transfer_refold} (Attrib.add_del refold_add refold_del) |
|
115 |
"declaration of transfer refolding rule") |
|
27468 | 116 |
|
117 |
end; |