Nominal/nominal_thmdecls.ML
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Tue, 22 Mar 2016 12:18:30 +0000
changeset 3244 a44479bde681
parent 3239 67370521c09c
permissions -rw-r--r--
fixed a problem with two example theories
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
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
    65
  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
    66
  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
    67
  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
    68
  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
    69
end;
fa810f01f7b5 added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
1037
2845e736dc1a added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents: 947
diff changeset
    71
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
    72
struct
fa810f01f7b5 added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
1037
2845e736dc1a added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents: 947
diff changeset
    74
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
    75
( 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
    76
  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
    77
  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
    78
  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
    79
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    80
(* EqvtRawData is implemented with a Termtab (rather than an
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    81
   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
    82
   constant has a corresponding equivariance theorem stored, cf.
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    83
   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
    84
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
    85
( 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
    86
  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
    87
  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
    88
  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
    89
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    90
val eqvts = Item_Net.content o EqvtData.get
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    91
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
    92
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3233
diff changeset
    93
val _ =
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3233
diff changeset
    94
  Theory.setup
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3233
diff changeset
    95
   (Global_Theory.add_thms_dynamic (@{binding "eqvts"}, eqvts) #>
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3233
diff changeset
    96
    Global_Theory.add_thms_dynamic (@{binding "eqvts_raw"}, eqvts_raw))
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3233
diff changeset
    97
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    98
val get_eqvts_thms = eqvts o Context.Proof
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
    99
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
   100
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
   101
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   102
(** 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
   103
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   104
(* 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
   105
   for a given term. *)
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   106
val is_eqvt =
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   107
  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
   108
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   109
(* 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
   110
   otherwise. *)
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   111
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
   112
  let
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   113
    fun error_msg () =
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   114
      error
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   115
        ("Theorem must be of the form \"?p \<bullet> c \<equiv> c\", with c a constant or fixed parameter:\n" ^
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3233
diff changeset
   116
         Syntax.string_of_term (Context.proof_of context) (Thm.prop_of thm))
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   117
  in
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3233
diff changeset
   118
    case Thm.prop_of thm of
3233
9ae285ce814e updated changes from upstream (AFP)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3231
diff changeset
   119
      Const (@{const_name Pure.eq}, _) $ (Const (@{const_name "permute"}, _) $ p $ c) $ c' =>
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   120
        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
   121
          c
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   122
        else
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   123
          error_msg ()
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   124
    | _ => error_msg ()
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   125
  end
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   126
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   127
fun add_raw_thm thm context =
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   128
  let
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   129
    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
   130
  in
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   131
    if Termtab.defined (EqvtRawData.get context) c then
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   132
      warning ("Replacing existing raw equivariance theorem for \"" ^
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   133
        Syntax.string_of_term (Context.proof_of context) c ^ "\".")
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   134
    else ();
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   135
    EqvtRawData.map (Termtab.update (c, thm)) context
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   136
  end
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   137
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   138
fun del_raw_thm thm context =
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   139
  let
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   140
    val c = key_of_raw_thm context thm
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   141
  in
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   142
    if Termtab.defined (EqvtRawData.get context) c then
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   143
      EqvtRawData.map (Termtab.delete c) context
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   144
    else (
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   145
      warning ("Cannot delete non-existing raw equivariance theorem for \"" ^
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   146
        Syntax.string_of_term (Context.proof_of context) c ^ "\".");
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   147
      context
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   148
    )
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   149
  end
2650
e5fa8de0e4bd derived equivariance for the function graph and function relation
Christian Urban <urbanc@in.tum.de>
parents: 2568
diff changeset
   150
1953
186d8486dfd5 rewrote eqvts_raw to be a symtab, that can be looked up
Christian Urban <urbanc@in.tum.de>
parents: 1947
diff changeset
   151
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   152
(** adding/deleting lemmas to/from "eqvts" **)
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   153
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   154
fun add_thm thm context =
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   155
  (
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   156
    if Item_Net.member (EqvtData.get context) thm then
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   157
      warning ("Theorem already declared as equivariant:\n" ^
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3233
diff changeset
   158
        Syntax.string_of_term (Context.proof_of context) (Thm.prop_of thm))
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   159
    else ();
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   160
    EqvtData.map (Item_Net.update thm) context
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   161
  )
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   162
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   163
fun del_thm thm context =
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   164
  (
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   165
    if Item_Net.member (EqvtData.get context) thm then
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   166
      EqvtData.map (Item_Net.remove thm) context
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   167
    else (
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   168
      warning ("Cannot delete non-existing equivariance theorem:\n" ^
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3233
diff changeset
   169
        Syntax.string_of_term (Context.proof_of context) (Thm.prop_of thm));
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   170
      context
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   171
    )
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   172
  )
1953
186d8486dfd5 rewrote eqvts_raw to be a symtab, that can be looked up
Christian Urban <urbanc@in.tum.de>
parents: 1947
diff changeset
   173
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
   174
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   175
(** transformation of equivariance lemmas **)
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   176
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   177
(* 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
   178
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
   179
3218
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3214
diff changeset
   180
fun tac ctxt thm =
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   181
  let
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   182
    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
   183
  in
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   184
    REPEAT o FIRST'
3218
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3214
diff changeset
   185
      [CHANGED o simp_tac (put_simpset HOL_basic_ss ctxt addsimps ss_thms),
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   186
       resolve_tac ctxt [thm RS @{thm trans}],
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   187
       resolve_tac ctxt @{thms trans[OF "permute_fun_def"]} THEN'
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   188
       resolve_tac ctxt @{thms ext}]
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   189
  end
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   190
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
   191
in
1947
51f411b1197d tuned and cleaned
Christian Urban <urbanc@in.tum.de>
parents: 1870
diff changeset
   192
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   193
fun thm_4_of_1 ctxt thm =
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   194
  let
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3233
diff changeset
   195
    val (p, c) = thm |> Thm.prop_of |> HOLogic.dest_Trueprop
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   196
      |> 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
   197
    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
   198
    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
   199
  in
3218
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3214
diff changeset
   200
    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
   201
      |> singleton (Proof_Context.export ctxt' ctxt)
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   202
      |> (fn th => th RS @{thm "eq_reflection"})
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   203
      |> zero_var_indexes
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   204
  end
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   205
  handle TERM _ =>
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   206
    raise THM ("thm_4_of_1", 0, [thm])
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   207
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   208
end (* local *)
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   209
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   210
(* 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
   211
local
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   212
3218
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3214
diff changeset
   213
fun tac ctxt thm thm' =
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   214
  let
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   215
    val ss_thms = @{thms "permute_minus_cancel"(2)}
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   216
  in
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   217
    EVERY' [resolve_tac ctxt @{thms iffI},
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   218
      dresolve_tac ctxt @{thms permute_boolE},
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   219
      resolve_tac ctxt [thm],
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   220
      assume_tac ctxt,
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   221
      resolve_tac ctxt @{thms permute_boolI},
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   222
      dresolve_tac ctxt [thm'],
3218
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3214
diff changeset
   223
      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
   224
  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
   225
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   226
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
   227
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   228
fun thm_1_of_2 ctxt thm =
2477
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2200
diff changeset
   229
  let
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3233
diff changeset
   230
    val (prem, concl) = thm |> Thm.prop_of |> Logic.dest_implies |> apply2 HOLogic.dest_Trueprop
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   231
    (* 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
   232
       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
   233
    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
   234
      | 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
   235
      | find_perm (Abs (_, _, body)) = find_perm body
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   236
      | 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
   237
    val p = concl |> dest_comb |> snd |> find_perm
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   238
    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
   239
    val ([goal', p'], ctxt') = Variable.import_terms false [goal, p] ctxt
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   240
    val thm' = infer_instantiate ctxt' [(#1 (dest_Var p), Thm.cterm_of ctxt' (mk_minus p'))] thm
2477
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2200
diff changeset
   241
  in
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3233
diff changeset
   242
    Goal.prove ctxt' [] [] goal' (fn {context = ctxt'', ...} => tac ctxt'' thm thm' 1)
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   243
      |> singleton (Proof_Context.export ctxt' ctxt)
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   244
  end
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   245
  handle TERM _ =>
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   246
    raise THM ("thm_1_of_2", 0, [thm])
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   247
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   248
end (* local *)
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   249
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   250
(* 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
   251
fun thm_3_of_1 _ thm =
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   252
  (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
   253
    |> zero_var_indexes
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   254
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   255
local
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   256
  val msg = cat_lines
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   257
    ["Equivariance theorem must be of the form",
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   258
     "  ?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
   259
     "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
   260
     "  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
   261
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
   262
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   263
(* 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
   264
fun eqvt_transform ctxt thm =
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3233
diff changeset
   265
  (case Thm.prop_of thm of @{const "Trueprop"} $ _ =>
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   266
    thm_4_of_1 ctxt thm
3233
9ae285ce814e updated changes from upstream (AFP)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3231
diff changeset
   267
  | @{const Pure.imp} $ _ $ _ =>
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   268
    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
   269
  | _ =>
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   270
    error msg)
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   271
  handle THM _ =>
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   272
    error msg
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   273
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   274
(* 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
   275
   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
   276
   (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
   277
   theorems of the form (3) and (4). *)
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   278
fun eqvt_and_raw_transform ctxt thm =
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3233
diff changeset
   279
  (case Thm.prop_of thm of @{const "Trueprop"} $ (Const (@{const_name "HOL.eq"}, _) $ _ $ c_args) =>
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   280
    let
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   281
      val th' =
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   282
        if fastype_of c_args = @{typ "bool"}
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   283
            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
   284
          thm_3_of_1 ctxt thm
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   285
        else
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   286
          thm
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   287
    in
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   288
      (th', thm_4_of_1 ctxt thm)
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   289
    end
3233
9ae285ce814e updated changes from upstream (AFP)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3231
diff changeset
   290
  | @{const Pure.imp} $ _ $ _ =>
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   291
    let
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   292
      val th1 = thm_1_of_2 ctxt thm
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   293
    in
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   294
      (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
   295
    end
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   296
  | _ =>
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   297
    error msg)
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   298
  handle THM _ =>
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   299
    error msg
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   300
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   301
end (* local *)
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   302
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
   303
55b2da92ff2f tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents: 1846
diff changeset
   304
(** attributes **)
947
fa810f01f7b5 added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   305
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   306
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
   307
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
   308
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   309
fun eqvt_add_or_del eqvt_fn raw_fn =
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   310
  Thm.declaration_attribute
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   311
    (fn thm => fn context =>
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   312
      let
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   313
        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
   314
      in
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   315
        context |> eqvt_fn eqvt |> raw_fn raw
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   316
      end)
947
fa810f01f7b5 added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   317
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3045
diff changeset
   318
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
   319
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
   320
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3233
diff changeset
   321
val _ =
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3233
diff changeset
   322
  Theory.setup
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3233
diff changeset
   323
   (Attrib.setup @{binding "eqvt"} (Attrib.add_del eqvt_add eqvt_del)
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3233
diff changeset
   324
      "Declaration of equivariance lemmas - they will automatically be brought into the form ?p \<bullet> c \<equiv> c" #>
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3233
diff changeset
   325
    Attrib.setup @{binding "eqvt_raw"} (Attrib.add_del eqvt_raw_add eqvt_raw_del)
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3233
diff changeset
   326
      "Declaration of raw equivariance lemmas - no transformation is performed")
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
   327
947
fa810f01f7b5 added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   328
end;