| author | huffman | 
| Wed, 27 Sep 2006 07:09:19 +0200 | |
| changeset 20730 | da903f59e9ba | 
| parent 20049 | f48c4a3a34bc | 
| child 21506 | b2a673894ce5 | 
| 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: 
17333diff
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: 
17333diff
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), | |
| 19734 | 37 | consts = Library.merge (op =) (consts1, consts2)} : T; | 
| 17329 | 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: 
17333diff
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 | |
| 19734 | 49 | fun unstar (Const(a,T) $ t) = if member (op =) consts a 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 | ||
| 18729 | 59 | fun transfer_thm_of ctxt ths t = | 
| 17329 | 60 | let | 
| 18729 | 61 | val thy = ProofContext.theory_of ctxt; | 
| 62 |     val {intros,unfolds,refolds,consts} = TransferData.get (Context.Proof ctxt)
 | |
| 19734 | 63 | val meta = LocalDefs.meta_rewrite_rule (Context.Proof ctxt) | 
| 64 | val unfolds' = map meta unfolds and refolds' = map meta refolds; | |
| 65 | val (_$_$t') = concl_of (Tactic.rewrite true unfolds' (cterm_of thy t)) | |
| 17329 | 66 | val u = unstar_term consts t' | 
| 18729 | 67 | val tac = | 
| 19734 | 68 | rewrite_goals_tac (ths @ refolds' @ unfolds') THEN | 
| 69 | ALLGOALS ObjectLogic.full_atomize_tac THEN | |
| 18729 | 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 | |
| 20049 | 74 | in Goal.prove ctxt [] [] (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 | |
| 19734 | 83 | |
| 17329 | 84 | fun map_intros f = TransferData.map | 
| 85 |   (fn {intros,unfolds,refolds,consts} =>
 | |
| 86 |     {intros=f intros, unfolds=unfolds, refolds=refolds, consts=consts})
 | |
| 87 | ||
| 88 | fun map_unfolds f = TransferData.map | |
| 89 |   (fn {intros,unfolds,refolds,consts} =>
 | |
| 90 |     {intros=intros, unfolds=f unfolds, refolds=refolds, consts=consts})
 | |
| 91 | ||
| 92 | fun map_refolds f = TransferData.map | |
| 93 |   (fn {intros,unfolds,refolds,consts} =>
 | |
| 94 |     {intros=intros, unfolds=unfolds, refolds=f refolds, consts=consts})
 | |
| 95 | in | |
| 18729 | 96 | val intro_add = Thm.declaration_attribute (map_intros o Drule.add_rule); | 
| 97 | val intro_del = Thm.declaration_attribute (map_intros o Drule.del_rule); | |
| 17329 | 98 | |
| 18729 | 99 | val unfold_add = Thm.declaration_attribute (map_unfolds o Drule.add_rule); | 
| 100 | val unfold_del = Thm.declaration_attribute (map_unfolds o Drule.del_rule); | |
| 17329 | 101 | |
| 18729 | 102 | val refold_add = Thm.declaration_attribute (map_refolds o Drule.add_rule); | 
| 103 | val refold_del = Thm.declaration_attribute (map_refolds o Drule.del_rule); | |
| 17329 | 104 | end | 
| 105 | ||
| 18729 | 106 | 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: 
17333diff
changeset | 107 |   (fn {intros,unfolds,refolds,consts} =>
 | 
| 18729 | 108 |     {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: 
17333diff
changeset | 109 | |
| 18729 | 110 | val transfer_method = Method.thms_ctxt_args (fn ths => fn ctxt => | 
| 111 | Method.SIMPLE_METHOD' HEADGOAL (transfer_tac ctxt ths)); | |
| 17329 | 112 | |
| 113 | val setup = | |
| 18708 | 114 | TransferData.init #> | 
| 115 | Attrib.add_attributes | |
| 18729 | 116 |     [("transfer_intro", Attrib.add_del_args intro_add intro_del,
 | 
| 18708 | 117 | "declaration of transfer introduction rule"), | 
| 18729 | 118 |      ("transfer_unfold", Attrib.add_del_args unfold_add unfold_del,
 | 
| 18708 | 119 | "declaration of transfer unfolding rule"), | 
| 18729 | 120 |      ("transfer_refold", Attrib.add_del_args refold_add refold_del,
 | 
| 18708 | 121 | "declaration of transfer refolding rule")] #> | 
| 18729 | 122 |   Method.add_method ("transfer", transfer_method, "transfer principle");
 | 
| 17329 | 123 | |
| 124 | end; |