src/HOL/Nominal/nominal_permeq.ML
author urbanc
Thu, 06 Apr 2006 17:29:40 +0200
changeset 19350 2e1c7ca05ee0
parent 19169 20a73345dd6e
child 19477 a95176d0f0dd
permissions -rw-r--r--
modified the perm_compose rule such that it is applied as simplification rule (as simproc) in the restricted case where the first permutation is a swapping coming from a supports problem also deleted the perm_compose' rule from the set of rules that are automatically tried
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
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
     5
local
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
     6
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
     7
(* pulls out dynamically a thm via the simpset *)
18434
a31e52a3e6ef fixed a bug that occured when more than one atom-type
urbanc
parents: 18279
diff changeset
     8
fun dynamic_thms ss name = 
a31e52a3e6ef fixed a bug that occured when more than one atom-type
urbanc
parents: 18279
diff changeset
     9
    ProofContext.get_thms (Simplifier.the_context ss) (Name name);
19139
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    10
fun dynamic_thm ss name = 
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    11
    ProofContext.get_thm (Simplifier.the_context ss) (Name name);
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    12
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    13
(* initial simplification step in the tactic *)
19139
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    14
fun perm_eval_tac ss i =
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    15
    let
19139
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    16
        fun perm_eval_simproc sg ss redex =
19169
20a73345dd6e fixed a problem where a permutation is not analysed
urbanc
parents: 19163
diff changeset
    17
        let 
20a73345dd6e fixed a problem where a permutation is not analysed
urbanc
parents: 19163
diff changeset
    18
	   
20a73345dd6e fixed a problem where a permutation is not analysed
urbanc
parents: 19163
diff changeset
    19
           (* the "application" case below is only applicable when the head   *)
20a73345dd6e fixed a problem where a permutation is not analysed
urbanc
parents: 19163
diff changeset
    20
           (* of f is not a constant  or when it is a permuattion with two or *) 
20a73345dd6e fixed a problem where a permutation is not analysed
urbanc
parents: 19163
diff changeset
    21
           (* more arguments                                                  *)
20a73345dd6e fixed a problem where a permutation is not analysed
urbanc
parents: 19163
diff changeset
    22
           fun applicable t = 
20a73345dd6e fixed a problem where a permutation is not analysed
urbanc
parents: 19163
diff changeset
    23
	       (case (strip_comb t) of
20a73345dd6e fixed a problem where a permutation is not analysed
urbanc
parents: 19163
diff changeset
    24
		  (Const ("nominal.perm",_),ts) => (length ts) >= 2
20a73345dd6e fixed a problem where a permutation is not analysed
urbanc
parents: 19163
diff changeset
    25
		| (Const _,_) => false
20a73345dd6e fixed a problem where a permutation is not analysed
urbanc
parents: 19163
diff changeset
    26
		| _ => true)
20a73345dd6e fixed a problem where a permutation is not analysed
urbanc
parents: 19163
diff changeset
    27
20a73345dd6e fixed a problem where a permutation is not analysed
urbanc
parents: 19163
diff changeset
    28
	in
19139
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    29
        (case redex of 
19169
20a73345dd6e fixed a problem where a permutation is not analysed
urbanc
parents: 19163
diff changeset
    30
        (* case pi o (f x) == (pi o f) (pi o x)          *)
20a73345dd6e fixed a problem where a permutation is not analysed
urbanc
parents: 19163
diff changeset
    31
        (* special treatment according to the head of f  *)
19144
9c8793c62d0c added support for arbitrary atoms in the simproc
urbanc
parents: 19139
diff changeset
    32
        (Const("nominal.perm",
19169
20a73345dd6e fixed a problem where a permutation is not analysed
urbanc
parents: 19163
diff changeset
    33
          Type("fun",[Type("List.list",[Type("*",[Type(n,_),_])]),_])) $ pi $ (f $ x)) => 
20a73345dd6e fixed a problem where a permutation is not analysed
urbanc
parents: 19163
diff changeset
    34
	   (case (applicable f) of
20a73345dd6e fixed a problem where a permutation is not analysed
urbanc
parents: 19163
diff changeset
    35
                false => NONE  
19163
b61039bf141f made some small tunings in the decision-procedure
urbanc
parents: 19151
diff changeset
    36
              | _ => 
b61039bf141f made some small tunings in the decision-procedure
urbanc
parents: 19151
diff changeset
    37
		let
b61039bf141f made some small tunings in the decision-procedure
urbanc
parents: 19151
diff changeset
    38
		    val name = Sign.base_name n
b61039bf141f made some small tunings in the decision-procedure
urbanc
parents: 19151
diff changeset
    39
		    val at_inst     = dynamic_thm ss ("at_"^name^"_inst")
b61039bf141f made some small tunings in the decision-procedure
urbanc
parents: 19151
diff changeset
    40
		    val pt_inst     = dynamic_thm ss ("pt_"^name^"_inst")  
b61039bf141f made some small tunings in the decision-procedure
urbanc
parents: 19151
diff changeset
    41
		    val perm_eq_app = thm "nominal.pt_fun_app_eq"	  
b61039bf141f made some small tunings in the decision-procedure
urbanc
parents: 19151
diff changeset
    42
		in SOME ((at_inst RS (pt_inst RS perm_eq_app)) RS eq_reflection) end)
19139
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    43
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    44
        (* case pi o (%x. f x) == (%x. pi o (f ((rev pi)o x))) *)
19144
9c8793c62d0c added support for arbitrary atoms in the simproc
urbanc
parents: 19139
diff changeset
    45
        | (Const("nominal.perm",_) $ pi $ (Abs _)) => 
9c8793c62d0c added support for arbitrary atoms in the simproc
urbanc
parents: 19139
diff changeset
    46
           let 
19163
b61039bf141f made some small tunings in the decision-procedure
urbanc
parents: 19151
diff changeset
    47
               val perm_fun_def = thm "nominal.perm_fun_def"
19139
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    48
           in SOME (perm_fun_def) end
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    49
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    50
        (* no redex otherwise *) 
19169
20a73345dd6e fixed a problem where a permutation is not analysed
urbanc
parents: 19163
diff changeset
    51
        | _ => NONE) end
19139
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    52
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    53
	val perm_eval =
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    54
	    Simplifier.simproc (Theory.sign_of (the_context ())) "perm_eval" 
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    55
	    ["nominal.perm pi x"] perm_eval_simproc;
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    56
19350
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    57
      (* applies the pt_perm_compose lemma              *)
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    58
      (*                                                *)
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    59
      (*     pi1 o (pi2 o x) = (pi1 o pi2) o (pi1 o x)  *)
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    60
      (*                                                *)
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    61
      (* in the restricted case where pi1 is a swapping *)
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    62
      (* (a b) coming from a "supports problem"; in     *)
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    63
      (* this rule would cause loops in the simplifier  *) 
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    64
      val pt_perm_compose = thm "pt_perm_compose";
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    65
	  
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    66
      fun perm_compose_simproc i sg ss redex =
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    67
      (case redex of
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    68
        (Const ("nominal.perm", _) $ (pi1 as Const ("List.list.Cons", _) $
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    69
         (Const ("Pair", _) $ Free (a as (_, T as Type (tname, _))) $ Free b) $ 
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    70
           Const ("List.list.Nil", _)) $ (Const ("nominal.perm", 
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    71
            Type ("fun", [Type ("List.list", [Type ("*", [U, _])]), _])) $ pi2 $ t)) =>
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    72
        let
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    73
            val ({bounds = (_, xs), ...}, _) = rep_ss ss
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    74
            val ai = find_index (fn (x, _) => x = a) xs
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    75
	    val bi = find_index (fn (x, _) => x = b) xs
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    76
	    val tname' = Sign.base_name tname
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    77
        in
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    78
            if ai = length xs - i - 1 andalso 
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    79
               bi = length xs - i - 2 andalso 
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    80
               T = U andalso pi1 <> pi2 then
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    81
                SOME (Drule.instantiate'
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    82
	              [SOME (ctyp_of sg (fastype_of t))]
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    83
		      [SOME (cterm_of sg pi1), SOME (cterm_of sg pi2), SOME (cterm_of sg t)]
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    84
		      (mk_meta_eq ([PureThy.get_thm sg (Name ("pt_"^tname'^"_inst")),
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    85
	               PureThy.get_thm sg (Name ("at_"^tname'^"_inst"))] MRS pt_perm_compose)))
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    86
            else NONE
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    87
        end
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    88
       | _ => NONE);
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    89
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    90
      fun perm_compose i =
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    91
	Simplifier.simproc (the_context()) "perm_compose" 
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    92
	["nominal.perm [(a, b)] (nominal.perm pi t)"] (perm_compose_simproc i);
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    93
         
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    94
      (* these lemmas are created dynamically according to the atom types *) 
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    95
      val perm_swap     = dynamic_thms ss "perm_swap"
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    96
      val perm_fresh    = dynamic_thms ss "perm_fresh_fresh"
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    97
      val perm_bij      = dynamic_thms ss "perm_bij"
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    98
      val perm_pi_simp  = dynamic_thms ss "perm_pi_simp"
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
    99
      val ss' = ss addsimps (perm_swap@perm_fresh@perm_bij@perm_pi_simp)
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   100
    in
19163
b61039bf141f made some small tunings in the decision-procedure
urbanc
parents: 19151
diff changeset
   101
      ("general simplification step", 
19350
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
   102
        FIRST [rtac conjI i, 
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
   103
               SUBGOAL (fn (g, i) => asm_full_simp_tac 
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
   104
                 (ss' addsimprocs [perm_eval,perm_compose (length (Logic.strip_params g)-2)]) i) i])
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   105
    end;
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   106
18434
a31e52a3e6ef fixed a bug that occured when more than one atom-type
urbanc
parents: 18279
diff changeset
   107
(* applies the perm_compose rule - this rule would loop in the simplifier     *)
a31e52a3e6ef fixed a bug that occured when more than one atom-type
urbanc
parents: 18279
diff changeset
   108
(* in case there are more atom-types we have to check every possible instance *)
19139
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
   109
(* of perm_compose                                                            *)
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   110
fun apply_perm_compose_tac ss i = 
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   111
    let
18434
a31e52a3e6ef fixed a bug that occured when more than one atom-type
urbanc
parents: 18279
diff changeset
   112
	val perm_compose = dynamic_thms ss "perm_compose"; 
a31e52a3e6ef fixed a bug that occured when more than one atom-type
urbanc
parents: 18279
diff changeset
   113
        val tacs = map (fn thm => (rtac (thm RS trans) i)) perm_compose
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   114
    in
18434
a31e52a3e6ef fixed a bug that occured when more than one atom-type
urbanc
parents: 18279
diff changeset
   115
	("analysing permutation compositions on the lhs",FIRST (tacs))
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   116
    end
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   117
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   118
(* applying Stefan's smart congruence tac *)
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   119
fun apply_cong_tac i = 
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   120
    ("application of congruence",
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   121
     (fn st => DatatypeAux.cong_tac  i st handle Subscript => no_tac st));
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   122
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   123
(* unfolds the definition of permutations applied to functions *)
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   124
fun unfold_perm_fun_def_tac i = 
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   125
    let
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   126
	val perm_fun_def = thm "nominal.perm_fun_def"
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   127
    in
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   128
	("unfolding of permutations on functions", 
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   129
	 simp_tac (HOL_basic_ss addsimps [perm_fun_def]) i)
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   130
    end
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   131
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   132
(* 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
   133
fun expand_fun_eq_tac i =    
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   134
    ("extensionality expansion of functions",
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   135
    EVERY [simp_tac (HOL_basic_ss addsimps [expand_fun_eq]) i, REPEAT_DETERM (rtac allI i)]);
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   136
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   137
(* debugging *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   138
fun DEBUG_tac (msg,tac) = 
19169
20a73345dd6e fixed a problem where a permutation is not analysed
urbanc
parents: 19163
diff changeset
   139
    CHANGED (EVERY [tac, print_tac ("after "^msg)]); 
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   140
fun NO_DEBUG_tac (_,tac) = CHANGED tac; 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   141
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   142
(* Main Tactic *)
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   143
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   144
fun perm_simp_tac tactical ss i = 
19139
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
   145
    DETERM (tactical (perm_eval_tac ss i));
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
   146
19151
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   147
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   148
(* perm_simp_tac plus additional tactics to decide            *)
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   149
(* support problems                                           *)
19163
b61039bf141f made some small tunings in the decision-procedure
urbanc
parents: 19151
diff changeset
   150
(* the "recursion"-depth is set to 10 - this seems sufficient *)
19151
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   151
fun perm_supports_tac tactical ss n = 
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   152
    if n=0 then K all_tac
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   153
    else DETERM o 
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   154
         (FIRST'[fn i => tactical (perm_eval_tac ss i),
19350
2e1c7ca05ee0 modified the perm_compose rule such that it
urbanc
parents: 19169
diff changeset
   155
                 (*fn i => tactical (apply_perm_compose_tac ss i),*)
19163
b61039bf141f made some small tunings in the decision-procedure
urbanc
parents: 19151
diff changeset
   156
		 fn i => tactical (apply_cong_tac i), 
b61039bf141f made some small tunings in the decision-procedure
urbanc
parents: 19151
diff changeset
   157
                 fn i => tactical (unfold_perm_fun_def_tac i),
b61039bf141f made some small tunings in the decision-procedure
urbanc
parents: 19151
diff changeset
   158
		 fn i => tactical (expand_fun_eq_tac i)]
19151
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   159
         THEN_ALL_NEW (TRY o (perm_supports_tac tactical ss (n-1))));
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   160
19139
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
   161
(* tactic that first unfolds the support definition          *)
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
   162
(* and strips off the intros, then applies perm_supports_tac *)
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   163
fun supports_tac tactical ss i =
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   164
  let 
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   165
      val supports_def = thm "nominal.op supports_def";
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   166
      val fresh_def    = thm "nominal.fresh_def";
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   167
      val fresh_prod   = thm "nominal.fresh_prod";
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   168
      val simps        = [supports_def,symmetric fresh_def,fresh_prod]
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   169
  in
19151
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   170
      EVERY [tactical ("unfolding of supports ", simp_tac (HOL_basic_ss addsimps simps) i),
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   171
             tactical ("stripping of foralls  ", REPEAT_DETERM (rtac allI i)),
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   172
             tactical ("geting rid of the imps", rtac impI i),
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   173
             tactical ("eliminating conjuncts ", REPEAT_DETERM (etac  conjE i)),
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   174
             tactical ("applying perm_simp    ", perm_supports_tac tactical ss 10 i)]
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   175
  end;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   176
19151
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   177
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   178
(* tactic that guesses the finite-support of a goal *)
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   179
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   180
fun collect_vars i (Bound j) vs = if j < i then vs else Bound (j - i) ins vs
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   181
  | collect_vars i (v as Free _) vs = v ins vs
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   182
  | collect_vars i (v as Var _) vs = v ins vs
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   183
  | collect_vars i (Const _) vs = vs
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   184
  | collect_vars i (Abs (_, _, t)) vs = collect_vars (i+1) t vs
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   185
  | collect_vars i (t $ u) vs = collect_vars i u (collect_vars i t vs);
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   186
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   187
val supports_rule = thm "supports_finite";
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   188
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   189
fun finite_guess_tac tactical ss i st =
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   190
    let val goal = List.nth(cprems_of st, i-1)
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   191
    in
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   192
      case Logic.strip_assums_concl (term_of goal) of
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   193
          _ $ (Const ("op :", _) $ (Const ("nominal.supp", T) $ x) $
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   194
            Const ("Finite_Set.Finites", _)) =>
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   195
          let
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   196
            val cert = Thm.cterm_of (sign_of_thm st);
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   197
            val ps = Logic.strip_params (term_of goal);
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   198
            val Ts = rev (map snd ps);
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   199
            val vs = collect_vars 0 x [];
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   200
            val s = foldr (fn (v, s) =>
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   201
                HOLogic.pair_const (fastype_of1 (Ts, v)) (fastype_of1 (Ts, s)) $ v $ s)
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   202
              HOLogic.unit vs;
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   203
            val s' = list_abs (ps,
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   204
              Const ("nominal.supp", fastype_of1 (Ts, s) --> body_type T) $ s);
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   205
            val supports_rule' = Thm.lift_rule goal supports_rule;
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   206
            val _ $ (_ $ S $ _) =
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   207
              Logic.strip_assums_concl (hd (prems_of supports_rule'));
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   208
            val supports_rule'' = Drule.cterm_instantiate
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   209
              [(cert (head_of S), cert s')] supports_rule'
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   210
          in
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   211
            (tactical ("guessing of the right supports-set",
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   212
                      EVERY [compose_tac (false, supports_rule'', 2) i,
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   213
                             asm_full_simp_tac ss (i+1),
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   214
                             supports_tac tactical ss i])) st
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   215
          end
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   216
        | _ => Seq.empty
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   217
    end
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   218
    handle Subscript => Seq.empty
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   219
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   220
in             
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   221
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   222
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   223
fun simp_meth_setup tac =
18046
b7389981170b Changed Simplifier.simp_modifiers to Simplifier.simp_modifiers'.
urbanc
parents: 18012
diff changeset
   224
  Method.only_sectioned_args (Simplifier.simp_modifiers' @ Splitter.split_modifiers)
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   225
  (Method.SIMPLE_METHOD' HEADGOAL o tac o local_simpset_of);
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   226
19151
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   227
val perm_eq_meth         = simp_meth_setup (perm_simp_tac NO_DEBUG_tac);
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   228
val perm_eq_meth_debug   = simp_meth_setup (perm_simp_tac DEBUG_tac);
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   229
val supports_meth        = simp_meth_setup (supports_tac NO_DEBUG_tac);
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   230
val supports_meth_debug  = simp_meth_setup (supports_tac DEBUG_tac);
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   231
val finite_gs_meth       = simp_meth_setup (finite_guess_tac NO_DEBUG_tac);
66e841b1001e added a finite_guess tactic, which solves
urbanc
parents: 19144
diff changeset
   232
val finite_gs_meth_debug = simp_meth_setup (finite_guess_tac DEBUG_tac);
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   233
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   234
end
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   235
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   236
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   237