Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fact(0,1).
- fact(N,R):- N1 is N-1,
- fact(N1,R1),
- R is N*R1,!.
- % Calculating the exponential (complex version)
- exp(_,0,1).
- exp(X,N,Res):- (N > 0,
- fact(N,Fact),
- Frac is X**N/Fact,
- N1 is N-1,
- exp(X,N1,Res1),
- Res is Res1 + Frac);
- (N < 0, write("N must be positive")).
- %% Simple version:
- exp2(_,0,1).
- exp2(X,N,Res):- fact(N,Fact),
- Frac is X**N/Fact,
- N1 is N-1,
- exp2(X,N1,Res1),
- Res is Res1 + Frac.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement