I came across this natural estimate of the number of logical numbers in a textbook, and this gave me some headache:
natural_number(0). natural_number(s(N)) :- natural_number(N).
The rule roughly states that: if N is 0 , it is natural if we do not try to send the contents of s/1 back recursively to the rule until the content is 0 , then this is a natural number if not, then this is not so.
So, I tested the above logical implementation, I thought to myself, it works well if I want to represent s(0) as 1 and s(s(0)) as 2 , but I would like to be able to convert s(0) to 1 .
I was thinking of a basic rule:
sToInt(0,0). %sToInt(X,Y) Where X=s(N) and Y=integer of X
So here is my question . How to convert s (0) to 1 and s (s (0)) to 2?
Was answered
Edit: I changed the basic rule in the implementation, which the answer I accepted pointed me to:
decode(0,0). %was orignally decode(z,0). decode(s(N),D):- decode(N,E), D is E +1. encode(0,0). %was orignally encode(0,z). encode(D,s(N)):- D > 0, E is D-1, encode(E,N).
So, now I can use it as I wanted, thanks to everyone!