The permutation/2 predicate is used to generate permutations of a given list.
permutation(List, PermutedList):Listis the input list, andPermutedListis the list of all possible permutations ofList.
Generate all possible permutations of a list.
?- permutation([a, b, c], Permutations).The append/3 predicate is used to concatenate two lists.
append(List1, List2, Result):List1andList2are the input lists to be concatenated, andResultis the concatenated list.
Concatenate two lists into one.
?- append([1, 2], [3, 4], ConcatenatedList).The bagof/3 predicate is used to gather solutions to a query and store them in a bag (list).
bagof(Variables, Condition, Bag):Variablesare the variables to be collected,Conditionis the query condition, andBagis the list that contains the collected solutions.
Gather all solutions to a query into a list.
?- bagof(Score, student_score(Student, Score), Scores).The delete/3 predicate is used to remove elements from a list.
delete(Element, List, Result):Elementis the element to be removed,Listis the input list, andResultis the resulting list after removal.
Remove all occurrences of an element from a list.
?- delete(apple, [apple, banana, apple, orange], Result).The findall/3 predicate is used to find all solutions to a query and collect them into a list.
findall(Variables, Condition, List):Variablesare the variables to be collected,Conditionis the query condition, andListis the list that contains all collected solutions.
Find all instances satisfying a condition and collect them into a list.
?- findall(Fruit, likes(_, Fruit), LikedFruits).The nth0/3 predicate is used to find the element at a specific index in a list.
nth0(Index, List, Element):Indexis the index of the desired element,Listis the input list, andElementis the element at the specified index.
Retrieve the element at a specific index in a list.
?- nth0(2, [apple, banana, orange], Element).The member/2 predicate is used to check if an element belongs to a list.
member(Element, List):Elementis the element to be checked, andListis the input list.
Check if an element exists in a list.
?- member(apple, [apple, banana, orange]).The sumlist/2 predicate is used to compute the sum of all elements in a list.
sumlist(List, Sum):Listis the input list, andSumis the sum of all elements in the list.
Compute the sum of all elements in a list.
?- sumlist([1, 2, 3, 4], Sum).The sort/2 predicate is used to sort a list in ascending order.
sort(List, SortedList):Listis the input list, andSortedListis the sorted version of the list.
Sort a list in ascending order.
?- sort([3, 1, 4, 1, 5, 9, 2, 6], SortedList).The length/2 predicate is used to determine the length of a list.
length(List, Length):Listis the input list, andLengthis the length of the list.
Determine the length of a list.
?- length([a, b, c, d, e], Length).This README provides a comprehensive overview of the predefined predicates in Prolog, along with their explanations, parameters, use cases, and implementation examples.