Question: Solve in DLV ASCII format Using DLV for First Order Logic: Predicate Logic programming The most important thing to remember is that in a DLV

Solve in DLV ASCII format
Using DLV for First Order Logic: Predicate Logic programming
The most important thing to remember is that in a DLV program CAPITAL LETTERS are variable terms, and lowercase are constant ground terms. Furthermore, all variables are universally quantified by default. We will discuss what to do with existential statements later.
Due to the semi-decidability of First Order Logic, DLV limits the kinds of statements that you can make. In particular, you cannot reference variables on the left hand side of an implication that did not exist on the right hand side (DLV reports rule not safe)
So x, y . p(x) q(x, y) is illegal (unsafe) in DLV [ q(X,Y) :- p(X).],
but x, y . p(x) r (y) q(x, y) is OK [ q(x,y) :- p(x), r(y).].
Using negation has another set of issues with decidability (safety). Usually, rather than true negation, you want to use constraints (if these things hold, then the model is inconsistent), encoded in DLV as :- likespuppies(X), hatespuppies(X). Meaning that nobody can both like and hate puppies simultaneously, that is an inconsistent model.
Complete the following program. There is only one correct model.
After seeing the latest Hollywood blockbuster, several friends went to the local cafe for a late-night drink. Using the clues below, match each person [Ivan, Linda, Patricia, Virgil] to their drink [cafe mocha, flat white, chai tea, earl grey tea], and determine the final bill for each [$5.99, $6.99, $7.99, $8.99]. Remember that in these kinds of problems each value is only used once in the solution.
1. The one who had the flat white paid 2 dollars less than Virgil.
2. The person who paid $6.99 had the earl grey tea.
3. Ivan paid 2 dollars more than the one who had the earl grey tea.
4. The one who had the cafe mocha paid 1 dollar more than Patricia.
Encoding in DLV requires some anchor facts (compare: Relational Database Tables; these act as a
Primary Key/ID). Here we use the person name as the Primary ID. Then the other facts are relations (e.g relational tables) indexed by the primary key. Here, the other relations are the drink (every person has a drink) and price paid (every person pays some amount).
The following is a partial solution in standard FOL notation to get you started. Remember that DLV variables are capitalized and constants are lowercase (exactly the opposite of the FOL notation)
%NOTE: written in FOL syntax, not DLV syntax!!!!!
% There exist four different people
%(these are the anchoring facts, like a database primary key)
person (IVAN)
person (LINDA)
person (PATRICIA)
person (VIRGIL)
%Every person drinks some drink.
p . person ( p) drinks ( p, MOCHA ) drinks ( p, FLAT ) drinks ( p, CHAI ) drinks ( p, EARL )
% Every person pays some bill (I've rounded up)
p . person ( p) pays ( p,6) pays ( p,7) pays ( p,8) pays ( p,9)
%Two different people cannot have the same drink (a constraint)
p1p2d1. drinks ( p1, d1) drinks ( p2, d1)( p1 p2) False
%Two different people cannot have the same bill (another constraint)
p1p2b1. pays ( p1, b1) pays ( p2, b1)( p1 p2) False
% CLUE 1: The one who had the flat white paid 2 dollars less than Virgil.
% DLV CAN do arithmetic, but let's keep it simple this week...
% If Virgil paid 9, then flat white paid 7.
% If Virgil paid 8, then flat white paid 6.
% It is inconsistent with the problem for Virgil to pay 6 or 7.
p . pays ( VIRGIL ,9) drinks ( p, FLAT ) pays ( p,7)
p . pays ( VIRGIL ,8) drinks ( p, FLAT ) pays ( p,6)
pays (VIRGIL ,7) False
pays (VIRGIL ,6) False
% CLUE 2: The person who paid $6.99 had the earl grey tea.
p . pays ( p,7) drinks ( p, EARL )
p b . drinks ( p, EARL ) pays ( p, b)(b 7) False
% CLUE 3: Ivan paid 2 dollars more than the one who had the earl grey tea.
% again, we'll do the math ourselves here
p . drinks ( p, EARL ) pays ( p,6) pays ( IVAN ,8)
p . drinks ( p, EARL ) pays ( p,7) pays ( IVAN ,9)
pays (IVAN ,6) False
pays (IVAN ,7) False
% CLUE 4: The one who had the cafe mocha paid 1 dollar more than Patricia
You finish the program.
% to make the solution easier to see,
% If we have a person, their drink, and their bill, then we have a solution
% run the command: ./dlv -pfilter=solution file.txt
solution(P,D,B) :- person(P), drinks(P,D), pays(P,B).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!