src/HOL/Nominal/nominal_fresh_fun.ML
author wenzelm
Sat, 05 Jan 2019 17:24:33 +0100
changeset 69597 ff784d5a5bfb
parent 60792 722cb21ab680
child 74282 c2ee8d993d6a
permissions -rw-r--r--
isabelle update -u control_cartouches;
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
56230
3e449273942a more standard method_setup;
wenzelm
parents: 55952
diff changeset
     8
(* FIXME proper ML structure! *)
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
     9
43278
1fbdcebb364b more robust exception pattern General.Subscript;
wenzelm
parents: 42806
diff changeset
    10
(* FIXME res_inst_tac mostly obsolete, cf. Subgoal.FOCUS *)
1fbdcebb364b more robust exception pattern General.Subscript;
wenzelm
parents: 42806
diff changeset
    11
1fbdcebb364b more robust exception pattern General.Subscript;
wenzelm
parents: 42806
diff changeset
    12
(* FIXME proper SUBGOAL/CSUBGOAL instead of cprems_of etc. *)
58956
a816aa3ff391 proper context for compose_tac, Splitter.split_tac (relevant for unify trace options);
wenzelm
parents: 58950
diff changeset
    13
fun gen_res_inst_tac_term ctxt instf tyinst tinst elim th i st =
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    14
  let
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    15
    val cgoal = nth (cprems_of st) (i - 1);
59586
ddf6deaadfe8 clarified signature;
wenzelm
parents: 59582
diff changeset
    16
    val maxidx = Thm.maxidx_of_cterm cgoal;
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    17
    val j = maxidx + 1;
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    18
    val tyinst' = map (apfst (Logic.incr_tvar j)) tyinst;
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59058
diff changeset
    19
    val ps = Logic.strip_params (Thm.term_of cgoal);
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    20
    val Ts = map snd ps;
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    21
    val tinst' = map (fn (t, u) =>
59787
6e2a20486897 local fixes may depend on goal params;
wenzelm
parents: 59635
diff changeset
    22
      (head_of (Logic.incr_indexes ([], Ts, j) t),
46219
426ed18eba43 discontinued old-style Term.list_abs in favour of plain Term.abs;
wenzelm
parents: 44121
diff changeset
    23
       fold_rev Term.abs ps u)) tinst;
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    24
    val th' = instf
60792
722cb21ab680 updated to infer_instantiate;
wenzelm
parents: 60754
diff changeset
    25
      (map (apsnd (Thm.ctyp_of ctxt)) tyinst')
722cb21ab680 updated to infer_instantiate;
wenzelm
parents: 60754
diff changeset
    26
      (map (apsnd (Thm.cterm_of ctxt)) tinst')
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    27
      (Thm.lift_rule cgoal th)
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    28
  in
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59058
diff changeset
    29
    compose_tac ctxt (elim, th', Thm.nprems_of th) i st
43278
1fbdcebb364b more robust exception pattern General.Subscript;
wenzelm
parents: 42806
diff changeset
    30
  end handle General.Subscript => Seq.empty;
1fbdcebb364b more robust exception pattern General.Subscript;
wenzelm
parents: 42806
diff changeset
    31
(* FIXME proper SUBGOAL/CSUBGOAL instead of cprems_of etc. *)
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    32
58956
a816aa3ff391 proper context for compose_tac, Splitter.split_tac (relevant for unify trace options);
wenzelm
parents: 58950
diff changeset
    33
fun res_inst_tac_term ctxt =
60642
48dd1cefb4ae simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents: 60359
diff changeset
    34
  gen_res_inst_tac_term ctxt (fn instT => fn inst =>
48dd1cefb4ae simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents: 60359
diff changeset
    35
    Thm.instantiate
60792
722cb21ab680 updated to infer_instantiate;
wenzelm
parents: 60754
diff changeset
    36
     (map (apfst dest_TVar) instT,
722cb21ab680 updated to infer_instantiate;
wenzelm
parents: 60754
diff changeset
    37
      map (apfst dest_Var) inst));
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    38
58956
a816aa3ff391 proper context for compose_tac, Splitter.split_tac (relevant for unify trace options);
wenzelm
parents: 58950
diff changeset
    39
fun res_inst_tac_term' ctxt =
60792
722cb21ab680 updated to infer_instantiate;
wenzelm
parents: 60754
diff changeset
    40
  gen_res_inst_tac_term ctxt
722cb21ab680 updated to infer_instantiate;
wenzelm
parents: 60754
diff changeset
    41
    (fn _ => fn inst => infer_instantiate ctxt (map (apfst (#1 o dest_Var)) inst)) [];
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    42
58950
d07464875dd4 optional proof context for unify operations, for the sake of proper local options;
wenzelm
parents: 58318
diff changeset
    43
fun cut_inst_tac_term' ctxt tinst th =
58956
a816aa3ff391 proper context for compose_tac, Splitter.split_tac (relevant for unify trace options);
wenzelm
parents: 58950
diff changeset
    44
  res_inst_tac_term' ctxt tinst false (Rule_Insts.make_elim_preserve ctxt th);
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    45
26337
44473c957672 auxiliary dynamic_thm(s) for fact lookup;
wenzelm
parents: 24558
diff changeset
    46
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
    47
  Global_Theory.get_thm thy name handle ERROR _ =>
27187
17b63e145986 use regular error function;
wenzelm
parents: 26343
diff changeset
    48
    error ("The atom type "^atom_name^" is not defined.");
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    49
24558
419f7cde7f59 some cleaning up
urbanc
parents: 24271
diff changeset
    50
(* The theorems needed that are known at compile time. *)
419f7cde7f59 some cleaning up
urbanc
parents: 24271
diff changeset
    51
val at_exists_fresh' = @{thm "at_exists_fresh'"};
419f7cde7f59 some cleaning up
urbanc
parents: 24271
diff changeset
    52
val fresh_fun_app'   = @{thm "fresh_fun_app'"};
419f7cde7f59 some cleaning up
urbanc
parents: 24271
diff changeset
    53
val fresh_prod       = @{thm "fresh_prod"};
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    54
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
    55
(* A tactic to generate a name fresh for  all the free *)
24558
419f7cde7f59 some cleaning up
urbanc
parents: 24271
diff changeset
    56
(* variables and parameters of the goal                *)
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    57
56230
3e449273942a more standard method_setup;
wenzelm
parents: 55952
diff changeset
    58
fun generate_fresh_tac ctxt atom_name = SUBGOAL (fn (goal, _) =>
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
    59
 let
56230
3e449273942a more standard method_setup;
wenzelm
parents: 55952
diff changeset
    60
   val thy = Proof_Context.theory_of ctxt;
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    61
(* 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
    62
   val atom_basename = Long_Name.base_name atom_name;
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    63
   val ps = Logic.strip_params goal;
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    64
   val Ts = rev (map snd ps);
35667
aa59452c913c tuned -- eliminated Sign.intern_sort;
wenzelm
parents: 35360
diff changeset
    65
   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
    66
(* rebuild de bruijn indices *)
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    67
   val bvs = map_index (Bound o fst) ps;
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    68
(* select variables of the right class *)
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    69
   val vs = filter (fn t => is_of_fs_name (fastype_of1 (Ts, t)))
44121
44adaa6db327 old term operations are legacy;
wenzelm
parents: 43278
diff changeset
    70
     (Misc_Legacy.term_frees goal @ bvs);
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    71
(* build the tuple *)
23368
ad690b9bca1c generate_fresh works even if there is no free variable in the goal
narboux
parents: 23094
diff changeset
    72
   val s = (Library.foldr1 (fn (v, s) =>
41519
0940fff556a6 avoid catch-all exception handler, presumably TERM was meant here;
wenzelm
parents: 39557
diff changeset
    73
       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
    74
     handle TERM _ => HOLogic.unit;
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    75
   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
    76
   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
    77
   val exists_fresh' = at_name_inst_thm RS at_exists_fresh';
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    78
(* find the variable we want to instantiate *)
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59058
diff changeset
    79
   val x = hd (Misc_Legacy.term_vars (Thm.prop_of exists_fresh'));
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
    80
 in
56230
3e449273942a more standard method_setup;
wenzelm
parents: 55952
diff changeset
    81
   fn st =>
58950
d07464875dd4 optional proof context for unify operations, for the sake of proper local options;
wenzelm
parents: 58318
diff changeset
    82
   (cut_inst_tac_term' ctxt [(x,s)] exists_fresh' 1 THEN
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
    83
   resolve_tac ctxt [fs_name_thm] 1 THEN
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
    84
   eresolve_tac ctxt [exE] 1) st
56230
3e449273942a more standard method_setup;
wenzelm
parents: 55952
diff changeset
    85
  handle List.Empty  => all_tac st (* if we collected no variables then we do nothing *)
3e449273942a more standard method_setup;
wenzelm
parents: 55952
diff changeset
    86
 end) 1;
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    87
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    88
fun get_inner_fresh_fun (Bound j) = NONE
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
    89
  | get_inner_fresh_fun (v as Free _) = NONE
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    90
  | get_inner_fresh_fun (v as Var _)  = NONE
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    91
  | get_inner_fresh_fun (Const _) = NONE
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
    92
  | get_inner_fresh_fun (Abs (_, _, t)) = get_inner_fresh_fun t
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 60792
diff changeset
    93
  | get_inner_fresh_fun (Const (\<^const_name>\<open>Nominal.fresh_fun\<close>,
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 60792
diff changeset
    94
      Type(\<^type_name>\<open>fun\<close>,[Type (\<^type_name>\<open>fun\<close>,[Type (T,_),_]),_])) $ u) = SOME T
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
    95
  | get_inner_fresh_fun (t $ u) =
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    96
     let val a = get_inner_fresh_fun u in
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
    97
     if a = NONE then get_inner_fresh_fun t else a
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    98
     end;
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
    99
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
   100
(* This tactic generates a fresh name of the atom type *)
24558
419f7cde7f59 some cleaning up
urbanc
parents: 24271
diff changeset
   101
(* given by the innermost fresh_fun                    *)
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
   102
56230
3e449273942a more standard method_setup;
wenzelm
parents: 55952
diff changeset
   103
fun generate_fresh_fun_tac ctxt = SUBGOAL (fn (goal, _) =>
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
   104
  let
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
   105
    val atom_name_opt = get_inner_fresh_fun goal;
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
   106
  in
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
   107
  case atom_name_opt of
56230
3e449273942a more standard method_setup;
wenzelm
parents: 55952
diff changeset
   108
    NONE => all_tac
3e449273942a more standard method_setup;
wenzelm
parents: 55952
diff changeset
   109
  | SOME atom_name  => generate_fresh_tac ctxt atom_name
3e449273942a more standard method_setup;
wenzelm
parents: 55952
diff changeset
   110
  end) 1;
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
   111
58318
f95754ca7082 fixed some spelling mistakes
blanchet
parents: 56253
diff changeset
   112
(* Two substitution tactics which looks for the innermost occurrence in
23091
c91530f18d9c add an option in fresh_fun_simp to prevent rewriting in assumptions
narboux
parents: 23065
diff changeset
   113
   one assumption or in the conclusion *)
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
   114
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
   115
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
   116
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
   117
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
   118
fun subst_inner_tac ctxt = EqSubst.eqsubst_tac' ctxt search_fun;
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
   119
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
   120
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
   121
(* A tactic to substitute in the first assumption
58318
f95754ca7082 fixed some spelling mistakes
blanchet
parents: 56253
diff changeset
   122
   which contains an occurrence. *)
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
   123
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
   124
fun subst_inner_asm_tac ctxt th =
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
   125
  curry (curry (FIRST' (map uncurry (map uncurry (map subst_inner_asm_tac_aux
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
   126
            (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
   127
56230
3e449273942a more standard method_setup;
wenzelm
parents: 55952
diff changeset
   128
fun fresh_fun_tac ctxt no_asm = SUBGOAL (fn (goal, i) =>
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
   129
  (* Find the variable we instantiate *)
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
   130
  let
56230
3e449273942a more standard method_setup;
wenzelm
parents: 55952
diff changeset
   131
    val thy = Proof_Context.theory_of ctxt;
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
   132
    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
   133
    val fresh_perm_app = Global_Theory.get_thms thy "fresh_perm_app";
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51669
diff changeset
   134
    val simp_ctxt =
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51669
diff changeset
   135
      ctxt addsimps (fresh_prod :: abs_fresh)
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51669
diff changeset
   136
      addsimps fresh_perm_app;
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59058
diff changeset
   137
    val x = hd (tl (Misc_Legacy.term_vars (Thm.prop_of exI)));
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
   138
    val atom_name_opt = get_inner_fresh_fun goal;
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
   139
    val n = length (Logic.strip_params goal);
24558
419f7cde7f59 some cleaning up
urbanc
parents: 24271
diff changeset
   140
    (* Here we rely on the fact that the variable introduced by generate_fresh_tac *)
419f7cde7f59 some cleaning up
urbanc
parents: 24271
diff changeset
   141
    (* is the last one in the list, the inner one *)
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
   142
  in
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
   143
  case atom_name_opt of
56230
3e449273942a more standard method_setup;
wenzelm
parents: 55952
diff changeset
   144
    NONE => all_tac
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
   145
  | SOME atom_name =>
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
   146
  let
30364
577edc39b501 moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents: 30280
diff changeset
   147
    val atom_basename = Long_Name.base_name atom_name;
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
   148
    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
   149
    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
   150
    fun inst_fresh vars params i st =
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59058
diff changeset
   151
   let val vars' = Misc_Legacy.term_vars (Thm.prop_of st);
33040
cffdb7b28498 removed old-style \ and \\ infixes
haftmann
parents: 33034
diff changeset
   152
   in case subtract (op =) vars vars' of
60642
48dd1cefb4ae simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents: 60359
diff changeset
   153
     [Var v] =>
60359
cb8828b859a1 clarified context;
wenzelm
parents: 59787
diff changeset
   154
      Seq.single
cb8828b859a1 clarified context;
wenzelm
parents: 59787
diff changeset
   155
        (Thm.instantiate ([],
60642
48dd1cefb4ae simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents: 60359
diff changeset
   156
          [(v, Thm.cterm_of ctxt (fold_rev Term.abs params (Bound 0)))]) st)
22787
85e7e32e6004 update fresh_fun_simp for debugging purposes
narboux
parents: 22774
diff changeset
   157
    | _ => error "fresh_fun_simp: Too many variables, please report."
46219
426ed18eba43 discontinued old-style Term.list_abs in favour of plain Term.abs;
wenzelm
parents: 44121
diff changeset
   158
   end
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
   159
  in
23091
c91530f18d9c add an option in fresh_fun_simp to prevent rewriting in assumptions
narboux
parents: 23065
diff changeset
   160
  ((fn st =>
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
   161
  let
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59058
diff changeset
   162
    val vars = Misc_Legacy.term_vars (Thm.prop_of st);
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59058
diff changeset
   163
    val params = Logic.strip_params (nth (Thm.prems_of st) (i-1))
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
   164
    (* 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
   165
       by the conditionnal rewrite rule. *)
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
   166
    val post_rewrite_tacs =
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
   167
          [resolve_tac ctxt [pt_name_inst],
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
   168
           resolve_tac ctxt [at_name_inst],
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51669
diff changeset
   169
           TRY o SOLVED' (NominalPermeq.finite_guess_tac simp_ctxt),
23054
d1bbe5afa279 change fresh_fun_simp to treat occurences in assumptions and try to solve the generated subgoals
narboux
parents: 22792
diff changeset
   170
           inst_fresh vars params THEN'
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51669
diff changeset
   171
           (TRY o SOLVED' (NominalPermeq.fresh_guess_tac simp_ctxt)) THEN'
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51669
diff changeset
   172
           (TRY o SOLVED' (asm_full_simp_tac simp_ctxt))]
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
   173
  in
23094
f1df8d2da98a fix a bug : the semantics of no_asm was the opposite
narboux
parents: 23091
diff changeset
   174
   ((if no_asm then no_tac else
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
   175
    (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
   176
    ORELSE
33034
66ef64a5f122 eliminated THENL -- use THEN RANGE;
wenzelm
parents: 32149
diff changeset
   177
    (subst_inner_tac ctxt fresh_fun_app' i THEN (RANGE post_rewrite_tacs i))) st
56230
3e449273942a more standard method_setup;
wenzelm
parents: 55952
diff changeset
   178
  end))
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
   179
  end
56230
3e449273942a more standard method_setup;
wenzelm
parents: 55952
diff changeset
   180
  end)
22729
69ef734825c5 add a tactic to generate fresh names
narboux
parents:
diff changeset
   181