src/Pure/logic.ML
author wenzelm
Mon, 23 Jun 2008 23:45:47 +0200
changeset 27334 3f17273766f2
parent 26424 a6cad32a27b0
child 28448 31a59d7d2168
permissions -rw-r--r--
added all, is_all; improved dest_all; added implies (from term.ML);
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
27334
3f17273766f2 added all, is_all;
wenzelm
parents: 26424
diff changeset
    11
  val all: term -> term -> term
3f17273766f2 added all, is_all;
wenzelm
parents: 26424
diff changeset
    12
  val is_all: term -> bool
3f17273766f2 added all, is_all;
wenzelm
parents: 26424
diff changeset
    13
  val dest_all: term -> (string * typ) * term
18181
wenzelm
parents: 18029
diff changeset
    14
  val mk_equals: term * term -> term
wenzelm
parents: 18029
diff changeset
    15
  val dest_equals: term -> term * term
27334
3f17273766f2 added all, is_all;
wenzelm
parents: 26424
diff changeset
    16
  val implies: term
18181
wenzelm
parents: 18029
diff changeset
    17
  val mk_implies: term * term -> term
wenzelm
parents: 18029
diff changeset
    18
  val dest_implies: term -> term * term
wenzelm
parents: 18029
diff changeset
    19
  val list_implies: term list * term -> term
wenzelm
parents: 18029
diff changeset
    20
  val strip_imp_prems: term -> term list
wenzelm
parents: 18029
diff changeset
    21
  val strip_imp_concl: term -> term
wenzelm
parents: 18029
diff changeset
    22
  val strip_prems: int * term list * term -> term list * term
21576
8c11b1ce2f05 simplified Logic.count_prems;
wenzelm
parents: 21520
diff changeset
    23
  val count_prems: term -> int
18181
wenzelm
parents: 18029
diff changeset
    24
  val nth_prem: int * term -> term
23418
c195f6f13769 balanced conjunctions;
wenzelm
parents: 23357
diff changeset
    25
  val true_prop: term
19125
59b26248547b simplified Pure conjunction, based on actual const;
wenzelm
parents: 19103
diff changeset
    26
  val conjunction: term
18181
wenzelm
parents: 18029
diff changeset
    27
  val mk_conjunction: term * term -> term
12757
b76a4376cfcb added mk_conjunction_list;
wenzelm
parents: 12137
diff changeset
    28
  val mk_conjunction_list: term list -> term
23418
c195f6f13769 balanced conjunctions;
wenzelm
parents: 23357
diff changeset
    29
  val mk_conjunction_balanced: term list -> term
18469
324245a561b5 mk_conjunction: proper treatment of bounds;
wenzelm
parents: 18248
diff changeset
    30
  val dest_conjunction: term -> term * term
19425
e0d7d9373faf added dest_conjunction_list;
wenzelm
parents: 19406
diff changeset
    31
  val dest_conjunction_list: term -> term list
23418
c195f6f13769 balanced conjunctions;
wenzelm
parents: 23357
diff changeset
    32
  val dest_conjunction_balanced: int -> term -> term list
18469
324245a561b5 mk_conjunction: proper treatment of bounds;
wenzelm
parents: 18248
diff changeset
    33
  val dest_conjunctions: term -> term list
18181
wenzelm
parents: 18029
diff changeset
    34
  val strip_horn: term -> term list * term
21520
63c73f461eec added type_map;
wenzelm
parents: 21016
diff changeset
    35
  val mk_type: typ -> term
18938
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
    36
  val dest_type: term -> typ
21520
63c73f461eec added type_map;
wenzelm
parents: 21016
diff changeset
    37
  val type_map: (term -> term) -> typ -> typ
18938
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
    38
  val const_of_class: class -> string
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
    39
  val class_of_const: string -> class
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
    40
  val mk_inclass: typ * class -> term
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
    41
  val dest_inclass: term -> typ * class
20630
2010cbb1a941 added name_classrel/arities/arity;
wenzelm
parents: 20548
diff changeset
    42
  val name_classrel: string * string -> string
19406
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
    43
  val mk_classrel: class * class -> term
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
    44
  val dest_classrel: term -> class * class
20630
2010cbb1a941 added name_classrel/arities/arity;
wenzelm
parents: 20548
diff changeset
    45
  val name_arities: arity -> string list
2010cbb1a941 added name_classrel/arities/arity;
wenzelm
parents: 20548
diff changeset
    46
  val name_arity: string * sort list * class -> string
2010cbb1a941 added name_classrel/arities/arity;
wenzelm
parents: 20548
diff changeset
    47
  val mk_arities: arity -> term list
19406
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
    48
  val dest_arity: term -> string * sort list * class
18181
wenzelm
parents: 18029
diff changeset
    49
  val protectC: term
wenzelm
parents: 18029
diff changeset
    50
  val protect: term -> term
wenzelm
parents: 18029
diff changeset
    51
  val unprotect: term -> term
19775
06cb6743adf6 support embedded terms;
wenzelm
parents: 19425
diff changeset
    52
  val mk_term: term -> term
06cb6743adf6 support embedded terms;
wenzelm
parents: 19425
diff changeset
    53
  val dest_term: term -> term
18181
wenzelm
parents: 18029
diff changeset
    54
  val occs: term * term -> bool
wenzelm
parents: 18029
diff changeset
    55
  val close_form: term -> term
18938
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
    56
  val combound: term * int * int -> term
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
    57
  val rlist_abs: (string * typ) list * term -> term
18181
wenzelm
parents: 18029
diff changeset
    58
  val incr_indexes: typ list * int -> term -> term
wenzelm
parents: 18029
diff changeset
    59
  val incr_tvar: int -> typ -> typ
wenzelm
parents: 18029
diff changeset
    60
  val lift_abs: int -> term -> term -> term
wenzelm
parents: 18029
diff changeset
    61
  val lift_all: int -> term -> term -> term
wenzelm
parents: 18029
diff changeset
    62
  val strip_assums_hyp: term -> term list
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
    63
  val strip_assums_concl: term -> term
18181
wenzelm
parents: 18029
diff changeset
    64
  val strip_params: term -> (string * typ) list
23597
ab67175ca8a5 simplified has_meta_prems;
wenzelm
parents: 23418
diff changeset
    65
  val has_meta_prems: term -> bool
18181
wenzelm
parents: 18029
diff changeset
    66
  val flatten_params: int -> term -> term
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    67
  val list_rename_params: string list * term -> term
18181
wenzelm
parents: 18029
diff changeset
    68
  val assum_pairs: int * term -> (term*term)list
19806
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
    69
  val varifyT: typ -> typ
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
    70
  val unvarifyT: typ -> typ
18181
wenzelm
parents: 18029
diff changeset
    71
  val varify: term -> term
wenzelm
parents: 18029
diff changeset
    72
  val unvarify: term -> term
19806
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
    73
  val legacy_varifyT: typ -> typ
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
    74
  val legacy_unvarifyT: typ -> typ
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
    75
  val legacy_varify: term -> term
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
    76
  val legacy_unvarify: term -> term
18181
wenzelm
parents: 18029
diff changeset
    77
  val get_goal: term -> int -> term
wenzelm
parents: 18029
diff changeset
    78
  val goal_params: term -> int -> term * term list
wenzelm
parents: 18029
diff changeset
    79
  val prems_of_goal: term -> int -> term list
wenzelm
parents: 18029
diff changeset
    80
  val concl_of_goal: term -> int -> term
4345
7e9436ffb813 tuned term order;
wenzelm
parents: 4318
diff changeset
    81
end;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    82
1500
b2de3b3277b8 Elimination of fully-functorial style.
paulson
parents: 1460
diff changeset
    83
structure Logic : LOGIC =
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    84
struct
398
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
    85
4345
7e9436ffb813 tuned term order;
wenzelm
parents: 4318
diff changeset
    86
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    87
(*** Abstract syntax operations on the meta-connectives ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    88
23238
3de6e253efc4 added is_atomic;
wenzelm
parents: 22893
diff changeset
    89
(** all **)
5041
a1d0a6d555cd Goals may now contain assumptions, which are not returned.
nipkow
parents: 4822
diff changeset
    90
27334
3f17273766f2 added all, is_all;
wenzelm
parents: 26424
diff changeset
    91
fun all v t = Const ("all", (Term.fastype_of v --> propT) --> propT) $ lambda v t;
3f17273766f2 added all, is_all;
wenzelm
parents: 26424
diff changeset
    92
3f17273766f2 added all, is_all;
wenzelm
parents: 26424
diff changeset
    93
fun is_all (Const ("all", _) $ Abs _) = true
3f17273766f2 added all, is_all;
wenzelm
parents: 26424
diff changeset
    94
  | is_all _ = false;
3f17273766f2 added all, is_all;
wenzelm
parents: 26424
diff changeset
    95
3f17273766f2 added all, is_all;
wenzelm
parents: 26424
diff changeset
    96
fun dest_all (Const ("all", _) $ Abs (abs as (_, T, _))) =
3f17273766f2 added all, is_all;
wenzelm
parents: 26424
diff changeset
    97
      let val (x, b) = Term.dest_abs abs  (*potentially slow*)
3f17273766f2 added all, is_all;
wenzelm
parents: 26424
diff changeset
    98
      in ((x, T), b) end
18762
9098c92a945f added dest_all;
wenzelm
parents: 18499
diff changeset
    99
  | dest_all t = raise TERM ("dest_all", [t]);
9098c92a945f added dest_all;
wenzelm
parents: 18499
diff changeset
   100
9098c92a945f added dest_all;
wenzelm
parents: 18499
diff changeset
   101
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   102
(** equality **)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   103
27334
3f17273766f2 added all, is_all;
wenzelm
parents: 26424
diff changeset
   104
fun mk_equals (t, u) =
3f17273766f2 added all, is_all;
wenzelm
parents: 26424
diff changeset
   105
  let val T = Term.fastype_of t
3f17273766f2 added all, is_all;
wenzelm
parents: 26424
diff changeset
   106
  in Const ("==", T --> T --> propT) $ t $ u end;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   107
20883
b432f20a47ca removed is_equals, is_implies;
wenzelm
parents: 20630
diff changeset
   108
fun dest_equals (Const ("==", _) $ t $ u) = (t, u)
b432f20a47ca removed is_equals, is_implies;
wenzelm
parents: 20630
diff changeset
   109
  | dest_equals t = raise TERM ("dest_equals", [t]);
637
b344bf624143 added is_equals: term -> bool;
wenzelm
parents: 585
diff changeset
   110
b344bf624143 added is_equals: term -> bool;
wenzelm
parents: 585
diff changeset
   111
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   112
(** implies **)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   113
27334
3f17273766f2 added all, is_all;
wenzelm
parents: 26424
diff changeset
   114
val implies = Const ("==>", propT --> propT --> propT);
3f17273766f2 added all, is_all;
wenzelm
parents: 26424
diff changeset
   115
20883
b432f20a47ca removed is_equals, is_implies;
wenzelm
parents: 20630
diff changeset
   116
fun mk_implies (A, B) = implies $ A $ B;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   117
20883
b432f20a47ca removed is_equals, is_implies;
wenzelm
parents: 20630
diff changeset
   118
fun dest_implies (Const ("==>", _) $ A $ B) = (A, B)
b432f20a47ca removed is_equals, is_implies;
wenzelm
parents: 20630
diff changeset
   119
  | dest_implies A = raise TERM ("dest_implies", [A]);
5041
a1d0a6d555cd Goals may now contain assumptions, which are not returned.
nipkow
parents: 4822
diff changeset
   120
4822
2733e21814fe added mk_cond_defpair, mk_defpair;
wenzelm
parents: 4693
diff changeset
   121
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   122
(** nested implications **)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   123
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   124
(* [A1,...,An], B  goes to  A1==>...An==>B  *)
18181
wenzelm
parents: 18029
diff changeset
   125
fun list_implies ([], B) = B
wenzelm
parents: 18029
diff changeset
   126
  | list_implies (A::As, B) = implies $ A $ list_implies(As,B);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   127
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   128
(* A1==>...An==>B  goes to  [A1,...,An], where B is not an implication *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   129
fun strip_imp_prems (Const("==>", _) $ A $ B) = A :: strip_imp_prems B
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   130
  | strip_imp_prems _ = [];
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   131
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   132
(* A1==>...An==>B  goes to B, where B is not an implication *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   133
fun strip_imp_concl (Const("==>", _) $ A $ B) = strip_imp_concl B
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   134
  | strip_imp_concl A = A : term;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   135
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   136
(*Strip and return premises: (i, [], A1==>...Ai==>B)
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   137
    goes to   ([Ai, A(i-1),...,A1] , B)         (REVERSED)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   138
  if  i<0 or else i too big then raises  TERM*)
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   139
fun strip_prems (0, As, B) = (As, B)
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   140
  | strip_prems (i, As, Const("==>", _) $ A $ B) =
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   141
        strip_prems (i-1, A::As, B)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   142
  | strip_prems (_, As, A) = raise TERM("strip_prems", A::As);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   143
16130
38b111451155 added nth_prem;
wenzelm
parents: 15596
diff changeset
   144
(*Count premises -- quicker than (length o strip_prems) *)
21576
8c11b1ce2f05 simplified Logic.count_prems;
wenzelm
parents: 21520
diff changeset
   145
fun count_prems (Const ("==>", _) $ _ $ B) = 1 + count_prems B
8c11b1ce2f05 simplified Logic.count_prems;
wenzelm
parents: 21520
diff changeset
   146
  | count_prems _ = 0;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   147
16130
38b111451155 added nth_prem;
wenzelm
parents: 15596
diff changeset
   148
(*Select Ai from A1 ==>...Ai==>B*)
38b111451155 added nth_prem;
wenzelm
parents: 15596
diff changeset
   149
fun nth_prem (1, Const ("==>", _) $ A $ _) = A
38b111451155 added nth_prem;
wenzelm
parents: 15596
diff changeset
   150
  | nth_prem (i, Const ("==>", _) $ _ $ B) = nth_prem (i - 1, B)
38b111451155 added nth_prem;
wenzelm
parents: 15596
diff changeset
   151
  | nth_prem (_, A) = raise TERM ("nth_prem", [A]);
38b111451155 added nth_prem;
wenzelm
parents: 15596
diff changeset
   152
13659
3cf622f6b0b2 Removed obsolete functions dealing with flex-flex constraints.
berghofe
parents: 12902
diff changeset
   153
(*strip a proof state (Horn clause):
3cf622f6b0b2 Removed obsolete functions dealing with flex-flex constraints.
berghofe
parents: 12902
diff changeset
   154
  B1 ==> ... Bn ==> C   goes to   ([B1, ..., Bn], C)    *)
3cf622f6b0b2 Removed obsolete functions dealing with flex-flex constraints.
berghofe
parents: 12902
diff changeset
   155
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
   156
4822
2733e21814fe added mk_cond_defpair, mk_defpair;
wenzelm
parents: 4693
diff changeset
   157
23418
c195f6f13769 balanced conjunctions;
wenzelm
parents: 23357
diff changeset
   158
12137
6123958975b8 added mk_conjunction;
wenzelm
parents: 10816
diff changeset
   159
(** conjunction **)
6123958975b8 added mk_conjunction;
wenzelm
parents: 10816
diff changeset
   160
23418
c195f6f13769 balanced conjunctions;
wenzelm
parents: 23357
diff changeset
   161
val true_prop = Term.all propT $ Abs ("dummy", propT, mk_implies (Bound 0, Bound 0));
26424
a6cad32a27b0 eliminated theory ProtoPure;
wenzelm
parents: 25939
diff changeset
   162
val conjunction = Const ("Pure.conjunction", propT --> propT --> propT);
19125
59b26248547b simplified Pure conjunction, based on actual const;
wenzelm
parents: 19103
diff changeset
   163
23418
c195f6f13769 balanced conjunctions;
wenzelm
parents: 23357
diff changeset
   164
18499
567370efb6d7 added mk_conjunction_list2;
wenzelm
parents: 18469
diff changeset
   165
(*A && B*)
19125
59b26248547b simplified Pure conjunction, based on actual const;
wenzelm
parents: 19103
diff changeset
   166
fun mk_conjunction (A, B) = conjunction $ A $ B;
12137
6123958975b8 added mk_conjunction;
wenzelm
parents: 10816
diff changeset
   167
18499
567370efb6d7 added mk_conjunction_list2;
wenzelm
parents: 18469
diff changeset
   168
(*A && B && C -- improper*)
23418
c195f6f13769 balanced conjunctions;
wenzelm
parents: 23357
diff changeset
   169
fun mk_conjunction_list [] = true_prop
12757
b76a4376cfcb added mk_conjunction_list;
wenzelm
parents: 12137
diff changeset
   170
  | mk_conjunction_list ts = foldr1 mk_conjunction ts;
12137
6123958975b8 added mk_conjunction;
wenzelm
parents: 10816
diff changeset
   171
23418
c195f6f13769 balanced conjunctions;
wenzelm
parents: 23357
diff changeset
   172
(*(A && B) && (C && D) -- balanced*)
c195f6f13769 balanced conjunctions;
wenzelm
parents: 23357
diff changeset
   173
fun mk_conjunction_balanced [] = true_prop
c195f6f13769 balanced conjunctions;
wenzelm
parents: 23357
diff changeset
   174
  | mk_conjunction_balanced ts = BalancedTree.make mk_conjunction ts;
c195f6f13769 balanced conjunctions;
wenzelm
parents: 23357
diff changeset
   175
18499
567370efb6d7 added mk_conjunction_list2;
wenzelm
parents: 18469
diff changeset
   176
567370efb6d7 added mk_conjunction_list2;
wenzelm
parents: 18469
diff changeset
   177
(*A && B*)
26424
a6cad32a27b0 eliminated theory ProtoPure;
wenzelm
parents: 25939
diff changeset
   178
fun dest_conjunction (Const ("Pure.conjunction", _) $ A $ B) = (A, B)
18469
324245a561b5 mk_conjunction: proper treatment of bounds;
wenzelm
parents: 18248
diff changeset
   179
  | dest_conjunction t = raise TERM ("dest_conjunction", [t]);
324245a561b5 mk_conjunction: proper treatment of bounds;
wenzelm
parents: 18248
diff changeset
   180
19425
e0d7d9373faf added dest_conjunction_list;
wenzelm
parents: 19406
diff changeset
   181
(*A && B && C -- improper*)
e0d7d9373faf added dest_conjunction_list;
wenzelm
parents: 19406
diff changeset
   182
fun dest_conjunction_list t =
e0d7d9373faf added dest_conjunction_list;
wenzelm
parents: 19406
diff changeset
   183
  (case try dest_conjunction t of
e0d7d9373faf added dest_conjunction_list;
wenzelm
parents: 19406
diff changeset
   184
    NONE => [t]
e0d7d9373faf added dest_conjunction_list;
wenzelm
parents: 19406
diff changeset
   185
  | SOME (A, B) => A :: dest_conjunction_list B);
e0d7d9373faf added dest_conjunction_list;
wenzelm
parents: 19406
diff changeset
   186
23418
c195f6f13769 balanced conjunctions;
wenzelm
parents: 23357
diff changeset
   187
(*(A && B) && (C && D) -- balanced*)
c195f6f13769 balanced conjunctions;
wenzelm
parents: 23357
diff changeset
   188
fun dest_conjunction_balanced 0 _ = []
c195f6f13769 balanced conjunctions;
wenzelm
parents: 23357
diff changeset
   189
  | dest_conjunction_balanced n t = BalancedTree.dest dest_conjunction n t;
c195f6f13769 balanced conjunctions;
wenzelm
parents: 23357
diff changeset
   190
18499
567370efb6d7 added mk_conjunction_list2;
wenzelm
parents: 18469
diff changeset
   191
(*((A && B) && C) && D && E -- flat*)
18469
324245a561b5 mk_conjunction: proper treatment of bounds;
wenzelm
parents: 18248
diff changeset
   192
fun dest_conjunctions t =
324245a561b5 mk_conjunction: proper treatment of bounds;
wenzelm
parents: 18248
diff changeset
   193
  (case try dest_conjunction t of
324245a561b5 mk_conjunction: proper treatment of bounds;
wenzelm
parents: 18248
diff changeset
   194
    NONE => [t]
324245a561b5 mk_conjunction: proper treatment of bounds;
wenzelm
parents: 18248
diff changeset
   195
  | SOME (A, B) => dest_conjunctions A @ dest_conjunctions B);
324245a561b5 mk_conjunction: proper treatment of bounds;
wenzelm
parents: 18248
diff changeset
   196
324245a561b5 mk_conjunction: proper treatment of bounds;
wenzelm
parents: 18248
diff changeset
   197
12137
6123958975b8 added mk_conjunction;
wenzelm
parents: 10816
diff changeset
   198
398
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   199
(** types as terms **)
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   200
19391
4812d28c90a6 Term.itselfT;
wenzelm
parents: 19125
diff changeset
   201
fun mk_type ty = Const ("TYPE", Term.itselfT ty);
398
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   202
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   203
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
   204
  | 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
   205
21520
63c73f461eec added type_map;
wenzelm
parents: 21016
diff changeset
   206
fun type_map f = dest_type o f o mk_type;
63c73f461eec added type_map;
wenzelm
parents: 21016
diff changeset
   207
4822
2733e21814fe added mk_cond_defpair, mk_defpair;
wenzelm
parents: 4693
diff changeset
   208
19406
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   209
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   210
(** type classes **)
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   211
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   212
(* const names *)
398
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   213
18938
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
   214
val classN = "_class";
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
   215
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
   216
val const_of_class = suffix classN;
19406
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   217
18938
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
   218
fun class_of_const c = unsuffix classN c
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
   219
  handle Fail _ => raise TERM ("class_of_const: bad name " ^ quote c, []);
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
   220
19406
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   221
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   222
(* class constraints *)
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   223
398
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   224
fun mk_inclass (ty, c) =
19391
4812d28c90a6 Term.itselfT;
wenzelm
parents: 19125
diff changeset
   225
  Const (const_of_class c, Term.itselfT ty --> propT) $ mk_type ty;
398
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   226
19406
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   227
fun dest_inclass (t as Const (c_class, _) $ ty) = (dest_type ty, class_of_const c_class)
398
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   228
  | 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
   229
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   230
19406
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   231
(* class relations *)
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   232
20630
2010cbb1a941 added name_classrel/arities/arity;
wenzelm
parents: 20548
diff changeset
   233
fun name_classrel (c1, c2) =
2010cbb1a941 added name_classrel/arities/arity;
wenzelm
parents: 20548
diff changeset
   234
  NameSpace.base c1 ^ "_" ^ NameSpace.base c2;
2010cbb1a941 added name_classrel/arities/arity;
wenzelm
parents: 20548
diff changeset
   235
19406
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   236
fun mk_classrel (c1, c2) = mk_inclass (Term.aT [c1], c2);
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   237
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   238
fun dest_classrel tm =
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   239
  (case dest_inclass tm of
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   240
    (TVar (_, [c1]), c2) => (c1, c2)
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   241
  | _ => raise TERM ("dest_classrel", [tm]));
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   242
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   243
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   244
(* type arities *)
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   245
20630
2010cbb1a941 added name_classrel/arities/arity;
wenzelm
parents: 20548
diff changeset
   246
fun name_arities (t, _, S) =
2010cbb1a941 added name_classrel/arities/arity;
wenzelm
parents: 20548
diff changeset
   247
  let val b = NameSpace.base t
2010cbb1a941 added name_classrel/arities/arity;
wenzelm
parents: 20548
diff changeset
   248
  in S |> map (fn c => NameSpace.base c ^ "_" ^ b) end;
2010cbb1a941 added name_classrel/arities/arity;
wenzelm
parents: 20548
diff changeset
   249
2010cbb1a941 added name_classrel/arities/arity;
wenzelm
parents: 20548
diff changeset
   250
fun name_arity (t, dom, c) = hd (name_arities (t, dom, [c]));
2010cbb1a941 added name_classrel/arities/arity;
wenzelm
parents: 20548
diff changeset
   251
19406
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   252
fun mk_arities (t, Ss, S) =
24848
5dbbd33c3236 replaced literal 'a by Name.aT;
wenzelm
parents: 24258
diff changeset
   253
  let val T = Type (t, ListPair.map TFree (Name.invents Name.context Name.aT (length Ss), Ss))
19406
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   254
  in map (fn c => mk_inclass (T, c)) S end;
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   255
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   256
fun dest_arity tm =
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   257
  let
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   258
    fun err () = raise TERM ("dest_arity", [tm]);
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   259
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   260
    val (ty, c) = dest_inclass tm;
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   261
    val (t, tvars) =
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   262
      (case ty of
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   263
        Type (t, tys) => (t, map dest_TVar tys handle TYPE _ => err ())
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   264
      | _ => err ());
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   265
    val Ss =
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   266
      if has_duplicates (eq_fst (op =)) tvars then err ()
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   267
      else map snd tvars;
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   268
  in (t, Ss, c) end;
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   269
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   270
18938
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
   271
24258
2f399483535a moved support for primitive defs to primitive_defs.ML;
wenzelm
parents: 23597
diff changeset
   272
  (** protected propositions and embedded terms **)
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   273
18029
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   274
val protectC = Const ("prop", propT --> propT);
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   275
fun protect t = protectC $ t;
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   276
18029
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   277
fun unprotect (Const ("prop", _) $ t) = t
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   278
  | unprotect t = raise TERM ("unprotect", [t]);
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   279
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   280
26424
a6cad32a27b0 eliminated theory ProtoPure;
wenzelm
parents: 25939
diff changeset
   281
fun mk_term t = Const ("Pure.term", Term.fastype_of t --> propT) $ t;
19775
06cb6743adf6 support embedded terms;
wenzelm
parents: 19425
diff changeset
   282
26424
a6cad32a27b0 eliminated theory ProtoPure;
wenzelm
parents: 25939
diff changeset
   283
fun dest_term (Const ("Pure.term", _) $ t) = t
19775
06cb6743adf6 support embedded terms;
wenzelm
parents: 19425
diff changeset
   284
  | dest_term t = raise TERM ("dest_term", [t]);
06cb6743adf6 support embedded terms;
wenzelm
parents: 19425
diff changeset
   285
06cb6743adf6 support embedded terms;
wenzelm
parents: 19425
diff changeset
   286
18181
wenzelm
parents: 18029
diff changeset
   287
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   288
(*** Low-level term operations ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   289
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   290
(*Does t occur in u?  Or is alpha-convertible to u?
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   291
  The term t must contain no loose bound variables*)
16846
bbebc68a7faf occs no longer infix (structure not open);
wenzelm
parents: 16130
diff changeset
   292
fun occs (t, u) = exists_subterm (fn s => t aconv s) u;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   293
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   294
(*Close up a formula over all free variables by quantification*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   295
fun close_form A =
19425
e0d7d9373faf added dest_conjunction_list;
wenzelm
parents: 19406
diff changeset
   296
  Term.list_all_free (rev (Term.add_frees A []), A);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   297
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   298
18938
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
   299
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   300
(*** Specialized operations for resolution... ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   301
18938
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
   302
(*computes t(Bound(n+k-1),...,Bound(n))  *)
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
   303
fun combound (t, n, k) =
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
   304
    if  k>0  then  combound (t,n+1,k-1) $ (Bound n)  else  t;
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
   305
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
   306
(* ([xn,...,x1], t)   ======>   (x1,...,xn)t *)
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
   307
fun rlist_abs ([], body) = body
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
   308
  | rlist_abs ((a,T)::pairs, body) = rlist_abs(pairs, Abs(a, T, body));
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
   309
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
   310
16879
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   311
local exception SAME in
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   312
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   313
fun incrT k =
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   314
  let
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   315
    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
   316
      | incr (Type (a, Ts)) = Type (a, incrs Ts)
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   317
      | incr _ = raise SAME
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   318
    and incrs (T :: Ts) =
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   319
        (incr T :: (incrs Ts handle SAME => Ts)
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   320
          handle SAME => T :: incrs Ts)
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   321
      | incrs [] = raise SAME;
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   322
  in incr end;
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   323
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   324
(*For all variables in the term, increment indexnames and lift over the Us
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   325
    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
   326
fun incr_indexes ([], 0) t = t
18029
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   327
  | incr_indexes (Ts, k) t =
16879
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   328
  let
18029
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   329
    val n = length Ts;
16879
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   330
    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
   331
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   332
    fun incr lev (Var ((x, i), T)) =
18938
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
   333
          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
   334
      | incr lev (Abs (x, T, body)) =
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   335
          (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
   336
            handle SAME => Abs (x, T, incr (lev + 1) body))
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   337
      | incr lev (t $ u) =
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   338
          (incr lev t $ (incr lev u handle SAME => u)
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   339
            handle SAME => t $ incr lev u)
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   340
      | incr _ (Const (c, T)) = Const (c, incrT T)
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   341
      | incr _ (Free (x, T)) = Free (x, incrT T)
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   342
      | incr _ (t as Bound _) = t;
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   343
  in incr 0 t handle SAME => t end;
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   344
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   345
fun incr_tvar 0 T = T
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   346
  | 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
   347
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   348
end;
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   349
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   350
18248
wenzelm
parents: 18181
diff changeset
   351
(* Lifting functions from subgoal and increment:
18029
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   352
    lift_abs operates on terms
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   353
    lift_all operates on propositions *)
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   354
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   355
fun lift_abs inc =
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   356
  let
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   357
    fun lift Ts (Const ("==>", _) $ _ $ B) t = lift Ts B t
18248
wenzelm
parents: 18181
diff changeset
   358
      | 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
   359
      | 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
   360
  in lift [] end;
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   361
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   362
fun lift_all inc =
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   363
  let
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   364
    fun lift Ts ((c as Const ("==>", _)) $ A $ B) t = c $ A $ lift Ts B t
18248
wenzelm
parents: 18181
diff changeset
   365
      | 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
   366
      | 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
   367
  in lift [] end;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   368
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   369
(*Strips assumptions in goal, yielding list of hypotheses.   *)
21016
430b35c9cd27 Repaired strip_assums_hyp (now also works for goals not
berghofe
parents: 20883
diff changeset
   370
fun strip_assums_hyp B =
430b35c9cd27 Repaired strip_assums_hyp (now also works for goals not
berghofe
parents: 20883
diff changeset
   371
  let
430b35c9cd27 Repaired strip_assums_hyp (now also works for goals not
berghofe
parents: 20883
diff changeset
   372
    fun strip Hs (Const ("==>", _) $ H $ B) = strip (H :: Hs) B
430b35c9cd27 Repaired strip_assums_hyp (now also works for goals not
berghofe
parents: 20883
diff changeset
   373
      | strip Hs (Const ("all", _) $ Abs (a, T, t)) =
430b35c9cd27 Repaired strip_assums_hyp (now also works for goals not
berghofe
parents: 20883
diff changeset
   374
          strip (map (incr_boundvars 1) Hs) t
430b35c9cd27 Repaired strip_assums_hyp (now also works for goals not
berghofe
parents: 20883
diff changeset
   375
      | strip Hs B = rev Hs
430b35c9cd27 Repaired strip_assums_hyp (now also works for goals not
berghofe
parents: 20883
diff changeset
   376
  in strip [] B end;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   377
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   378
(*Strips assumptions in goal, yielding conclusion.   *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   379
fun strip_assums_concl (Const("==>", _) $ H $ B) = strip_assums_concl B
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   380
  | strip_assums_concl (Const("all",_)$Abs(a,T,t)) = strip_assums_concl t
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   381
  | strip_assums_concl B = B;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   382
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   383
(*Make a list of all the parameters in a subgoal, even if nested*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   384
fun strip_params (Const("==>", _) $ H $ B) = strip_params B
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   385
  | strip_params (Const("all",_)$Abs(a,T,t)) = (a,T) :: strip_params t
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   386
  | strip_params B = [];
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   387
23597
ab67175ca8a5 simplified has_meta_prems;
wenzelm
parents: 23418
diff changeset
   388
(*test for nested meta connectives in prems*)
ab67175ca8a5 simplified has_meta_prems;
wenzelm
parents: 23418
diff changeset
   389
val has_meta_prems =
9667
48cefe2daf32 fixed has_meta_prems: strip_assums_hyp;
wenzelm
parents: 9483
diff changeset
   390
  let
23597
ab67175ca8a5 simplified has_meta_prems;
wenzelm
parents: 23418
diff changeset
   391
    fun is_meta (Const ("==", _) $ _ $ _) = true
ab67175ca8a5 simplified has_meta_prems;
wenzelm
parents: 23418
diff changeset
   392
      | is_meta (Const ("==>", _) $ _ $ _) = true
9667
48cefe2daf32 fixed has_meta_prems: strip_assums_hyp;
wenzelm
parents: 9483
diff changeset
   393
      | is_meta (Const ("all", _) $ _) = true
48cefe2daf32 fixed has_meta_prems: strip_assums_hyp;
wenzelm
parents: 9483
diff changeset
   394
      | is_meta _ = false;
23597
ab67175ca8a5 simplified has_meta_prems;
wenzelm
parents: 23418
diff changeset
   395
    fun ex_meta (Const ("==>", _) $ A $ B) = is_meta A orelse ex_meta B
ab67175ca8a5 simplified has_meta_prems;
wenzelm
parents: 23418
diff changeset
   396
      | ex_meta (Const ("all", _) $ Abs (_, _, B)) = ex_meta B
ab67175ca8a5 simplified has_meta_prems;
wenzelm
parents: 23418
diff changeset
   397
      | ex_meta _ = false;
ab67175ca8a5 simplified has_meta_prems;
wenzelm
parents: 23418
diff changeset
   398
  in ex_meta end;
9483
708a8a05497d added has_meta_prems;
wenzelm
parents: 9460
diff changeset
   399
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   400
(*Removes the parameters from a subgoal and renumber bvars in hypotheses,
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   401
    where j is the total number of parameters (precomputed)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   402
  If n>0 then deletes assumption n. *)
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   403
fun remove_params j n A =
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   404
    if j=0 andalso n<=0 then A  (*nothing left to do...*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   405
    else case A of
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   406
        Const("==>", _) $ H $ B =>
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   407
          if n=1 then                           (remove_params j (n-1) B)
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   408
          else implies $ (incr_boundvars j H) $ (remove_params j (n-1) B)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   409
      | Const("all",_)$Abs(a,T,t) => remove_params (j-1) n t
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   410
      | _ => if n>0 then raise TERM("remove_params", [A])
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   411
             else A;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   412
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   413
(*Move all parameters to the front of the subgoal, renaming them apart;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   414
  if n>0 then deletes assumption n. *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   415
fun flatten_params n A =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   416
    let val params = strip_params A;
25939
ddea202704b4 Removed Logic.auto_rename.
berghofe
parents: 24848
diff changeset
   417
        val vars = ListPair.zip (Name.variant_list [] (map #1 params),
ddea202704b4 Removed Logic.auto_rename.
berghofe
parents: 24848
diff changeset
   418
                                 map #2 params)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   419
    in  list_all (vars, remove_params (length vars) n A)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   420
    end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   421
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   422
(*Makes parameters in a goal have the names supplied by the list cs.*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   423
fun list_rename_params (cs, Const("==>", _) $ A $ B) =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   424
      implies $ A $ list_rename_params (cs, B)
27334
3f17273766f2 added all, is_all;
wenzelm
parents: 26424
diff changeset
   425
  | list_rename_params (c::cs, (a as Const("all",_)) $ Abs(_,T,t)) =
3f17273766f2 added all, is_all;
wenzelm
parents: 26424
diff changeset
   426
      a $ Abs(c, T, list_rename_params (cs, t))
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   427
  | list_rename_params (cs, B) = B;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   428
19806
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   429
(*** Treatment of "assume", "erule", etc. ***)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   430
16879
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   431
(*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
   432
   HS = [Hn,...,H1],   params = [xm,...,x1], and B,
16879
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   433
  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
   434
  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
   435
  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
   436
  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
   437
  Used ONLY by assum_pairs.
4b339d3907a0 thin_tac now works on P==>Q
paulson
parents: 15451
diff changeset
   438
      Unless nasms<0, it can terminate the recursion early; that allows
4b339d3907a0 thin_tac now works on P==>Q
paulson
parents: 15451
diff changeset
   439
  erule to work on assumptions of the form P==>Q.*)
4b339d3907a0 thin_tac now works on P==>Q
paulson
parents: 15451
diff changeset
   440
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
   441
  | strip_assums_imp (nasms, Hs, Const("==>", _) $ H $ B) =
15454
4b339d3907a0 thin_tac now works on P==>Q
paulson
parents: 15451
diff changeset
   442
      strip_assums_imp (nasms-1, H::Hs, B)
4b339d3907a0 thin_tac now works on P==>Q
paulson
parents: 15451
diff changeset
   443
  | strip_assums_imp (_, Hs, B) = (Hs, B); (*recursion terminated by B*)
4b339d3907a0 thin_tac now works on P==>Q
paulson
parents: 15451
diff changeset
   444
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   445
15451
c6c8786b9921 fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents: 14137
diff changeset
   446
(*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
   447
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
   448
      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
   449
  | strip_assums_all (params, B) = (params, B);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   450
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   451
(*Produces disagreement pairs, one for each assumption proof, in order.
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   452
  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
   453
    H1 ==> ... Hk ==> B   and the pairs are (H1,B),...,(Hk,B).
4b339d3907a0 thin_tac now works on P==>Q
paulson
parents: 15451
diff changeset
   454
  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
   455
    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
   456
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
   457
  let val (params, A') = strip_assums_all ([],A)
15454
4b339d3907a0 thin_tac now works on P==>Q
paulson
parents: 15451
diff changeset
   458
      val (Hs,B) = strip_assums_imp (nasms,[],A')
18938
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
   459
      fun abspar t = rlist_abs(params, t)
15451
c6c8786b9921 fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents: 14137
diff changeset
   460
      val D = abspar B
c6c8786b9921 fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents: 14137
diff changeset
   461
      fun pairrev ([], pairs) = pairs
c6c8786b9921 fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents: 14137
diff changeset
   462
        | 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
   463
  in  pairrev (Hs,[])
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   464
  end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   465
19806
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   466
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   467
(* global schematic variables *)
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   468
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   469
fun bad_schematic xi = "Illegal schematic variable: " ^ quote (Term.string_of_vname xi);
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   470
fun bad_fixed x = "Illegal fixed variable: " ^ quote x;
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   471
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   472
fun varifyT ty = ty |> Term.map_atyps
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   473
  (fn TFree (a, S) => TVar ((a, 0), S)
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   474
    | TVar (ai, _) => raise TYPE (bad_schematic ai, [ty], []));
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   475
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   476
fun unvarifyT ty = ty |> Term.map_atyps
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   477
  (fn TVar ((a, 0), S) => TFree (a, S)
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   478
    | TVar (ai, _) => raise TYPE (bad_schematic ai, [ty], [])
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   479
    | TFree (a, _) => raise TYPE (bad_fixed a, [ty], []));
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   480
19806
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   481
fun varify tm =
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   482
  tm |> Term.map_aterms
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   483
    (fn Free (x, T) => Var ((x, 0), T)
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   484
      | Var (xi, _) => raise TERM (bad_schematic xi, [tm])
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   485
      | t => t)
20548
8ef25fe585a8 renamed Term.map_term_types to Term.map_types (cf. Term.fold_types);
wenzelm
parents: 20078
diff changeset
   486
  |> Term.map_types varifyT
19879
6a346150611a (un)varify: tuned exceptions;
wenzelm
parents: 19806
diff changeset
   487
  handle TYPE (msg, _, _) => raise TERM (msg, [tm]);
19806
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   488
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   489
fun unvarify tm =
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   490
  tm |> Term.map_aterms
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   491
    (fn Var ((x, 0), T) => Free (x, T)
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   492
      | Var (xi, _) => raise TERM (bad_schematic xi, [tm])
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   493
      | Free (x, _) => raise TERM (bad_fixed x, [tm])
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   494
      | t => t)
20548
8ef25fe585a8 renamed Term.map_term_types to Term.map_types (cf. Term.fold_types);
wenzelm
parents: 20078
diff changeset
   495
  |> Term.map_types unvarifyT
19879
6a346150611a (un)varify: tuned exceptions;
wenzelm
parents: 19806
diff changeset
   496
  handle TYPE (msg, _, _) => raise TERM (msg, [tm]);
19806
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   497
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   498
val legacy_varifyT = Term.map_atyps (fn TFree (a, S) => TVar ((a, 0), S) | T => T);
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   499
val legacy_unvarifyT = Term.map_atyps (fn TVar ((a, 0), S) => TFree (a, S) | T => T);
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   500
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   501
val legacy_varify =
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   502
  Term.map_aterms (fn Free (x, T) => Var ((x, 0), T) | t => t) #>
20548
8ef25fe585a8 renamed Term.map_term_types to Term.map_types (cf. Term.fold_types);
wenzelm
parents: 20078
diff changeset
   503
  Term.map_types legacy_varifyT;
19806
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   504
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   505
val legacy_unvarify =
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   506
  Term.map_aterms (fn Var ((x, 0), T) => Free (x, T) | t => t) #>
20548
8ef25fe585a8 renamed Term.map_term_types to Term.map_types (cf. Term.fold_types);
wenzelm
parents: 20078
diff changeset
   507
  Term.map_types legacy_unvarifyT;
546
36e40454e03e /unvarifyT, unvarify: moved to Pure/logic.ML
lcp
parents: 447
diff changeset
   508
13799
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   509
16862
wenzelm
parents: 16846
diff changeset
   510
(* goal states *)
wenzelm
parents: 16846
diff changeset
   511
wenzelm
parents: 16846
diff changeset
   512
fun get_goal st i = nth_prem (i, st)
wenzelm
parents: 16846
diff changeset
   513
  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
   514
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   515
(*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
   516
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
   517
  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
   518
      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
   519
  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
   520
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   521
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
   522
  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
   523
      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
   524
  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
   525
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   526
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
   527
  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
   528
      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
   529
  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
   530
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   531
end;