Prolog Tutorial 3

Prolog Tutorial 3 - Programming:Prolog Putting it Together...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Programming:Prolog Putting it Together From Wikibooks Programming Prolog This section serves both to combine the knowledge from the previous chapters and to review it. Prolog is first explained in more detail, true to it's basic structure, and then a small program is presented that combines the knowledge from the previous chapters. Contents [ hide ] 1 Prolog 2 The Prolog Compiler 3 An example program 4 Examples 5 Exercises [ edit ] Prolog A prolog program consists of a database of rules. These rules are loaded into the compiler. The user can then run queries on the database. The compiler will try to prove that the query is true. Everything in prolog is described in logic (prolog logic is variant of classic predicate- or first order logic). Starting from the atoms (the smallest bits) these are the most important logical symbols that make up a prolog program or query. constants These consist of one or more lowercase characters, starting with a letter. A constant is not made up of other prolog symbols (it's an atom) and it does not represent anything in the prolog world except itself. A good way to think of atoms is as the objects of the prolog world. They have no meaning attached to them. Examples of valid constants: foo cd_p0345 a dirk
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Variables Variables are containers. They can represent pretty much any prolog structure, from constants to predicates. Variables consist of one or more lower- or uppercase characters, starting with an uppercase letter. It's important to note that variables function differently in Prolog than in most programming languages. You do not assign a value to them and then use them, various values are assigned to them by prolog when you run a query to try and make the query true. Examples of valid variables: B Parent Result PredicateList023 Predicates Predicates consist of a functor(one or more lowercase characters, starting with a letter), possibly followed by a number of terms between brackets, separated by commas. A predicate is either true or false, based on its terms. Examples of valid predicates: childof(Child, Father) predicate(dog(x), cat(Y)) architect(a_vandelay) termless_predicate Functions A function is built up the same way as a predicate, but instead of being false or true, it can represent anything a variable can represent. For instance, the function sqrt(A), will return the square root of whatever number A represents. Atomic Sentences An atomic sentence is the smallest part in a prolog program that can take on the the meaning true or false. All predicates are atomic sentences. Some other prolog statements, such as unification (=) are atomic sentences as well. Examples of atomic sentences: childof(george_w_b, george_b) A = tan(B, C) + D Sentences (and connectives) Sentences are prolog constructions that can take on the meaning true or false. Atomic Sentences are of course sentences. Other sentences (ie. non-atomic ones) are comprised of atomic sentences joined together by
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 9

Prolog Tutorial 3 - Programming:Prolog Putting it Together...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online