Next: Mortgage Calculator, Previous: Cumulative Scheduling, Up: CLPFD Example Programs [Contents][Index]
The following small examples show how you can use this package for solving equations over reals.
This example shows how propagation alone can prune the bounds of variables:
| ?- X in 1.0 .. 3.0, Y^2.0 $= X. X in 1.0..3.0, Y in-1.7320508075688776..1.7320508075688779 ?
This example solves a small equation system over two variables and
illustrates the use of the precision
parameter and the fact
that it’s sometimes not possible to avoid spurious solutions that
arise due to accumulated rounding errors.
| ?- X in 0.0..1.0, X^3.0 + Y^3.0 $= 2.0*X*Y, X^2.0+Y^2.0 $= 1.0, labeling([precision(1.5E-15)], [X,Y]). X = 0.39105200381556626, Y = -0.9203685839444056 ? ; X = 0.4497874598272418, Y = 0.8931356229499292 ? ; X = 0.4497874598272409, Y = 0.893135622949929 ? ; X = 0.44978745982724133, Y = 0.8931356229499292 ? ; X = 0.8931356229499289, Y = 0.4497874598272413 ? ; no
This example encodes the problem of finding the complex square root of -1.
| ?- R in -1.0..1.0, I in -1.0..1.0, -R*I $= R*I, I*I-1.0 $= R*R, labeling([precision(0.1)], [R,I]). R = 0.0, I = -1.0 ? ; R = 0.0, I = 1.0 ? ; no
This example solves a small equation system over two variables that involves a trigonometric function:
| ?- X $>= 0.0, Y $>= 0.0, tan(X) $= Y, X^2.0 + Y^2.0 $= 5.0, labeling([precision(3.0E-15)], [X,Y]). X = 1.096668128705471, Y = 1.948671089609952 ? ; no
This example solves how to explore the set of solution to a high-degree equation:
| ?- X in 0.8..1.0, 0.0 $= 35.0*X^256.0 -14.0*X^17.0 + X, labeling([precision(5.0E-16)], [X]). X = 0.8479436608273152 ? ; X = 0.995842494200498 ? ; no