src/Pure/IsaPlanner/isand.ML
author wenzelm
Tue, 07 Feb 2006 19:56:51 +0100
changeset 18969 49aa2c8791ba
parent 18678 dd0c569fa43d
child 19250 932a50e2332f
permissions -rw-r--r--
removed obsolete sign_of_cterm; adapted Sign.certify_term;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
     1
(* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- *) 
16179
fa7e70be26b0 header;
wenzelm
parents: 15959
diff changeset
     2
(*  Title:      Pure/IsaPlanner/isand.ML
fa7e70be26b0 header;
wenzelm
parents: 15959
diff changeset
     3
    ID:		$Id$
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
     4
    Author:     Lucas Dixon, University of Edinburgh
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
     5
                lucas.dixon@ed.ac.uk
15854
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
     6
    Updated:    26 Apr 2005
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
     7
    Date:       6 Aug 2004
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
     8
*)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
     9
(* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- *) 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    10
(*  DESCRIPTION:
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    11
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    12
    Natural Deduction tools
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    13
15854
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
    14
    For working with Isabelle theorems in a natural detuction style.
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    15
    ie, not having to deal with meta level quantified varaibles,
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    16
    instead, we work with newly introduced frees, and hide the
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    17
    "all"'s, exporting results from theorems proved with the frees, to
15854
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
    18
    solve the all cases of the previous goal. This allows resolution
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
    19
    to do proof search normally. 
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    20
15854
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
    21
    Note: A nice idea: allow exporting to solve any subgoal, thus
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    22
    allowing the interleaving of proof, or provide a structure for the
15854
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
    23
    ordering of proof, thus allowing proof attempts in parrell, but
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    24
    recording the order to apply things in.
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    25
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    26
    debugging tools:
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    27
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    28
    fun asm_mk t = (assume (cterm_of (Theory.sign_of (the_context())) t)); 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    29
    fun asm_read s =  
15854
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
    30
      (assume (read_cterm (Theory.sign_of (Context.the_context())) (s,propT)));
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    31
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    32
    THINK: are we really ok with our varify name w.r.t the prop - do
15854
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
    33
    we also need to avoid names in the hidden hyps? What about
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
    34
    unification contraints in flex-flex pairs - might they also have
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
    35
    extra free vars?
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    36
*)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    37
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    38
signature ISA_ND =
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    39
sig
15854
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
    40
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
    41
  (* export data *)
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    42
  datatype export = export of
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    43
           {gth: Thm.thm, (* initial goal theorem *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    44
            sgid: int, (* subgoal id which has been fixed etc *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    45
            fixes: Thm.cterm list, (* frees *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    46
            assumes: Thm.cterm list} (* assumptions *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    47
  val fixes_of_exp : export -> Thm.cterm list
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    48
  val export_back : export -> Thm.thm -> Thm.thm Seq.seq
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    49
  val export_solution : export -> Thm.thm -> Thm.thm
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    50
  val export_solutions : export list * Thm.thm -> Thm.thm
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    51
15854
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
    52
  (* inserting meta level params for frees in the conditions *)
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    53
  val allify_conditions :
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    54
      (Term.term -> Thm.cterm) ->
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    55
      (string * Term.typ) list -> Thm.thm -> Thm.thm * Thm.cterm list
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    56
  val allify_conditions' :
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    57
      (string * Term.typ) list -> Thm.thm -> Thm.thm * Thm.cterm list
15915
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
    58
  val assume_allified :
15928
66b165ee016c lucas - made clean unify smash unifiers so that when we get flex-flex constraints subst does not barf. Also added fix_vars_upto_idx to IsaND.
dixon
parents: 15924
diff changeset
    59
      Sign.sg -> (string * Term.sort) list * (string * Term.typ) list
15915
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
    60
      -> Term.term -> (Thm.cterm * Thm.thm)
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    61
15854
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
    62
  (* meta level fixed params (i.e. !! vars) *)
15915
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
    63
  val fix_alls_in_term : Term.term -> Term.term * Term.term list
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    64
  val fix_alls_term : int -> Term.term -> Term.term * Term.term list
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    65
  val fix_alls_cterm : int -> Thm.thm -> Thm.cterm * Thm.cterm list
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    66
  val fix_alls' : int -> Thm.thm -> Thm.thm * Thm.cterm list
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    67
  val fix_alls : int -> Thm.thm -> Thm.thm * export
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    68
15854
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
    69
  (* meta variables in types and terms *)
15915
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
    70
  val fix_tvars_to_tfrees_in_terms 
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
    71
      : string list (* avoid these names *)
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
    72
        -> Term.term list -> 
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
    73
        (((string * int) * Term.sort) * (string * Term.sort)) list (* renamings *)
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
    74
  val fix_vars_to_frees_in_terms
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
    75
      : string list (* avoid these names *)
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
    76
        -> Term.term list ->
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
    77
        (((string * int) * Term.typ) * (string * Term.typ)) list (* renamings *)
15854
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
    78
  val fix_tvars_to_tfrees : Thm.thm -> Thm.ctyp list * Thm.thm
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
    79
  val fix_vars_to_frees : Thm.thm -> Thm.cterm list * Thm.thm
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
    80
  val fix_vars_and_tvars : 
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
    81
      Thm.thm -> (Thm.cterm list * Thm.ctyp list) * Thm.thm
15928
66b165ee016c lucas - made clean unify smash unifiers so that when we get flex-flex constraints subst does not barf. Also added fix_vars_upto_idx to IsaND.
dixon
parents: 15924
diff changeset
    82
  val fix_vars_upto_idx : int -> Thm.thm -> Thm.thm
66b165ee016c lucas - made clean unify smash unifiers so that when we get flex-flex constraints subst does not barf. Also added fix_vars_upto_idx to IsaND.
dixon
parents: 15924
diff changeset
    83
  val fix_tvars_upto_idx : int -> Thm.thm -> Thm.thm
15854
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
    84
  val unfix_frees : Thm.cterm list -> Thm.thm -> Thm.thm
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
    85
  val unfix_tfrees : Thm.ctyp list -> Thm.thm -> Thm.thm
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
    86
  val unfix_frees_and_tfrees :
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
    87
      (Thm.cterm list * Thm.ctyp list) -> Thm.thm -> Thm.thm
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    88
15854
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
    89
  (* assumptions/subgoals *)
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
    90
  val assume_prems :
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
    91
      int -> Thm.thm -> Thm.thm list * Thm.thm * Thm.cterm list
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    92
  val fixed_subgoal_thms : Thm.thm -> Thm.thm list * (Thm.thm list -> Thm.thm)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    93
  val fixes_and_assumes : int -> Thm.thm -> Thm.thm list * Thm.thm * export
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    94
  val hide_other_goals : Thm.thm -> Thm.thm * Thm.cterm list
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    95
  val hide_prems : Thm.thm -> Thm.thm * Thm.cterm list
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    96
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    97
  (* abstracts cterms (vars) to locally meta-all bounds *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    98
  val prepare_goal_export : string list * Thm.cterm list -> Thm.thm 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    99
                            -> int * Thm.thm
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   100
  val solve_with : Thm.thm -> Thm.thm -> Thm.thm Seq.seq
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   101
  val subgoal_thms : Thm.thm -> Thm.thm list * (Thm.thm list -> Thm.thm)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   102
end
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   103
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   104
15854
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
   105
structure IsaND 
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
   106
: ISA_ND
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
   107
= struct
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   108
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   109
(* Solve *some* subgoal of "th" directly by "sol" *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   110
(* Note: this is probably what Markus ment to do upon export of a
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   111
"show" but maybe he used RS/rtac instead, which would wrongly lead to
15854
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
   112
failing if there are premices to the shown goal. 
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
   113
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
   114
given: 
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
   115
sol : Thm.thm = [| Ai... |] ==> Ci
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
   116
th : Thm.thm = 
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
   117
  [| ... [| Ai... |] ==> Ci ... |] ==> G
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
   118
results in: 
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
   119
  [| ... [| Ai-1... |] ==> Ci-1
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
   120
    [| Ai+1... |] ==> Ci+1 ...
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
   121
  |] ==> G
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
   122
i.e. solves some subgoal of th that is identical to sol. 
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
   123
*)
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   124
fun solve_with sol th = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   125
    let fun solvei 0 = Seq.empty
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   126
          | solvei i = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   127
            Seq.append (bicompose false (false,sol,0) i th, 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   128
                        solvei (i - 1))
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   129
    in
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   130
      solvei (Thm.nprems_of th)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   131
    end;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   132
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   133
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   134
(* Given ctertmify function, (string,type) pairs capturing the free
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   135
vars that need to be allified in the assumption, and a theorem with
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   136
assumptions possibly containing the free vars, then we give back the
15854
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
   137
assumptions allified as hidden hyps. 
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
   138
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
   139
Given: x 
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   140
th: A vs ==> B vs 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   141
Results in: "B vs" [!!x. A x]
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   142
*)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   143
fun allify_conditions ctermify Ts th = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   144
    let 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   145
      val premts = Thm.prems_of th;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   146
    
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   147
      fun allify_prem_var (vt as (n,ty),t)  = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   148
          (Term.all ty) $ (Abs(n,ty,Term.abstract_over (Free vt, t)))
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   149
15574
b1d1b5bfc464 Removed practically all references to Library.foldr.
skalberg
parents: 15570
diff changeset
   150
      fun allify_prem Ts p = foldr allify_prem_var p Ts
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   151
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   152
      val cTs = map (ctermify o Free) Ts
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   153
      val cterm_asms = map (ctermify o allify_prem Ts) premts
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   154
      val allifyied_asm_thms = map (Drule.forall_elim_list cTs o Thm.assume) cterm_asms
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   155
    in 
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15531
diff changeset
   156
      (Library.foldl (fn (x,y) => y COMP x) (th, allifyied_asm_thms), cterm_asms)
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   157
    end;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   158
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   159
fun allify_conditions' Ts th = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   160
    allify_conditions (Thm.cterm_of (Thm.sign_of_thm th)) Ts th;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   161
15915
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   162
(* allify types *)
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   163
fun allify_typ ts ty = 
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   164
    let 
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   165
      fun trec (x as (TFree (s,srt))) = 
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   166
          (case Library.find_first (fn (s2,srt2) => s = s2) ts
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   167
            of NONE => x
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   168
             | SOME (s2,_) => TVar ((s,0),srt))
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   169
            (*  Maybe add in check here for bad sorts? 
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   170
             if srt = srt2 then TVar ((s,0),srt) 
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   171
               else raise  ("thaw_typ", ts, ty) *)
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   172
          | trec (Type (s,typs)) = Type (s, map trec typs)
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   173
          | trec (v as TVar _) = v;
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   174
    in trec ty end;
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   175
15924
ed29db71c631 eta-expansion
paulson
parents: 15915
diff changeset
   176
(* implicit types and term *)
ed29db71c631 eta-expansion
paulson
parents: 15915
diff changeset
   177
fun allify_term_typs ty = Term.map_term_types (allify_typ ty);
ed29db71c631 eta-expansion
paulson
parents: 15915
diff changeset
   178
15928
66b165ee016c lucas - made clean unify smash unifiers so that when we get flex-flex constraints subst does not barf. Also added fix_vars_upto_idx to IsaND.
dixon
parents: 15924
diff changeset
   179
(* allified version of term, given frees to allify over. Note that we
66b165ee016c lucas - made clean unify smash unifiers so that when we get flex-flex constraints subst does not barf. Also added fix_vars_upto_idx to IsaND.
dixon
parents: 15924
diff changeset
   180
only allify over the types on the given allified cterm, we can't do
66b165ee016c lucas - made clean unify smash unifiers so that when we get flex-flex constraints subst does not barf. Also added fix_vars_upto_idx to IsaND.
dixon
parents: 15924
diff changeset
   181
this for the theorem as we are not allowed type-vars in the hyp. *)
66b165ee016c lucas - made clean unify smash unifiers so that when we get flex-flex constraints subst does not barf. Also added fix_vars_upto_idx to IsaND.
dixon
parents: 15924
diff changeset
   182
fun assume_allified sgn (tyvs,vs) t = 
15915
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   183
    let
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   184
      fun allify_var (vt as (n,ty),t)  = 
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   185
          (Term.all ty) $ (Abs(n,ty,Term.abstract_over (Free vt, t)))
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   186
      fun allify Ts p = List.foldr allify_var p Ts
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   187
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   188
      val ctermify = Thm.cterm_of sgn;
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   189
      val cvars = map (fn (n,ty) => ctermify (Var ((n,0),ty))) vs
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   190
      val allified_term = t |> allify vs;
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   191
      val ct = ctermify allified_term;
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   192
      val typ_allified_ct = ctermify (allify_term_typs tyvs allified_term);
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   193
    in (typ_allified_ct, 
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   194
        Drule.forall_elim_vars 0 (Thm.assume ct)) end;
15854
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
   195
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
   196
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
   197
(* change type-vars to fresh type frees *)
15915
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   198
fun fix_tvars_to_tfrees_in_terms names ts = 
15854
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
   199
    let 
15915
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   200
      val tfree_names = map fst (List.foldr Term.add_term_tfrees [] ts);
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   201
      val tvars = List.foldr Term.add_term_tvars [] ts;
15854
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
   202
      val (names',renamings) = 
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
   203
          List.foldr (fn (tv as ((n,i),s),(Ns,Rs)) => 
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
   204
                         let val n2 = Term.variant Ns n in 
15915
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   205
                           (n2::Ns, (tv, (n2,s))::Rs)
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   206
                         end) (tfree_names @ names,[]) tvars;
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   207
    in renamings end;
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   208
fun fix_tvars_to_tfrees th = 
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   209
    let 
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   210
      val sign = Thm.sign_of_thm th;
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   211
      val ctypify = Thm.ctyp_of sign;
15959
366d39e95d3c lucas - fixed bug with uninstantiated type contexts in eqsubst and added the automatic removal of duplicate subgoals (when there are no flex-flex constraints)
dixon
parents: 15928
diff changeset
   212
      val tpairs = Thm.terms_of_tpairs (Thm.tpairs_of th);
366d39e95d3c lucas - fixed bug with uninstantiated type contexts in eqsubst and added the automatic removal of duplicate subgoals (when there are no flex-flex constraints)
dixon
parents: 15928
diff changeset
   213
      val renamings = fix_tvars_to_tfrees_in_terms 
366d39e95d3c lucas - fixed bug with uninstantiated type contexts in eqsubst and added the automatic removal of duplicate subgoals (when there are no flex-flex constraints)
dixon
parents: 15928
diff changeset
   214
                        [] ((Thm.prop_of th) :: tpairs);
15915
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   215
      val crenamings = 
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   216
          map (fn (v,f) => (ctypify (TVar v), ctypify (TFree f)))
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   217
              renamings;
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   218
      val fixedfrees = map snd crenamings;
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   219
    in (fixedfrees, Thm.instantiate (crenamings, []) th) end;
15854
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
   220
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
   221
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
   222
(* change type-free's to type-vars *)
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
   223
fun unfix_tfrees ns th = 
15915
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   224
    let 
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   225
      val varfiytfrees = (map (fn x => Term.dest_TFree (Thm.typ_of x)) ns)
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   226
      val skiptfrees = Term.add_term_tfrees (Thm.prop_of th,[]) \\ varfiytfrees;
18127
9f03d8a9a81b Thm.varifyT': natural argument order;
wenzelm
parents: 17970
diff changeset
   227
    in #2 (Thm.varifyT' skiptfrees th) end;
15854
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
   228
15915
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   229
(* change schematic/meta vars to fresh free vars *)
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   230
fun fix_vars_to_frees_in_terms names ts = 
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   231
    let 
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   232
      val vars = map Term.dest_Var (List.foldr Term.add_term_vars [] ts);
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   233
      val Ns = List.foldr Term.add_term_names names ts;
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   234
      val (_,renamings) = 
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   235
          Library.foldl (fn ((Ns,Rs),v as ((n,i),ty)) => 
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   236
                    let val n2 = Term.variant Ns n in
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   237
                      (n2 :: Ns, (v, (n2,ty)) :: Rs)
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   238
                    end) ((Ns,[]), vars);
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   239
    in renamings end;
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   240
fun fix_vars_to_frees th = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   241
    let 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   242
      val ctermify = Thm.cterm_of (Thm.sign_of_thm th)
15959
366d39e95d3c lucas - fixed bug with uninstantiated type contexts in eqsubst and added the automatic removal of duplicate subgoals (when there are no flex-flex constraints)
dixon
parents: 15928
diff changeset
   243
      val tpairs = Thm.terms_of_tpairs (Thm.tpairs_of th);
366d39e95d3c lucas - fixed bug with uninstantiated type contexts in eqsubst and added the automatic removal of duplicate subgoals (when there are no flex-flex constraints)
dixon
parents: 15928
diff changeset
   244
      val renamings = fix_vars_to_frees_in_terms 
366d39e95d3c lucas - fixed bug with uninstantiated type contexts in eqsubst and added the automatic removal of duplicate subgoals (when there are no flex-flex constraints)
dixon
parents: 15928
diff changeset
   245
                        [] ([Thm.prop_of th] @ tpairs);
15915
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   246
      val crenamings = 
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   247
          map (fn (v,f) => (ctermify (Var v), ctermify (Free f)))
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   248
              renamings;
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   249
      val fixedfrees = map snd crenamings;
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   250
    in (fixedfrees, Thm.instantiate ([], crenamings) th) end;
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   251
15928
66b165ee016c lucas - made clean unify smash unifiers so that when we get flex-flex constraints subst does not barf. Also added fix_vars_upto_idx to IsaND.
dixon
parents: 15924
diff changeset
   252
fun fix_tvars_upto_idx ix th = 
66b165ee016c lucas - made clean unify smash unifiers so that when we get flex-flex constraints subst does not barf. Also added fix_vars_upto_idx to IsaND.
dixon
parents: 15924
diff changeset
   253
    let 
66b165ee016c lucas - made clean unify smash unifiers so that when we get flex-flex constraints subst does not barf. Also added fix_vars_upto_idx to IsaND.
dixon
parents: 15924
diff changeset
   254
      val sgn = Thm.sign_of_thm th;
66b165ee016c lucas - made clean unify smash unifiers so that when we get flex-flex constraints subst does not barf. Also added fix_vars_upto_idx to IsaND.
dixon
parents: 15924
diff changeset
   255
      val ctypify = Thm.ctyp_of sgn
15959
366d39e95d3c lucas - fixed bug with uninstantiated type contexts in eqsubst and added the automatic removal of duplicate subgoals (when there are no flex-flex constraints)
dixon
parents: 15928
diff changeset
   256
      val tpairs = Thm.terms_of_tpairs (Thm.tpairs_of th);
15928
66b165ee016c lucas - made clean unify smash unifiers so that when we get flex-flex constraints subst does not barf. Also added fix_vars_upto_idx to IsaND.
dixon
parents: 15924
diff changeset
   257
      val prop = (Thm.prop_of th);
15959
366d39e95d3c lucas - fixed bug with uninstantiated type contexts in eqsubst and added the automatic removal of duplicate subgoals (when there are no flex-flex constraints)
dixon
parents: 15928
diff changeset
   258
      val tvars = List.foldr Term.add_term_tvars [] (prop :: tpairs);
15928
66b165ee016c lucas - made clean unify smash unifiers so that when we get flex-flex constraints subst does not barf. Also added fix_vars_upto_idx to IsaND.
dixon
parents: 15924
diff changeset
   259
      val ctyfixes = 
66b165ee016c lucas - made clean unify smash unifiers so that when we get flex-flex constraints subst does not barf. Also added fix_vars_upto_idx to IsaND.
dixon
parents: 15924
diff changeset
   260
          Library.mapfilter 
66b165ee016c lucas - made clean unify smash unifiers so that when we get flex-flex constraints subst does not barf. Also added fix_vars_upto_idx to IsaND.
dixon
parents: 15924
diff changeset
   261
            (fn (v as ((s,i),ty)) => 
66b165ee016c lucas - made clean unify smash unifiers so that when we get flex-flex constraints subst does not barf. Also added fix_vars_upto_idx to IsaND.
dixon
parents: 15924
diff changeset
   262
                if i <= ix then SOME (ctypify (TVar v), ctypify (TFree (s,ty)))
66b165ee016c lucas - made clean unify smash unifiers so that when we get flex-flex constraints subst does not barf. Also added fix_vars_upto_idx to IsaND.
dixon
parents: 15924
diff changeset
   263
                else NONE) tvars;
66b165ee016c lucas - made clean unify smash unifiers so that when we get flex-flex constraints subst does not barf. Also added fix_vars_upto_idx to IsaND.
dixon
parents: 15924
diff changeset
   264
    in Thm.instantiate (ctyfixes, []) th end;
66b165ee016c lucas - made clean unify smash unifiers so that when we get flex-flex constraints subst does not barf. Also added fix_vars_upto_idx to IsaND.
dixon
parents: 15924
diff changeset
   265
fun fix_vars_upto_idx ix th = 
66b165ee016c lucas - made clean unify smash unifiers so that when we get flex-flex constraints subst does not barf. Also added fix_vars_upto_idx to IsaND.
dixon
parents: 15924
diff changeset
   266
    let 
66b165ee016c lucas - made clean unify smash unifiers so that when we get flex-flex constraints subst does not barf. Also added fix_vars_upto_idx to IsaND.
dixon
parents: 15924
diff changeset
   267
      val sgn = Thm.sign_of_thm th;
66b165ee016c lucas - made clean unify smash unifiers so that when we get flex-flex constraints subst does not barf. Also added fix_vars_upto_idx to IsaND.
dixon
parents: 15924
diff changeset
   268
      val ctermify = Thm.cterm_of sgn
15959
366d39e95d3c lucas - fixed bug with uninstantiated type contexts in eqsubst and added the automatic removal of duplicate subgoals (when there are no flex-flex constraints)
dixon
parents: 15928
diff changeset
   269
      val tpairs = Thm.terms_of_tpairs (Thm.tpairs_of th);
15928
66b165ee016c lucas - made clean unify smash unifiers so that when we get flex-flex constraints subst does not barf. Also added fix_vars_upto_idx to IsaND.
dixon
parents: 15924
diff changeset
   270
      val prop = (Thm.prop_of th);
15959
366d39e95d3c lucas - fixed bug with uninstantiated type contexts in eqsubst and added the automatic removal of duplicate subgoals (when there are no flex-flex constraints)
dixon
parents: 15928
diff changeset
   271
      val vars = map Term.dest_Var (List.foldr Term.add_term_vars 
366d39e95d3c lucas - fixed bug with uninstantiated type contexts in eqsubst and added the automatic removal of duplicate subgoals (when there are no flex-flex constraints)
dixon
parents: 15928
diff changeset
   272
                                               [] (prop :: tpairs));
15928
66b165ee016c lucas - made clean unify smash unifiers so that when we get flex-flex constraints subst does not barf. Also added fix_vars_upto_idx to IsaND.
dixon
parents: 15924
diff changeset
   273
      val cfixes = 
66b165ee016c lucas - made clean unify smash unifiers so that when we get flex-flex constraints subst does not barf. Also added fix_vars_upto_idx to IsaND.
dixon
parents: 15924
diff changeset
   274
          Library.mapfilter 
66b165ee016c lucas - made clean unify smash unifiers so that when we get flex-flex constraints subst does not barf. Also added fix_vars_upto_idx to IsaND.
dixon
parents: 15924
diff changeset
   275
            (fn (v as ((s,i),ty)) => 
66b165ee016c lucas - made clean unify smash unifiers so that when we get flex-flex constraints subst does not barf. Also added fix_vars_upto_idx to IsaND.
dixon
parents: 15924
diff changeset
   276
                if i <= ix then SOME (ctermify (Var v), ctermify (Free (s,ty)))
66b165ee016c lucas - made clean unify smash unifiers so that when we get flex-flex constraints subst does not barf. Also added fix_vars_upto_idx to IsaND.
dixon
parents: 15924
diff changeset
   277
                else NONE) vars;
66b165ee016c lucas - made clean unify smash unifiers so that when we get flex-flex constraints subst does not barf. Also added fix_vars_upto_idx to IsaND.
dixon
parents: 15924
diff changeset
   278
    in Thm.instantiate ([], cfixes) th end;
66b165ee016c lucas - made clean unify smash unifiers so that when we get flex-flex constraints subst does not barf. Also added fix_vars_upto_idx to IsaND.
dixon
parents: 15924
diff changeset
   279
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   280
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   281
(* make free vars into schematic vars with index zero *)
15854
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
   282
 fun unfix_frees frees = 
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   283
     apply (map (K (Drule.forall_elim_var 0)) frees) 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   284
     o Drule.forall_intr_list frees;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   285
15854
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
   286
(* fix term and type variables *)
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
   287
fun fix_vars_and_tvars th = 
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
   288
    let val (tvars, th') = fix_tvars_to_tfrees th
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
   289
      val (vars, th'') = fix_vars_to_frees th' 
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
   290
    in ((vars, tvars), th'') end;
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
   291
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
   292
(* implicit Thm.thm argument *)
15959
366d39e95d3c lucas - fixed bug with uninstantiated type contexts in eqsubst and added the automatic removal of duplicate subgoals (when there are no flex-flex constraints)
dixon
parents: 15928
diff changeset
   293
(* assumes: vars may contain fixed versions of the frees *)
366d39e95d3c lucas - fixed bug with uninstantiated type contexts in eqsubst and added the automatic removal of duplicate subgoals (when there are no flex-flex constraints)
dixon
parents: 15928
diff changeset
   294
(* THINK: what if vs already has types varified? *)
15854
1ae0a47dcccd lucas - improved comments, clarified function behaviour, added missing functions for working with meta variables.
dixon
parents: 15574
diff changeset
   295
fun unfix_frees_and_tfrees (vs,tvs) = 
15959
366d39e95d3c lucas - fixed bug with uninstantiated type contexts in eqsubst and added the automatic removal of duplicate subgoals (when there are no flex-flex constraints)
dixon
parents: 15928
diff changeset
   296
    (unfix_tfrees tvs o unfix_frees vs);
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   297
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   298
(* datatype to capture an exported result, ie a fix or assume. *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   299
datatype export = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   300
         export of {fixes : Thm.cterm list, (* fixed vars *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   301
                    assumes : Thm.cterm list, (* hidden hyps/assumed prems *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   302
                    sgid : int,
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   303
                    gth :  Thm.thm}; (* subgoal/goalthm *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   304
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   305
fun fixes_of_exp (export rep) = #fixes rep;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   306
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   307
(* export the result of the new goal thm, ie if we reduced teh
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   308
subgoal, then we get a new reduced subtgoal with the old
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   309
all-quantified variables *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   310
local 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   311
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   312
(* allify puts in a meta level univ quantifier for a free variavble *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   313
fun allify_term (v, t) = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   314
    let val vt = #t (Thm.rep_cterm v)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   315
      val (n,ty) = Term.dest_Free vt
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   316
    in (Term.all ty) $ (Abs(n,ty,Term.abstract_over (vt, t))) end;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   317
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   318
fun allify_for_sg_term ctermify vs t =
15574
b1d1b5bfc464 Removed practically all references to Library.foldr.
skalberg
parents: 15570
diff changeset
   319
    let val t_alls = foldr allify_term t vs;
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   320
        val ct_alls = ctermify t_alls; 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   321
    in 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   322
      (ct_alls, Drule.forall_elim_list vs (Thm.assume ct_alls))
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   323
    end;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   324
(* lookup type of a free var name from a list *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   325
fun lookupfree vs vn  = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   326
    case Library.find_first (fn (n,ty) => n = vn) vs of 
18678
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18330
diff changeset
   327
      NONE => error ("prepare_goal_export:lookupfree: " ^ vn ^ " does not occur in the term")
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15481
diff changeset
   328
    | SOME x => x;
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   329
in
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   330
fun export_back (export {fixes = vs, assumes = hprems, 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   331
                         sgid = i, gth = gth}) newth = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   332
    let 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   333
      val sgn = Thm.sign_of_thm newth;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   334
      val ctermify = Thm.cterm_of sgn;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   335
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   336
      val sgs = prems_of newth;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   337
      val (sgallcts, sgthms) = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   338
          Library.split_list (map (allify_for_sg_term ctermify vs) sgs);
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   339
      val minimal_newth = 
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15531
diff changeset
   340
          (Library.foldl (fn ( newth', sgthm) => 
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   341
                          Drule.compose_single (sgthm, 1, newth'))
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   342
                      (newth, sgthms));
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   343
      val allified_newth = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   344
          minimal_newth 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   345
            |> Drule.implies_intr_list hprems
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   346
            |> Drule.forall_intr_list vs 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   347
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   348
      val newth' = Drule.implies_intr_list sgallcts allified_newth
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   349
    in
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   350
      bicompose false (false, newth', (length sgallcts)) i gth
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   351
    end;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   352
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   353
(* 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   354
Given "vs" : names of free variables to abstract over,
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   355
Given cterms : premices to abstract over (P1... Pn) in terms of vs,
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   356
Given a thm of the form: 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   357
P1 vs; ...; Pn vs ==> Goal(C vs)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   358
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   359
Gives back: 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   360
(n, length of given cterms which have been allified
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   361
 [| !! vs. P1 vs; !! vs. Pn vs |] ==> !! C vs) the allified thm
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   362
*)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   363
(* note: C may contain further premices etc 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   364
Note that cterms is the assumed facts, ie prems of "P1" that are
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   365
reintroduced in allified form.
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   366
*)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   367
fun prepare_goal_export (vs, cterms) th = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   368
    let 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   369
      val sgn = Thm.sign_of_thm th;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   370
      val ctermify = Thm.cterm_of sgn;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   371
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   372
      val allfrees = map Term.dest_Free (Term.term_frees (Thm.prop_of th))
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   373
      val cfrees = map (ctermify o Free o lookupfree allfrees) vs
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   374
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   375
      val sgs = prems_of th;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   376
      val (sgallcts, sgthms) = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   377
          Library.split_list (map (allify_for_sg_term ctermify cfrees) sgs);
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   378
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   379
      val minimal_th = 
17970
a84ac7c201ea Goal.conclude;
wenzelm
parents: 16179
diff changeset
   380
          Goal.conclude (Library.foldl (fn ( th', sgthm) => 
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   381
                          Drule.compose_single (sgthm, 1, th'))
17970
a84ac7c201ea Goal.conclude;
wenzelm
parents: 16179
diff changeset
   382
                      (th, sgthms));
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   383
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   384
      val allified_th = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   385
          minimal_th 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   386
            |> Drule.implies_intr_list cterms
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   387
            |> Drule.forall_intr_list cfrees 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   388
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   389
      val th' = Drule.implies_intr_list sgallcts allified_th
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   390
    in
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   391
      ((length sgallcts), th')
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   392
    end;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   393
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   394
end;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   395
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   396
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   397
(* exporting function that takes a solution to the fixed/assumed goal,
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   398
and uses this to solve the subgoal in the main theorem *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   399
fun export_solution (export {fixes = cfvs, assumes = hcprems,
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   400
                             sgid = i, gth = gth}) solth = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   401
    let 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   402
      val solth' = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   403
          solth |> Drule.implies_intr_list hcprems
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   404
                |> Drule.forall_intr_list cfvs
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   405
    in Drule.compose_single (solth', i, gth) end;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   406
15574
b1d1b5bfc464 Removed practically all references to Library.foldr.
skalberg
parents: 15570
diff changeset
   407
fun export_solutions (xs,th) = foldr (uncurry export_solution) th xs;
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   408
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   409
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   410
(* fix parameters of a subgoal "i", as free variables, and create an
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   411
exporting function that will use the result of this proved goal to
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   412
show the goal in the original theorem. 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   413
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   414
Note, an advantage of this over Isar is that it supports instantiation
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   415
of unkowns in the earlier theorem, ie we can do instantiation of meta
15915
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   416
vars! 
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   417
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   418
avoids constant, free and vars names. 
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   419
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   420
loosely corresponds to:
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   421
Given "[| SG0; ... !! x. As ==> SGi x; ... SGm |] ==> G" : thm
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   422
Result: 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   423
  ("(As ==> SGi x') ==> (As ==> SGi x')" : thm, 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   424
   expf : 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   425
     ("As ==> SGi x'" : thm) -> 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   426
     ("[| SG0; ... SGi-1; SGi+1; ... SGm |] ==> G") : thm)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   427
*)
15915
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   428
fun fix_alls_in_term alledt = 
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   429
    let
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   430
      val t = Term.strip_all_body alledt;
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   431
      val alls = rev (Term.strip_all_vars alledt);
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   432
      val varnames = map (fst o fst o Term.dest_Var) (Term.term_vars t)
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   433
      val names = Term.add_term_names (t,varnames);
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   434
      val fvs = map Free 
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   435
                    ((Term.variantlist (map fst alls, names)) 
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   436
                       ~~ (map snd alls));
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   437
    in ((subst_bounds (fvs,t)), fvs) end;
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   438
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   439
fun fix_alls_term i t = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   440
    let 
15915
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   441
      val varnames = map (fst o fst o Term.dest_Var) (Term.term_vars t)
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   442
      val names = Term.add_term_names (t,varnames);
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   443
      val gt = Logic.get_goal t i;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   444
      val body = Term.strip_all_body gt;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   445
      val alls = rev (Term.strip_all_vars gt);
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   446
      val fvs = map Free 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   447
                    ((Term.variantlist (map fst alls, names)) 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   448
                       ~~ (map snd alls));
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   449
    in ((subst_bounds (fvs,body)), fvs) end;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   450
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   451
fun fix_alls_cterm i th = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   452
    let
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   453
      val ctermify = Thm.cterm_of (Thm.sign_of_thm th);
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   454
      val (fixedbody, fvs) = fix_alls_term i (Thm.prop_of th);
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   455
      val cfvs = rev (map ctermify fvs);
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   456
      val ct_body = ctermify fixedbody
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   457
    in
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   458
      (ct_body, cfvs)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   459
    end;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   460
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   461
fun fix_alls' i = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   462
     (apfst Thm.trivial) o (fix_alls_cterm i);
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   463
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   464
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   465
(* hide other goals *) 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   466
(* note the export goal is rotated by (i - 1) and will have to be
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   467
unrotated to get backto the originial position(s) *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   468
fun hide_other_goals th = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   469
    let
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   470
      (* tl beacuse fst sg is the goal we are interested in *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   471
      val cprems = tl (Drule.cprems_of th)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   472
      val aprems = map Thm.assume cprems
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   473
    in
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   474
      (Drule.implies_elim_list (Drule.rotate_prems 1 th) aprems, 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   475
       cprems)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   476
    end;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   477
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   478
(* a nicer version of the above that leaves only a single subgoal (the
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   479
other subgoals are hidden hyps, that the exporter suffles about)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   480
namely the subgoal that we were trying to solve. *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   481
(* loosely corresponds to:
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   482
Given "[| SG0; ... !! x. As ==> SGi x; ... SGm |] ==> G" : thm
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   483
Result: 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   484
  ("(As ==> SGi x') ==> SGi x'" : thm, 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   485
   expf : 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   486
     ("SGi x'" : thm) -> 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   487
     ("[| SG0; ... SGi-1; SGi+1; ... SGm |] ==> G") : thm)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   488
*)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   489
fun fix_alls i th = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   490
    let 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   491
      val (fixed_gth, fixedvars) = fix_alls' i th
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   492
      val (sml_gth, othergoals) = hide_other_goals fixed_gth
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   493
    in
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   494
      (sml_gth, export {fixes = fixedvars, 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   495
                        assumes = othergoals, 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   496
                        sgid = i, gth = th})
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   497
    end;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   498
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   499
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   500
(* assume the premises of subgoal "i", this gives back a list of
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   501
assumed theorems that are the premices of subgoal i, it also gives
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   502
back a new goal thm and an exporter, the new goalthm is as the old
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   503
one, but without the premices, and the exporter will use a proof of
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   504
the new goalthm, possibly using the assumed premices, to shoe the
15915
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   505
orginial goal.
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   506
15915
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   507
Note: Dealing with meta vars, need to meta-level-all them in the
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   508
shyps, which we can later instantiate with a specific value.... ? 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   509
think about this... maybe need to introduce some new fixed vars and
15915
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   510
then remove them again at the end... like I do with rw_inst. 
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   511
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   512
loosely corresponds to:
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   513
Given "[| SG0; ... [| A0; ... An |] ==> SGi; ... SGm |] ==> G" : thm
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   514
Result: 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   515
(["A0" [A0], ... ,"An" [An]] : thm list, -- assumptions
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   516
 "SGi ==> SGi" : thm, -- new goal 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   517
 "SGi" ["A0" ... "An"] : thm ->   -- export function
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   518
    ("[| SG0 ... SGi-1, SGi+1, SGm |] ==> G" : thm) list)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   519
*)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   520
fun assume_prems i th =
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   521
    let 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   522
      val t = (prop_of th); 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   523
      val gt = Logic.get_goal t i;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   524
      val _ = case Term.strip_all_vars gt of [] => () 
18678
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18330
diff changeset
   525
              | _ => error "assume_prems: goal has params"
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   526
      val body = gt;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   527
      val prems = Logic.strip_imp_prems body;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   528
      val concl = Logic.strip_imp_concl body;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   529
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   530
      val sgn = Thm.sign_of_thm th;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   531
      val ctermify = Thm.cterm_of sgn;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   532
      val cprems = map ctermify prems;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   533
      val aprems = map Thm.assume cprems;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   534
      val gthi = Thm.trivial (ctermify concl);
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   535
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   536
      (* fun explortf thi = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   537
          Drule.compose (Drule.implies_intr_list cprems thi, 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   538
                         i, th) *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   539
    in
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   540
      (aprems, gthi, cprems)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   541
    end;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   542
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   543
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   544
(* first fix the variables, then assume the assumptions *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   545
(* loosely corresponds to:
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   546
Given 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   547
  "[| SG0; ... 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   548
      !! xs. [| A0 xs; ... An xs |] ==> SGi xs; 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   549
      ... SGm |] ==> G" : thm
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   550
Result: 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   551
(["A0 xs'" [A0 xs'], ... ,"An xs'" [An xs']] : thm list, -- assumptions
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   552
 "SGi xs' ==> SGi xs'" : thm,  -- new goal 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   553
 "SGi xs'" ["A0 xs'" ... "An xs'"] : thm ->   -- export function
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   554
    ("[| SG0 ... SGi-1, SGi+1, SGm |] ==> G" : thm) list)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   555
*)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   556
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   557
(* Note: the fix_alls actually pulls through all the assumptions which
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   558
means that the second export is not needed. *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   559
fun fixes_and_assumes i th = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   560
    let 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   561
      val (fixgth, exp1) = fix_alls i th
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   562
      val (assumps, goalth, _) = assume_prems 1 fixgth
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   563
    in 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   564
      (assumps, goalth, exp1)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   565
    end;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   566
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   567
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   568
(* Fixme: allow different order of subgoals given to expf *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   569
(* make each subgoal into a separate thm that needs to be proved *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   570
(* loosely corresponds to:
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   571
Given 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   572
  "[| SG0; ... SGm |] ==> G" : thm
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   573
Result: 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   574
(["SG0 ==> SG0", ... ,"SGm ==> SGm"] : thm list, -- goals
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   575
 ["SG0", ..., "SGm"] : thm list ->   -- export function
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   576
   "G" : thm)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   577
*)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   578
fun subgoal_thms th = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   579
    let 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   580
      val t = (prop_of th); 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   581
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   582
      val prems = Logic.strip_imp_prems t;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   583
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   584
      val sgn = Thm.sign_of_thm th;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   585
      val ctermify = Thm.cterm_of sgn;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   586
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   587
      val aprems = map (Thm.trivial o ctermify) prems;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   588
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   589
      fun explortf premths = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   590
          Drule.implies_elim_list th premths
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   591
    in
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   592
      (aprems, explortf)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   593
    end;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   594
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   595
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   596
(* make all the premices of a theorem hidden, and provide an unhide
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   597
function, that will bring them back out at a later point. This is
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   598
useful if you want to get back these premices, after having used the
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   599
theorem with the premices hidden *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   600
(* loosely corresponds to:
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   601
Given "As ==> G" : thm
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   602
Result: ("G [As]" : thm, 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   603
         "G [As]" : thm -> "As ==> G" : thm
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   604
*)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   605
fun hide_prems th = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   606
    let 
15915
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   607
      val cprems = Drule.cprems_of th;
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15854
diff changeset
   608
      val aprems = map Thm.assume cprems;
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   609
    (*   val unhidef = Drule.implies_intr_list cprems; *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   610
    in
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   611
      (Drule.implies_elim_list th aprems, cprems)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   612
    end;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   613
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   614
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   615
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   616
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   617
(* Fixme: allow different order of subgoals in exportf *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   618
(* as above, but also fix all parameters in all subgoals, and uses
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   619
fix_alls, not fix_alls', ie doesn't leave extra asumptions as apparent
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   620
subgoals. *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   621
(* loosely corresponds to:
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   622
Given 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   623
  "[| !! x0s. A0s x0s ==> SG0 x0s; 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   624
      ...; !! xms. Ams xms ==> SGm xms|] ==> G" : thm
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   625
Result: 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   626
(["(A0s x0s' ==> SG0 x0s') ==> SG0 x0s'", 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   627
  ... ,"(Ams xms' ==> SGm xms') ==> SGm xms'"] : thm list, -- goals
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   628
 ["SG0 x0s'", ..., "SGm xms'"] : thm list ->   -- export function
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   629
   "G" : thm)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   630
*)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   631
(* requires being given solutions! *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   632
fun fixed_subgoal_thms th = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   633
    let 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   634
      val (subgoals, expf) = subgoal_thms th;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   635
(*       fun export_sg (th, exp) = exp th; *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   636
      fun export_sgs expfs solthms = 
18330
444f16d232a2 introduced new map2, fold
haftmann
parents: 18127
diff changeset
   637
          expf (map2 (curry (op |>)) solthms expfs);
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   638
(*           expf (map export_sg (ths ~~ expfs)); *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   639
    in 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   640
      apsnd export_sgs (Library.split_list (map (apsnd export_solution o 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   641
                                                 fix_alls 1) subgoals))
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   642
    end;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   643
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   644
end;