1 / 4

SWI Prolog

SWI Prolog. SWI Prolog is a popular, open, implementation of Prolog that is based upon WAM (Warren Abstract Machine). This implementation is freely available and runs on various Unix systems (including OS X), as well as Windows platforms. (See www.swi-prolog.org ). Using SWI Prolog.

mihaly
Download Presentation

SWI 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. SWI Prolog SWI Prolog is a popular, open, implementation of Prolog that is based upon WAM (Warren Abstract Machine). This implementation is freely available and runs on various Unix systems (including OS X), as well as Windows platforms. (See www.swi-prolog.org). Using SWI Prolog Startup: swipl Once started, SWI prolog behaves in an interactive (interpreter) style. Prompt: ?- Some Basic Commands To compile a collection of facts & rules: consult(filename). To terminate use of the interpreter: halt. To enter a query: (see Prolog notation for goals) SWI Response to Queries fail means the query (goal) cannot be satisfied true means the query (goal) is true Variable assignments are reported for satisfaction of queries involving variables.

  2. Sample Session family.pl file session mother(sue, sam). mother(sue, mae). mother(mia, sue). mother(kay, jim). mother(kay, max). mother(mia, joe). mother(mia, bob). father(jim, sam). father(jim, mae). father(ed, sue). father(moe, jim). father(moe, max). father(ed, joe). father(ed, bob). child(C, P) :- parent(P, C). parent(P, C) :- mother(P, C). parent(P, C) :- father(P, C). siblings(A,B) :- parent(P,A), parent(P,B), A \= B. > swipl Welcome to SWI Prolog (Version 5.0.10) … ?- consult(family). % family compiled 0.00 sec. 2,584 bytes true. ?- mother(sue, sam). true. ?- mother(mae, sam). fail. ?- mother(M, max). M = kay. ?- parent(P, max). P = kay; P = moe; fail.

  3. Variable Queries When an SWI query contains variables, the Prolog response is to show a complete set of variable bindings that make the query true. …but there may be other sets of bindings that also satisfy the query. Therefore, after each set of bindings the session waits for one of two responses: ; is a request for another set of bindings return (enter) terminates the query.

  4. gcd Revisited Axiom 1:If (N  1), then gcd(N,1) = 1 Axiom 2:If (N  1) and (N < D), then gcd(N,D) = gcd(D,N) Axiom 3:If (N  1) and (D  1) and (N mod D = 0), then gcd(N,D) = D Axiom 4:If (D > 1) and (N > D) and (N mod D  0), then gcd(N,D) = gcd(D, N mod D) gcd.pl file gcd(N,1,1) :- N >= 1. gcd(N,D,Z) :- N >= 1, N < D, gcd(D,N,Z). gcd(N,D,D) :- N >= 1, D >= 1, N mod D=:=0.

More Related