Is Prolog first order logic?

(Note:  We may earn commissions from products/services you click on.  This is at no extra cost to you.)

Table of Contents

PROLOG has become a reference when it comes to programming language aimed at artificial intelligence and computational linguistics. It is often used for rapid prototyping of programs in research, and there are many full-scale applications that have been put together using PROLOG. In particular, PROLOG has been used to design commercial expert systems in many capacities, including medicine, business, and finance. PROLOG is a programming language used to solve problems related to “”objects”” and “”relations”” between things. Programs can be expressed “”declaratively””. In other languages, it is expressed “”procedurally””. It is based on first-order predicate logic. A PROLOG program consists of the following three elements.

• Declaring some facts about things and their relationships.

• To define rules about things and their relationships.

• Ask questions about things and their relationships.

The logic used in PROLOG is a version of first-order logic, with the use of capital letters inverted (predicates and objects start with a lowercase letter, variables start with an uppercase letter). A PROLOG program consists of a knowledge base where each sentence is a conjunction of predicates connected to a final predicate with an implication. For instance:

           

A sentence like this is called a Horn Clause. In PROLOG, the above sentence would be like this:

pred4(A) :- pred1(A, B), pred2(B, C), pred3(C, D).

Note that the implication sign is inverted, commas are used for conjunction, a period is used to terminate the sentence, and all variables are assumed to be universally quantified.

The first-order logic or the predicate logic allows us to enter into the content of propositions. Statements like “”Juan is the father of Luis”” and “”Luis is the son of Juan”” in propositional logic can only be represented as propositional variables, and it is not possible to represent knowledge as simple as that if x is the father of y then y is the son of x. With the first-order logic, we can represent conceptualizations that contain relations between objects (such as the relations “”parent”” and “”child””). Now, sometimes the conceptualization also expresses relations between relations or properties (relations of degree1) of relations. For example, “”father is a family relationship.”” A logic that only allows representing relationships between objects is called the first order, which allows relations between relations, second-order, and so on.

ou can become a data scientist – click this affiliate link to register for the Data Science Certification Course using R.

Click this affiliate link now to register for Python Certification Training and boost your career to the next level.

Is Prolog first order logic?
programming-583923_1280

Is PROLOG sequential?

PROLOG is a sequential programming language. Sequential PROLOG can be parallelized, and much research is dedicated to effective ways to do this. PROLOG allows only sequential execution and has insufficient working memory space. This inclines the programmers to write deterministic programs (i.e., programs with a cut ratio close to 1). Some programs, however, can be transformed into concurrently executable form by eliminating cuts according to the conversion rule. The converted programs, when executed in OR-parallel, are predictable to offer an OR-relation count equal to or greater than the static OR-relation count. Also, AND parallel execution may offer a higher parallel degree. (Note that the number of solutions to a variable shared among AND-literals is expected to be one.)

PROLOG is a very powerful fifth-generation programming language, particularly in the area of Artificial Intelligence, where it is the absolute leader. It has been used for symbolic computing applications, such as relational databases, understanding of natural languages, project automation, analysis of biochemical structures, and expert systems. As we can see, PROLOG has become a locus when it comes to programming languages meant for artificial intelligence and computational linguistics. PROLOG’s ability to compute procedurally is one of the definite benefits that the language has. As a consequence, this boosts the programmer to consider the declarative meaning of programs relatively independent of their procedural meaning. That is, the benefits of the declarative form of this language are clear (it is easier to think of solutions, and many procedural details are automatically solved by the language itself), and we can take advantage of them.

Click this affiliate link to register for Machine Learning using Python Training and Certification.

What are first-order logic examples?

First-order logic is a method of formalizing natural language into a computable format. In turn, this allows us to treat the problems expressed in language sentences in a formal way. Then from the formalization of natural language, we derive the ability to express and prove theorems, which in turn makes it possible to reason in such disciplines as mathematics, computer science, and philosophy.

The problem of the formalization of natural language is as old as philosophy itself. However, in the field of computer science, it found the foundation when it developed the first system for processing logical expressions in the 1950s. However, the first such system has serious limitations, especially that they can only use propositional logic, not predicate logic.

You can become a data scientist – click this affiliate link to register for the Data Science Certification Course using R.

Propositional logic does not allow reasoning about variables and functions with universal and variable content, which means that its abstract ability is limited. This also means that the first computing system logic solution that cannot be solved located proposition space is the sub-space vector space problem. This problem has been overcome by the development of formal logic systems.

Dive right in and never stop learning!  Click this affiliate link to register for AI and Deep Learning with TensorFlow Certification.

There are also dedicated programming languages for first-order logic. The most famous of these is PROLOG. The acronym represents “”propositional logic”” in a rather confusing way, but its grammar largely corresponds to first-order logic. The feature of PROLOG is that it can quickly build a knowledge base, and it requires almost no training of human analysts to enable them to encode their knowledge.

You can become a data scientist – click this affiliate link to register for the Data Science Certification Course using R.

Is first-order logic a language? 

First-order logic is also called Predicate logic or First-order predicate logic. First-order logic is an influential language that develops information about the objects in a more easy way and can also express the relationship between those objects.

First-order logic is a formal language representation of statements, reports, and logical reasoning. As in a natural language, even in the logic of the first order, the reality is a whole divided into objects (elements) and relationships (connections) between objects. Reality can consist of a closed or an open whole. First-order logic uses its own syntax and semantics to represent reality through objects and relationships. For example, the statement “”every mother is a female parent”” is expressed using the following first-order formula:

∀ x,y mother=y ⇒ female(x) ∧ parent(y,x)

The previous formula can be read in the following way “”for each”” (∀) pair of persons (x, y), in which subject y is the mother of subject x, if this is true, then subject y is female and is the parent of x. First-order logic is used for the representation of knowledge and, more generally, of mathematical logic and propositional logic. A language of first-order logic is characterized by a set of symbols (alphabet), a set of terms (objects) belonging to a given set, and, finally, a set of well-formed formulas (wffs) of sentence syntax and relations and functions.

First-order logic (like natural language) does not only assume that the world contains facts like propositional logic but also assumes the following things in the world:

Objects: A, B, people, numbers, colors, wars, theories, squares, pits, etc.

Relations: It can be unary relation such as: red, round, is adjacent, or n-any relation such as the sister of, brother of, has color, etc.

Function: Father of, best friend, third inning of, end of, etc.

What is logic in PROLOG?

PROLOG is a logic programming language. It has an important role in artificial intelligence. Contrasting many other programming languages, PROLOG is meant mainly as a declarative programming language. In PROLOG, logic is stated as relations (called Facts and Rules). 

Become a Java expert – click this affiliate link to register for Comprehensive Java Course Certification Training. 

Facts: It is something that is happening in the world, characteristic or relationship between objects. In natural language, a fact could be, for example, that Logic and Compatibility is a Computer Engineering subject. They express relationships between objects. Suppose you want to express the fact that “”a car has wheels””. This fact consists of two objects, “”car”” and “”wheels””, and a relationship called “”has””. The way to represent it in PROLOG is: it has (car, wheels).

•Object and relationship names must begin with a lowercase letter.

•The relationship is written first, and then the objects are separated by commas and enclosed in parentheses.

•At the end of a fact, there must be a period (“”.””).

The order of the objects within the relationship is arbitrary, but we must be consistent across the fact base.

Rules: Rules are used in PROLOG to mean that a fact depends on one or more facts. They are the representation of the logical implications of the type p —> q (p implies q).

•A ruler consists of a head and a body, joined by the sign “”: -.””

•The head is made up of a single fact.

•The body can be one or more facts (conjunction of facts), separated by a comma (“, “””), which acts as the logical “”and.””

•Rules end with a period (“”.””).

The head in a PROLOG rule corresponds to the consequence of a logical implication and the body to the antecedent. This fact can lead to misrepresentation. Assume the following logical reasoning: weather (rainy) —-> ground (wet) ground (wet):

That the ground is wet is a sufficient condition for the weather to be rainy, but not necessary. Therefore, from that fact, we cannot deduce by implication that it is raining (they may have watered the streets). The correct representation in PROLOG would be:

ground (wet): – weather (rainy). wet floor).

Note that the rule is “”backward””. This is because of the backward deduction mechanism used by PROLOG. If we made the mistake of representing it as:

weather (rainy): – ground (wet). wet floor).

PROLOG, starting from the fact that the ground is wet, would incorrectly deduce that the weather is rainy. To generalize a relationship between objects by means of a rule, we will use variables. For instance:

Logical representation PROLOG representation is_a_car (X) —-> has (X, wheels)

has (X, wheels): – is_a_car (X).

With this rule, we generalize the fact that any object that is a car will have wheels. As before, the fact that an object has wheels is not a sufficient condition that it is a car. Therefore the inverse representation would be incorrect.

You can become a data scientist – click this affiliate link to register for the Data Science Certification Course using R

PROLOG programming language

PROLOG is a semi-interpreted programming language. Its operation is very similar to Java. The source code is compiled into byte code which is interpreted in a virtual machine called Warren Abstract Machine (commonly called WAM).

Therefore, a PROLOG development environment consists of:

• A compiler: Converts the source code into byte code. Unlike Java, there is no standard on this. For this reason, the byte code generated by one development environment does not have to work in the interpreter of another environment.

Become a Java expert – click this affiliate link to register for Comprehensive Java Course Certification Training. 

• An interpreter: Execute the byte code. A shell or top-level. It is a utility that allows you to test programs, debug them, etc. Its operation is similar to the command-line interfaces of operating systems.

• A library of utilities: These libraries are, in general, very extensive. Many environments include (fortunately) standard-ISO libraries that allow basic functionalities such as manipulating strings, input/output, etc.

Generally, development environments offer extensions to the language such as constrained, concurrent, object-oriented programming, etc. It would be partial not to mention the most popular development environment here: SICStus PROLOG, although it is a commercial (not free) development environment. SICStus, CIAO PROLOG, and possibly others offer integrated environments generally based on Emacs that are very easy to use. CIAO PROLOG also offers a self-documenting similar to the existing one for Java as well as a program preprocessor. Virtually all of them are cross-platform.

When programming in PROLOG, there are two main bodies: the specification of the facts and the questions about those objects or relationships. When you create a database with that specification of facts, you can ask questions about that specification, resulting in yes or no.

PROLOG gets the answer by exploring each one of the facts entered in the database until it finds one that matches, which will be the case in which the answer will be affirmative, or until the entire database is finished, in which case it will give a negative answer. . The factual questions we ask can be more complex using logical operators like AND, OR, and NOT. In this case, PROLOG looks for satisfaction in the first part of the question, and if it is, it looks for it in the second part.

PROLOG examples and solutions

The PROLOG programming language is the most popular logic programming language. Logic programming is a type of declarative programming that allows us to model our problem based on a series of facts and predicates that, applied to user input, allow the interpreter to automatically infer the solution. This is the most important part: in PROLOG, we do not tell the program how to obtain the solution; we only define the facts that we know to be true and the predicates that define the rules of the system. It is the logic engine of the interpreter that, by applying the predicates, will explore the search space that we have created in our model to try to find a solution. Let’sLet’s see some examples:

1. Here are some simple clauses.

likes(mary,food).

likes(mary,wine).

likes(john,wine).

likes(john,mary).

The following queries yield the specified answers.

 | ?- likes(mary,food). 

 yes.

 | ?- likes(john,wine). 

 yes.

 | ?- likes(john,food). 

 no.

How do you add the following facts?

1. John likes anything that Mary likes 

2. John likes anyone who likes wine 

3. John likes anyone who likes themselves 

2. Slightly more complicated family tree.

                              James I

                                 |

                                 |

               

+—————-+—————–+

                | |

             Charles I Elizabeth

                | |

                | |

     +———-+————+ |

     |         

| | |

 Catherine  

Charles II James II Sophia

                                                  

|

                                                  

|

                                                  

|

                                               

George I

Here are the resultant clauses:

——————————-

  male(james1).

  male(charles1).

  male(charles2).

  male(james2).

  male(george1).

  female(catherine).

  female(elizabeth).

  female(sophia).

  parent(charles1, james1).

  parent(elizabeth, james1).

  parent(charles2, charles1).

  parent(catherine, charles1).

  parent(james2, charles1).

  parent(sophia, elizabeth).

  parent(george1, sophia).

Here is how you would formulate the following queries:

     Was George I the parent of Charles I? 

     Query: parent(charles1, george1). 

     Who was Charles I’sI’s parent?

     Query: parent(charles1,X). 

     Who were the children of Charles I?

     Query: parent(X,charles1). 

Now try expressing the following rules:

     M is the mother of X if she is a parent of X and is female 

     F is the father of X if he is a parent of X and is male 

     X is a sibling of Y if they both have the same parent. 

Furthermore, add rules defining:

     “sister”, “brother”, 

     “aunt”, “uncle”, 

     “grandparent”, “cousin” 

SWI PROLOG

SWI-PROLOG is a multipurpose implementation of the PROLOG language. Although SWI-PROLOG expanded its popularity mainly in education, its development is generally driven by the requirements for application development. This is eased by a rich interface to other IT components by supporting many document types and (network) protocols as well as a complete low-level interface to C that is the basis for high-level interfaces to C++, Java (bundled), C#, Python, etc. (externally available). Data type extensions such as dicts and strings, as well as full backing for Unicode and unbounded integers, simplify the smooth exchange of data with other components.

SWI-PROLOG aims at scalability. Its vigorous support for multi-threading exploits multi-core hardware competently and simplifies embedding in concurrent applications. It is Just In Time Indexing (JITI) offers transparent and efficient support for predicates with millions of clauses.

SWI-PROLOG unites many extensions of the core language that have been established in the PROLOG community, such as tabling, constraints, global variables, destructive assignment, delimited continuations, and interactors.

SWI-PROLOG provides a variety of development tools, most of which may be combined at will. The native system provides an editor written in PROLOG that is a close clone of Emacs. It offers semantic highlighting based on real-time analysis of the code by the PROLOG system itself. Complementary tools contain a graphical debugger, profiler, and cross-referencer. Otherwise, there is a mode for GNU-Emacs and, Eclipse plugin called PDT and a VSC plugin, each of which may be combined with the native graphical tools. Lastly, a computational notebook and web-based IDE is provided by SWISH. SWISH is a handy tool that can be organized and extended to suit many different scenarios.

PROLOG predicate example

PROLOG programs are written in units of clauses (horn clauses). That is, clauses correspond to sentences in other programming languages. And a clause is composed of a basic logical expression called a predicate. The clause indicates that a fact clause (or simply called a fact) indicates that a predicate is unconditionally true and that some other predicates must be true as a condition for one predicate to be true. There is a rule clause (rule). Write a period “”.”” at the end of each section.x

Fact: Predicate.

Rule: Predicate 0:-Predicate 1, Predicate 2,…, Predicate n.

Here, the predicates 1 to n are the conditions under which the predicate 0 is true. The comma “”,”” when there are multiple conditions means and (and). In addition, the predicate is generally described as follows.

Predicate name (argument 1, argument 2,…, argument n)

Here, the predicate name is an alphanumeric character starting with lowercase letters and a name given with an underscore “”_””. In addition to constants such as numbers and names, variables are described as arguments. There may be no arguments. If there is no argument, write only the predicate name (without parentheses).

Programming in PROLOG is quite different from programming in a procedural language. In PROLOG, facts and rules for a database are provided, which will later be executed queries on top of the database.

The structure of a fact is formed by a predicate, its arguments (objects), and we end the statement with a period (.) equivalent to the semicolon in common programming languages. See below:

predicate (argument1,argument2…).

The predicate is the relationship over which objects will interact.

Examples:

friend (joana, maria).

We define a friendship relationship between two objects, joana and maria.

man (jose).

Note that when we use only one object, the predicate becomes a feature of the object itself.

So just to conclude, it is important to point out that the names of predicates and objects must always start with a lowercase letter, as you may have noticed in the previous examples. Predicates are written first, followed by objects that are separated by a comma. It is also important to remember that the order of objects can interfere with the result of an application.

Click this affiliate link to register for Machine Learning using Python Training and Certification.

What is PROLOG used for?

PROLOG is a very powerful fifth-generation programming language, especially in the area of Artificial Intelligence, where it is the absolute leader. It has been used for symbolic computing applications, such as relational databases, understanding of natural languages, project automation, analysis of biochemical structures, and expert systems. As we can see, PROLOG has become a reference when it comes to programming language aimed at artificial intelligence and computational linguistics. PROLOG’sPROLOG’s ability to compute procedurally is one of the specific advantages that the language has. As a consequence, this inspires the programmer to consider the declarative meaning of programs relatively independent of their procedural meaning. That is, the benefits of the declarative form of this language are clear (it is easier to think of solutions, and many procedural details are automatically solved by the language itself), and we can take advantage of them.

You can become a data scientist – click this affiliate link to register for the Data Science Certification Course using R

A benefit from the point of view of the user is the ease of programming since programs can be written quickly, with few errors, resulting in clearly readable programs, even if the language is not well understood. Do not think too much about solving the problem, as PROLOG infers its answers based on the rules declared within the program. In PROLOG, each predicate (procedure) can be executed, validated, and examined independently and individually. PROLOG has no global variables, no assignment. Each relationship is self-contained, allowing for greater modularity, portability, and reusability of relationships between programs. 

PROLOG uses a search mechanism independent of the fact base. Although it may seem somewhat twisted, it is a good strategy since it guarantees the process of all possibilities. It is useful for the programmer to know this mechanism when debugging and optimizing programs. It brings dynamic and automatic memory management.

References

https://www.swi-prolog.org/features.html

https://en.wikipedia.org/wiki/First-order_logic

https://cse.sc.edu/~ahein/330/example.html

Click this affiliate link now to register for Python Certification Training and boost your career to the next level.

Luis Gillman
Luis Gillman

Hi, I Am Luis Gillman CA (SA), ACMA
I am a Chartered Accountant (SA) and CIMA (SA) and author of Due Diligence: A strategic and Financial Approach.

The book was published by Lexis Nexis on 2001. In 2010, I wrote the second edition. Much of this website is derived from these two books.

In addition I have published an article entitled the Link Between Due Diligence and Valautions.

Disclaimer: Whilst every effort has been made to ensure that the information published on this website is accurate, the author and owners of this website take no responsibility  for any loss or damage suffered as a result of relience upon the information contained therein.  Furthermore the bulk of the information is derived from information in 2018 and use therefore is at your on risk. In addition you should consult professional advice if required.