src/HOL/Nominal/nominal_fresh_fun.ML
author wenzelm
Sat, 16 Apr 2011 18:11:20 +0200
changeset 42364 8c674b3b8e44
parent 42361 23f352990944
child 42806 4b660cdab9b7
permissions -rw-r--r--
eliminated old List.nth; tuned;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
     1
(*  Title:      HOL/Nominal/nominal_fresh_fun.ML
29265
5b4247055bd7 moved old add_term_vars, add_term_frees etc. to structure OldTerm;
wenzelm
parents: 28397
diff changeset
     2
    Authors:    Stefan Berghofer and Julien Narboux, TU Muenchen
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
     3
24558
419f7cde7f59 some cleaning up
urbanc
parents: 24271
diff changeset
     4
Provides a tactic to generate fresh names and
419f7cde7f59 some cleaning up
urbanc
parents: 24271
diff changeset
     5
a tactic to analyse instances of the fresh_fun.
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
     6
*)
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
     7
24558
419f7cde7f59 some cleaning up
urbanc
parents: 24271
diff changeset
     8
(* First some functions that should be in the library *)
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
     9
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    10
fun gen_res_inst_tac_term instf tyinst tinst elim th i st =
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    11
  let
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    12
    val thy = theory_of_thm st;
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    13
    val cgoal = nth (cprems_of st) (i - 1);
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    14
    val {maxidx, ...} = rep_cterm cgoal;
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    15
    val j = maxidx + 1;
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    16
    val tyinst' = map (apfst (Logic.incr_tvar j)) tyinst;
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    17
    val ps = Logic.strip_params (term_of cgoal);
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    18
    val Ts = map snd ps;
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    19
    val tinst' = map (fn (t, u) =>
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    20
      (head_of (Logic.incr_indexes (Ts, j) t),
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    21
       list_abs (ps, u))) tinst;
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    22
    val th' = instf
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    23
      (map (pairself (ctyp_of thy)) tyinst')
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    24
      (map (pairself (cterm_of thy)) tinst')
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    25
      (Thm.lift_rule cgoal th)
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    26
  in
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    27
    compose_tac (elim, th', nprems_of th) i st
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    28
  end handle Subscript => Seq.empty;
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    29
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
    30
val res_inst_tac_term =
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    31
  gen_res_inst_tac_term (curry Thm.instantiate);
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    32
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
    33
val res_inst_tac_term' =
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    34
  gen_res_inst_tac_term (K Drule.cterm_instantiate) [];
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    35
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    36
fun cut_inst_tac_term' tinst th =
27239
f2f42f9fa09d pervasive RuleInsts;
wenzelm
parents: 27187
diff changeset
    37
  res_inst_tac_term' tinst false (RuleInsts.make_elim_preserve th);
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    38
26337
44473c957672 auxiliary dynamic_thm(s) for fact lookup;
wenzelm
parents: 24558
diff changeset
    39
fun get_dyn_thm thy name atom_name =
39557
fe5722fce758 renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
wenzelm
parents: 36610
diff changeset
    40
  Global_Theory.get_thm thy name handle ERROR _ =>
27187
17b63e145986 use regular error function;
wenzelm
parents: 26343
diff changeset
    41
    error ("The atom type "^atom_name^" is not defined.");
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    42
24558
419f7cde7f59 some cleaning up
urbanc
parents: 24271
diff changeset
    43
(* End of function waiting to be in the library :o) *)
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    44
24558
419f7cde7f59 some cleaning up
urbanc
parents: 24271
diff changeset
    45
(* The theorems needed that are known at compile time. *)
419f7cde7f59 some cleaning up
urbanc
parents: 24271
diff changeset
    46
val at_exists_fresh' = @{thm "at_exists_fresh'"};
419f7cde7f59 some cleaning up
urbanc
parents: 24271
diff changeset
    47
val fresh_fun_app'   = @{thm "fresh_fun_app'"};
419f7cde7f59 some cleaning up
urbanc
parents: 24271
diff changeset
    48
val fresh_prod       = @{thm "fresh_prod"};
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    49
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
    50
(* A tactic to generate a name fresh for  all the free *)
24558
419f7cde7f59 some cleaning up
urbanc
parents: 24271
diff changeset
    51
(* variables and parameters of the goal                *)
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    52
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    53
fun generate_fresh_tac atom_name i thm =
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
    54
 let
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    55
   val thy = theory_of_thm thm;
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    56
(* the parsing function returns a qualified name, we get back the base name *)
30364
577edc39b501 moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents: 30280
diff changeset
    57
   val atom_basename = Long_Name.base_name atom_name;
42364
8c674b3b8e44 eliminated old List.nth;
wenzelm
parents: 42361
diff changeset
    58
   val goal = nth (prems_of thm) (i - 1);
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    59
   val ps = Logic.strip_params goal;
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    60
   val Ts = rev (map snd ps);
35667
aa59452c913c tuned -- eliminated Sign.intern_sort;
wenzelm
parents: 35360
diff changeset
    61
   fun is_of_fs_name T = Sign.of_sort thy (T, [Sign.intern_class thy ("fs_"^atom_basename)]);
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    62
(* rebuild de bruijn indices *)
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    63
   val bvs = map_index (Bound o fst) ps;
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    64
(* select variables of the right class *)
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    65
   val vs = filter (fn t => is_of_fs_name (fastype_of1 (Ts, t)))
29265
5b4247055bd7 moved old add_term_vars, add_term_frees etc. to structure OldTerm;
wenzelm
parents: 28397
diff changeset
    66
     (OldTerm.term_frees goal @ bvs);
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    67
(* build the tuple *)
23368
ad690b9bca1c generate_fresh works even if there is no free variable in the goal
narboux
parents: 23094
diff changeset
    68
   val s = (Library.foldr1 (fn (v, s) =>
41519
0940fff556a6 avoid catch-all exception handler, presumably TERM was meant here;
wenzelm
parents: 39557
diff changeset
    69
       HOLogic.pair_const (fastype_of1 (Ts, v)) (fastype_of1 (Ts, s)) $ v $ s) vs)
0940fff556a6 avoid catch-all exception handler, presumably TERM was meant here;
wenzelm
parents: 39557
diff changeset
    70
     handle TERM _ => HOLogic.unit;
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    71
   val fs_name_thm = get_dyn_thm thy ("fs_"^atom_basename^"1") atom_basename;
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    72
   val at_name_inst_thm = get_dyn_thm thy ("at_"^atom_basename^"_inst") atom_basename;
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    73
   val exists_fresh' = at_name_inst_thm RS at_exists_fresh';
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    74
(* find the variable we want to instantiate *)
29265
5b4247055bd7 moved old add_term_vars, add_term_frees etc. to structure OldTerm;
wenzelm
parents: 28397
diff changeset
    75
   val x = hd (OldTerm.term_vars (prop_of exists_fresh'));
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
    76
 in
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    77
   (cut_inst_tac_term' [(x,s)] exists_fresh' 1 THEN
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    78
   rtac fs_name_thm 1 THEN
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    79
   etac exE 1) thm
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    80
  handle Empty  => all_tac thm (* if we collected no variables then we do nothing *)
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    81
  end;
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    82
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    83
fun get_inner_fresh_fun (Bound j) = NONE
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
    84
  | get_inner_fresh_fun (v as Free _) = NONE
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    85
  | get_inner_fresh_fun (v as Var _)  = NONE
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    86
  | get_inner_fresh_fun (Const _) = NONE
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
    87
  | get_inner_fresh_fun (Abs (_, _, t)) = get_inner_fresh_fun t
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
    88
  | get_inner_fresh_fun (Const ("Nominal.fresh_fun",Type("fun",[Type ("fun",[Type (T,_),_]),_])) $ u)
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
    89
                           = SOME T
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
    90
  | get_inner_fresh_fun (t $ u) =
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    91
     let val a = get_inner_fresh_fun u in
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
    92
     if a = NONE then get_inner_fresh_fun t else a
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    93
     end;
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    94
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
    95
(* This tactic generates a fresh name of the atom type *)
24558
419f7cde7f59 some cleaning up
urbanc
parents: 24271
diff changeset
    96
(* given by the innermost fresh_fun                    *)
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    97
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    98
fun generate_fresh_fun_tac i thm =
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    99
  let
42364
8c674b3b8e44 eliminated old List.nth;
wenzelm
parents: 42361
diff changeset
   100
    val goal = nth (prems_of thm) (i - 1);
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
   101
    val atom_name_opt = get_inner_fresh_fun goal;
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
   102
  in
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
   103
  case atom_name_opt of
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
   104
    NONE => all_tac thm
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
   105
  | SOME atom_name  => generate_fresh_tac atom_name i thm
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
   106
  end
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
   107
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
   108
(* Two substitution tactics which looks for the innermost occurence in
23091
c91530f18d9c add an option in fresh_fun_simp to prevent rewriting in assumptions
narboux
parents: 23065
diff changeset
   109
   one assumption or in the conclusion *)
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
   110
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
   111
val search_fun = curry (Seq.flat o uncurry EqSubst.searchf_bt_unify_valid);
23065
ab28e8398670 search bottom up to get the inner fresh fun
narboux
parents: 23054
diff changeset
   112
val search_fun_asm = EqSubst.skip_first_asm_occs_search EqSubst.searchf_bt_unify_valid;
23054
d1bbe5afa279 change fresh_fun_simp to treat occurences in assumptions and try to solve the generated subgoals
narboux
parents: 22792
diff changeset
   113
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
   114
fun subst_inner_tac ctxt = EqSubst.eqsubst_tac' ctxt search_fun;
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
   115
fun subst_inner_asm_tac_aux i ctxt = EqSubst.eqsubst_asm_tac' ctxt search_fun_asm i;
23054
d1bbe5afa279 change fresh_fun_simp to treat occurences in assumptions and try to solve the generated subgoals
narboux
parents: 22792
diff changeset
   116
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
   117
(* A tactic to substitute in the first assumption
23091
c91530f18d9c add an option in fresh_fun_simp to prevent rewriting in assumptions
narboux
parents: 23065
diff changeset
   118
   which contains an occurence. *)
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
   119
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
   120
fun subst_inner_asm_tac ctxt th =
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
   121
  curry (curry (FIRST' (map uncurry (map uncurry (map subst_inner_asm_tac_aux
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
   122
            (1 upto Thm.nprems_of th)))))) ctxt th;
23091
c91530f18d9c add an option in fresh_fun_simp to prevent rewriting in assumptions
narboux
parents: 23065
diff changeset
   123
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
   124
fun fresh_fun_tac no_asm i thm =
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
   125
  (* Find the variable we instantiate *)
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
   126
  let
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
   127
    val thy = theory_of_thm thm;
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 41519
diff changeset
   128
    val ctxt = Proof_Context.init_global thy;
32149
ef59550a55d3 renamed simpset_of to global_simpset_of, and local_simpset_of to simpset_of -- same for claset and clasimpset;
wenzelm
parents: 30549
diff changeset
   129
    val ss = global_simpset_of thy;
39557
fe5722fce758 renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
wenzelm
parents: 36610
diff changeset
   130
    val abs_fresh = Global_Theory.get_thms thy "abs_fresh";
fe5722fce758 renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
wenzelm
parents: 36610
diff changeset
   131
    val fresh_perm_app = Global_Theory.get_thms thy "fresh_perm_app";
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
   132
    val ss' = ss addsimps fresh_prod::abs_fresh;
23054
d1bbe5afa279 change fresh_fun_simp to treat occurences in assumptions and try to solve the generated subgoals
narboux
parents: 22792
diff changeset
   133
    val ss'' = ss' addsimps fresh_perm_app;
29265
5b4247055bd7 moved old add_term_vars, add_term_frees etc. to structure OldTerm;
wenzelm
parents: 28397
diff changeset
   134
    val x = hd (tl (OldTerm.term_vars (prop_of exI)));
22787
85e7e32e6004 update fresh_fun_simp for debugging purposes
narboux
parents: 22774
diff changeset
   135
    val goal = nth (prems_of thm) (i-1);
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
   136
    val atom_name_opt = get_inner_fresh_fun goal;
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
   137
    val n = length (Logic.strip_params goal);
24558
419f7cde7f59 some cleaning up
urbanc
parents: 24271
diff changeset
   138
    (* Here we rely on the fact that the variable introduced by generate_fresh_tac *)
419f7cde7f59 some cleaning up
urbanc
parents: 24271
diff changeset
   139
    (* is the last one in the list, the inner one *)
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
   140
  in
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
   141
  case atom_name_opt of
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
   142
    NONE => all_tac thm
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
   143
  | SOME atom_name =>
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
   144
  let
30364
577edc39b501 moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents: 30280
diff changeset
   145
    val atom_basename = Long_Name.base_name atom_name;
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
   146
    val pt_name_inst = get_dyn_thm thy ("pt_"^atom_basename^"_inst") atom_basename;
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
   147
    val at_name_inst = get_dyn_thm thy ("at_"^atom_basename^"_inst") atom_basename;
22787
85e7e32e6004 update fresh_fun_simp for debugging purposes
narboux
parents: 22774
diff changeset
   148
    fun inst_fresh vars params i st =
29265
5b4247055bd7 moved old add_term_vars, add_term_frees etc. to structure OldTerm;
wenzelm
parents: 28397
diff changeset
   149
   let val vars' = OldTerm.term_vars (prop_of st);
22787
85e7e32e6004 update fresh_fun_simp for debugging purposes
narboux
parents: 22774
diff changeset
   150
       val thy = theory_of_thm st;
33040
cffdb7b28498 removed old-style \ and \\ infixes
haftmann
parents: 33034
diff changeset
   151
   in case subtract (op =) vars vars' of
22787
85e7e32e6004 update fresh_fun_simp for debugging purposes
narboux
parents: 22774
diff changeset
   152
     [x] => Seq.single (Thm.instantiate ([],[(cterm_of thy x,cterm_of thy (list_abs (params,Bound 0)))]) st)
85e7e32e6004 update fresh_fun_simp for debugging purposes
narboux
parents: 22774
diff changeset
   153
    | _ => error "fresh_fun_simp: Too many variables, please report."
85e7e32e6004 update fresh_fun_simp for debugging purposes
narboux
parents: 22774
diff changeset
   154
  end
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
   155
  in
23091
c91530f18d9c add an option in fresh_fun_simp to prevent rewriting in assumptions
narboux
parents: 23065
diff changeset
   156
  ((fn st =>
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
   157
  let
29265
5b4247055bd7 moved old add_term_vars, add_term_frees etc. to structure OldTerm;
wenzelm
parents: 28397
diff changeset
   158
    val vars = OldTerm.term_vars (prop_of st);
22787
85e7e32e6004 update fresh_fun_simp for debugging purposes
narboux
parents: 22774
diff changeset
   159
    val params = Logic.strip_params (nth (prems_of st) (i-1))
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
   160
    (* The tactics which solve the subgoals generated
23091
c91530f18d9c add an option in fresh_fun_simp to prevent rewriting in assumptions
narboux
parents: 23065
diff changeset
   161
       by the conditionnal rewrite rule. *)
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
   162
    val post_rewrite_tacs =
23054
d1bbe5afa279 change fresh_fun_simp to treat occurences in assumptions and try to solve the generated subgoals
narboux
parents: 22792
diff changeset
   163
          [rtac pt_name_inst,
d1bbe5afa279 change fresh_fun_simp to treat occurences in assumptions and try to solve the generated subgoals
narboux
parents: 22792
diff changeset
   164
           rtac at_name_inst,
34885
6587c24ef6d8 added SOLVED' -- a more direct version of THEN_ALL_NEW (K no_tac) -- strictly speaking it does not even depend on subgoal addressing, but it would be too confusing without it;
wenzelm
parents: 33040
diff changeset
   165
           TRY o SOLVED' (NominalPermeq.finite_guess_tac ss''),
23054
d1bbe5afa279 change fresh_fun_simp to treat occurences in assumptions and try to solve the generated subgoals
narboux
parents: 22792
diff changeset
   166
           inst_fresh vars params THEN'
34885
6587c24ef6d8 added SOLVED' -- a more direct version of THEN_ALL_NEW (K no_tac) -- strictly speaking it does not even depend on subgoal addressing, but it would be too confusing without it;
wenzelm
parents: 33040
diff changeset
   167
           (TRY o SOLVED' (NominalPermeq.fresh_guess_tac ss'')) THEN'
6587c24ef6d8 added SOLVED' -- a more direct version of THEN_ALL_NEW (K no_tac) -- strictly speaking it does not even depend on subgoal addressing, but it would be too confusing without it;
wenzelm
parents: 33040
diff changeset
   168
           (TRY o SOLVED' (asm_full_simp_tac ss''))]
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
   169
  in
23094
f1df8d2da98a fix a bug : the semantics of no_asm was the opposite
narboux
parents: 23091
diff changeset
   170
   ((if no_asm then no_tac else
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
   171
    (subst_inner_asm_tac ctxt fresh_fun_app' i THEN (RANGE post_rewrite_tacs i)))
23091
c91530f18d9c add an option in fresh_fun_simp to prevent rewriting in assumptions
narboux
parents: 23065
diff changeset
   172
    ORELSE
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
   173
    (subst_inner_tac ctxt fresh_fun_app' i THEN (RANGE post_rewrite_tacs i))) st
22787
85e7e32e6004 update fresh_fun_simp for debugging purposes
narboux
parents: 22774
diff changeset
   174
  end)) thm
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
   175
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
   176
  end
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
   177
  end
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
   178
23091
c91530f18d9c add an option in fresh_fun_simp to prevent rewriting in assumptions
narboux
parents: 23065
diff changeset
   179
(* syntax for options, given "(no_asm)" will give back true, without
c91530f18d9c add an option in fresh_fun_simp to prevent rewriting in assumptions
narboux
parents: 23065
diff changeset
   180
   gives back false *)
c91530f18d9c add an option in fresh_fun_simp to prevent rewriting in assumptions
narboux
parents: 23065
diff changeset
   181
val options_syntax =
c91530f18d9c add an option in fresh_fun_simp to prevent rewriting in assumptions
narboux
parents: 23065
diff changeset
   182
    (Args.parens (Args.$$$ "no_asm") >> (K true)) ||
c91530f18d9c add an option in fresh_fun_simp to prevent rewriting in assumptions
narboux
parents: 23065
diff changeset
   183
     (Scan.succeed false);
c91530f18d9c add an option in fresh_fun_simp to prevent rewriting in assumptions
narboux
parents: 23065
diff changeset
   184
30549
d2d7874648bd simplified method setup;
wenzelm
parents: 30510
diff changeset
   185
fun setup_generate_fresh x =
35360
df2b2168e43a clarified ProofContext.read_type_name/Args.type_name wrt strict logical constructors;
wenzelm
parents: 34885
diff changeset
   186
  (Args.goal_spec -- Args.type_name true >>
30549
d2d7874648bd simplified method setup;
wenzelm
parents: 30510
diff changeset
   187
    (fn (quant, s) => K (SIMPLE_METHOD'' quant (generate_fresh_tac s)))) x;
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
   188
30549
d2d7874648bd simplified method setup;
wenzelm
parents: 30510
diff changeset
   189
fun setup_fresh_fun_simp x =
d2d7874648bd simplified method setup;
wenzelm
parents: 30510
diff changeset
   190
  (Scan.lift options_syntax >> (fn b => K (SIMPLE_METHOD' (fresh_fun_tac b)))) x;
d2d7874648bd simplified method setup;
wenzelm
parents: 30510
diff changeset
   191