src/HOL/Nominal/nominal_permeq.ML
author urbanc
Sun, 26 Feb 2006 22:24:05 +0100
changeset 19139 af69e41eab5d
parent 18434 a31e52a3e6ef
child 19144 9c8793c62d0c
permissions -rw-r--r--
improved the decision-procedure for permutations; now uses a simproc FIXME: the simproc still needs to be adapted for arbitrary atom types
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
19139
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    13
(* FIXME: make it usable for all atom-types *)
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    14
(* initial simplification step in the tactic *)
19139
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    15
fun perm_eval_tac ss i =
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    16
    let
19139
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    17
        val perm_eq_app   = thm "nominal.pt_fun_app_eq";
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    18
        val at_inst       = dynamic_thm ss "at_name_inst";
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    19
        val pt_inst       = dynamic_thm ss "pt_name_inst";
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    20
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    21
        fun perm_eval_simproc sg ss redex =
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    22
        (case redex of 
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    23
        (* case pi o (f x) == (pi o f) (pi o x)    *)
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    24
        (* special treatment in cases of constants *)
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    25
        (Const("nominal.perm",Type("fun",[Type("List.list",[Type("*",[ty,_])]),_])) $ pi $ (f $ x)) 
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    26
        => let
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    27
             val _ = warning ("type: "^Sign.string_of_typ (sign_of (the_context())) ty)
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    28
           in
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    29
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    30
           (case f of
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    31
                    (* nothing to do on constants *)
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    32
                    (* FIXME: proper treatment of constants *)
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    33
                      Const(_,_)                   => NONE
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    34
                    | (Const(_,_) $ _)             => NONE
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    35
                    | ((Const(_,_) $ _) $ _)       => NONE
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    36
                    | (((Const(_,_) $ _) $ _) $ _) => NONE
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    37
                    | _ => 
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    38
                       (* FIXME: analyse type here or at "pty"*)
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    39
		       SOME ((at_inst RS (pt_inst RS perm_eq_app)) RS eq_reflection))
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    40
            end
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    41
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    42
        (* case pi o (%x. f x) == (%x. pi o (f ((rev pi)o x))) *)
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    43
        | (Const("nominal.perm",_) $ pi $ (Abs _)) 
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    44
        => let 
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    45
             val perm_fun_def = thm "nominal.perm_fun_def"
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    46
           in SOME (perm_fun_def) end
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    47
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    48
        (* no redex otherwise *) 
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    49
        | _ => NONE);
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    50
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    51
	val perm_eval =
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    52
	    Simplifier.simproc (Theory.sign_of (the_context ())) "perm_eval" 
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    53
	    ["nominal.perm pi x"] perm_eval_simproc;
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    54
18279
f7a18e2b10fc made some of the theorem look-ups static (by using
urbanc
parents: 18052
diff changeset
    55
        (* these lemmas are created dynamically according to the atom types *) 
19139
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    56
	val perm_swap     = dynamic_thms ss "perm_swap";
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    57
        val perm_fresh    = dynamic_thms ss "perm_fresh_fresh";
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    58
        val perm_bij      = dynamic_thms ss "perm_bij";
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    59
        val perm_compose' = dynamic_thms ss "perm_compose'";
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    60
        val perm_pi_simp  = dynamic_thms ss "perm_pi_simp";
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    61
        val ss' = ss addsimps (perm_swap@perm_fresh@perm_bij@perm_compose'@perm_pi_simp)
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    62
                     addsimprocs [perm_eval];
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
    63
                    
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    64
    in
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    65
      ("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
    66
    end;
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    67
18434
a31e52a3e6ef fixed a bug that occured when more than one atom-type
urbanc
parents: 18279
diff changeset
    68
(* 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
    69
(* 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
    70
(* of perm_compose                                                            *)
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    71
fun apply_perm_compose_tac ss i = 
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    72
    let
18434
a31e52a3e6ef fixed a bug that occured when more than one atom-type
urbanc
parents: 18279
diff changeset
    73
	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
    74
        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
    75
    in
18434
a31e52a3e6ef fixed a bug that occured when more than one atom-type
urbanc
parents: 18279
diff changeset
    76
	("analysing permutation compositions on the lhs",FIRST (tacs))
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    77
    end
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    78
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    79
(* applying Stefan's smart congruence tac *)
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    80
fun apply_cong_tac i = 
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    81
    ("application of congruence",
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    82
     (fn st => DatatypeAux.cong_tac  i st handle Subscript => no_tac st));
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    83
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    84
(* unfolds the definition of permutations applied to functions *)
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    85
fun unfold_perm_fun_def_tac i = 
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    86
    let
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    87
	val perm_fun_def = thm "nominal.perm_fun_def"
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    88
    in
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    89
	("unfolding of permutations on functions", 
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    90
	 simp_tac (HOL_basic_ss addsimps [perm_fun_def]) i)
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    91
    end
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    92
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    93
(* 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
    94
fun expand_fun_eq_tac i =    
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    95
    ("extensionality expansion of functions",
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
    96
    EVERY [simp_tac (HOL_basic_ss addsimps [expand_fun_eq]) i, REPEAT_DETERM (rtac allI i)]);
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    97
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    98
(* debugging *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    99
fun DEBUG_tac (msg,tac) = 
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   100
    EVERY [CHANGED tac, print_tac ("after "^msg)]; 
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   101
fun NO_DEBUG_tac (_,tac) = CHANGED tac; 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   102
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   103
(* Main Tactic *)
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   104
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   105
fun perm_simp_tac tactical ss i = 
19139
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
   106
    DETERM (tactical (perm_eval_tac ss i));
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
   107
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
   108
(* perm_simp_tac plus additional tactics to decide            *)
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
   109
(* support problems                                           *)
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
   110
(* the "repeating"-depth is set to 40 - this seems sufficient *)
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
   111
fun perm_supports_tac tactical ss i = 
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   112
    DETERM (REPEAT_DETERM_N 40 
19139
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
   113
      (FIRST[tactical (perm_eval_tac ss i),
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   114
             tactical (apply_perm_compose_tac ss i),
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   115
             tactical (apply_cong_tac i), 
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   116
             tactical (unfold_perm_fun_def_tac i),
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   117
             tactical (expand_fun_eq_tac i)]));
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   118
19139
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
   119
(* tactic that first unfolds the support definition          *)
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
   120
(* and strips off the intros, then applies perm_supports_tac *)
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   121
fun supports_tac tactical ss i =
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   122
  let 
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   123
      val supports_def = thm "nominal.op supports_def";
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   124
      val fresh_def    = thm "nominal.fresh_def";
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   125
      val fresh_prod   = thm "nominal.fresh_prod";
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   126
      val simps        = [supports_def,symmetric fresh_def,fresh_prod]
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   127
  in
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   128
      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
   129
             tactical ("stripping of foralls  " ,REPEAT_DETERM (rtac allI i)),
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   130
             tactical ("geting rid of the imps",rtac impI i),
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   131
             tactical ("eliminating conjuncts ",REPEAT_DETERM (etac  conjE i)),
19139
af69e41eab5d improved the decision-procedure for permutations;
urbanc
parents: 18434
diff changeset
   132
             tactical ("applying perm_simp    ",perm_supports_tac tactical ss i)]
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   133
  end;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   134
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   135
in             
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   136
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   137
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   138
fun simp_meth_setup tac =
18046
b7389981170b Changed Simplifier.simp_modifiers to Simplifier.simp_modifiers'.
urbanc
parents: 18012
diff changeset
   139
  Method.only_sectioned_args (Simplifier.simp_modifiers' @ Splitter.split_modifiers)
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   140
  (Method.SIMPLE_METHOD' HEADGOAL o tac o local_simpset_of);
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   141
18012
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   142
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
   143
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
   144
val supports_meth       = simp_meth_setup (supports_tac NO_DEBUG_tac);
23e6cfda8c4b Added (optional) arguments to the tactics
urbanc
parents: 17870
diff changeset
   145
val supports_meth_debug = simp_meth_setup (supports_tac DEBUG_tac);
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   146
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   147
end
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   148
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   149
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   150