Home  >  Article  >  What are the three basic statements of prolog language?

What are the three basic statements of prolog language?

藏色散人
藏色散人Original
2021-02-01 09:42:486019browse

The three basic statements of the prolog language are facts, rules and queries, and correspond to the headed and headless HORN clauses; therefore, programming in the PROLOG language can be reduced to declaring facts and defining rules and make inquiries.

What are the three basic statements of prolog language?

The operating environment of this article: Windows 7 system, Dell G3 computer.

Prolog (abbreviation for Programming in Logic) is a logic programming language. It is based on the theoretical basis of logic and was initially used in research fields such as natural language.

Introduction to Prolog

A logic programming language. In 1972, in order to improve the execution efficiency of the reduction method, the French Comolaue group developed a program executor for the theorem proving program, named PROLOG (Programming In Logic), marking the birth of the first logic programming language PROLOG. In 1974 and later, R. Kowalski further clarified the theoretical basis of PROLOG from the perspective of the HORN clause of predicate logic, and systematically proposed the idea of ​​logic programming.

There are three types of basic statements in the PROLOG language, which represent facts, rules and inquiries respectively, and correspond to the headed (without body, body) and headless HORN clauses. For example:

What are the three basic statements of prolog language?

So programming in the PROLOG language can be boiled down to declaring facts, defining rules and asking questions.

The interpretation and execution process of the PROLOG program uses specific input reduction, that is, starting from the target statement, the reduction formula of it and a clause of the original clause set is found (the tail and the head match), and the new clause is then Find the reduction formula with a clause of the original clause set, and so on. At no time is the reduction found between two derived clauses or two clauses of the original set of clauses. In the above example,

⑥: -human(u), greek(u) (the reduction of ④ and ⑤, mgu=u/x)

⑦: -greek(socarates) (② And the reduction formula of ⑥, mgu=socarates/u)

⑧:-(The reduction formula of ③ and ⑦, get an empty clause)

The answer to the question is u=socarates. It can be seen that the PROLOG explanation system is actually a theorem proving program or problem solving program based on the principle of reduction.

Low spatiotemporal efficiency is an important issue affecting the application of PROLOG language. The ways to improve efficiency are: improving the PROLOG interpretation system, adopting the PROLOG compilation system, developing the PROLOG machine, introducing meta-rules for control, and using heuristics Search mode enables intelligent backtracking, adopts collaborative and concurrent solving technology, and develops parallel processing mechanisms.

Because the PROLOG interpreter can automatically seek solutions to problems based on inference rules, program designers can focus on revealing the logical relationships between objects without having to think too much about the details of the process. This is to A step forward in the direction of automatic programming. But the PROLOG language also has some non-logical features. For example, in order to control backtracking, we use CUT technology (cut-off technology, which means programmers use the CUT symbol to notify the system that it no longer considers useless search paths that have been carried out in the past and does not need to record backtracking points), and introduces the predicate assert (in the database add clause) ret ract (delete clause from database). This causes the axiom set of the system to change during the reasoning process, which is inconsistent with the basic ideas of same-order logic. Therefore, PROLOG is not a logic programming language in the strict sense. In order to make it more logical, the non-logical components of language need to be restricted to a minimum, and research in this area is ongoing.

Recommended: "Programming Video"

The above is the detailed content of What are the three basic statements of prolog language?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn