src/Pure/term_ord.ML
author wenzelm
Thu, 09 Sep 2021 14:50:26 +0200
changeset 74269 f084d599bb44
parent 74266 612b7e0d6721
child 74270 ad2899cdd528
permissions -rw-r--r--
clarified set of items with order of addition;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29269
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/term_ord.ML
74265
wenzelm
parents: 74260
diff changeset
     2
    Author:     Tobias Nipkow, TU Muenchen
wenzelm
parents: 74260
diff changeset
     3
    Author:     Makarius
29269
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
     4
74265
wenzelm
parents: 74260
diff changeset
     5
Term orderings and scalable collections.
29269
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
     6
*)
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
     7
74266
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
     8
signature ITEMS =
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
     9
sig
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    10
  type key
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    11
  type 'a table
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    12
  val empty: 'a table
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    13
  val build: ('a table -> 'a table) -> 'a table
74269
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
    14
  val size: 'a table -> int
74266
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    15
  val is_empty: 'a table -> bool
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    16
  val map: (key -> 'a -> 'b) -> 'a table -> 'b table
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    17
  val fold: (key * 'b -> 'a -> 'a) -> 'b table -> 'a -> 'a
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    18
  val fold_rev: (key * 'b -> 'a -> 'a) -> 'b table -> 'a -> 'a
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    19
  val dest: 'a table -> (key * 'a) list
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    20
  val keys: 'a table -> key list
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    21
  val exists: (key * 'a -> bool) -> 'a table -> bool
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    22
  val forall: (key * 'a -> bool) -> 'a table -> bool
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    23
  val get_first: (key * 'a -> 'b option) -> 'a table -> 'b option
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    24
  val lookup: 'a table -> key -> 'a option
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    25
  val defined: 'a table -> key -> bool
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    26
  val add: key * 'a -> 'a table -> 'a table
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    27
  val make: (key * 'a) list -> 'a table
74269
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
    28
  type set = int table
74266
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    29
  val add_set: key -> set -> set
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    30
  val make_set: key list -> set
74269
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
    31
  val list_set: set -> key list
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
    32
  val list_set_rev: set -> key list
74266
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    33
  val subset: set * set -> bool
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    34
  val eq_set: set * set -> bool
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    35
end;
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    36
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    37
functor Items(Key: KEY): ITEMS =
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    38
struct
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    39
74269
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
    40
(* table with length *)
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
    41
74266
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    42
structure Table = Table(Key);
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    43
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    44
type key = Table.key;
74269
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
    45
datatype 'a table = Items of int * 'a Table.table;
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
    46
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
    47
fun size (Items (n, _)) = n;
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
    48
fun table (Items (_, tab)) = tab;
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
    49
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
    50
val empty = Items (0, Table.empty);
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
    51
fun build (f: 'a table -> 'a table) = f empty;
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
    52
fun is_empty items = size items = 0;
74266
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    53
74269
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
    54
fun dest items = Table.dest (table items);
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
    55
fun keys items = Table.keys (table items);
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
    56
fun exists pred = Table.exists pred o table;
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
    57
fun forall pred = Table.forall pred o table;
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
    58
fun get_first get = Table.get_first get o table;
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
    59
fun lookup items = Table.lookup (table items);
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
    60
fun defined items = Table.defined (table items);
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
    61
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
    62
fun add (key, x) (items as Items (n, tab)) =
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
    63
  if Table.defined tab key then items
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
    64
  else Items (n + 1, Table.update_new (key, x) tab);
74266
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    65
74269
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
    66
fun make entries = build (fold add entries);
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
    67
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
    68
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
    69
(* set with order of addition *)
74266
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    70
74269
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
    71
type set = int table;
74266
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    72
74269
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
    73
fun add_set x (items as Items (n, tab)) =
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
    74
  if Table.defined tab x then items
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
    75
  else Items (n + 1, Table.update_new (x, n) tab);
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
    76
74266
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    77
fun make_set xs = build (fold add_set xs);
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    78
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    79
fun subset (A: set, B: set) = forall (defined B o #1) A;
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    80
fun eq_set (A: set, B: set) = size A = size B andalso subset (A, B);
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    81
74269
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
    82
fun list_set_ord ord items = Table.dest (table items) |> sort (ord o apply2 #2) |> map #1
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
    83
val list_set = list_set_ord int_ord;
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
    84
val list_set_rev = list_set_ord (rev_order o int_ord);
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
    85
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
    86
fun map f (Items (n, tab)) = Items (n, Table.map f tab);
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
    87
fun fold f = Table.fold f o table;
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
    88
fun fold_rev f = Table.fold_rev f o table;
74266
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    89
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    90
end;
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    91
32841
57dcddf81b01 added term_cache;
wenzelm
parents: 31976
diff changeset
    92
signature BASIC_TERM_ORD =
57dcddf81b01 added term_cache;
wenzelm
parents: 31976
diff changeset
    93
sig
57dcddf81b01 added term_cache;
wenzelm
parents: 31976
diff changeset
    94
  structure Vartab: TABLE
57dcddf81b01 added term_cache;
wenzelm
parents: 31976
diff changeset
    95
  structure Sorttab: TABLE
57dcddf81b01 added term_cache;
wenzelm
parents: 31976
diff changeset
    96
  structure Typtab: TABLE
57dcddf81b01 added term_cache;
wenzelm
parents: 31976
diff changeset
    97
  structure Termtab: TABLE
74265
wenzelm
parents: 74260
diff changeset
    98
  structure Var_Graph: GRAPH
wenzelm
parents: 74260
diff changeset
    99
  structure Sort_Graph: GRAPH
wenzelm
parents: 74260
diff changeset
   100
  structure Typ_Graph: GRAPH
wenzelm
parents: 74260
diff changeset
   101
  structure Term_Graph: GRAPH
74266
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   102
  structure TFrees:
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   103
  sig
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   104
    include ITEMS
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   105
    val add_tfreesT: typ -> set -> set
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   106
    val add_tfrees: term -> set -> set
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   107
  end
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   108
  structure TVars:
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   109
  sig
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   110
    include ITEMS
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   111
    val add_tvarsT: typ -> set -> set
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   112
    val add_tvars: term -> set -> set
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   113
  end
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   114
  structure Frees:
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   115
  sig
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   116
    include ITEMS
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   117
    val add_frees: term -> set -> set
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   118
  end
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   119
  structure Vars:
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   120
  sig
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   121
    include ITEMS
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   122
    val add_vars: term -> set -> set
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   123
  end
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   124
  structure Names:
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   125
  sig
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   126
    include ITEMS
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   127
    val add_tfree_namesT: typ -> set -> set
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   128
    val add_tfree_names: term -> set -> set
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   129
    val add_free_names: term -> set -> set
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   130
  end
32841
57dcddf81b01 added term_cache;
wenzelm
parents: 31976
diff changeset
   131
end;
57dcddf81b01 added term_cache;
wenzelm
parents: 31976
diff changeset
   132
29269
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   133
signature TERM_ORD =
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   134
sig
32841
57dcddf81b01 added term_cache;
wenzelm
parents: 31976
diff changeset
   135
  include BASIC_TERM_ORD
70586
57df8a85317a clarified signature;
wenzelm
parents: 67561
diff changeset
   136
  val fast_indexname_ord: indexname ord
57df8a85317a clarified signature;
wenzelm
parents: 67561
diff changeset
   137
  val sort_ord: sort ord
57df8a85317a clarified signature;
wenzelm
parents: 67561
diff changeset
   138
  val typ_ord: typ ord
57df8a85317a clarified signature;
wenzelm
parents: 67561
diff changeset
   139
  val fast_term_ord: term ord
57df8a85317a clarified signature;
wenzelm
parents: 67561
diff changeset
   140
  val syntax_term_ord: term ord
57df8a85317a clarified signature;
wenzelm
parents: 67561
diff changeset
   141
  val indexname_ord: indexname ord
57df8a85317a clarified signature;
wenzelm
parents: 67561
diff changeset
   142
  val tvar_ord: (indexname * sort) ord
57df8a85317a clarified signature;
wenzelm
parents: 67561
diff changeset
   143
  val var_ord: (indexname * typ) ord
57df8a85317a clarified signature;
wenzelm
parents: 67561
diff changeset
   144
  val term_ord: term ord
57df8a85317a clarified signature;
wenzelm
parents: 67561
diff changeset
   145
  val hd_ord: term ord
57df8a85317a clarified signature;
wenzelm
parents: 67561
diff changeset
   146
  val term_lpo: (term -> int) -> term ord
32841
57dcddf81b01 added term_cache;
wenzelm
parents: 31976
diff changeset
   147
  val term_cache: (term -> 'a) -> term -> 'a
29269
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   148
end;
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   149
35408
b48ab741683b modernized structure Term_Ord;
wenzelm
parents: 35406
diff changeset
   150
structure Term_Ord: TERM_ORD =
29269
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   151
struct
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   152
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   153
(* fast syntactic ordering -- tuned for inequalities *)
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   154
74260
bb37fb85d82c pointer_eq_ord: minor performance tuning;
wenzelm
parents: 73863
diff changeset
   155
val fast_indexname_ord =
bb37fb85d82c pointer_eq_ord: minor performance tuning;
wenzelm
parents: 73863
diff changeset
   156
  pointer_eq_ord (int_ord o apply2 snd ||| fast_string_ord o apply2 fst);
29269
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   157
74260
bb37fb85d82c pointer_eq_ord: minor performance tuning;
wenzelm
parents: 73863
diff changeset
   158
val sort_ord =
bb37fb85d82c pointer_eq_ord: minor performance tuning;
wenzelm
parents: 73863
diff changeset
   159
  pointer_eq_ord (dict_ord fast_string_ord);
29269
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   160
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   161
local
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   162
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   163
fun cons_nr (TVar _) = 0
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   164
  | cons_nr (TFree _) = 1
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   165
  | cons_nr (Type _) = 2;
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   166
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   167
in
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   168
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   169
fun typ_ord TU =
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   170
  if pointer_eq TU then EQUAL
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   171
  else
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   172
    (case TU of
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   173
      (Type (a, Ts), Type (b, Us)) =>
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   174
        (case fast_string_ord (a, b) of EQUAL => dict_ord typ_ord (Ts, Us) | ord => ord)
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   175
    | (TFree (a, S), TFree (b, S')) =>
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   176
        (case fast_string_ord (a, b) of EQUAL => sort_ord (S, S') | ord => ord)
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   177
    | (TVar (xi, S), TVar (yj, S')) =>
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   178
        (case fast_indexname_ord (xi, yj) of EQUAL => sort_ord (S, S') | ord => ord)
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   179
    | (T, U) => int_ord (cons_nr T, cons_nr U));
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   180
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   181
end;
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   182
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   183
local
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   184
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   185
fun cons_nr (Const _) = 0
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   186
  | cons_nr (Free _) = 1
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   187
  | cons_nr (Var _) = 2
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   188
  | cons_nr (Bound _) = 3
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   189
  | cons_nr (Abs _) = 4
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   190
  | cons_nr (_ $ _) = 5;
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   191
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   192
fun struct_ord (Abs (_, _, t), Abs (_, _, u)) = struct_ord (t, u)
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   193
  | struct_ord (t1 $ t2, u1 $ u2) =
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   194
      (case struct_ord (t1, u1) of EQUAL => struct_ord (t2, u2) | ord => ord)
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   195
  | struct_ord (t, u) = int_ord (cons_nr t, cons_nr u);
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   196
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   197
fun atoms_ord (Abs (_, _, t), Abs (_, _, u)) = atoms_ord (t, u)
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   198
  | atoms_ord (t1 $ t2, u1 $ u2) =
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   199
      (case atoms_ord (t1, u1) of EQUAL => atoms_ord (t2, u2) | ord => ord)
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   200
  | atoms_ord (Const (a, _), Const (b, _)) = fast_string_ord (a, b)
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   201
  | atoms_ord (Free (x, _), Free (y, _)) = fast_string_ord (x, y)
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   202
  | atoms_ord (Var (xi, _), Var (yj, _)) = fast_indexname_ord (xi, yj)
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   203
  | atoms_ord (Bound i, Bound j) = int_ord (i, j)
43794
49cbbe2768a8 sub-structural sharing after Syntax.check phase, with global interning of logical entities (the latter is relevant when bypassing default parsing via YXML);
wenzelm
parents: 37852
diff changeset
   204
  | atoms_ord _ = EQUAL;
29269
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   205
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   206
fun types_ord (Abs (_, T, t), Abs (_, U, u)) =
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   207
      (case typ_ord (T, U) of EQUAL => types_ord (t, u) | ord => ord)
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   208
  | types_ord (t1 $ t2, u1 $ u2) =
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   209
      (case types_ord (t1, u1) of EQUAL => types_ord (t2, u2) | ord => ord)
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   210
  | types_ord (Const (_, T), Const (_, U)) = typ_ord (T, U)
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   211
  | types_ord (Free (_, T), Free (_, U)) = typ_ord (T, U)
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   212
  | types_ord (Var (_, T), Var (_, U)) = typ_ord (T, U)
43794
49cbbe2768a8 sub-structural sharing after Syntax.check phase, with global interning of logical entities (the latter is relevant when bypassing default parsing via YXML);
wenzelm
parents: 37852
diff changeset
   213
  | types_ord _ = EQUAL;
49cbbe2768a8 sub-structural sharing after Syntax.check phase, with global interning of logical entities (the latter is relevant when bypassing default parsing via YXML);
wenzelm
parents: 37852
diff changeset
   214
49cbbe2768a8 sub-structural sharing after Syntax.check phase, with global interning of logical entities (the latter is relevant when bypassing default parsing via YXML);
wenzelm
parents: 37852
diff changeset
   215
fun comments_ord (Abs (x, _, t), Abs (y, _, u)) =
49cbbe2768a8 sub-structural sharing after Syntax.check phase, with global interning of logical entities (the latter is relevant when bypassing default parsing via YXML);
wenzelm
parents: 37852
diff changeset
   216
      (case fast_string_ord (x, y) of EQUAL => comments_ord (t, u) | ord => ord)
49cbbe2768a8 sub-structural sharing after Syntax.check phase, with global interning of logical entities (the latter is relevant when bypassing default parsing via YXML);
wenzelm
parents: 37852
diff changeset
   217
  | comments_ord (t1 $ t2, u1 $ u2) =
49cbbe2768a8 sub-structural sharing after Syntax.check phase, with global interning of logical entities (the latter is relevant when bypassing default parsing via YXML);
wenzelm
parents: 37852
diff changeset
   218
      (case comments_ord (t1, u1) of EQUAL => comments_ord (t2, u2) | ord => ord)
49cbbe2768a8 sub-structural sharing after Syntax.check phase, with global interning of logical entities (the latter is relevant when bypassing default parsing via YXML);
wenzelm
parents: 37852
diff changeset
   219
  | comments_ord _ = EQUAL;
29269
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   220
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   221
in
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   222
73863
wenzelm
parents: 70586
diff changeset
   223
val fast_term_ord = pointer_eq_ord (struct_ord ||| atoms_ord ||| types_ord);
29269
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   224
73863
wenzelm
parents: 70586
diff changeset
   225
val syntax_term_ord = fast_term_ord ||| comments_ord;
43794
49cbbe2768a8 sub-structural sharing after Syntax.check phase, with global interning of logical entities (the latter is relevant when bypassing default parsing via YXML);
wenzelm
parents: 37852
diff changeset
   226
29269
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   227
end;
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   228
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   229
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   230
(* term_ord *)
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   231
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   232
(*a linear well-founded AC-compatible ordering for terms:
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   233
  s < t <=> 1. size(s) < size(t) or
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   234
            2. size(s) = size(t) and s=f(...) and t=g(...) and f<g or
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   235
            3. size(s) = size(t) and s=f(s1..sn) and t=f(t1..tn) and
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   236
               (s1..sn) < (t1..tn) (lexicographically)*)
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   237
73863
wenzelm
parents: 70586
diff changeset
   238
val indexname_ord = int_ord o apply2 #2 ||| string_ord o apply2 #1;
29269
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   239
val tvar_ord = prod_ord indexname_ord sort_ord;
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   240
val var_ord = prod_ord indexname_ord typ_ord;
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   241
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   242
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   243
local
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   244
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   245
fun hd_depth (t $ _, n) = hd_depth (t, n + 1)
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   246
  | hd_depth p = p;
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   247
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   248
fun dest_hd (Const (a, T)) = (((a, 0), T), 0)
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   249
  | dest_hd (Free (a, T)) = (((a, 0), T), 1)
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   250
  | dest_hd (Var v) = (v, 2)
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   251
  | dest_hd (Bound i) = ((("", i), dummyT), 3)
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   252
  | dest_hd (Abs (_, T, _)) = ((("", 0), T), 4);
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   253
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   254
in
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   255
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   256
fun term_ord tu =
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   257
  if pointer_eq tu then EQUAL
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   258
  else
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   259
    (case tu of
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   260
      (Abs (_, T, t), Abs(_, U, u)) =>
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   261
        (case term_ord (t, u) of EQUAL => typ_ord (T, U) | ord => ord)
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   262
    | (t, u) =>
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   263
        (case int_ord (size_of_term t, size_of_term u) of
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   264
          EQUAL =>
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   265
            (case prod_ord hd_ord int_ord (hd_depth (t, 0), hd_depth (u, 0)) of
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   266
              EQUAL => args_ord (t, u) | ord => ord)
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   267
        | ord => ord))
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   268
and hd_ord (f, g) =
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   269
  prod_ord (prod_ord indexname_ord typ_ord) int_ord (dest_hd f, dest_hd g)
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   270
and args_ord (f $ t, g $ u) =
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   271
      (case args_ord (f, g) of EQUAL => term_ord (t, u) | ord => ord)
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   272
  | args_ord _ = EQUAL;
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   273
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   274
end;
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   275
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   276
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   277
(* Lexicographic path order on terms *)
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   278
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   279
(*
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   280
  See Baader & Nipkow, Term rewriting, CUP 1998.
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   281
  Without variables.  Const, Var, Bound, Free and Abs are treated all as
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   282
  constants.
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   283
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   284
  f_ord maps terms to integers and serves two purposes:
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   285
  - Predicate on constant symbols.  Those that are not recognised by f_ord
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   286
    must be mapped to ~1.
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   287
  - Order on the recognised symbols.  These must be mapped to distinct
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   288
    integers >= 0.
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   289
  The argument of f_ord is never an application.
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   290
*)
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   291
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   292
local
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   293
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   294
fun unrecognized (Const (a, T)) = ((1, ((a, 0), T)), 0)
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   295
  | unrecognized (Free (a, T)) = ((1, ((a, 0), T)), 0)
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   296
  | unrecognized (Var v) = ((1, v), 1)
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   297
  | unrecognized (Bound i) = ((1, (("", i), dummyT)), 2)
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   298
  | unrecognized (Abs (_, T, _)) = ((1, (("", 0), T)), 3);
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   299
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   300
fun dest_hd f_ord t =
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   301
  let val ord = f_ord t
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   302
  in if ord = ~1 then unrecognized t else ((0, (("", ord), fastype_of t)), 0) end;
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   303
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   304
fun term_lpo f_ord (s, t) =
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   305
  let val (f, ss) = strip_comb s and (g, ts) = strip_comb t in
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   306
    if forall (fn si => term_lpo f_ord (si, t) = LESS) ss
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   307
    then case hd_ord f_ord (f, g) of
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   308
        GREATER =>
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   309
          if forall (fn ti => term_lpo f_ord (s, ti) = GREATER) ts
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   310
          then GREATER else LESS
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   311
      | EQUAL =>
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   312
          if forall (fn ti => term_lpo f_ord (s, ti) = GREATER) ts
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   313
          then list_ord (term_lpo f_ord) (ss, ts)
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   314
          else LESS
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   315
      | LESS => LESS
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   316
    else GREATER
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   317
  end
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   318
and hd_ord f_ord (f, g) = case (f, g) of
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   319
    (Abs (_, T, t), Abs (_, U, u)) =>
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   320
      (case term_lpo f_ord (t, u) of EQUAL => typ_ord (T, U) | ord => ord)
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   321
  | (_, _) => prod_ord (prod_ord int_ord
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   322
                  (prod_ord indexname_ord typ_ord)) int_ord
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   323
                (dest_hd f_ord f, dest_hd f_ord g);
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   324
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   325
in
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   326
val term_lpo = term_lpo
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   327
end;
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   328
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   329
74265
wenzelm
parents: 74260
diff changeset
   330
(* scalable collections *)
32841
57dcddf81b01 added term_cache;
wenzelm
parents: 31976
diff changeset
   331
57dcddf81b01 added term_cache;
wenzelm
parents: 31976
diff changeset
   332
structure Vartab = Table(type key = indexname val ord = fast_indexname_ord);
57dcddf81b01 added term_cache;
wenzelm
parents: 31976
diff changeset
   333
structure Sorttab = Table(type key = sort val ord = sort_ord);
57dcddf81b01 added term_cache;
wenzelm
parents: 31976
diff changeset
   334
structure Typtab = Table(type key = typ val ord = typ_ord);
57dcddf81b01 added term_cache;
wenzelm
parents: 31976
diff changeset
   335
structure Termtab = Table(type key = term val ord = fast_term_ord);
57dcddf81b01 added term_cache;
wenzelm
parents: 31976
diff changeset
   336
74266
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   337
fun term_cache f = Cache.create Termtab.empty Termtab.lookup Termtab.update f;
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   338
74265
wenzelm
parents: 74260
diff changeset
   339
structure Var_Graph = Graph(type key = indexname val ord = fast_indexname_ord);
wenzelm
parents: 74260
diff changeset
   340
structure Sort_Graph = Graph(type key = sort val ord = sort_ord);
wenzelm
parents: 74260
diff changeset
   341
structure Typ_Graph = Graph(type key = typ val ord = typ_ord);
wenzelm
parents: 74260
diff changeset
   342
structure Term_Graph = Graph(type key = term val ord = fast_term_ord);
wenzelm
parents: 74260
diff changeset
   343
74266
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   344
structure TFrees =
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   345
struct
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   346
  structure Items =
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   347
    Items(type key = string * sort val ord = pointer_eq_ord (prod_ord fast_string_ord sort_ord));
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   348
  open Items;
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   349
  val add_tfreesT = fold_atyps (fn TFree v => add_set v | _ => I);
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   350
  val add_tfrees = fold_types add_tfreesT;
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   351
end;
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   352
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   353
structure TVars =
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   354
struct
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   355
  structure Items =
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   356
    Items(type key = indexname * sort val ord = pointer_eq_ord (prod_ord fast_indexname_ord sort_ord));
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   357
  open Items;
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   358
  val add_tvarsT = fold_atyps (fn TVar v => add_set v | _ => I);
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   359
  val add_tvars = fold_types add_tvarsT;
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   360
end;
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   361
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   362
structure Frees =
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   363
struct
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   364
  structure Items =
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   365
    Items(type key = string * typ val ord = pointer_eq_ord (prod_ord fast_string_ord typ_ord));
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   366
  open Items;
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   367
  val add_frees = fold_aterms (fn Free v => add_set v | _ => I);
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   368
end;
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   369
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   370
structure Vars =
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   371
struct
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   372
  structure Items =
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   373
    Items(type key = indexname * typ val ord = pointer_eq_ord (prod_ord fast_indexname_ord typ_ord));
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   374
  open Items;
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   375
  val add_vars = fold_aterms (fn Var v => add_set v | _ => I);
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   376
end;
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   377
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   378
structure Names =
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   379
struct
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   380
  structure Items = Items(type key = string val ord = fast_string_ord);
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   381
  open Items;
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   382
  val add_tfree_namesT = fold_atyps (fn TFree (a, _) => add_set a | _ => I);
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   383
  val add_tfree_names = fold_types add_tfree_namesT;
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   384
  val add_free_names = fold_aterms (fn Free (x, _) => add_set x | _ => I);
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   385
end;
32841
57dcddf81b01 added term_cache;
wenzelm
parents: 31976
diff changeset
   386
29269
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   387
end;
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
diff changeset
   388
35408
b48ab741683b modernized structure Term_Ord;
wenzelm
parents: 35406
diff changeset
   389
structure Basic_Term_Ord: BASIC_TERM_ORD = Term_Ord;
32841
57dcddf81b01 added term_cache;
wenzelm
parents: 31976
diff changeset
   390
open Basic_Term_Ord;