# \#clpfd

**URL:** https://swi-prolog.discourse.group/tag/clpfd/26.md

[Latest](https://swi-prolog.discourse.group/latest.md) · [Categories](https://swi-prolog.discourse.group/categories.md) · [Tags](https://swi-prolog.discourse.group/tags.md)

---

## [Struggling with repeated floor division and clause matching in CLPFD](https://swi-prolog.discourse.group/t/struggling-with-repeated-floor-division-and-clause-matching-in-clpfd/9235)

<div class="topic-metadata">

**Author:** [@Nekkowe](https://swi-prolog.discourse.group/u/Nekkowe)\
**Replies:** 3\
**Last updated:** [August 28, 2025, 1:35am UTC](https://swi-prolog.discourse.group/t/struggling-with-repeated-floor-division-and-clause-matching-in-clpfd/9235 "2025-08-28T01:35:16Z")

</div>

I’m using: SWI-Prolog version 9.0.4 (Linux Mint Cinnamon) I want the code to: Find out if a number can be reduced to a multiple of another number by repeatedly applying floor division by 2, and how often that floor divi…

---

## [Bug in element/3?](https://swi-prolog.discourse.group/t/bug-in-element-3/9086)

<div class="topic-metadata">

**Author:** [@AZH](https://swi-prolog.discourse.group/u/AZH)\
**Replies:** 4\
**Last updated:** [July 1, 2025, 5:39pm UTC](https://swi-prolog.discourse.group/t/bug-in-element-3/9086 "2025-07-01T17:39:02Z")

</div>

Hi there! I’m using SWI-Prolog version 9.3.19 and I’ve found probably a bug in element/3 with this test: test(N) :- element(N, \[1,2\], A), element(N, \[1,2\], B), A #=\< 2, A + B #\>= 3. The correct output I expect is…

---

## [CLPFD max\_member/2](https://swi-prolog.discourse.group/t/clpfd-max-member-2/8639)

<div class="topic-metadata">

**Author:** [@albangabillon](https://swi-prolog.discourse.group/u/albangabillon)\
**Replies:** 5\
**Last updated:** [December 2, 2024, 8:03pm UTC](https://swi-prolog.discourse.group/t/clpfd-max-member-2/8639 "2024-12-02T20:03:52Z")

</div>

Hi all, Consider the code below, schedule(T,EndTime) :- Starts = \[S1,S2\], Ends = \[E1,E2\], T = \[ task(S1,D1,E1,C1,t1), task(S2,D2,E2,C2,t2) \], \[D1,D2\] = \[3, 2\], \[C1,C2\] = \[1, 1\], …

---

## [Why is my code so slow?](https://swi-prolog.discourse.group/t/why-is-my-code-so-slow/7681)

<div class="topic-metadata">

**Author:** [@NielsVandenEynde](https://swi-prolog.discourse.group/u/NielsVandenEynde)\
**Replies:** 5\
**Last updated:** [August 12, 2024, 6:11pm UTC](https://swi-prolog.discourse.group/t/why-is-my-code-so-slow/7681 "2024-08-12T18:11:30Z")

</div>

Does anyone know why my code is so slow? I’m at my wit’s end here. I am writing a program where you get a list of chocolates with different shapes that you have to pack in some different boxes. Each box also has a cost …

---

## [CLP(FD) labeling/2 predicate](https://swi-prolog.discourse.group/t/clp-fd-labeling-2-predicate/6847)

<div class="topic-metadata">

**Author:** [@albangabillon](https://swi-prolog.discourse.group/u/albangabillon)\
**Replies:** 3\
**Last updated:** [September 15, 2023, 11:27pm UTC](https://swi-prolog.discourse.group/t/clp-fd-labeling-2-predicate/6847 "2023-09-15T23:27:46Z")

</div>

Hi, I cannot figure out how the ff option works for the labeling/2 predicate X in 1..5, Y in 1..2, X + Y #= 6, labeling(\[ff\],\[X,Y\]). X = 4, Y = 2 X = 5, Y = 1 I would have expected solution X=5 and Y=1 to come up fir…

---

## [CLP Optimizations Solved! Should I have known?](https://swi-prolog.discourse.group/t/clp-optimizations-solved-should-i-have-known/6621)

<div class="topic-metadata">

**Author:** [@z5h](https://swi-prolog.discourse.group/u/z5h)\
**Replies:** 8\
**Last updated:** [June 13, 2023, 5:22pm UTC](https://swi-prolog.discourse.group/t/clp-optimizations-solved-should-i-have-known/6621 "2023-06-13T17:22:52Z")

</div>

You might have noticed from other posts that I’ve been getting into CLP. The problem relates to board-game maps that must satisfy constraints as follows. (Feel free to skip this.) the map is a grid of known size each …

---

## [Efficiently require a specific cardinality in clpfd](https://swi-prolog.discourse.group/t/efficiently-require-a-specific-cardinality-in-clpfd/6614)

<div class="topic-metadata">

**Author:** [@z5h](https://swi-prolog.discourse.group/u/z5h)\
**Replies:** 1\
**Last updated:** [June 6, 2023, 4:04pm UTC](https://swi-prolog.discourse.group/t/efficiently-require-a-specific-cardinality-in-clpfd/6614 "2023-06-06T16:04:19Z")

</div>

I need ways to guarantee that a value occurs exactly once, or at least one, in a list. I’m running out of memory. It seems global\_cardinality, with it’s requirement of specifying all (other) values with wildcards consum…

---

## [List\_to\_fdset/2](https://swi-prolog.discourse.group/t/list-to-fdset-2/5914)

<div class="topic-metadata">

**Author:** [@albangabillon](https://swi-prolog.discourse.group/u/albangabillon)\
**Replies:** 2\
**Last updated:** [November 6, 2022, 11:17pm UTC](https://swi-prolog.discourse.group/t/list-to-fdset-2/5914 "2022-11-06T23:17:53Z")

</div>

Hi, I wanted to naively translate a list of integers into a finite domain set but I got this error which I am unable to interpret. L = \[1,3,5\], list\_to\_fdset(L, S), X in S. Domain error: \`clpfd\_domain' expected, found …

---

## [I need help with my homework](https://swi-prolog.discourse.group/t/i-need-help-with-my-homework/5241)

<div class="topic-metadata">

**Author:** [@Spartan](https://swi-prolog.discourse.group/u/Spartan)\
**Replies:** 0\
**Last updated:** [April 8, 2022, 6:38am UTC](https://swi-prolog.discourse.group/t/i-need-help-with-my-homework/5241 "2022-04-08T06:38:01Z")

</div>

My programming teacher let us make an expert system of a farm with: 3 sensors and 3 actuators. A trapezoidal, triangular or bell fuzzy control has to be used. But honestly I don’t know how to implement what we saw in …

---

## [Implementing a \`range\` predicate](https://swi-prolog.discourse.group/t/implementing-a-range-predicate/5097)

<div class="topic-metadata">

**Author:** [@pbaille](https://swi-prolog.discourse.group/u/pbaille)\
**Replies:** 7\
**Last updated:** [March 6, 2022, 6:13pm UTC](https://swi-prolog.discourse.group/t/implementing-a-range-predicate/5097 "2022-03-06T18:13:59Z")

</div>

I’m trying to implement a ‘range’ predicate and got stuck range(\_,0, \[\]) :- !. range(From, Len, R) :- From2 #= (From + 1), Len2 #= (Len - 1), range(From2, Len2, R2), R = \[From|R2\]. ?- range(From,Length…

---

## [Use of SWI's clpfd with labeling option min versus GNU's fd\_minimize](https://swi-prolog.discourse.group/t/use-of-swis-clpfd-with-labeling-option-min-versus-gnus-fd-minimize/4778)

<div class="topic-metadata">

**Author:** [@adamcrussell](https://swi-prolog.discourse.group/u/adamcrussell)\
**Replies:** 3\
**Last updated:** [December 17, 2021, 1:51pm UTC](https://swi-prolog.discourse.group/t/use-of-swis-clpfd-with-labeling-option-min-versus-gnus-fd-minimize/4778 "2021-12-17T13:51:46Z")

</div>

On this input http://paste.debian.net/hidden/78d86c08/ this GNU Prolog code http://paste.debian.net/hidden/1bfbf7ee/ returns a correct answer of 40. This SWI-Prolog code against the same input does not return a correct …

---

## [Clpfd - when the 'label()' is necessary? - newbie question](https://swi-prolog.discourse.group/t/clpfd-when-the-label-is-necessary-newbie-question/4314)

<div class="topic-metadata">

**Author:** [@ktp](https://swi-prolog.discourse.group/u/ktp)\
**Replies:** 8\
**Last updated:** [August 24, 2021, 12:50pm UTC](https://swi-prolog.discourse.group/t/clpfd-when-the-label-is-necessary-newbie-question/4314 "2021-08-24T12:50:01Z")

</div>

Hello Everybody :slight\_smile: I’m the clpfd newbie and I try to use it to solve the fraction problem from the YT movie: I’m using: SWI-Prolog version 8.3.17 (but I think it is not very important) I want …

---

## [Specifying a simple puzzle in CLP](https://swi-prolog.discourse.group/t/specifying-a-simple-puzzle-in-clp/3892)

<div class="topic-metadata">

**Author:** [@bladyjoker](https://swi-prolog.discourse.group/u/bladyjoker)\
**Replies:** 4\
**Last updated:** [May 1, 2021, 7:02pm UTC](https://swi-prolog.discourse.group/t/specifying-a-simple-puzzle-in-clp/3892 "2021-05-01T19:02:58Z")

</div>

Hello marvelous Prolog community, I watched Vsauces’ recent Future of Reasoning video on YouTube (https://youtu.be/\_ArVh3Cj9rw?t=590) where he presented his audience with a simple logical puzzle: Paul is looking at Mar…

---

## [Some CLP(FD) shenanigans with indexing predicates](https://swi-prolog.discourse.group/t/some-clp-fd-shenanigans-with-indexing-predicates/3343)

<div class="topic-metadata">

**Author:** [@AmbientTea](https://swi-prolog.discourse.group/u/AmbientTea)\
**Replies:** 0\
**Last updated:** [December 5, 2020, 6:23pm UTC](https://swi-prolog.discourse.group/t/some-clp-fd-shenanigans-with-indexing-predicates/3343 "2020-12-05T18:23:13Z")

</div>

Hello, I’ve had this idea that I wanted to explore for a little while and today I wrote a little note with examples showing how little changes it takes to make length and nth work nicely with clp(fd) to handle some inte…

---

## [Clpfd: Declare variables dynamically?](https://swi-prolog.discourse.group/t/clpfd-declare-variables-dynamically/3271)

<div class="topic-metadata">

**Author:** [@softmonaut](https://swi-prolog.discourse.group/u/softmonaut)\
**Replies:** 7\
**Last updated:** [November 19, 2020, 7:41pm UTC](https://swi-prolog.discourse.group/t/clpfd-declare-variables-dynamically/3271 "2020-11-19T19:41:00Z")

</div>

Beginner question: Is it possible to generate/declare variables dynamically? I have a factbase representing the elements, attributes, etc. of a xml structure: xml\_fact(Kind, Property, Factid, Parentid, Value) , e.g. x…

---

## [Clpfd: "not in" constraint](https://swi-prolog.discourse.group/t/clpfd-not-in-constraint/3260)

<div class="topic-metadata">

**Author:** [@softmonaut](https://swi-prolog.discourse.group/u/softmonaut)\
**Replies:** 1\
**Last updated:** [November 18, 2020, 3:24pm UTC](https://swi-prolog.discourse.group/t/clpfd-not-in-constraint/3260 "2020-11-18T15:24:14Z")

</div>

Hi, this is obviously a beginner question: How to write a “not in” constraint to restrict a variable possible values by supplying a list of integers to exclude from the variable’s domain? Thx J

---

## [Interesting results with library(clpfd)](https://swi-prolog.discourse.group/t/interesting-results-with-library-clpfd/2797)

<div class="topic-metadata">

**Author:** [@sits](https://swi-prolog.discourse.group/u/sits)\
**Replies:** 6\
**Last updated:** [August 18, 2020, 3:36am UTC](https://swi-prolog.discourse.group/t/interesting-results-with-library-clpfd/2797 "2020-08-18T03:36:17Z")

</div>

Hi, I have a very simple program using library(clpfd) but I am confused as to why a possible answer is not being reported. The program is as follows: :- use\_module(library(clpfd)). solution1(A, D, B) :- B #= A + …

---

## [Don't understand syntax of clpfd cryptarithmetic puzzle example](https://swi-prolog.discourse.group/t/dont-understand-syntax-of-clpfd-cryptarithmetic-puzzle-example/1730)

<div class="topic-metadata">

**Author:** [@DamienDeville](https://swi-prolog.discourse.group/u/DamienDeville)\
**Replies:** 4\
**Last updated:** [January 10, 2020, 8:00am UTC](https://swi-prolog.discourse.group/t/dont-understand-syntax-of-clpfd-cryptarithmetic-puzzle-example/1730 "2020-01-10T08:00:26Z")

</div>

Could someone please explain the strange syntax of the first line of the cryptarithmetic puzzle example in the CLP(FD) documentation: https://www.swi-prolog.org/pldoc/man?section=clpfd puzzle(\[S,E,N,D\] + \[M,O,R,E\] = \[M,…

---

## [How do I get a prolog number from this clpfd code](https://swi-prolog.discourse.group/t/how-do-i-get-a-prolog-number-from-this-clpfd-code/1636)

<div class="topic-metadata">

**Author:** [@PasiK](https://swi-prolog.discourse.group/u/PasiK)\
**Replies:** 1\
**Last updated:** [December 18, 2019, 8:56pm UTC](https://swi-prolog.discourse.group/t/how-do-i-get-a-prolog-number-from-this-clpfd-code/1636 "2019-12-18T20:56:57Z")

</div>

This would be in a file tmp.pl :-use\_module(library(clpfd)). tst(R,G,X):- (R + G) // 2 #= X. These queries works as I expect ?- tst(100,400,X). X = 250. ?- tst(100,400,250). true Why am I getting this, I expect X …
