Unification
The concept of unification is a central notion of the Logique predicates as well as other systems of Logique and is undoubtedly what distinguishes more Prolog of the others computer programming languages.
The unification of two terms and consists in finding (when there are some) a third term such as one can pass from to and by instanciant certain variables. is then called a unifying of and . Intuitively, the unification is the fact of allotting a value to certain variables of and and can be looked at as a kind of assignment which could be carried out only once. When one solves a algebraic equation, an unknown factor can have one, several or no solutions, but its value does not change during the operations; it is similar for the unification. In fact one can see the solution of an equation like a particular case of unification. In prolog , this operation is indicated by symbol “=”. The rules of the unification are the following ones:
- a non-instanciée variable X (i.e. not having yet a value) can be unified with another variable (instanciée or not); the two variables then become simply synonyms one of the other and will represent the same thing henceforth;
- a non-instanciée variable X can be unified with a term or an atom and will represent this term or atom henceforth;
- an atom can be only unified with the same atom;
- a term can be unified with another term: if their names are identical, if their numbers of arguments are identical and if each argument of the first term is (recursively) unifiable with the argument corresponding of the second term.
Because of its declaratory nature, the order in a succession of unifications does not play (usually) any part.
Unification and logic of a higher nature
When one reasons in Logique first order, where the variables can be unified only with constants, the things do well : to know if two terms and are unifiables is décidable (grace for example to the algorithm above). Moreover, if they are it, there exists the unifying most general ( most general to unify or mgu in English), i.e. a term such as all the other unifiers of and is derivable by instantiation of variables of .This ideal situation is alas not found in all the logical systems. In particular, if one places in Logique of a higher nature, i.e. one is authorized to use of the variables like symbols of function or predicates, one loses the decidability and the unicity of the unifier when there exists. In the worst case, two terms can even have an infinity of different unifiers all.
Examples of unification in prolog
It will be supposed that all the variables (in Majuscule S) are non-instanciées. With =
- has makes a success of (tautology)
- has and B is unified with the atom “ABC”
- succeeds: the unification is symmetrical
- succeeds: the atoms are identical
- fails: distinct atoms do not unify
- succeeds: has is unified with B
- fails: the terms have different names
- fails: the terms have a number of different arguments
- succeeds: B is unified at the end G ( has )
- succeeds: B is unified at the end G (xyz) and has is unified with the atom “xyz”
- the unification is infinite: has is unified at the end F (F (F (F (F (...)))). According to the logical system that one wishes one can consider that the unification fails or succeeds; the majority of these systems consider that the unification fails.
- fails: because abc=xyz fails
| Random links: | Autheuil-Authouillet | Copa America 1926 | Automobile Grand Prix of Australia 1987 | Oc Eo | County of Monmouth |