/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 -- List Manipulation
      • broadcast.pl
      • shlib.pl
      • option.pl -- Option list processing
      • thread_pool.pl
      • gensym.pl -- Generate unique symbols
      • settings.pl -- Setting management
      • arithmetic.pl -- Extensible arithmetic
        • arithmetic_function/1
        • arithmetic_expression_value/2
      • main.pl -- Provide entry point for scripts
      • readutil.pl -- Read utilities
      • 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 -- Modify solution sequences
      • ordsets.pl -- Ordered set manipulation
      • random.pl -- Random numbers
      • base64.pl -- Base64 encoding and decoding
      • aggregate.pl
      • yall.pl -- Lambda expressions
      • sandbox.pl -- Sandboxed Prolog code
      • apply_macros.pl -- Goal expansion rules to avoid meta-calling
      • assoc.pl -- Binary associations
      • prolog_format.pl -- Analyse format specifications
      • predicate_options.pl
      • csv.pl -- Process CSV (Comma-Separated Values) data
      • pprint.pl -- Pretty Print Prolog terms
      • atom.pl -- Operations on atoms
      • modules.pl -- Module utility predicates
      • occurs.pl -- Finding and counting sub-terms
      • prolog_xref.pl -- Prolog cross-referencer data collection
      • prolog_colour.pl -- Prolog syntax colouring support.
      • lazy_lists.pl -- Lazy list handling
      • ugraphs.pl -- Graph manipulation library
      • 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
      • dif.pl -- The dif/2 constraint
      • charsio.pl -- I/O on Lists of Character Codes
      • prolog_stack.pl
      • 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 -- Utilities for numbered terms
      • optparse.pl -- command line parsing
      • prolog_codewalk.pl -- Prolog code walker
      • prolog_metainference.pl
      • base32.pl -- Base32 encoding and decoding
      • codesio.pl -- I/O on Lists of Character Codes
      • coinduction.pl -- Co-Logic Programming
      • date.pl -- Process dates and times
      • heaps.pl -- heaps/priority queues
      • statistics.pl -- Get information about resource usage
      • terms.pl -- Term manipulation
      • utf8.pl -- UTF-8 encoding/decoding on lists of character codes.
      • when.pl -- Conditional coroutining
      • backcomp.pl -- Backward compatibility
      • listing.pl
      • fastrw.pl -- Fast reading and writing of terms
      • explain.pl
      • prolog_wrap.pl
      • prolog_debug.pl -- User level debugging tools
      • threadutil.pl -- Interactive thread utilities
      • quintus.pl -- Quintus compatibility
      • edit.pl
      • make.pl -- Reload modified source files
      • strings.pl -- String utilities
      • ctypes.pl -- Character code classification
      • prolog_autoload.pl
      • check.pl -- Consistency checking
      • portray_text.pl
      • help.pl
      • ansi_term.pl -- Print decorated text to ANSI consoles
      • prolog_versions.pl -- Demand specific (Prolog) versions
      • thread.pl -- High level thread primitives
      • writef.pl
      • hashtable.pl
      • prolog_profile.pl -- Execution profiler
      • zip.pl -- Access resource ZIP archives
      • prolog_trace.pl
      • nb_set.pl -- Non-backtrackable sets
      • rwlocks.pl
      • shell.pl -- Elementary shell commands
      • tables.pl
      • system.pl -- System utilities
      • macros.pl
      • oset.pl
      • files.pl
      • increval.pl -- Incremental dynamic predicate modification
      • exceptions.pl -- Exception classification
      • prolog_jiti.pl
      • qsave.pl
      • prolog_coverage.pl -- Coverage analysis tool
      • intercept.pl -- Intercept and signal interface
      • persistency.pl -- Provide persistent dynamic predicates
      • prolog_history.pl -- Per-directory persistent commandline history
      • prolog_config.pl -- Provide configuration information
      • streams.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.