Reputation: 307
I need to check if first given term (for example s(s(nul))
(or 2)) is dividable by the second term, (for example s(nul)
(or 1)).
What I want to do is multiply given term by two and then check if that term is smaller or equal to the other term (if it is equal - problem is solved).
So far I got this:
checkingIfDividable(X,X).
checkingIfDividable(X,Y) :-
X > Y,
multiplication(X,Y).
/* multiplication by two should occur here.
I can't figure it out. This solution does not work!*/
multiplication(Y):-
YY is Y * 2,
checkingIfDividable(X,YY).
I can't seem to figure out how to multiply a term by 2. Any ideas?
Upvotes: 0
Views: 493
Reputation: 71075
If a = n*b, n > 0
, it is also a = n*b = (1+m)*b = b + m*b, m >= 0
.
So if a
is dividable by b
, and a = b+x
, then x
is also dividable by b
.
In Peano encoding, n = 1+m
is written n = s(m)
.
Take it from here.
Upvotes: 1