For faster navigation, this Iframe is preloading the Wikiwand page for CLP(R).

CLP(R)

CLP(R) is a declarative programming language. It stands for constraint logic programming (real) where real refers to the real numbers. It can be considered and is generally implemented as a superset or add-on package for a Prolog implementation.

Example rule

[edit]

The simultaneous linear equations:

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

[edit]

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

[edit]

CLP(R) has first been integrated into a Prolog system in 1994, namely into SICStus Prolog.[1] This implementation has since been ported to many popular Prolog systems, including Ciao,[2] SWI-Prolog[3] and XSB.[4]

See also

[edit]

References

[edit]
  1. ^ Holzbaur, Christian (1995). "OEFAI clp(q,r) Manual Revision 1.3.2,". ÖFAI Technical Reports Online (95–09).
  2. ^ "Introduction — The Ciao System v1.22". ciao-lang.org. Retrieved 2023-11-06.
  3. ^ "SWI-Prolog manual". www.swi-prolog.org. Retrieved 2023-11-06.
  4. ^ Swift, Theresa (13 May 2022). "Constraint Packages". The XSB System, Version 5.0, Volume 2: Interfaces and Packages. p. 71.
[edit]


{{bottomLinkPreText}} {{bottomLinkText}}
CLP(R)
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 ๐ŸŽ‰! the new version arrives on September 1st! Don't want to wait?