logics. the lecture set theory boolean logic logic reasoning fuzzy sets fuzzy logic fuzzy reasoning...
TRANSCRIPT
Logics
The lecture
• Set theory• Boolean Logic• Logic reasoning
• Fuzzy sets• Fuzzy logic• Fuzzy reasoning• Implementing fuzzy logic in Java
Paradoxes and impossibilities
• Zeno’s
• Cantor
• Russell
• Gödel
• Turing
Logic - classic
Basic set theory
• (Naïve or basic) Set theory was developed at the end of the 19th century (principally by Georg Cantor and Frege) in order to allow mathematicians to work with infinite sets consistently.
• A set is described as a collection of objects. Those objects that belong to a set are called its members.
• If x is a member of A, then we also say that x is an element of A, or that x belongs to A, or that x is in A, or that A owns x, that is expressed by x ∈ A.
• We define two sets to be equal when they have precisely the same elements (denoted symbolically as A = B ).
Basic set theory (cont.)
• The simplest way to describe a set is to list its elements between curly braces. Thus {1,2} denotes the set whose only elements are 1 and 2. Note the following points: – Order of elements is immaterial; for example, {1,2} = {2,1}.
– Repetition of elements is irrelevant; for example, {1,2,2} = {1,1,1,2} = {1,2}.
• We can also use the notation {x | P(x)} to denote the set containing all objects for which the condition P holds. For example:– {x | x is a dog} denotes the set {dogs} of all dogs.
Basic set theory (cont.)
• Subsets: given two sets A and B we say that A is a subset of B, if every element of A is also an element of B.
A 3
5
2
6
Universe
A = {2,6}U = { 2,3,5,6}
A subset U
2 A
3 A
Venn diagrams
Basic set theory (cont.)
Intersections, unions, and relative complements • Given two sets A and B, we may construct their union. This is the
set consisting of all objects which are elements of A or of B or of both. It is denoted by A ∪ B.
• The intersection of A and B is the set of all objects which are both in A and in B. It is denoted by A ∩ B.
• Finally, the relative complement of B relative to A, is the set of all objects that belong to A but not to B. It is written as A \ B.
Symbolically, these are respectively: • A B∪ := { x | (x ∈ A) or (x ∈ B) } • A ∩ B := { x | (x ∈ A) and (x ∈ B) }• A \ B := {x | (x ∈ A) and not (x ∈ B) }
Basic set theory (cont.)
A 3
6
Universe
2
5
B
A = {2,6}B = {2,5}U = { 2,3,5,6}
A ∩ B = { 2 }
Intersection
Basic set theory (cont.)
A 3
6
Universe
2
5
B
A = {2,6}B = {2,5}U = { 2,3,5,6}
A ∪ B = { 2,5,6 }
Union
Basic set theory (cont.)
• Now let E be the set of all human beings, and let F be the set of all living things over 1000 years old.
• What is E ∩ F in this case? No human being is over 1000 years old, so E ∩ F must be the empty set {}.
• Cardinality:#A = number of elements of A
If A={1,4,6} then #A = 3#{} = 0#N = infinity
Basic set theory - links
• Evolution of set theory http://en.wikipedia.org/wiki/Set_theory
• http://en.wikipedia.org/wiki/Basic_Set_Theory
• Venn diagrams http://en.wikipedia.org/wiki/Venn_diagram
Boolean algebra
• It is named after George Boole, an Englishman, who first defined them as part of a system of logic in the mid 19th century.
• Boolean algebra was an attempt to use algebraic techniques to deal with expressions in the propositional calculus.
• Today, Boolean algebras find many applications in electronic design.
Boolean algebra (cont.)
We needA set {0,1} and three operators , ∧ ∨ , ¬
Boolean algebra (cont.)
p | q | p ∧ q | p ∨ q | ¬ p
0 | 0 | 0 | 0 | 1
0 | 1 | 0 | 1 | 1
1 | 0 | 0 | 1 | 0
1 | 1 | 1 | 1 | 0
Boolean algebra (cont.)
Visualizing Operators
Another way:http://florin.syr.edu/webarch/searchpro/boolean_tutorial.html
p
Universe
q
U = 1
{ } = 0
p ∩ q = p ∧ q
p ∪ q = p ∨ q
p\U = ¬ p
Boolean algebra (cont.)
p ∧ q = ¬ ( ¬ p ∨ ¬ q ) (X)
p ∨ q = ¬ ( ¬ p ∧ ¬ q )
De Morgan’s rules
Visual proof of De Morgan rule (X)
pU
q
p ∩ q = ( p\U ∪ q\U ) \U
pU
q
p ∩ q = ( p\U ∪ q\U ) \U
p\U
pU
q
q\U
( p\U ∪ q\U )
pU
q
( p\U ∪ q\U ) \U
pU
q
Boole and boolean algebra - links
• http://en.wikipedia.org/wiki/Boole• http://en.wikipedia.org/wiki/Boolean_algebra• http://en.wikipedia.org/wiki/Logic_gate • What's so logical about boolean algebra?
http://www.home.gil.com.au/~bredshaw/boolean.htm
• http://www2.kcma.edu/library2/boolean.html
Logic• Formal logic, also called symbolic logic, is concerned
primarily with the structure of reasoning. Formal logic deals with the relationships between concepts and provides a way to compose proofs of statements. In formal logic, concepts are rigorously defined, and sentences are translated into a precise, compact, and unambiguous symbolic notation.
• Some examples of symbolic notation are: p: 1 + 2 = 3
• This statement defines p is 1 + 2 = 3 and that is true. • Two propositions can be combined using the operations of
conjunction, disjunction or conditional. These are called binary logical operators. Such combined propositions are called compound propositions. For example:p: 1 + 1 = 2 and "logic is the study of reasoning."
http://en.wikipedia.org/wiki/Propositional_calculus
Predicate logic (Gottlob Frege)
• Sentential logic explains the workings of words such as "and", "but", "or", "not", "if-then", "if and only if", and "neither-nor". Frege expanded logic to include words such as "all", "some", and "none". He showed how we can introduce variables and "quantifiers" to rearrange sentences.
• "All humans are mortal" becomes "All things x are such that, if x is a human then x is mortal." which may be written symbolically
Predicate logic (cont.)
• "Some humans are vegetarian" becomes "There exists some (at least one) thing x such that x is human and x is vegetarian" which may be written symbolically
• Frege's work started contemporary formal logic.
Predicate logic (cont.)
p | q | p q | p q | p xor q
0 | 0 | 1 | 1 | 0
0 | 1 | 1 | 0 | 1
1 | 0 | 0 | 0 | 1
1 | 1 | 1 | 1 | 0
p q ∧ q p = p q
Special cases!
p ¬∧ p = falsep ¬∨ p = true
Modus ponens
a b , a------------ b
Example: (MonsterAhead ∧MonsterAlive) Shoot , (MonsterAhead ∧MonsterAlive)----------------------------------------------------------------------------------------------------
Shoot
1- If the monster is ahead and it is alive then I should shoot.2- I know that ” the monster is ahead and it is alive ”3- Then I infer: we have to shoot!
Wumpus worldWumpus: The central monster (and, in many versions, the name) of a famous family of very early computer games called "Hunt The Wumpus'. The original was invented in 1970 by Gregory Yob.
The wumpus lived somewhere in a cave; the player started somewhere at random in the cave with one arrow, that would kill the wumpus on a hit.
Unfortunately for players, the movement necessary to map the maze was made hazardous not merely by the wumpus (which would eat you if you stepped on him) but also by bottomless pits.
Play with the wumpushttp://www.taylor.org/~patrick/wumpus/
Definition:http://info.astrian.net/jargon/terms/w/wumpus.html
http://scv.bu.edu/htbin/wcl
Wumpus world (cont.)
The wumpus is a terrible beast of whom none as lived to describe. The only real things known is that it generally sleeps in one place unless disturbed, has very strong smell which can be smelt in neibouring rooms. In our version it is not moving!
When you are close to a pit (1 cell distance), you feel a breeze.
Wumpus world (cont.)
In a square the agent gets a vector of percepts, with components Stench,Breeze,Glitter,Bump,Scream
For example [Stench,None,Glitter,None,None]
• Stench is perceived at a square iff the wumpus is at this square or in its neighborhood.
• Breeze is perceived at a square iff a pit is in the neighborhood of this square.
• Glitter is perceived at a square iff gold is in this square • Bump is perceived at a square iff the agent goes Forward into a wall • Scream is perceived at a square iff the wumpus is killed anywhere in the
cave
Wumpus world (cont.)
An agent can do the following actions (one at a time): Turn(Right), Turn(Left), Forward, Shoot, Grab, Release, Climb
• The agent can go Forward in the direction it is currently facing, or Turn Right, or Turn Left. Going Forward into a wall will generate a Bump percept.
• The agent has a single arrow that it can Shoot. It will go straight in the direction faced by the agent until it hits (and kills) the wumpus, or hits (and is absorbed by) a wall.
• The agent can Grab a portable object at the current square or it can Release an object that it is holding.
• The agent can Climb out of the cave if at the Start square.
Wumpus world (cont.)
Reasoning
BreezeAt(2,2) ( PitAt(2,3) ∨ PitAt(1,2) ∨ PitAt(2,1) ∨ PitAt(3,2) )
Then we step into 2,3 and there is no pit there, so we move in 3,3 and there is no breeze:
BreezeAt(2,2)∧ ¬ PitAt(2,3) ∧ ¬BreezeAt(3,3)
We infer that there cannot be a pit in 3,2!!
(...using inference rules)
The pit must be in 1,2 or 2,1.
2,2
2,3
3,2
2,1
1,2
2,2
¬ P
3,2
2,1
1,2
¬ B
Logic - links
• Definition and history of Logic: http://en.wikipedia.org/wiki/Logic#Formal_logic
• Predicate logic http://en.wikipedia.org/wiki/Logic#Predicate_logic
• http://en.wikipedia.org/wiki/Propositional_calculus • Wumpus world
http://www.cis.temple.edu/~ingargio/cis587/readings/wumpus.shtml
http://www.math.vanderbilt.edu/~schectex/logics/
Logic - fuzzy
Fuzzy set theory
• Fuzzy sets are an extension of the classical set theory.
• A fuzzy set is characterized by a membership-degree function, which maps the members of the universe into the unit interval [0,1].
• The value 0 means that the member is not included in the given set, 1 describes a fully included member (this behaviour corresponds to the classical sets).
• The values between 0 and 1 characterize fuzzy members.
Fuzzy set theory (cont.)
Let’s define the fuzzy set Young. • The universe is the set of all persons,• The membership function is defined as:
0, if age<=15...
m( age ) = 1 , if age=35...0, if age>=55
Fuzzy set theory (cont.)
35
20
0
1
15 5535
YoungAge m-ship
10 015 020 0.430 0.635 140 0.650 0.460 0
Fuzzy set theory (cont.)
35
20
0
1
15 5535
Young
ClassicVersion!
Fuzzy set theory (cont.)
35
20
0
1
15 5535
Young
Anothermembershipfunction!
Fuzzy set theory (cont.)
35
20
0
1
15 5535
Young
We can complement a fuzzy set!
0
1
15 5535
m1(x)
m2(x) = 1-m1(x)
Fuzzy set theory (cont.)
35
20
0
1
15 5535
Young Old
70
20
Where ”Old” is from 50 to 90.
0
1
50 9070
Fuzzy sets can intersect!
Fuzzy set theory (cont.)
0
1
15 5535
0
1
50 9070
Young
Old
0
1
50
Young Old
m3(x) = min( m1(x),m2(x) )
m1(x)
m2(x)
m3(x)55
You are Young and Old if you are aroung 52.5!
Fuzzy set theory (cont.)
35
20
0
1
15 5535
Young Old
70
20
0
1
50 9070
Fuzzy sets can be united!
Fuzzy set theory (cont.)
0
1
15 5535
0
1
50 9070
Young
Old
0
1
50
Young Old
m4(x) = max( m1(x),m2(x) )
m1(x)
m2(x)
m4(x)55
You are Young or Old if you are from 15 to 90!
Fuzzy set theory (cont.)
• Implementation -> the interpreter pattern
ApplicationFuzzySet
Membership
MembershipFunction
Complement
Intersect Union
center , width
Fuzzy set theory (cont.)
ApplicationFuzzySet
Membership
MembershipFunction
Complement
Intersect Union
center , width
1
1
1
1
2
{x|m(x)>0} , m(x):[10.0;40.0] -> [0;1] , center=25.0
{x|m(x)>0} , m(x):[25.0;75.0] -> [0;1] , center=50.0
-----
Age=30 => young:0.666
Age=30 => old:0.199
------------------------------
Age=30 => notYoung:0.333
------------------------------
Age=30 => young Intersection old:0.199
------------------------------
Age=30 => young Union old:0.666
------------------------------
Fuzzy set theory - links
• Membership-degree function http://en.wikipedia.org/wiki/Fuzzy_set
• Used in: http://en.wikipedia.org/wiki/Artificial_intelligence
• FUZZY FAQ: http://www-2.cs.cmu.edu/Groups/AI/html/faqs/ai/fuzzy/part1/faq.html
• What is: http://www-2.cs.cmu.edu/Groups/AI/html/faqs/ai/fuzzy/part1/faq-doc-2.html
• An example: http://www.rpi.edu/dept/chem-eng/Biotech-nviron/Fuzzy/fuzzy_sets.html
Fuzzy Logic
Operation Definition
fuzzy AND (f-AND) a f-AND b = min(a,b)
fuzzy OR (f-OR) a f-OR b = max(a,b)
(same as unary NOT) not a = 1-a
• Fuzzy logic is an organized method which allows computer programs to deal with the imprecision of data, especially that which deals with human reasoning.• In reality, information is often puzzling and unclear. However, people have the ability to sort through muddled information and come out with sound conclusions. • In fuzzy logic, the imprecise data being considered are called fuzzy sets.
[ FROM: http://www.rpi.edu/dept/chem-eng/Biotech-Environ/Fuzzy/ ]
Fuzzy Logic (cont.)
• Very is usually defined as follows: very m(x) = m(x)2
• More_or_lessmoreOrLess m(x) = sqrt( m(x) )
Exercise: try and implement these two operators in the FuzzySet implementation.(Suggestion: take inspiration from the Complement class)
Fuzzy Logic (cont.)
Use of fuzzy logicI’m a monster (in a video-game).
1- If the player’s character (hero) is far I ramble
2- If the hero is very close I attack
3- If I’m wounded badly I run away from the hero
I can have 3 fuzzy sets (so 3 membership functions):
1. far(x) = someFunctionOf ( distance(monster,x) )
2. VeryClose(x) = very( not far(x) )
3. wounded(x) =
0
1
5535 100
Fuzzy Logic (cont.)
How to decide what to do?I will have 3 values, at each step: f,vc,w in [0,1]So I should:
ramble * f +attack * vc +runAway * w = myAction!
For example: f=0.3 , vc=0.49 , w=0.25Then I should
ramble for 30% (I move randomly about with a small speed) attack for some 49% (so maybe I prepare to bite)
runAway for a 25% (so my direction is away from the hero, but my speed is small)
And then I produce my action!(it is simpler with numerical parameters)
Fuzzy Logic - links
• A good intro: http://en.wikipedia.org/wiki/Fuzzy_logic
• Index of links: http://www.calresco.org/links.htm#fuzz
Paradoxes and impossibilities
Paradoxes in logic
This sentence is false!
x = 1 – x , with x in {0,1}
x = 1 -> x = 0 -> x = 1 -> ...
Magritte Treason-of-imageFuzzy Version:x = 1 – x , with x in [0,1]
x = 0.5 !!!
Paradox of Omnipotence
Take an omnipotent genie and wish that he creates a stone that he cannot lift.
1. He can do that -> then he cannot lift the stone, so his omnipotence is gone!
2. He cannot do that -> so he was not omnipotent after all!!
Paradoxes of Infinity
Zeno’s paradoxes
http://plato.stanford.edu/entries/paradox-zeno
...?
How many parts are there in a finite object?
If the arrow is still at each step, how can it be moving at all ?!
Zeno’s paradoxes (cont.)
http://plato.stanford.edu/entries/paradox-zeno
Velocity is a tricky concept!
?
What is the velocity of A from the point of view of B?And which w.r.t. C??How can A have 2 velocities?!?
BA
C
Infinity
• Recall that cardinality is the number of elements of a set.• We can invent a name for the #NaturalNumbers, and say
that it is 0 ( aleph0 )• Georg Cantor developed a system of transfinite numbers,
in which the first transfinite cardinal is aleph0 .
• Do the sets {1,2,3} and {a,b,c} have the same size? • Yes, because we can define the correspondence
a ↔ 1, b ↔ 2, c ↔ 3
• so that every element of {a,b,c} is paired with precisely one element of {1,2,3} (and vice versa): this defines a bijection
Infinity (cont.)
• We now generalise this situation and define two sets to be of the same size (same cardinality) precisely when there is a bijection between them.
• Consider– N = {1,2,3,...} the set of all natural numbers
– and E = {2,4,6,...} the set of even numbers.
• If we can fine a bijection between N and E, the 2 sets have the same size! And we can say that B is countably infinite.
• It is easy: 1 ↔ 2, 2 ↔ 4, 3 ↔ 6, 4 ↔ 8, ...
So the even numbers are as many as the natural numbers!Or: #N = #E , even if E is a proper subset of N!!!
Infinity (cont.)
• What about sets being "larger than" N?
• For example I, the set of all integers: I={...,-1,0,+1,2,...}
The bijection here is:
1 2 3 4 5 6
0 -1 1 -2 2 -3
which is given by:
f(n) = { -n/2 , if n even
{ (n-1)/2 , if n odd
So the integer numbers are as many as the natural numbers!Or: #N = #I , even if N is a proper subset of I!!!
http://www.mpcs.ryerson.ca/~mth314/Handouts/car.pdf
Infinity (cont.)
http://planetmath.org/?op=getobj&from=objects&name=ProofThatTheRationalsAreCountable
• What about Q, the set of all rational numbers (ie fractions), which is clearly much bigger than N?
Infinity (cont.)
The bijection here is: 1 2 3 4 5 6 ...1/1 1/2 2/1 3/1 2/2 1/3 ...
So also the rational numbers are as many as the natural numbers!Or: #N = #Q , even if N is a proper subset of Q!!!
Infinity (cont.)
http://planetmath.org/encyclopedia/CantorsDiagonalArgument.html
#N = 0 = #E = #I = #Q
The results so far:
What about , the set of all irrational numbers (ie real numbers)? What is its cardinality??
Maybe the whole is too BIG, so why don’t we start with the interval [0,1], which is a subset of , and try to see if we can define a bijection from natural numbers onto [0,1]...
Infinity (cont.)
Cantor’s diagonalizationWe can try and make a list of all the real numbers in [0,1] and
give each one an index (a natural number).
1 0,000000000000000000000000...
2 0,1204832092002000283932 ...
3 0,23430054500000123090050...
4 0,260380505005031930960329...
5 0,30805040530313093273920...
6 0,50389325540760985939282...
... ...
Infinity (cont.)
Is this list complete?We can try to show a real number that is not in the table. To do that we take the
diagonal of the table:
0,013009...
1 0,000000000000000000000000...
2 0,11204832092002000283932 ...
3 0,123430054500000123090050...
4 0,1680380505005031930960329...
5 0,305805040530313093273920...
6 0,510389325540760985939282...
... ...
Infinity (cont.)
Then we change each digit with the next digit (1->2, ... 9->0):
0,013009... -> 0,124110...
This number cannot be in the table!
1 0,000000000000000000000000...
2 0,11204832092002000283932 ...
3 0,123430054500000123090050...
4 0,1680380505005031930960329...
5 0,305805040530313093273920...
6 0,510389325540760985939282...
... ...
0,124110...
0,124110...
0,124110...
0,124110...
0,124110...
0,124110...
Infinity (cont.)
ConclusionIt is impossible to make a complete list of real numbers in
[0,1] and count them with natural numbers. Using the diagonal-argument, we can show that the list is
never complete, so:
Real numbers (even the interval [0,1]) are MORE INFINTE than natural numbers!
So we can say that #N = 0 < # = 1
1 is also called the continuum!
Infinity - links• http://en.wikipedia.org/wiki/Georg_Cantor
• http://community.middlebury.edu/~schar/Courses/fs023.F02/presentations/cantor.htm
• A little story of infinity: http://en.wikipedia.org/wiki/Infinity
• On Cantor– http://planetmath.org/?op=getobj&from=objects&name=
ProofThatTheRationalsAreCountable
– http://www.mpcs.ryerson.ca/~mth314/Handouts/car.pdf
– BOOK: http://www.4w8w.com/bookrucker3.html • Escher (animation) http://becontent.de/escher/infinity_2.html • Tutorial http://www.mathacademy.com/pr/minitext/infinity/index.asp• Zeno’s paradoxes http://plato.stanford.edu/entries/paradox-zeno/
The barber paradoxThe paradox considers a town with a male barber who daily shaves every man who does not shave himself, and no one else.
Such a town cannot exist, infact:•If the barber does not shave himself, he must bide by the rule and shave himself. •If he does shave himself, according to the rule he will not shave himself.
This is then an impossible situation!
The barber paradox (cont.)
http://www.tutorgig.com/encyclopedia/getdefn.jsp?keywords=Russell's_paradoxhttp://www.tutorgig.com/encyclopedia/getdefn.jsp?keywords=Barber_paradox
Consider the set M to be "The set of all sets that do not contain themselves as members". Does M contain itself?
1.If it does, it is not a member of M according to the definition. 2.On the other hand, if we assume that M does not contain itself, then it has to be a member of M, again according to the very definition of M. Therefore, the statements "M is a member of M" and "M is not a member of M" both lead to contradictions.
banana1
banana35
banana1
banana35 banana99
A set of bananas
A set of sets of bananas
The set of all the sets (of bananas), contains itself!
Gödel’s theorem
Gödel was able to demonstrate that any formal system (such as mathematics) is inherently incomplete.
He explained that there are truths that exist in a system that are not provable using the rules of the system. An unprovable truth is known as a “Gödel Sentence” (G) and all formal systems contain them.
In Gödel’s demonstration he was able to show that the truth and certainty of any system was inherently flawed.
For example a Gödel sentence would be similar to the following: There is no way to prove this rule.
Turing’s HALT problem• A program can:
– Compute for sometimes, then produce an output– Go in loop and cycle forever without answering.
• Can there be a program capable of checking every program and tell if it will go in loop or finish and give an answer??
• If such a program exists we can call it A. By definition A is able to take another program and tell if it will halt or loop. We then write a program Z that will halt everytime A will loop and vice versa. What happens if we ask A to judge Z???
• (this is like the genie!)
Turing’s HALT problem
Gödel's incompleteness theorem•http://en.wikipedia.org/wiki/G%F6del
%27s_incompleteness_theorem
•http://mathworld.wolfram.com/HaltingProblem.html
http://mathworld.wolfram.com/UniversalTuringMachine.html
Exercises
• Implement the fuzzy logic very operator on top of the FuzzySet program.
• Try and code a 4x4 world class (as a subclass of the Environment) and try to implement the wumpus world. Use the sensors described for the wumpus world, but do not include the rotation in the actions for the hero.Create a class Hero (subclass of the Agent) that will be an agent able to survive in the wumpus world. What kind of performance measure can we adopt for this agent? Each Hero can have a map (bi-dimensional array, 4x4) representing its world, and at each step the map is filled with as many infos as possible. Use some IFs to fill the mental-map so that the Hero can navigate safely (avoiding pits, when possible) and the Wumpus!
• Discuss a possible genetic-algorithm implementation of the Hero-agent. What informations do you need to write in its DNA?
Links• Set theory http://en.wikipedia.org/wiki/Basic_Set_Theory • Logic
– Visual tutorial of logic: http://www.logictutorial.com/– http://en.wikipedia.org/wiki/G%F6del
• Fuzzy Logic– http://www.abo.fi/~rfuller/fuzs.html – http://en.wikipedia.org/wiki/Fuzzy_set – http://www.comp.nus.edu.sg/~pris/FuzzyLogic/FuzzyLogicIndex.html (also source
code in Java)– http://www.cse.dmu.ac.uk/~rij/newrep/node4.html – http://www.austinlinks.com/Fuzzy/tutorial.html
• Paradoxes in set theory http://en.wikipedia.org/wiki/Naive_set_theory#Paradoxes
• Russell’s paradox – http://en.wikipedia.org/wiki/Russell%27s_Paradox – http://en.wikipedia.org/wiki/Barber_paradox
Extra
• http://www-personal.umich.edu/~jlawler/geb.html
• Can Humans Escape Gödel? http://psyche.cs.monash.edu.au/v2/psyche-2-04-mccullough.html
• Gödel's Theorem and Information http://www.cs.auckland.ac.nz/CDMTCS/chaitin/georgia.html