3. CS 19.305
Logic in Computer Science
Text Books:
1. Huth M and Ryan M, Logic in Computer Science: Modelling
and Reasoning about Systems, Cambridge University Press
2. Enderton H B, A Mathematical Introduction to Logic,
Academic Press, 2nd edition, 2001.
Reference Books:
1. Arindama Singh, Logics for Computer Science, Prentice Hall
of India, 1st edition, 2004.
2. M. Ben-Ari, Mathematical Logic for Computer Science,
Springer, 2nd edition, 2003.
3. 3. Rich E., and Knight K., Artificial Intelligence, Tata
McGraw-Hill, 3rd edition, 2009.
4. C. L. Chang and R. C. T. Lee, Symbolic Logic and Mechanical
Theorem Proving, Academic Press
4. Logic evolution
In the early years of this century symbolic or formal
logic became quite popular with philosophers and
mathematicians because they were interested in
the concept of what constitutes a correct proof in
mathematics.
Concept of logic then hinged upon what is a correct
argument as opposed to a wrong (or faulty)
Logic is the science of the correctness or
incorrectness of reasoning, or the study of the
evaluation of arguments.
5. Different so-called proofs that have come up for
Euclid’s parallel postulate and for Fermat’s last
theorem.
There have invariably been “bugs”
(a term popularized by computer scientists for the
faults in a program)
which were often very hard to detect and it was
necessary therefore to find infallible methods of
proof.
6. The early logicians of the nineteenth and twentieth
centuries hoped to establish formal logic as a
foundation for mathematics, though that never
really happened.
But mathematics does rest on one firm
foundation, namely set theory.
Set theory itself has been expressed in first order
logic.
What really needed to be answered were
questions relating to the automation or
mechanizability of proofs.
Very relevant for today’s computers
7. David Hilbert asked the important question,
if all the statements are reduced to symbolic logic,
then can it be derived by a machine?
Latter half of the twentieth century logic has been
used in computer science for various purposes
ranging from program specification and
verification to theorem-proving.
Initially its use was restricted to merely specifying
programs and reasoning about their
implementations.
8. This is exemplified in the some fairly elegant
research on the development of correct programs
using first-order logic in such calculi such as the
weakest-precondition calculus of Dijkstra.
Amethod called Hoare Logic which combines
first-order logic sentences and program phrases
into a specification and reasoning mechanism is
also quite useful in the development of small
programs.
Logic in this form has also been used to specify
the meanings of some programming languages,
notably Pascal.
9. The close link between logic as a formal system
and computer-based theorem proving is proving
to be very useful especially where there are a
large number of cases.
10. Logic evolution
In the early years of this century symbolic or formal
logic became quite popular with philosophers and
mathematicians because they were interested in
the concept of what constitutes a correct proof in
mathematics
Concept of logic then hinged upon what is a correct
argument as opposed to a wrong (or faulty)
Logic is the science of the correctness or
incorrectness of reasoning, or the study of the
evaluation of arguments.
11. What is Logic in Computer
Science ?
Logical formalisms are applied in many areas of
computer science.
The extensive use of those formalisms resulted in
defining hundreds of logics that fit nicely to
particular application areas.
First the role of logic in the clarification of human
reasoning
First, decide what is the subject of reasoning
or, in other words, what are we going to talk about
and what language are we going to use
12. What is Logic in Computer
Science ?
The next step is to associate a precise meaning to
basic notions of the language, in order to avoid
ambiguities and misunderstandings.
First, decide what is the subject of reasoning
or, in other words, what are we going to talk about
and what language are we going to use
state clearly what kind of opinions (sentences),
which of those opinions are true (valid), and which
are false (invalid).
13. What is Logic in Computer
Science ?
Traditionally, there are two methodologies to
introduce a logic:
syntactically, via a notion of a proof and proof
system
semantically, via a notion of a model,
satisfiability and truth
Both methodologies first require to chose a
language that suits best a particular application
a sentence (formula) is considered valid provided
that it can be proved (syntactical approach)
14. What is Logic in Computer
Science ?
or it is valid in models accepted as semantical
structures (semantical approach).
Logic dealt with arguments in the natural language
used by humans.
Example
All men are mortal. P (Socrates) mortal
Socrates is a man
Therefore, Socrates is mortal
15. What is Logic in Computer
Science ?
In computer science, we design and study
systems through the use of formal languages that
can themselves be interpreted by a formal system.
Example
Boolean circuits
Programming languages
Design Validation and verification
AI, Security. Etc.
16. What is Logic in Computer
Science ?
Different logics in computer science
Example
Boolean circuits
Propositional Logic
First Order Logic
Higher Order Logic
Theory of Construction
Real-time Logic, Temporal Logic
ProcessAlgebras
Linear Logic
17. Summary
Logic is a tool for working with complicated
compound statements. It includes:
A language for expressing them.
A concise notation for writing them.
A methodology for objectively reasoning about
their truth or falsity.
It is the foundation for expressing formal proofs
in all branches of mathematics.
19. Propositional Logic
Propositional Logic is the logic of compound
statements built from simpler statements
using so-called Boolean connectives.
Some applications in computer science:
Design of digital electronic circuits.
Expressing conditions in programs.
Queries to databases & search engines.
George Boole
(1815-1864)
Chrysippus of Soli
(ca. 281 B.C. – 205 B.C.)
20. Propositional Logic
A proposition (p, q, r, …) is simply a statement
(i.e., a declarative sentence) with a definite
meaning, having a truth value that’s either true
(T) or false (F) (never both, neither, or
somewhere in between).
However, you might not know the actual truth
value, and it might be situation-dependent.
Later we will study probability theory, in which
we assign degrees of certainty to propositions.
But for now: think True/False only
21. Examples Propositional Logic
“It is raining.” (In a given situation.)
“Colombo is the capital of Sri Lanka.”
• “1 + 2 = 3”
But, the following are NOT propositions:
•“Who’s there?” (interrogative, question)
•“La la la la la.” (meaningless interjection)
•“Just do it!” (imperative, command)
•“Yeah, I sorta dunno, whatever...” (vague)
•“1 + 2” (expression with a non-true/false value)
22. Predicate logic
Predicate logic is an extension of propositional
logic that permits concisely reasoning about
whole classes of entities.
Propositional logic (recall) treats simple
propositions (sentences) as atomic entities.
In contrast, predicate logic distinguishes the
subject of a sentence from its predicate.
Remember these English grammar terms?
23. Predicate logic
It is the formal notation for writing perfectly clear,
concise, and unambiguous mathematical
definitions, axioms, and theorems for any
branch of mathematics.
It is the foundation of the field of mathematical
logic, which culminated in Gödel’s
incompleteness theorem, which revealed the
ultimate limits of mathematical thought:
Kurt Gödel
1906-1978
24. Predicate logic
Given any finitely describable, consistent proof
procedure, there will still be some true
statements that can never be proven by that
procedure.
We can’t discover all mathematical truths,
unless we sometimes resort to making guesses
25. Predicate logic Applications
Basis for clearly expressed formal specifications
for any complex system.
Basis for automatic theorem provers and many
other Artificial Intelligence systems.
Supported by some of the more sophisticated
database query engines and container class
libraries (these are types of programming tools).
26. Example Predicate logic
In the sentence “The dog is sleeping”
The phrase “the dog” denotes the subject -
the object or entity that the sentence is about.
The phrase “is sleeping” denotes the predicate-
a property that is true of the subject.
In predicate logic, a predicate is modeled as a
function P(·) from objects to propositions.
P(x) = “x is sleeping” (where x is any object).
27. Example Predicate logic
Convention: Lowercase variables x, y, z...
denote objects/entities; uppercase variables P,
Q, R… denote propositional functions
(predicates).
Keep in mind that the result of applying a
predicate P to an object x is the proposition P(x).
But the predicate P itself (e.g. P=“is sleeping”) is
not a proposition (not a complete sentence).
E.g. if P(x) = “x is a prime number”,
P(3) is the proposition “3 is a prime number”.
28. Example Predicate logic
Predicate logic generalizes the grammatical notion
of a predicate to also include propositional
functions of any number of arguments, each of
which may take any grammatical role that a noun
can take.
E.g. let P(x, y, z) = “x gave y the grade z”, then
P(x, y, z) = “Mike gave Mary the grade A”
x can fool y at time z
If x=“”, y=“”, z=“”, then
29. Mathematical Induction
Mathematical Induction is a method of
mathematical proof typically used to establish
that a given statement is true for all natural
numbers.
Mathematical induction is a mathematical
proof technique. It is essentially used to prove
that a statement P(n) holds for every natural
number n = 0, 1, 2, 3, . . . ; that is, the overall
statement is a sequence of infinitely many
cases P(0), P(1), P(2), P(3), . . . . Informal
metaphors help to explain this technique, such
as falling dominoes or climbing a ladder:
30. Mathematical Induction
It is a method of mathematical
proof typically used to establish
that a given statement is true of
all natural numbers.
A method of proof
It does not generate answers:
it only can prove them
31. Mathematical Induction
It works in three parts:
Base case(s): show it is true for one element
Inductive hypothesis: assume it is true for any
given element, Must be clearly labeled!!!
Show that if it is true for the next highest element
32. Mathematical Induction
Mathematical induction is a legitimate method
of proof for all positive integers n
Principle:
Let Pn be a statement involving n, a positive
integer. If
1. P1 is true, and
2. the truth of Pk implies the truth of Pk + 1 for
every positive k,
then Pn must be true for all positive integers n.
33. Question: 1.1
Use mathematical induction to prove
Sn = 2 + 4 + 6 + 8 + . . . + 2n = n(n + 1)
for every positive integer n.
34. Mathematical Induction
Question: 1.1
Use mathematical induction to prove
Sn = 2 + 4 + 6 + 8 + . . . + 2n = n(n + 1)
for every positive integer n.
Step 1. Show that the formula is true when n = 1.
S1 = n(n + 1) = 1(1 + 1) = 2 is True
Step 2. Assume the formula is valid for some integer k.
Use this assumption to prove the formula is valid for
the next integer, k + 1 and show that the formula
Sk + 1 = (k + 1)(k + 2) is true
35. Mathematical Induction
Let’s assume
Sk = 2 + 4 + 6 + 8 + . . . + 2k = k(k + 1) // assuming that it will hold
Now,
Sk + 1 = 2 + 4 + 6 + 8 + . . . + 2k + [2(k + 1)]
= 2 + 4 + 6 + 8 + . . . + 2k + (2k + 2)
=Sk + (2k + 2)
= k(k + 1) + (2k + 2) Replace Sk by k(k + 1).
= k2 + k + 2k + 2
= k2 + 3k + 2
= (k + 1)(k + 2)
= (k + 1)((k + 1)+1)
The formula Sn = n(n + 1) is valid for all positive integer values of n.
36. Question:1.2
Prove that the sum of the first n natural numbers
is given by this formula:
1 + 2 + 3 + . . . + n = n(n + 1)
2
37. Mathematical Induction
Question:1.2 Prove that the sum of the first n natural numbers
is given by this formula:
1 + 2 + 3 + . . . + n = n(n + 1)
2
First, we will assume that the formula is true for n = k; that is,
we will assume:
1 + 2 + 3 + . . . + k = k(k + 1)
2 (1)
This is the induction assumption. Assuming this, we must prove
that the formula is true for its successor, n = k + 1. That is, we
must show:
1 + 2 + 3 + . . . + (k + 1) = (k + 1)(k + 2)
2 (2)
38. Mathematical Induction
To do that, we will simply add the next term (k + 1) to
both sides of the induction assumption in equation 1
1 + 2 + 3 + . . . + k+ (k+1) = k(k + 1) + (k+1)
2
= k(k + 1) + 2(k+1)
2
= (k + 1)(k+2)
2
(on taking (k+1) as a common factor)
Does it corresponds to equation 2; Yes ; Its true
39. Mathematical Induction
Assignments
1.3 Prove that
12 + 22 + 32 + ... + n2 = n (n + 1) (2n + 1)/ 6
For all positive integers n.
1.4 Use mathematical induction to prove that
13 + 23 + 33 + ... + n3 = n2 (n + 1)2 / 4
for all positive integers n.