# Arithmetic functions, documentation and operator inconsistencies

**URL:** <https://swi-prolog.discourse.group/t/arithmetic-functions-documentation-and-operator-inconsistencies/8619>\
**Category:** General\
**Created:** [November 21, 2024, 4:30pm UTC](https://swi-prolog.discourse.group/t/arithmetic-functions-documentation-and-operator-inconsistencies/8619 "2024-11-21T16:30:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![z5h](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/z5h/32/5445_2.png) [@z5h](https://swi-prolog.discourse.group/u/z5h)\
**Post date:** [November 21, 2024, 4:30pm UTC](https://swi-prolog.discourse.group/t/arithmetic-functions-documentation-and-operator-inconsistencies/8619/1 "2024-11-21T16:30:47Z")

</div>

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`.

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [November 21, 2024, 4:56pm UTC](https://swi-prolog.discourse.group/t/arithmetic-functions-documentation-and-operator-inconsistencies/8619/2 "2024-11-21T16:56:38Z")

</div>

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 ☹

`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.

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [November 22, 2024, 9:35am UTC](https://swi-prolog.discourse.group/t/arithmetic-functions-documentation-and-operator-inconsistencies/8619/4 "2024-11-22T09:35:47Z")

</div>

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_).

---

<div class="post-metadata">

**Author:** ![Boris](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/boris/32/7486_2.png) [@Boris](https://swi-prolog.discourse.group/u/Boris)\
**Post date:** [November 22, 2024, 10:06am UTC](https://swi-prolog.discourse.group/t/arithmetic-functions-documentation-and-operator-inconsistencies/8619/5 "2024-11-22T10:06:23Z")

</div>

Still, the docs are misleading to the uninitiated. I am looking [here](https://github.com/SWI-Prolog/swipl-devel/blob/099f021a43c1752954a28cde22a3f373135c7c9e/man/builtin.doc#L8659C6-L8659C19) 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:

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

```

If instead of

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

```

it would say

```prolog
\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.

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [November 22, 2024, 10:16am UTC](https://swi-prolog.discourse.group/t/arithmetic-functions-documentation-and-operator-inconsistencies/8619/6 "2024-11-22T10:16:16Z")

</div>

> [@Boris](#):
>
> it would say
> 
> ```prolog
> \function{gcd}{2}{+Expr1, +Expr2}
> 
> ```
> 
> there would be no confusion.

Indeed. Fixed.
