src/HOL/Hyperreal/transfer.ML
changeset 17329 72637e062a0d
child 17332 4910cf8c0cd2
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/HOL/Hyperreal/transfer.ML	Mon Sep 12 23:06:24 2005 +0200
     1.3 @@ -0,0 +1,140 @@
     1.4 +signature TRANSFER_TAC =
     1.5 +sig
     1.6 +  val transfer_tac: thm list -> int -> tactic
     1.7 +  val setup: (theory -> theory) list
     1.8 +end;
     1.9 +
    1.10 +structure Transfer: TRANSFER_TAC =
    1.11 +struct
    1.12 +
    1.13 +(* TODO: make this list extensible *)
    1.14 +val star_consts =
    1.15 +  [ "StarType.star_of", "StarType.Ifun"
    1.16 +  , "StarType.unstar", "StarType.Iset" ]
    1.17 +
    1.18 +structure TransferData = TheoryDataFun
    1.19 +(struct
    1.20 +  val name = "HOL/transfer";
    1.21 +  type T = {
    1.22 +    intros: thm list,
    1.23 +    unfolds: thm list,
    1.24 +    refolds: thm list,
    1.25 +    consts: string list
    1.26 +  };
    1.27 +  val empty = {intros = [], unfolds = [], refolds = [], consts = star_consts};
    1.28 +  val copy = I;
    1.29 +  val extend = I;
    1.30 +  fun merge _
    1.31 +    ({intros = intros1, unfolds = unfolds1,
    1.32 +      refolds = refolds1, consts = consts1},
    1.33 +     {intros = intros2, unfolds = unfolds2,
    1.34 +      refolds = refolds2, consts = consts2}) =
    1.35 +   {intros = Drule.merge_rules (intros1, intros2),
    1.36 +    unfolds = Drule.merge_rules (unfolds1, unfolds2),
    1.37 +    refolds = Drule.merge_rules (refolds1, refolds2),
    1.38 +    consts = merge_lists consts1 consts2};
    1.39 +  fun print _ _ = ();
    1.40 +end);
    1.41 +
    1.42 +val transfer_start = thm "transfer_start"
    1.43 +
    1.44 +fun unstar_typ (Type ("StarType.star",[t])) = unstar_typ t
    1.45 +  | unstar_typ (Type (a, Ts)) = Type (a, map unstar_typ Ts)
    1.46 +  | unstar_typ T = T
    1.47 +
    1.48 +fun unstar_term consts term =
    1.49 +  let
    1.50 +    fun delete a = exists (fn x => x = a) consts
    1.51 +    fun unstar (Const(a,T) $ t) = if (delete a) then (unstar t)
    1.52 +          else (Const(a,unstar_typ T) $ unstar t)
    1.53 +      | unstar (f $ t) = unstar f $ unstar t
    1.54 +      | unstar (Const(a,T)) = Const(a,unstar_typ T)
    1.55 +      | unstar (Abs(a,T,t)) = Abs(a,unstar_typ T,unstar t) 
    1.56 +      | unstar t = t
    1.57 +  in
    1.58 +    unstar term
    1.59 +  end
    1.60 +
    1.61 +val atomizers = map thm ["atomize_all", "atomize_imp", "atomize_eq"]
    1.62 +
    1.63 +fun transfer_thm_of thy ths t =
    1.64 +  let
    1.65 +    val {intros,unfolds,refolds,consts} = TransferData.get thy
    1.66 +    val (_$_$t') = concl_of (Tactic.rewrite true unfolds (cterm_of thy t))
    1.67 +    val u = unstar_term consts t'
    1.68 +    val ct = cterm_of thy (Logic.mk_equals (t,u))
    1.69 +    val tacs =
    1.70 +      [ rewrite_goals_tac atomizers
    1.71 +      , match_tac [transitive_thm] 1
    1.72 +      , resolve_tac [transfer_start] 1
    1.73 +      , REPEAT_ALL_NEW (resolve_tac intros) 1
    1.74 +      , match_tac [reflexive_thm] 1 ]
    1.75 +  in
    1.76 +    prove_goalw_cterm (ths @ refolds @ unfolds) ct (fn _ => tacs)
    1.77 +  end
    1.78 +
    1.79 +fun transfer_tac ths =
    1.80 +    SUBGOAL (fn (t,i) =>
    1.81 +        (fn th =>
    1.82 +            let val thy = theory_of_thm th
    1.83 +                val tr = transfer_thm_of thy ths t
    1.84 +            in rewrite_goals_tac [tr] th
    1.85 +            end
    1.86 +        )
    1.87 +    )
    1.88 +
    1.89 +local
    1.90 +fun map_intros f = TransferData.map
    1.91 +  (fn {intros,unfolds,refolds,consts} =>
    1.92 +    {intros=f intros, unfolds=unfolds, refolds=refolds, consts=consts})
    1.93 +
    1.94 +fun map_unfolds f = TransferData.map
    1.95 +  (fn {intros,unfolds,refolds,consts} =>
    1.96 +    {intros=intros, unfolds=f unfolds, refolds=refolds, consts=consts})
    1.97 +
    1.98 +fun map_refolds f = TransferData.map
    1.99 +  (fn {intros,unfolds,refolds,consts} =>
   1.100 +    {intros=intros, unfolds=unfolds, refolds=f refolds, consts=consts})
   1.101 +
   1.102 +fun map_consts f = TransferData.map
   1.103 +  (fn {intros,unfolds,refolds,consts} =>
   1.104 +    {intros=intros, unfolds=unfolds, refolds=refolds, consts=f consts})
   1.105 +in
   1.106 +fun intro_add_global (thy, thm) = (map_intros (Drule.add_rule thm) thy, thm);
   1.107 +fun intro_del_global (thy, thm) = (map_intros (Drule.del_rule thm) thy, thm);
   1.108 +
   1.109 +fun unfold_add_global (thy, thm) = (map_unfolds (Drule.add_rule thm) thy, thm);
   1.110 +fun unfold_del_global (thy, thm) = (map_unfolds (Drule.del_rule thm) thy, thm);
   1.111 +
   1.112 +fun refold_add_global (thy, thm) = (map_refolds (Drule.add_rule thm) thy, thm);
   1.113 +fun refold_del_global (thy, thm) = (map_refolds (Drule.del_rule thm) thy, thm);
   1.114 +end
   1.115 +
   1.116 +local
   1.117 +  val undef_local =
   1.118 +    Attrib.add_del_args
   1.119 +      Attrib.undef_local_attribute
   1.120 +      Attrib.undef_local_attribute;
   1.121 +in
   1.122 +  val intro_attr =
   1.123 +   (Attrib.add_del_args intro_add_global intro_del_global, undef_local);
   1.124 +  val unfold_attr =
   1.125 +   (Attrib.add_del_args unfold_add_global unfold_del_global, undef_local);
   1.126 +  val refold_attr =
   1.127 +   (Attrib.add_del_args refold_add_global refold_del_global, undef_local);
   1.128 +end
   1.129 +
   1.130 +val transfer_method = Method.SIMPLE_METHOD' HEADGOAL o transfer_tac;
   1.131 +
   1.132 +val setup =
   1.133 +  [ TransferData.init
   1.134 +  , Attrib.add_attributes
   1.135 +    [ ("transfer_intro", intro_attr, "transfer introduction rule")
   1.136 +    , ("transfer_unfold", unfold_attr, "transfer unfolding rule")
   1.137 +    , ("transfer_refold", refold_attr, "transfer refolding rule")
   1.138 +    ]
   1.139 +  , Method.add_method
   1.140 +    ("transfer", Method.thms_args transfer_method, "transfer principle")
   1.141 +  ];
   1.142 +
   1.143 +end;