LOGIC PROGRAMMING - PROLOG PROPLOG - Propositional Fragment of Prolog THREE CLASES OF FORMULAS Atomic A ::= Propositional symbols Goal Clauses G ::= T | A | G ^ G Definite Clauses D ::= G => A (NOTE: T => A == A) Program P == set of D Sequent: P |- G ______ P |- T P |- G1 P |- G2 ---------------- P |- G1 ^ G2 P |- G ----------- P,G=>A |- A Example Program: B^C => A, D=>B, E=>B, E=>D true=>C true=>E Computation in Prolog: -Interactive Language -Programs loaded -User enters a Goal clause -System attempts to solve Goal using Program -Responds "yes" or "no" (or maybe never terminates) Prolog Syntax: atoms A - symbols begin w/ lowercase G ::= true | A | G,G D ::= A :- G. Running Prolog on the Suns: %sicstus | ?- ['test.pl']. {consulting /auto/home/sol4/hannan/Courses/520/lectures/test.pl...} {/auto/home/sol4/hannan/Courses/520/lectures/test.pl consulted, 30 msec 264 bytes} yes | ?- a. yes | ?- b. yes | ?- q. {Warning: The predicate q/0 is undefined} 1 1 Fail: q ? no EXAMPLE: CS Requirements csReq :- basicCS, mathReq, advancedCS, engReq, natSciReq. basicCS :- introReq, compOrg, advProg, theory. %two choices for introReq introReq :- introCS. introReq :- introI, introII. mathReq :- calcReq, finiteReq, algReq. calcReq :- basicCalc, advCalc. basicCalc :- calcI, calcII. basicCalc :- calcA, calcB, calcC. basicCalc :- honorsCalcI, honorsCalcII. advCalc :- linAlg. advCalc :- honorsLinAlg. finiteReq :- finStructI, stat. algReq :- finStructII. algReq :- absAlg. advancedCS :- group1All, group2One. advancedCS :- group1Two, group2Two. group1All :- compilers, opSys, arch. group1Two :- compilers, opSys. group1Two :- compilers, arch. group1Two :- opSys, arch. group2One :- progLang. group2One :- dbms. group2One :- ai. group2Two :- progLang, dbms. group2Two :- progLang, ai. group2Two :- dbms, ai. engReq :- digSys. natSciReq :- physicsI, physicsII. natSciReq :- chemI, chemII. natSciReq :- bioI, bioII. Now to this program we could add the courses taken by an individual: introI. introII. etc. Then from this program we could try to solve csReq. ADDING FIRST-ORDER QUANTIFIERS TO N. (First-order Predicate Logic) Assume given some set of terms T (lambda terms?) Our Formulas become:... P(t1,...,tn) G |- A [y/x] G |- all x.A ------------* ------------ G |- all x.A G |- A[t/x] G |- A[t/x] G |- ex x.A G,z:A[y/x] |- C ----------- ----------------------------* G |- ex x.A G |- C * y a fresh variable. In Gentzen Systems: A[t/x], G |- C G |- A[y/x] -------------- ------------ all x.A, G |- C G |- all x.A A[y/x], G |- C G |- A[t/x] -------------- ----------- ex x.A, G |- C G |- ex x.A First-Order Horn Clauses (Prolog) Terms : T ::= c | X | f(t1,...,tm) A ::= true | p(t1,...,tn) G ::= A | G ^ G | exists x.G D ::= G => A | all x. G Prolog Syntax: G ::= A | G,G D ::= A :- G