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