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

  • swipl
    • library
      • error.pl
      • debug.pl
      • apply.pl -- Apply predicates on a list
      • lists.pl
      • broadcast.pl -- Event service
      • shlib.pl -- Utility library for loading foreign objects (DLLs, shared objects)
      • option.pl -- Option list processing
      • thread_pool.pl -- Resource bounded thread management
      • gensym.pl
      • settings.pl
      • arithmetic.pl -- Extensible arithmetic
        • arithmetic_function/1
        • arithmetic_expression_value/2
      • main.pl
      • readutil.pl -- Read utilities
      • operators.pl
      • pairs.pl -- Operations on key-value lists
      • prolog_source.pl -- Examine Prolog source-files
      • record.pl -- Access compound arguments by name
      • quasi_quotations.pl
      • pure_input.pl
      • solution_sequences.pl -- Modify solution sequences
      • ordsets.pl -- Ordered set manipulation
      • random.pl -- Random numbers
      • base64.pl -- Base64 encoding and decoding
      • aggregate.pl -- Aggregation operators on backtrackable predicates
      • yall.pl
      • sandbox.pl
      • apply_macros.pl -- Goal expansion rules to avoid meta-calling
      • assoc.pl
      • prolog_format.pl -- Analyse format specifications
      • predicate_options.pl
      • csv.pl
      • pprint.pl
      • 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 -- Run GIT commands
      • rbtrees.pl -- Red black trees
      • dif.pl -- The dif/2 constraint
      • charsio.pl
      • prolog_stack.pl
      • edinburgh.pl -- Some traditional Edinburgh predicates
      • prolog_clause.pl
      • prolog_breakpoints.pl -- Manage Prolog break-points
      • wfs.pl -- Well Founded Semantics interface
      • dialect.pl -- Support multiple Prolog dialects
      • prolog_code.pl
      • sort.pl
      • iostream.pl -- Utilities to deal with streams
      • dicts.pl -- Dict utilities
      • varnumbers.pl
      • base32.pl -- Base32 encoding and decoding
      • codesio.pl -- I/O on Lists of Character Codes
      • coinduction.pl
      • date.pl
      • heaps.pl -- heaps/priority queues
      • statistics.pl
      • terms.pl
      • utf8.pl -- UTF-8 encoding/decoding on lists of character codes.
      • when.pl
      • backcomp.pl -- Backward compatibility
      • nb_set.pl -- Non-backtrackable sets
      • check.pl
      • edit.pl -- Editor interface
      • thread.pl -- High level thread primitives
      • macros.pl -- Macro expansion
      • persistency.pl
      • prolog_profile.pl -- Execution profiler
      • optparse.pl
      • make.pl
      • listing.pl -- List programs and pretty print clauses
      • threadutil.pl -- Interactive thread utilities
      • zip.pl
      • prolog_versions.pl
      • strings.pl -- String utilities
      • tables.pl
      • prolog_debug.pl
      • ansi_term.pl -- Print decorated text to ANSI consoles
      • shell.pl
      • quintus.pl
      • prolog_jiti.pl -- Just In Time Indexing (JITI) utilities
      • increval.pl
      • prolog_history.pl -- Per-directory persistent commandline history
      • prolog_config.pl
      • writef.pl -- Old-style formatted write
      • help.pl
      • prolog_codewalk.pl
      • prolog_coverage.pl -- Coverage analysis tool
      • prolog_trace.pl -- Print access to predicates
      • hashtable.pl
      • system.pl
      • intercept.pl -- Intercept and signal interface
      • exceptions.pl -- Exception classification
      • explain.pl -- Describe Prolog Terms
      • prolog_metainference.pl
      • prolog_wrap.pl
      • prolog_autoload.pl
      • files.pl
      • ctypes.pl -- Character code classification
      • streams.pl
      • qsave.pl
      • fastrw.pl
      • portray_text.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.