Syntax and Meaning of Prolog Programs

  • Chapter Objectives:

    • Prolog syntax and semantics
    • Simple data objects (atoms, numbers and variables)
    • Structured objects
    • Matching as the fundamental operation on objects
    • Declarative meaning of a program
    • Procedural meaning of a program
    • Relation between declarative and procedural meaning of a program
    • Altering the procedural meaning by reordering clauses and goals

    (Section 2.1) Data Objects

  • The Prolog system recognizes the type of an object in the program by its syntactic from
  • Objects types in Prolog:

  • Variables start with upper-case letters and atoms start with lower-case

(Section 2.1.1) Atoms and Numbers

  • If we want to define a variable with upper-case we can write it between quotes ‘Var’
  • Integer range: -16383 à 16383
  • Reason of not including real numbers (widely) in Prolog:

    • To make the program neat
    • The numerical error

(Section 2.1.2) Variables

  • They could start with uppercase letter or _ character
  • Anonymous variable is used is cases like this:

    • Haschild(X) :- parent(X, Y) à haschild :- parent(X, _)
  • The lexical scope of variable name is one clause, but not in constants

(Section 2.1.3) Structures (Structured objects)

  • Structures are objects that have several components the components could be structures
  • date(day, month, year):

    • Here date is called functor
    • And day, month and year are called structure argument
  • All Prolog objects are terms
  • All structured objects can be pictured as trees
  • In composite structures the root is called principle functor of the term
  • The functions is defined by the following:

    • Name, as atom
    • Arity, number of arguments

(Section 2.2) Matching

  • Rules to decide whether two terms S and T match:

    • If S and T are constants the match if they have the same value
    • If S is variable and T is anything they match, then S is instantiated to T
    • If S and T are structure, they match if:

      • S and T have the same principle functor
      • All their corresponding components

(Section 2.3) Declarative meaning of Prolog programs

  • The declarative meaning of programs determines whether a given goal is true, and in which variables
  • Instance of clause C means that the clause C with each of its variables substituted by term
  • Variant of clause C is such instance of C where each variable is substituted by variable
  • A goal G is true if and only if:

    • There is a clause C in the program such that
    • C has instance I, that satisfies:

      • Head of I is identical to G
      • All the goals in the body of I are true

(Section 2.4 Procedural Meaning)

  • To make the program faster order the goal conditions in order to be the mostly true then the false

(Section 2.6) Order of Clauses and Goals

  • P :- p, infinite loop
  • Matching in Prolog corresponds to what is called unification in logic

(Section 2.7) Remarks on Relations between Prolog and Logic

The best way to describe Prolog programs theoretically is in math logic

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s