src/HOL/Hyperreal/transfer.ML
author urbanc
Tue, 13 Dec 2005 18:11:21 +0100
changeset 18396 b3e7da94b51f
parent 17985 d5d576b72371
child 18708 4b3dadb4fe33
permissions -rw-r--r--
added a fresh_left lemma that contains all instantiation for the various atom-types.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17333
605c97701833 add header
huffman
parents: 17332
diff changeset
     1
(*  Title       : HOL/Hyperreal/transfer.ML
605c97701833 add header
huffman
parents: 17332
diff changeset
     2
    ID          : $Id$
605c97701833 add header
huffman
parents: 17332
diff changeset
     3
    Author      : Brian Huffman
605c97701833 add header
huffman
parents: 17332
diff changeset
     4
605c97701833 add header
huffman
parents: 17332
diff changeset
     5
Transfer principle tactic for nonstandard analysis
605c97701833 add header
huffman
parents: 17332
diff changeset
     6
*)
605c97701833 add header
huffman
parents: 17332
diff changeset
     7
17329
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
     8
signature TRANSFER_TAC =
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
     9
sig
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    10
  val transfer_tac: thm list -> int -> tactic
17429
e8d6ed3aacfe merged Transfer.thy and StarType.thy into StarDef.thy; renamed Ifun2_of to starfun2; cleaned up
huffman
parents: 17333
diff changeset
    11
  val add_const: string -> theory -> theory
17329
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    12
  val setup: (theory -> theory) list
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    13
end;
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    14
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    15
structure Transfer: TRANSFER_TAC =
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    16
struct
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    17
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    18
structure TransferData = TheoryDataFun
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    19
(struct
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    20
  val name = "HOL/transfer";
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    21
  type T = {
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    22
    intros: thm list,
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    23
    unfolds: thm list,
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    24
    refolds: thm list,
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    25
    consts: string list
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    26
  };
17429
e8d6ed3aacfe merged Transfer.thy and StarType.thy into StarDef.thy; renamed Ifun2_of to starfun2; cleaned up
huffman
parents: 17333
diff changeset
    27
  val empty = {intros = [], unfolds = [], refolds = [], consts = []};
17329
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    28
  val copy = I;
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    29
  val extend = I;
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    30
  fun merge _
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    31
    ({intros = intros1, unfolds = unfolds1,
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    32
      refolds = refolds1, consts = consts1},
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    33
     {intros = intros2, unfolds = unfolds2,
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    34
      refolds = refolds2, consts = consts2}) =
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    35
   {intros = Drule.merge_rules (intros1, intros2),
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    36
    unfolds = Drule.merge_rules (unfolds1, unfolds2),
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    37
    refolds = Drule.merge_rules (refolds1, refolds2),
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    38
    consts = merge_lists consts1 consts2};
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    39
  fun print _ _ = ();
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    40
end);
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    41
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    42
val transfer_start = thm "transfer_start"
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    43
17429
e8d6ed3aacfe merged Transfer.thy and StarType.thy into StarDef.thy; renamed Ifun2_of to starfun2; cleaned up
huffman
parents: 17333
diff changeset
    44
fun unstar_typ (Type ("StarDef.star",[t])) = unstar_typ t
17329
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    45
  | unstar_typ (Type (a, Ts)) = Type (a, map unstar_typ Ts)
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    46
  | unstar_typ T = T
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    47
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    48
fun unstar_term consts term =
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    49
  let
17432
835647238122 use mem operator
huffman
parents: 17429
diff changeset
    50
    fun unstar (Const(a,T) $ t) = if (a mem consts) then (unstar t)
17329
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    51
          else (Const(a,unstar_typ T) $ unstar t)
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    52
      | unstar (f $ t) = unstar f $ unstar t
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    53
      | unstar (Const(a,T)) = Const(a,unstar_typ T)
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    54
      | unstar (Abs(a,T,t)) = Abs(a,unstar_typ T,unstar t) 
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    55
      | unstar t = t
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    56
  in
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    57
    unstar term
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    58
  end
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    59
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    60
val atomizers = map thm ["atomize_all", "atomize_imp", "atomize_eq"]
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    61
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    62
fun transfer_thm_of thy ths t =
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    63
  let
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    64
    val {intros,unfolds,refolds,consts} = TransferData.get thy
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    65
    val (_$_$t') = concl_of (Tactic.rewrite true unfolds (cterm_of thy t))
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    66
    val u = unstar_term consts t'
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    67
    val tacs =
17985
d5d576b72371 avoid legacy goals;
wenzelm
parents: 17956
diff changeset
    68
      [ rewrite_goals_tac (ths @ refolds @ unfolds)
d5d576b72371 avoid legacy goals;
wenzelm
parents: 17956
diff changeset
    69
      , rewrite_goals_tac atomizers
17329
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    70
      , match_tac [transitive_thm] 1
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    71
      , resolve_tac [transfer_start] 1
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    72
      , REPEAT_ALL_NEW (resolve_tac intros) 1
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    73
      , match_tac [reflexive_thm] 1 ]
17985
d5d576b72371 avoid legacy goals;
wenzelm
parents: 17956
diff changeset
    74
  in Goal.prove thy [] [] (Logic.mk_equals (t,u)) (fn _ => EVERY tacs) end
17329
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    75
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    76
fun transfer_tac ths =
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    77
    SUBGOAL (fn (t,i) =>
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    78
        (fn th =>
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    79
            let val thy = theory_of_thm th
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    80
                val tr = transfer_thm_of thy ths t
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    81
            in rewrite_goals_tac [tr] th
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    82
            end
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    83
        )
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    84
    )
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    85
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    86
local
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    87
fun map_intros f = TransferData.map
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    88
  (fn {intros,unfolds,refolds,consts} =>
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    89
    {intros=f intros, unfolds=unfolds, refolds=refolds, consts=consts})
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    90
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    91
fun map_unfolds f = TransferData.map
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    92
  (fn {intros,unfolds,refolds,consts} =>
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    93
    {intros=intros, unfolds=f unfolds, refolds=refolds, consts=consts})
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    94
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    95
fun map_refolds f = TransferData.map
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    96
  (fn {intros,unfolds,refolds,consts} =>
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    97
    {intros=intros, unfolds=unfolds, refolds=f refolds, consts=consts})
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    98
in
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
    99
fun intro_add_global (thy, thm) = (map_intros (Drule.add_rule thm) thy, thm);
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
   100
fun intro_del_global (thy, thm) = (map_intros (Drule.del_rule thm) thy, thm);
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
   101
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
   102
fun unfold_add_global (thy, thm) = (map_unfolds (Drule.add_rule thm) thy, thm);
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
   103
fun unfold_del_global (thy, thm) = (map_unfolds (Drule.del_rule thm) thy, thm);
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
   104
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
   105
fun refold_add_global (thy, thm) = (map_refolds (Drule.add_rule thm) thy, thm);
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
   106
fun refold_del_global (thy, thm) = (map_refolds (Drule.del_rule thm) thy, thm);
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
   107
end
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
   108
17429
e8d6ed3aacfe merged Transfer.thy and StarType.thy into StarDef.thy; renamed Ifun2_of to starfun2; cleaned up
huffman
parents: 17333
diff changeset
   109
fun add_const c = TransferData.map
e8d6ed3aacfe merged Transfer.thy and StarType.thy into StarDef.thy; renamed Ifun2_of to starfun2; cleaned up
huffman
parents: 17333
diff changeset
   110
  (fn {intros,unfolds,refolds,consts} =>
e8d6ed3aacfe merged Transfer.thy and StarType.thy into StarDef.thy; renamed Ifun2_of to starfun2; cleaned up
huffman
parents: 17333
diff changeset
   111
    {intros=intros, unfolds=unfolds, refolds=refolds, consts=c::consts})
e8d6ed3aacfe merged Transfer.thy and StarType.thy into StarDef.thy; renamed Ifun2_of to starfun2; cleaned up
huffman
parents: 17333
diff changeset
   112
17329
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
   113
local
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
   114
  val undef_local =
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
   115
    Attrib.add_del_args
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
   116
      Attrib.undef_local_attribute
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
   117
      Attrib.undef_local_attribute;
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
   118
in
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
   119
  val intro_attr =
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
   120
   (Attrib.add_del_args intro_add_global intro_del_global, undef_local);
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
   121
  val unfold_attr =
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
   122
   (Attrib.add_del_args unfold_add_global unfold_del_global, undef_local);
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
   123
  val refold_attr =
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
   124
   (Attrib.add_del_args refold_add_global refold_del_global, undef_local);
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
   125
end
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
   126
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
   127
val transfer_method = Method.SIMPLE_METHOD' HEADGOAL o transfer_tac;
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
   128
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
   129
val setup =
17332
4910cf8c0cd2 added theorem attributes transfer_intro, transfer_unfold, transfer_refold; simplified some proofs; some rearranging
huffman
parents: 17329
diff changeset
   130
  [ TransferData.init,
4910cf8c0cd2 added theorem attributes transfer_intro, transfer_unfold, transfer_refold; simplified some proofs; some rearranging
huffman
parents: 17329
diff changeset
   131
    Attrib.add_attributes
4910cf8c0cd2 added theorem attributes transfer_intro, transfer_unfold, transfer_refold; simplified some proofs; some rearranging
huffman
parents: 17329
diff changeset
   132
    [ ("transfer_intro", intro_attr,
4910cf8c0cd2 added theorem attributes transfer_intro, transfer_unfold, transfer_refold; simplified some proofs; some rearranging
huffman
parents: 17329
diff changeset
   133
       "declaration of transfer introduction rule"),
4910cf8c0cd2 added theorem attributes transfer_intro, transfer_unfold, transfer_refold; simplified some proofs; some rearranging
huffman
parents: 17329
diff changeset
   134
      ("transfer_unfold", unfold_attr,
4910cf8c0cd2 added theorem attributes transfer_intro, transfer_unfold, transfer_refold; simplified some proofs; some rearranging
huffman
parents: 17329
diff changeset
   135
       "declaration of transfer unfolding rule"),
4910cf8c0cd2 added theorem attributes transfer_intro, transfer_unfold, transfer_refold; simplified some proofs; some rearranging
huffman
parents: 17329
diff changeset
   136
      ("transfer_refold", refold_attr,
4910cf8c0cd2 added theorem attributes transfer_intro, transfer_unfold, transfer_refold; simplified some proofs; some rearranging
huffman
parents: 17329
diff changeset
   137
       "declaration of transfer refolding rule")
4910cf8c0cd2 added theorem attributes transfer_intro, transfer_unfold, transfer_refold; simplified some proofs; some rearranging
huffman
parents: 17329
diff changeset
   138
    ],
4910cf8c0cd2 added theorem attributes transfer_intro, transfer_unfold, transfer_refold; simplified some proofs; some rearranging
huffman
parents: 17329
diff changeset
   139
    Method.add_method
17329
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
   140
    ("transfer", Method.thms_args transfer_method, "transfer principle")
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
   141
  ];
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
   142
72637e062a0d new implementation of transfer principle
huffman
parents:
diff changeset
   143
end;