0% found this document useful (0 votes)
68 views

Maths (Lectures 1 & 2 The Foundations Logic and Proofs)

The document discusses the foundations of logic and proofs in computer science. It introduces key concepts such as propositions, truth tables, logical connectives like conjunction and disjunction, conditional statements, and the contrapositive of conditional statements. Proofs are important in computer science to verify that programs produce correct outputs and algorithms give right results. Logic provides a precise way to represent and reason about statements that is useful for many areas of computer science.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views

Maths (Lectures 1 & 2 The Foundations Logic and Proofs)

The document discusses the foundations of logic and proofs in computer science. It introduces key concepts such as propositions, truth tables, logical connectives like conjunction and disjunction, conditional statements, and the contrapositive of conditional statements. Proofs are important in computer science to verify that programs produce correct outputs and algorithms give right results. Logic provides a precise way to represent and reason about statements that is useful for many areas of computer science.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 51

The Foundations: Logic and Proofs

UNIT I
Automated reasoning systems have been created to allow computers to
construct their own proofs.

Many people find it surprising, how important proofs are in computer science?
In fact, proofs are used to verify that computer programs,

produce the correct output for all possible input values;

to show that algorithms always produce the correct result;

to establish the security of a system, and to create artificial intelligence.


Logic is the basis of all automated reasoning.
It has practical applications to the design of computing machines;

to the specification of system;

to artificial intelligence;

to computer programming;

to programming languages;

and to other areas of computer science, as well as to many other fields of study.
Precision is important when communicating with computers, but the English
language is rife with ambiguities.
 
We begin with an introduction to the basic building blocks
of logic — propositions.
 
Propositions
A proposition or statement is a declarative sentence that is either true or false,
but not both.
Example: Which of the following are statements?
 
(a) The earth is round.
(b) 2 + 3 = 5
(c) Do you speak English?
(d) 3 − x = 5
(e) Take two aspirins.
(f) The temperature on the surface of the planet Venus is 8000 F.
(g) The sun will come out tomorrow.
Solution:
(a) and (b) are statements that happen to be true. 
(c) is a question, so it is not a statement. 

(d) is a declarative sentence, but not a statement, since it is true or false depending

on the value of x. 


(e) is not a statement; it is a command. 

(f) is a declarative sentence whose truth or falsity we do not know at this time;
however, we can in principle determine if it is true or false, so it is a statement. 
(g) is a statement since it is either true or false, but not both, although we would
We’ll use symbols such as p, q, and r as propositional variables—that is,

variables that represent propositions, in the same way that in ordinary algebra
use variables such as x and y to represent numbers.
 
Propositional variables may also be called atomic propositions, as opposed to
compound propositions,

which are composed from other propositions using “and,” “or,” and the like.
The truth value of a proposition is true, denoted by T, if it is a true proposition,

and the truth value of a proposition is false, denoted by F, if it is a false


proposition.

For example, let’s say

P = “2000 was a leap year” (a true proposition)


 
and

Q = “16 is a prime number” (a false proposition).


 
The negation of a statement is only, as unambiguous as the original statement.

For example, we might negate

“hens are black” by saying “hens are not black,”

but does this mean that no hens are black, or

that there is some hen somewhere that isn’t black?


 
In general, the negation of a proposition is exactly what we would have to observe
in order to conclude that the proposition is false —

in other words, for every proposition p, either p is true or ¬ p is true but not
both.

If r is the statement that all hens are black, then ¬ r is the statement that there is

a hen that is not black.


Following Table, displays the truth table for the negation of a proposition p.

Truth table for the negation operator.

This table has a row for each of the two possible truth values of a proposition p.
Each row shows the truth value of ¬ p corresponding to the truth value of p for
that row.
Definition 2: Let p and q be propositions. The conjunction of p and q, denoted
by p ∧ q, is the proposition “p and q.”

The conjunction p ∧ q is true when both p and q are true and is false otherwise.
Truth table for the “and” operator.

Remark: In logic the word “but” sometimes is used instead of “and” in a


conjunction.
For example, the statement “The sun is shining, but it is raining” is another way of
saying “The sun is shining and it is raining.”
Example: Form the conjunction of p and q for each of the following.

(a) P : It is snowing. q : I am cold.


(b) P : 2 < 3. q : −5 > −8.
(c) P : It is snowing. q : 3 < 5.

Solution
(a) p ∧ q : It is snowing and I am cold.

(b) p ∧ q : 2 < 3 and −5 > −8.

(c) p ∧ q : It is snowing and 3 < 5.

Example, shows that in logic, unlike in everyday English, we may join


two totally unrelated statements by the connective and.
Definition: Let p and q be propositions. The disjunction of p and q, denoted
by p ∨ q, is the proposition “p or q.”

The disjunction p ∨ q is false when both p and q are false and is true otherwise.

Truth table for the “ or ” operator.


 
The connective or is more complicated than the connective and because it is used in
two different ways in English.

Suppose that we say “I left for Spain on Monday or I left for Spain on Friday.”

In this compound statement we have the disjunction of the statements

p : I left for Spain on Monday and q : I left for Spain on Friday.

Of course, exactly one of the two possibilities could have occurred.

Both could not have occurred, so the connective or is being used in an exclusive
sense.
On the other hand, consider the disjunction

“I passed mathematics or I failed French.”

In this case, at least one of the two possibilities occurred.

However, both could have occurred, so the connective or is being used in an


inclusive sense.

In mathematics and computer science, we agree to use the connective or always


in the inclusive manner.
 
Definition: Let p and q be propositions. The exclusive or of p and q, denoted
by p ⊕ q, is the proposition that is true

when exactly one of p and q is true and is false otherwise.

Truth table for the“ exclusive or” operator


Conditional Statements

Definition: Let p and q be propositions. The conditional statement p → q is the


proposition “if p, then q.”

The conditional statement p → q is false when p is true and q is false,

and true otherwise.

In the conditional statement p → q,

p is called the hypothesis and q is called the conclusion.


The statement p → q is called a conditional statement because p → q asserts that
q is true on the condition that p holds.

A conditional statement is also called an implication.

Note that the statement p → q is true when both p and q are true and when p is
false (no matter what truth value q has).

The Truth Table for the Conditional Statement p → q.


A useful way to understand the truth value of a conditional statement is to think
of an obligation or a contract.

For example, the pledge many politicians make when running for office is

“If I am elected, then I will lower taxes.”

If the politician is elected, voters would expect this politician to lower taxes.
Furthermore, if the politician is not elected, then voters will not have any
expectation that this person will lower taxes,

although the person may have sufficient influence to cause those in power to
lower taxes.

It is only when the politician is elected but does not lower taxes that voters can say
that the politician has broken the campaign pledge.

This last scenario corresponds to the case when p is true but q is false, in p → q.
A variety of terminology is used to express p → q, in most if not all of the
following ways to express p → q :
“if p, then q” “p implies q”

“if p, q” “p only if q”

“p is sufficient for q” “a sufficient condition for q is p”

“q if p” “q whenever p”

“q when p” “q is necessary for p”

“a necessary condition for p is q” “q follows from p”

“q unless ¬ p”
Of the various ways to express the conditional statement p → q,

the two that seem to cause the most confusion are “p only if q” and “q unless ¬
p.”

Consequently, we will provide some guidance for clearing up this confusion.

To remember that “p only if q” expresses the same thing as “if p, then q,”

note that “p only if q” says that p cannot be true

when q is not true.

That is, the statement is false if p is true, but q is false.


When p is false, q may be either true or false,

because the statement says nothing about the truth value of q.

Be careful not to use “q only if p” to express p → q

because this is incorrect.

To see this, note that the true values of “q only if p”

and p → q are different

when p and q have different truth values.


Be careful not to use “q only if p” to express p → q because this is incorrect.

To see this, note that the true values of “q only if p” and p → q are different

when p and q have different truth values.


To remember that “q unless ¬ p” expresses the same conditional statement

as “if p, then q,” note that “q unless ¬ p” means

that if ¬ p is false, then q must be true.

That is, the statement “q unless ¬ p” is false when p is true but q is false,
but it is true otherwise.

Consequently, “q unless ¬ p” and p → q always have the same truth value.


CONVERSE, CONTRAPOSITIVE, AND INVERSE

We can form new conditional statements starting with a conditional statement


p → q.
There are three related conditional statements that occur so often that they
have special names.

The proposition q → p is called the converse of p → q.

The contrapositive of p → q is the proposition ¬ q → ¬ p.

The proposition ¬ p → ¬ q is called the inverse of p → q.

We will see that of these three conditional statements formed from p → q,

only the contrapositive always has the same truth value as p → q.


We first show that the contrapositive ¬ q → ¬ p, of a conditional statement

p → q always has the same truth value as p → q.

To see this, note that the contrapositive is false only when ¬ p is false

and ¬ q is true, that is, only when p is true and q is false.


 
What are the contrapositive, the converse, and the inverse of the following
conditional statement

“The home team wins whenever it is raining?”

“q whenever p” is one of the ways to express the conditional statement p → q.

the original statement can be rewritten as

“If it is raining, then the home team wins.”

Consequently, the contrapositive of this conditional statement is

“If the home team does not win, then it is not raining.”
The original statement can be rewritten as

“If it is raining, then the home team wins.”

Consequently, the contrapositive of this conditional statement is

“If the home team does not win, then it is not raining.”

The converse is
“If the home team wins, then it is raining.”

The inverse is
“If it is not raining, then the home team does not win.”

Only the contrapositive is equivalent to the original statement.


We now show that neither the converse, q → p, nor the inverse, ¬ p → ¬ q,

has the same truth value as p → q for all possible truth values of p and q.

Note that when p is true and q is false, the original conditional statement is false,

but the converse and the inverse are both true.


BICONDITIONALS

Definition: Let p and q be propositions. The biconditional statement p ↔ q is the


proposition “p if and only if q.”

The biconditional statement p ↔ q is true when p and q have the same truth
values, and is false otherwise.

Biconditional statements are also called bi-implications.

The biconditional statement p ↔ q uses the abbreviation “iff” for “if and only if.”

Note that p ↔ q has exactly the same truth value as (p → q) ∧ (q → p).


The Truth Table for the Biconditional p ↔ q.

Note that the statement p ↔ q is true when both

the conditional statements p → q and q → p are true and is false otherwise.

That is why we use the words “if and only if” to express this logical connective and

why it is symbolically written

by combining the symbols → and ←.


There are some other common ways to express p ↔ q:

“p is necessary and sufficient for q”

“if p then q, and conversely”

“p iff q.”
Example: Let p be the statement “You can take the flight,” and let q be the
statement “You buy a ticket.”

Then p ↔ q is the statement “You can take the flight if and only if you buy a
ticket.”
This statement is true if p and q are either both true or both false, that is, if you buy
a ticket and can take the flight

or if you do not buy a ticket and you cannot take the flight.

It is false when p and q have opposite truth values, that is, when you do not buy a
ticket, but you can take the flight (such as when you get a free trip)

and when you buy a ticket but you cannot take the flight (such as when the airline
dumps you).
IMPLICIT USE OF BICONDITIONALS

You should be aware that biconditionals are not always explicit in natural language.

In particular, the “if and only if” construction used in biconditionals is rarely used in
common language.

Instead, biconditionals are often expressed using an “if, then” or an “only if”
construction.

The other part of the “if and only if” is implicit. That is, the converse is implied, but
not stated.
For example, consider the statement in English

“If you finish your meal, then you can have dessert.”

What is really meant is

“You can have dessert if and only if you finish your meal.”

This last statement is logically equivalent to the two statements

“If you finish your meal, then you can have dessert” and “You can have dessert
only if you finish your meal.”

Because of this imprecision in natural language, we need to make an assumption


whether a conditional statement in natural language implicitly includes its converse.
Because precision is essential in mathematics and in logic,

we will always distinguish between the conditional statement p → q and the

biconditional statement p ↔ q.
Logic and Bit Operations

Computers represent information using bits.

A bit is a symbol with two possible values, namely, 0 (zero) and 1 (one).

This meaning of the word bit comes from binary digit,

because zeros and ones are the digits used in binary representations of numbers.
A bit can be used to represent a truth value, because there are two truth values,
namely, true and false.

We will use a 1 bit to represent true and a 0 bit to represent false.

That is, 1 represents T (true), 0 represents F (false).

A variable is called a Boolean variable if its value is either true or false.

Consequently, a Boolean variable can be represented using a bit.


Computer bit operations correspond to the logical connectives.

By replacing true by a one and false by a zero in the truth tables for the operators
∧, ∨, and ⊕, for the corresponding bit operations.

We will also use the notation OR, AND, and XOR for the operators ∨,∧, and ⊕, as
is done in various programming languages.

Table for the Bit Operators OR, AND, and XOR.


Information is often represented using bit strings, which are lists of zeros and
ones.

When this is done, operations on the bit strings can be used to manipulate this
information.
Definition: A bit string is a sequence of zero or more bits. The length of this
string is the number of bits in the string.

Example: 101010011 is a bit string of length nine.

We use the symbols ∨, ∧, and ⊕ to represent the bitwise OR, bitwise AND, and
bitwise XOR operations, respectively.
Example: Find the bitwise OR, bitwise AND, and bitwise XOR of the bit strings
0110110110 and 1100011101.

Solution: The bitwise OR, bitwise AND, and bitwise XOR of these strings are
obtained by taking the OR, AND, and XOR of the corresponding bits,
respectively. This gives us

0110110110
1100011101

1110111111 bitwise OR

0100010100 bitwise AND

1010101011 bitwise XOR

You might also like