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

  • swipl
    • library
      • error.pl
      • debug.pl -- Print debug messages and test assertions
      • apply.pl
      • 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 -- 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 -- Access compound arguments by name
      • quasi_quotations.pl -- Define Quasi Quotation syntax
      • sandbox.pl -- Sandboxed Prolog code
      • apply_macros.pl -- Goal expansion rules to avoid meta-calling
      • yall.pl -- Lambda expressions
      • assoc.pl -- Binary associations
      • prolog_format.pl -- Analyse format specifications
      • pure_input.pl -- Pure Input from files and streams
      • solution_sequences.pl -- Modify solution sequences
      • ordsets.pl
      • random.pl -- Random numbers
      • base64.pl -- Base64 encoding and decoding
      • aggregate.pl
      • predicate_options.pl -- Access and analyse predicate options
      • csv.pl -- Process CSV (Comma-Separated Values) data
      • pprint.pl -- Pretty Print Prolog terms
      • atom.pl
      • 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 -- A package manager for Prolog
      • git.pl -- Run GIT commands
      • utf8.pl -- UTF-8 encoding/decoding on lists of character codes.
      • quintus.pl -- Quintus compatibility
      • prolog_versions.pl
      • prolog_wrap.pl -- Wrapping predicates
      • dialect.pl -- Support multiple Prolog dialects
      • date.pl -- Process dates and times
      • persistency.pl -- Provide persistent dynamic predicates
      • iostream.pl -- Utilities to deal with streams
      • prolog_code.pl -- Utilities for reasoning about code
      • strings.pl
      • dif.pl -- The dif/2 constraint
      • edinburgh.pl -- Some traditional Edinburgh predicates
      • terms.pl -- Term manipulation
      • ansi_term.pl -- Print decorated text to ANSI consoles
      • threadutil.pl -- Interactive thread utilities
      • prolog_stack.pl -- Examine the Prolog stack
      • prolog_clause.pl
      • prolog_breakpoints.pl
      • wfs.pl -- Well Founded Semantics interface
      • sort.pl
      • dicts.pl
      • varnumbers.pl -- Utilities for numbered terms
      • rbtrees.pl -- Red black trees
      • backcomp.pl -- Backward compatibility
      • charsio.pl -- I/O on Lists of Character Codes
      • base32.pl -- Base32 encoding and decoding
      • codesio.pl -- I/O on Lists of Character Codes
      • coinduction.pl
      • statistics.pl -- Get information about resource usage
      • heaps.pl -- heaps/priority queues
      • when.pl -- Conditional coroutining
      • ctypes.pl -- Character code classification
      • thread.pl
      • prolog_jiti.pl
      • tables.pl
      • prolog_trace.pl -- Print access to predicates
      • check.pl
      • listing.pl -- List programs and pretty print clauses
      • make.pl
      • help.pl -- Text based manual
      • increval.pl -- Incremental dynamic predicate modification
      • prolog_debug.pl -- User level debugging tools
      • optparse.pl
      • qsave.pl -- Save current program as a state or executable
      • prolog_codewalk.pl
      • nb_set.pl
      • zip.pl -- Access resource ZIP archives
      • prolog_deps.pl
      • prolog_autoload.pl
      • prolog_metainference.pl -- Infer meta-predicate properties
      • prolog_coverage.pl -- Coverage analysis tool
      • readln.pl -- Read line as list of tokens
      • prolog_profile.pl -- Execution profiler
      • macros.pl
      • edit.pl
      • hashtable.pl -- Hash tables
      • pio.pl
      • prolog_history.pl
      • qpforeign.pl -- Quintus compatible foreign loader
      • shell.pl -- Elementary shell commands
      • oset.pl
      • portray_text.pl
      • intercept.pl -- Intercept and signal interface
      • fastrw.pl
      • check_installation.pl -- Check installation issues and features
      • vm.pl
      • writef.pl
      • nb_rbtrees.pl
      • system.pl
      • exceptions.pl -- Exception classification
      • prolog_config.pl
      • streams.pl -- Manage Prolog streams
      • files.pl
      • tty.pl -- Terminal operations
      • explain.pl -- Describe Prolog Terms
      • rwlocks.pl
      • tabling.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.