Syntax Semantics and Intended Meaning The 1 slide

  • Slides: 29
Download presentation
Syntax, Semantics and Intended Meaning The 1 -slide course 4 Syntax – Symbols +

Syntax, Semantics and Intended Meaning The 1 -slide course 4 Syntax – Symbols + a set of rules for their valid composition into aggregate structures 4 Semantics – The relationship between syntactic structures of a symbol system and what they are intended to denote -- their intended meaning 4 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, …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 4 Terms – Constant, Variable, Functor, Term, Compound Term 4 Instances

LP Syntactic Structures 4 Terms – Constant, Variable, Functor, Term, Compound Term 4 Instances – Substitution, Instance 4 Facts and Queries – Facts and the rule of instantiation – Queries and the rule of generalization 4 Rules and Logic Programs – Rules, Unification, Logic Programs

Term The single data structure 4 Constant – letter, number, string of letters or

Term The single data structure 4 Constant – letter, number, string of letters or numbers beginning with a lower case letter. – Intended to represent entities, individuals, existent etc. : dog, cat, alfred, r 2 d 2, selmer, the number 2. 4 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. 4 Compound term – Functor(A 1, …, An) – Functor is any constant – Ai is a term. – Intended to represent relations or predicates about things: father(selmer, r 2 d 2).

Substitution A formal definition 4 A finite set of pairs of the form xi=

Substitution A formal definition 4 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 4 Substitutions can be applied to terms – foo(X, Y) {X=selmer, Y=r 2 d 2} foo(selmer, r 2 d 2).

Instances A relationship between terms 4 One term may be an instance of another

Instances A relationship between terms 4 One term may be an instance of another term. 4 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 4 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? 4 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 4 A compound term preceded by ‘ : - ‘ – : -

Queries 4 A compound term preceded by ‘ : - ‘ – : - functor(t 1, …, tn) 4 Variables are existentially quantified 4 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 4 An existential query P is a logical consequent of an

Rule of Generalization 4 An existential query P is a logical consequent of an instance of P, P{q}, for any substitution q. 4 Example – : - father(big_Tony, X) is a logical consequent of father(big_Tony, two_Ton_Tommy) 4 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 4 Compound Term – Functor(t 1, …, tn) 4 Variables are universally

A Fact 4 Compound Term – Functor(t 1, …, tn) 4 Variables are universally quantified 4 father(big_Tony, X) means – English: big Tony is everyone’s father – FOL: (X) father(big_Tony, X)

Rule of Instantiation 4 From a universally quantified statement P (i. e. , a

Rule of Instantiation 4 From a universally quantified statement P (i. e. , a fact) deduce an instance of it, P{q}, for any substitution q. 4 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, r 2 d 2) …

My best attempt at communicate meaning is by offering yet another syntactic structure form

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. A Rule Where is meaning ultimately captured? Is it captured at all? 4 Complex query composed of simpler queries We gather evidence that expressions in one system align with expressions in 4 Has a head (a term) and a body (a sequence of terms) another. At some point we agree that we understand each other. But do we? – H B 1, …, Bn Have we capture meaning or just aligned expressions in different symbol 4 A fact is a rule where n=0 systems to realize functional communication? 4 Example Does the meaning of the American word love have a direct analog in Latin? – 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?

Rule of Universal Modus Ponens 4 From – A B 1, …, Bn (B`1,

Rule of Universal Modus Ponens 4 From – A B 1, …, 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 4 Deduce – A` 4 From – grandfather(X, Z) father(X, Y), father(Y, Z) – father(big_Tony, little_Tony), father(little_Tony, tiny_Tony) 4 Deduce – grandfather(big_Tony, tiny_Tony)

A Logic Program 4 A logic program is a finite set of rules. 4

A Logic Program 4 A logic program is a finite set of rules. 4 Example Logic Program: The “Family” Tree – father(big_Tony, little_Tony). – father(little_Tony, tiny_Tony). – boss(quick_Nick, franky_three_shots). Facts are rules where the body is empty. – boss(buddy_the_button, mikey_the_mop). – boss(big_tony, Y) boss(Y, Z). – grandfather(X, Z) father(X, Y), father(Y, Z). Rules with bodies 4 Example Queries – : - boss(big_Tony, quick_Nick) • yes – : - boss(big_Tony, r 2 d 2) • no…. why? What’s the intended meaning of the boss(big_tony_Y) rule above?

More on Semantics Declarative and Operational

More on Semantics Declarative and Operational

Declarative Semantics What it means is what it is. 4 How a the syntactic

Declarative Semantics What it means is what it is. 4 How a the syntactic structure of a program relates to its intended meaning 4 The meaning of a logic program is the set of all the statements it entails 4 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 Semantics What it means is what a procedure produces. 4 The meaning of

Operational Semantics What it means is what a procedure produces. 4 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. 4 A computation of a program P is a procedure. 4 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. 4 How does goal reduction produces statements (i. e. , answers)? 4 How it works is the operational semantics of logic programming. 4 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 4 What are the declarative semantics? – Scott-Strachey approach to programming

Classic Programming Languages 4 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. 4 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

Goal Reduction The computational core of LP

Elements of Goal Reduction 4 Unification Pattern Matching 4 Resolution Inference 4 Chronological Backtracking

Elements of Goal Reduction 4 Unification Pattern Matching 4 Resolution Inference 4 Chronological Backtracking Search

Unification 4 A constructive pattern matching procedure 4 Determines the most general unifier (MGU)

Unification 4 A constructive pattern matching procedure 4 Determines the most general unifier (MGU) of two terms. 4 Using the MGU constructs the most general common instance of two terms 4 Used to compute the resolution inference 4 Resolution is used to iteratively reduce a goal generating its proof from the program if possible (i. e. , goal reduction)

Most General Unifier(MGU) 4 A common instance of A and B is an instance

Most General Unifier(MGU) 4 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) 4 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 4 The MGU of two terms is a unifier that produces the most general common instance of the two terms. 4 Which are instances of both foo(X, Y), foo(1, Y)? What is the MGU? – bar(1, 2) None, None – foo(A, 1) {X=A, Y=1}, None – foo(A, B) {X=A, Y=B}, None – foo(1, 2) {X=1, Y=2}, {Y=2} – foo(1, B) {X=1, Y=B}, {Y=B}

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

Unification Procedure 4 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) 4 Produces the most general common instance 4 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 4 Fact Schema: Supports(Video_Card, Display_Type, Number_of_Colors) 4 Example 1: Neither A nor

Unification Examples 4 Fact Schema: Supports(Video_Card, Display_Type, Number_of_Colors) 4 Example 1: Neither A nor B entails the other – Facts (A and B): supports(V, b 14, C), supports(nvidia, D, 256) – MCI: supports(nvidia, b 14, 256) – MGU: {V=nvidia, D=b 14, C=256) 4 Example 2: B is an instance of A – Facts (A and B): supports(V, b 14, C), supports(rage, b 14, 16) – MCI: supports(rage, b 14, 16) – MGU: {V=rage, C=16} 4 Example 3: A and B are not unifiable – Facts (A and B): supports(V, b 14, 16), supports(nvidia, D, 256) – MCI: None – MGU: None

Resolution 4 Enables a reduction of two rules into one 4 Eliminates a common

Resolution 4 Enables a reduction of two rules into one 4 Eliminates a common term from the consequent of one rule and from the antecedent of another 4 Efficient application depends on the constructive unification procedure 4 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.

Resolution Example 4 Rule 1 – affinity(Y, Z) : - likes(Y, Z), even(Z). 4

Resolution Example 4 Rule 1 – affinity(Y, Z) : - likes(Y, Z), even(Z). 4 Rule 2 – basic_affinity(Y) : - affinity(Y, 2) 4 Inference: – basic_affinity(Y) : - likes(Y, 2), even(2). 4 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. 4 What fact would make : - basic_affinity(r 2 d 2) true?

Chronological Backtracking 4 A search procedure for finding unifying terms 4 Conducted over an

Chronological Backtracking 4 A search procedure for finding unifying terms 4 Conducted over an explicit set of clauses 4 Upon failure (a “dead-end”) previous variable bindings are chronologically unwound and the search begins again until all possible bindings are exhausted 4 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 4 plugs. In(X, Y) : out. Port(X), in. Port(Y), compatible(Y, Y). 4

Backtracking Example 4 plugs. In(X, Y) : out. Port(X), in. Port(Y), compatible(Y, Y). 4 in. Port(in 1). 4 in. Port(in 2). 4 inport(in 3). 4 out. Port(o 5). 4 compatible(o 5, in 3). Search order matters. Put compatible first in the plugs. In rule? 4 : - plugs. In(X, Y) – out. Port(o 5) – in. Port(in 1) – compatible(o 5, in 1) – FAIL and Backtrack – in. Port(in 2) – compatible(o 5, in 2) – FAIL and Backtrack – in. Port(in 3) – compatible(o 5, in 3) 4 Success(1). plugs. In(o 5, in 3). – in. Port(Y) – FAIL and Backtrack – out. Port(X) – FAIL

Practical Introduction to Prolog Basics

Practical Introduction to Prolog Basics

Programming Excursions 4 Exploring Unification 4 Basic Constructs 4 Arithmetic, Recursion and Lists 4

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

Practical Introduction to Prolog Negation and the Cut

Practical Introduction to Prolog Negation and the Cut