1
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

false
  • 10,264
  • 13
  • 101
  • 209
Edgar
  • 159
  • 5
  • 1
    See [this](https://stackoverflow.com/a/32478496/772868) for a definition that does terminate in that case. – false Sep 30 '22 at 17:37

2 Answers2

1

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.
brebs
  • 3,462
  • 2
  • 3
  • 12
  • Thanks. The version without clpfd still does not terminate. `?- length(Ls, N), N<10, false.` Sorry for the noob question, I am still trying to understand the conditions for termination in prolog. – Edgar Sep 30 '22 at 09:41
  • 1
    That's because `length` would be incrementing N into infinity. Use e.g. `between(1, 9, N)` *before* `length`. – brebs Sep 30 '22 at 09:51
  • Great. `between` will work for me – Edgar Sep 30 '22 at 10:00
0

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.

TessellatingHeckler
  • 27,511
  • 4
  • 48
  • 87