Nominal/nominal_thmdecls.ML
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Fri, 19 Apr 2013 00:10:52 +0100
changeset 3218 89158f401b07
parent 3214 13ab4f0a0b0e
child 3231 188826f1ccdb
permissions -rw-r--r--
updated to simplifier changes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1037
2845e736dc1a added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents: 947
diff changeset
     1
(*  Title:      nominal_thmdecls.ML
2845e736dc1a added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents: 947
diff changeset
     2
    Author:     Christian Urban
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
     3
    Author:     Tjark Weber
1037
2845e736dc1a added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents: 947
diff changeset
     4
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
     5
  Infrastructure for the lemma collections "eqvts", "eqvts_raw".
1037
2845e736dc1a added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents: 947
diff changeset
     6
1066
96651cddeba9 eqvts and eqvts_raw are separate thm-lists; otherwise permute_eqvt is problematic as it causes looks in eqvts
Christian Urban <urbanc@in.tum.de>
parents: 1059
diff changeset
     7
  Provides the attributes [eqvt] and [eqvt_raw], and the theorem
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
     8
  lists "eqvts" and "eqvts_raw".
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
     9
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    10
  The [eqvt] attribute expects a theorem of the form
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    11
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    12
    ?p \<bullet> (c ?x1 ?x2 ...) = c (?p \<bullet> ?x1) (?p \<bullet> ?x2) ...    (1)
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    13
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    14
  or, if c is a relation with arity >= 1, of the form
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    15
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    16
    c ?x1 ?x2 ... ==> c (?p \<bullet> ?x1) (?p \<bullet> ?x2) ...         (2)
947
fa810f01f7b5 added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    18
  [eqvt] will store this theorem in the form (1) or, if c
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    19
  is a relation with arity >= 1, in the form
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    20
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    21
    c (?p \<bullet> ?x1) (?p \<bullet> ?x2) ... = c ?x1 ?x2 ...           (3)
1811
ae176476b525 implemented in thmdecls the case where eqvt-lemmas are of the form _ ==> _
Christian Urban <urbanc@in.tum.de>
parents: 1810
diff changeset
    22
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    23
  in "eqvts". (The orientation of (3) was chosen because
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    24
  Isabelle's simplifier uses equations from left to right.)
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    25
  [eqvt] will also derive and store the theorem
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    26
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    27
    ?p \<bullet> c == c                                           (4)
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    28
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    29
  in "eqvts_raw".
1811
ae176476b525 implemented in thmdecls the case where eqvt-lemmas are of the form _ ==> _
Christian Urban <urbanc@in.tum.de>
parents: 1810
diff changeset
    30
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    31
  (1)-(4) are all logically equivalent. We consider (1) and (2)
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    32
  to be more end-user friendly, i.e., slightly more natural to
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    33
  understand and prove, while (3) and (4) make the rewriting
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    34
  system for equivariance more predictable and less prone to
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    35
  looping in Isabelle.
1037
2845e736dc1a added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents: 947
diff changeset
    36
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    37
  The [eqvt_raw] attribute expects a theorem of the form (4),
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    38
  and merely stores it in "eqvts_raw".
1037
2845e736dc1a added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents: 947
diff changeset
    39
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    40
  [eqvt_raw] is provided because certain equivariance theorems
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    41
  would lead to looping when used for simplification in the form
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    42
  (1): notably, equivariance of permute (infix \<bullet>), i.e.,
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    43
  ?p \<bullet> (?q \<bullet> ?x) = (?p \<bullet> ?q) \<bullet> (?p \<bullet> ?x).
947
fa810f01f7b5 added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    45
  To support binders such as All/Ex/Ball/Bex etc., which are
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    46
  typically applied to abstractions, argument terms ?xi (as well
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    47
  as permuted arguments ?p \<bullet> ?xi) in (1)-(3) need not be eta-
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    48
  contracted, i.e., they may be of the form "%z. ?xi z" or
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    49
  "%z. (?p \<bullet> ?x) z", respectively.
1037
2845e736dc1a added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents: 947
diff changeset
    50
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    51
  For convenience, argument terms ?xi (as well as permuted
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    52
  arguments ?p \<bullet> ?xi) in (1)-(3) may actually be tuples, e.g.,
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    53
  "(?xi, ?xj)" or "(?p \<bullet> ?xi, ?p \<bullet> ?xj)", respectively.
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    54
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    55
  In (1)-(4), "c" is either a (global) constant or a locally
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    56
  fixed parameter, e.g., of a locale or type class.
947
fa810f01f7b5 added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
*)
fa810f01f7b5 added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
fa810f01f7b5 added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
signature NOMINAL_THMDECLS =
fa810f01f7b5 added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
sig
fa810f01f7b5 added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
  val eqvt_add: attribute
fa810f01f7b5 added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
  val eqvt_del: attribute
1066
96651cddeba9 eqvts and eqvts_raw are separate thm-lists; otherwise permute_eqvt is problematic as it causes looks in eqvts
Christian Urban <urbanc@in.tum.de>
parents: 1059
diff changeset
    63
  val eqvt_raw_add: attribute
96651cddeba9 eqvts and eqvts_raw are separate thm-lists; otherwise permute_eqvt is problematic as it causes looks in eqvts
Christian Urban <urbanc@in.tum.de>
parents: 1059
diff changeset
    64
  val eqvt_raw_del: attribute
947
fa810f01f7b5 added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
  val setup: theory -> theory
1066
96651cddeba9 eqvts and eqvts_raw are separate thm-lists; otherwise permute_eqvt is problematic as it causes looks in eqvts
Christian Urban <urbanc@in.tum.de>
parents: 1059
diff changeset
    66
  val get_eqvts_thms: Proof.context -> thm list
96651cddeba9 eqvts and eqvts_raw are separate thm-lists; otherwise permute_eqvt is problematic as it causes looks in eqvts
Christian Urban <urbanc@in.tum.de>
parents: 1059
diff changeset
    67
  val get_eqvts_raw_thms: Proof.context -> thm list
1870
55b2da92ff2f tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents: 1846
diff changeset
    68
  val eqvt_transform: Proof.context -> thm -> thm
1953
186d8486dfd5 rewrote eqvts_raw to be a symtab, that can be looked up
Christian Urban <urbanc@in.tum.de>
parents: 1947
diff changeset
    69
  val is_eqvt: Proof.context -> term -> bool
947
fa810f01f7b5 added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
end;
fa810f01f7b5 added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
1037
2845e736dc1a added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents: 947
diff changeset
    72
structure Nominal_ThmDecls: NOMINAL_THMDECLS =
947
fa810f01f7b5 added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
struct
fa810f01f7b5 added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
1037
2845e736dc1a added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents: 947
diff changeset
    75
structure EqvtData = Generic_Data
1066
96651cddeba9 eqvts and eqvts_raw are separate thm-lists; otherwise permute_eqvt is problematic as it causes looks in eqvts
Christian Urban <urbanc@in.tum.de>
parents: 1059
diff changeset
    76
( type T = thm Item_Net.T;
96651cddeba9 eqvts and eqvts_raw are separate thm-lists; otherwise permute_eqvt is problematic as it causes looks in eqvts
Christian Urban <urbanc@in.tum.de>
parents: 1059
diff changeset
    77
  val empty = Thm.full_rules;
1037
2845e736dc1a added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents: 947
diff changeset
    78
  val extend = I;
1953
186d8486dfd5 rewrote eqvts_raw to be a symtab, that can be looked up
Christian Urban <urbanc@in.tum.de>
parents: 1947
diff changeset
    79
  val merge = Item_Net.merge);
1037
2845e736dc1a added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents: 947
diff changeset
    80
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    81
(* EqvtRawData is implemented with a Termtab (rather than an
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    82
   Item_Net) so that we can efficiently decide whether a given
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    83
   constant has a corresponding equivariance theorem stored, cf.
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    84
   the function is_eqvt. *)
1066
96651cddeba9 eqvts and eqvts_raw are separate thm-lists; otherwise permute_eqvt is problematic as it causes looks in eqvts
Christian Urban <urbanc@in.tum.de>
parents: 1059
diff changeset
    85
structure EqvtRawData = Generic_Data
2200
31f1ec832d39 fixed bug where perm_simp 'forgets' how to prove equivariance for the empty set
Christian Urban <urbanc@in.tum.de>
parents: 2123
diff changeset
    86
( type T = thm Termtab.table;
31f1ec832d39 fixed bug where perm_simp 'forgets' how to prove equivariance for the empty set
Christian Urban <urbanc@in.tum.de>
parents: 2123
diff changeset
    87
  val empty = Termtab.empty;
1066
96651cddeba9 eqvts and eqvts_raw are separate thm-lists; otherwise permute_eqvt is problematic as it causes looks in eqvts
Christian Urban <urbanc@in.tum.de>
parents: 1059
diff changeset
    88
  val extend = I;
2200
31f1ec832d39 fixed bug where perm_simp 'forgets' how to prove equivariance for the empty set
Christian Urban <urbanc@in.tum.de>
parents: 2123
diff changeset
    89
  val merge = Termtab.merge (K true));
1059
090fa3f21380 restored the old behaviour of having an eqvts list; the transformed theorems are stored in eqvts_raw
Christian Urban <urbanc@in.tum.de>
parents: 1039
diff changeset
    90
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    91
val eqvts = Item_Net.content o EqvtData.get
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    92
val eqvts_raw = map snd o Termtab.dest o EqvtRawData.get
1037
2845e736dc1a added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents: 947
diff changeset
    93
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    94
val get_eqvts_thms = eqvts o Context.Proof
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    95
val get_eqvts_raw_thms = eqvts_raw o Context.Proof
1037
2845e736dc1a added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents: 947
diff changeset
    96
1870
55b2da92ff2f tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents: 1846
diff changeset
    97
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    98
(** raw equivariance lemmas **)
1870
55b2da92ff2f tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents: 1846
diff changeset
    99
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   100
(* Returns true iff an equivariance lemma exists in "eqvts_raw"
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   101
   for a given term. *)
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   102
val is_eqvt =
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   103
  Termtab.defined o EqvtRawData.get o Context.Proof
1953
186d8486dfd5 rewrote eqvts_raw to be a symtab, that can be looked up
Christian Urban <urbanc@in.tum.de>
parents: 1947
diff changeset
   104
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   105
(* Returns c if thm is of the form (4), raises an error
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   106
   otherwise. *)
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   107
fun key_of_raw_thm context thm =
2650
e5fa8de0e4bd derived equivariance for the function graph and function relation
Christian Urban <urbanc@in.tum.de>
parents: 2568
diff changeset
   108
  let
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   109
    fun error_msg () =
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   110
      error
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   111
        ("Theorem must be of the form \"?p \<bullet> c \<equiv> c\", with c a constant or fixed parameter:\n" ^
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   112
         Syntax.string_of_term (Context.proof_of context) (prop_of thm))
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   113
  in
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   114
    case prop_of thm of
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   115
      Const ("==", _) $ (Const (@{const_name "permute"}, _) $ p $ c) $ c' =>
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   116
        if is_Var p andalso is_fixed (Context.proof_of context) c andalso c aconv c' then
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   117
          c
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   118
        else
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   119
          error_msg ()
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   120
    | _ => error_msg ()
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   121
  end
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   122
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   123
fun add_raw_thm thm context =
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   124
  let
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   125
    val c = key_of_raw_thm context thm
2650
e5fa8de0e4bd derived equivariance for the function graph and function relation
Christian Urban <urbanc@in.tum.de>
parents: 2568
diff changeset
   126
  in
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   127
    if Termtab.defined (EqvtRawData.get context) c then
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   128
      warning ("Replacing existing raw equivariance theorem for \"" ^
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   129
        Syntax.string_of_term (Context.proof_of context) c ^ "\".")
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   130
    else ();
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   131
    EqvtRawData.map (Termtab.update (c, thm)) context
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   132
  end
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   133
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   134
fun del_raw_thm thm context =
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   135
  let
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   136
    val c = key_of_raw_thm context thm
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   137
  in
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   138
    if Termtab.defined (EqvtRawData.get context) c then
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   139
      EqvtRawData.map (Termtab.delete c) context
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   140
    else (
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   141
      warning ("Cannot delete non-existing raw equivariance theorem for \"" ^
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   142
        Syntax.string_of_term (Context.proof_of context) c ^ "\".");
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   143
      context
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   144
    )
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   145
  end
2650
e5fa8de0e4bd derived equivariance for the function graph and function relation
Christian Urban <urbanc@in.tum.de>
parents: 2568
diff changeset
   146
1953
186d8486dfd5 rewrote eqvts_raw to be a symtab, that can be looked up
Christian Urban <urbanc@in.tum.de>
parents: 1947
diff changeset
   147
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   148
(** adding/deleting lemmas to/from "eqvts" **)
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   149
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   150
fun add_thm thm context =
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   151
  (
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   152
    if Item_Net.member (EqvtData.get context) thm then
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   153
      warning ("Theorem already declared as equivariant:\n" ^
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   154
        Syntax.string_of_term (Context.proof_of context) (prop_of thm))
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   155
    else ();
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   156
    EqvtData.map (Item_Net.update thm) context
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   157
  )
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   158
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   159
fun del_thm thm context =
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   160
  (
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   161
    if Item_Net.member (EqvtData.get context) thm then
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   162
      EqvtData.map (Item_Net.remove thm) context
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   163
    else (
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   164
      warning ("Cannot delete non-existing equivariance theorem:\n" ^
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   165
        Syntax.string_of_term (Context.proof_of context) (prop_of thm));
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   166
      context
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   167
    )
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   168
  )
1953
186d8486dfd5 rewrote eqvts_raw to be a symtab, that can be looked up
Christian Urban <urbanc@in.tum.de>
parents: 1947
diff changeset
   169
1870
55b2da92ff2f tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents: 1846
diff changeset
   170
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   171
(** transformation of equivariance lemmas **)
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   172
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   173
(* Transforms a theorem of the form (1) into the form (4). *)
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   174
local
1870
55b2da92ff2f tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents: 1846
diff changeset
   175
3218
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3214
diff changeset
   176
fun tac ctxt thm =
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   177
  let
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   178
    val ss_thms = @{thms "permute_minus_cancel" "permute_prod.simps" "split_paired_all"}
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   179
  in
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   180
    REPEAT o FIRST'
3218
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3214
diff changeset
   181
      [CHANGED o simp_tac (put_simpset HOL_basic_ss ctxt addsimps ss_thms),
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   182
       rtac (thm RS @{thm "trans"}),
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   183
       rtac @{thm "trans"[OF "permute_fun_def"]} THEN' rtac @{thm "ext"}]
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   184
  end
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   185
1841
fcc660ece040 thmdecls can deal with lemmas like alpha_gen which contain pairs or tuples
Christian Urban <urbanc@in.tum.de>
parents: 1835
diff changeset
   186
in
1947
51f411b1197d tuned and cleaned
Christian Urban <urbanc@in.tum.de>
parents: 1870
diff changeset
   187
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   188
fun thm_4_of_1 ctxt thm =
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   189
  let
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   190
    val (p, c) = thm |> prop_of |> HOLogic.dest_Trueprop
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   191
      |> HOLogic.dest_eq |> fst |> dest_perm ||> fst o (fixed_nonfixed_args ctxt)
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   192
    val goal = HOLogic.mk_Trueprop (HOLogic.mk_eq (mk_perm p c, c))
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   193
    val ([goal', p'], ctxt') = Variable.import_terms false [goal, p] ctxt
2477
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2200
diff changeset
   194
  in
3218
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3214
diff changeset
   195
    Goal.prove ctxt [] [] goal' (fn {context, ...} => tac context thm 1)
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   196
      |> singleton (Proof_Context.export ctxt' ctxt)
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   197
      |> (fn th => th RS @{thm "eq_reflection"})
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   198
      |> zero_var_indexes
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   199
  end
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   200
  handle TERM _ =>
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   201
    raise THM ("thm_4_of_1", 0, [thm])
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   202
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   203
end (* local *)
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   204
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   205
(* Transforms a theorem of the form (2) into the form (1). *)
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   206
local
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   207
3218
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3214
diff changeset
   208
fun tac ctxt thm thm' =
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   209
  let
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   210
    val ss_thms = @{thms "permute_minus_cancel"(2)}
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   211
  in
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   212
    EVERY' [rtac @{thm "iffI"}, dtac @{thm "permute_boolE"}, rtac thm, atac,
3218
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3214
diff changeset
   213
      rtac @{thm "permute_boolI"}, dtac thm', 
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3214
diff changeset
   214
      full_simp_tac (put_simpset HOL_basic_ss ctxt addsimps ss_thms)]
2477
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2200
diff changeset
   215
  end
1811
ae176476b525 implemented in thmdecls the case where eqvt-lemmas are of the form _ ==> _
Christian Urban <urbanc@in.tum.de>
parents: 1810
diff changeset
   216
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   217
in
1870
55b2da92ff2f tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents: 1846
diff changeset
   218
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   219
fun thm_1_of_2 ctxt thm =
2477
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2200
diff changeset
   220
  let
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   221
    val (prem, concl) = thm |> prop_of |> Logic.dest_implies |> pairself HOLogic.dest_Trueprop
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   222
    (* since argument terms "?p \<bullet> ?x1" may actually be eta-expanded
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   223
       or tuples, we need the following function to find ?p *)
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   224
    fun find_perm (Const (@{const_name "permute"}, _) $ (p as Var _) $ _) = p
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   225
      | find_perm (Const (@{const_name "Pair"}, _) $ x $ _) = find_perm x
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   226
      | find_perm (Abs (_, _, body)) = find_perm body
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   227
      | find_perm _ = raise THM ("thm_3_of_2", 0, [thm])
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   228
    val p = concl |> dest_comb |> snd |> find_perm
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   229
    val goal = HOLogic.mk_Trueprop (HOLogic.mk_eq (mk_perm p prem, concl))
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   230
    val ([goal', p'], ctxt') = Variable.import_terms false [goal, p] ctxt
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   231
    val certify = cterm_of (theory_of_thm thm)
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   232
    val thm' = Drule.cterm_instantiate [(certify p, certify (mk_minus p'))] thm
2477
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2200
diff changeset
   233
  in
3218
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3214
diff changeset
   234
    Goal.prove ctxt' [] [] goal' (fn {context, ...} => tac context thm thm' 1)
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   235
      |> singleton (Proof_Context.export ctxt' ctxt)
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   236
  end
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   237
  handle TERM _ =>
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   238
    raise THM ("thm_1_of_2", 0, [thm])
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   239
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   240
end (* local *)
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   241
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   242
(* Transforms a theorem of the form (1) into the form (3). *)
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   243
fun thm_3_of_1 _ thm =
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   244
  (thm RS (@{thm "permute_bool_def"} RS @{thm "sym"} RS @{thm "trans"}) RS @{thm "sym"})
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   245
    |> zero_var_indexes
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   246
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   247
local
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   248
  val msg = cat_lines
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   249
    ["Equivariance theorem must be of the form",
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   250
     "  ?p \<bullet> (c ?x1 ?x2 ...) = c (?p \<bullet> ?x1) (?p \<bullet> ?x2) ...",
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   251
     "or, if c is a relation with arity >= 1, of the form",
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   252
     "  c ?x1 ?x2 ... ==> c (?p \<bullet> ?x1) (?p \<bullet> ?x2) ..."]
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   253
in
1811
ae176476b525 implemented in thmdecls the case where eqvt-lemmas are of the form _ ==> _
Christian Urban <urbanc@in.tum.de>
parents: 1810
diff changeset
   254
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   255
(* Transforms a theorem of the form (1) or (2) into the form (4). *)
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   256
fun eqvt_transform ctxt thm =
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   257
  (case prop_of thm of @{const "Trueprop"} $ _ =>
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   258
    thm_4_of_1 ctxt thm
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   259
  | @{const "==>"} $ _ $ _ =>
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   260
    thm_4_of_1 ctxt (thm_1_of_2 ctxt thm)
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   261
  | _ =>
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   262
    error msg)
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   263
  handle THM _ =>
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   264
    error msg
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   265
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   266
(* Transforms a theorem of the form (1) into theorems of the
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   267
   form (1) (or, if c is a relation with arity >= 1, of the form
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   268
   (3)) and (4); transforms a theorem of the form (2) into
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   269
   theorems of the form (3) and (4). *)
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   270
fun eqvt_and_raw_transform ctxt thm =
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   271
  (case prop_of thm of @{const "Trueprop"} $ (Const (@{const_name "HOL.eq"}, _) $ _ $ c_args) =>
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   272
    let
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   273
      val th' =
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   274
        if fastype_of c_args = @{typ "bool"}
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   275
            andalso (not o null) (snd (fixed_nonfixed_args ctxt c_args)) then
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   276
          thm_3_of_1 ctxt thm
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   277
        else
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   278
          thm
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   279
    in
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   280
      (th', thm_4_of_1 ctxt thm)
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   281
    end
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   282
  | @{const "==>"} $ _ $ _ =>
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   283
    let
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   284
      val th1 = thm_1_of_2 ctxt thm
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   285
    in
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   286
      (thm_3_of_1 ctxt th1, thm_4_of_1 ctxt th1)
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   287
    end
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   288
  | _ =>
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   289
    error msg)
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   290
  handle THM _ =>
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   291
    error msg
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   292
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   293
end (* local *)
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   294
1870
55b2da92ff2f tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents: 1846
diff changeset
   295
55b2da92ff2f tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents: 1846
diff changeset
   296
(** attributes **)
947
fa810f01f7b5 added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   297
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   298
val eqvt_raw_add = Thm.declaration_attribute add_raw_thm
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   299
val eqvt_raw_del = Thm.declaration_attribute del_raw_thm
1870
55b2da92ff2f tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents: 1846
diff changeset
   300
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   301
fun eqvt_add_or_del eqvt_fn raw_fn =
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   302
  Thm.declaration_attribute
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   303
    (fn thm => fn context =>
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   304
      let
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   305
        val (eqvt, raw) = eqvt_and_raw_transform (Context.proof_of context) thm
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   306
      in
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   307
        context |> eqvt_fn eqvt |> raw_fn raw
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   308
      end)
947
fa810f01f7b5 added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   309
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   310
val eqvt_add = eqvt_add_or_del add_thm add_raw_thm
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   311
val eqvt_del = eqvt_add_or_del del_thm del_raw_thm
947
fa810f01f7b5 added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   312
1870
55b2da92ff2f tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents: 1846
diff changeset
   313
55b2da92ff2f tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents: 1846
diff changeset
   314
(** setup function **)
55b2da92ff2f tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents: 1846
diff changeset
   315
947
fa810f01f7b5 added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   316
val setup =
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   317
  Attrib.setup @{binding "eqvt"} (Attrib.add_del eqvt_add eqvt_del)
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   318
    "Declaration of equivariance lemmas - they will automatically be brought into the form ?p \<bullet> c \<equiv> c" #>
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   319
  Attrib.setup @{binding "eqvt_raw"} (Attrib.add_del eqvt_raw_add eqvt_raw_del)
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   320
    "Declaration of raw equivariance lemmas - no transformation is performed" #>
2484
594f3401605f updated to Isabelle 22 Sept
Christian Urban <urbanc@in.tum.de>
parents: 2478
diff changeset
   321
  Global_Theory.add_thms_dynamic (@{binding "eqvts"}, eqvts) #>
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   322
  Global_Theory.add_thms_dynamic (@{binding "eqvts_raw"}, eqvts_raw)
1066
96651cddeba9 eqvts and eqvts_raw are separate thm-lists; otherwise permute_eqvt is problematic as it causes looks in eqvts
Christian Urban <urbanc@in.tum.de>
parents: 1059
diff changeset
   323
947
fa810f01f7b5 added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   324
end;