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