In general, AI language should have the following characteristics:
1, with symbolic processing capacity (that is, non-numerical processing capacity);
2, suitable for structured programming, easy to program;
3, with recursive function and backtracking function;
4, has the human-computer interaction ability;
5, suitable for reasoning;
6, both the process and the description of the data structure of the ability to mix, but also to identify and determine the control of the pattern matching mechanism.
The difference between AI language solutions and traditional methods:
The traditional method is usually to put all the problems only in the various models expressed in the fixed program, the problem of the solution under the guidance of a fully-implemented step by step (one-by-part) execution. The solution is in accord with the von Neumann-type computer structure.
As for the problem of artificial intelligence, it is often impossible to fix all the knowledge in the program, usually to establish a knowledge base (including facts and inference rules), and the program decides its actions according to the environment and the input information given and the problems to be solved. So it is the reasoning process under the guidance of the environmental model. This approach has great flexibility, conversational ability, self-explanatory ability and learning ability. This method is better than the traditional method to solve some conditions and goals of the non-clear or incomplete unstructured problem, it usually uses heuristic, heuristics strategy to solve the problem.
Second, Prolog language and its basic structure
Although there are many versions of the Prolog language, their core parts are the same. There are only three basic statements for Prolog: facts , rules , and targets three types of statements, all of which are represented by predicates.
Prolog is a declarative language, and once the necessary facts and rules have been submitted to it, Prolog can use the internal deductive inference mechanism to automatically solve a given goal of the program. Not enough to list the detailed solution steps in the program.
①, Facts (facts)
The fact is the simplest predicate in Prolog, which is very similar to a record in a database. Facts are used to illustrate the known objects in a problem and the relationships between them.
The fact syntax structure is as follows:
Pred (ARG1,ARG2...ARGN).
Where pred is the predicate name, Arg1 is a parameter, total N, '. ' Is the Terminator of all Prolog clauses.
The predicate with no arguments is as follows: Pred.
The parameters can be one of the following four scenarios:
1, Number (integer) 2, Atom (atom, that is, a string beginning with a lowercase letter) 3, variable (variable, beginning of capital letter, or _) 4, structure (structure)
Atomic:
A, identifier atom: A lowercase alphanumeric string that starts with a lowercase letter or a lowercase letter. Purpose: Used to flag the name and predicate of an object or function name.
B, String atom: A string enclosed in quotation marks
C, special atoms, some special symbols.
Constants are composed of numbers or atoms.
Variable:
Represents an object that is temporarily unavailable or does not need to be named. Start with capital letters
The special variable "_" is an empty variable that indicates that we do not care about the value of one of the variables of the problem.
② Rules:
A rule consists of several simple sentences (predicates) that depend on each other. Used to describe the dependency between facts.
The form is as follows: The rule consists of the left-hand representation of the subsequent predicate of the conclusion and the precondition predicate for the right to represent the condition
Example: Bird (x):-animal (x), has (x,feature)
P:-P 1,p2,p3,p4 .... Pn.
:-Implies a personal understanding in the logic of sufficient conditions to read the implication, from the previous pieces can be introduced.
, which means that the judgment statement is true when all conditions are true.
Meaning: If P1 .... When Pn is true, p is true.
HORN clause: p1^p2^p3^p4^ .... Pn--> P
③ problem (target)
After you write the facts and rules into the Prolog program, you can ask Prolog questions about the answers, and ask questions about the program's operational goals.
The structure of the target can be the same as the fact or the rule, so that a simple predicate can also make a combination of multiple predicates. Target inside and outside, internal target is written in the program, the external target is entered manually by the user when the program is running.
Example:? -Student (John)
?-for Prolog software prompt, student (John) is the problem (target)
A piece of code (written by Swi-prolog)
test.pl file
Love (Zhangxueyou,wangfei), Love (Zhangxueyou,zhouhuimin), Love (Wangfei,xietingfeng), Love (zhouhuimin,zhangxueyou). Love (Xietingfeng,wangfei)-Love (Xietingfeng,zhouhuimin). Love (Liudehua,zhouhuimin). Loves (x, y):-love (x, y), Love (y,x). % lover Rival_in_love (x, y):-love (X,z), Not (Love (z,x)), Love (Z,y). % rival
/* * * Multi-line Comment
% single-line comment
Double-click test.pl file, program initial state
“ ? -"for prompt
Enter some questions (target) to see the results of the program running
Note: As with the rule, "." is added to the problem, and ";" is entered manually, indicating that the query continues. Until false occurs.
Features of Prolog:
1. The Prolog program does not have a specific sequence of operations, and its running sequence is determined by the computer rather than by the person who programmed it.
2. Prolog no Process Control statements such as if Case else
3, prolog program and data highly unified
4, Prolog is actually a smart database
5, powerful recursive function.
Reference from: http://blog.csdn.net/mwsong/article/category/331639
I. INTRODUCTION of Prolog