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
1
vote
1 answer

Prolog : Ordering a list alphabetically

I have the following problem, i'm supposed to order a List containing only Strings in alphabetical order using only 'bagof', 'findall', 'setoff' , i am not suposed to use any sort of sorting algorithm. Here is the content of the .pl document i have…
eXistanCe
  • 735
  • 1
  • 9
  • 25
1
vote
1 answer

Prolog, finding largest value from a setOf list

I have a predicate which purpose is to print out which country that has the biggest area(one with biggest border = biggest area). This is how my predicate looks like: /* If I write get_country(X, 'Europe'). then all the countries in Europe that…
Fjodor
  • 529
  • 1
  • 7
  • 19
1
vote
1 answer

How do you get only one output from a swi-prolog query?

How do I get only one output from a SWI-Prolog query? I have tried using cut (!) but it does not seem to work. For example: I already filled my knowledge base up with statements and I wanted to find any one name who is both female and is the mother…
user3369494
  • 123
  • 11
1
vote
3 answers

Prolog: How to eliminate redundant answers?

I have the map of Romania from the Russell and Norvig book about artificial intelligence. I created links between the cities like this: link(oradea, zerind, 71). link(oradea, sibiu, 151). link(zerind, arad, 75). link(arad, sibiu, 140). link(arad,…
1
vote
2 answers

Use of setof/3 with recursive call in GOAL gets wrong, why?

I have problems using setof/3, some results are missing. The context: I load a xml-file using SWI-Prolog load_xml() to get a recursive list element (see testelement in the example). Then I want to look up specific elements in this list (in the xml…
kiw
  • 155
  • 6
1
vote
2 answers

Correct use of findall/3, especially the last result argument

I'm a beginner in Prolog and I am dealing with a problem that might seem stupid to you, but I really can't understand what I'm doing wrong! Ok, I have this file fruits.pl and inside that I have something like…
elli
  • 1,109
  • 1
  • 13
  • 20
1
vote
2 answers

Prolog how to prevent repetitive answers

For my program the Knowledge Base has atomic statements and rules such as store(itemName, ProductType) ex: store(iPhone5, phone) manufacturer(itemName, Company) ex: manufacturer(iPhone5, apple) query is to find out if there is a company that…
emanyalpsid
  • 329
  • 1
  • 5
  • 19
1
vote
1 answer

How to remove repetitions using retract in this particular situation?

%Examples: %days([saturday,sunday,monday,tuesday,wednesday,thursday]). %slots([1,2,3,4,5]). %course_meetings(csen402,tutorial,t07,nehal,'tutorial for t07'). %course_meetings(comm401,lecture,all_group_4,dr_amr_talaat,'lecture…
M.K
  • 179
  • 1
  • 2
  • 10
0
votes
1 answer

Prolog rule can condition to be before a date, but not after a date, why?

I have the following rules looking for facts in a database with certain dates: preceding(ID,Date,Category,Preceding) :- setof([ID,D,Category,Amount], row(ID,D,Category,Amount), Preceding), D @< Date. after(ID,After,Category,Rows) :- …
Stas
  • 305
  • 3
  • 8
0
votes
1 answer

Setof: Is there a way for early stopping?

I want to find the minimun number of errors for a lot of schedules. I produce a schedule, take it's errors, store all Errors in a list and take the first element(MinError). The MinError is >=0, so I wonder if I can stop this process when a random…
0
votes
2 answers

Max Occurrences in a List

I'm trying to write a Prolog function that given a list returns the element(s) that repeats most times in that list, like: ['a', 'a', 'b', 'c', 'b'] should return ['a', 'b'] ['c', 'a', 'a', 'c', 'b', 'c', 'b'] should return ['c'] etc... I'm trying…
Tiago
  • 21
  • 3
0
votes
2 answers

Usage of distinct still leading to duplicates

I'm new to prolog, and as I understand it, the purpose of 'distinct' is to weed out duplicates. However, this code block: allpartsincity(City):- distinct((proj(Project, _, City), sppj(_, Part, Project, _), part(Part, _, _, _, _))), …
vio
  • 1
0
votes
2 answers

Is there a way of obtaining itemsets from transactions efficiently witho prolog?

I am sorry to ask this question, but it has been a lot since I programmed in Prolog. I think I am used to imperative paradigm. :-( I am trying to obtain itemsets from a Prolog relation: % transaction(Time, Client, Item) transaction(1, 2,…
0
votes
1 answer

the first query and duplicating elements in a list in Prolog

I am new to Prolog. I wrote the basic code below. flight(acompany, paris, 7). flight(bcompany,paris,7). flight(ccompany,paris,7). flight(dcompany,paris,7). search([X],Y,Z) :- flight(X,Y,Z). search([X|T],Y,Z) :- search(T,Y,Z) , flight(X,Y,Z). I…
stedkka
  • 345
  • 2
  • 4
  • 14
0
votes
0 answers

Prolog scheduling without pressing ';' every time

I have the following file with the predicate attends which symbolizes that every student attends a certain course (the first argument : Student_ID, the second argument : Course_ID). attends(476, c216). attends(478, c216). attends(484,…
DIMITRIOS
  • 305
  • 1
  • 3
  • 10