src/HOL/Hyperreal/transfer.ML
author wenzelm
Fri Oct 21 18:14:34 2005 +0200 (2005-10-21 ago)
changeset 17956 369e2af8ee45
parent 17432 835647238122
child 17985 d5d576b72371
permissions -rw-r--r--
Goal.prove;
     1 (*  Title       : HOL/Hyperreal/transfer.ML
     2     ID          : $Id$
     3     Author      : Brian Huffman
     4 
     5 Transfer principle tactic for nonstandard analysis
     6 *)
     7 
     8 signature TRANSFER_TAC =
     9 sig
    10   val transfer_tac: thm list -> int -> tactic
    11   val add_const: string -> theory -> theory
    12   val setup: (theory -> theory) list
    13 end;
    14 
    15 structure Transfer: TRANSFER_TAC =
    16 struct
    17 
    18 structure TransferData = TheoryDataFun
    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   };
    27   val empty = {intros = [], unfolds = [], refolds = [], consts = []};
    28   val copy = I;
    29   val extend = I;
    30   fun merge _
    31     ({intros = intros1, unfolds = unfolds1,
    32       refolds = refolds1, consts = consts1},
    33      {intros = intros2, unfolds = unfolds2,
    34       refolds = refolds2, consts = consts2}) =
    35    {intros = Drule.merge_rules (intros1, intros2),
    36     unfolds = Drule.merge_rules (unfolds1, unfolds2),
    37     refolds = Drule.merge_rules (refolds1, refolds2),
    38     consts = merge_lists consts1 consts2};
    39   fun print _ _ = ();
    40 end);
    41 
    42 val transfer_start = thm "transfer_start"
    43 
    44 fun unstar_typ (Type ("StarDef.star",[t])) = unstar_typ t
    45   | unstar_typ (Type (a, Ts)) = Type (a, map unstar_typ Ts)
    46   | unstar_typ T = T
    47 
    48 fun unstar_term consts term =
    49   let
    50     fun unstar (Const(a,T) $ t) = if (a mem consts) then (unstar t)
    51           else (Const(a,unstar_typ T) $ unstar t)
    52       | unstar (f $ t) = unstar f $ unstar t
    53       | unstar (Const(a,T)) = Const(a,unstar_typ T)
    54       | unstar (Abs(a,T,t)) = Abs(a,unstar_typ T,unstar t) 
    55       | unstar t = t
    56   in
    57     unstar term
    58   end
    59 
    60 val atomizers = map thm ["atomize_all", "atomize_imp", "atomize_eq"]
    61 
    62 fun transfer_thm_of thy ths t =
    63   let
    64     val {intros,unfolds,refolds,consts} = TransferData.get thy
    65     val (_$_$t') = concl_of (Tactic.rewrite true unfolds (cterm_of thy t))
    66     val u = unstar_term consts t'
    67     val ct = cterm_of thy (Logic.mk_equals (t,u))
    68     val tacs =
    69       [ rewrite_goals_tac atomizers
    70       , match_tac [transitive_thm] 1
    71       , resolve_tac [transfer_start] 1
    72       , REPEAT_ALL_NEW (resolve_tac intros) 1
    73       , match_tac [reflexive_thm] 1 ]
    74   in
    75     OldGoals.prove_goalw_cterm (ths @ refolds @ unfolds) ct (fn _ => tacs)
    76   end
    77 
    78 fun transfer_tac ths =
    79     SUBGOAL (fn (t,i) =>
    80         (fn th =>
    81             let val thy = theory_of_thm th
    82                 val tr = transfer_thm_of thy ths t
    83             in rewrite_goals_tac [tr] th
    84             end
    85         )
    86     )
    87 
    88 local
    89 fun map_intros f = TransferData.map
    90   (fn {intros,unfolds,refolds,consts} =>
    91     {intros=f intros, unfolds=unfolds, refolds=refolds, consts=consts})
    92 
    93 fun map_unfolds f = TransferData.map
    94   (fn {intros,unfolds,refolds,consts} =>
    95     {intros=intros, unfolds=f unfolds, refolds=refolds, consts=consts})
    96 
    97 fun map_refolds f = TransferData.map
    98   (fn {intros,unfolds,refolds,consts} =>
    99     {intros=intros, unfolds=unfolds, refolds=f refolds, consts=consts})
   100 in
   101 fun intro_add_global (thy, thm) = (map_intros (Drule.add_rule thm) thy, thm);
   102 fun intro_del_global (thy, thm) = (map_intros (Drule.del_rule thm) thy, thm);
   103 
   104 fun unfold_add_global (thy, thm) = (map_unfolds (Drule.add_rule thm) thy, thm);
   105 fun unfold_del_global (thy, thm) = (map_unfolds (Drule.del_rule thm) thy, thm);
   106 
   107 fun refold_add_global (thy, thm) = (map_refolds (Drule.add_rule thm) thy, thm);
   108 fun refold_del_global (thy, thm) = (map_refolds (Drule.del_rule thm) thy, thm);
   109 end
   110 
   111 fun add_const c = TransferData.map
   112   (fn {intros,unfolds,refolds,consts} =>
   113     {intros=intros, unfolds=unfolds, refolds=refolds, consts=c::consts})
   114 
   115 local
   116   val undef_local =
   117     Attrib.add_del_args
   118       Attrib.undef_local_attribute
   119       Attrib.undef_local_attribute;
   120 in
   121   val intro_attr =
   122    (Attrib.add_del_args intro_add_global intro_del_global, undef_local);
   123   val unfold_attr =
   124    (Attrib.add_del_args unfold_add_global unfold_del_global, undef_local);
   125   val refold_attr =
   126    (Attrib.add_del_args refold_add_global refold_del_global, undef_local);
   127 end
   128 
   129 val transfer_method = Method.SIMPLE_METHOD' HEADGOAL o transfer_tac;
   130 
   131 val setup =
   132   [ TransferData.init,
   133     Attrib.add_attributes
   134     [ ("transfer_intro", intro_attr,
   135        "declaration of transfer introduction rule"),
   136       ("transfer_unfold", unfold_attr,
   137        "declaration of transfer unfolding rule"),
   138       ("transfer_refold", refold_attr,
   139        "declaration of transfer refolding rule")
   140     ],
   141     Method.add_method
   142     ("transfer", Method.thms_args transfer_method, "transfer principle")
   143   ];
   144 
   145 end;