因此,我试图仅使用一个谓词来确定一个数字是否为素数。我真的不明白为什么这里的每个数字都被宣布为假。
is_prime(2).
is_prime(X) :-
X > 2, %0 and 1 aren't primes, 2 is dealt with above
1 is mod(X,2), %number is odd
N is floor(X/2), %I want to only divide X from 1 to X/2
forall( between(1,N,Z), mod(X,Z) > 0 ). %This should do X mod 1:X/2