• 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.5 Reification predicates
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
      • The SWI-Prolog library
        • library(clpfd): CLP(FD): Constraint Logic Programming over Finite Domains
          • CLP(FD) predicate index
            • Reification predicates
              • #\/1
              • #<==>/2
              • #==>/2
              • #<==/2
              • #/\/2
              • #\//2
              • #\/2
              • zcompare/3
    • Packages
zcompare(?Order, ?A, ?B)
Analogous to compare/3, with finite domain variables A and B.

This predicate allows you to make several predicates over integers deterministic while preserving their generality and completeness. For example:

n_factorial(N, F) :-
        zcompare(C, N, 0),
        n_factorial_(C, N, F).

n_factorial_(=, _, 1).
n_factorial_(>, N, F) :-
        F #= F0*N, N1 #= N - 1,
        n_factorial(N1, F0).

This version is deterministic if the first argument is instantiated, because first argument indexing can distinguish the two different clauses:

?- n_factorial(30, F).
F = 265252859812191058636308480000000.

The predicate can still be used in all directions, including the most general query:

?- n_factorial(N, F).
N = 0,
F = 1 ;
N = F, F = 1 ;
N = F, F = 2 .

ClioPatria (version V3.0.0-338-gc91dba5-DIRTY)