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

  • swipl
    • library
      • error.pl
      • debug.pl -- Print debug messages and test assertions
      • apply.pl -- Apply predicates on a list
      • lists.pl -- List Manipulation
      • broadcast.pl -- Event service
      • shlib.pl
      • option.pl
      • thread_pool.pl
      • gensym.pl
      • settings.pl -- Setting management
      • arithmetic.pl -- Extensible arithmetic
        • arithmetic_function/1
        • arithmetic_expression_value/2
      • main.pl -- Provide entry point for scripts
      • readutil.pl
      • operators.pl -- Manage operators
      • pairs.pl -- Operations on key-value lists
      • prolog_source.pl -- Examine Prolog source-files
      • record.pl
      • quasi_quotations.pl
      • pure_input.pl -- Pure Input from files and streams
      • solution_sequences.pl
      • ordsets.pl -- Ordered set manipulation
      • random.pl -- Random numbers
      • base64.pl -- Base64 encoding and decoding
      • aggregate.pl -- Aggregation operators on backtrackable predicates
      • yall.pl -- Lambda expressions
      • sandbox.pl
      • apply_macros.pl -- Goal expansion rules to avoid meta-calling
      • assoc.pl -- Binary associations
      • prolog_format.pl
      • predicate_options.pl
      • csv.pl -- Process CSV (Comma-Separated Values) data
      • pprint.pl -- Pretty Print Prolog terms
      • atom.pl -- Operations on atoms
      • modules.pl
      • occurs.pl
      • prolog_xref.pl
      • prolog_colour.pl
      • lazy_lists.pl
      • ugraphs.pl
      • url.pl -- Analysing and constructing URL
      • www_browser.pl -- Open a URL in the users browser
      • prolog_pack.pl
      • git.pl
      • rbtrees.pl
      • dif.pl -- The dif/2 constraint
      • charsio.pl -- I/O on Lists of Character Codes
      • prolog_stack.pl -- Examine the Prolog stack
      • edinburgh.pl -- Some traditional Edinburgh predicates
      • prolog_clause.pl
      • prolog_breakpoints.pl
      • wfs.pl
      • dialect.pl -- Support multiple Prolog dialects
      • prolog_code.pl -- Utilities for reasoning about code
      • sort.pl
      • iostream.pl -- Utilities to deal with streams
      • dicts.pl -- Dict utilities
      • varnumbers.pl
      • persistency.pl
      • date.pl -- Process dates and times
      • base32.pl
      • codesio.pl -- I/O on Lists of Character Codes
      • coinduction.pl
      • heaps.pl
      • statistics.pl
      • terms.pl
      • utf8.pl
      • when.pl
      • backcomp.pl -- Backward compatibility
      • strings.pl
      • system.pl -- System utilities
      • quintus.pl -- Quintus compatibility
      • qsave.pl
      • zip.pl
      • check.pl -- Consistency checking
      • explain.pl
      • writef.pl
      • optparse.pl
      • prolog_wrap.pl
      • macros.pl
      • threadutil.pl -- Interactive thread utilities
      • make.pl
      • prolog_profile.pl
      • files.pl
      • prolog_autoload.pl -- Autoload all dependencies
      • help.pl -- Text based manual
      • ctypes.pl -- Character code classification
      • ansi_term.pl
      • nb_set.pl
      • listing.pl
      • fastrw.pl
      • prolog_trace.pl
      • edit.pl -- Editor interface
      • prolog_jiti.pl
      • prolog_metainference.pl
      • portray_text.pl
      • prolog_history.pl
      • thread.pl
      • shell.pl -- Elementary shell commands
      • intercept.pl -- Intercept and signal interface
      • tables.pl
      • rwlocks.pl
      • prolog_versions.pl
      • prolog_coverage.pl -- Coverage analysis tool
      • increval.pl
      • prolog_debug.pl
      • streams.pl -- Manage Prolog streams
      • oset.pl
      • exceptions.pl
      • prolog_codewalk.pl
      • hashtable.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.