Did you know ... | Search Documentation: |
Predicate arithmetic_function/1 |
:- use_module(library(arithmetic)). :- arithmetic_function(mid/2). mid(A,B,C) :- C is (A+B)/2.
After which we may call ?- A is mid(3,5).
, resulting in A = 4
.
The implementation uses goal_expansion/2 to rewrite an arithmetic expression using user functions into a conjunction of arithmetic evaluation and predicate calls. This implies that the expression must be known at compile time. Runtime evaluation is supported using arithmetic_expression_value/2.