• Places
    • Home
    • Graphs
    • Prefixes
  • Admin
    • Users
    • Settings
    • Plugins
    • Statistics
  • Repository
    • Load local file
    • Load from HTTP
    • Load from library
    • Remove triples
    • Clear repository
  • Query
    • YASGUI SPARQL Editor
    • Simple Form
  • Help
    • Documentation
    • Tutorial
    • Roadmap
    • HTTP Services
  • Login

A.8.17 CLP(FD) predicate index
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
      • The SWI-Prolog library
        • library(clpfd): CLP(FD): Constraint Logic Programming over Finite Domains
          • CLP(FD) predicate index
            • Arithmetic constraints
              • #=/2
              • #\=/2
              • #>=/2
              • #=</2
              • #>/2
              • #</2
            • Membership constraints
            • Enumeration predicates
            • Global constraints
            • Reification predicates
            • Reflection predicates
    • Packages

A.8.17.1 Arithmetic constraints

Arithmetic constraints are the most basic use of CLP(FD). Every time you use (is)/2 or one of the low-level arithmetic comparisons ((<)/2, (>)/2 etc.) over integers, consider using CLP(FD) constraints instead. This can at most increase the generality of your programs. See declarative integer arithmetic (section A.8.3).

?X #= ?Y
The arithmetic expression X equals Y. This is the most important arithmetic constraint (section A.8.2), subsuming and replacing both (is)/2 and (=:=)/2 over integers. See declarative integer arithmetic (section A.8.3).
?X #\= ?Y
The arithmetic expressions X and Y evaluate to distinct integers. When reasoning over integers, replace (=\=)/2 by #\=/2 to obtain more general relations. See declarative integer arithmetic (section A.8.3).
?X #>= ?Y
Same as Y #=< X. When reasoning over integers, replace (>=)/2 by #>=/2 to obtain more general relations. See declarative integer arithmetic (section A.8.3).
?X #=< ?Y
The arithmetic expression X is less than or equal to Y. When reasoning over integers, replace (=<)/2 by #=</2 to obtain more general relations. See declarative integer arithmetic (section A.8.3).
?X #> ?Y
Same as Y #< X. When reasoning over integers, replace (>)/2 by #>/2 to obtain more general relations See declarative integer arithmetic (section A.8.3).
?X #< ?Y
The arithmetic expression X is less than Y. When reasoning over integers, replace (<)/2 by #</2 to obtain more general relations. See declarative integer arithmetic (section A.8.3).

In addition to its regular use in tasks that require it, this constraint can also be useful to eliminate uninteresting symmetries from a problem. For example, all possible matches between pairs built from four players in total:

?- Vs = [A,B,C,D], Vs ins 1..4,
        all_different(Vs),
        A #< B, C #< D, A #< C,
   findall(pair(A,B)-pair(C,D), label(Vs), Ms).
Ms = [ pair(1, 2)-pair(3, 4),
       pair(1, 3)-pair(2, 4),
       pair(1, 4)-pair(2, 3)].

ClioPatria (version V3.1.1-51-ga0b30a5)