| author | wenzelm | 
| Tue, 31 Mar 2015 00:11:54 +0200 | |
| changeset 59859 | f9d1442c70f3 | 
| parent 59816 | 034b13f4efae | 
| 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: 
42361diff
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: 
42361diff
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 | |
| 55 |     val {intros,unfolds,refolds,consts} = TransferData.get (Context.Proof ctxt);
 | |
| 35624 | 56 | val meta = Local_Defs.meta_rewrite_rule ctxt; | 
| 27468 | 57 | val ths' = map meta ths; | 
| 58 | val unfolds' = map meta unfolds and refolds' = map meta refolds; | |
| 59643 | 59 | val (_$_$t') = Thm.concl_of (Raw_Simplifier.rewrite ctxt true unfolds' (Thm.cterm_of ctxt t)) | 
| 27468 | 60 | val u = unstar_term consts t' | 
| 61 | val tac = | |
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
47432diff
changeset | 62 | 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: 
47432diff
changeset | 63 | ALLGOALS (Object_Logic.full_atomize_tac ctxt) THEN | 
| 58957 | 64 | match_tac ctxt [transitive_thm] 1 THEN | 
| 59498 
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
 wenzelm parents: 
58957diff
changeset | 65 |       resolve_tac ctxt [@{thm transfer_start}] 1 THEN
 | 
| 
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
 wenzelm parents: 
58957diff
changeset | 66 | REPEAT_ALL_NEW (resolve_tac ctxt intros) 1 THEN | 
| 58957 | 67 | match_tac ctxt [reflexive_thm] 1 | 
| 27468 | 68 | in Goal.prove ctxt [] [] (Logic.mk_equals (t,u)) (K tac) end | 
| 69 | ||
| 70 | fun transfer_tac ctxt ths = | |
| 59816 
034b13f4efae
distributivity of partial minus establishes desired properties of dvd in semirings
 haftmann parents: 
59643diff
changeset | 71 | SUBGOAL (fn (t, _) => | 
| 27468 | 72 | (fn th => | 
| 73 | let | |
| 74 | val tr = transfer_thm_of ctxt ths t | |
| 59582 | 75 | val (_$l$r) = Thm.concl_of tr; | 
| 27468 | 76 | 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: 
47432diff
changeset | 77 | in rewrite_goals_tac ctxt trs th end)) | 
| 27468 | 78 | |
| 79 | local | |
| 80 | ||
| 81 | fun map_intros f = TransferData.map | |
| 82 |   (fn {intros,unfolds,refolds,consts} =>
 | |
| 83 |     {intros=f intros, unfolds=unfolds, refolds=refolds, consts=consts})
 | |
| 84 | ||
| 85 | fun map_unfolds f = TransferData.map | |
| 86 |   (fn {intros,unfolds,refolds,consts} =>
 | |
| 87 |     {intros=intros, unfolds=f unfolds, refolds=refolds, consts=consts})
 | |
| 88 | ||
| 89 | fun map_refolds f = TransferData.map | |
| 90 |   (fn {intros,unfolds,refolds,consts} =>
 | |
| 91 |     {intros=intros, unfolds=unfolds, refolds=f refolds, consts=consts})
 | |
| 92 | in | |
| 93 | val intro_add = Thm.declaration_attribute (map_intros o Thm.add_thm); | |
| 94 | val intro_del = Thm.declaration_attribute (map_intros o Thm.del_thm); | |
| 95 | ||
| 96 | val unfold_add = Thm.declaration_attribute (map_unfolds o Thm.add_thm); | |
| 97 | val unfold_del = Thm.declaration_attribute (map_unfolds o Thm.del_thm); | |
| 98 | ||
| 99 | val refold_add = Thm.declaration_attribute (map_refolds o Thm.add_thm); | |
| 100 | val refold_del = Thm.declaration_attribute (map_refolds o Thm.del_thm); | |
| 101 | end | |
| 102 | ||
| 103 | fun add_const c = Context.theory_map (TransferData.map | |
| 104 |   (fn {intros,unfolds,refolds,consts} =>
 | |
| 105 |     {intros=intros, unfolds=unfolds, refolds=refolds, consts=c::consts}))
 | |
| 106 | ||
| 58825 | 107 | val _ = | 
| 108 | Theory.setup | |
| 109 |    (Attrib.setup @{binding transfer_intro} (Attrib.add_del intro_add intro_del)
 | |
| 110 | "declaration of transfer introduction rule" #> | |
| 111 |     Attrib.setup @{binding transfer_unfold} (Attrib.add_del unfold_add unfold_del)
 | |
| 112 | "declaration of transfer unfolding rule" #> | |
| 113 |     Attrib.setup @{binding transfer_refold} (Attrib.add_del refold_add refold_del)
 | |
| 114 | "declaration of transfer refolding rule") | |
| 27468 | 115 | |
| 116 | end; |