Did you know ... | Search Documentation: |

library(clpqr): Constraint Logic Programming over Rationals and Reals |

- Home
- DOWNLOAD
- DOCUMENTATION
- TUTORIALS
- Beginner▶
- Advanced▶
- Web applications▶
- Semantic web▶
- Graphics▶
- Machine learning▶
- External collections▶
- For packagers▶

- COMMUNITY
- USERS
- WIKI

- Documentation
- Reference manual
- The SWI-Prolog library
- library(aggregate): Aggregation operators on backtrackable predicates
- library(ansi_term): Print decorated text to ANSI consoles
- library(apply): Apply predicates on a list
- library(assoc): Association lists
- library(broadcast): Broadcast and receive event notifications
- library(charsio): I/O on Lists of Character Codes
- library(check): Consistency checking
- library(clpb): CLP(B): Constraint Logic Programming over Boolean Variables
- library(clpfd): CLP(FD): Constraint Logic Programming over Finite Domains
- library(clpqr): Constraint Logic Programming over Rationals and Reals
- library(csv): Process CSV (Comma-Separated Values) data
- library(dcg/basics): Various general DCG utilities
- library(dcg/high_order): High order grammar operations
- library(debug): Print debug messages and test assertions
- library(dicts): Dict utilities
- library(error): Error generating support
- library(gensym): Generate unique identifiers
- library(iostream): Utilities to deal with streams
- library(lists): List Manipulation
- library(main): Provide entry point for scripts
- library(nb_set): Non-backtrackable set
- library(www_browser): Activating your Web-browser
- library(occurs): Finding and counting sub-terms
- library(option): Option list processing
- library(optparse): command line parsing
- library(ordsets): Ordered set manipulation
- library(pairs): Operations on key-value lists
- library(persistency): Provide persistent dynamic predicates
- library(pio): Pure I/O
- library(predicate_options): Declare option-processing of predicates
- library(prolog_pack): A package manager for Prolog
- library(prolog_xref): Cross-reference data collection library
- library(quasi_quotations): Define Quasi Quotation syntax
- library(random): Random numbers
- library(readutil): Reading lines, streams and files
- library(record): Access named fields in a term
- library(registry): Manipulating the Windows registry
- library(settings): Setting management
- library(simplex): Solve linear programming problems
- library(solution_sequences): Modify solution sequences
- library(thread_pool): Resource bounded thread management
- library(ugraphs): Unweighted Graphs
- library(url): Analysing and constructing URL
- library(varnumbers): Utilities for numbered terms
- library(yall): Lambda expressions

- The SWI-Prolog library
- Packages

- Reference manual

Author:Christian Holzbaur, ported to SWI-Prolog byLeslie De Koninck, K.U. Leuven

This CLP(Q,R) system is a port of the CLP(Q,R) system of Sicstus
Prolog by Christian Holzbaur: Holzbaur C.: OFAI clp(q,r) Manual, Edition
1.3.3, Austrian Research Institute for Artificial Intelligence, Vienna,
TR-95-09, 1995.^{192http://www.ai.univie.ac.at/cgi-bin/tr-online?number+95-09}
This manual is roughly based on the manual of the above mentioned
CLP(Q,R) implementation.

The CLP(Q,R) system consists of two components: the CLP(Q) library for handling constraints over the rational numbers and the CLP(R) library for handling constraints over the real numbers (using floating point numbers as representation). Both libraries offer the same predicates (with exception of bb_inf/4 in CLP(Q) and bb_inf/5 in CLP(R)). It is allowed to use both libraries in one program, but using both CLP(Q) and CLP(R) constraints on the same variable will result in an exception.

Please note that the `library(clpqr)`

library is *not*
an
*autoload* library and therefore this library must be loaded
explicitly before using it:

:- use_module(library(clpq)).

or

:- use_module(library(clpr)).

**{}**(`+Constraints`)- Adds the constraints given by
`Constraints`to the constraint store. **entailed**(`+Constraint`)- Succeeds if
`Constraint`is necessarily true within the current constraint store. This means that adding the negation of the constraint to the store results in failure. **inf**(`+Expression, -Inf`)- Computes the infimum of
`Expression`within the current state of the constraint store and returns that infimum in`Inf`. This predicate does not change the constraint store. **sup**(`+Expression, -Sup`)- Computes the supremum of
`Expression`within the current state of the constraint store and returns that supremum in`Sup`. This predicate does not change the constraint store. **minimize**(`+Expression`)- Minimizes
`Expression`within the current constraint store. This is the same as computing the infimum and equating the expression to that infimum. **maximize**(`+Expression`)- Maximizes
`Expression`within the current constraint store. This is the same as computing the supremum and equating the expression to that supremum. **bb_inf**(`+Ints, +Expression, -Inf, -Vertex, +Eps`)- This predicate is offered in CLP(R) only. It computes the infimum of
`Expression`within the current constraint store, with the additional constraint that in that infimum, all variables in`Ints`have integral values.`Vertex`will contain the values of`Ints`in the infimum.`Eps`denotes how much a value may differ from an integer to be considered an integer. E.g. when`Eps`= 0.001, then X = 4.999 will be considered as an integer (5 in this case).`Eps`should be between 0 and 0.5. **bb_inf**(`+Ints, +Expression, -Inf, -Vertex`)- This predicate is offered in CLP(Q) only. It behaves the same as bb_inf/5 but does not use an error margin.
**bb_inf**(`+Ints, +Expression, -Inf`)- The same as bb_inf/5 or bb_inf/4 but without returning the values of the integers. In CLP(R), an error margin of 0.001 is used.
**dump**(`+Target, +Newvars, -CodedAnswer`)- Returns the constraints on
`Target`in the list`CodedAnswer`where all variables of`Target`have been replaced by`NewVars`. This operation does not change the constraint store. E.g. indump([X,Y,Z],[x,y,z],Cons)

`Cons`

will contain the constraints on X, Y and Z, where these variables have been replaced by atoms x, y and z.

<Constraints> | ::= | <Constraint> | single constraint |

| | <Constraint> , <Constraints> | conjunction | |

| | <Constraint> ; <Constraints> | disjunction | |

< | ::= | <Expression> `<` <Expression> | less than |

| | <Expression> `>` <Expression> | greater than | |

| | <Expression> `=<` <Expression> | less or equal | |

| | `<=` (<Expression>, <Expression>) | less or equal | |

| | <Expression> `>=` <Expression> | greater or equal | |

| | <Expression> `=\=` <Expression> | not equal | |

| | <Expression> =:= <Expression> | equal | |

| | <Expression> = <Expression> | equal | |

< | ::= | <Variable> | Prolog variable |

| | <Number> | Prolog number | |

| | +<Expression> | unary plus | |

| | -<Expression> | unary minus | |

| | <Expression> + <Expression> | addition | |

| | <Expression> - <Expression> | substraction | |

| | <Expression> * <Expression> | multiplication | |

| | <Expression> / <Expression> | division | |

| | abs(<Expression>) | absolute value | |

| | sin(<Expression>) | sine | |

| | cos(<Expression>) | cosine | |

| | tan(<Expression>) | tangent | |

| | exp(<Expression>) | exponent | |

| | pow(<Expression>) | exponent | |

| | <Expression> `^` <Expression> | exponent | |

| | min(<Expression>, <Expression>) | minimum | |

| | max(<Expression>, <Expression>) | maximum |

Instead of using the {}/1 predicate, you can also use the standard unification mechanism to store constraints. The following code samples are equivalent:

*Unification with a variable*

{X =:= Y} {X = Y} X = Y

*Unification with a number*

{X =:= 5.0} {X = 5.0} X = 5.0

A = B * C | B or C is ground | A = 5 * C or A = B * 4 |

A and (B or C) are ground | 20 = 5 * C or 20 = B * 4 | |

A = B / C | C is ground | A = B / 3 |

A and B are ground | 4 = 12 / C | |

X = min(Y,Z) | Y and Z are ground | X = min(4,3) |

X = max(Y,Z) | Y and Z are ground | X = max(4,3) |

X = abs(Y) | Y is ground | X = abs(-7) |

X = pow(Y,Z) | X and Y are ground | 8 = 2 `^` Z |

X = exp(Y,Z) | X and Z are ground | 8 =
Y `^` 3 |

X = Y `^` Z | Y and Z are ground | X = 2 `^` 3 |

X = sin(Y) | X is ground | 1 = sin(Y) |

X = cos(Y) | Y is ground | X = sin(1.5707) |

X = tan(Y) |

The clpq and clpr libraries are `orphaned', i.e., they currently have no maintainer.

*Top-level output*

The top-level output may contain variables not present in the original query:?- {X+Y>=1}. {Y=1-X+_G2160, _G2160>=0}. ?-

Nonetheless, for linear constraints this kind of answer means unconditional satisfiability.

*Dumping constraints*

The first argument of dump/3 has to be a list of free variables at call-time:?- {X=1},dump([X],[Y],L). ERROR: Unhandled exception: Unknown message: instantiation_error(dump([1],[_G11],_G6),1) ?-

Tag confusing pages with **doc-needs-help**|Tags are associated to your profile if you are logged in

Tags: