[ library(ic) | Reference Manual | Alphabetic Index ]

?Vars $:: ++Lo..++Hi

Constrain Vars to only take real values in the given Domain.
Vars
Variable or collection (a la collection_to_list/2) of variables
Domain
Domain in the form Lo..Hi

Description

Constrains Vars to take only real values in the given range, i.e. between (and including) Lo and Hi. Vars may be a variable or a collection of variables (as accepted by collection_to_list/2). The range must be give in the form Lo..Hi, where Lo and Hi are numbers or ground numeric expressions of arbitrary type.

If the variables already have domains, their domain is intersected with the new one, possibly failing if it becomes empty. Also, integrality is simply a constraint, and may be imposed on the variables independently.

Real domain variables can be instantiated to integers, floats, bounded reals or rationals (as they are all considered to be representations of real numbers).

Examples

?- X $:: 0.1..9.9.
X = X{0.1..9.9}
Yes (0.00s cpu)

?- X $:: -1..9.
X = X{-1.0..9.0}
Yes (0.00s cpu)

?- dim(Start, [4]), Start $:: 0.0..5.0.
Start = [](_434{0.0..5.0}, _449{0.0..5.0}, _464{0.0..5.0}, _479{0.0..5.0})
Yes (0.00s cpu)

?- length(Xs, 3), Xs $:: 0..inf.
Xs = [_400{0.0..1.0Inf}, _415{0.0..1.0Inf}, _430{0.0..1.0Inf}]
Yes (0.00s cpu)

?- X $:: [1 .. 3, 4 .. 5].
type error in X $:: [1 .. 3, 4 .. 5]

See Also

#:: / 2, $:: / 3, reals / 1, suspend : $:: / 2, eplex : $:: / 2