src/Pure/IsaPlanner/isa_fterm.ML
author wenzelm
Mon, 04 Jul 2005 17:07:11 +0200
changeset 16677 6c038c13fd0f
parent 16179 fa7e70be26b0
child 17045 e108cd5b6986
permissions -rw-r--r--
use fast_string_ord;
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: 15915
diff changeset
     2
(*  Title:      Pure/IsaPlanner/isa_fterm.ML
fa7e70be26b0 header;
wenzelm
parents: 15915
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
                lucasd@dai.ed.ac.uk
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
     6
    Date:       16 April 2003
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
     7
*)
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
(*  DESCRIPTION:
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    10
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    11
    Generic Foucs terms (like Zippers) instantiation for Isabelle terms. 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    12
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    13
*)   
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    14
(* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    15
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    16
signature ISA_ENCODE_TERM = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    17
  F_ENCODE_TERM_SIG
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    18
    where type term = Term.term type TypeT = Term.typ;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    19
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    20
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    21
(* signature BASIC_ISA_FTERM = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    22
FOCUS_TERM_SIG where type Term = ISA_ENCODE_TERM.Term *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    23
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    24
signature ISA_FTERM =
15814
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
    25
  sig
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
    26
    type Term = EncodeIsaFTerm.TermT
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
    27
    type Type = Term.typ
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
    28
    type UpTerm
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
    29
    datatype FcTerm = focus of Term * UpTerm
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
    30
    structure MinTermS : F_ENCODE_TERM_SIG
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
    31
    val add_upterm :
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
    32
       UpTerm -> FcTerm -> FcTerm
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    33
    val clean_match_ft :
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    34
       Type.tsig ->
15814
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
    35
       Term.term ->
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    36
       FcTerm ->
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    37
       (
15915
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15814
diff changeset
    38
       ((Term.indexname * (Term.sort * Term.typ)) list 
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15814
diff changeset
    39
        * (Term.indexname * (Term.typ * Term.term)) list)
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15814
diff changeset
    40
       * (string * Term.typ) list 
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15814
diff changeset
    41
       * (string * Term.typ) list 
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15814
diff changeset
    42
       * Term.term)
15814
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
    43
       option
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    44
    val clean_unify_ft :
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    45
       Sign.sg ->
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    46
       int ->
15814
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
    47
       Term.term ->
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    48
       FcTerm ->
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    49
       (
15915
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15814
diff changeset
    50
       ((Term.indexname * (Term.sort * Term.typ)) list 
b0e8b37642a4 lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents: 15814
diff changeset
    51
        * (Term.indexname * (Term.typ * Term.term)) list)
15814
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
    52
       * (string * Term.typ) list * (string * Term.typ) list * Term.term)
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
    53
       Seq.seq
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
    54
    val enc_appl :
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
    55
       EncodeIsaFTerm.term * UpTerm -> UpTerm
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
    56
    val enc_appr :
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
    57
       EncodeIsaFTerm.term * UpTerm -> UpTerm
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
    58
    val fakefree_badbounds : 
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
    59
       (string * Term.typ) list -> Term.term ->
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
    60
       (string * Term.typ) list * (string * Term.typ) list * Term.term
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
    61
    val fcterm_of_term : EncodeIsaFTerm.term -> FcTerm
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    62
    val find_fcterm_matches :
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    63
       ((FcTerm -> 'a) -> FcTerm -> 'b) ->
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    64
       (FcTerm -> 'a) -> FcTerm -> 'b
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    65
    val find_sg_concl_matches :
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    66
       ((FcTerm -> 'a) -> FcTerm -> 'b) ->
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    67
       (FcTerm -> 'a) -> int -> EncodeIsaFTerm.term -> 'b
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    68
    val find_sg_concl_thm_matches :
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    69
       ((FcTerm -> 'a) -> FcTerm -> 'b) ->
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    70
       (FcTerm -> 'a) -> int -> Thm.thm -> 'b
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    71
    val find_sg_matches :
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    72
       ((FcTerm -> 'a) -> FcTerm -> 'b) ->
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    73
       (FcTerm -> 'a) -> int -> EncodeIsaFTerm.term -> 'b
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    74
    val find_sg_thm_matches :
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    75
       ((FcTerm -> 'a) -> FcTerm -> 'b) ->
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    76
       (FcTerm -> 'a) -> int -> Thm.thm -> 'b
15814
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
    77
    val focus_abs : FcTerm -> FcTerm
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
    78
    val focus_bot_left_leaf : FcTerm -> FcTerm
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
    79
    val focus_bot_left_nonabs_leaf :
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
    80
       FcTerm -> FcTerm
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
    81
    val focus_fake_abs : FcTerm -> FcTerm
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
    82
    val focus_left : FcTerm -> FcTerm
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
    83
    val focus_of_fcterm : FcTerm -> EncodeIsaFTerm.term
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
    84
    val focus_right : FcTerm -> FcTerm
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
    85
    val focus_strict_left : FcTerm -> FcTerm
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
    86
    exception focus_term_exp of string
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    87
    val focus_to_concl : FcTerm -> FcTerm
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    88
    val focus_to_concl_of_term : EncodeIsaFTerm.term -> FcTerm
15814
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
    89
    val focus_to_dest_impl :
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
    90
       FcTerm -> FcTerm * FcTerm
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    91
    val focus_to_subgoal :
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    92
       int -> FcTerm -> FcTerm
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    93
    val focus_to_subgoal_of_term :
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    94
       int -> EncodeIsaFTerm.term -> FcTerm
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    95
    val focus_to_term_goal_prem :
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
    96
       int * int -> EncodeIsaFTerm.term -> FcTerm
15814
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
    97
    val focus_to_top : FcTerm -> FcTerm
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
    98
    val focus_up : FcTerm -> FcTerm
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
    99
    val focus_up_abs : FcTerm -> FcTerm option
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   100
    val focus_up_abs_or_appr :
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   101
       FcTerm -> FcTerm option
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   102
    val focus_up_appl : FcTerm -> FcTerm option
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   103
    val focus_up_appr : FcTerm -> FcTerm option
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   104
    val focus_up_right : FcTerm -> FcTerm
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   105
    val focus_up_right1 : FcTerm -> FcTerm
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   106
    val focuseq_to_subgoals :
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   107
       FcTerm -> FcTerm Seq.seq
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   108
    exception isa_focus_term_exp of string
15814
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   109
    val leaf_seq_of_fcterm :
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   110
       FcTerm -> FcTerm Seq.seq
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   111
    val mk_foo_match :
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   112
       (Term.term -> Term.term) ->
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   113
       ('a * Term.typ) list -> Term.term -> Term.term
15814
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   114
    val mk_term_of_upterm :
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   115
       EncodeIsaFTerm.term * UpTerm -> EncodeIsaFTerm.term
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   116
    val mk_termf_of_upterm :
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   117
       UpTerm ->
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   118
       (string * Type) list *
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   119
       (EncodeIsaFTerm.term -> EncodeIsaFTerm.term)
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   120
    val next_leaf_fcterm : FcTerm -> FcTerm
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   121
    val next_leaf_of_fcterm_seq :
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   122
       FcTerm -> FcTerm Seq.seq
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   123
    exception out_of_term_exception of string
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   124
    val prepmatch :
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   125
       FcTerm ->
15814
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   126
       Term.term *
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   127
       ((string * Term.typ) list * (string * Term.typ) list * Term.term)
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   128
    val pretty_fcterm : FcTerm -> Pretty.T
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   129
    val pure_mk_termf_of_upterm :
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   130
       (EncodeIsaFTerm.term, Type) UpTermLib.T ->
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   131
       (string * Type) list *
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   132
       (EncodeIsaFTerm.term -> EncodeIsaFTerm.term)
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   133
    val search_all_bl_ru_f :
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   134
       (FcTerm -> 'a Seq.seq) ->
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   135
       FcTerm -> 'a Seq.seq
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   136
    val search_all_bl_ur_f :
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   137
       (FcTerm -> 'a Seq.seq) ->
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   138
       FcTerm -> 'a Seq.seq
15814
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   139
    val search_tlr_all_f :
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   140
       (FcTerm -> 'a Seq.seq) ->
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   141
       FcTerm -> 'a Seq.seq
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   142
    val search_tlr_valid_f :
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   143
       (FcTerm -> 'a Seq.seq) ->
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   144
       FcTerm -> 'a Seq.seq
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   145
    val search_valid_bl_ru_f :
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   146
       (FcTerm -> 'a Seq.seq) ->
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   147
       FcTerm -> 'a Seq.seq
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   148
    val search_valid_bl_ur_f :
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   149
       (FcTerm -> 'a Seq.seq) ->
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   150
       FcTerm -> 'a Seq.seq
15814
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   151
    val set_focus_of_fcterm :
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   152
       FcTerm -> EncodeIsaFTerm.term -> FcTerm
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   153
    val term_of_fcterm : FcTerm -> EncodeIsaFTerm.term
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   154
    val tyenv_of_focus :
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   155
       FcTerm -> (string * Type) list
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   156
    val tyenv_of_focus' : FcTerm -> Type list
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   157
    val upsize_of_fcterm : FcTerm -> int
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   158
    val upterm_of : FcTerm -> UpTerm
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   159
    val valid_match_start : FcTerm -> bool
15814
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   160
  end
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   161
15814
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   162
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   163
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   164
structure BasicIsaFTerm = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   165
FocusTermFUN( structure EncodeTerm = EncodeIsaFTerm);
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   166
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   167
(* HOL Dependent *)
15814
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   168
structure IsaFTerm : ISA_FTERM=
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   169
struct 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   170
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   171
(* include BasicIsaFTerm *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   172
(* open FocusTermFUN( structure EncodeTerm = EncodeIsaFTerm ); *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   173
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   174
open BasicIsaFTerm;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   175
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   176
15661
9ef583b08647 reverted renaming of Some/None in comments and strings;
wenzelm
parents: 15531
diff changeset
   177
(* Some general search within a focus term... *)
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   178
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   179
(* Note: only upterms with a free or constant are going to yeald a
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   180
match, thus if we get anything else (bound or var) skip it! This is
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   181
important if we switch to a unification net! in particular to avoid
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   182
vars. *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   183
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   184
fun valid_match_start ft =
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   185
    (case TermLib.bot_left_leaf_of (focus_of_fcterm ft) of 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   186
       Const _ => true
15814
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   187
     | Free _ => true
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   188
     | Abs _ => true (* allowed to look inside abs... search decides if we actually consider the abstraction itself *)
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   189
     | _ => false); (* avoid vars - always suceeds uninterestingly. *)
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   190
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   191
(* match starting at the bottom left, moving up to top of the term,
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   192
   then moving right to the next leaf and up again etc *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   193
(* FIXME: make properly lazy! *)
15814
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   194
fun search_valid_bl_ur_f f ft = 
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   195
    let 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   196
      val fts = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   197
          Seq.filter valid_match_start
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   198
                     (leaf_seq_of_fcterm ft)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   199
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   200
      fun mk_match_up_seq ft =
15814
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   201
          (* avoid abstractions? - possibly infinite unifiers? *)
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   202
          let val hereseq = case (focus_of_fcterm ft) of 
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   203
                              Abs _ => Seq.empty
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   204
                            | _ => f ft
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   205
          in
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   206
            case focus_up_abs_or_appr ft of 
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   207
              SOME ft' => Seq.append(hereseq, mk_match_up_seq ft')
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   208
            | NONE => hereseq
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   209
          end
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   210
    in
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   211
      Seq.flat (Seq.map mk_match_up_seq fts)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   212
    end;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   213
15814
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   214
fun search_all_bl_ur_f f ft = 
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   215
    let 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   216
      val fts = (leaf_seq_of_fcterm ft)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   217
15814
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   218
      fun mk_match_up_seq ft =            
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   219
          case focus_up_abs_or_appr ft of 
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15481
diff changeset
   220
            SOME ft' => Seq.append(f ft, mk_match_up_seq ft')
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15481
diff changeset
   221
          | NONE => f ft
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   222
    in
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   223
      Seq.flat (Seq.map mk_match_up_seq fts)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   224
    end;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   225
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   226
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   227
(* FIXME: make properly lazy! *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   228
(* FIXME: make faking of bound vars local - for speeeeed *)
15814
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   229
fun search_valid_bl_ru_f f ft = 
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   230
    let
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   231
      fun mauxtop ft = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   232
          if (valid_match_start ft)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   233
            then maux ft else Seq.empty
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   234
      and maux ft = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   235
          let val t' = (focus_of_fcterm ft) 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   236
          (* val _ = writeln ("Examining: " ^ (TermLib.string_of_term t')) *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   237
          in 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   238
          (case t' of 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   239
            (_ $ _) => Seq.append (maux (focus_left ft), 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   240
                         Seq.append(mauxtop (focus_right ft), 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   241
                                    f ft))
15814
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   242
          | (Abs _) => maux (focus_abs ft)
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   243
          | leaf => f ft) end
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   244
    in
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   245
      mauxtop ft
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   246
    end;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   247
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   248
15814
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   249
fun search_all_bl_ru_f f ft = 
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   250
    let
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   251
      fun maux ft = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   252
          let val t' = (focus_of_fcterm ft) 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   253
          (*   val _ = writeln ("Examining: " ^ (TermLib.string_of_term t')) *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   254
          in 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   255
          (case t' of 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   256
            (_ $ _) => Seq.append (maux (focus_left ft), 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   257
                         Seq.append(maux (focus_right ft), 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   258
                                    f ft))
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   259
          | (Abs _) => Seq.append (maux (focus_abs ft), 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   260
                                   f ft)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   261
          | leaf => f ft) end
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   262
    in maux ft end;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   263
15814
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   264
(* search from top, left to right, then down *)
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   265
fun search_tlr_all_f f ft = 
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   266
    let
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   267
      fun maux ft = 
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   268
          let val t' = (focus_of_fcterm ft) 
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   269
            (* val _ = 
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   270
                if !trace_subst_search then 
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   271
                  (writeln ("Examining: " ^ (TermLib.string_of_term t'));
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   272
                   TermLib.writeterm t'; ())
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   273
                else (); *)
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   274
          in 
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   275
          (case t' of 
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   276
            (_ $ _) => Seq.append(maux (focus_left ft), 
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   277
                       Seq.append(f ft, 
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   278
                                  maux (focus_right ft)))
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   279
          | (Abs _) => Seq.append(f ft, maux (focus_abs ft))
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   280
          | leaf => f ft) end
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   281
    in maux ft end;
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   282
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   283
fun search_tlr_valid_f f ft = 
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   284
    let
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   285
      fun maux ft = 
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   286
          let 
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   287
            val hereseq = if valid_match_start ft then f ft else Seq.empty
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   288
          in 
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   289
          (case (focus_of_fcterm ft) of 
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   290
            (_ $ _) => Seq.append(maux (focus_left ft), 
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   291
                       Seq.append(hereseq, 
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   292
                                  maux (focus_right ft)))
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   293
          | (Abs _) => Seq.append(hereseq, maux (focus_abs ft))
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   294
          | leaf => hereseq)
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   295
          end
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   296
    in maux ft end;
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   297
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   298
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   299
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   300
exception isa_focus_term_exp of string;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   301
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   302
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   303
fun focus_to_dest_impl ft = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   304
    let val (lhs, rhs) = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   305
            Logic.dest_implies (focus_of_fcterm ft) 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   306
    in (focus_left ft, focus_right ft) end
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   307
    handle Term.TERM _ => 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   308
           raise isa_focus_term_exp 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   309
                   "focus_to_dest_impl: applied to non implication";
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   310
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
(* move focus to the conlusion *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   313
fun focus_to_concl ft = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   314
    let val (lhs, rhs) = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   315
            Logic.dest_implies (focus_of_fcterm ft) 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   316
    in focus_to_concl (focus_right ft) end
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   317
    handle Term.TERM _ =>  ft;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   318
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   319
val focus_to_concl_of_term = focus_to_concl o fcterm_of_term;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   320
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   321
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   322
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   323
(* give back sequence of focuses at different subgoals *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   324
(* FIXME: make truly lazy *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   325
fun focuseq_to_subgoals ft = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   326
    if (Logic.is_implies (focus_of_fcterm ft)) then 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   327
      Seq.cons (focus_right (focus_left ft), focuseq_to_subgoals (focus_right ft))
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   328
    else
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   329
      Seq.empty;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   330
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   331
(* move focus to a specific subgoal, 0 is first  *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   332
fun focus_to_subgoal j ft = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   333
    let fun focus_to_subgoal' (ft, 0) = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   334
            let val (lhs, rhs) = Logic.dest_implies (focus_of_fcterm ft) 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   335
            in ft |> focus_left |> focus_right end
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   336
          | focus_to_subgoal' (ft, i) = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   337
            let val (lhs, rhs) = Logic.dest_implies (focus_of_fcterm ft) 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   338
            in focus_to_subgoal' (focus_right ft, i - 1) end
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   339
    in focus_to_subgoal' (ft, j - 1) end
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   340
    handle Term.TERM _ => 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   341
           raise isa_focus_term_exp 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   342
                   ("focus_to_subgoal: No such subgoal: " ^ 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   343
                    (string_of_int j));
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   344
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   345
fun focus_to_subgoal_of_term i t = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   346
    focus_to_subgoal i (fcterm_of_term t)
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
(* move focus to a specific premise *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   349
(* fun focus_past_params i ft = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   350
    (focus_to_subgoal (focus_right ft, i))
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   351
    handle isa_focus_term_exp _ => 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   352
           raise isa_focus_term_exp 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   353
             ("focus_to_prmise: No such premise: " ^ (string_of_int i)); *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   354
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   355
fun focus_to_term_goal_prem (premid,gaolid) t = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   356
    focus_to_subgoal premid (focus_to_subgoal_of_term gaolid t);
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   357
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   358
15814
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   359
(* FIXME: make a sturcture for holding free variable names and making
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   360
them distinct --- ? maybe part of the new prooftree datatype ?
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   361
Alos: use this to fix below... *)
15481
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
(* T is outer bound vars, n is number of locally bound vars *)
15814
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   364
(* THINK: is order of Ts correct...? or reversed? *)
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   365
fun fakefree_badbounds Ts t = 
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   366
    let val (FakeTs,Ts,newnames) = 
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   367
            List.foldr (fn ((n,ty),(FakeTs,Ts,usednames)) => 
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   368
                           let val newname = Term.variant usednames n
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   369
                           in ((RWTools.mk_fake_bound_name newname,ty)::FakeTs,
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   370
                               (newname,ty)::Ts, 
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   371
                               newname::usednames) end)
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   372
                       ([],[],[])
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   373
                       Ts
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   374
    in (FakeTs, Ts, Term.subst_bounds (map Free FakeTs, t)) end;
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   375
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   376
(* fun fakefree_badbounds usednames T n (a $ b) =  *)
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   377
(*     let val (usednames', T', a') = fakefree_badbounds usednames T n a *)
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   378
(*       val (usednames'', T'', b') = fakefree_badbounds usednames' T n b in  *)
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   379
(*       (usednames'', T'', a' $ b') end *)
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   380
(*   | fakefree_badbounds usednames T n (Abs(s,ty,t)) =  *)
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   381
(*     let val (usednames', T', t') = fakefree_badbounds usednames T (n + 1) t in *)
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   382
(*     (usednames', T', Abs(s,ty, t')) *)
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   383
(*   | fakefree_badbounds usednames T n (b as Bound i) =  *)
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   384
(*     let fun mkfake_bound j [] =  *)
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   385
(*             raise ERROR_MESSAGE "fakefree_badbounds: bound is outside of the known types!" *)
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   386
(*           | mkfake_bound 0 ((s,ty)::Ts) =  *)
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   387
(*             let val newname = Term.variant s usednames in *)
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   388
(*             usednames, (newname,ty) :: T,  Free (newname,ty) *)
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   389
(*           | mkfake_bound j (d::Ts) = mkfake_bound (j - 1) Ts *)
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   390
(*     in if n <= i then mkfake_bound (i - n) T else b end *)
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   391
(*   | fakefree_badbounds usednames T t = t; *)
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   392
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
(* note: outerterm is the taget with the match replaced by a bound 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   395
         variable : ie: "P lhs" beocmes "%x. P x" 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   396
         insts is the types of instantiations of vars in lhs
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   397
         and typinsts is the type instantiations of types in the lhs
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   398
         Note: Final rule is the rule lifted into the ontext of the 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   399
         taget thm. *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   400
fun mk_foo_match mkuptermfunc Ts t = 
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 ty = Term.type_of t
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   403
      val bigtype = (rev (map snd Ts)) ---> ty
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   404
      fun mk_foo 0 t = t
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   405
        | mk_foo i t = mk_foo (i - 1) (t $ (Bound (i - 1)))
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   406
      val num_of_bnds = (length Ts)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   407
      (* foo_term = "fooabs y0 ... yn" where y's are local bounds *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   408
      val foo_term = mk_foo num_of_bnds (Bound num_of_bnds)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   409
    in Abs("fooabs", bigtype, mkuptermfunc foo_term) end;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   410
15814
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   411
(* before matching we need to fake the bound vars that are missing an
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   412
abstraction. In this function we additionally construct the
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   413
abstraction environment, and an outer context term (with the focus
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   414
abstracted out) for use in rewriting with RWInst.rw *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   415
fun prepmatch ft = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   416
    let 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   417
      val t = focus_of_fcterm ft  
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   418
      val Ts = tyenv_of_focus ft
15814
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   419
      val (FakeTs', Ts', t') = fakefree_badbounds Ts t
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   420
      fun mktermf t = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   421
          term_of_fcterm (set_focus_of_fcterm ft t)
15814
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   422
      val absterm = mk_foo_match mktermf Ts' t'
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   423
    in
15814
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   424
      (t', (FakeTs', Ts', absterm))
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   425
    end;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   426
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   427
(* matching and unification for a focus term's focus *)
15814
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   428
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   429
(* Note: Ts is a modified version of the original names of the outer
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   430
bound variables. New names have been introduced to make sure they are
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   431
unique w.r.t all names in the term and each other. usednames' is
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   432
oldnames + new names. *)
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   433
fun clean_match_ft tsig pat ft = 
15814
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   434
    let val (t, (FakeTs,Ts,absterm)) = prepmatch ft in
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   435
      case TermLib.clean_match tsig (pat, t) of 
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15481
diff changeset
   436
        NONE => NONE 
15814
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   437
      | SOME insts => SOME (insts, FakeTs, Ts, absterm) end;
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   438
(* ix = max var index *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   439
fun clean_unify_ft sgn ix pat ft = 
15814
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   440
    let val (t, (FakeTs, Ts,absterm)) = prepmatch ft in
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   441
    Seq.map (fn insts => (insts, FakeTs, Ts, absterm)) 
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   442
            (TermLib.clean_unify sgn ix (t, pat)) end;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   443
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   444
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   445
(* THINK: ? do we not need to incremement bound indices? *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   446
(* THINK: it should be the search which localisaes the search to the
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   447
current focus, not this hack in the matcher... ? *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   448
(* find matches below this particular focus term *) 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   449
(* The search function is to find a match within a term... *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   450
(* the matcher is something that is applied to each node chosen by the
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   451
searchf and the results are flattened to form a lazy list. *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   452
fun find_fcterm_matches searchf matcher ft = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   453
    let 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   454
      val ftupterm = upterm_of ft
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   455
      val focusft = focus_of_fcterm ft
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   456
      val add_uptermf = add_upterm ftupterm 
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
    searchf
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   459
      (fn ft' => matcher (add_uptermf ft'))
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   460
      (fcterm_of_term focusft)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   461
    end;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   462
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   463
(* FIXME: move argument orders for efficiency... 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   464
i.e. wenzel style val foofunc = x o y;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   465
*)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   466
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   467
(* find the matches inside subgoal i of th *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   468
fun find_sg_matches searchf matcher i t = 
15814
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   469
    let 
d65f461c8672 lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents: 15661
diff changeset
   470
      val subgoal_fcterm = focus_to_subgoal_of_term i t
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   471
    in find_fcterm_matches searchf matcher subgoal_fcterm end;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   472
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   473
(* find the matches inside subgoal i of th *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   474
fun find_sg_thm_matches searchf matcher i th = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   475
    find_sg_matches searchf matcher i (Thm.prop_of th);
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   476
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
(* find the matches inside subgoal i's conclusion of th *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   479
fun find_sg_concl_matches searchf matcher i t = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   480
    let 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   481
      val subgoal_fcterm = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   482
          focus_to_concl (focus_to_subgoal_of_term i t)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   483
    in
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   484
      find_fcterm_matches searchf matcher subgoal_fcterm
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   485
    end;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   486
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   487
(* find the matches inside subgoal i's conclusion of th *)
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   488
fun find_sg_concl_thm_matches searchf matcher i th = 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   489
    find_sg_concl_matches searchf matcher i (Thm.prop_of th);
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   490
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   491
end;
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   492
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   493
(* 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   494
test... 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   495
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   496
f_encode_isatermS.encode (read "P a");
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   497
isafocustermS.fcterm_of_term (read "f a");
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   498
isafocustermS.term_of_fcterm it;
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
Goal "P b ==> P (suc b)";
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   501
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   502
TermLib.string_of_term ((focus_of_fcterm o focus_to_subgoal_of_term 1 o prop_of) (topthm()));
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   503
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   504
TermLib.string_of_term ((focus_of_fcterm o focus_to_concl o focus_to_subgoal_of_term 1 o prop_of) (topthm()));
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   505
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   506
TermLib.string_of_term ((focus_of_fcterm o focus_to_term_goal_prem (1,1) o prop_of) (topthm()));
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   507
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents:
diff changeset
   508
*)