Search code examples
prologclpfdeclipse-clp

Handle huge numeric values prolog


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).


Solution

  • 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)