SHARE
TWEET

Untitled

a guest Oct 21st, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. isnumber(zero).
  2. isnumber(s(X)) :- isnumber(X).
  3.  
  4. isequal(X,X) :- isnumber(X).
  5. isequal(s(X),s(Y)) :- isequal(X,Y).
  6.  
  7. lessthanequal(zero,X) :- isnumber(X).
  8. lessthanequal(s(X),s(Y)) :- lessthanequal(X,Y).
  9.  
  10. add1(zero,X,X) :- isnumber(X).
  11. add1(s(X),Y,s(Z)) :- add1(X,Y,Z).
  12.  
  13. odd(s(zero)).
  14. odd(s(s(s(X)))) :- odd(s(X)).
  15.  
  16. even(zero).
  17. even(s(s(X))) :- even(X).
  18.  
  19. times(zero,X,zero) :- isnumber(X).
  20. times(s(X),Y,Z) :- times(X,Y,Q), add1(Y,Q,Z).
  21.  
  22. quotient(X,X,s(zero)) :- isnumber(s(zero)).
  23. quotient(X,Y,s(Z)) :- quotient(Q,Y,Z), add1(Y,Q,X).
  24.  
  25. remainder(X,X,zero).
  26. remainder(X,Y,R) :- add1(X,Y,Q), remainder(Q,Y,R).
  27.  
  28. fact(zero,s(zero)) :- isnumber(s(zero)).
  29. fact(N,X) :- fact(A,B), add1(A,s(zero),N), times(B,N,X).
  30.  
  31. fib(0, 0).
  32. fib(1, 1).
  33. fib(N, X) :- fib(A, C), fib(B, D), A is N - 1, B is N - 2, X is C + D.
  34.  
  35. shownum(zero,0).
  36. shownum(X,N) :- shownum(A,B), add1(A,s(zero),X), N is B + 1.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top