1 / 5

Pattern Matching in Prolog

Pattern Matching in Prolog. f rom simple to complicated … let’s review how it works Database : suppose we have p(1). p(a(1)). p(a(b(1,2),3)). pattern matching (PM) in queries …. functors can’t be variables in Prolog. Pattern Matching in Prolog. Pattern matching (PM) in programs

oki
Download Presentation

Pattern Matching in Prolog

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Pattern Matching in Prolog from simple to complicated … let’s review how it works • Database: suppose we have • p(1). • p(a(1)). • p(a(b(1,2),3)). • pattern matching (PM) in queries … functors can’t be variables in Prolog

  2. Pattern Matching in Prolog Pattern matching (PM) in programs • Suppose we have defined • q(X,Y) :- p(a(X,Y)). • already have: • p(1). • p(a(1)). • p(a(b(1,2),3)). PM q(A,B) q(X,Y) A=X, B=Y PM p(a(X,Y)) p(1) PM a(X,Y) 1fails PM p(a(X,Y)) p(a(1)) PM a(X,Y) a(1) fails PM p(a(X,Y)) p(a(b(1,2),3)) PM a(X,Y) a(b(1,2),3) PM X b(1,2) X=b(1,2) PM Y 3 Y=3

  3. From lecture 9 • Example: [S [NP [Q every][N man]][VP [V likes][NP John]]] • WordExpression • every λP1.[λP2.[∀X (P1(X) -> P2(X))]] • man man • likes λY.[λX.[ X likes Y]] • John John • Logic steps: • [Q every][N man]] λP1.[λP2.[∀X (P1(X) -> P2(X))]](man) • [Q every][N man]] λP2.[∀X (man(X) -> P2(X))] • [VP [V likes][NP John]] λY.[λX.[ X likes Y]](John) • [VP [V likes][NP John]] λX.[ X likes John] • [S [NP [Q every][N man]][VP [V likes][NP John]]] • λP2.[∀X (man(X) -> P2(X))](λX.[ X likes John]) • ∀X (man(X) -> λX.[ X likes John](X)) • ∀X (man(X) -> [ X likes John]) Let’s take a look at how to compute this …

  4. Pattern Matching in Prolog • Given: • likes λY.[λX.[ X likes Y]] • Prolog representation is: lambda(Y,lambda(X,likes(X,Y))) • pattern matching (PM) this in a program … • Given grammar rule fragment: vp(LE2) --> v(LE1), np(X). v(lambda(Y,lambda(X,likes(X,Y))) --> [likes]. np(john) --> [john]. • How do we define LE1 and LE2 (lambda expression)? so the VP rule returns: lambda(X,likes(X,john) Answer: using PM substitute lambda(X,LE2) forLE1in VP rule

  5. Pattern Matching in Prolog • WordSemanticExpression • every λP1.[λP2.[∀X (P1(X) -> P2(X))]] • man man • Logic steps: • [Q every][N man] λP1.[λP2.[∀X (P1(X) -> P2(X))]](man) • [Q every][N man] λP2.[∀X (man(X) -> P2(X))] • λP1.[λP2.[∀X (P1(X) -> P2(X))]] Illegal: lambda(P1,lambda(P2,(\+ (P1(X), \+ P2(X))))) Alternate: lambda(P1,lambda(P2,(\+ (call(P1,X),\+ call(P2,X))))) Let’s write the grammar rule fragment for [NP[Q every][N man]]

More Related