Arithmetic functions, documentation and operator inconsistencies

The documentation of mathematical functions, and the declarations of operators is inconsistent and confusing.

mod is documented with +IntExpr1 mod +IntExpr2, and current_op(_,_,mod) is true.
gcd is documented with +IntExpr1 gcd +IntExpr2, but current_op(_,_,gcd) is false.
div is documented with div(+IntExpr1, +IntExpr2), yet current_op(_,_,div) is true.

It occurred to me that gcd not being an operator might have something to do with the fact that it’s not an ISO function. However

rdiv is not ISO, is documented with +IntExpr1 gcd +IntExpr2, and current_op(_,_,rdiv) is true.

There is no relation between arithmetic functions and Prolog operators. E.g., ISO sin(Angle) is also not an operator. There is current_arithmetic_function/1 to test whether something is evaluable by is/2, =:=/2, etc. Unfortunately that is not a standard predicate :frowning:

rdiv is from the days that SWI-Prolog did not have rational numbers as first class citizens. It should not have been an operator, but deleting it will probably make (too) many people unhappy because they still have legacy code from before the days that SWI-Prolog supports rational numbers properly.

1 Like

Agree. SWI-Prolog’s section on arithmetic does not talk about operators at all though. It always refers to them as functions (or arithmetic functions).

Still, the docs are misleading to the uninitiated. I am looking here for example.

Since it is using \infixfunction macro, it shows up on the website as:

+IntExpr1 gcd +IntExpr2

but when we type it like that its no work:

?- X is 3 gcd 5.
ERROR: Syntax error: Operator expected

If instead of

\infixfunction{gcd}{+IntExpr1}{+IntExpr2}

it would say

\function{gcd}{2}{+Expr1, +Expr2}

there would be no confusion.

I again apologize for not making PRs for docs lightly, it way easier to mess it up than to make it better.

2 Likes

Indeed. Fixed.

2 Likes