/usr/local/lib/swipl/library/arithmetic.pl
All Application Manual Name SummaryHelp

  • swipl
    • library
      • error.pl
      • debug.pl
      • apply.pl
      • lists.pl
      • broadcast.pl
      • shlib.pl
      • option.pl
      • thread_pool.pl
      • gensym.pl
      • settings.pl
      • arithmetic.pl -- Extensible arithmetic
        • arithmetic_function/1
        • arithmetic_expression_value/2
      • main.pl -- Provide entry point for scripts
      • readutil.pl
      • operators.pl
      • pairs.pl
      • prolog_source.pl
      • record.pl
      • quasi_quotations.pl
      • pure_input.pl
      • solution_sequences.pl
      • ordsets.pl
      • random.pl
      • base64.pl
      • aggregate.pl
      • yall.pl
      • sandbox.pl
      • apply_macros.pl -- Goal expansion rules to avoid meta-calling
      • assoc.pl
      • prolog_format.pl
      • predicate_options.pl
      • csv.pl
      • pprint.pl
      • atom.pl
      • modules.pl
      • occurs.pl
      • prolog_xref.pl
      • prolog_colour.pl
      • lazy_lists.pl
      • ugraphs.pl
      • url.pl
      • www_browser.pl
      • prolog_pack.pl
      • git.pl
      • utf8.pl
      • dialect.pl
      • system.pl -- System utilities
      • terms.pl
      • date.pl
      • persistency.pl
      • iostream.pl -- Utilities to deal with streams
      • prolog_stack.pl
      • edinburgh.pl
      • prolog_clause.pl
      • prolog_breakpoints.pl
      • wfs.pl
      • prolog_code.pl
      • sort.pl
      • dicts.pl
      • dif.pl
      • varnumbers.pl
      • pio.pl
      • prolog_jiti.pl
      • ansi_term.pl
      • listing.pl
      • backcomp.pl
      • base32.pl
      • charsio.pl
      • codesio.pl
      • coinduction.pl
      • heaps.pl
      • rbtrees.pl
      • statistics.pl
      • when.pl
      • tables.pl
      • ctypes.pl -- Character code classification
      • prolog_wrap.pl
      • thread.pl
      • prolog_coverage.pl -- Coverage analysis tool
      • hashtable.pl
      • explain.pl
      • portray_text.pl
      • quintus.pl
      • threadutil.pl -- Interactive thread utilities
      • prolog_trace.pl
      • writef.pl
      • prolog_versions.pl -- Demand specific (Prolog) versions
      • optparse.pl
      • make.pl
      • prolog_codewalk.pl
      • zip.pl
      • strings.pl
      • nb_set.pl
      • qsave.pl
      • prolog_debug.pl -- User level debugging tools
      • increval.pl
      • intercept.pl
 arithmetic_function(:NameArity) is det
Declare a predicate as an arithmetic function. The function is visible in the module in which it is defined as well as modules that import the implementation predicate or inherit from this module. For example:
:- 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.

deprecated
- This function provides a partial work around for pure Prolog user-defined arithmetic functions that has been dropped in SWI-Prolog 5.11.23. Notably, it only deals with expression know at compile time.