1 / 6

Chapter Two: Syntax and Meaning of Prolog Programs

Chapter Two: Syntax and Meaning of Prolog Programs. 2.2 Matching. Matching is the most important operation on terms . Given two terms, they match if: they are identical, or

waite
Download Presentation

Chapter Two: Syntax and Meaning of Prolog Programs

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. Chapter Two: Syntax and Meaning of Prolog Programs

  2. 2.2 Matching • Matching is the most important operation on terms. • Given two terms, they match if: • they are identical, or • the variables in both terms can be instantiated to objects in such a way after the substitution of variables by these objects the terms become identical. Example date(D, M, 2001) and date(D1, may, Y1) date(D, M, 2001) and date(D1, M1, 1444) date(X, Y, Z) and point(X, Y, Z)

  3. 2.2 Matching • Matching is a process that takes as inputs two terms and check whether they match. If the terms do not match, we say this process fails. If they match, the process succeeds. • To request Prolog matching operation, we use ‘=‘ : ?- date(D, M, 2001)=date(D1, may, Y1). • Matching in Prolog always results in the most general instantiation.

  4. 2.2 Matching Example Consider the following terms in Prolog program: point (_, _). seg(point(_,_), point(_,_)). triangle(point(_,_), point(_,_), point(_,_)). Declare vertical and horizontal relations vertical (seg(point(X,_), point(X,_))). horizontal (seg(point(_,Y), point(_,Y))). Formulate the following questions and find Prolog answers: • Is the segment (1,1), (1,4) is vertical? • What is the other coordinate that make the segment (1,1), (2,Y) vertical? • What is the other coordinate that make the segment (1,1), (2,Y) horizontal? • Are there any vertical segment that start at point(2,3)? • Is there a segment that is both vertical and horizontal?

  5. Meaning of Prolog programs • Consider the clause: P :- Q, R. • Declarative readings: • P is true if Q and R is true • From Q and R follows P • Procedural readings: • To solve problem P, first solve the subproblem Q, and then the subproblem R. • To satisfy P, first satisfy Q and then R.

  6. Meaning of Prolog programs • Consider the clause: P :- Q; R. • ; means OR • Same as the following two clauses together: P :- Q.P :- R. • The comma binds stronger than the semicolon. • P :- Q,R;S,T,U. is understood as: • P:- (Q,R);(S,T,U). and means the same as the clauses: • P :- Q,R. • P :- S,T,U.

More Related