Comparing terms

Author(s): Daniel Cabeza, Manuel Hermenegildo.

These built-in predicates are extra-logical. They treat uninstantiated variables as objects with values which may be compared, and they never instantiate those variables. They should not be used when what you really want is arithmetic comparison or unification.

The predicates make reference to a standard total ordering of terms, which is as follows:

  • Variables, by age (roughly, oldest first -- the order is not related to the names of variables).

  • Floats, in numeric order (e.g. -1.0 is put before 1.0).

  • Integers, in numeric order (e.g. -1 is put before 1).

  • Atoms, in alphabetical (i.e. character code) order.

  • Compound terms, ordered first by arity, then by the name of the principal functor, then by the arguments in left-to-right order. Recall that lists are equivalent to compound terms with principal functor '.'/2.

For example, here is a list of terms in standard order:

[ X, -1.0, -9, 1, bar, foo, [1], X = Y, foo(0,2), bar(1,1,1) ]

Usage and interface

Documentation on exports

PROPERTY

Usage:Term1==Term2

The terms Term1 and Term2 are strictly identical.

    General properties:

    True:Term1==Term2

    • The following properties hold globally:
      (basic_props:not_further_inst/2)Term1 is not further instantiated.
      (basic_props:not_further_inst/2)Term2 is not further instantiated.
      (basic_props:sideff/2)Term1==Term2 is side-effect free.
      (basic_props:native/1)This predicate is understood natively by CiaoPP.

    True:Term1==Term2

    • If the following properties hold at call time:
      (term_typing:ground/1)Term1 is currently ground (it contains no variables).
      (term_typing:ground/1)Term2 is currently ground (it contains no variables).
      then the following properties hold globally:
      (basic_props:eval/1)Term1==Term2 is evaluable at compile-time.

    Trust:Term1==Term2

    • The following properties hold globally:
      (native_props:is_det/1)All calls of the form Term1==Term2 are deterministic.
      (native_props:test_type/2)Indicates the type of test that a predicate performs. Required by the nonfailure analyisis.

    PREDICATE

    (Trust) Usage:Term1\==Term2

    The terms Term1 and Term2 are not strictly identical.

    • The following properties hold globally:
      (basic_props:not_further_inst/2)Term1 is not further instantiated.
      (basic_props:not_further_inst/2)Term2 is not further instantiated.
      (basic_props:sideff/2)Term1\==Term2 is side-effect free.
      (basic_props:native/1)This predicate is understood natively by CiaoPP.
    General properties:

    True:Term1\==Term2

    • If the following properties hold at call time:
      (term_typing:ground/1)Term1 is currently ground (it contains no variables).
      (term_typing:ground/1)Term2 is currently ground (it contains no variables).
      then the following properties hold globally:
      (basic_props:eval/1)Term1\==Term2 is evaluable at compile-time.

    Trust:Term1\==Term2

    • The following properties hold globally:
      (native_props:is_det/1)All calls of the form Term1\==Term2 are deterministic.
      (native_props:test_type/2)Indicates the type of test that a predicate performs. Required by the nonfailure analyisis.

    PREDICATE

    (Trust) Usage:Term1@<Term2

    The term Term1 precedes the term Term2 in the standard order.

    • The following properties hold globally:
      (basic_props:not_further_inst/2)Term1 is not further instantiated.
      (basic_props:not_further_inst/2)Term2 is not further instantiated.
      (basic_props:sideff/2)Term1@<Term2 is side-effect free.
      (basic_props:native/1)This predicate is understood natively by CiaoPP.
    General properties:

    True:Term1@<Term2

    • If the following properties hold at call time:
      (term_typing:ground/1)Term1 is currently ground (it contains no variables).
      (term_typing:ground/1)Term2 is currently ground (it contains no variables).
      then the following properties hold globally:
      (basic_props:eval/1)Term1@<Term2 is evaluable at compile-time.

    PREDICATE

    (Trust) Usage:Term1@=<Term2

    The term Term1 precedes or is identical to the term Term2 in the standard order.

    • The following properties hold globally:
      (basic_props:not_further_inst/2)Term1 is not further instantiated.
      (basic_props:not_further_inst/2)Term2 is not further instantiated.
      (basic_props:sideff/2)Term1@=<Term2 is side-effect free.
      (basic_props:native/1)This predicate is understood natively by CiaoPP.
    General properties:

    True:Term1@=<Term2

    • If the following properties hold at call time:
      (term_typing:ground/1)Term1 is currently ground (it contains no variables).
      (term_typing:ground/1)Term2 is currently ground (it contains no variables).
      then the following properties hold globally:
      (basic_props:eval/1)Term1@=<Term2 is evaluable at compile-time.

    PREDICATE

    (Trust) Usage:Term1@>Term2

    The term Term1 follows the term Term2 in the standard order.

    • The following properties hold globally:
      (basic_props:not_further_inst/2)Term1 is not further instantiated.
      (basic_props:not_further_inst/2)Term2 is not further instantiated.
      (basic_props:sideff/2)Term1@>Term2 is side-effect free.
      (basic_props:native/1)This predicate is understood natively by CiaoPP.
    General properties:

    True:Term1@>Term2

    • If the following properties hold at call time:
      (term_typing:ground/1)Term1 is currently ground (it contains no variables).
      (term_typing:ground/1)Term2 is currently ground (it contains no variables).
      then the following properties hold globally:
      (basic_props:eval/1)Term1@>Term2 is evaluable at compile-time.

    PREDICATE

    (Trust) Usage:Term1@>=Term2

    The term Term1 follows or is identical to the term Term2 in the standard order.

    • The following properties hold globally:
      (basic_props:not_further_inst/2)Term1 is not further instantiated.
      (basic_props:not_further_inst/2)Term2 is not further instantiated.
      (basic_props:sideff/2)Term1@>=Term2 is side-effect free.
      (basic_props:native/1)This predicate is understood natively by CiaoPP.
    General properties:

    True:Term1@>=Term2

    • If the following properties hold at call time:
      (term_typing:ground/1)Term1 is currently ground (it contains no variables).
      (term_typing:ground/1)Term2 is currently ground (it contains no variables).
      then the following properties hold globally:
      (basic_props:eval/1)Term1@>=Term2 is evaluable at compile-time.

    PREDICATE
    compare(Op,Term1,Term2)

    Op is the result of comparing the terms Term1 and Term2.

    (Trust) Usage:

    • Calls should, and exit will be compatible with:
      (basic_props:atm/1)Op is an atom.
    • The following properties should hold at call time:
      (basic_props:term/1)Term1 is any term.
      (basic_props:term/1)Term2 is any term.
    • The following properties hold upon exit:
      (basic_props:atm/1)Op is an atom.
      (basic_props:term/1)Term1 is any term.
      (basic_props:term/1)Term2 is any term.
      (term_compare:comparator/1)term_compare:comparator(Op)
      (basic_props:term/1)Term1 is any term.
      (basic_props:term/1)Term2 is any term.
    • The following properties hold globally:
      (basic_props:not_further_inst/2)Term1 is not further instantiated.
      (basic_props:not_further_inst/2)Term2 is not further instantiated.
      (basic_props:sideff/2)compare(Op,Term1,Term2) is side-effect free.
      (basic_props:native/1)This predicate is understood natively by CiaoPP.
    General properties:

    True:compare(Op,Term1,Term2)

    • If the following properties hold at call time:
      (term_typing:ground/1)Term1 is currently ground (it contains no variables).
      (term_typing:ground/1)Term2 is currently ground (it contains no variables).
      then the following properties hold globally:
      (basic_props:eval/1)compare(Op,Term1,Term2) is evaluable at compile-time.

    REGTYPE
    A regular type, defined as follows:
    comparator(=).
    comparator(>).
    comparator(<).
    

    Known bugs and planned improvements

    • Run-time checks have been reported not to work with this code. That means that either the assertions here, or the code that implements the run-time checks are erroneous.