Next: Rack Configuration, Previous: Equation Solving, Up: CLPFD Example Programs [Contents][Index]
This small example, adapted from CLPQR Projection, illustrates the use of arithmetic relations over reals. It defines a simple mortgage calculator as a relation over:
T
, a parameter, is the number of interest periods (e.g., years)
P
is the initial balance
I
is the interest ratio, e.g., 0.10 means 10%
B
is the balance at the end of the period
MP
is the withdrawal amount for each interest period
mortgage(1, P, Interest, B, MP) :- !, B + MP $= P * (1.0 + Interest). mortgage(T, P, Interest, B, MP) :- P1 + MP $= P * (1.0 + Interest), T1 is T - 1, mortgage(T1, P1, Interest, B, MP). | ?- % if I deposit 1000.0 at 10% interest, % what is the balance if I withdraw 250.0 per year four times? mortgage(4, 1000.0, 0.10, B, 250.0), indomain(B). B = 303.8500000000002 | ?- % if I deposit 1000.0 at 10% interest, % how much should I redraw to empty the account in four years? mortgage(4, 1000.0, 0.10, 0.0, MP), MP $>= 0.0, indomain(MP). MP = 315.47080370609797 | ?- % At 10% interest, how much should I deposit % if I want the balance to be 2000.0 in four years? mortgage(4, P, 0.10, 2000.0, 0.0), indomain(P). P = 1366.026910730141