Prolog - Organization of Programming Languages - Lecture Notes, Study notes of Programming Languages

This course is an introduction to concepts in programming languages. The course covers a range of programming paradigms including procedural, functional, and logic-based languages. This lecture includes: Prolog Intro, Haskell Pattern Matching, Haskell Guards, Haskell User-Defined Data Types, Haskell Higher-Order Functions

Typology: Study notes

2012/2013

Uploaded on 09/28/2013

noob
noob 🇮🇳

4.4

(25)

105 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Lecture Notes CPSC 326 (Spring 2013)
Today ...
Prolog Review
Assignments
HW 7, Reading 8, Project 1
Logic Refresher. Draw truth tables for:
PAND Q(PQ)
POR Q(PQ)
NOT P(¬P)
PQ(¬PQ)
PQ(PQQP)
What do the following mean?
x(Person(x)) ...everything is a person
x(Person(x)) ...there’s at least one person
xy(Person(x)Mother(y, x)) ...everyone has a mother
xy(Person(y)Mother(x, y)) ...someone’s the mother of everyone
xy(Person(x)Mother(x, y)) ...at least one person is a mother
xy(Person(x)Mother(x, y)) ...everbody’s the mother of everbody
Make each of these true for the domain {Alice,Bob}
S. Bowers 1 of 4
pf3
pf4

Partial preview of the text

Download Prolog - Organization of Programming Languages - Lecture Notes and more Study notes Programming Languages in PDF only on Docsity!

Today ...

  • Prolog Review Assignments
  • HW 7, Reading 8, Project 1

Logic Refresher. Draw truth tables for:

  • P AND Q (P ∧ Q)
  • P OR Q (P ∨ Q)
  • NOT P (¬P )
  • P → Q (¬P ∨ Q)
  • P ≡ Q (P → Q ∧ Q → P )

What do the following mean?

  • ∀x (Person(x)) ...everything is a person
  • ∃x (Person(x)) ...there’s at least one person
  • ∀x∃y (Person(x) → Mother(y, x)) ...everyone has a mother
  • ∃x∀y (Person(y) → Mother(x, y)) ...someone’s the mother of everyone
  • ∃x∃y (Person(x) ∧ Mother(x, y)) ...at least one person is a mother
  • ∀x∀y (Person(x) ∧ Mother(x, y)) ...everbody’s the mother of everbody

Make each of these true for the domain {Alice, Bob}

Prolog syntax (review)

Prolog programs are built from “terms” A term is either:

  • a constant
  • a variable
  • or a structure a constant is either:
  • a number (int or float)
  • an atom (everything else)
  • letters, digits, and underscores ( )
  • single quotes (double quotes a list of chars)
  • some symbols (like +)
  • true and false atoms are special A variable:
  • begins with an uppercase character or an underscore
  • can contain letters, digits, underscores ...

Onto Prolog Programming Semantics Consider the following rule: p(X,Z) :- q(X,Y), r(Y,Z).

Two ways to “view” (conceptualize) a prolog program:

  • “Bottom-up” view:
    • read rules from right to left (from current facts to derived facts)
    • “if X is q-related to Y and Y is q-related to Z, then X is p-related to Z”
    • this is the “database” perspective (like in SQL): always deriving newfacts from previous ones
  • “Top-down” view:
    • read rules from left to right
    • e.g., “given X, compute Z by computing Y from X via q, and thencomputing Z from Y via R”
    • the more standard prolog perspective (think function definitions in Haskell) Prolog is a full-fledged programming language
  • arithmetic operations, I/O, etc.
  • sequencing through conjunction (in above example do r(Y,Z)) q(X,Y) followed by
  • if-then through rules
  • looping through recursion
  • plus explicit support for lists