Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.



Published on

Published in: Education, Technology, Spiritual
  • Be the first to comment

  • Be the first to like this


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