Title: Syntax, Semantics and Intended Meaning The 1-slide course
1Syntax, Semantics and Intended MeaningThe
1-slide course
- Syntax
- Symbols a set of rules for their valid
composition into aggregate structures - Semantics
- The relationship between syntactic structures of
a symbol system and what they are intended to
denote -- their intended meaning - Intended Meaning
- A set of truths, T, about some world
- Source is external to the symbol system
- Represented in the symbol system by syntactic
structures (S1,Sn) - The system is good/useful/fruitful/meaningful
if - All truths in T may be represented by some Si
(complete) - Every Si entailed by the system represents some
truth in T (sound)
2LP Syntactic Structures
- Terms
- Constant, Variable, Functor, Term, Compound Term
- Instances
- Substitution, Instance
- Facts and Queries
- Facts and the rule of instantiation
- Queries and the rule of generalization
- Rules and Logic Programs
- Rules, Unification, Logic Programs
3TermThe single data structure
- Constant
- letter, number, string of letters or numbers
beginning with a lower case letter. - Intended to represent entities, individuals,
existent etc. dog, cat, alfred, r2d2, selmer,
the number 2. - Variable
- Capital letter, or string of letters or numbers
beginning with a capital letter - Intended to represent an yet to be
identified/deduced constant. - Operationally Write Once, Ready Many. Once
found truth can not be unfound. - Compound term
- Functor(A1,,An)
- Functor is any constant
- Ai is a term.
- Intended to represent relations or predicates
about things father(selmer,r2d2).
4SubstitutionA formal definition
- A finite set of pairs of the form xi tj, where
- xi is a variable
- ti is a term
- xi lt gt xj for every i lt gt j
- variables are bound only once in the substitution
- xi does not occur in tj, for any i and j.
- no recursive references in a binding
- Substitutions can be applied to terms
- foo(X,Y) Xselmer,Yr2d2 ? foo(selmer, r2d2).
5InstancesA relationship between terms
- One term may be an instance of another term.
- A is an instance of B if
- There exists a substitution q such that ABq
- Think of a substitution as a set of variable
bindings - Examples
- 1 is an instance of X.
- The substitution is X1
- foo(bar,1) is an instance of foo(V,1)
- the substitution is VBar
- father(big_Tony,franky_three_shots) is an
instance of father(X,Y) - What is the substitution?
- A ground instance is an instance with NO
variables - foo(V,Y)Vbar) foo(bar,Y) is NOT ground.
- foo(V,Y)Vbar, Y1) foo(bar,1) is ground.
6Queries
- A compound term preceded by -
- - functor(t1,,tn)
- Variables are existentially quantified
- Example
- LP - father(big_Tony,X)
- FOL ?x father(big_Tony, x)
- English
- Is Big Tony anyone's father?
- Does there exist a thing, X, such that Big Tony
is the father of X?
7Rule of Generalization
- An existential query P is a logical consequent of
an instance of P, Pq, for any substitution q. - Example
- - father(big_Tony, X) is a logical consequent of
- father(big_Tony, two_Ton_Tommy)
- Different ways of saying the same thing
- ?X p(X) is true if p(anything here) is true.
- The existential generalization is true if an
instance of it is true.
8A Fact
- Compound Term
- Functor(t1,,tn)
- Variables are universally quantified
- father(big_Tony, X) means
- English big Tony is everyones father
- FOL ?(X) father(big_Tony,X)
9Rule of Instantiation
- From a universally quantified statement P (i.e.,
a fact) deduce an instance of it, Pq, for any
substitution q. - From father(big_Tony,X) deduce
- father(big_Tony, two_Ton_Tommy),
- father(big_Tony, selmer),
- father(big_Tony, franky_Three_shots),
- father(big_Tony, r2d2)
10A Rule
- Complex query composed of simpler queries
- Has a head (a term) and a body (a sequence of
terms) - H ? B1,,Bn
- A fact is a rule where n0
- Example
- LP grandmother(X,Z) ? mother(X,Y), mother(Y,Z).
- FOL ?(X,Y,Z) mother(X,Y) mother(Y,Z) ?
grandmother(X,Z) - English A person who is the mother of another
person who is herself the mother of a third
person is the grandmother of the third person - Which representation do you prefer?
11Rule of Universal Modus Ponens
- From
- A ? B1,,Bn ? (B1,,Bn)
- where for all i between 1 and n, Bi is an
instance of Bi - A is an instance of A
- Deduce
- A
- From
- grandfather(X,Z) ? father(X,Y), father(Y,Z)
- father(big_Tony, little_Tony), father(little_Tony,
tiny_Tony) - Deduce
- grandfather(big_Tony, tiny_Tony)
12A Logic Program
- A logic program is a finite set of rules.
- Example Logic Program The Family Tree
- father(big_Tony, little_Tony).
- father(little_Tony, tiny_Tony).
- boss(quick_Nick, franky_three_shots).
- boss(buddy_the_button, mikey_the_mop).
- boss(big_tony,Y) ? boss(Y,Z).
- grandfather(X,Z) ? father(X,Y), father(Y,Z).
- Example Queries
- - boss(big_Tony, quick_Nick)
- yes
- - boss(big_Tony, r2d2)
- no.why? Whats the intended meaning of the
boss(big_tony_Y) rule above?
Facts are rules where the body is empty.
Rules with bodies
13More on Semantics
- Declarative and Operational
14Declarative SemanticsWhat it means is what it is.
- How a the syntactic structure of a program
relates to its intended meaning - The meaning of a logic program is the set of all
the statements it entails - The meaning of a logic program P is the minimal
model for P
- where the minimal model for P is the intersection
of all models of P, - where a model of P is an interpretation, I, for P
where, for every ground instance of a clause A ?
B in P, A is in I if B is in I - where an interpretation is a subset of the
Herbrand Base - where the Herbrand Base is the set of all ground
goals that can be formed (syntactically) form the
predicates in P and the terms in the Herbrand
Universe - where the Herbrand Universe is the set of all
ground terms that can be formed from the
constants and function symbols appearing in P.
15Operational SemanticsWhat it means is what a
procedure produces.
- The meaning of a logic program, P, is the set of
ground goals that are instances of queries
produced by P according to a LP computation. - A computation of a program P is a procedure.
- The procedure starts with a query G, progresses
via goal reduction and it either succeeds, fails
or never terminates. - If it succeeds then the instance of G produced is
in the meaning of P. - If it fails then no instance of G is in the
meaning of P. - If it never terminates, then we dont know if any
instance of G is in the meaning of P. - How does goal reduction produces statements
(i.e., answers)? - How it works is the operational semantics of
logic programming. - The meaning is the output of the procedure. The
operational semantics is a formal description of
the procedure for producing the output from the
input.
16Classic Programming Languages
- What are the declarative semantics?
- Scott-Strachey approach to programming language
theory - Denotational Semantics (book by Joseph Stoy)
- Lambda Calculus (dates back to Lisp in the
1950s) - Concept Given a program, P and the environment,
E (contents of the registers of the machine or of
variable/value bindings), there is a formal
theory for logically deducing the next
environment -- the environment that is entailed
by P E. - What are the operational semantics?
- How the compiler processes the program to
determine the assignment of variables to values.
17Goal Reduction
- The computational core of LP
18Elements of Goal Reduction
- Unification Pattern Matching
- Resolution Inference
- Chronological Backtracking Search
19Unification
- A constructive pattern matching procedure
- Determines the most general unifier (MGU) of two
terms. - Using the MGU constructs the most general common
instance of two terms - Used to compute the resolution inference
- Resolution is used to iteratively reduce a goal
generating its proof from the program if possible
(i.e., goal reduction)
20Most General Unifier(MGU)
- A common instance of A and B is an instance of
both A and B. - foo(1,2) is a common instance of foo(1,Y) and of
foo(X,2) - A unifier of two terms is a substitution that
renders the terms identical - X1,Y2 applied to foo(1,Y) and to foo(X,2)
produces identical terms - The MGU of two terms is a unifier that produces
the most general common instance of the two
terms. - Which are instances of both foo(X,Y), foo(1,Y)?
What is the MGU? - bar(1, 2)
- foo(A, 1)
- foo(A, B)
- foo(1, 2)
- foo(1, B)
None, None XA, Y1, None XA, YB,
None X1,Y2, Y2 X1,YB, YB
21Unification Procedure
- Computes the MGU of two terms if it exists else
fails. - unify(X,1) X,1
- unify(a(X,1), a(1,Y)) X1, Y1)
- Produces the most general common instance
- If two terms unify it is NOT necessarily the case
that one is an instance of the other - a(X,1) is not an instance of a(1,Y)
- a(1,Y) is not an instance of a(X,1)
22Unification Examples
- Fact Schema Supports(Video_Card, Display_Type,
Number_of_Colors) - Example 1 Neither A nor B entails the other
- Facts (A and B) supports(V,b14,C),
supports(nvidia,D,256) - MCI supports(nvidia, b14, 256)
- MGU Vnvidia, Db14, C256)
- Example 2 B is an instance of A
- Facts (A and B) supports(V,b14,C),
supports(rage,b14,16) - MCI supports(rage, b14, 16)
- MGU Vrage, C16
- Example 3 A and B are not unifiable
- Facts (A and B) supports(V,b14,16),
supports(nvidia,D,256) - MCI None
- MGU None
23Resolution
- Enables a reduction of two rules into one
- Eliminates a common term from the consequent of
one rule and from the antecedent of another - Efficient application depends on the constructive
unification procedure - General Form
- Rule 1 A ? (B M)
- Rule 2 (C N) ? D
- Resolution Inference (A C)q ? (B D) q
- where q is the MGU of M and N.
24Resolution Example
- Rule 1
- affinity(Y,Z) - likes(Y,Z), even(Z).
- Rule 2
- basic_affinity(Y) - affinity(Y,2)
- Inference
- basic_affinity(Y) - likes(Y,2), even(2).
- The inference allowed the
- elimination of affinity(Y,Z) and
- reduction to a single rule through finding
- the MGU of affinity(Y,Z) and affinity(Y,2) and
- applying it to the body of rule 1.
- What fact would make - basic_affinity(r2d2) true?
25Chronological Backtracking
- A search procedure for finding unifying terms
- Conducted over an explicit set of clauses
- Upon failure (a dead-end) previous variable
bindings are chronologically unwound and the
search begins again until all possible bindings
are exhausted - Note
- Fruitful bindings may be unrelated to chronology
- Can therefore be terrible inefficient
- Must be aware of how this works to write
efficient LPs
26Backtracking Example
- - plugsIn(X,Y)
- outPort(o5)
- inPort(in1)
- compatible(o5,in1)
- FAIL and Backtrack
- inPort(in2)
- compatible(o5,in2)
- FAIL and Backtrack
- inPort(in3)
- compatible(o5,in3)
- Success(1). plugsIn(o5,in3).
- inPort(Y)
- FAIL and Backtrack
- outPort(X)
- FAIL
- plugsIn(X,Y) -
- outPort(X),
- inPort(Y),
- compatible(Y,Y).
- inPort(in1).
- inPort(in2).
- inport(in3).
- outPort(o5).
- compatible(o5,in3).
Search order matters. Put compatible first in the
plugsIn rule?
27Practical Introduction to Prolog
28Programming Excursions
- Exploring Unification
- Basic Constructs
- Arithmetic, Recursion and Lists
- Database Programming
- Trees and Parsing
29Practical Introduction to Prolog