Home > Blockchain >  Prolog Termination of Generated List
Prolog Termination of Generated List

Time:10-01

N #>= 0, N #< 3, length(Ls, N), false.

The expression above does not terminate when posted on the swi prolog terminal.

I have tried exchanging the order of goals.

length(Ls, N), N #>= 0, N #< 3,  false.

and

length(Ls, N), N >= 0, N < 3, false.

I am using SWI-Prolog version 8.4.3 for x86_64-linux

CodePudding user response:

N is still var at that point. Use instead (if you really want to use clpfd - I'm not seeing a reason):

?- N #>= 0, N #< 3, label([N]), length(Ls, N), false.
false.

CodePudding user response:

length(Ls, N), N >= 0, N < 3, false.

This will count up N trying different values until all the conditions are true, but false is never true.

So this is "count until false is true", which is "count forever", an infinite loop.

  • Related