Questions tagged [prolog-findall]

findall/3 is a built-in predicate of ISO Prolog.

66 questions
10
votes
3 answers

findall/3 creates new, unrelated variables in its resulting list

?- permutation([A,B,C],Z). Z = [A, B, C] ; Z = [A, C, B] ; Z = [B, A, C] ; Z = [B, C, A] ; Z = [C, A, B] ; Z = [C, B, A] ; false. Makes sense. I can work on a permutation of [A,B,C] and that permutation contains the same elements as in [A,B,C], so…
Fatalize
  • 3,513
  • 15
  • 25
6
votes
2 answers

Prolog - finding all combinations (The product) of List of Lists (of Lists)

I'v tried a few features to implement a predicate which finds all the combinations, like in that example: List = [[1, 2], [1, 2, 3]] These should be the output, Comb = [[1,1],[1,2],[1,3],[2,1],[2,2],[2,3]] but all the solutions I've found were…
Ilya.K.
  • 291
  • 1
  • 13
5
votes
3 answers

Find all solutions to a predicate

I'm trying to define a predicate that receives a single term with free variables and returns a list of mappings of those variables, so for example if the database is a(0,1). a(1,1). the expected output would be ?- eval(a(X,1),Maps). Maps =…
ailnlv
  • 1,779
  • 1
  • 15
  • 29
5
votes
1 answer

Findall with multiple variables in Prolog

I would like to get a list of solutions from a rule I made in Prolog. However the findall predicate appears to only work with one variable. Can anyone suggest how to get around this apparent limitation? My rule beat(P,M,E) What I want L =…
ReiiYuki
  • 365
  • 5
  • 19
5
votes
1 answer

Prolog findall/3: more than one bag

I'm writing AI for a Fox and Geese type of game. One of my predicates looks like this: moveFox(+PrevState, -NextState, -PegList, +VisitedStates, -NewVisitedStates) It takes a game state and makes a move with a fox. The resulting state is unified…
Johan Nilsson
  • 77
  • 3
  • 8
4
votes
2 answers

Extract Facts as Matrix in Prolog

Suppose we have the following: edge(a, 1, 10). edge(b, 2, 20). edge(c, 3, 30). edge(d, 4, 40). I want to extract a matrix representation (M) of these facts, such that M = [[a,b,c,d],[1,2,3,4],[10,20,30,40]] Here's a no-brainer…
Hugo Sereno Ferreira
  • 8,600
  • 7
  • 46
  • 92
3
votes
1 answer

Prolog findall solutions within time limit

I would like to find all solutions to a goal within some time limit. I mean that I would like to search for solutions for at most the time limit, and return all solutions found, whether the time limit has been reached or not, which is regardless of…
catbow
  • 85
  • 9
3
votes
1 answer

Prolog, read a csv file and make a predicate. findall

I am using SWI-Prolog. I have a csv file where the top row are probes and then each row is a sample: 1007_s_at 1053_at 117_at ... GSM102447.CEL 1 0 0 ... GSM102449.CEL 1 0 0 ... GSM102451.CEL 1 0 0 ... GSM102455.CEL 1 0 …
user27815
  • 4,767
  • 14
  • 28
2
votes
1 answer

How to use and inside findall/3 meta predicate

I would like to write this: paths( Result ) :- findall( B, f(B) , Result ). f( B ) :- f1( B ), f2( B ). in just one line. So basically something like: paths( Result ) :- findall( B, f1(B) AND f2(B), Result ). I don't know how to…
Antiz
  • 1,424
  • 1
  • 13
  • 20
2
votes
2 answers

Unusual behaviour of findall

The following looks very unusual : ?- findall(X, member(X, [1, 2, 3]), X). X = [1, 2, 3]. The trace even more so ?- trace, findall(X, member(X, [1, 2, 3]), X). ^ Call: (11) findall(_100058, member(_100058, [1, 2, 3]), _100058) ? creep ^ Exit:…
rajashekar
  • 3,460
  • 11
  • 27
2
votes
1 answer

How do I write 'findall' in a Prolog code itself?

So, I am very new to Prolog and I have to write a short code about timetable. How can I add the findall function to a code…
newtothis
  • 35
  • 4
2
votes
2 answers

Prolog findall/3 rule convert to recursive rule

score(Movies,Total) :- findall(Money,(member(Movie,Movies),takings(Movie,Money)),Profit), sum_list(Profit,Total) I want to convert this rule using recursion but I am not sure how. Help! Link to the previous question that answers this one :…
2
votes
1 answer

How to return a list of recommendations in Prolog?

For my assignment, I am supposed to list 20 potential pets and then define facts about each of the pets. Then I need to ask the potential pet owner five questions that will help decide which pets would be good recommendations. I am trying to return…
Jordan Ward
  • 91
  • 1
  • 1
  • 7
2
votes
1 answer

Efficient findall() processing?

I have the following structure of "facts". if( conds, score, idx). Then I expect to have thousands of them. The 'conds' is a conditions that will be evaluated as the facts are processed. For every fact that is true I store the score and the index…
sten
  • 7,028
  • 9
  • 41
  • 63
2
votes
1 answer

Translate Haskell to Prolog - finding sublist of sum

I am trying to translate the following Haskell code: -- sublistSums list sum returns a list of the sublists of list that add up to sum sublistSums :: [Int] -> Int -> [[Int]] sublistSums [] 0 = [[]] sublistSums [] _ = [] sublistSums (x:xs) sum =…
1
2 3 4 5