src/HOL/Hyperreal/transfer.ML
author huffman
Thu Sep 15 23:46:22 2005 +0200 (2005-09-15 ago)
changeset 17429 e8d6ed3aacfe
parent 17333 605c97701833
child 17432 835647238122
permissions -rw-r--r--
merged Transfer.thy and StarType.thy into StarDef.thy; renamed Ifun2_of to starfun2; cleaned up
     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 delete a = exists (fn x => x = a) consts
    51     fun unstar (Const(a,T) $ t) = if (delete a) then (unstar t)
    52           else (Const(a,unstar_typ T) $ unstar t)
    53       | unstar (f $ t) = unstar f $ unstar t
    54       | unstar (Const(a,T)) = Const(a,unstar_typ T)
    55       | unstar (Abs(a,T,t)) = Abs(a,unstar_typ T,unstar t) 
    56       | unstar t = t
    57   in
    58     unstar term
    59   end
    60 
    61 val atomizers = map thm ["atomize_all", "atomize_imp", "atomize_eq"]
    62 
    63 fun transfer_thm_of thy ths t =
    64   let
    65     val {intros,unfolds,refolds,consts} = TransferData.get thy
    66     val (_$_$t') = concl_of (Tactic.rewrite true unfolds (cterm_of thy t))
    67     val u = unstar_term consts t'
    68     val ct = cterm_of thy (Logic.mk_equals (t,u))
    69     val tacs =
    70       [ rewrite_goals_tac atomizers
    71       , match_tac [transitive_thm] 1
    72       , resolve_tac [transfer_start] 1
    73       , REPEAT_ALL_NEW (resolve_tac intros) 1
    74       , match_tac [reflexive_thm] 1 ]
    75   in
    76     prove_goalw_cterm (ths @ refolds @ unfolds) ct (fn _ => tacs)
    77   end
    78 
    79 fun transfer_tac ths =
    80     SUBGOAL (fn (t,i) =>
    81         (fn th =>
    82             let val thy = theory_of_thm th
    83                 val tr = transfer_thm_of thy ths t
    84             in rewrite_goals_tac [tr] th
    85             end
    86         )
    87     )
    88 
    89 local
    90 fun map_intros f = TransferData.map
    91   (fn {intros,unfolds,refolds,consts} =>
    92     {intros=f intros, unfolds=unfolds, refolds=refolds, consts=consts})
    93 
    94 fun map_unfolds f = TransferData.map
    95   (fn {intros,unfolds,refolds,consts} =>
    96     {intros=intros, unfolds=f unfolds, refolds=refolds, consts=consts})
    97 
    98 fun map_refolds f = TransferData.map
    99   (fn {intros,unfolds,refolds,consts} =>
   100     {intros=intros, unfolds=unfolds, refolds=f refolds, consts=consts})
   101 in
   102 fun intro_add_global (thy, thm) = (map_intros (Drule.add_rule thm) thy, thm);
   103 fun intro_del_global (thy, thm) = (map_intros (Drule.del_rule thm) thy, thm);
   104 
   105 fun unfold_add_global (thy, thm) = (map_unfolds (Drule.add_rule thm) thy, thm);
   106 fun unfold_del_global (thy, thm) = (map_unfolds (Drule.del_rule thm) thy, thm);
   107 
   108 fun refold_add_global (thy, thm) = (map_refolds (Drule.add_rule thm) thy, thm);
   109 fun refold_del_global (thy, thm) = (map_refolds (Drule.del_rule thm) thy, thm);
   110 end
   111 
   112 fun add_const c = TransferData.map
   113   (fn {intros,unfolds,refolds,consts} =>
   114     {intros=intros, unfolds=unfolds, refolds=refolds, consts=c::consts})
   115 
   116 local
   117   val undef_local =
   118     Attrib.add_del_args
   119       Attrib.undef_local_attribute
   120       Attrib.undef_local_attribute;
   121 in
   122   val intro_attr =
   123    (Attrib.add_del_args intro_add_global intro_del_global, undef_local);
   124   val unfold_attr =
   125    (Attrib.add_del_args unfold_add_global unfold_del_global, undef_local);
   126   val refold_attr =
   127    (Attrib.add_del_args refold_add_global refold_del_global, undef_local);
   128 end
   129 
   130 val transfer_method = Method.SIMPLE_METHOD' HEADGOAL o transfer_tac;
   131 
   132 val setup =
   133   [ TransferData.init,
   134     Attrib.add_attributes
   135     [ ("transfer_intro", intro_attr,
   136        "declaration of transfer introduction rule"),
   137       ("transfer_unfold", unfold_attr,
   138        "declaration of transfer unfolding rule"),
   139       ("transfer_refold", refold_attr,
   140        "declaration of transfer refolding rule")
   141     ],
   142     Method.add_method
   143     ("transfer", Method.thms_args transfer_method, "transfer principle")
   144   ];
   145 
   146 end;