Clpfd is not a square number

Is it possible to make a restriction for an integer to say that it cannot be a (ideal) square number?

I have:

square(Square):- N#>0, Square #= N*N.

How to determine notsquare(Notsquare):- ...

My first thought was to have P*P =Q*Q*NotsquareandRemainder #>0, Remainder #= P rem Q.

But P and Q must not be integers, so this did not work.

+4
source share
1 answer

What about

notSquare(S):- N #> 0, R #>0, R #< 2*N+1, S #= N*N+R.

?

Should work if S > 0; if you need to work with negative numbers too, I suppose you could change it as

notSquare(S):- S #> 0, N #> 0, R #>0, R #< 2*N+1, S #= N*N+R.
notSquare(S):- S #< 0, SM #= -S, notSquare(SM).
+5
source

Source: https://habr.com/ru/post/1651656/


All Articles