In expressions like ?X is <expression> or ?X = <expression>, you can use some predefined constants and functions.
The operator '=' and 'is' are aliases.
Constants |
Examples |
PI,pi |
?- ?X = PI. // 3.1415.... |
E,e |
?- ?X = E. // Euler's constant 2.71... |
RANDOM |
?- ?X = RANDOM. // random number |
Functions |
Examples |
+ |
?- ?X is 6 + 3. // ?X = 9 |
- |
?- ?X is 6 - 3. |
* |
?- ?X is 6 * 3. |
/ |
?- ?X is 6 / 3. |
mod |
?- ?X is 7 mod 4. |
abs(_integer), abs(_double) |
?- ?X = abs(-2). |
max(_integer,_ integer), |
?- ?X = max(12, 34). |
min(_integer,_ integer) |
?- ?X = min(12, 34). |
round(_double) |
?- ?X = round(4.4). |
ceil(_double) |
?- ?X = ceil(4.4). |
floor(_double) |
?- ?X = floor(4.4). |
rint(_double) |
?- ?X = rint(3.5). |
tan(_double) |
?- ?X = tan(PI / 4). |
atan(_double) |
?- ?X = atan(1). |
sin(_double) |
?- ?X = sin(PI / 4). |
asin(_double) |
?- ?X = asin(1). |
cos(_double) |
?- ?X = cos(0). |
acos(_double) |
?- ?X = acos(1). |
exp(_double) |
?- ?X = exp(1). |
log(_double) |
?- ?X = log(E). // natural logarithm, ?X = 1.0 |
pow(_double,_double) |
?- ?X is pow(4.5, 2). |
sqrt(_double) |
?- ?X is sqrt(16). |
Of course you can build more complex expressions using brackets.
?- ?X = 3 * (4 + sin(pi * ?Y)), ?Y = 0.5. // ?X = 15.0, ?Y = 0.5
And you can use the expressions at places where a term is expected.
?- ?X[age -> 3 * (4 + sin(pi * 0.5))]. // same as ?- ?X[age -> 15.0].
The plus operator also work on strings
?- ?X = "a" + "b". // ?X = "ab"
Comparators |
Examples |
< |
?- 3 < 6. |
<= |
?- 3 <= 6. |
> |
?- 6 > 3. |
>= |
?- 6 >= 3. |
== |
?- 6 == 6.0. |
!= |
?- 3 != 6. |
These comparators do not need any variable or is-statement; the result is simply “true” or “false”.