src/HOL/Hyperreal/transfer.ML
author huffman
Mon Sep 12 23:18:01 2005 +0200 (2005-09-12 ago)
changeset 17333 605c97701833
parent 17332 4910cf8c0cd2
child 17429 e8d6ed3aacfe
permissions -rw-r--r--
add header
     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 setup: (theory -> theory) list
    12 end;
    13 
    14 structure Transfer: TRANSFER_TAC =
    15 struct
    16 
    17 (* TODO: make this list extensible *)
    18 val star_consts =
    19   [ "StarType.star_of", "StarType.Ifun"
    20   , "StarType.unstar", "StarType.Iset" ]
    21 
    22 structure TransferData = TheoryDataFun
    23 (struct
    24   val name = "HOL/transfer";
    25   type T = {
    26     intros: thm list,
    27     unfolds: thm list,
    28     refolds: thm list,
    29     consts: string list
    30   };
    31   val empty = {intros = [], unfolds = [], refolds = [], consts = star_consts};
    32   val copy = I;
    33   val extend = I;
    34   fun merge _
    35     ({intros = intros1, unfolds = unfolds1,
    36       refolds = refolds1, consts = consts1},
    37      {intros = intros2, unfolds = unfolds2,
    38       refolds = refolds2, consts = consts2}) =
    39    {intros = Drule.merge_rules (intros1, intros2),
    40     unfolds = Drule.merge_rules (unfolds1, unfolds2),
    41     refolds = Drule.merge_rules (refolds1, refolds2),
    42     consts = merge_lists consts1 consts2};
    43   fun print _ _ = ();
    44 end);
    45 
    46 val transfer_start = thm "transfer_start"
    47 
    48 fun unstar_typ (Type ("StarType.star",[t])) = unstar_typ t
    49   | unstar_typ (Type (a, Ts)) = Type (a, map unstar_typ Ts)
    50   | unstar_typ T = T
    51 
    52 fun unstar_term consts term =
    53   let
    54     fun delete a = exists (fn x => x = a) consts
    55     fun unstar (Const(a,T) $ t) = if (delete a) then (unstar t)
    56           else (Const(a,unstar_typ T) $ unstar t)
    57       | unstar (f $ t) = unstar f $ unstar t
    58       | unstar (Const(a,T)) = Const(a,unstar_typ T)
    59       | unstar (Abs(a,T,t)) = Abs(a,unstar_typ T,unstar t) 
    60       | unstar t = t
    61   in
    62     unstar term
    63   end
    64 
    65 val atomizers = map thm ["atomize_all", "atomize_imp", "atomize_eq"]
    66 
    67 fun transfer_thm_of thy ths t =
    68   let
    69     val {intros,unfolds,refolds,consts} = TransferData.get thy
    70     val (_$_$t') = concl_of (Tactic.rewrite true unfolds (cterm_of thy t))
    71     val u = unstar_term consts t'
    72     val ct = cterm_of thy (Logic.mk_equals (t,u))
    73     val tacs =
    74       [ rewrite_goals_tac atomizers
    75       , match_tac [transitive_thm] 1
    76       , resolve_tac [transfer_start] 1
    77       , REPEAT_ALL_NEW (resolve_tac intros) 1
    78       , match_tac [reflexive_thm] 1 ]
    79   in
    80     prove_goalw_cterm (ths @ refolds @ unfolds) ct (fn _ => tacs)
    81   end
    82 
    83 fun transfer_tac ths =
    84     SUBGOAL (fn (t,i) =>
    85         (fn th =>
    86             let val thy = theory_of_thm th
    87                 val tr = transfer_thm_of thy ths t
    88             in rewrite_goals_tac [tr] th
    89             end
    90         )
    91     )
    92 
    93 local
    94 fun map_intros f = TransferData.map
    95   (fn {intros,unfolds,refolds,consts} =>
    96     {intros=f intros, unfolds=unfolds, refolds=refolds, consts=consts})
    97 
    98 fun map_unfolds f = TransferData.map
    99   (fn {intros,unfolds,refolds,consts} =>
   100     {intros=intros, unfolds=f unfolds, refolds=refolds, consts=consts})
   101 
   102 fun map_refolds f = TransferData.map
   103   (fn {intros,unfolds,refolds,consts} =>
   104     {intros=intros, unfolds=unfolds, refolds=f refolds, consts=consts})
   105 
   106 fun map_consts f = TransferData.map
   107   (fn {intros,unfolds,refolds,consts} =>
   108     {intros=intros, unfolds=unfolds, refolds=refolds, consts=f consts})
   109 in
   110 fun intro_add_global (thy, thm) = (map_intros (Drule.add_rule thm) thy, thm);
   111 fun intro_del_global (thy, thm) = (map_intros (Drule.del_rule thm) thy, thm);
   112 
   113 fun unfold_add_global (thy, thm) = (map_unfolds (Drule.add_rule thm) thy, thm);
   114 fun unfold_del_global (thy, thm) = (map_unfolds (Drule.del_rule thm) thy, thm);
   115 
   116 fun refold_add_global (thy, thm) = (map_refolds (Drule.add_rule thm) thy, thm);
   117 fun refold_del_global (thy, thm) = (map_refolds (Drule.del_rule thm) thy, thm);
   118 end
   119 
   120 local
   121   val undef_local =
   122     Attrib.add_del_args
   123       Attrib.undef_local_attribute
   124       Attrib.undef_local_attribute;
   125 in
   126   val intro_attr =
   127    (Attrib.add_del_args intro_add_global intro_del_global, undef_local);
   128   val unfold_attr =
   129    (Attrib.add_del_args unfold_add_global unfold_del_global, undef_local);
   130   val refold_attr =
   131    (Attrib.add_del_args refold_add_global refold_del_global, undef_local);
   132 end
   133 
   134 val transfer_method = Method.SIMPLE_METHOD' HEADGOAL o transfer_tac;
   135 
   136 val setup =
   137   [ TransferData.init,
   138     Attrib.add_attributes
   139     [ ("transfer_intro", intro_attr,
   140        "declaration of transfer introduction rule"),
   141       ("transfer_unfold", unfold_attr,
   142        "declaration of transfer unfolding rule"),
   143       ("transfer_refold", refold_attr,
   144        "declaration of transfer refolding rule")
   145     ],
   146     Method.add_method
   147     ("transfer", Method.thms_args transfer_method, "transfer principle")
   148   ];
   149 
   150 end;