These subclauses define the format and the definitions of other evaluable functors.
Templates and modes represent a specification for the type of the values when the arguments of the evaluable functor are evaluated as an expression, and the type of its value. A specific notation is employed for the structure and type of the arguments and value:
(**)/2
(power)'**'(X, Y)
evaluates the expressions X and Y with values VX and VY, and has the value of VX raised to the power of VY. If VX and VY are both zero, the value is 1.0.
Templates and modes for the predicate are as follows:
'**'(int-exp, int-exp) = float '**'(float-exp, int-exp) = float '**'(int-exp, float-exp) = float '**'(float-exp, float-exp) = float
Note that **
is an infix predefined operator.
First of all, let's start an appropriate fixture.
fit.ActionFixture | |
start | alice.tuprolog.EvaluationFixture |
Then, ask the engine to evaluate an expression and verify the result.
alice.tuprolog.PrologActionFixture | ||
enter | evaluable | '**'(5, 3). |
check | value | 125.0 |
enter | evaluable | '**'(-5.0, 3). |
check | value | -125.0 |
enter | evaluable | '**'(5, -1). |
check | value | 0.2 |
enter | evaluable | '**'(77, N). |
check | exception | instantiation_error |
enter | evaluable | '**'(foo, 2). |
check | exception | type_error(number, foo) |
enter | evaluable | '**'(5, 3.0). |
check | value | 125.0 |
enter | evaluable | '**'(0.0, 0). |
check | value | 1.0 |
sin/1
sin(X)
evaluates the expression X with value VX and has the value of the sine of VX (measured in radians).
Templates and modes for the predicate are as follows:
sin(float-exp) = float sin(int-exp) = float
First of all, let's start an appropriate fixture.
fit.ActionFixture | |
start | alice.tuprolog.EvaluationFixture |
Then, ask the engine to evaluate an expression and verify the result.
alice.tuprolog.PrologActionFixture | ||
enter | evaluable | sin(0.0). |
check | value | 0.0 |
enter | evaluable | sin(N). |
check | exception | instantiation_error |
enter | evaluable | sin(0). |
check | value | 0.0 |
enter | evaluable | sin(foo). |
check | exception | type_error(number, foo) |
Now we run some tests also verifying the unification for some of the variables in goals.
First of all, let's start an appropriate fixture containing an engine.
fit.ActionFixture | |
start | alice.tuprolog.EngineFixture |
Then, ask the engine to solve a query, and check variable bindings.
fit.ActionFixture | ||
enter | query | PI is atan(1.0) * 4, X is sin(PI / 2.0). |
check | hasSolution | true |
enter | variable | X |
check | binding | 1.0 |
enter | variable | PI |
check | binding | 3.141592653589793 |
cos/1
cos(X)
evaluates the expression X with value VX and has the value of the cosine of VX (measured in radians).
Templates and modes for the predicate are as follows:
cos(float-exp) = float cos(int-exp) = float
First of all, let's start an appropriate fixture.
fit.ActionFixture | |
start | alice.tuprolog.EvaluationFixture |
Then, ask the engine to evaluate an expression and verify the result.
alice.tuprolog.PrologActionFixture | ||
enter | evaluable | cos(0.0). |
check | value | 1.0 |
enter | evaluable | cos(N). |
check | exception | instantiation_error |
enter | evaluable | cos(0). |
check | value | 1.0 |
enter | evaluable | cos(foo). |
check | exception | type_error(number, foo) |
Now we run some tests also verifying the unification for some of the variables in goals.
First of all, let's start an appropriate fixture containing an engine.
fit.ActionFixture | |
start | alice.tuprolog.EngineFixture |
Then, ask the engine to solve a query, and check variable bindings.
fit.ActionFixture | ||
enter | query | PI is atan(1.0) * 4, X is cos(PI / 2.0). |
check | hasSolution | true |
enter | variable | X |
check | binding | 6.123233995736766e-17 |
enter | variable | PI |
check | binding | 3.141592653589793 |
atan/1
atan(X)
evaluates the expression X with value VX and has the value of the principal value of the arc tangent of VX, that is the value R satisfies π/2 ≤ R ≤ π/2.
Templates and modes for the predicate are as follows:
atan(float-exp) = float atan(int-exp) = float
First of all, let's start an appropriate fixture.
fit.ActionFixture | |
start | alice.tuprolog.EvaluationFixture |
Then, ask the engine to evaluate an expression and verify the result.
alice.tuprolog.PrologActionFixture | ||
enter | evaluable | atan(0.0). |
check | value | 0.0 |
enter | evaluable | atan(N). |
check | exception | instantiation_error |
enter | evaluable | atan(0). |
check | value | 0.0 |
enter | evaluable | atan(foo). |
check | exception | type_error(number, foo) |
Now we run some tests also verifying the unification for some of the variables in goals.
First of all, let's start an appropriate fixture containing an engine.
fit.ActionFixture | |
start | alice.tuprolog.EngineFixture |
Then, ask the engine to solve a query, and check variable bindings.
fit.ActionFixture | ||
enter | query | PI is atan(1.0) * 4. |
check | hasSolution | true |
enter | variable | PI |
check | binding | 3.141592653589793 |
exp/1
exp(X)
evaluates the expression X with value VX and has the value of the exponential function of VX.
Templates and modes for the predicate are as follows:
exp(float-exp) = float exp(int-exp) = float
First of all, let's start an appropriate fixture.
fit.ActionFixture | |
start | alice.tuprolog.EvaluationFixture |
Then, ask the engine to evaluate an expression and verify the result.
alice.tuprolog.PrologActionFixture | ||
enter | evaluable | exp(0.0). |
check | value | 1.0 |
enter | evaluable | exp(1.0). |
check | value | 2.7182818284590455 |
enter | evaluable | exp(N). |
check | exception | instantiation_error |
enter | evaluable | exp(0). |
check | value | 1.0 |
enter | evaluable | exp(foo). |
check | exception | type_error(number, foo) |
log/1
log(X)
evaluates the expression X with value VX and has the value of the natural logarithm of VX.
Templates and modes for the predicate are as follows:
log(float-exp) = float log(int-exp) = float
First of all, let's start an appropriate fixture.
fit.ActionFixture | |
start | alice.tuprolog.EvaluationFixture |
Then, ask the engine to evaluate an expression and verify the result.
alice.tuprolog.PrologActionFixture | ||
enter | evaluable | log(1.0). |
check | value | 0.0 |
enter | evaluable | log(2.7182818284590455). |
check | value | 1.0 |
enter | evaluable | log(N). |
check | exception | instantiation_error |
enter | evaluable | log(0) |
check | exception | evaluation_error(undefined) |
enter | evaluable | log(foo). |
check | exception | type_error(number, foo) |
enter | evaluable | log(0.0) |
check | exception | evaluation_error(undefined) |
sqrt/1
sqrt(X)
evaluates the expression X with value VX and has the value of the square root of VX.
Templates and modes for the predicate are as follows:
sqrt(float-exp) = float sqrt(int-exp) = float
First of all, let's start an appropriate fixture.
fit.ActionFixture | |
start | alice.tuprolog.EvaluationFixture |
Then, ask the engine to evaluate an expression and verify the result.
alice.tuprolog.PrologActionFixture | ||
enter | evaluable | sqrt(0.0). |
check | value | 0.0 |
enter | evaluable | sqrt(1). |
check | value | 1.0 |
enter | evaluable | sqrt(1.21). |
check | value | 1.1 |
enter | evaluable | sqrt(N). |
check | exception | instantiation_error |
enter | evaluable | sqrt(-1.0) |
check | exception | evaluation_error(undefined) |
enter | evaluable | sqrt(foo). |
check | exception | type_error(number, foo) |
Run the tests!
The results of the tests for Other arithmetic functors are as follows:
fit.Summary |