Arithmetic comparison

These predicates cause two expressions to be evaluated and their values to be compared.

Each arithmetic comparison predicate corresponds to an operation which depends on the types of the values which are obtained by evaluating the argument(s) of the predicate.

1. =:=/2 (arithmetic equal), =\=/2 (arithmetic not equal), </2 (arithmetic less than), =< (arithmetic less than or equal), >/2 (arithmetic greater than), >=/2 (arithmetic greater than or equal)

The following requirements are true for all P where P = {=:=, =\=, <, =<, >, >=}.

'P'(E1, E2)is true iff evaluating E1 and E2 as expressions and performing the corresponding arithmetic operation on their values is true.

Templates and modes for the predicate are as follows:

'=:='(@evaluable, @evaluable)
'=\\='(@evaluable, @evaluable)
'<'(@evaluable, @evaluable)
'=<'(@evaluable, @evaluable)
'>'(@evaluable, @evaluable)
'>='(@evaluable, @evaluable)

1.1 Example tests

Let's start with some simple tests verifying success of failure of single goals.

jTrolog.engine.SimpleGoalFixture
goalsuccess()exception()
'=:='(0, 1). false no exception
'=\\='(0, 1). true no exception
'<'(0, 1). true no exception
'>'(0, 1). false no exception
'>='(0, 1). false no exception
'=<'(0, 1). true no exception
'=:='(1.0, 1). true no exception
'=\\='(1.0, 1). false no exception
'<'(1.0, 1). false no exception
'>'(1.0, 1). false no exception
'>='(1.0, 1). true no exception
'=<'(1.0, 1). true no exception
'=:='(3 * 2, 7 - 1). true no exception
'=\\='(3 * 2, 7 - 1). false no exception
'<'(3 * 2, 7 - 1). false no exception
'>'(3 * 2, 7 - 1). false no exception
'>='(3 * 2, 7 - 1). true no exception
'=<'(3 * 2, 7 - 1). true no exception
'=:='(X, 5). false instantiation_error
=\=(X, 5). false instantiation_error
'<'(X, 5). false instantiation_error
'>'(X, 5). false instantiation_error
'>='(X, 5). false instantiation_error
'=<'(X, 5). false instantiation_error

The remaining tests cover the cases when an error or exception is thrown by the engine while solving a query.

First of all, let's start an appropriate fixture containing an engine.

fit.ActionFixture
start jTrolog.engine.EngineFixture

Then, ask the engine to solve a query, and check variable bindings.

jTrolog.engine.PrologActionFixture
enter query '=:='(X, 5).
check hasSolution false
check exception instantiation_error
enter query '=\\='(X, 5).
check hasSolution false
check exception instantiation_error
enter query '<'(X, 5).
check hasSolution false
check exception instantiation_error
enter query '>'(X, 5).
check hasSolution false
check exception instantiation_error
enter query '>='(X, 5).
check hasSolution false
check exception instantiation_error
enter query '=<'(X, 5).
check hasSolution false
check exception instantiation_error

The results of the tests for Arithmetic comparison are as follows:

fit.Summary