src/Pure/logic.ML
author paulson
Mon, 24 Jan 2005 12:41:06 +0100
changeset 15454 4b339d3907a0
parent 15451 c6c8786b9921
child 15596 8665d08085df
permissions -rw-r--r--
thin_tac now works on P==>Q
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
     1
(*  Title:      Pure/logic.ML
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     2
    ID:         $Id$
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     4
    Copyright   Cambridge University 1992
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     5
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
     6
Abstract syntax operations of the Pure meta-logic.
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     7
*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     8
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     9
infix occs;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    10
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
    11
signature LOGIC =
4345
7e9436ffb813 tuned term order;
wenzelm
parents: 4318
diff changeset
    12
sig
5041
a1d0a6d555cd Goals may now contain assumptions, which are not returned.
nipkow
parents: 4822
diff changeset
    13
  val is_all            : term -> bool
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
    14
  val mk_equals         : term * term -> term
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
    15
  val dest_equals       : term -> term * term
3963
29c5ec9ecbaa Corrected alphabetical order of entries in signature.
nipkow
parents: 3915
diff changeset
    16
  val is_equals         : term -> bool
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
    17
  val mk_implies        : term * term -> term
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
    18
  val dest_implies      : term -> term * term
5041
a1d0a6d555cd Goals may now contain assumptions, which are not returned.
nipkow
parents: 4822
diff changeset
    19
  val is_implies        : term -> bool
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
    20
  val list_implies      : term list * term -> term
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
    21
  val strip_imp_prems   : term -> term list
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
    22
  val strip_imp_concl   : term -> term
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
    23
  val strip_prems       : int * term list * term -> term list * term
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
    24
  val count_prems       : term * int -> int
12137
6123958975b8 added mk_conjunction;
wenzelm
parents: 10816
diff changeset
    25
  val mk_conjunction    : term * term -> term
12757
b76a4376cfcb added mk_conjunction_list;
wenzelm
parents: 12137
diff changeset
    26
  val mk_conjunction_list: term list -> term
13659
3cf622f6b0b2 Removed obsolete functions dealing with flex-flex constraints.
berghofe
parents: 12902
diff changeset
    27
  val strip_horn        : term -> term list * term
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
    28
  val mk_cond_defpair   : term list -> term * term -> string * term
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
    29
  val mk_defpair        : term * term -> string * term
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
    30
  val mk_type           : typ -> term
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
    31
  val dest_type         : term -> typ
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
    32
  val mk_inclass        : typ * class -> term
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
    33
  val dest_inclass      : term -> typ * class
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
    34
  val goal_const        : term
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
    35
  val mk_goal           : term -> term
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
    36
  val dest_goal         : term -> term
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
    37
  val occs              : term * term -> bool
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
    38
  val close_form        : term -> term
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
    39
  val incr_indexes      : typ list * int -> term -> term
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
    40
  val lift_fns          : term * int -> (term -> term) * (term -> term)
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
    41
  val strip_assums_hyp  : term -> term list
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
    42
  val strip_assums_concl: term -> term
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
    43
  val strip_params      : term -> (string * typ) list
9667
48cefe2daf32 fixed has_meta_prems: strip_assums_hyp;
wenzelm
parents: 9483
diff changeset
    44
  val has_meta_prems    : term -> int -> bool
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
    45
  val flatten_params    : int -> term -> term
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
    46
  val auto_rename       : bool ref
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
    47
  val set_rename_prefix : string -> unit
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    48
  val list_rename_params: string list * term -> term
15454
4b339d3907a0 thin_tac now works on P==>Q
paulson
parents: 15451
diff changeset
    49
  val assum_pairs       : int * term -> (term*term)list
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
    50
  val varify            : term -> term
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
    51
  val unvarify          : term -> term
13799
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
    52
  val get_goal          : term -> int -> term
14107
215585ac94e2 Exported function goal_params.
berghofe
parents: 13799
diff changeset
    53
  val goal_params       : term -> int -> term * term list
13799
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
    54
  val prems_of_goal     : term -> int -> term list
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
    55
  val concl_of_goal     : term -> int -> term
4345
7e9436ffb813 tuned term order;
wenzelm
parents: 4318
diff changeset
    56
end;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    57
1500
b2de3b3277b8 Elimination of fully-functorial style.
paulson
parents: 1460
diff changeset
    58
structure Logic : LOGIC =
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    59
struct
398
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
    60
4345
7e9436ffb813 tuned term order;
wenzelm
parents: 4318
diff changeset
    61
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    62
(*** Abstract syntax operations on the meta-connectives ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    63
5041
a1d0a6d555cd Goals may now contain assumptions, which are not returned.
nipkow
parents: 4822
diff changeset
    64
(** all **)
a1d0a6d555cd Goals may now contain assumptions, which are not returned.
nipkow
parents: 4822
diff changeset
    65
a1d0a6d555cd Goals may now contain assumptions, which are not returned.
nipkow
parents: 4822
diff changeset
    66
fun is_all (Const ("all", _) $ _) = true
a1d0a6d555cd Goals may now contain assumptions, which are not returned.
nipkow
parents: 4822
diff changeset
    67
  | is_all _ = false;
a1d0a6d555cd Goals may now contain assumptions, which are not returned.
nipkow
parents: 4822
diff changeset
    68
a1d0a6d555cd Goals may now contain assumptions, which are not returned.
nipkow
parents: 4822
diff changeset
    69
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    70
(** equality **)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    71
1835
07eee14f5bd4 Restored warning comment
paulson
parents: 1500
diff changeset
    72
(*Make an equality.  DOES NOT CHECK TYPE OF u*)
64
0bbe5d86cb38 logic/mk_equals,mk_flexpair: now calls fastype_of instead of type_of.
lcp
parents: 0
diff changeset
    73
fun mk_equals(t,u) = equals(fastype_of t) $ t $ u;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    74
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    75
fun dest_equals (Const("==",_) $ t $ u)  =  (t,u)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    76
  | dest_equals t = raise TERM("dest_equals", [t]);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    77
637
b344bf624143 added is_equals: term -> bool;
wenzelm
parents: 585
diff changeset
    78
fun is_equals (Const ("==", _) $ _ $ _) = true
b344bf624143 added is_equals: term -> bool;
wenzelm
parents: 585
diff changeset
    79
  | is_equals _ = false;
b344bf624143 added is_equals: term -> bool;
wenzelm
parents: 585
diff changeset
    80
b344bf624143 added is_equals: term -> bool;
wenzelm
parents: 585
diff changeset
    81
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    82
(** implies **)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    83
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    84
fun mk_implies(A,B) = implies $ A $ B;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    85
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    86
fun dest_implies (Const("==>",_) $ A $ B)  =  (A,B)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    87
  | dest_implies A = raise TERM("dest_implies", [A]);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    88
5041
a1d0a6d555cd Goals may now contain assumptions, which are not returned.
nipkow
parents: 4822
diff changeset
    89
fun is_implies (Const ("==>", _) $ _ $ _) = true
a1d0a6d555cd Goals may now contain assumptions, which are not returned.
nipkow
parents: 4822
diff changeset
    90
  | is_implies _ = false;
a1d0a6d555cd Goals may now contain assumptions, which are not returned.
nipkow
parents: 4822
diff changeset
    91
4822
2733e21814fe added mk_cond_defpair, mk_defpair;
wenzelm
parents: 4693
diff changeset
    92
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    93
(** nested implications **)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    94
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    95
(* [A1,...,An], B  goes to  A1==>...An==>B  *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    96
fun list_implies ([], B) = B : term
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    97
  | list_implies (A::AS, B) = implies $ A $ list_implies(AS,B);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    98
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    99
(* A1==>...An==>B  goes to  [A1,...,An], where B is not an implication *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   100
fun strip_imp_prems (Const("==>", _) $ A $ B) = A :: strip_imp_prems B
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   101
  | strip_imp_prems _ = [];
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   102
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   103
(* A1==>...An==>B  goes to B, where B is not an implication *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   104
fun strip_imp_concl (Const("==>", _) $ A $ B) = strip_imp_concl B
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   105
  | strip_imp_concl A = A : term;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   106
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   107
(*Strip and return premises: (i, [], A1==>...Ai==>B)
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   108
    goes to   ([Ai, A(i-1),...,A1] , B)         (REVERSED)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   109
  if  i<0 or else i too big then raises  TERM*)
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   110
fun strip_prems (0, As, B) = (As, B)
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   111
  | strip_prems (i, As, Const("==>", _) $ A $ B) =
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   112
        strip_prems (i-1, A::As, B)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   113
  | strip_prems (_, As, A) = raise TERM("strip_prems", A::As);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   114
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   115
(*Count premises -- quicker than (length ostrip_prems) *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   116
fun count_prems (Const("==>", _) $ A $ B, n) = count_prems (B,n+1)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   117
  | count_prems (_,n) = n;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   118
13659
3cf622f6b0b2 Removed obsolete functions dealing with flex-flex constraints.
berghofe
parents: 12902
diff changeset
   119
(*strip a proof state (Horn clause):
3cf622f6b0b2 Removed obsolete functions dealing with flex-flex constraints.
berghofe
parents: 12902
diff changeset
   120
  B1 ==> ... Bn ==> C   goes to   ([B1, ..., Bn], C)    *)
3cf622f6b0b2 Removed obsolete functions dealing with flex-flex constraints.
berghofe
parents: 12902
diff changeset
   121
fun strip_horn A = (strip_imp_prems A, strip_imp_concl A);
3cf622f6b0b2 Removed obsolete functions dealing with flex-flex constraints.
berghofe
parents: 12902
diff changeset
   122
4822
2733e21814fe added mk_cond_defpair, mk_defpair;
wenzelm
parents: 4693
diff changeset
   123
12137
6123958975b8 added mk_conjunction;
wenzelm
parents: 10816
diff changeset
   124
(** conjunction **)
6123958975b8 added mk_conjunction;
wenzelm
parents: 10816
diff changeset
   125
6123958975b8 added mk_conjunction;
wenzelm
parents: 10816
diff changeset
   126
fun mk_conjunction (t, u) =
6123958975b8 added mk_conjunction;
wenzelm
parents: 10816
diff changeset
   127
  Term.list_all ([("C", propT)], mk_implies (list_implies ([t, u], Bound 0), Bound 0));
6123958975b8 added mk_conjunction;
wenzelm
parents: 10816
diff changeset
   128
12757
b76a4376cfcb added mk_conjunction_list;
wenzelm
parents: 12137
diff changeset
   129
fun mk_conjunction_list [] = Term.all propT $ Abs ("dummy", propT, mk_implies (Bound 0, Bound 0))
b76a4376cfcb added mk_conjunction_list;
wenzelm
parents: 12137
diff changeset
   130
  | mk_conjunction_list ts = foldr1 mk_conjunction ts;
12137
6123958975b8 added mk_conjunction;
wenzelm
parents: 10816
diff changeset
   131
6123958975b8 added mk_conjunction;
wenzelm
parents: 10816
diff changeset
   132
4822
2733e21814fe added mk_cond_defpair, mk_defpair;
wenzelm
parents: 4693
diff changeset
   133
(** definitions **)
2733e21814fe added mk_cond_defpair, mk_defpair;
wenzelm
parents: 4693
diff changeset
   134
2733e21814fe added mk_cond_defpair, mk_defpair;
wenzelm
parents: 4693
diff changeset
   135
fun mk_cond_defpair As (lhs, rhs) =
2733e21814fe added mk_cond_defpair, mk_defpair;
wenzelm
parents: 4693
diff changeset
   136
  (case Term.head_of lhs of
2733e21814fe added mk_cond_defpair, mk_defpair;
wenzelm
parents: 4693
diff changeset
   137
    Const (name, _) =>
2733e21814fe added mk_cond_defpair, mk_defpair;
wenzelm
parents: 4693
diff changeset
   138
      (Sign.base_name name ^ "_def", list_implies (As, mk_equals (lhs, rhs)))
2733e21814fe added mk_cond_defpair, mk_defpair;
wenzelm
parents: 4693
diff changeset
   139
  | _ => raise TERM ("Malformed definition: head of lhs not a constant", [lhs, rhs]));
2733e21814fe added mk_cond_defpair, mk_defpair;
wenzelm
parents: 4693
diff changeset
   140
2733e21814fe added mk_cond_defpair, mk_defpair;
wenzelm
parents: 4693
diff changeset
   141
fun mk_defpair lhs_rhs = mk_cond_defpair [] lhs_rhs;
2733e21814fe added mk_cond_defpair, mk_defpair;
wenzelm
parents: 4693
diff changeset
   142
2733e21814fe added mk_cond_defpair, mk_defpair;
wenzelm
parents: 4693
diff changeset
   143
398
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   144
(** types as terms **)
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   145
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   146
fun mk_type ty = Const ("TYPE", itselfT ty);
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   147
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   148
fun dest_type (Const ("TYPE", Type ("itself", [ty]))) = ty
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   149
  | dest_type t = raise TERM ("dest_type", [t]);
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   150
4822
2733e21814fe added mk_cond_defpair, mk_defpair;
wenzelm
parents: 4693
diff changeset
   151
447
d1f827fa0a18 changed comment only;
wenzelm
parents: 398
diff changeset
   152
(** class constraints **)
398
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   153
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   154
fun mk_inclass (ty, c) =
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   155
  Const (Sign.const_of_class c, itselfT ty --> propT) $ mk_type ty;
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   156
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   157
fun dest_inclass (t as Const (c_class, _) $ ty) =
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   158
      ((dest_type ty, Sign.class_of_const c_class)
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   159
        handle TERM _ => raise TERM ("dest_inclass", [t]))
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   160
  | dest_inclass t = raise TERM ("dest_inclass", [t]);
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   161
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   162
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   163
(** atomic goals **)
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   164
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   165
val goal_const = Const ("Goal", propT --> propT);
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   166
fun mk_goal t = goal_const $ t;
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   167
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   168
fun dest_goal (Const ("Goal", _) $ t) = t
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   169
  | dest_goal t = raise TERM ("dest_goal", [t]);
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   170
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   171
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   172
(*** Low-level term operations ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   173
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   174
(*Does t occur in u?  Or is alpha-convertible to u?
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   175
  The term t must contain no loose bound variables*)
4631
c7fa4ae34495 Improved loop-test for rewrite rules a little.
nipkow
parents: 4443
diff changeset
   176
fun t occs u = exists_subterm (fn s => t aconv s) u;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   177
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   178
(*Close up a formula over all free variables by quantification*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   179
fun close_form A =
4443
d55e85d7f0c2 term order stuff moved to term.ML;
wenzelm
parents: 4345
diff changeset
   180
  list_all_free (sort_wrt fst (map dest_Free (term_frees A)), A);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   181
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   182
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   183
(*** Specialized operations for resolution... ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   184
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   185
(*For all variables in the term, increment indexnames and lift over the Us
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   186
    result is ?Gidx(B.(lev+n-1),...,B.lev) where lev is abstraction level *)
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   187
fun incr_indexes (Us: typ list, inc:int) t =
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   188
  let fun incr (Var ((a,i), T), lev) =
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   189
                Unify.combound (Var((a, i+inc), Us---> incr_tvar inc T),
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   190
                                lev, length Us)
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   191
        | incr (Abs (a,T,body), lev) =
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   192
                Abs (a, incr_tvar inc T, incr(body,lev+1))
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   193
        | incr (Const(a,T),_) = Const(a, incr_tvar inc T)
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   194
        | incr (Free(a,T),_) = Free(a, incr_tvar inc T)
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   195
        | incr (f$t, lev) = incr(f,lev) $ incr(t,lev)
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   196
        | incr (t,lev) = t
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   197
  in  incr(t,0)  end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   198
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   199
(*Make lifting functions from subgoal and increment.
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   200
    lift_abs operates on tpairs (unification constraints)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   201
    lift_all operates on propositions     *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   202
fun lift_fns (B,inc) =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   203
  let fun lift_abs (Us, Const("==>", _) $ _ $ B) u = lift_abs (Us,B) u
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   204
        | lift_abs (Us, Const("all",_)$Abs(a,T,t)) u =
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   205
              Abs(a, T, lift_abs (T::Us, t) u)
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   206
        | lift_abs (Us, _) u = incr_indexes(rev Us, inc) u
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   207
      fun lift_all (Us, Const("==>", _) $ A $ B) u =
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   208
              implies $ A $ lift_all (Us,B) u
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   209
        | lift_all (Us, Const("all",_)$Abs(a,T,t)) u =
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   210
              all T $ Abs(a, T, lift_all (T::Us,t) u)
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   211
        | lift_all (Us, _) u = incr_indexes(rev Us, inc) u;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   212
  in  (lift_abs([],B), lift_all([],B))  end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   213
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   214
(*Strips assumptions in goal, yielding list of hypotheses.   *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   215
fun strip_assums_hyp (Const("==>", _) $ H $ B) = H :: strip_assums_hyp B
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   216
  | strip_assums_hyp (Const("all",_)$Abs(a,T,t)) = strip_assums_hyp t
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   217
  | strip_assums_hyp B = [];
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   218
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   219
(*Strips assumptions in goal, yielding conclusion.   *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   220
fun strip_assums_concl (Const("==>", _) $ H $ B) = strip_assums_concl B
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   221
  | strip_assums_concl (Const("all",_)$Abs(a,T,t)) = strip_assums_concl t
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   222
  | strip_assums_concl B = B;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   223
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   224
(*Make a list of all the parameters in a subgoal, even if nested*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   225
fun strip_params (Const("==>", _) $ H $ B) = strip_params B
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   226
  | strip_params (Const("all",_)$Abs(a,T,t)) = (a,T) :: strip_params t
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   227
  | strip_params B = [];
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   228
9667
48cefe2daf32 fixed has_meta_prems: strip_assums_hyp;
wenzelm
parents: 9483
diff changeset
   229
(*test for meta connectives in prems of a 'subgoal'*)
48cefe2daf32 fixed has_meta_prems: strip_assums_hyp;
wenzelm
parents: 9483
diff changeset
   230
fun has_meta_prems prop i =
48cefe2daf32 fixed has_meta_prems: strip_assums_hyp;
wenzelm
parents: 9483
diff changeset
   231
  let
48cefe2daf32 fixed has_meta_prems: strip_assums_hyp;
wenzelm
parents: 9483
diff changeset
   232
    fun is_meta (Const ("==>", _) $ _ $ _) = true
10442
8ef083987af9 has_meta_prems: include "==";
wenzelm
parents: 9684
diff changeset
   233
      | is_meta (Const ("==", _) $ _ $ _) = true
9667
48cefe2daf32 fixed has_meta_prems: strip_assums_hyp;
wenzelm
parents: 9483
diff changeset
   234
      | is_meta (Const ("all", _) $ _) = true
48cefe2daf32 fixed has_meta_prems: strip_assums_hyp;
wenzelm
parents: 9483
diff changeset
   235
      | is_meta _ = false;
48cefe2daf32 fixed has_meta_prems: strip_assums_hyp;
wenzelm
parents: 9483
diff changeset
   236
  in
13659
3cf622f6b0b2 Removed obsolete functions dealing with flex-flex constraints.
berghofe
parents: 12902
diff changeset
   237
    (case strip_prems (i, [], prop) of
9667
48cefe2daf32 fixed has_meta_prems: strip_assums_hyp;
wenzelm
parents: 9483
diff changeset
   238
      (B :: _, _) => exists is_meta (strip_assums_hyp B)
48cefe2daf32 fixed has_meta_prems: strip_assums_hyp;
wenzelm
parents: 9483
diff changeset
   239
    | _ => false) handle TERM _ => false
48cefe2daf32 fixed has_meta_prems: strip_assums_hyp;
wenzelm
parents: 9483
diff changeset
   240
  end;
9483
708a8a05497d added has_meta_prems;
wenzelm
parents: 9460
diff changeset
   241
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   242
(*Removes the parameters from a subgoal and renumber bvars in hypotheses,
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   243
    where j is the total number of parameters (precomputed)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   244
  If n>0 then deletes assumption n. *)
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   245
fun remove_params j n A =
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   246
    if j=0 andalso n<=0 then A  (*nothing left to do...*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   247
    else case A of
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   248
        Const("==>", _) $ H $ B =>
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   249
          if n=1 then                           (remove_params j (n-1) B)
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   250
          else implies $ (incr_boundvars j H) $ (remove_params j (n-1) B)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   251
      | Const("all",_)$Abs(a,T,t) => remove_params (j-1) n t
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   252
      | _ => if n>0 then raise TERM("remove_params", [A])
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   253
             else A;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   254
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   255
(** Auto-renaming of parameters in subgoals **)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   256
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   257
val auto_rename = ref false
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   258
and rename_prefix = ref "ka";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   259
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   260
(*rename_prefix is not exported; it is set by this function.*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   261
fun set_rename_prefix a =
4693
2e47ea2c6109 adapted to baroque chars;
wenzelm
parents: 4679
diff changeset
   262
    if a<>"" andalso forall Symbol.is_letter (Symbol.explode a)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   263
    then  (rename_prefix := a;  auto_rename := true)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   264
    else  error"rename prefix must be nonempty and consist of letters";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   265
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   266
(*Makes parameters in a goal have distinctive names (not guaranteed unique!)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   267
  A name clash could cause the printer to rename bound vars;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   268
    then res_inst_tac would not work properly.*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   269
fun rename_vars (a, []) = []
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   270
  | rename_vars (a, (_,T)::vars) =
12902
a23dc0b7566f Symbol.bump_string;
wenzelm
parents: 12796
diff changeset
   271
        (a,T) :: rename_vars (Symbol.bump_string a, vars);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   272
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   273
(*Move all parameters to the front of the subgoal, renaming them apart;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   274
  if n>0 then deletes assumption n. *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   275
fun flatten_params n A =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   276
    let val params = strip_params A;
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   277
        val vars = if !auto_rename
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   278
                   then rename_vars (!rename_prefix, params)
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   279
                   else ListPair.zip (variantlist(map #1 params,[]),
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   280
                                      map #2 params)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   281
    in  list_all (vars, remove_params (length vars) n A)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   282
    end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   283
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   284
(*Makes parameters in a goal have the names supplied by the list cs.*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   285
fun list_rename_params (cs, Const("==>", _) $ A $ B) =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   286
      implies $ A $ list_rename_params (cs, B)
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   287
  | list_rename_params (c::cs, Const("all",_)$Abs(_,T,t)) =
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   288
      all T $ Abs(c, T, list_rename_params (cs, t))
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   289
  | list_rename_params (cs, B) = B;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   290
15451
c6c8786b9921 fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents: 14137
diff changeset
   291
(*** Treatmsent of "assume", "erule", etc. ***)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   292
15451
c6c8786b9921 fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents: 14137
diff changeset
   293
(*Strips assumptions in goal yielding  
c6c8786b9921 fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents: 14137
diff changeset
   294
   HS = [Hn,...,H1],   params = [xm,...,x1], and B,
c6c8786b9921 fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents: 14137
diff changeset
   295
  where x1...xm are the parameters. This version (21.1.2005) REQUIRES 
c6c8786b9921 fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents: 14137
diff changeset
   296
  the the parameters to be flattened, but it allows erule to work on 
c6c8786b9921 fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents: 14137
diff changeset
   297
  assumptions of the form !!x. phi. Any !! after the outermost string
c6c8786b9921 fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents: 14137
diff changeset
   298
  will be regarded as belonging to the conclusion, and left untouched.
15454
4b339d3907a0 thin_tac now works on P==>Q
paulson
parents: 15451
diff changeset
   299
  Used ONLY by assum_pairs.
4b339d3907a0 thin_tac now works on P==>Q
paulson
parents: 15451
diff changeset
   300
      Unless nasms<0, it can terminate the recursion early; that allows
4b339d3907a0 thin_tac now works on P==>Q
paulson
parents: 15451
diff changeset
   301
  erule to work on assumptions of the form P==>Q.*)
4b339d3907a0 thin_tac now works on P==>Q
paulson
parents: 15451
diff changeset
   302
fun strip_assums_imp (0, Hs, B) = (Hs, B)  (*recursion terminated by nasms*)
4b339d3907a0 thin_tac now works on P==>Q
paulson
parents: 15451
diff changeset
   303
  | strip_assums_imp (nasms, Hs, Const("==>", _) $ H $ B) = 
4b339d3907a0 thin_tac now works on P==>Q
paulson
parents: 15451
diff changeset
   304
      strip_assums_imp (nasms-1, H::Hs, B)
4b339d3907a0 thin_tac now works on P==>Q
paulson
parents: 15451
diff changeset
   305
  | strip_assums_imp (_, Hs, B) = (Hs, B); (*recursion terminated by B*)
4b339d3907a0 thin_tac now works on P==>Q
paulson
parents: 15451
diff changeset
   306
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   307
15451
c6c8786b9921 fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents: 14137
diff changeset
   308
(*Strips OUTER parameters only, unlike similar legacy versions.*)
c6c8786b9921 fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents: 14137
diff changeset
   309
fun strip_assums_all (params, Const("all",_)$Abs(a,T,t)) =
c6c8786b9921 fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents: 14137
diff changeset
   310
      strip_assums_all ((a,T)::params, t)
c6c8786b9921 fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents: 14137
diff changeset
   311
  | strip_assums_all (params, B) = (params, B);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   312
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   313
(*Produces disagreement pairs, one for each assumption proof, in order.
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   314
  A is the first premise of the lifted rule, and thus has the form
15454
4b339d3907a0 thin_tac now works on P==>Q
paulson
parents: 15451
diff changeset
   315
    H1 ==> ... Hk ==> B   and the pairs are (H1,B),...,(Hk,B).
4b339d3907a0 thin_tac now works on P==>Q
paulson
parents: 15451
diff changeset
   316
  nasms is the number of assumptions in the original subgoal, needed when B
4b339d3907a0 thin_tac now works on P==>Q
paulson
parents: 15451
diff changeset
   317
    has the form B1 ==> B2: it stops B1 from being taken as an assumption. *)
4b339d3907a0 thin_tac now works on P==>Q
paulson
parents: 15451
diff changeset
   318
fun assum_pairs(nasms,A) =
15451
c6c8786b9921 fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents: 14137
diff changeset
   319
  let val (params, A') = strip_assums_all ([],A)
15454
4b339d3907a0 thin_tac now works on P==>Q
paulson
parents: 15451
diff changeset
   320
      val (Hs,B) = strip_assums_imp (nasms,[],A')
15451
c6c8786b9921 fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents: 14137
diff changeset
   321
      fun abspar t = Unify.rlist_abs(params, t)
c6c8786b9921 fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents: 14137
diff changeset
   322
      val D = abspar B
c6c8786b9921 fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents: 14137
diff changeset
   323
      fun pairrev ([], pairs) = pairs
c6c8786b9921 fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents: 14137
diff changeset
   324
        | pairrev (H::Hs, pairs) = pairrev(Hs,  (abspar H, D) :: pairs)
c6c8786b9921 fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents: 14137
diff changeset
   325
  in  pairrev (Hs,[])
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   326
  end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   327
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   328
(*Converts Frees to Vars and TFrees to TVars so that axioms can be written
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   329
  without (?) everywhere*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   330
fun varify (Const(a,T)) = Const(a, Type.varifyT T)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   331
  | varify (Free(a,T)) = Var((a,0), Type.varifyT T)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   332
  | varify (Var(ixn,T)) = Var(ixn, Type.varifyT T)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   333
  | varify (Abs (a,T,body)) = Abs (a, Type.varifyT T, varify body)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   334
  | varify (f$t) = varify f $ varify t
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   335
  | varify t = t;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   336
546
36e40454e03e /unvarifyT, unvarify: moved to Pure/logic.ML
lcp
parents: 447
diff changeset
   337
(*Inverse of varify.  Converts axioms back to their original form.*)
585
409c9ee7a9f3 Pure/type/unvarifyT: moved there from logic.ML
lcp
parents: 546
diff changeset
   338
fun unvarify (Const(a,T))    = Const(a, Type.unvarifyT T)
409c9ee7a9f3 Pure/type/unvarifyT: moved there from logic.ML
lcp
parents: 546
diff changeset
   339
  | unvarify (Var((a,0), T)) = Free(a, Type.unvarifyT T)
409c9ee7a9f3 Pure/type/unvarifyT: moved there from logic.ML
lcp
parents: 546
diff changeset
   340
  | unvarify (Var(ixn,T))    = Var(ixn, Type.unvarifyT T)  (*non-0 index!*)
409c9ee7a9f3 Pure/type/unvarifyT: moved there from logic.ML
lcp
parents: 546
diff changeset
   341
  | unvarify (Abs (a,T,body)) = Abs (a, Type.unvarifyT T, unvarify body)
546
36e40454e03e /unvarifyT, unvarify: moved to Pure/logic.ML
lcp
parents: 447
diff changeset
   342
  | unvarify (f$t) = unvarify f $ unvarify t
36e40454e03e /unvarifyT, unvarify: moved to Pure/logic.ML
lcp
parents: 447
diff changeset
   343
  | unvarify t = t;
36e40454e03e /unvarifyT, unvarify: moved to Pure/logic.ML
lcp
parents: 447
diff changeset
   344
13799
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   345
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   346
(*Get subgoal i*)
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   347
fun get_goal st i = List.nth (strip_imp_prems st, i-1)
14107
215585ac94e2 Exported function goal_params.
berghofe
parents: 13799
diff changeset
   348
  handle Subscript => error "Goal number out of range";
13799
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   349
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   350
(*reverses parameters for substitution*)
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   351
fun goal_params st i =
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   352
  let val gi = get_goal st i
14137
c57ec95e7763 Removed extraneous rev in function goal_params (the list of parameters
berghofe
parents: 14107
diff changeset
   353
      val rfrees = map Free (rename_wrt_term gi (strip_params gi))
13799
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   354
  in (gi, rfrees) end;
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   355
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   356
fun concl_of_goal st i =
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   357
  let val (gi, rfrees) = goal_params st i
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   358
      val B = strip_assums_concl gi
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   359
  in subst_bounds (rfrees, B) end;
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   360
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   361
fun prems_of_goal st i =
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   362
  let val (gi, rfrees) = goal_params st i
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   363
      val As = strip_assums_hyp gi
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   364
  in map (fn A => subst_bounds (rfrees, A)) As end;
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   365
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   366
end;