syntax, semantics and intended meaning the 1-slide course 4 syntax –symbols + a set of rules for...

29
Syntax, Semantics and Intended Meaning The 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 (S 1 ,…S n ) The system is “good/useful/fruitful/meaningful” if All truths in T may be represented by some S i (complete) Every S i entailed by the system represents some truth in T (sound)

Upload: melvyn-johnston

Post on 17-Dec-2015

223 views

Category:

Documents


0 download

TRANSCRIPT

Syntax, 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)

LP 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

TermThe 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).

SubstitutionA formal definition

A finite set of pairs of the form xi= tj, where

– xi is a variable

– ti is a term

– xi < > xj for every i < > 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) {X=selmer,Y=r2d2} foo(selmer, r2d2).

InstancesA 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 A=B{q}

– Think of a substitution as a set of variable bindings

Examples– 1 is an instance of X.

• The substitution is {X=1}

– foo(bar,1) is an instance of foo(V,1)• the substitution is {V=Bar}

– 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){V=bar) = foo(bar,Y) is NOT ground.

– foo(V,Y){V=bar, Y=1) = foo(bar,1) is ground.

Queries

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?

Rule of Generalization

An existential query P is a logical consequent of an instance of P,

P{q}, 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.

A Fact

Compound Term

– Functor(t1,…,tn)

Variables are universally quantified

father(big_Tony, X) means

– English: big Tony is everyone’s father

– FOL: (X) father(big_Tony,X)

Rule of Instantiation

From a universally quantified statement P (i.e., a fact)

deduce an instance of it, P{q}, 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) …

A 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 n=0

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?

My best attempt at communicate meaning is by offering yet another syntactic structure form some other symbol system with yet another semantics that I hope my audience understands.

Where is meaning ultimately captured? Is it captured at all?

We gather evidence that expressions in one system align with expressions in another. At some point we agree that we understand each other. But do we?

Have we capture meaning or just aligned expressions in different symbol systems to realize functional communication?

Does the meaning of the American word love have a direct analog in Latin?

My best attempt at communicate meaning is by offering yet another syntactic structure form some other symbol system with yet another semantics that I hope my audience understands.

Where is meaning ultimately captured? Is it captured at all?

We gather evidence that expressions in one system align with expressions in another. At some point we agree that we understand each other. But do we?

Have we capture meaning or just aligned expressions in different symbol systems to realize functional communication?

Does the meaning of the American word love have a direct analog in Latin?

Rule of Universal Modus Ponens From

– A B1,…,Bn (B`1,…,B`n)

• where for all i between 1 and n, B`i 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)

A 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? What’s the intended meaning of the boss(big_tony_Y) rule above?

Facts are rules where the body is empty.

Rules with bodies

More on Semantics

Declarative and Operational

Declarative 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.

Operational 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 don’t 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.

Classic 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 1950’s)

– 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.

Goal Reduction

The computational core of LP

Elements of Goal Reduction

Unification Pattern Matching

Resolution Inference

Chronological Backtracking Search

Unification

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)

Most 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

– {X=1,Y=2} 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{X=A, Y=1}, None{X=A, Y=B}, None{X=1,Y=2}, {Y=2}{X=1,Y=B}, {Y=B}

Unification Procedure

Computes the MGU of two terms if it exists else fails.

– unify(X,1) {X,1}

– unify(a(X,1), a(1,Y)) {X=1, Y=1)

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)

Unification 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: {V=nvidia, D=b14, C=256)

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: {V=rage, C=16}

Example 3: A and B are not unifiable– Facts (A and B): supports(V,b14,16), supports(nvidia,D,256)

– MCI: None

– MGU: None

Resolution

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) (B ^ D) – where is the MGU of M and N.

Resolution 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?

Chronological 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

Backtracking Example

plugsIn(X,Y) :-outPort(X),

inPort(Y),

compatible(Y,Y). inPort(in1). inPort(in2). inport(in3). outPort(o5). compatible(o5,in3).

:- 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

Search order matters.Put compatible first in the plugsIn rule?

Practical Introduction to Prolog

Basics

Programming Excursions

Exploring Unification Basic Constructs Arithmetic, Recursion and Lists Database Programming Trees and Parsing

Practical Introduction to Prolog

Negation and the Cut