SWI-Prolog 5.11.18 Reference Manual: Section 4.26

## 4.26 Adding Arithmetic Functions

Prolog predicates can be given the role of arithmetic function. The last argument is used to return the result, the arguments before the last are the inputs. Arithmetic functions are added using the predicate arithmetic_function/1, which takes the head as its argument. Arithmetic functions are module sensitive, that is they are only visible from the module in which the function is defined and declared. Global arithmetic functions should be defined and registered from module `user`. Global definitions can be overruled locally in modules. The built-in functions described above can be redefined as well.

arithmetic_function(:Head)
  Register a Prolog predicate as an arithmetic function (see is/2, >/2, etc.). The Prolog predicate should have one more argument than specified by Head, which it either a term Name/Arity, an atom or a complex term. This last argument is an unbound variable at call time and should be instantiated to an integer or floating point number. The other arguments are the parameters. This predicate is module sensitive and will declare the arithmetic function only for the context module, unless declared from module `user`. Example:

      1 ?- [user].
      :- arithmetic_function(mean/2).

      mean(A, B, C) :-
              C is (A+B)/2.
      user compiled, 0.07 sec, 440 bytes.

      Yes
      2 ?- A is mean(4, 5).

      A = 4.500000

current_arithmetic_function(:Head)
  True if Head is a function that is visible from the current module. Built-in functions are visible from all modules, while user-defined functions (see arithmetic_function/1) obey the module visibility rules. E.g.,

      ?- current_arithmetic_function(sin(_)).
      true.