CLP(R) is a
declarative programming language
In computer science, declarative programming is a programming paradigm—a style of building the structure and elements of computer programs—that expresses the logic of a computation without describing its control flow.
Many languages that app ...
. It stands for
constraint logic programming
Constraint logic programming is a form of constraint programming, in which logic programming is extended to include concepts from constraint satisfaction. A constraint logic program is a logic program that contains constraints in the body of claus ...
(real) where real refers to the
real number
In mathematics, a real number is a number that can be used to measure a continuous one- dimensional quantity such as a duration or temperature. Here, ''continuous'' means that pairs of values can have arbitrarily small differences. Every re ...
s. It can be considered and is generally implemented as a superset or add-on package for a
Prolog
Prolog is a logic programming language that has its origins in artificial intelligence, automated theorem proving, and computational linguistics.
Prolog has its roots in first-order logic, a formal logic. Unlike many other programming language ...
implementation.
Example rule
The
simultaneous linear equations
In mathematics, a system of linear equations (or linear system) is a collection of two or more linear equations involving the same variables.
For example,
: \begin
3x+2y-z=1\\
2x-2y+4z=-2\\
-x+\fracy-z=0
\end
is a system of three equations in ...
:
:
are expressed in CLP(R) as:
3*X + 4*Y - 2*Z = 8,
X - 5*Y + Z = 10,
2*X + 3*Y -Z = 20.
and a typical implementation's response would be:
Z = 35.75
Y = 8.25
X = 15.5
Yes
Example program
CLP(R) allows the definition of predicates using recursive definitions. For example a ''mortgage'' relation can be defined as
relating the principal P, the number of time periods of the loan T, the repayment each period R, the interest rate per period I
and the final balance owing at the end of the loan B.
mg(P, T, R, I, B) :- T = 0, B = R.
mg(P, T, R, I, B) :- T >= 1, P1 = P*(1+I) - R, mg(P1, T - 1, R, I, B).
The first rule expresses that for a 0 period loan the balance owing at the end is simply the original principal.
The second rule expresses that for a loan of at least one time period we can calculate the new owing amount P1 by
multiplying the principal by 1 plus the interest rate and subtracting the repayment. The remainder of the loan
is treated as another mortgage for the new principal and one less time period.
What can you do with it? You can ask many questions.
If I borrow 1000$ for 10 years at 10% per year repaying 150 per year, how much will I owe at the end?
?- mg(1000, 10, 150, 10/100, B).
The system responds with the answer
B = 203.129.
How much can I borrow with a 10 year loan at 10% repaying 150 each year to owe nothing at the end?
?- mg(P, 10, 150, 10/100, 0).
The system responds with the answer
P = 921.685.
What is the relationship between the principal, repayment and balance on a 10 year loan at 10% interest?
?- mg(P, 10, R, 10/100, B).
The system responds with the answer
P = 0.3855*B + 6.1446 * R.
This shows the relationship between the variables, without requiring any to take a particular value.
Prolog Integration
CLP(R) has first been integrated into a Prolog system in 1994, namely into
SICStus Prolog
SICStus Prolog is a proprietary, ISO-conforming implementation of the logic programming language Prolog. It is developed by the Swedish Institute of Computer Science since 1985 and puts a strong focus on performance and scalability.
History ...
. This implementation has since been ported to many popular Prolog systems, including
Ciao
( , ) is an informal salutation in the Italian language that is used for both " hello" and "goodbye".
Originally from the Venetian language, it has entered the vocabulary of English and of many other languages around the world. Its dual mea ...
,
SWI-Prolog
SWI-Prolog is a free implementation of the programming language Prolog, commonly used for teaching and semantic web applications. It has a rich set of features, libraries for constraint logic programming, multithreading, unit testing, GUI, int ...
and
XSB.
See also
*
Comparison of Prolog implementations
The following Comparison of Prolog implementations provides a reference for the relative feature sets and performance of different implementations of the Prolog computer programming language. A comprehensive discussion of the most significant Pro ...
*
Prolog syntax and semantics
The syntax and semantics of Prolog, a programming language, are the sets of rules that define how a Prolog program is written and how it is interpreted, respectively. The rules are laid out in ISO standard ISO/IEC 13211''ISO/IEC 13211: Informat ...
References
* Joxan Jaffar, Spiro Michaylov, Peter J. Stuckey, Roland H. C. Yap
The CLP(R) Language and System ACM Transactions on Programming Languages and Systems
The ''ACM Transactions on Programming Languages and Systems'' (''TOPLAS'') is a bimonthly, open access, peer-reviewed scientific journal on the topic of programming languages published by the Association for Computing Machinery.
Background
Publi ...
14(3): 339-395 (1992)
External links
How To CLP(R)
CLP(R) Programming Manual
Prolog programming language family
Constraint logic programming
{{prog-lang-stub