What will be the final balance if I borrow $P for T years, at an interest rate of I%, and annual repayments R?
Repeat this with the question:
If I can afford to make annual repayments R over a period T, and the interest rates are I%, how much can I borrow?
Finally, imagine a program which can give meaningful answers to the question:
In general, if I'm looking at a T year loan with I% interest rates, what is the relationship between the principal sum, the repayments, and the final balance?
Now take a look at a simple CLP(R) program (here's a commented version). Copy and paste this program into a file in your own area called "mort". Now load up CLP(R), and input the program mort:
(Note that you will get a message regarding poor style in the program - ignore it, this is an issue for later).sealion_246 %clpr CLP(R) Version 1.2a (c) Copyright International Business Machines Corporation 1989 (1991, 1992) All Rights Reserved 1 ?- [mort].
2 ?- mortgage(1000,10,10/100,150,B). B = 203.129 *** Retry? ; *** Noindicating that the balance is $203.13 (the "retry" asks clpr if there is any other balance that satisfies the requirements).
3 ?- mortgage(P,10,10/100,150,0). P = 921.685 *** Retry? ; *** No
4 ?- mortgage(P,10,10/100,R,B). P = 0.385543*B + 6.14457*R *** Retry? ; *** No
You may have come across cryptarithms, for example
SEND +MORE ----- MONEYThe idea is that
Try solving the program for yourself.
Try to design a program to solve it, in a language you're familiar with
Finally, try out ECLiPSe:
Take a look at an ECLiPSe program for this. Copy and paste this into a program in your own area called "sendmore". Start up ECLiPSe and load the program:
sealion_251 %eclipse ECLiPSe Constraint Logic Programming System [sepia parallel mps] Version 4.0.2, Copyright ECRC GmbH and ICL/IC-Parc, Fri Jul 28 15:30 1998 [eclipse 1]: [sendmore]. structures.pl compiled traceable 3984 bytes in 0.00 seconds lists.pl compiled traceable 6436 bytes in 0.01 seconds sorts.pl compiled traceable 1292 bytes in 0.00 seconds fd_domain.sd loaded traceable 27392 bytes in 0.06 seconds fd_arith.sd loaded traceable 72912 bytes in 0.15 seconds fd_util.pl compiled traceable 2116 bytes in 0.01 seconds fd_chip.pl compiled traceable 4744 bytes in 0.02 seconds fd_elipsys.pl compiled traceable 10836 bytes in 0.02 seconds fd.sd loaded traceable 19300 bytes in 0.21 seconds sendmore compiled traceable 1352 bytes in 0.22 seconds yes.Now ask ECLiPSe to solve the problem:
[eclipse 2]: smm(S,E,N,D,M,O,R,Y). S = 9 E = 5 N = 6 D = 7 M = 1 O = 0 R = 8 Y = 2 More? (;) no (more) solution.(like CLP(R), ECLiPSe gives you the option of finding more than one answer; typing ";" leads to further searching - in this case unsuccessful, ie there is only one solution). You may find it interesting to trace what ECLiPSe is doing:
[eclipse 4]: trace(smm(S,E,N,D,M,O,R,Y)).You may find ECLiPSe's approach is somewhat similar to your human approach!