My code below is meant to generate the square of natural numbers in order
(i.e sq(X). -> X=0; X=1; X=4; X=9; X=16; ...
)
nat(0).
nat(X) :- nat(Y), Z is Y+1, X is Z*Z.
but the answer I am getting is:
1
0 ?- nat(X).
X = 0 ;
X = 1 ;
X = 4 ;
X = 25 ;
X = 676
Should be a quick fix, but I've spent longer on this than I'd like to say. Any help is greatly appreciated!