Nominal/nominal_permeq.ML
author Christian Urban <urbanc@in.tum.de>
Sun, 09 Jan 2011 01:17:44 +0000
changeset 2653 d0f774d06e6e
parent 2610 f5c7375ab465
child 2765 7ac5e5c86c7d
permissions -rw-r--r--
added eqvt_at premises in function definition - however not proved at the moment
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1801
6d2a39db3862 added more robust tracing infrastructure; a strict version of the eqvt_tac raises an error if not all permutations cannot be analysed
Christian Urban <urbanc@in.tum.de>
parents: 1800
diff changeset
     1
(*  Title:      nominal_permeq.ML
6d2a39db3862 added more robust tracing infrastructure; a strict version of the eqvt_tac raises an error if not all permutations cannot be analysed
Christian Urban <urbanc@in.tum.de>
parents: 1800
diff changeset
     2
    Author:     Christian Urban
6d2a39db3862 added more robust tracing infrastructure; a strict version of the eqvt_tac raises an error if not all permutations cannot be analysed
Christian Urban <urbanc@in.tum.de>
parents: 1800
diff changeset
     3
    Author:     Brian Huffman
1037
2845e736dc1a added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
*)
2845e736dc1a added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
2845e736dc1a added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
signature NOMINAL_PERMEQ =
2845e736dc1a added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
sig
2610
f5c7375ab465 added theorem-rewriter conversion
Christian Urban <urbanc@in.tum.de>
parents: 2568
diff changeset
     8
  val eqvt_rule: Proof.context -> thm list -> string list -> thm -> thm
f5c7375ab465 added theorem-rewriter conversion
Christian Urban <urbanc@in.tum.de>
parents: 2568
diff changeset
     9
  val eqvt_strict_rule: Proof.context -> thm list -> string list -> thm -> thm
f5c7375ab465 added theorem-rewriter conversion
Christian Urban <urbanc@in.tum.de>
parents: 2568
diff changeset
    10
1801
6d2a39db3862 added more robust tracing infrastructure; a strict version of the eqvt_tac raises an error if not all permutations cannot be analysed
Christian Urban <urbanc@in.tum.de>
parents: 1800
diff changeset
    11
  val eqvt_tac: Proof.context -> thm list -> string list -> int -> tactic
6d2a39db3862 added more robust tracing infrastructure; a strict version of the eqvt_tac raises an error if not all permutations cannot be analysed
Christian Urban <urbanc@in.tum.de>
parents: 1800
diff changeset
    12
  val eqvt_strict_tac: Proof.context -> thm list -> string list -> int -> tactic
1947
51f411b1197d tuned and cleaned
Christian Urban <urbanc@in.tum.de>
parents: 1866
diff changeset
    13
  
51f411b1197d tuned and cleaned
Christian Urban <urbanc@in.tum.de>
parents: 1866
diff changeset
    14
  val perm_simp_meth: thm list * string list -> Proof.context -> Method.method
51f411b1197d tuned and cleaned
Christian Urban <urbanc@in.tum.de>
parents: 1866
diff changeset
    15
  val perm_strict_simp_meth: thm list * string list -> Proof.context -> Method.method
51f411b1197d tuned and cleaned
Christian Urban <urbanc@in.tum.de>
parents: 1866
diff changeset
    16
  val args_parser: (thm list * string list) context_parser
51f411b1197d tuned and cleaned
Christian Urban <urbanc@in.tum.de>
parents: 1866
diff changeset
    17
1800
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1774
diff changeset
    18
  val trace_eqvt: bool Config.T
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1774
diff changeset
    19
  val setup: theory -> theory
1037
2845e736dc1a added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
end;
2845e736dc1a added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
1801
6d2a39db3862 added more robust tracing infrastructure; a strict version of the eqvt_tac raises an error if not all permutations cannot be analysed
Christian Urban <urbanc@in.tum.de>
parents: 1800
diff changeset
    22
(* 
6d2a39db3862 added more robust tracing infrastructure; a strict version of the eqvt_tac raises an error if not all permutations cannot be analysed
Christian Urban <urbanc@in.tum.de>
parents: 1800
diff changeset
    23
6d2a39db3862 added more robust tracing infrastructure; a strict version of the eqvt_tac raises an error if not all permutations cannot be analysed
Christian Urban <urbanc@in.tum.de>
parents: 1800
diff changeset
    24
- eqvt_tac and eqvt_strict_tac take a list of theorems
6d2a39db3862 added more robust tracing infrastructure; a strict version of the eqvt_tac raises an error if not all permutations cannot be analysed
Christian Urban <urbanc@in.tum.de>
parents: 1800
diff changeset
    25
  which are first tried to simplify permutations
6d2a39db3862 added more robust tracing infrastructure; a strict version of the eqvt_tac raises an error if not all permutations cannot be analysed
Christian Urban <urbanc@in.tum.de>
parents: 1800
diff changeset
    26
6d2a39db3862 added more robust tracing infrastructure; a strict version of the eqvt_tac raises an error if not all permutations cannot be analysed
Christian Urban <urbanc@in.tum.de>
parents: 1800
diff changeset
    27
  the string list contains constants that should not be
6d2a39db3862 added more robust tracing infrastructure; a strict version of the eqvt_tac raises an error if not all permutations cannot be analysed
Christian Urban <urbanc@in.tum.de>
parents: 1800
diff changeset
    28
  analysed (for example there is no raw eqvt-lemma for
2080
0532006ec7ec added eqvt-lemma for split; changed semantics of perm_simp: excluded stands for constants about which no complaint is written out...eqvt_apply is now always applied
Christian Urban <urbanc@in.tum.de>
parents: 2069
diff changeset
    29
  the constant The); therefore it should not be analysed 
1037
2845e736dc1a added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
1801
6d2a39db3862 added more robust tracing infrastructure; a strict version of the eqvt_tac raises an error if not all permutations cannot be analysed
Christian Urban <urbanc@in.tum.de>
parents: 1800
diff changeset
    31
- setting [[trace_eqvt = true]] switches on tracing 
6d2a39db3862 added more robust tracing infrastructure; a strict version of the eqvt_tac raises an error if not all permutations cannot be analysed
Christian Urban <urbanc@in.tum.de>
parents: 1800
diff changeset
    32
  information  
6d2a39db3862 added more robust tracing infrastructure; a strict version of the eqvt_tac raises an error if not all permutations cannot be analysed
Christian Urban <urbanc@in.tum.de>
parents: 1800
diff changeset
    33
1037
2845e736dc1a added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
*)
2845e736dc1a added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
2845e736dc1a added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
structure Nominal_Permeq: NOMINAL_PERMEQ =
2845e736dc1a added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
struct
2845e736dc1a added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
1801
6d2a39db3862 added more robust tracing infrastructure; a strict version of the eqvt_tac raises an error if not all permutations cannot be analysed
Christian Urban <urbanc@in.tum.de>
parents: 1800
diff changeset
    39
open Nominal_ThmDecls;
1800
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1774
diff changeset
    40
1801
6d2a39db3862 added more robust tracing infrastructure; a strict version of the eqvt_tac raises an error if not all permutations cannot be analysed
Christian Urban <urbanc@in.tum.de>
parents: 1800
diff changeset
    41
(* tracing infrastructure *)
1800
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1774
diff changeset
    42
val (trace_eqvt, trace_eqvt_setup) = Attrib.config_bool "trace_eqvt" (K false);
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1774
diff changeset
    43
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1774
diff changeset
    44
fun trace_enabled ctxt = Config.get ctxt trace_eqvt
1037
2845e736dc1a added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
1801
6d2a39db3862 added more robust tracing infrastructure; a strict version of the eqvt_tac raises an error if not all permutations cannot be analysed
Christian Urban <urbanc@in.tum.de>
parents: 1800
diff changeset
    46
fun trace_msg ctxt result = 
2477
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
    47
  let
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
    48
    val lhs_str = Syntax.string_of_term ctxt (term_of (Thm.lhs_of result))
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
    49
    val rhs_str = Syntax.string_of_term ctxt (term_of (Thm.rhs_of result))
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
    50
  in
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
    51
    warning (Pretty.string_of (Pretty.strs ["Rewriting", lhs_str, "to", rhs_str]))
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
    52
  end
1801
6d2a39db3862 added more robust tracing infrastructure; a strict version of the eqvt_tac raises an error if not all permutations cannot be analysed
Christian Urban <urbanc@in.tum.de>
parents: 1800
diff changeset
    53
6d2a39db3862 added more robust tracing infrastructure; a strict version of the eqvt_tac raises an error if not all permutations cannot be analysed
Christian Urban <urbanc@in.tum.de>
parents: 1800
diff changeset
    54
fun trace_conv ctxt conv ctrm =
2477
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
    55
  let
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
    56
    val result = conv ctrm
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
    57
  in
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
    58
    if Thm.is_reflexive result 
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
    59
    then result
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
    60
    else (trace_msg ctxt result; result)
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
    61
  end
1801
6d2a39db3862 added more robust tracing infrastructure; a strict version of the eqvt_tac raises an error if not all permutations cannot be analysed
Christian Urban <urbanc@in.tum.de>
parents: 1800
diff changeset
    62
6d2a39db3862 added more robust tracing infrastructure; a strict version of the eqvt_tac raises an error if not all permutations cannot be analysed
Christian Urban <urbanc@in.tum.de>
parents: 1800
diff changeset
    63
(* this conversion always fails, but prints 
6d2a39db3862 added more robust tracing infrastructure; a strict version of the eqvt_tac raises an error if not all permutations cannot be analysed
Christian Urban <urbanc@in.tum.de>
parents: 1800
diff changeset
    64
   out the analysed term  *)
6d2a39db3862 added more robust tracing infrastructure; a strict version of the eqvt_tac raises an error if not all permutations cannot be analysed
Christian Urban <urbanc@in.tum.de>
parents: 1800
diff changeset
    65
fun trace_info_conv ctxt ctrm = 
2477
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
    66
  let
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
    67
    val trm = term_of ctrm
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
    68
    val _ = case (head_of trm) of 
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
    69
        @{const "Trueprop"} => ()
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
    70
      | _ => warning ("Analysing term " ^ Syntax.string_of_term ctxt trm)
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
    71
  in
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
    72
    Conv.no_conv ctrm
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
    73
  end
1801
6d2a39db3862 added more robust tracing infrastructure; a strict version of the eqvt_tac raises an error if not all permutations cannot be analysed
Christian Urban <urbanc@in.tum.de>
parents: 1800
diff changeset
    74
2080
0532006ec7ec added eqvt-lemma for split; changed semantics of perm_simp: excluded stands for constants about which no complaint is written out...eqvt_apply is now always applied
Christian Urban <urbanc@in.tum.de>
parents: 2069
diff changeset
    75
(* conversion for applications *)
0532006ec7ec added eqvt-lemma for split; changed semantics of perm_simp: excluded stands for constants about which no complaint is written out...eqvt_apply is now always applied
Christian Urban <urbanc@in.tum.de>
parents: 2069
diff changeset
    76
fun eqvt_apply_conv ctrm =
1801
6d2a39db3862 added more robust tracing infrastructure; a strict version of the eqvt_tac raises an error if not all permutations cannot be analysed
Christian Urban <urbanc@in.tum.de>
parents: 1800
diff changeset
    77
  case (term_of ctrm) of
2080
0532006ec7ec added eqvt-lemma for split; changed semantics of perm_simp: excluded stands for constants about which no complaint is written out...eqvt_apply is now always applied
Christian Urban <urbanc@in.tum.de>
parents: 2069
diff changeset
    78
    Const (@{const_name "permute"}, _) $ _ $ (_ $ _) =>
1800
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1774
diff changeset
    79
      let
1801
6d2a39db3862 added more robust tracing infrastructure; a strict version of the eqvt_tac raises an error if not all permutations cannot be analysed
Christian Urban <urbanc@in.tum.de>
parents: 1800
diff changeset
    80
        val (perm, t) = Thm.dest_comb ctrm
1037
2845e736dc1a added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
        val (_, p) = Thm.dest_comb perm
2845e736dc1a added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
        val (f, x) = Thm.dest_comb t
2845e736dc1a added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
        val a = ctyp_of_term x;
2845e736dc1a added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
        val b = ctyp_of_term t;
2845e736dc1a added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
        val ty_insts = map SOME [b, a]
1800
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1774
diff changeset
    86
        val term_insts = map SOME [p, f, x]                        
1037
2845e736dc1a added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
      in
2080
0532006ec7ec added eqvt-lemma for split; changed semantics of perm_simp: excluded stands for constants about which no complaint is written out...eqvt_apply is now always applied
Christian Urban <urbanc@in.tum.de>
parents: 2069
diff changeset
    88
        Drule.instantiate' ty_insts term_insts @{thm eqvt_apply}
1037
2845e736dc1a added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
      end
1801
6d2a39db3862 added more robust tracing infrastructure; a strict version of the eqvt_tac raises an error if not all permutations cannot be analysed
Christian Urban <urbanc@in.tum.de>
parents: 1800
diff changeset
    90
  | _ => Conv.no_conv ctrm
1037
2845e736dc1a added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
1800
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1774
diff changeset
    92
(* conversion for lambdas *)
1801
6d2a39db3862 added more robust tracing infrastructure; a strict version of the eqvt_tac raises an error if not all permutations cannot be analysed
Christian Urban <urbanc@in.tum.de>
parents: 1800
diff changeset
    93
fun eqvt_lambda_conv ctrm =
6d2a39db3862 added more robust tracing infrastructure; a strict version of the eqvt_tac raises an error if not all permutations cannot be analysed
Christian Urban <urbanc@in.tum.de>
parents: 1800
diff changeset
    94
  case (term_of ctrm) of
6d2a39db3862 added more robust tracing infrastructure; a strict version of the eqvt_tac raises an error if not all permutations cannot be analysed
Christian Urban <urbanc@in.tum.de>
parents: 1800
diff changeset
    95
    Const (@{const_name "permute"}, _) $ _ $ (Abs _) =>
6d2a39db3862 added more robust tracing infrastructure; a strict version of the eqvt_tac raises an error if not all permutations cannot be analysed
Christian Urban <urbanc@in.tum.de>
parents: 1800
diff changeset
    96
      Conv.rewr_conv @{thm eqvt_lambda} ctrm
6d2a39db3862 added more robust tracing infrastructure; a strict version of the eqvt_tac raises an error if not all permutations cannot be analysed
Christian Urban <urbanc@in.tum.de>
parents: 1800
diff changeset
    97
  | _ => Conv.no_conv ctrm
6d2a39db3862 added more robust tracing infrastructure; a strict version of the eqvt_tac raises an error if not all permutations cannot be analysed
Christian Urban <urbanc@in.tum.de>
parents: 1800
diff changeset
    98
2080
0532006ec7ec added eqvt-lemma for split; changed semantics of perm_simp: excluded stands for constants about which no complaint is written out...eqvt_apply is now always applied
Christian Urban <urbanc@in.tum.de>
parents: 2069
diff changeset
    99
1801
6d2a39db3862 added more robust tracing infrastructure; a strict version of the eqvt_tac raises an error if not all permutations cannot be analysed
Christian Urban <urbanc@in.tum.de>
parents: 1800
diff changeset
   100
(* conversion that raises an error or prints a warning message, 
6d2a39db3862 added more robust tracing infrastructure; a strict version of the eqvt_tac raises an error if not all permutations cannot be analysed
Christian Urban <urbanc@in.tum.de>
parents: 1800
diff changeset
   101
   if a permutation on a constant or application cannot be analysed *)
2080
0532006ec7ec added eqvt-lemma for split; changed semantics of perm_simp: excluded stands for constants about which no complaint is written out...eqvt_apply is now always applied
Christian Urban <urbanc@in.tum.de>
parents: 2069
diff changeset
   102
0532006ec7ec added eqvt-lemma for split; changed semantics of perm_simp: excluded stands for constants about which no complaint is written out...eqvt_apply is now always applied
Christian Urban <urbanc@in.tum.de>
parents: 2069
diff changeset
   103
fun is_excluded excluded (Const (a, _)) = member (op=) excluded a 
0532006ec7ec added eqvt-lemma for split; changed semantics of perm_simp: excluded stands for constants about which no complaint is written out...eqvt_apply is now always applied
Christian Urban <urbanc@in.tum.de>
parents: 2069
diff changeset
   104
  | is_excluded _ _ = false 
0532006ec7ec added eqvt-lemma for split; changed semantics of perm_simp: excluded stands for constants about which no complaint is written out...eqvt_apply is now always applied
Christian Urban <urbanc@in.tum.de>
parents: 2069
diff changeset
   105
0532006ec7ec added eqvt-lemma for split; changed semantics of perm_simp: excluded stands for constants about which no complaint is written out...eqvt_apply is now always applied
Christian Urban <urbanc@in.tum.de>
parents: 2069
diff changeset
   106
fun progress_info_conv ctxt strict_flag excluded ctrm =
2477
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
   107
  let
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
   108
    fun msg trm =
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
   109
      if is_excluded excluded trm then () else 
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
   110
        (if strict_flag then error else warning) 
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
   111
          ("Cannot solve equivariance for " ^ (Syntax.string_of_term ctxt trm))
1801
6d2a39db3862 added more robust tracing infrastructure; a strict version of the eqvt_tac raises an error if not all permutations cannot be analysed
Christian Urban <urbanc@in.tum.de>
parents: 1800
diff changeset
   112
2477
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
   113
    val _ = case (term_of ctrm) of
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
   114
        Const (@{const_name "permute"}, _) $ _ $ (trm as Const _) => msg trm
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
   115
      | Const (@{const_name "permute"}, _) $ _ $ (trm as _ $ _) => msg trm
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
   116
      | _ => () 
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
   117
  in
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
   118
    Conv.all_conv ctrm 
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
   119
  end
1037
2845e736dc1a added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
2064
2725853f43b9 solved the problem with equivariance by first eta-normalising the goal
Christian Urban <urbanc@in.tum.de>
parents: 1947
diff changeset
   121
(* main conversion *) 
2610
f5c7375ab465 added theorem-rewriter conversion
Christian Urban <urbanc@in.tum.de>
parents: 2568
diff changeset
   122
fun main_eqvt_conv ctxt strict_flag user_thms excluded ctrm =
2477
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
   123
  let
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
   124
    val first_conv_wrapper = 
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
   125
      if trace_enabled ctxt 
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
   126
      then Conv.first_conv o (cons (trace_info_conv ctxt)) o (map (trace_conv ctxt))
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
   127
      else Conv.first_conv
1801
6d2a39db3862 added more robust tracing infrastructure; a strict version of the eqvt_tac raises an error if not all permutations cannot be analysed
Christian Urban <urbanc@in.tum.de>
parents: 1800
diff changeset
   128
2477
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
   129
    val pre_thms = map safe_mk_equiv user_thms @ @{thms eqvt_bound} @ get_eqvts_raw_thms ctxt
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
   130
    val post_thms = map safe_mk_equiv @{thms permute_pure}
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
   131
  in
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
   132
    first_conv_wrapper
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
   133
      [ Conv.rewrs_conv pre_thms,
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
   134
        eqvt_apply_conv,
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
   135
        eqvt_lambda_conv,
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
   136
        Conv.rewrs_conv post_thms,
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
   137
        progress_info_conv ctxt strict_flag excluded
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
   138
      ] ctrm
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2301
diff changeset
   139
  end
1037
2845e736dc1a added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
2064
2725853f43b9 solved the problem with equivariance by first eta-normalising the goal
Christian Urban <urbanc@in.tum.de>
parents: 1947
diff changeset
   141
(* the eqvt-tactics first eta-normalise goals in 
2725853f43b9 solved the problem with equivariance by first eta-normalising the goal
Christian Urban <urbanc@in.tum.de>
parents: 1947
diff changeset
   142
   order to avoid problems with inductions in the
2610
f5c7375ab465 added theorem-rewriter conversion
Christian Urban <urbanc@in.tum.de>
parents: 2568
diff changeset
   143
   equivariance command. *)
2064
2725853f43b9 solved the problem with equivariance by first eta-normalising the goal
Christian Urban <urbanc@in.tum.de>
parents: 1947
diff changeset
   144
1801
6d2a39db3862 added more robust tracing infrastructure; a strict version of the eqvt_tac raises an error if not all permutations cannot be analysed
Christian Urban <urbanc@in.tum.de>
parents: 1800
diff changeset
   145
(* raises an error if some permutations cannot be eliminated *)
2610
f5c7375ab465 added theorem-rewriter conversion
Christian Urban <urbanc@in.tum.de>
parents: 2568
diff changeset
   146
fun eqvt_strict_conv ctxt user_thms excluded = 
f5c7375ab465 added theorem-rewriter conversion
Christian Urban <urbanc@in.tum.de>
parents: 2568
diff changeset
   147
  Conv.top_conv 
f5c7375ab465 added theorem-rewriter conversion
Christian Urban <urbanc@in.tum.de>
parents: 2568
diff changeset
   148
    (fn ctxt => Thm.eta_conversion then_conv (main_eqvt_conv ctxt true user_thms excluded)) ctxt
1800
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1774
diff changeset
   149
1801
6d2a39db3862 added more robust tracing infrastructure; a strict version of the eqvt_tac raises an error if not all permutations cannot be analysed
Christian Urban <urbanc@in.tum.de>
parents: 1800
diff changeset
   150
(* prints a warning message if some permutations cannot be eliminated *)
2610
f5c7375ab465 added theorem-rewriter conversion
Christian Urban <urbanc@in.tum.de>
parents: 2568
diff changeset
   151
fun eqvt_conv ctxt user_thms excluded = 
f5c7375ab465 added theorem-rewriter conversion
Christian Urban <urbanc@in.tum.de>
parents: 2568
diff changeset
   152
  Conv.top_conv 
f5c7375ab465 added theorem-rewriter conversion
Christian Urban <urbanc@in.tum.de>
parents: 2568
diff changeset
   153
    (fn ctxt => Thm.eta_conversion then_conv (main_eqvt_conv ctxt false user_thms excluded)) ctxt
f5c7375ab465 added theorem-rewriter conversion
Christian Urban <urbanc@in.tum.de>
parents: 2568
diff changeset
   154
f5c7375ab465 added theorem-rewriter conversion
Christian Urban <urbanc@in.tum.de>
parents: 2568
diff changeset
   155
f5c7375ab465 added theorem-rewriter conversion
Christian Urban <urbanc@in.tum.de>
parents: 2568
diff changeset
   156
(* thms rewriters *)
f5c7375ab465 added theorem-rewriter conversion
Christian Urban <urbanc@in.tum.de>
parents: 2568
diff changeset
   157
fun eqvt_strict_rule ctxt user_thms excluded = 
f5c7375ab465 added theorem-rewriter conversion
Christian Urban <urbanc@in.tum.de>
parents: 2568
diff changeset
   158
  Conv.fconv_rule (eqvt_strict_conv ctxt user_thms excluded)
f5c7375ab465 added theorem-rewriter conversion
Christian Urban <urbanc@in.tum.de>
parents: 2568
diff changeset
   159
f5c7375ab465 added theorem-rewriter conversion
Christian Urban <urbanc@in.tum.de>
parents: 2568
diff changeset
   160
fun eqvt_rule ctxt user_thms excluded = 
f5c7375ab465 added theorem-rewriter conversion
Christian Urban <urbanc@in.tum.de>
parents: 2568
diff changeset
   161
  Conv.fconv_rule (eqvt_conv ctxt user_thms excluded)
f5c7375ab465 added theorem-rewriter conversion
Christian Urban <urbanc@in.tum.de>
parents: 2568
diff changeset
   162
f5c7375ab465 added theorem-rewriter conversion
Christian Urban <urbanc@in.tum.de>
parents: 2568
diff changeset
   163
(* tactics *)
f5c7375ab465 added theorem-rewriter conversion
Christian Urban <urbanc@in.tum.de>
parents: 2568
diff changeset
   164
fun eqvt_strict_tac ctxt user_thms excluded = 
f5c7375ab465 added theorem-rewriter conversion
Christian Urban <urbanc@in.tum.de>
parents: 2568
diff changeset
   165
  CONVERSION (eqvt_strict_conv ctxt user_thms excluded)
f5c7375ab465 added theorem-rewriter conversion
Christian Urban <urbanc@in.tum.de>
parents: 2568
diff changeset
   166
2080
0532006ec7ec added eqvt-lemma for split; changed semantics of perm_simp: excluded stands for constants about which no complaint is written out...eqvt_apply is now always applied
Christian Urban <urbanc@in.tum.de>
parents: 2069
diff changeset
   167
fun eqvt_tac ctxt user_thms excluded = 
2610
f5c7375ab465 added theorem-rewriter conversion
Christian Urban <urbanc@in.tum.de>
parents: 2568
diff changeset
   168
  CONVERSION (eqvt_conv ctxt user_thms excluded)
1800
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1774
diff changeset
   169
1801
6d2a39db3862 added more robust tracing infrastructure; a strict version of the eqvt_tac raises an error if not all permutations cannot be analysed
Christian Urban <urbanc@in.tum.de>
parents: 1800
diff changeset
   170
(* setup of the configuration value *)
1800
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1774
diff changeset
   171
val setup =
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1774
diff changeset
   172
  trace_eqvt_setup
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1774
diff changeset
   173
1947
51f411b1197d tuned and cleaned
Christian Urban <urbanc@in.tum.de>
parents: 1866
diff changeset
   174
51f411b1197d tuned and cleaned
Christian Urban <urbanc@in.tum.de>
parents: 1866
diff changeset
   175
(** methods **)
2291
20ee31bc34d5 proper parser for "exclude:"
Christian Urban <urbanc@in.tum.de>
parents: 2150
diff changeset
   176
fun unless_more_args scan = Scan.unless (Scan.lift ((Args.$$$ "exclude") -- Args.colon)) scan
20ee31bc34d5 proper parser for "exclude:"
Christian Urban <urbanc@in.tum.de>
parents: 2150
diff changeset
   177
20ee31bc34d5 proper parser for "exclude:"
Christian Urban <urbanc@in.tum.de>
parents: 2150
diff changeset
   178
val add_thms_parser = Scan.optional (Scan.lift (Args.add -- Args.colon) |-- 
20ee31bc34d5 proper parser for "exclude:"
Christian Urban <urbanc@in.tum.de>
parents: 2150
diff changeset
   179
   Scan.repeat (unless_more_args Attrib.multi_thm) >> flat) [];
20ee31bc34d5 proper parser for "exclude:"
Christian Urban <urbanc@in.tum.de>
parents: 2150
diff changeset
   180
1947
51f411b1197d tuned and cleaned
Christian Urban <urbanc@in.tum.de>
parents: 1866
diff changeset
   181
val exclude_consts_parser = Scan.optional (Scan.lift ((Args.$$$ "exclude") -- Args.colon) |-- 
51f411b1197d tuned and cleaned
Christian Urban <urbanc@in.tum.de>
parents: 1866
diff changeset
   182
  (Scan.repeat (Args.const true))) []
51f411b1197d tuned and cleaned
Christian Urban <urbanc@in.tum.de>
parents: 1866
diff changeset
   183
2064
2725853f43b9 solved the problem with equivariance by first eta-normalising the goal
Christian Urban <urbanc@in.tum.de>
parents: 1947
diff changeset
   184
val args_parser =  add_thms_parser -- exclude_consts_parser 
1947
51f411b1197d tuned and cleaned
Christian Urban <urbanc@in.tum.de>
parents: 1866
diff changeset
   185
51f411b1197d tuned and cleaned
Christian Urban <urbanc@in.tum.de>
parents: 1866
diff changeset
   186
fun perm_simp_meth (thms, consts) ctxt = 
51f411b1197d tuned and cleaned
Christian Urban <urbanc@in.tum.de>
parents: 1866
diff changeset
   187
  SIMPLE_METHOD (HEADGOAL (eqvt_tac ctxt thms consts))
51f411b1197d tuned and cleaned
Christian Urban <urbanc@in.tum.de>
parents: 1866
diff changeset
   188
51f411b1197d tuned and cleaned
Christian Urban <urbanc@in.tum.de>
parents: 1866
diff changeset
   189
fun perm_strict_simp_meth (thms, consts) ctxt = 
51f411b1197d tuned and cleaned
Christian Urban <urbanc@in.tum.de>
parents: 1866
diff changeset
   190
  SIMPLE_METHOD (HEADGOAL (eqvt_strict_tac ctxt thms consts))
51f411b1197d tuned and cleaned
Christian Urban <urbanc@in.tum.de>
parents: 1866
diff changeset
   191
2069
2b6ba4d4e19a Fixes for new isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2064
diff changeset
   192
end; (* structure *)