since last midterm
play

Since Last midterm Sign up for project demos For more details about - PowerPoint PPT Presentation

Since Last midterm Sign up for project demos For more details about the exam and a review session keep watching the Canvas site What is now required is to give the greatest possible de- velopment to mathematical logic, to allow to the full


  1. Since Last midterm Sign up for project demos For more details about the exam and a review session — keep watching the Canvas site What is now required is to give the greatest possible de- velopment to mathematical logic, to allow to the full the importance of relations... If this can be successfully ac- complished, there is every reason to hope that the near future will be as great an epoch in pure philosophy as the immediate past has been in the principles of mathematics. Great triumphs inspire great hopes; and pure thought may achieve, within our generation, such results as will place our time, in this respect, on a level with the greatest age of Greece. – Bertrand Russell, Mysticism and Logic and Other Essays [1917] � D. Poole 2018 c CPSC 312 — Lecture 33 1 / 19

  2. Since Last midterm difference lists, definite clause grammars and natural language interfaces to databases computer algebra and calculus Triples are universal representations of relations, and are the basis for RDF, and knowledge graphs URIs provide constants that have standard meanings Ontologies define the meaning of symbols used in information systems. You should know what the following mean: RDF, URI, rdf:type, rdfs:subClassOf, rdfs:domain, rdfs:range Complete knowledge assumption and negation as failure Substitutions and Unification Today Proofs and answers. Negation with variables. � D. Poole 2018 c CPSC 312 — Lecture 33 2 / 19

  3. Unifiers Substitution σ is a unifier of e 1 and e 2 if e 1 σ = e 2 σ . Substitution σ is a most general unifier (mgu) of e 1 and e 2 if ◮ σ is a unifier of e 1 and e 2 ; and ◮ if substitution σ ′ also unifies e 1 and e 2 , then e σ ′ is an instance of e σ for all atoms e . If two atoms have a unifier, they have a most general unifier. If there are more than one most general unifiers, they only differ in the names of the variables. � D. Poole 2018 c CPSC 312 — Lecture 33 3 / 19

  4. Top-down propositional definite clause interpreter (review) To solve the query ? q 1 , . . . , q k : ac := “ yes :- q 1 , . . . , q k ” repeat select leftmost atom a 1 from the body of ac choose clause C from KB with a 1 as head replace a 1 in the body of ac by the body of C until ac is an answer. � D. Poole 2018 c CPSC 312 — Lecture 33 4 / 19

  5. Top-down Proof procedure A generalized answer clause is of the form yes ( t 1 , . . . , t k ) :- a 1 , a 2 , . . . , a m , where t 1 , . . . , t k are terms and a 1 , . . . , a m are atoms. The SLD resolution of this generalized answer clause on a 1 with the clause a :- b 1 , . . . , b p , where a i and a have most general unifier θ , is ( yes ( t 1 , . . . , t k ) :- b 1 , . . . , b p , a 2 , . . . , a m ) θ. � D. Poole 2018 c CPSC 312 — Lecture 33 5 / 19

  6. Top-down Proof Procedure To solve query ? B with variables V 1 , . . . , V k : Set ac to generalized answer clause yes ( V 1 , . . . , V k ) :- B while body of ac is not empty do Suppose ac is yes ( t 1 , . . . , t k ) :- a 1 , a 2 , . . . , a m select leftmost atom a i in the body of ac choose clause a :- b 1 , . . . , b p in KB Rename all variables in a :- b 1 , . . . , b p Let θ be the most general unifier of a i and a . Fail if they don’t unify Set ac to ( yes ( t 1 , . . . , t k ) :- b 1 , . . . , b p , a 2 , . . . , a m ) θ end while . Answer is V 1 = t 1 , . . . , V k = t k � D. Poole 2018 c CPSC 312 — Lecture 33 6 / 19

  7. Example live ( Y ) :- connected to ( Y , Z ) , live ( Z ) . live ( outside ) . connected to ( w 6 , w 5 ) . connected to ( w 5 , outside ) . ? live ( A ) . yes ( A ) :- live ( A ) . yes ( A ) :- connected to ( A , Z 1 ) , live ( Z 1 ) . yes ( w 6 ) :- live ( w 5 ) . yes ( w 6 ) :- connected to ( w 5 , Z 2 ) , live ( Z 2 ) . yes ( w 6 ) :- live ( outside ) . yes ( w 6 ) :- . Answer is A = w 6 � D. Poole 2018 c CPSC 312 — Lecture 33 7 / 19

  8. Example append ([] , L , L ) . append ([ H | T ] , A , [ H | R ]) :- append ( T , A , R ) . ? append ([ a , b , c ] , [1 , 2 , 3] , L ) . yes ( L ) :- append ([ a , b , c ] , [1 , 2 , 3] , L ) . yes ([ a | R 1]) :- append ([ b , c ] , [1 , 2 , 3] , R 1) . yes ([ a , b | R 2]) :- append ([ c ] , [1 , 2 , 3] , R 2) . yes ([ a , b , c | R 3]) :- append ([] , [1 , 2 , 3] , R 3) . yes ([ a , b , c , 1 , 2 , 3]) :- . Answer is L = [ a , b , c , 1 , 2 , 3] � D. Poole 2018 c CPSC 312 — Lecture 33 8 / 19

  9. Clicker Question What is the resolution of the generalized answer clause: yes ( B , N ) :- append ( B , [ a , N | R ] , [ b , a , c , d ]) . with the clause append ([] , L , L ) . A yes ([] , c ) :- append ( B , R , [ d ]) B yes ([ b ] , c ) :- C yes ([ b | T 1] , N ) :- append ( T 1 , [ a , N | R ] , [ a , c , d ]) . D yes ([ b ] , N ) :- append ([] , [ a , N | R ] , [ a , c , d ]) . E the resolution fails (they do not resolve) � D. Poole 2018 c CPSC 312 — Lecture 33 9 / 19

  10. Clicker Question What is the resolution of the generalized answer clause: yes ( B , N ) :- append ( B , [ a , N | R ] , [ b , a , c , d ]) . with the clause append ([ H | T ] , A , [ H | R ]) :- append ( T , A , R ) . A yes ([] , c ) :- append ( B , R , [ d ]) B yes ([ b ] , c ) :- C yes ([ b | T 1] , N ) :- append ( T 1 , [ a , N | R ] , [ a , c , d ]) . D yes ([ b ] , N ) :- append ([] , [ a , N | R ] , [ a , c , d ]) . E the resolution fails (they do not resolve) � D. Poole 2018 c CPSC 312 — Lecture 33 10 / 19

  11. Clicker Question What is the resolution of the generalized answer clause: yes ([ b | T 1] , N ) :- append ( T 1 , [ a , N | R ] , [ a , c , d ]) . with the clause append ([] , L , L ) . A yes ([] , c ) :- append ( B , R , [ d ]) B yes ([ b ] , c ) :- C yes ([ b | T 1] , N ) :- append ([] , [ a , c , d ] , [ a , c , d ]) . D yes ([ b ] , N ) :- append ([] , [ a , N | R ] , [ a , c , d ]) . E the resolution fails (they do not resolve) � D. Poole 2018 c CPSC 312 — Lecture 33 11 / 19

  12. Unification with function symbols Consider a knowledge base consisting of one fact: lt ( X , s ( X )) . Should the following query succeed? ? - lt ( Y , Y ) . What does the top-down proof procedure give? Solution: variable X should not unify with a term that contains X inside. “Occurs check” E.g., X should not unify with s ( X ). Simple modification of the unification algorithm, which Prolog does not do! � D. Poole 2018 c CPSC 312 — Lecture 33 12 / 19

  13. Equality Equality is a special predicate symbol with a standard domain-independent intended interpretation. Suppose interpretation I = � D , φ, π � . t 1 and t 2 are ground terms then t 1 = t 2 is true in interpretation I if t 1 and t 2 denote the same individual. That is, t 1 = t 2 if φ ( t 1 ) is the same as φ ( t 2 ). t 1 � = t 2 when t 1 and t 2 denote different individuals. Example: D = { ✂ , ☎ , ✎ } . φ ( phone ) = ☎ , φ ( pencil ) = ✎ , φ ( telephone ) = ☎ What equalities and inequalities hold? phone = telephone , phone = phone , pencil = pencil , telephone = telephone pencil � = phone , pencil � = telephone Equality does not mean similarity! � D. Poole 2018 c CPSC 312 — Lecture 33 13 / 19

  14. Equality Constants/Terms Individuals a b c d f(a) e � D. Poole 2018 c CPSC 312 — Lecture 33 14 / 19

  15. Properties of Equality Equality is: Reflexive: X = X Symmetric: if X = Y then Y = X Transitive: if X = Y and Y = Z then X = Z For each n -ary function symbol f f ( X 1 , . . . , X n ) = f ( Y 1 , . . . , Y n ) if X 1 = Y 1 and · · · and X n = Y n . For each n -ary predicate symbol p p ( X 1 , . . . , X n ) if p ( Y 1 , . . . , Y n ) and X 1 = Y 1 and · · · and X n = Y n . � D. Poole 2018 c CPSC 312 — Lecture 33 15 / 19

  16. Unique Names Assumption Suppose the only clauses for enrolled are enrolled ( sam , cs 222) enrolled ( chris , cs 222) enrolled ( sam , cs 873) To conclude ¬ enrolled ( chris , cs 873), what do we need to assume? ◮ All other enrolled facts are false ◮ Inequalities: sam � = chris ∧ cs 873 � = cs 222 The unique names assumption (UNA) is the assumption that distinct ground terms denote different individuals. � D. Poole 2018 c CPSC 312 — Lecture 33 16 / 19

  17. Inequality as a subgoal What should the following query return? ? − X � = 4 . What should the following query return? ? − X � = 4 , X = 7 . What should the following query return? ? − X � = 4 , X = 4 . Prolog has 3 different inequalities that differ on examples like these: \== \= dif() They differ in cases where there are free variables, and terms unify but are not identical. � D. Poole 2018 c CPSC 312 — Lecture 33 17 / 19

  18. Implementing dif dif ( X , Y ) ◮ all instances fail when X and Y are identical ◮ all instances succeed when X and Y do not unify ◮ otherwise some instance succeed and some fail To implement dif ( X , Y ) in the body of a clause: ◮ Select leftmost clause unless it is a dif which cannot be resolved (delay dif calls) ◮ Return the dif calls not resolved. Consider the calls: dif(X,4), X=7. dif(X,4), X=4. dif(X,4), dif(X,7). � D. Poole 2018 c CPSC 312 — Lecture 33 18 / 19

  19. Functional and logic programming Unifying ideas: specify what not how program by thinking about the problem, not about the computation variables don’t change their values once assigned — referential transparency Haskell: strong typing higher-order functions allow us to create our own abstractions lazy computation Prolog: unification allows for powerful pattern matching non-determinism through search extends relational databases Programming at a high-level can help no matter what language you use! � D. Poole 2018 c CPSC 312 — Lecture 33 19 / 19

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend