529 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
3
votes
0
answers
168
views
Sliding 15-puzzle using CLP(FD)
Below is my code for a shortest-path solver of the well-known sliding 15 puzzle, using CLP(FD).
:- use_module(library(clpfd)).
% length 35 (starting position plus 34 moves), roughly 11 CPU seconds
...
brebs's user avatar
- 4,520
3
votes
1
answer
222
views
Sicstus CLPFD labeling time discrepancy
I was using Sicstus Prolog to solve Advent of Code 2024 Day 13, and I came across a surprising discrepancy in labeling times between different instances of the same constraint model. I have:
minCost(...
1
vote
1
answer
147
views
How to return general formulas from query?
So in many cases, like:
summa(X, Y, Z) :-
Z #= X + Y.
You can give the most general query to return a generic solution:
?-summa(X, Y, Z).
$VAR(X)+ $VAR(Y)#= $VAR(Z).
I have a formula involving ...
0
votes
1
answer
120
views
Can reification predicates from CLP(FD) be used to check equality of logic expressions?
According to the documentation (section A.9.12), CLP(FD) constraints such as #>, #=, #/\ etc. can be reified.
Constraint #<==>/2 is supposed to be
True iff P and Q are equivalent
according ...
0
votes
1
answer
78
views
How to transform a list of integers (solutions) into a list of continuous intervals
I have written a CSP program using CLP(FD) and SWI-Prolog.
Some constraints look like Xi mod N #= 0, so I have to call res(Xi,Li) (with res(X,L) :- setof(X, indomain(X), L)) for each variable Xi to do ...
1
vote
1
answer
195
views
CLP(FD): solution number count speedup
I'm working with the following SWI-Prolog version: SWI-Prolog version 9.1.2 for x86_64-linux.
I'm trying to count the number of valid solutions using Prolog and the CLP(FD) module. Currently, to count ...
0
votes
0
answers
75
views
Matching arithmetic expressions in SWI-Prolog?
I have an arithmetic expression containing Var, and I need to match it to the following format:
Step * Var + Offset
If it can be represented in this form, I need to get Step and Offset values. If not, ...
2
votes
2
answers
167
views
Can CLPFD distribute things evenly into groups?
This is a simplified example; say I want to distribute weights over tables such that the tables end up roughly equally loaded, e.g. (10 10 10 5 5) Kg can balance equally as (10 10) (10 5 5).
(10 9 8 7)...
0
votes
0
answers
128
views
"Syntax error: Operator expected" with CLPFD Prolog
I'm reading The Power Of Prolog, and have got as far as the section on the Collatz sequence.
I copied and pasted the code from there, adding the appropriate use_module line before...
use_module(...
4
votes
1
answer
295
views
Different ways of expressing collatz conjecture in prolog fail
I'm learning prolog using SWI Prolog and the tutorial here. I find that if I express the collatz conjecture exactly like they do in the video, it works as long as I replace #= with is which I'm ...
2
votes
2
answers
233
views
Which operators and predicates can be used with clp(fd)?
Firstly, the clp(fd) documentation mentions:
In modern Prolog systems, arithmetic constraints subsume and supersede low-level predicates over integers. The main advantage of arithmetic constraints is ...
0
votes
2
answers
116
views
Why does this prolog rule using include/3 evaluate to false, but not when exploding it into individual comparisons?
I have a prolog rule position_that_is_equals_to_two that sets X to the position at which the number 2 was found in the provided list of three elements [X, Y, Z]:
position_that_is_equals_to_two([X, Y, ...
1
vote
0
answers
127
views
Preserve clpfd constraint variable in findall
I'm trying to capture a constraint variable in findall. But on the other end I get independent copies of the variable:
?- X #> 1, findall(X, (true; true), Xs), X #< 100.
Xs = [_A, _B],
X in 2.....
1
vote
1
answer
190
views
Why is this code in PROLOG using constraints gives Operator expected syntax error?
col_tri(Vars):- Vars=[X1,X2,X3],
Vars in 1..3,
X1#\=X2,
X1#\=X3,
X2#\=X3,
label(Vars).
This code is giving me this ...
1
vote
2
answers
135
views
Non-branching version of 'bagof'
I'm trying to implement a sudoku-like puzzle solver that involves groups in prolog, and where one of the rules is that the same value cannot be repeated in the same group. My code 'works', but it ends ...