The operator #=
is mentioned on some page, e.g. https://www.metalevel.at/prolog but not on most other pages, e.g.: http://www.swi-prolog.org/pldoc/man?section=operators
What does this operator mean?
The operator #=
is mentioned on some page, e.g. https://www.metalevel.at/prolog but not on most other pages, e.g.: http://www.swi-prolog.org/pldoc/man?section=operators
What does this operator mean?
Operators are simply syntactical sugar for predicates: if you write X #= Y
, it is short for #=(X,Y)
, so lookup the predicate (#=)/2
.
The operator is mentioned as a predicate in the SWI-Prolog documentation:
The arithmetic expression
X
equalsY
. When reasoning over integers, replace(is)/2
by(#=)/2
to obtain more general relations. See declarative integer arithmetic (section A.8.3).
They are part of the Constraint Logic Programming on Finite Domains (CLP(FD)) package. One advantage of this constraint over the (is)/2
operator, is that it can be used in multiple directions. For instance:
?- use_module(library(clpfd)). true. ?- 4 #= 2*Y. Y = 2. ?- X #= 2*16. X = 32.
Furthermore, constraints can be delayed. For example:
?- X #= 2*Y, Y #= 14.
X = 28,
Y = 14.
For a more extensive introduction read this clpfd primer by @mat.
© 2022 - 2024 — McMap. All rights reserved.