src/Pure/logic.ML
author wenzelm
Fri, 23 Dec 2005 15:16:48 +0100
changeset 18499 567370efb6d7
parent 18469 324245a561b5
child 18762 9098c92a945f
permissions -rw-r--r--
added mk_conjunction_list2;
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
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
     9
signature LOGIC =
4345
7e9436ffb813 tuned term order;
wenzelm
parents: 4318
diff changeset
    10
sig
18181
wenzelm
parents: 18029
diff changeset
    11
  val is_all: term -> bool
wenzelm
parents: 18029
diff changeset
    12
  val mk_equals: term * term -> term
wenzelm
parents: 18029
diff changeset
    13
  val dest_equals: term -> term * term
wenzelm
parents: 18029
diff changeset
    14
  val is_equals: term -> bool
wenzelm
parents: 18029
diff changeset
    15
  val mk_implies: term * term -> term
wenzelm
parents: 18029
diff changeset
    16
  val dest_implies: term -> term * term
wenzelm
parents: 18029
diff changeset
    17
  val is_implies: term -> bool
wenzelm
parents: 18029
diff changeset
    18
  val list_implies: term list * term -> term
wenzelm
parents: 18029
diff changeset
    19
  val strip_imp_prems: term -> term list
wenzelm
parents: 18029
diff changeset
    20
  val strip_imp_concl: term -> term
wenzelm
parents: 18029
diff changeset
    21
  val strip_prems: int * term list * term -> term list * term
wenzelm
parents: 18029
diff changeset
    22
  val count_prems: term * int -> int
wenzelm
parents: 18029
diff changeset
    23
  val nth_prem: int * term -> term
wenzelm
parents: 18029
diff changeset
    24
  val mk_conjunction: term * term -> term
12757
b76a4376cfcb added mk_conjunction_list;
wenzelm
parents: 12137
diff changeset
    25
  val mk_conjunction_list: term list -> term
18499
567370efb6d7 added mk_conjunction_list2;
wenzelm
parents: 18469
diff changeset
    26
  val mk_conjunction_list2: term list list -> term
18469
324245a561b5 mk_conjunction: proper treatment of bounds;
wenzelm
parents: 18248
diff changeset
    27
  val dest_conjunction: term -> term * term
324245a561b5 mk_conjunction: proper treatment of bounds;
wenzelm
parents: 18248
diff changeset
    28
  val dest_conjunctions: term -> term list
18181
wenzelm
parents: 18029
diff changeset
    29
  val strip_horn: term -> term list * term
wenzelm
parents: 18029
diff changeset
    30
  val mk_cond_defpair: term list -> term * term -> string * term
wenzelm
parents: 18029
diff changeset
    31
  val mk_defpair: term * term -> string * term
wenzelm
parents: 18029
diff changeset
    32
  val mk_type: typ -> term
wenzelm
parents: 18029
diff changeset
    33
  val dest_type: term -> typ
wenzelm
parents: 18029
diff changeset
    34
  val mk_inclass: typ * class -> term
wenzelm
parents: 18029
diff changeset
    35
  val dest_inclass: term -> typ * class
wenzelm
parents: 18029
diff changeset
    36
  val protectC: term
wenzelm
parents: 18029
diff changeset
    37
  val protect: term -> term
wenzelm
parents: 18029
diff changeset
    38
  val unprotect: term -> term
wenzelm
parents: 18029
diff changeset
    39
  val occs: term * term -> bool
wenzelm
parents: 18029
diff changeset
    40
  val close_form: term -> term
wenzelm
parents: 18029
diff changeset
    41
  val incr_indexes: typ list * int -> term -> term
wenzelm
parents: 18029
diff changeset
    42
  val incr_tvar: int -> typ -> typ
wenzelm
parents: 18029
diff changeset
    43
  val lift_abs: int -> term -> term -> term
wenzelm
parents: 18029
diff changeset
    44
  val lift_all: int -> term -> term -> term
wenzelm
parents: 18029
diff changeset
    45
  val strip_assums_hyp: term -> term list
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
    46
  val strip_assums_concl: term -> term
18181
wenzelm
parents: 18029
diff changeset
    47
  val strip_params: term -> (string * typ) list
wenzelm
parents: 18029
diff changeset
    48
  val has_meta_prems: term -> int -> bool
wenzelm
parents: 18029
diff changeset
    49
  val flatten_params: int -> term -> term
wenzelm
parents: 18029
diff changeset
    50
  val auto_rename: bool ref
wenzelm
parents: 18029
diff changeset
    51
  val set_rename_prefix: string -> unit
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    52
  val list_rename_params: string list * term -> term
18181
wenzelm
parents: 18029
diff changeset
    53
  val assum_pairs: int * term -> (term*term)list
wenzelm
parents: 18029
diff changeset
    54
  val varify: term -> term
wenzelm
parents: 18029
diff changeset
    55
  val unvarify: term -> term
wenzelm
parents: 18029
diff changeset
    56
  val get_goal: term -> int -> term
wenzelm
parents: 18029
diff changeset
    57
  val goal_params: term -> int -> term * term list
wenzelm
parents: 18029
diff changeset
    58
  val prems_of_goal: term -> int -> term list
wenzelm
parents: 18029
diff changeset
    59
  val concl_of_goal: term -> int -> term
4345
7e9436ffb813 tuned term order;
wenzelm
parents: 4318
diff changeset
    60
end;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    61
1500
b2de3b3277b8 Elimination of fully-functorial style.
paulson
parents: 1460
diff changeset
    62
structure Logic : LOGIC =
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    63
struct
398
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
    64
4345
7e9436ffb813 tuned term order;
wenzelm
parents: 4318
diff changeset
    65
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    66
(*** Abstract syntax operations on the meta-connectives ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    67
5041
a1d0a6d555cd Goals may now contain assumptions, which are not returned.
nipkow
parents: 4822
diff changeset
    68
(** all **)
a1d0a6d555cd Goals may now contain assumptions, which are not returned.
nipkow
parents: 4822
diff changeset
    69
a1d0a6d555cd Goals may now contain assumptions, which are not returned.
nipkow
parents: 4822
diff changeset
    70
fun is_all (Const ("all", _) $ _) = true
a1d0a6d555cd Goals may now contain assumptions, which are not returned.
nipkow
parents: 4822
diff changeset
    71
  | is_all _ = false;
a1d0a6d555cd Goals may now contain assumptions, which are not returned.
nipkow
parents: 4822
diff changeset
    72
a1d0a6d555cd Goals may now contain assumptions, which are not returned.
nipkow
parents: 4822
diff changeset
    73
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    74
(** equality **)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    75
1835
07eee14f5bd4 Restored warning comment
paulson
parents: 1500
diff changeset
    76
(*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
    77
fun mk_equals(t,u) = equals(fastype_of t) $ t $ u;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    78
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    79
fun dest_equals (Const("==",_) $ t $ u)  =  (t,u)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    80
  | dest_equals t = raise TERM("dest_equals", [t]);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    81
637
b344bf624143 added is_equals: term -> bool;
wenzelm
parents: 585
diff changeset
    82
fun is_equals (Const ("==", _) $ _ $ _) = true
b344bf624143 added is_equals: term -> bool;
wenzelm
parents: 585
diff changeset
    83
  | is_equals _ = false;
b344bf624143 added is_equals: term -> bool;
wenzelm
parents: 585
diff changeset
    84
b344bf624143 added is_equals: term -> bool;
wenzelm
parents: 585
diff changeset
    85
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    86
(** implies **)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    87
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    88
fun mk_implies(A,B) = implies $ A $ B;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    89
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    90
fun dest_implies (Const("==>",_) $ A $ B)  =  (A,B)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    91
  | dest_implies A = raise TERM("dest_implies", [A]);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    92
5041
a1d0a6d555cd Goals may now contain assumptions, which are not returned.
nipkow
parents: 4822
diff changeset
    93
fun is_implies (Const ("==>", _) $ _ $ _) = true
a1d0a6d555cd Goals may now contain assumptions, which are not returned.
nipkow
parents: 4822
diff changeset
    94
  | is_implies _ = false;
a1d0a6d555cd Goals may now contain assumptions, which are not returned.
nipkow
parents: 4822
diff changeset
    95
4822
2733e21814fe added mk_cond_defpair, mk_defpair;
wenzelm
parents: 4693
diff changeset
    96
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    97
(** nested implications **)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    98
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    99
(* [A1,...,An], B  goes to  A1==>...An==>B  *)
18181
wenzelm
parents: 18029
diff changeset
   100
fun list_implies ([], B) = B
wenzelm
parents: 18029
diff changeset
   101
  | list_implies (A::As, B) = implies $ A $ list_implies(As,B);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   102
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   103
(* A1==>...An==>B  goes to  [A1,...,An], where B is not an implication *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   104
fun strip_imp_prems (Const("==>", _) $ A $ B) = A :: strip_imp_prems B
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   105
  | strip_imp_prems _ = [];
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   106
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   107
(* A1==>...An==>B  goes to B, where B is not an implication *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   108
fun strip_imp_concl (Const("==>", _) $ A $ B) = strip_imp_concl B
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   109
  | strip_imp_concl A = A : term;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   110
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   111
(*Strip and return premises: (i, [], A1==>...Ai==>B)
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   112
    goes to   ([Ai, A(i-1),...,A1] , B)         (REVERSED)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   113
  if  i<0 or else i too big then raises  TERM*)
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   114
fun strip_prems (0, As, B) = (As, B)
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   115
  | strip_prems (i, As, Const("==>", _) $ A $ B) =
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   116
        strip_prems (i-1, A::As, B)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   117
  | strip_prems (_, As, A) = raise TERM("strip_prems", A::As);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   118
16130
38b111451155 added nth_prem;
wenzelm
parents: 15596
diff changeset
   119
(*Count premises -- quicker than (length o strip_prems) *)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   120
fun count_prems (Const("==>", _) $ A $ B, n) = count_prems (B,n+1)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   121
  | count_prems (_,n) = n;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   122
16130
38b111451155 added nth_prem;
wenzelm
parents: 15596
diff changeset
   123
(*Select Ai from A1 ==>...Ai==>B*)
38b111451155 added nth_prem;
wenzelm
parents: 15596
diff changeset
   124
fun nth_prem (1, Const ("==>", _) $ A $ _) = A
38b111451155 added nth_prem;
wenzelm
parents: 15596
diff changeset
   125
  | nth_prem (i, Const ("==>", _) $ _ $ B) = nth_prem (i - 1, B)
38b111451155 added nth_prem;
wenzelm
parents: 15596
diff changeset
   126
  | nth_prem (_, A) = raise TERM ("nth_prem", [A]);
38b111451155 added nth_prem;
wenzelm
parents: 15596
diff changeset
   127
13659
3cf622f6b0b2 Removed obsolete functions dealing with flex-flex constraints.
berghofe
parents: 12902
diff changeset
   128
(*strip a proof state (Horn clause):
3cf622f6b0b2 Removed obsolete functions dealing with flex-flex constraints.
berghofe
parents: 12902
diff changeset
   129
  B1 ==> ... Bn ==> C   goes to   ([B1, ..., Bn], C)    *)
3cf622f6b0b2 Removed obsolete functions dealing with flex-flex constraints.
berghofe
parents: 12902
diff changeset
   130
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
   131
4822
2733e21814fe added mk_cond_defpair, mk_defpair;
wenzelm
parents: 4693
diff changeset
   132
12137
6123958975b8 added mk_conjunction;
wenzelm
parents: 10816
diff changeset
   133
(** conjunction **)
6123958975b8 added mk_conjunction;
wenzelm
parents: 10816
diff changeset
   134
18499
567370efb6d7 added mk_conjunction_list2;
wenzelm
parents: 18469
diff changeset
   135
(*A && B*)
12137
6123958975b8 added mk_conjunction;
wenzelm
parents: 10816
diff changeset
   136
fun mk_conjunction (t, u) =
18469
324245a561b5 mk_conjunction: proper treatment of bounds;
wenzelm
parents: 18248
diff changeset
   137
  Term.list_all ([("X", propT)],
324245a561b5 mk_conjunction: proper treatment of bounds;
wenzelm
parents: 18248
diff changeset
   138
    mk_implies (list_implies (map (Term.incr_boundvars 1) [t, u], Bound 0), Bound 0));
12137
6123958975b8 added mk_conjunction;
wenzelm
parents: 10816
diff changeset
   139
18499
567370efb6d7 added mk_conjunction_list2;
wenzelm
parents: 18469
diff changeset
   140
(*A && B && C -- improper*)
12757
b76a4376cfcb added mk_conjunction_list;
wenzelm
parents: 12137
diff changeset
   141
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
   142
  | mk_conjunction_list ts = foldr1 mk_conjunction ts;
12137
6123958975b8 added mk_conjunction;
wenzelm
parents: 10816
diff changeset
   143
18499
567370efb6d7 added mk_conjunction_list2;
wenzelm
parents: 18469
diff changeset
   144
(*(A1 && B1 && C1) && (A2 && B2 && C2 && D2) && A3 && B3 -- improper*)
567370efb6d7 added mk_conjunction_list2;
wenzelm
parents: 18469
diff changeset
   145
fun mk_conjunction_list2 tss =
567370efb6d7 added mk_conjunction_list2;
wenzelm
parents: 18469
diff changeset
   146
  mk_conjunction_list (map mk_conjunction_list (filter_out null tss));
567370efb6d7 added mk_conjunction_list2;
wenzelm
parents: 18469
diff changeset
   147
567370efb6d7 added mk_conjunction_list2;
wenzelm
parents: 18469
diff changeset
   148
(*A && B*)
18469
324245a561b5 mk_conjunction: proper treatment of bounds;
wenzelm
parents: 18248
diff changeset
   149
fun dest_conjunction
324245a561b5 mk_conjunction: proper treatment of bounds;
wenzelm
parents: 18248
diff changeset
   150
      (t as Const ("all", _) $ Abs (_, _,
324245a561b5 mk_conjunction: proper treatment of bounds;
wenzelm
parents: 18248
diff changeset
   151
        Const ("==>", _) $ (Const ("==>", _) $ A $ (Const ("==>", _) $ B $ Bound 0)) $ Bound 0)) =
324245a561b5 mk_conjunction: proper treatment of bounds;
wenzelm
parents: 18248
diff changeset
   152
      if Term.loose_bvar1 (A, 0) orelse Term.loose_bvar1 (B, 0)
324245a561b5 mk_conjunction: proper treatment of bounds;
wenzelm
parents: 18248
diff changeset
   153
      then raise TERM ("dest_conjunction", [t])
324245a561b5 mk_conjunction: proper treatment of bounds;
wenzelm
parents: 18248
diff changeset
   154
      else (Term.incr_boundvars ~1 A, Term.incr_boundvars ~1 B)
324245a561b5 mk_conjunction: proper treatment of bounds;
wenzelm
parents: 18248
diff changeset
   155
  | dest_conjunction t = raise TERM ("dest_conjunction", [t]);
324245a561b5 mk_conjunction: proper treatment of bounds;
wenzelm
parents: 18248
diff changeset
   156
18499
567370efb6d7 added mk_conjunction_list2;
wenzelm
parents: 18469
diff changeset
   157
(*((A && B) && C) && D && E -- flat*)
18469
324245a561b5 mk_conjunction: proper treatment of bounds;
wenzelm
parents: 18248
diff changeset
   158
fun dest_conjunctions t =
324245a561b5 mk_conjunction: proper treatment of bounds;
wenzelm
parents: 18248
diff changeset
   159
  (case try dest_conjunction t of
324245a561b5 mk_conjunction: proper treatment of bounds;
wenzelm
parents: 18248
diff changeset
   160
    NONE => [t]
324245a561b5 mk_conjunction: proper treatment of bounds;
wenzelm
parents: 18248
diff changeset
   161
  | SOME (A, B) => dest_conjunctions A @ dest_conjunctions B);
324245a561b5 mk_conjunction: proper treatment of bounds;
wenzelm
parents: 18248
diff changeset
   162
324245a561b5 mk_conjunction: proper treatment of bounds;
wenzelm
parents: 18248
diff changeset
   163
12137
6123958975b8 added mk_conjunction;
wenzelm
parents: 10816
diff changeset
   164
4822
2733e21814fe added mk_cond_defpair, mk_defpair;
wenzelm
parents: 4693
diff changeset
   165
(** definitions **)
2733e21814fe added mk_cond_defpair, mk_defpair;
wenzelm
parents: 4693
diff changeset
   166
2733e21814fe added mk_cond_defpair, mk_defpair;
wenzelm
parents: 4693
diff changeset
   167
fun mk_cond_defpair As (lhs, rhs) =
2733e21814fe added mk_cond_defpair, mk_defpair;
wenzelm
parents: 4693
diff changeset
   168
  (case Term.head_of lhs of
2733e21814fe added mk_cond_defpair, mk_defpair;
wenzelm
parents: 4693
diff changeset
   169
    Const (name, _) =>
2733e21814fe added mk_cond_defpair, mk_defpair;
wenzelm
parents: 4693
diff changeset
   170
      (Sign.base_name name ^ "_def", list_implies (As, mk_equals (lhs, rhs)))
2733e21814fe added mk_cond_defpair, mk_defpair;
wenzelm
parents: 4693
diff changeset
   171
  | _ => raise TERM ("Malformed definition: head of lhs not a constant", [lhs, rhs]));
2733e21814fe added mk_cond_defpair, mk_defpair;
wenzelm
parents: 4693
diff changeset
   172
2733e21814fe added mk_cond_defpair, mk_defpair;
wenzelm
parents: 4693
diff changeset
   173
fun mk_defpair lhs_rhs = mk_cond_defpair [] lhs_rhs;
2733e21814fe added mk_cond_defpair, mk_defpair;
wenzelm
parents: 4693
diff changeset
   174
2733e21814fe added mk_cond_defpair, mk_defpair;
wenzelm
parents: 4693
diff changeset
   175
398
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   176
(** types as terms **)
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   177
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   178
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
   179
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   180
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
   181
  | 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
   182
4822
2733e21814fe added mk_cond_defpair, mk_defpair;
wenzelm
parents: 4693
diff changeset
   183
447
d1f827fa0a18 changed comment only;
wenzelm
parents: 398
diff changeset
   184
(** class constraints **)
398
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   185
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   186
fun mk_inclass (ty, c) =
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   187
  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
   188
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   189
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
   190
      ((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
   191
        handle TERM _ => raise TERM ("dest_inclass", [t]))
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   192
  | 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
   193
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   194
18029
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   195
(** protected propositions **)
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   196
18029
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   197
val protectC = Const ("prop", propT --> propT);
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   198
fun protect t = protectC $ t;
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   199
18029
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   200
fun unprotect (Const ("prop", _) $ t) = t
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   201
  | unprotect t = raise TERM ("unprotect", [t]);
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   202
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   203
18181
wenzelm
parents: 18029
diff changeset
   204
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   205
(*** Low-level term operations ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   206
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   207
(*Does t occur in u?  Or is alpha-convertible to u?
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   208
  The term t must contain no loose bound variables*)
16846
bbebc68a7faf occs no longer infix (structure not open);
wenzelm
parents: 16130
diff changeset
   209
fun occs (t, u) = exists_subterm (fn s => t aconv s) u;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   210
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   211
(*Close up a formula over all free variables by quantification*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   212
fun close_form A =
4443
d55e85d7f0c2 term order stuff moved to term.ML;
wenzelm
parents: 4345
diff changeset
   213
  list_all_free (sort_wrt fst (map dest_Free (term_frees A)), A);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   214
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   215
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   216
(*** Specialized operations for resolution... ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   217
16879
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   218
local exception SAME in
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   219
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   220
fun incrT k =
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   221
  let
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   222
    fun incr (TVar ((a, i), S)) = TVar ((a, i + k), S)
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   223
      | incr (Type (a, Ts)) = Type (a, incrs Ts)
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   224
      | incr _ = raise SAME
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   225
    and incrs (T :: Ts) =
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   226
        (incr T :: (incrs Ts handle SAME => Ts)
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   227
          handle SAME => T :: incrs Ts)
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   228
      | incrs [] = raise SAME;
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   229
  in incr end;
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   230
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   231
(*For all variables in the term, increment indexnames and lift over the Us
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   232
    result is ?Gidx(B.(lev+n-1),...,B.lev) where lev is abstraction level *)
17120
4ddeef83bd66 optimization to incr_indexes?
paulson
parents: 16879
diff changeset
   233
fun incr_indexes ([], 0) t = t
18029
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   234
  | incr_indexes (Ts, k) t =
16879
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   235
  let
18029
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   236
    val n = length Ts;
16879
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   237
    val incrT = if k = 0 then I else incrT k;
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   238
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   239
    fun incr lev (Var ((x, i), T)) =
18029
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   240
          Unify.combound (Var ((x, i + k), Ts ---> (incrT T handle SAME => T)), lev, n)
16879
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   241
      | incr lev (Abs (x, T, body)) =
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   242
          (Abs (x, incrT T, incr (lev + 1) body handle SAME => body)
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   243
            handle SAME => Abs (x, T, incr (lev + 1) body))
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   244
      | incr lev (t $ u) =
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   245
          (incr lev t $ (incr lev u handle SAME => u)
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   246
            handle SAME => t $ incr lev u)
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   247
      | incr _ (Const (c, T)) = Const (c, incrT T)
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   248
      | incr _ (Free (x, T)) = Free (x, incrT T)
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   249
      | incr _ (t as Bound _) = t;
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   250
  in incr 0 t handle SAME => t end;
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   251
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   252
fun incr_tvar 0 T = T
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   253
  | incr_tvar k T = incrT k T handle SAME => T;
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   254
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   255
end;
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   256
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   257
18248
wenzelm
parents: 18181
diff changeset
   258
(* Lifting functions from subgoal and increment:
18029
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   259
    lift_abs operates on terms
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   260
    lift_all operates on propositions *)
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   261
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   262
fun lift_abs inc =
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   263
  let
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   264
    fun lift Ts (Const ("==>", _) $ _ $ B) t = lift Ts B t
18248
wenzelm
parents: 18181
diff changeset
   265
      | lift Ts (Const ("all", _) $ Abs (a, T, B)) t = Abs (a, T, lift (T :: Ts) B t)
18029
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   266
      | lift Ts _ t = incr_indexes (rev Ts, inc) t;
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   267
  in lift [] end;
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   268
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   269
fun lift_all inc =
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   270
  let
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   271
    fun lift Ts ((c as Const ("==>", _)) $ A $ B) t = c $ A $ lift Ts B t
18248
wenzelm
parents: 18181
diff changeset
   272
      | lift Ts ((c as Const ("all", _)) $ Abs (a, T, B)) t = c $ Abs (a, T, lift (T :: Ts) B t)
18029
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   273
      | lift Ts _ t = incr_indexes (rev Ts, inc) t;
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   274
  in lift [] end;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   275
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   276
(*Strips assumptions in goal, yielding list of hypotheses.   *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   277
fun strip_assums_hyp (Const("==>", _) $ H $ B) = H :: strip_assums_hyp B
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   278
  | strip_assums_hyp (Const("all",_)$Abs(a,T,t)) = strip_assums_hyp t
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   279
  | strip_assums_hyp B = [];
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   280
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   281
(*Strips assumptions in goal, yielding conclusion.   *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   282
fun strip_assums_concl (Const("==>", _) $ H $ B) = strip_assums_concl B
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   283
  | strip_assums_concl (Const("all",_)$Abs(a,T,t)) = strip_assums_concl t
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   284
  | strip_assums_concl B = B;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   285
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   286
(*Make a list of all the parameters in a subgoal, even if nested*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   287
fun strip_params (Const("==>", _) $ H $ B) = strip_params B
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   288
  | strip_params (Const("all",_)$Abs(a,T,t)) = (a,T) :: strip_params t
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   289
  | strip_params B = [];
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   290
9667
48cefe2daf32 fixed has_meta_prems: strip_assums_hyp;
wenzelm
parents: 9483
diff changeset
   291
(*test for meta connectives in prems of a 'subgoal'*)
48cefe2daf32 fixed has_meta_prems: strip_assums_hyp;
wenzelm
parents: 9483
diff changeset
   292
fun has_meta_prems prop i =
48cefe2daf32 fixed has_meta_prems: strip_assums_hyp;
wenzelm
parents: 9483
diff changeset
   293
  let
48cefe2daf32 fixed has_meta_prems: strip_assums_hyp;
wenzelm
parents: 9483
diff changeset
   294
    fun is_meta (Const ("==>", _) $ _ $ _) = true
10442
8ef083987af9 has_meta_prems: include "==";
wenzelm
parents: 9684
diff changeset
   295
      | is_meta (Const ("==", _) $ _ $ _) = true
9667
48cefe2daf32 fixed has_meta_prems: strip_assums_hyp;
wenzelm
parents: 9483
diff changeset
   296
      | is_meta (Const ("all", _) $ _) = true
48cefe2daf32 fixed has_meta_prems: strip_assums_hyp;
wenzelm
parents: 9483
diff changeset
   297
      | is_meta _ = false;
48cefe2daf32 fixed has_meta_prems: strip_assums_hyp;
wenzelm
parents: 9483
diff changeset
   298
  in
13659
3cf622f6b0b2 Removed obsolete functions dealing with flex-flex constraints.
berghofe
parents: 12902
diff changeset
   299
    (case strip_prems (i, [], prop) of
9667
48cefe2daf32 fixed has_meta_prems: strip_assums_hyp;
wenzelm
parents: 9483
diff changeset
   300
      (B :: _, _) => exists is_meta (strip_assums_hyp B)
48cefe2daf32 fixed has_meta_prems: strip_assums_hyp;
wenzelm
parents: 9483
diff changeset
   301
    | _ => false) handle TERM _ => false
48cefe2daf32 fixed has_meta_prems: strip_assums_hyp;
wenzelm
parents: 9483
diff changeset
   302
  end;
9483
708a8a05497d added has_meta_prems;
wenzelm
parents: 9460
diff changeset
   303
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   304
(*Removes the parameters from a subgoal and renumber bvars in hypotheses,
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   305
    where j is the total number of parameters (precomputed)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   306
  If n>0 then deletes assumption n. *)
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   307
fun remove_params j n A =
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   308
    if j=0 andalso n<=0 then A  (*nothing left to do...*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   309
    else case A of
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   310
        Const("==>", _) $ H $ B =>
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   311
          if n=1 then                           (remove_params j (n-1) B)
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   312
          else implies $ (incr_boundvars j H) $ (remove_params j (n-1) B)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   313
      | Const("all",_)$Abs(a,T,t) => remove_params (j-1) n t
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   314
      | _ => if n>0 then raise TERM("remove_params", [A])
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   315
             else A;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   316
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   317
(** Auto-renaming of parameters in subgoals **)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   318
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   319
val auto_rename = ref false
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   320
and rename_prefix = ref "ka";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   321
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   322
(*rename_prefix is not exported; it is set by this function.*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   323
fun set_rename_prefix a =
4693
2e47ea2c6109 adapted to baroque chars;
wenzelm
parents: 4679
diff changeset
   324
    if a<>"" andalso forall Symbol.is_letter (Symbol.explode a)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   325
    then  (rename_prefix := a;  auto_rename := true)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   326
    else  error"rename prefix must be nonempty and consist of letters";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   327
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   328
(*Makes parameters in a goal have distinctive names (not guaranteed unique!)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   329
  A name clash could cause the printer to rename bound vars;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   330
    then res_inst_tac would not work properly.*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   331
fun rename_vars (a, []) = []
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   332
  | rename_vars (a, (_,T)::vars) =
12902
a23dc0b7566f Symbol.bump_string;
wenzelm
parents: 12796
diff changeset
   333
        (a,T) :: rename_vars (Symbol.bump_string a, vars);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   334
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   335
(*Move all parameters to the front of the subgoal, renaming them apart;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   336
  if n>0 then deletes assumption n. *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   337
fun flatten_params n A =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   338
    let val params = strip_params A;
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   339
        val vars = if !auto_rename
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   340
                   then rename_vars (!rename_prefix, params)
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   341
                   else ListPair.zip (variantlist(map #1 params,[]),
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   342
                                      map #2 params)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   343
    in  list_all (vars, remove_params (length vars) n A)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   344
    end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   345
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   346
(*Makes parameters in a goal have the names supplied by the list cs.*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   347
fun list_rename_params (cs, Const("==>", _) $ A $ B) =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   348
      implies $ A $ list_rename_params (cs, B)
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   349
  | list_rename_params (c::cs, Const("all",_)$Abs(_,T,t)) =
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   350
      all T $ Abs(c, T, list_rename_params (cs, t))
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   351
  | list_rename_params (cs, B) = B;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   352
15451
c6c8786b9921 fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents: 14137
diff changeset
   353
(*** Treatmsent of "assume", "erule", etc. ***)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   354
16879
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   355
(*Strips assumptions in goal yielding
15451
c6c8786b9921 fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents: 14137
diff changeset
   356
   HS = [Hn,...,H1],   params = [xm,...,x1], and B,
16879
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   357
  where x1...xm are the parameters. This version (21.1.2005) REQUIRES
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   358
  the the parameters to be flattened, but it allows erule to work on
15451
c6c8786b9921 fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents: 14137
diff changeset
   359
  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
   360
  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
   361
  Used ONLY by assum_pairs.
4b339d3907a0 thin_tac now works on P==>Q
paulson
parents: 15451
diff changeset
   362
      Unless nasms<0, it can terminate the recursion early; that allows
4b339d3907a0 thin_tac now works on P==>Q
paulson
parents: 15451
diff changeset
   363
  erule to work on assumptions of the form P==>Q.*)
4b339d3907a0 thin_tac now works on P==>Q
paulson
parents: 15451
diff changeset
   364
fun strip_assums_imp (0, Hs, B) = (Hs, B)  (*recursion terminated by nasms*)
16879
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   365
  | strip_assums_imp (nasms, Hs, Const("==>", _) $ H $ B) =
15454
4b339d3907a0 thin_tac now works on P==>Q
paulson
parents: 15451
diff changeset
   366
      strip_assums_imp (nasms-1, H::Hs, B)
4b339d3907a0 thin_tac now works on P==>Q
paulson
parents: 15451
diff changeset
   367
  | strip_assums_imp (_, Hs, B) = (Hs, B); (*recursion terminated by B*)
4b339d3907a0 thin_tac now works on P==>Q
paulson
parents: 15451
diff changeset
   368
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   369
15451
c6c8786b9921 fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents: 14137
diff changeset
   370
(*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
   371
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
   372
      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
   373
  | strip_assums_all (params, B) = (params, B);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   374
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   375
(*Produces disagreement pairs, one for each assumption proof, in order.
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   376
  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
   377
    H1 ==> ... Hk ==> B   and the pairs are (H1,B),...,(Hk,B).
4b339d3907a0 thin_tac now works on P==>Q
paulson
parents: 15451
diff changeset
   378
  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
   379
    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
   380
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
   381
  let val (params, A') = strip_assums_all ([],A)
15454
4b339d3907a0 thin_tac now works on P==>Q
paulson
parents: 15451
diff changeset
   382
      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
   383
      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
   384
      val D = abspar B
c6c8786b9921 fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents: 14137
diff changeset
   385
      fun pairrev ([], pairs) = pairs
c6c8786b9921 fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents: 14137
diff changeset
   386
        | 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
   387
  in  pairrev (Hs,[])
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   388
  end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   389
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   390
(*Converts Frees to Vars and TFrees to TVars so that axioms can be written
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   391
  without (?) everywhere*)
16862
wenzelm
parents: 16846
diff changeset
   392
fun varify (Const(a, T)) = Const (a, Type.varifyT T)
wenzelm
parents: 16846
diff changeset
   393
  | varify (Free (a, T)) = Var ((a, 0), Type.varifyT T)
wenzelm
parents: 16846
diff changeset
   394
  | varify (Var (ixn, T)) = Var (ixn, Type.varifyT T)
wenzelm
parents: 16846
diff changeset
   395
  | varify (t as Bound _) = t
wenzelm
parents: 16846
diff changeset
   396
  | varify (Abs (a, T, body)) = Abs (a, Type.varifyT T, varify body)
wenzelm
parents: 16846
diff changeset
   397
  | varify (f $ t) = varify f $ varify t;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   398
546
36e40454e03e /unvarifyT, unvarify: moved to Pure/logic.ML
lcp
parents: 447
diff changeset
   399
(*Inverse of varify.  Converts axioms back to their original form.*)
16862
wenzelm
parents: 16846
diff changeset
   400
fun unvarify (Const (a, T)) = Const (a, Type.unvarifyT T)
wenzelm
parents: 16846
diff changeset
   401
  | unvarify (Free (a, T)) = Free (a, Type.unvarifyT T)
wenzelm
parents: 16846
diff changeset
   402
  | unvarify (Var ((a, 0), T)) = Free (a, Type.unvarifyT T)
wenzelm
parents: 16846
diff changeset
   403
  | unvarify (Var (ixn, T)) = Var (ixn, Type.unvarifyT T)  (*non-0 index!*)
wenzelm
parents: 16846
diff changeset
   404
  | unvarify (t as Bound _) = t
wenzelm
parents: 16846
diff changeset
   405
  | unvarify (Abs (a, T, body)) = Abs (a, Type.unvarifyT T, unvarify body)
wenzelm
parents: 16846
diff changeset
   406
  | unvarify (f $ t) = unvarify f $ unvarify t;
546
36e40454e03e /unvarifyT, unvarify: moved to Pure/logic.ML
lcp
parents: 447
diff changeset
   407
13799
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   408
16862
wenzelm
parents: 16846
diff changeset
   409
(* goal states *)
wenzelm
parents: 16846
diff changeset
   410
wenzelm
parents: 16846
diff changeset
   411
fun get_goal st i = nth_prem (i, st)
wenzelm
parents: 16846
diff changeset
   412
  handle TERM _ => 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
   413
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   414
(*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
   415
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
   416
  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
   417
      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
   418
  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
   419
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   420
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
   421
  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
   422
      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
   423
  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
   424
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   425
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
   426
  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
   427
      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
   428
  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
   429
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   430
end;