1

I'm working with prolog and i need to handle huge numerical values (i know, prolog is not originaly designed to handle numbers). I'm using ECLiPSe 6.1 and the documentation of some built in predicates as fd_global:ordered_sum\2 says:

Any input variables which do not already have finite bounds will be given default bounds of -10000000 to 10000000

How can i handle value greater than 10000000? (In general, not necessarily with ECLiPSe).

damianodamiano
  • 2,528
  • 2
  • 13
  • 21
  • 2
    Well in other systems such as SWI-Prolog (including its CLP(FD) library), numbers can be arbitrarily large (assuming you have enough memory of course…) – Fatalize Nov 23 '17 at 07:36
  • 1
    @Fatalize: An expression like `X #>= 0` includes *all* numbers above `X`. – false Nov 23 '17 at 18:51

1 Answers1

2

If you use library(ic), then generally variables get infinite bounds by default, when used in the basic constraints:

?- lib(ic).
Yes (0.13s cpu)

?- sum([X,Y,Z]) #= 0.
X = X{-1.0Inf .. 1.0Inf}
Y = Y{-1.0Inf .. 1.0Inf}
Z = Z{-1.0Inf .. 1.0Inf}
There is 1 delayed goal.
Yes (0.00s cpu)

However, the algorithms in some of the global constraint implementations cannot handle infinite bounds, and therefore impose the default bounds you mention:

?- ic_global:ordered_sum([X,Y,Z], 0).
X = X{-10000000 .. 0}
Y = Y{-5000000 .. 5000000}
Z = Z{0 .. 10000000}
There are 5 delayed goals.
Yes (0.06s cpu)

To avoid this, you can initialize the variables with larger finite bounds before invoking the global constraint:

?- [X,Y,Z] :: -1000000000000000..1000000000000000, ic_global:ordered_sum([X,Y,Z], 0).
X = X{-1000000000000000 .. 0}
Y = Y{-500000000000000 .. 500000000000000}
Z = Z{0 .. 1000000000000000}
There are 5 delayed goals.
Yes (0.00s cpu)
false
  • 10,264
  • 13
  • 101
  • 209
jschimpf
  • 4,904
  • 11
  • 24
  • 2
    Nice and clear explanation. So you also suggest to use the predicates from `ic_global` and not `fd_global` or `fd` when available? Are there some huge differences? – damianodamiano Nov 23 '17 at 11:42
  • @damianodamiano: If that answer fits you, upvote it and accept it by checking the checkmark – false Nov 23 '17 at 19:43
  • 2
    Yes, you should use the ``ic`` and ``ic_xxx`` family of libraries. The ``fd`` family is an older implementation. – jschimpf Nov 24 '17 at 18:03