This entry is part 2 of 2 in the series Prolog Tutorials
[Hướng dẫn Prolog] Prolog is a commonly used language in the field of artificial intelligence. The logic of programming is based on Horn clauses. This article Nguyen Van Hieu Blog will show you how to use Prolog language: Prolog syntax, variables & data types of Prolog, how to build events and rules in Prolog with examples.
1. Some terms about Prolog
A Prolog program is a database of statements. Each clause is built from predicates. A predicate is a statement about objects that is either true or false. A predicate can have arguments that are logic atoms.
You are viewing: What is Prolog
Each atom (in short) represents a relationship between terms (term). Thus, the rank and the relationship between the terms form the proposition.
Classes are considered “data” objects in a Prolog. A class can be an elementary term consisting of a constant, a variable, and a compound term.
Complex ranks represent complex objects of the problem to be solved in the field under consideration. A complex term is a function containing arguments, of the form:
The function name is a string of letters and/or numbers that begin with a lowercase letter. The arguments can be variables, elementary, or compound classes.
Hot: Executives Who Resort to Fear, Intimidation Can Lose Support at All Levels
For example:
- f(5, a, b).
- student(robert, 1975, info, 2,
- address(6, 'mal juin', 'Caen')).
- [a, b, c]
A proposition can be a fact, a rule (or rule), or a question. Prolog convention writes after each clause a period to end as follows:
- Event : < … >. (corresponds to the law < … > :- true. )
- Rule: < … > :- < … >.
- Question ?- < … >. (in interactive mode with command prompt)
2. Law making
Law example:
We have defined the unary relations woman and man because they relate only to a single object. The parent relationship is binary, because it involves a pair of objects. Thus, simple relations are used to establish a property of an object. Clause :
is explained : Mary is female. However, we can also use binary relations to define gender:
Now we introduce a new relation child, as opposed to parent, as follows:
See more: 100% genuine Jindian imported high-grade solar lights
From there, we define the new rule as follows:
The above law is understood as: For all X and Y, Y is a child of X if X is the father (or mother) of Y.
Or: For all X and Y, if X is the parent (or parent) of Y, then Y is a child of X.
3. Example programming language consulting program
Below is the Prolog program from the same programming language. You copy it and save it as a file with the extension ".pl". Then use Prolog to run the instructions below. You can refer to the following program to better understand the Prolog language.
Attention: If you do not have Prolog installed, read the article How to connect Prolog with C# on Visual Studio. In this article, there will be instructions on how to install Prolog and have an expert system program to choose a programming language using Winform C#.
To run this Prolog file. You do it in the following order:
- Open Prolog, go to File -> Consult menu, then select this Prolog file.
- After the Consult is done. Type go. to test the program
See also: What is propane gas? Who can use propane and for what purpose?
4. Prolog . Documentation
- Logic programming course in Prolog
- How to connect Prolog to C# on Visual Studio
Post a Comment
Post a Comment