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
2
votes
3 answers

Prolog - how to do setof that returns empty list instead of failing

I need an ordered list of Objects that satisfy Goal. setof takes care of the ordering, but fails when no Objects satisfy Goal. I want to return an empty list instead like findall does. This works, but is there a way of accomplishing this without a…
brabec
  • 4,632
  • 8
  • 37
  • 63
2
votes
3 answers

run function with all possibilities resulted from other function

I have two predicates: foo(Y,X) bar(Y,Z) After running foo, How can I run bar with all possibilities of Y ? example: foo(Y, key) % all possibilities of Y => chat % faq % …
user1423470
  • 77
  • 2
  • 6
1
vote
1 answer

How to get the list of all friends of a given person in prolog?

I'm a beginner in Prolog, and I just want to get the list of all friends of a given person. if i have predicates, like: friend(hend, khadija). friend(huda, mariam). friend(huda, aisha). friend(huda, lamia). friend(mariam, hagar). how can i write a…
1
vote
1 answer

How do I combine rules and facts from a PROLOG program into a list?

Im trying to find the list of all release dates of all intel processors. It should look like this [1993, 1976, 1974, 1971] Currently I can only create a list with 1 entry like this setof(Y,released(pentium,Y),S1) which gives me…
1
vote
1 answer

Prolog setOf with Multiple Predicates

In my prolog database, I have below facts: played('Sharon rose', piano). played('Robert Kay', piano). played('Kelvin Cage', drums). singer('Robert Kay'). band_leader('Sharon rose'). I want to print out all the names uniquely as a single list. Below…
niyidrums
  • 13
  • 3
1
vote
1 answer

Prolog understanding setof/3 with ^ markings

Could someone explain to me what this is doing? (\+ setof((P1,C),P^R^Bag,PS) -> ... otherwise ->... I have read the documentation of setof; my understanding is that the thrid argument gets unified with the facts. However, I can't make sense of the…
nz_21
  • 6,140
  • 7
  • 34
  • 80
1
vote
2 answers

Get multiple answers from prolog predicate

Suppose I have a predicate that sometimes gives me multiple outputs. Like this - foo(Number, Out) :- Number < 10, Out = less_than_ten. foo(Number, Out) :- Number > 0, Out = more_than_zero. How might I get hold of all the values for Out that foo…
1
vote
2 answers

How to order a list of tuples in Swi-Prolog

I have a list in swi-prolog like this: [(5,4), (1,4), (3,12), (4,2), (5,4)] I need to have the list organized by the second element of each "tuple", removing any repeated elements, so this list would look like this: [(4,2), (1,4), (5,4),…
Sam
  • 13
  • 3
1
vote
2 answers

Prolog - sum of list members

I have been trying to find the circumference of a country in Prolog. I have the finished predicate borders(Country1, Country2, Length) and setof(Item, Condition, Set) which gives a list of all items into the set which fulfill the condition. To…
kalle konsida
  • 323
  • 2
  • 5
  • 12
1
vote
2 answers

Prolog (Sicstus) - nonmember and setof issues

Given following facts: route(TubeLine, ListOfStations). route(green, [a,b,c,d,e,f]). route(blue, [g,b,c,h,i,j]). ... I am required to find all the pairs of tube Lines that do not have any stations in common, producing the following: | ?-…
qwerty
  • 321
  • 1
  • 5
  • 13
1
vote
1 answer

Prolog (Sicstus) - setof and findall combination issues

Given a set of routes a given station has, such us : route(TubeLine, ListOfStations). route(green, [a,b,c,d,e,f]). route(blue, [g,b,c,h,i,j]). ... I am required to find names of lines that have a specific station in common. The result must be…
qwerty
  • 321
  • 1
  • 5
  • 13
1
vote
0 answers

Prolog - Allowing lists L iff #L > n in setof/3

likes(russel, wittgenstein). likes(whitehead, wittgenstein). likes(godel, wittgenstein). likes(hardy, ramanujan). likes(littlewood, ramanujan). at_least_three_fans :- setof(X, Z^(fact(X, idol), fact(Z, idol)), admirers). I'd like to have print…
1
vote
2 answers

Why is there a difference in the output of setof between facts with a different amount of elements?

In Prolog, given a knowledge base of facts: someFact(one). someFact(two). otherFact(one, two, 123, 456). otherFact(one, four, 789, 123). The query setof(X, someFact(X), List). produces this result: List = [one, two] However, the query setof(X,…
Zimano
  • 1,870
  • 2
  • 23
  • 41
1
vote
1 answer

Find all facts with matching predicates

I have a factbase full of interacts relationships: % Drug, Drug, Interaction…
starscream_disco_party
  • 2,816
  • 5
  • 26
  • 42
1
vote
2 answers

SWI Prolog usage of agregation

I created a simple database on SWI Prolog. My task is to count how long each of departments will work depending on production plan. I am almost finished, but I don't know how to sum my results. As for now I am getting something like this department…