src/HOL/Nominal/nominal_permeq.ML
author urbanc
Fri, 28 Oct 2005 16:43:46 +0200
changeset 18012 23e6cfda8c4b
parent 17870 c35381811d5c
child 18046 b7389981170b
permissions -rw-r--r--
Added (optional) arguments to the tactics perm_eq_simp and supports_simp. They now follow the "simp"-way and use the syntax: apply(supports_simp simp add: thms) etc.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
     1
(* $Id$ *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
     2
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
     3
(* METHOD FOR ANALYSING EQUATION INVOLVING PERMUTATION *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
     4
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
     5
(* tries until depth 40 the following (in that order):                     *)
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
     6
(*                                                                         *)
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
     7
(*  - simplification plus analysing perm_swaps, perm_fresh_fresh, perm_bij *)
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
     8
(*  - permutation compositions (on the left hand side of =)                *)
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
     9
(*  - simplification of permutation on applications and abstractions       *)
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    10
(*  - analysing congruences (from Stefan Berghofer's datatype pkg)         *)
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    11
(*  - unfolding permutation on functions                                   *)
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    12
(*  - expanding equalities of functions                                    *)
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    13
(*                                                                         *)
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    14
(*  for supports - it first unfolds the definitions and strips of intros   *)
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    15
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    16
local
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    17
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    18
(* pulls out dynamically a thm via the simpset *)
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    19
fun dynamic_thm ss name = 
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    20
    ProofContext.get_thm (Simplifier.the_context ss) (Name name);
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    21
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    22
(* initial simplification step in the tactic *)
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    23
fun initial_simp_tac ss i =
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    24
    let
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    25
	val perm_swap  = dynamic_thm ss "perm_swap";
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    26
        val perm_fresh = dynamic_thm ss "perm_fresh_fresh";
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    27
        val perm_bij   = dynamic_thm ss "perm_bij";
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    28
        val ss' = ss addsimps [perm_swap,perm_fresh,perm_bij]
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    29
    in
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    30
      ("general simplification step", FIRST [rtac conjI i, asm_full_simp_tac ss' i])
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    31
    end;
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    32
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    33
(* applies the perm_compose rule - this rule would loop in the simplifier *)
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    34
fun apply_perm_compose_tac ss i = 
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    35
    let
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    36
	val perm_compose = dynamic_thm ss "perm_compose"; 
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    37
    in
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    38
	("analysing permutation compositions on the lhs",rtac (perm_compose RS trans)  i)
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    39
    end
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    40
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    41
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    42
(* applies the perm_eq_lam and perm_eq_app simplifications *)
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    43
fun apply_app_lam_simp_tac ss i =
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    44
    let 
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    45
	val perm_app_eq  = dynamic_thm ss "perm_app_eq";
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    46
        val perm_lam_eq  = dynamic_thm ss "perm_eq_lam"
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    47
    in
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    48
     ("simplification of permutations on applications and lambdas", 
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    49
      asm_full_simp_tac (HOL_basic_ss addsimps [perm_app_eq,perm_lam_eq]) i)
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    50
    end
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    51
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    52
(* applying Stefan's smart congruence tac *)
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    53
fun apply_cong_tac i = 
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    54
    ("application of congruence",
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    55
     (fn st => DatatypeAux.cong_tac  i st handle Subscript => no_tac st));
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    56
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    57
(* unfolds the definition of permutations applied to functions *)
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    58
fun unfold_perm_fun_def_tac i = 
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    59
    let
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    60
	val perm_fun_def = thm "nominal.perm_fun_def"
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    61
    in
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    62
	("unfolding of permutations on functions", 
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    63
	 simp_tac (HOL_basic_ss addsimps [perm_fun_def]) i)
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    64
    end
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    65
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    66
(* applies the expand_fun_eq rule to the first goal and strips off all universal quantifiers *)
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    67
fun expand_fun_eq_tac i =    
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    68
    ("extensionality expansion of functions",
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    69
    EVERY [simp_tac (HOL_basic_ss addsimps [expand_fun_eq]) i, REPEAT_DETERM (rtac allI i)]);
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    70
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    71
(* debugging *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    72
fun DEBUG_tac (msg,tac) = 
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    73
    EVERY [CHANGED tac, print_tac ("after "^msg)]; 
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    74
fun NO_DEBUG_tac (_,tac) = CHANGED tac; 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    75
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    76
(* Main Tactic *)
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    77
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    78
(* "repeating"-depth is set to 40 - this seems sufficient *)
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    79
fun perm_simp_tac tactical ss i = 
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    80
    DETERM (REPEAT_DETERM_N 40 
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    81
      (FIRST[tactical (initial_simp_tac ss i),
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    82
             tactical (apply_perm_compose_tac ss i),
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    83
             tactical (apply_app_lam_simp_tac ss i),
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    84
             tactical (apply_cong_tac i), 
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    85
             tactical (unfold_perm_fun_def_tac i),
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    86
             tactical (expand_fun_eq_tac i)]));
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    87
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    88
(* tactic that first unfolds the support definition *)
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    89
(* and strips of intros, then applies perm_simp_tac *)
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    90
fun supports_tac tactical ss i =
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    91
  let 
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    92
      val supports_def = thm "nominal.op supports_def";
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    93
      val fresh_def    = thm "nominal.fresh_def";
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    94
      val fresh_prod   = thm "nominal.fresh_prod";
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    95
      val simps        = [supports_def,symmetric fresh_def,fresh_prod]
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    96
  in
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    97
      EVERY [tactical ("unfolding of supports ",simp_tac (HOL_basic_ss addsimps simps) i),
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    98
             tactical ("stripping of foralls  " ,REPEAT_DETERM (rtac allI i)),
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    99
             tactical ("geting rid of the imps",rtac impI i),
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   100
             tactical ("eliminating conjuncts ",REPEAT_DETERM (etac  conjE i)),
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   101
             tactical ("applying perm_simp    ",perm_simp_tac tactical ss i)]
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   102
  end;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   103
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   104
in             
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   105
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   106
(* FIXME simp_modifiers' 
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   107
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   108
(Markus needs to commit this)
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   109
*)
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   110
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   111
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   112
fun simp_meth_setup tac =
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   113
  Method.only_sectioned_args (Simplifier.simp_modifiers @ Splitter.split_modifiers)
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   114
  (Method.SIMPLE_METHOD' HEADGOAL o tac o local_simpset_of);
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   115
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   116
val perm_eq_meth        = simp_meth_setup (perm_simp_tac NO_DEBUG_tac);
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   117
val perm_eq_meth_debug  = simp_meth_setup (perm_simp_tac DEBUG_tac);
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   118
val supports_meth       = simp_meth_setup (supports_tac NO_DEBUG_tac);
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   119
val supports_meth_debug = simp_meth_setup (supports_tac DEBUG_tac);
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   120
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   121
end
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   122
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   123
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   124