home *** CD-ROM | disk | FTP | other *** search
Prolog Source | 1986-10-10 | 1.9 KB | 70 lines |
- /*****
- This program illustrates number crunching ability
- and predicate return versatility by calculating
- various elements needed in exponentiaiton
- Eddy C. Vasile 5/8/86
- PLC 213-689-5647
- 73317,701 on CompuServe
- occ4edi@uclamvs on BitNet
- *****/
-
- predicates
- power(real,real,real)
- example1
- example2
- example3
- run
- goal run.
- clauses
- /*****
- Prolog tries hard to give you what you ask for. If the variables
- Base and Exponent are bound (i.e. values assigned) then Result
- is calculated, if Base and Result are Bound and Exponent is free
- then a solution is returned for Exponent
- *****/
-
- power(A,B,C):-
- bound(A),
- bound(B),
- C=exp(B*ln(A)).
- power(A,B,C):-
- bound(A),
- bound(C),
- B=ln(C)/ln(A).
- power(A,B,C):-
- bound(B),
- bound(C),
- A=exp(ln(C)/B).
-
- run:-
- example1,
- example2,
- example3.
-
- example1:-
- makewindow(1,31,3,"Calculate Result",1,1,6,78),
- write("Enter base >"),
- readreal(A),
- write("Enter Coefficient > "),
- readreal(B),
- power(A,B,C),
- writef("%1.3f ^ %-1.3f = %-1.3f\n",A,B,C).
-
- example2:-
- makewindow(2,31,3,"Calculate Coefficient",7,1,6,78),
- write("Enter base >"),
- readreal(A),
- write("Enter Result > "),
- readreal(C),
- power(A,B,C),
- writef("%1.3f ^ %-1.3f = %-1.3f\n",A,B,C).
-
- example3:-
- makewindow(3,31,3,"Calculate Base",13,1,6,78),
- write("Enter Coefficient >"),
- readreal(B),
- write("Enter Result > "),
- readreal(C),
- power(A,B,C),
- writef("%1.3f ^ %-1.3f = %-1.3f\n",A,B,C).
-