Reasoning with Logic: CSP, ASP, and Common Sense
Introduction
This lecture introduces the use of Answer Set Programming (ASP) and constraint satisfaction techniques for modeling and solving problems that require common sense reasoning. We will explore the limitations of classical logic, particularly its monotonic nature, and demonstrate how non-monotonic logic, as implemented in ASP, offers a more appropriate framework for handling real-world scenarios. The lecture will also provide a historical context for these ideas, referencing the seminal work of McCarthy, Chitta Baral, and Michael Gelfond.
We will apply these concepts to solve various logic puzzles, showcasing the power and flexibility of ASP in encoding complex relationships and constraints. The main objectives of this lecture are:
To understand how to model problems using ASP.
To appreciate the nuances of non-monotonic reasoning.
To apply these techniques to solve logical puzzles.
Key concepts that will be covered include:
Non-monotonic logic
Stable model semantics
Constraint satisfaction
Encoding of common sense knowledge
This approach allows us to transition from traditional, rigid logical systems to more flexible and intuitive methods for dealing with the complexities of everyday reasoning.
Background: Monotonicity vs. Non-Monotonicity
The Limitations of Classical Logic
Classical logic, while a powerful and well-understood system, often proves inadequate when dealing with common sense reasoning. This inadequacy primarily arises from its monotonic nature.
Definition 1 (Monotonicity). A logical system is monotonic if the addition of new information (premises) never invalidates previously derived conclusions. Formally, if a set of premises \(\Gamma\) entails a conclusion \(\phi\) (denoted as \(\Gamma \vdash \phi\)), and \(\Gamma\) is a subset of another set of premises \(\Delta\) (i.e., \(\Gamma \subseteq \Delta\)), then \(\Delta\) also entails \(\phi\) (i.e., \(\Delta \vdash \phi\)).
Consider the classic syllogism:
Premise 1: All men are mortal.
Premise 2: Socrates is a man.
Conclusion: Therefore, Socrates is mortal.
Adding new information, such as "Socrates is a philosopher," does not change the conclusion that Socrates is mortal. This is a characteristic of monotonic reasoning.
However, real-world reasoning often requires revising conclusions based on new information, which classical logic cannot handle effectively.
Non-Monotonic Logic
Non-monotonic logic addresses the limitations of classical logic by allowing conclusions to be retracted in light of new evidence. This is crucial for modeling common sense reasoning, where our understanding of the world is constantly updated.
Definition 2 (Non-Monotonicity). A logical system is non-monotonic if the addition of new information can invalidate previously derived conclusions. This means that if \(\Gamma \vdash \phi\), it is possible that for some \(\Delta\) with \(\Gamma \subseteq \Delta\), we have \(\Delta \nvdash \phi\).
Consider the following scenario:
Premise 1: You can cross the railway if the train is not there.
Premise 2: The barriers are vertical (indicating no train).
Conclusion 1: You cross the railway.
New Information: There is a power failure, and the barriers are always vertical.
Conclusion 2: You reconsider crossing the railway, as the barriers no longer reliably indicate the absence of a train.
In this case, the new information about the power failure invalidates the previous conclusion, demonstrating non-monotonic reasoning.
Common Sense Reasoning and ASP
McCarthy’s Vision
John McCarthy, a pioneer in Artificial Intelligence, advocated for a declarative approach to AI. His vision involved using logic not just as a tool for formal proofs, but as a means to represent and manipulate knowledge in a way that mirrors human reasoning. This perspective, as emphasized by Chitta Baral and Michael Gelfond, highlights the necessity of an unambiguous language coupled with a precise and well-understood method for manipulating sentences. This approach would enable us to draw inferences, answer queries, and update our knowledge base effectively. This is in contrast to procedural programming, where the focus is on how to compute a solution, rather than what the solution should be.
The Tweety Example
A classic and illustrative example of common sense reasoning is the "Tweety" problem. This problem highlights the limitations of monotonic logic and the need for non-monotonic approaches. The problem can be stated as follows:
Premise 1: Birds typically fly.
Premise 2: Tweety is a bird.
Query: Does Tweety fly?
In a classical logic setting, we would conclude that Tweety flies based on the given premises. However, if we introduce additional information, such as "Tweety is a penguin," we intuitively understand that Tweety does not fly. This requires us to retract our initial conclusion, a process that classical logic cannot handle naturally.
Modeling with ASP
Answer Set Programming (ASP) provides a natural and elegant way to model scenarios like the Tweety problem, using default negation to represent exceptions to general rules. The ASP encoding for the Tweety problem is as follows:
flies(X) :- bird(X), not abnormal(X).
bird(tweety).
abnormal(X) :- penguin(X).
penguin(tweety).
This ASP code can be interpreted as follows:
flies(X) :- bird(X), not abnormal(X).: A birdXflies if it is not known to beabnormal. This is an example of default negation.bird(tweety).: Tweety is a bird.abnormal(X) :- penguin(X).: A penguinXis consideredabnormal.penguin(tweety).: Tweety is a penguin.
In this encoding, the rule flies(X) :- bird(X), not abnormal(X). expresses that birds typically fly, but this can be overridden by the fact that penguins are abnormal and therefore do not fly. This demonstrates the non-monotonic nature of ASP, where the addition of new facts can lead to the retraction of previously inferred conclusions. When this program is executed by an ASP solver, it will correctly infer that Tweety does not fly, due to the presence of the penguin(tweety) fact, which makes abnormal(tweety) true, and thus not abnormal(tweety) false.
Logic Puzzles and ASP
In this section, we will explore how ASP can be used to model and solve various logic puzzles. These puzzles serve as excellent examples to demonstrate the expressive power and flexibility of ASP in handling complex constraints and relationships.
The Zebra Puzzle
The Zebra Puzzle is a classic logic puzzle that involves five houses, each with a different color, nationality, pet, drink, and cigarette brand. The goal is to determine who owns the zebra and who drinks water, based on a set of clues.
Modeling the Puzzle
We can model this puzzle in ASP by representing each clue as a logical rule. The following ASP code provides a basic structure for the Zebra Puzzle:
% There are five houses.
house(1..5).
% The Englishman lives in the red house.
i2 :- house(C), colored(C, red), owner(C, english).
% The Spaniard owns the dog.
i3 :- house(C), owner(C, spanish), owns(C, dog).
% The Ukrainian drinks tea.
i4 :- house(C), owner(C, ukrainian), drinks(C, tea).
% The green house is immediately to the right of the ivory house.
i5 :- house(C1), house(C2), colored(C1, ivory), colored(C2, green), next(C1, C2).
% The Old Gold smoker owns snails.
i6 :- house(C), smokes(C, old_gold), owns(C, snails).
% Kools are smoked in the yellow house.
i7 :- house(C), colored(C, yellow), smokes(C, kools).
% Milk is drunk in the middle house.
i8 :- house(C), middle(C), drinks(C, milk).
% The Norwegian lives in the first house.
i9 :- house(C), first(C), owner(C, norwegian).
% The man who smokes Chesterfields lives in the house next to the man with the fox.
i10 :- house(C1), house(C2), smokes(C1, chesterfield), owns(C2, fox), next(C1, C2).
% Kools are smoked in the house next to the house where the horse is kept.
i11 :- house(C1), house(C2), smokes(C1, kools), owns(C2, horse), next(C1, C2).
% The Lucky Strike smoker drinks orange juice.
i12 :- house(C), smokes(C, lucky_strike), drinks(C, orange_juice).
% The Japanese smokes parliaments.
i13 :- house(C), owner(C, japanese), smokes(C, parliaments).
% The Norwegian lives next to the blue house.
i14 :- house(C1), house(C2), owner(C1, norwegian), colored(C2, blue), next(C1, C2).
% Auxiliary predicates
left_to_right(C1, C2) :- C1 = C2 - 1.
next(C1, C2) :- left_to_right(C1, C2).
next(C1, C2) :- left_to_right(C2, C1).
middle(3).
first(1).
% Ensure all clues are satisfied.
hints :- i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14.
:- not hints.
% Assign exactly one value to each attribute for each house.
1 { owner(H, english; spanish; ukrainian; norwegian; japanese) } 1 :- house(H).
1 { colored(H, red; green; ivory; yellow; blue) } 1 :- house(H).
1 { owns(H, dog; snails; fox; horse; zebra) } 1 :- house(H).
1 { drinks(H, tea; coffee; milk; orange_juice; water) } 1 :- house(H).
1 { smokes(H, old_gold; kools; chesterfield; lucky_strike; parliaments) } 1 :- house(H).
In this encoding:
house(1..5)defines the five houses.i2, i3, ... i14represent the clues of the puzzle as logical rules.left_to_right, next, middle, firstare auxiliary predicates to help define the relationships between houses.hintsensures that all the clues are satisfied.The last set of rules ensures that each house has exactly one owner, color, pet, drink, and cigarette brand.
Solving the Puzzle
By running an ASP solver on this encoding, we can obtain a solution that satisfies all the constraints. The solution will reveal who owns the zebra and who drinks water.
The Jobs Puzzle
The Jobs Puzzle involves four people (Roberta, Thelma, Robin, and Pete) and eight jobs. Each person holds exactly two jobs. The goal is to assign the correct jobs to each person based on a set of clues.
Modeling the Puzzle
The ASP encoding for the Jobs Puzzle is as follows:
person(roberta; thelma; robin; pete).
job(chef; guard; nurse; telephone_operator; police_officer; teacher; actor; boxer).
% Each person has two jobs.
2 { work_as(P, J) : job(J) } 2 :- person(P).
% Each job is assigned to one person.
1 { work_as(P, J) : person(P) } 1 :- job(J).
% Clues
male(robin; pete).
female(roberta; thelma).
% The job of nurse is held by a male.
:- work_as(A, nurse), female(A).
% The husband of the chef is the telephone operator.
:- work_as(A, telephone_operator), female(A).
husband_of(A, B) :- work_as(A, telephone_operator), male(A), work_as(B, chef), female(B).
% Roberta is not a boxer.
:- work_as(roberta, boxer).
% Pete has no education past the ninth grade.
:- work_as(pete, nurse).
:- work_as(pete, teacher).
:- work_as(pete, police_officer).
% Roberta, the chef, and the police officer went golfing together.
:- work_as(roberta, chef).
:- work_as(roberta, police_officer).
:- work_as(A, chef), work_as(A, police_officer).
In this encoding:
personandjobdefine the individuals and the jobs.The cardinality constraints
2 { work_as(P, J) : job(J) } 2 :- person(P).and1 { work_as(P, J) : person(P) } 1 :- job(J).ensure that each person has exactly two jobs and each job is assigned to exactly one person.maleandfemaledefine the gender of each person.The remaining rules encode the clues of the puzzle as constraints.
Solving the Puzzle
An ASP solver can find the unique assignment of jobs that satisfies all the given constraints, providing the solution to the puzzle.
The Sorcerer’s Apprentice
This puzzle involves finding a sorcerer’s apprentice among three people, based on their statements and the constraint that at most one of them tells the truth.
Modeling the Puzzle
The ASP encoding for the Sorcerer’s Apprentice puzzle is as follows:
man(a; b; c).
% Only one is the apprentice.
1 { apprentice(X) : man(X) } 1.
% Statements
holds(a_apprentice) :- apprentice(a).
holds(b_apprentice) :- apprentice(b).
holds(at_most_one_knight) :- 0 { knight(X) : man(X) } 1.
% Who said what
says(a, a_apprentice).
says(b, b_apprentice).
says(c, at_most_one_knight).
% Rules for lying (same as before)
:- says(A, F), knight(A), not holds(F).
:- says(A, F), knight(A), holds(F).
:- says(A, F), knave(A), holds(F).
:- says(A, F), knave(A), not holds(F).
% Apprentice is a knave
apprentice(X) :- knave(X).
In this encoding:
mandefines the individuals in the puzzle.1 { apprentice(X) : man(X) } 1.ensures that exactly one person is the apprentice.holdsdefines the truth of the statements.saysrepresents the statements made by each person.The rules for lying are the same as in the Knights and Knaves puzzle.
apprentice(X) :- knave(X).states that the apprentice is a knave.
Solving the Puzzle
An ASP solver can identify the sorcerer’s apprentice based on the given information, providing a solution to the puzzle.
Conclusion
This lecture has demonstrated the power and versatility of Answer Set Programming (ASP) in modeling and solving problems that require common sense reasoning. We have explored the inherent limitations of classical logic, particularly its monotonic nature, and highlighted the advantages of non-monotonic logic, which is naturally supported by ASP. By applying ASP to a variety of logic puzzles, we have seen how complex relationships and constraints can be encoded and solved efficiently.
Suitability of ASP for Common Sense Reasoning: ASP is well-suited for modeling common sense reasoning due to its ability to handle non-monotonicity, allowing for the retraction of conclusions in light of new information.
Stable Model Semantics: Stable model semantics provides a clear and intuitive way to interpret ASP programs, making it easier to understand the logical consequences of the encoded rules.
Logic Puzzles as Illustrative Examples: Logic puzzles serve as excellent examples for illustrating the power and flexibility of ASP, showcasing its ability to handle complex constraints and relationships.
Importance of Hidden Information and Context: Hidden information and context are crucial when modeling real-world problems, and ASP allows us to incorporate these aspects into our models.
How can we extend these techniques to handle more complex scenarios with uncertainty and incomplete information?
What are the limitations of ASP, and when might other approaches be more suitable?
How can we automatically generate explanations from ASP solutions, making the reasoning process more transparent?
How can we integrate ASP with other AI techniques, such as machine learning, to create more powerful hybrid systems?
In the next lecture, we will:
Explore different types of non-monotonic reasoning, delving deeper into the theoretical foundations of this approach.
Investigate advanced ASP features, such as aggregates and choice rules, to handle more complex modeling scenarios.
Consider the application of ASP to real-world problems in areas like planning, diagnosis, and configuration, demonstrating its practical utility.
Discuss the relationship between ASP and other declarative programming paradigms, highlighting the connections and differences between these approaches.