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