Updated April 5, 2023
Introduction to Prolog predicate
Prolog predicate is the method to contain the argument and return the boolean values such as true or false. It is a function to operate and return given values, variables, or arguments using a prolog programming language. It is a function to operate different operations on the argument and return output in the boolean format. It is contained multiple arguments and defines a relation between them using prolog language. It operates append, reverse, deletes operation on the given data, and shows boolean output such as a yes or no. It is a boolean interface to work on different values using a programming language. It is a built-in function to operate the prolog programming language’s object, argument, and variable.
Syntax of Prolog predicate
The prolog has many predicates to operate multiple arguments as per requirement. The prolog predicate has a name and contains numbers and values.
The basic prolog predicate syntax shows below.
name(value1, value2, value3).
The prolog member predicate syntax shows below.
name(v1, [v1, v2, v3]).
The prolog append predicate syntax shows below.
name([value1, value2, value3], [value4, value5, value6], [value1, value2, value3, value4, value5, value6]).
The basic prolog intersection predicate syntax shows below.
name([value1, value2, value3], [value4, value1, value6], Result).
The basic prolog reverse predicate syntax shows below.
Prolog pl file syntax:
reverse_value([], V, V).
reverse_value([H|Tail], V, Res) :- reverse_value(Tail, V, [H|Res]).
Prolog console syntax:
reverse_value([value1, value2, value3, value 4, value5], A, []).
The prolog predicate syntax shows below.
Prolog pl file syntax:
name (X, Y) :- sub_name (X, Y).
Prolog console syntax:
sub_name(value1, value2).
The built-in prolog predicate syntax shows below.
- Yes: It is represented a true output of the boolean predicates.
- No: It is represented a false output of the boolean predicates.
How does Prolog work in Prolog?
Prolog comment works in the “pl” file. Create a file with the “pl” extension.
Example:
main.pl
Insert data into the prolog file.
Save the object with value into a pl file.
The following commands can use for the prolog predicate.
- The basic prolog predicate shows below.
study(books, notebook).
- The prolog member predicate shows below.
study(eng, [eng, math, sci]).
- The basic prolog append predicate shows below.
appends([1, 2, 3, 8], [4, 5, 6, 7], [1, 2, 3, 4, 5, 6, 7, 8]).
- The basic prolog reverse predicate shows below.
reverse_value([1, 2, 3, 4], V, []).
reverse_value([H|Tail], V, Res) :- reverse_value(Tail, V, [H|Res]).
- The basic prolog predicate shows below.
teacher(adam, sandy).
teacher(X, Y) :- principle(X, Y).
teacher(X, Y) :- student(X, Y).
- The basic prolog intersection predicate shows below.
name([1, 2, 3], [4, 1, 6], Result).
Prolog comment works in the console:
Open prolog console or interpreter. Set the required directory path of the prolog file. Use the given prolog file.
[main].
The basic prolog predicate shows below.
study(books, notebook).
The prolog member predicate shows below.
study(eng, [eng, math, sci]).
The basic prolog append predicate shows below.
appends([1, 2, 3, 8], [4, 5, 6, 7], [1, 2, 3, 4, 5, 6, 7, 8]).
The basic prolog reverse predicate shows below.
reverse_value([], V, []).
reverse_value([H|Tail], V, Res) :- reverse_value(Tail, V, [H|Res]).
The basic prolog predicate shows below.
teacher(adam, sandy).
The basic prolog intersection predicate shows below.
name([1, 2, 3], [4, 1, 6], Result).
Combine the working procedure of the prolog length function:
Use the “main.pl” file.
study(books, notebook).
study(eng, [eng, math, sci]).
teacher(adam, sandy).
teacher(X, Y) :- principle(X, Y).
teacher(X, Y) :- student(X, Y).
name([1, 2, 3], [4, 1, 6], Result).
Use the given prolog console with the required directory path.
[main].
- The basic prolog predicate shows below.
study(books, notebook).
- The prolog member predicate shows below.
study(eng, [eng, math, sci]).
- The basic prolog predicate shows below.
teacher(adam, sandy).
Examples of Prolog predicate
Given below are the examples mentioned:
Example #1
The basic prolog predicate example and the output shows below.
The prolog (pl) file:
study(books, notebook).
Code:
| ?- study(books, notebook).
Output:
This predicate shows true boolean output because of similar arguments.
Code:
| ?- study(boos, ok).
Output:
This predicate shows false boolean output because of different arguments.
Example #2
The basic prolog predicate example and the output shows below.
The prolog (pl) file:
study(eng, [eng, math, sci]).
Code:
| ?- study(eng, [eng, math, sci]).
Output:
This predicate shows true boolean output because of similar arguments.
Code:
| ?- study(engl, [eng, math, sci]).
Output:
This predicate shows false boolean output because of different arguments.
Example #3
The prolog predicate example and the output shown below.
The prolog (pl) file:
teacher(adam, sandy).
teacher(X, Y) :- principle(X, Y).
teacher(X, Y) :- student(X, Y).
Code:
| ?- principle(emma, ram).
Output:
This predicate shows the true boolean output.
Code:
| ?- student(sunny, jack).
Output:
True boolean output.
Example #4
The basic prolog append predicate example and the output shown below.
The prolog (pl) file:
appends([1, 2, 3, 8], [4, 5, 6, 7], [1, 2, 3, 4, 5, 6, 7, 8]).
Code:
| ?- appends([1, 2, 3, 8], [4, 5, 6, 7], [1, 2, 3, 4, 5, 6, 7, 8]).
Output:
Shows the “true: boolean output.
Code:
| ?- appends([1, 2, 3, 8], [4, 5, 6, 7], [1, 2, 3, 4, 5, 6, 7]).
Output:
Shows the “false” boolean output.
Example #5
The basic prolog predicate example and the output is shown below.
The prolog (pl) file and prolog code:
name([1, 2, 3], [4, 1, 6], Result).
Output:
Conclusion
It operates the value of the prolog database and its value. It creates an application user-friendly, advance, and efficient. It helps to maintain the coding arguments and works as per requirement. It makes attractive, elegant, and operative applications. This function works with multiple values and attributes.
Recommended Articles
We hope that this EDUCBA information on “Prolog predicate” was beneficial to you. You can view EDUCBA’s recommended articles for more information.