Questions tagged [prolog-setof]

setof/3 is a built-in predicate of ISO Prolog. It determines the set of solutions as a list for each different instantiation of the free variables.

69 questions
15
votes
1 answer

How do I find all solutions to a goal in Prolog?

I have predicate P1 that returns values one after the other like this: -? P1(ARGUMENTS, RETURN). -? RETURN = 1; -? RETURN = 2; -? RETURN = 3; -? fail. I also have another predicate called P2: P2(ARGUMENTS, LIST) :- P1(ARGUMENTS, RETURN),... %…
Asterisk
  • 3,534
  • 2
  • 34
  • 53
12
votes
4 answers

What is the Prolog operator `^` ("caret")?

What is the Prolog operator ^ ? Looking at The Prolog Built-in Directive op gives a list of the built-in operators. I see ** is exponentiation /\ is or but what is ^ ? Each of the three current answers are of value and I learned something: …
Guy Coder
  • 24,501
  • 8
  • 71
  • 136
10
votes
2 answers

How to choose between bagof, setof and findall in Prolog

How does one choose between bagof, setof and findall? Are there any important differences? Which is most commonly used and which is the safest? Thanks for your comments/answers. I checked the SWI-Prolog manual page on findall/3 and found them to be…
rnso
  • 23,686
  • 25
  • 112
  • 234
9
votes
6 answers

Don't repeat solutions in Prolog

Suppose you have a database with the following content: son(a, d). son(b, d). son(a, c). son(b, c). So a and b are sons of d and c. Now you want to know, given a bigger database, who is brother to who. A solution would be: brother(X, Y) :- …
petermlm
  • 930
  • 4
  • 12
  • 27
8
votes
2 answers

Duplicate solutions

I have a problem trying to get some code that returns unique answers to my query. For example, defining stuff(A,B,C) :- A=C ; B=C. morestuff([],[],[]). morestuff([A|AA],[B|BB],[C|CC]) :- stuff(A,B,C), morestuff(AA,BB,CC). then…
Lucas
  • 1,869
  • 4
  • 20
  • 36
7
votes
3 answers

Collect all "minimum" solutions from a predicate

Given the following facts in a database: foo(a, 3). foo(b, 2). foo(c, 4). foo(d, 3). foo(e, 2). foo(f, 6). foo(g, 3). foo(h, 2). I want to collect all first arguments that have the smallest second argument, plus the value of the second argument.…
user1812457
6
votes
2 answers

Prolog - wolf goat cabbage

I'm working on a puzzle game named "wolf goat cabbage". The programming language is Prolog. change(e,w). change(w,e). move([X,X,Goat,Cabbage],wolf,[Y,Y,Goat,Cabbage]) :- change(X,Y). move([X,Wolf,X,Cabbage],goat,[Y,Wolf,Y,Cabbage]) :-…
Amay
  • 1,461
  • 5
  • 27
  • 56
6
votes
2 answers

Prolog: Failure driven loops

I used the following failure driven loop to list everything without using semicolons. happiness(fred,5). happiness(john,3). happiness(grace,2). someGoal(X) :- happiness(X,Y), write(Y), tab(4), fail. In query mode, I get this as expected ?-…
Zoran
  • 459
  • 1
  • 6
  • 19
5
votes
2 answers

setof in prolog

what is the source code of setof in prolog?
5
votes
4 answers

How to check if any statisfying clause exists in Prolog without backtracking through all different paths?

Let's say I have the following: parent(alice, charlie). parent(bob, charlie). parent(bob, diane). parent(alice, diane). parent(bob, eve). parent(alice, eve). % people are siblings of each other if they share a parent % and aren't the same…
SQB
  • 3,926
  • 2
  • 28
  • 49
5
votes
1 answer

existential qualifier in prolog, using setof / bagof

I had a quick question re. existential qualifier using setof in prolog (i.e. ^). using SICStus it seems that (despite what a number of websites claim), S does indeed appear to be quantified in the code below (using the bog standard, mother of /…
oneAday
  • 1,261
  • 4
  • 15
  • 16
4
votes
3 answers

Prolog Recursion skipping same results

My code runs but the problem is it shows the same results more than once. Here's my code:…
Mezzan
  • 329
  • 1
  • 5
  • 18
4
votes
1 answer

bagof/3 is unpredictable

I am baffled by the following results. I am using SWI-Prolog. ?- bagof(Q, (Q=A, (A=[a,_] ; A=[_,b])), X). A = [_G16898, b], X = [[_G16898, b]] ; A = [a, _G16892], X = [[a, _G16892]]. Notice that [a,_] and [_,b] are not unified to produce an answer…
A. Zinoviev
  • 101
  • 5
4
votes
3 answers

Prolog Query Duplicates

I've seen a few questions on this topic, however none of them really answers my question properly. I'll write a small example, here are some facts: football(john). football(sam). tennis(john). tennis(pete). netball(sandy). I want to create a rule…
3
votes
1 answer

setof/3 inside setof/3 not working, but why?

Inspired by Find mutual element in different facts in swi-prolog I wanted to try my hand at "RDBMS operations in Prolog" (actually, this is more or less Datalog) Problem statement Given a database of "actors starring in…
David Tonhofer
  • 14,559
  • 5
  • 55
  • 51
1
2 3 4 5