Professional Documents
Culture Documents
First Order Logic
First Order Logic
Easy.
I choose a trillion trillion.
The proof:
Let x be an arbitrary integer.
Let y = x+1
Note y = x+1 >x
Good game.
Let me try again. I will win this time!
Understand Quantifiers!!!
Loves(b,g) Sam Mary
Bob Beth
Marilin
John
Monro
Fred Ann
A relation/predicate
• returns True/False
• depending whether objects
b and g have relation Loves.
Loves(Sam,Mary) = False
Loves(Sam,Beth) = True
Understand Quantifiers!!!
Loves(b,g) Sam Mary
Bob Beth
Marilin
John
Monro
Fred Ann
Sam Mary
Bob Beth
Marilin
John
Monro
Fred Ann
His special woman.
Understand Quantifiers!!!
Sam Mary
Bob Beth
Marilin
John
“There is a girl whom every boy loves” Monro
Fred Ann
“There is a inverse (eg 1/3) for all reals.”One girl
Sam Mary
Not clear.
Bob Beth
Marilin
John
Monro
Fred Ann
Could be a separate girl.
Sam Mary
Bob Beth
“For each boy, there is a girl.” John
Marilin
Monro
“For each person, there is God.” Fred Ann
His special woman.
Understand Quantifiers!!!
Sam Mary
Bob Beth
Marilin
John
Monro
Fred Ann
One girl
Sam Mary
$g, "b, Loves(b, g) Bob Beth
Marilin
John
"b, $g, Loves(b, g)
Monro
Fred Ann
Could be a separate girl.
Sam Mary
Bob Beth
Marilin
John
Monro
Fred Ann
His special woman.
Understand Quantifiers!!!
$g, "b, Loves(b, g, date) Sam Mary
Property (date)
Bob Beth
Marilin
John
Monro
Let’s understand this deeply One girl
Fred Ann
$ g , Property (g)
Bob Beth
Marilin
John
Monro
Let’s understand this deeply One girl
Fred Ann
bProperty(g)
, Property g ( b
Bob Beth
Marilin
John
Monro
Let’s understand this deeply One girl
Fred Ann
Bob Beth
Marilin
John
Monro
Fred Ann
Understand Quantifiers!!!
Proof: "b, $g, Loves(b, g)
They read the statement left to right.
Bob Beth
Marilin
Sam A Beth John
Monro
Fred Ann
Fred Ann
Understand Quantifiers!!!
Negations: Ø[ $g, "b, Loves(b, g) ]
= "g, Ø[ "b, Loves(b, g) ]
= "g, $b, Ø[ Loves(b, g) ]
= "g, $b, ØLoves(b, g)
Ø moves right
$ "
=
Reals
Build understanding by building the
"x, $y, x+y=0 statement backwards.
$y, "x, x+y=0 What does each subsequence say
about its free variables.
$y, "x, x+y=x (with little emphasis on the bound
2 -2 variables.)
x+y=0 “y is the additive inverse of x”.
$y, x+y=0 “x has an additive inverse”.
"x, $y, x+y=0 “Every real has an additive inverse”.
x+y=0 “x is the additive inverse of y”.
"x, x+y=0 “Every real is an additive inverse of y.
$ y, "x, x+y=0 “Some real has every real as an inverse”.
x+y=x “Adding y does not change x”.
"x, x+y=x “Adding y makes no changes”.
$ y, "x, x+y=x “There is an additive zero”.
Reals
Proof: "x, $y, x+y=0 true (additive inverse)
Let y = -x.
Let x=-y+1
The relation is false.
x+y = (-y+1) + y ≠ 0
Yup
Reals
Proof: "x, $y, x+y=0 true (additive inverse)
$y, "x, x+y=0 false
$y, "x, x+y=x true (additive zero)
Let y = 0.
Let y = 1/x.
If x= 0, let y=5.
Else let y= 1/x . I can
always win.
x=a or x×y=1 is always Hence,
true. the statement
If x= 0, then x=a. is true.
1
Playing Game White moves.
Who wins? Black moves.
White wins
Black wins
Playing Game White moves.
Who wins? Black moves.
White wins
Black wins
Playing Game White moves.
Who wins? Black moves.
White wins
Black wins
Playing Game White moves.
Who wins? Black moves.
M1w M1b White wins
Black wins
Black has a
winning strategy
White wins
White has a
winning strategy
f(n) = θ(g(n))
c 1, c 2, n 0, n n 0, c 1 g ( n ) f ( n ) c 2 g ( n )
f(n) is sandwiched between c1g(n) and c2g(n)
for some sufficiently small c1 (= 0.0001)
Classifying Functions
f(n) = θ(g(n))
c 1, c 2, n 0, n n 0, c 1 g ( n ) f ( n ) c 2 g ( n )
For all sufficiently large n
For some definition of “sufficiently large”
Classifying Functions
Proof: $c,n0, "n≥n0, 8n2+1000n ≤ cn2 true
Let c=9 & n0=1000.
Let n be an arbitrary real number
≥1000
The relation is true.
8n2+1000n ≤ 8n2+n2 = 9n2 = cn2
Let c=2n.
The relation is true.
2n ≤ 2nn = cn
Classifying Functions
Theta f(n) = θ(g(n)) f(n) ≈ c g(n)
BigOh f(n) = O(g(n)) f(n) ≤ c g(n)
Omega f(n) = Ω(g(n)) f(n) ≥ c g(n)
Little Oh f(n) = o(g(n)) f(n) << c g(n)
Little Omega f(n) = ω(g(n)) f(n) >> c g(n)
3n2 + 7n + 8 = nθ(1)
Polynomial time
3n n = 2[ log(3) n + log n ]
= 2θ(n)
Exponential time
An Algorithm/Program/Machine M is
• a set of instructions
(described by a finite string “M”)
• on a given input I
• follow instructions and
• produces output M(I)
• or runs for ever.
Eg: Insertion Sort
Computable Problem
Problem P is
computable if
$M, "I, M(I)=P(I)
$M,“Machine/Algorithm M
computes problem P.”
"I, “Machine/Algorithm M
gives the answer required
by problem P on input I.”
M(I)=P(I)
Computable Problem
Problem P is
computable if
$M, "I, M(I)=P(I)
I have a machine M that I
claim works.
Oh yeah, I have an input I for
which it does not.
I win if M on input I gives
the correct output
Computable mean
that some algorithm
computes it.
Computable with Fixed Resources
Note that the number of line
in a print out of the code
does not actually depend on
the input
Computable with Fixed Resources
I give an “alg”
with input b,
and output an g
Sam Mary
and a proof that
Loves(b, g). Bob Beth
$bBoys, ØLoves(b, g)
properties of the b
in the set Boys.
Understand Quantifiers!!!
Negations: "x $yx, y=2x
What is the negation of this?
$x "y<x, y2x
$x "yx, y2x
No, we are still talking about
properties of the y
that are bigger than x.
Understand Quantifiers!!!
"x, $y, x×y=1
"x>0, $y, x×y=1
How about
“Every real number has a
multiplicative inverse
except for zero”
This does correctly express it.
But changing the range of x,
is more like 2nd order logic.
Understand Quantifiers!!!
"x, $y, x×y=1
"x, [x0] and [$y, x×y=1]
How about
“Every real number has a
multiplicative inverse
except for zero”
How about
“Every real number has a
multiplicative inverse
except for zero”
How about
“Every real number has a
multiplicative inverse
except for zero”
How about
“Every real number has a
multiplicative inverse
except for zero”
Understand Quantifiers!!!
"b, Loves(b, g)
“Every boy loves g”
b vs g?
b is a bound variable. g is a free variable.
(appears in or ) (does not appear in or )
The statement is about The statement is about g.
the set of all boys. Free variable
x=5 Object
loop i = 1..9 Bound variable
++x
end loop
Understand Quantifiers!!!
"b, Loves(b, g)
g is a free variable.
(does not appear in or )
A relation/predicate
• returns True/False The statement is about g.
• depending whether object
g has the property VeryLoved.
VeryLoved(g) = "b, Loves(b, g)
Classifying Functions
3n2 + 7n + 8 = θ(n2)
True
c 1, c 2, n 0, n n 0, c 1 g ( n ) f ( n ) c 2 g ( n )
3 4 8 n ³ 8 3·n2 £ 3n2 + 7n + 8 £ 4·n2
7n + 8 £ 1·n2
7 + 8/n £ 1·n
Classifying Functions
3n2 + 7n + 8 = θ(n2)
c 1, c 2, n 0, n n 0, c 1 g ( n ) f ( n ) c 2 g ( n )
Classifying Functions
3n2 + 7n + 8 = θ(n)
c 1, c 2, n 0, n n 0, c 1 g ( n ) f ( n ) c 2 g ( n )
c 1, c 2, n 0, n n 0, c 1 g ( n ) f ( n ) o r f ( n ) c 2 g ( n )
AB Implications
• If A is true then B is true.
• This may because A causes B.
• The counter positive is B A
because if B is not true, then A can’t be true
because otherwise B would be true.
Hence B may cause A.
• Or C may cause both A and B.
• Or maybe cause and effect is not involved at all.
• A ⇒ B formally means ¬(A and ¬B)
• Bring the negation in gives ¬A or B
If A is false, then the statement A ⇒ B follows.
If B is true, then A ⇒ B again follows.
Proof of A B Implications
• Officially two cases.
ignore
• If A is false, then A ⇒ B is trivially true.
• If A is true, one must prove B.
• Indenting, pushing and popping stack.
• A proof consists of a sequence of statements
that follow from the initial assumptions.
• When we make the new assumption A,
indents the lines for the duration
of this new assumption.
• Then after B is proved,
this indenting “stack” is popped
with the conclusion that A ⇒ B.
Proof of A B Implications
• Goal is to prove A ⇒ B.
• Assume that A is true.
• Goal is to prove B.
• ... proof of B.
• Hence B is true.
• Hence A ⇒ B is true.
Implications
Suppose you assume this is true:
S1: "x, P(x)
Then you know that P(x’) is true
for your favorite value x′.
I want my input to be
the worst for his algorithm
so I should go second.
The Time Complexity
Upper Bound:
$A, "I, A(I)=P(I) and Time(A,I) £ Tupper(|I|)
What do we want from our
problem P?
Where does it come from?
Upper Bound:
$A, "I, A(I)=P(I) and Time(A,I) £ Tupper(|I|)
Lower Bound:
"A, $I, A(I) ≠ P(I) or Time(A,I) ³ Tlower(|I|)
If he comes up with
a bigger c,
I will come up with
an even bigger I.
The Time Complexity
• Problem P is computable in polynomial time.
A, c, "I, A(I)=P(I) & Time(A,I) ≤ |I|c
Time(A,I) ≤ |I|c
Does not apply for small I.
The Time Complexity
• Problem P is computable in polynomial time.
A, c,n0,"I, A(I)=P(I) & (|I| < n0 or Time(A,I) ≤ |I|c)
Time(A,I) ≤ |I|c
Does not apply for small I.
The Time Complexity
• Problem P is computable in polynomial time.
A, c, n0,"I, A(I)=P(I) & (|I| < n0 or Time(A,I) ≤ |I|c)
• Problem P is not computable in polynomial time.
A, c, n0, I, A(I)≠P(I) or (|I| ≥ n0 & Time(A,I) > |I|c)
• Problem P is computable in exponential time.
A, c, n0,"I, A(I)=P(I) & (|I| < n0 or Time(A,I) ≤ 2c|I|)
• The computational class “Exponential Time"
is strictly bigger than the computational
class “Polynomial Time”.
P, [ A, c, n0, I, A(I)≠P(I) or (|I| ≥ n0 & Time(A,I) > |I|c)]
& [ A, c, n 0 ,"I, A(I)=P(I) & (|I| < n 0 or Time(A,I) ≤ 2c|I|
)]
Fixed/Constant vs Arbitrary/Finite
• Given the needs of the problem at hand,
• a programmer can give her Java program
• as many lines of code
• as many variables and
• as a big of a (finite) range for each variable
as she wants.
But these numbers are fixed/constant. Meaning:
• If K(J,I) is these numbers
program J has on input I,
then this function can depend on J,
but can’t depend on I (or on |I|)
• "computable problems P,
a Java program J, an integer k,
"inputs I,
K(J,I) = k
Fixed/Constant vs Arbitrary/Finite
• Given the needs of the problem at hand,
• a programmer can give her Java program
• as many lines of code number of lines actually
• as many variables and used by J on I.
• as a big of a (finite) range for each variable
as she wants.
But these numbers are fixed/constant. Meaning:
• If K(J,I) is these numbers
program J has on input I,
then this function can depend on J,
but can’t depend on I (or on |I|) K(J,I) does
• "computable problems P, depend on I.
a Java program J, an integer k,
"inputs I, Clearly J can’t use more lines
K(J,I) = k than the number k that it actually has.
Fixed/Constant vs Arbitrary/Finite
Remember that we say that
f(n) = 5+sin(n) (1)
because, though f(n) is not actually constant wrt n,
it is bounded above by a constant.
• "computable problems P,
a Java program J, an integer k,
"inputs I,
K(J,I) = k
Fixed/Constant vs Arbitrary/Finite
I write a Java program J
and give it some k lines of code.
I can use as MANY as I like.
1,000,000,000,000,000!
• "computable problems P,
a Java program J, an integer k,
"inputs I,
K(J,I) = k
Fixed/Constant vs Arbitrary/Finite
I write a Java program J
and give it some k lines of code.
I can use as MANY as I like.
1,000,000,000,000,000!
• "computable problems P,
a Java program J, an integer k,
"inputs I,
K(J,I) = k
Fixed/Constant vs Arbitrary/Finite
I write a Java program J
and give it some k lines of code.
I can use as MANY as I like.
1,000,000,000,000,000!
• "computable problems P,
a Java program J, an integer k,
"inputs I,
K(J,I) = k
Fixed/Constant vs Arbitrary/Finite
I write a Java program J
and give it some k lines of code.
I can use as MANY as I like.
1,000,000,000,000,000!
• "computable problems P,
a Java program J, an integer k,
"inputs I,
K(J,I) = k
Fixed/Constant vs Arbitrary/Finite
A similar statement
that speaks of all J,
even if not associated with a P.
• "computable problems P, " Java programs J,
a Java program J, an integer k, an integer k,
"inputs I, "inputs I,
K(J,I) = k K(J,I) = k
Fixed/Constant vs Arbitrary/Finite
• Given the input,
• a Java program,
• can dynamically allocated as many bytes of memory
as it wants.
• This number, though still finite, is not constant. Meaning:
• If K(J,I) is the number bytes
program J uses on input I,
then this function can depend on J,
and on I. (hence on |I|)
Careful will infinity.
• "computable problems P,
There are more than one
a Java program J,
infinities and some are
"inputs I,
in fact smaller than others.
K(J,I) <
Fixed/Constant vs Arbitrary/Finite
• Given the input,
• a Java program,
• can dynamically allocated as many bytes of memory
as it wants.
• This number, though still finite, is not constant. Meaning:
• If K(J,I) is the number bytes
program J uses on input I,
then this function can depend on J,
and on I. (hence on |I|)
In contrast, when we say
• "computable problems P,
J(I) = to mean J runs
a Java program J,
forever, we are really using
"inputs I,
∞ as a symbol and not really
K(J,I) <
as meaning it to be infinity.
Fixed/Constant vs Arbitrary/Finite
• Given the input,
• a Java program,
• can dynamically allocated as many bytes of memory
as it wants.
• This number, though still finite, is not constant. Meaning:
• If K(J,I) is the number bytes
program J uses on input I,
then this function can depend on J,
and on I. (hence on |I|)
• "computable problems P,
a Java program J,
"inputs I,
an integer k,
K(J,I) = k
Fixed/Constant vs Arbitrary/Finite
I come up with a hard problem P
• "computable problems P,
a Java program J,
"inputs I,
an integer k,
K(J,I) = k
Fixed/Constant vs Arbitrary/Finite
I write a Java program J.
I don’t need to specify how many
bytes of memory k it will allocate.
Oops.
I now need to come up with
the input I before knowing this k.
• "computable problems P,
a Java program J,
"inputs I,
an integer k,
K(J,I) = k
Fixed/Constant vs Arbitrary/Finite
No problem.
If he gives me a bigger input I,
I will use even more memory!
• "computable problems P,
a Java program J,
"inputs I,
an integer k,
K(J,I) = k
Fixed/Constant vs Arbitrary/Finite
No problem.
If he gives me a bigger input I,
I will use even more memory!