intro to discrete structures spring 2014 text: mathematical structures for computer science

22
Intro to Discrete Structures Spring 2014 Text: Mathematical Structures for Computer Science

Upload: maryann-holmes

Post on 26-Dec-2015

227 views

Category:

Documents


0 download

TRANSCRIPT

Intro to Discrete Structures

Spring 2014Text: Mathematical Structures for

Computer Science

CS 214 - Chapter 1 2

Course Overview

• Discrete versus continuous • Major topics:– Develop abstract thinking through the study of logical

arguments, proofs– Develop recursive thinking, which provides problem

solving tools such as recurrence relations and induction– Algorithms & analysis (explored more fully in CS 317)– Combinatorial techniques for counting objects– Discrete structures such as graphs, sets, functions, trees,

Formal Logic: Chapter 1

1.1: Statements, Symbolic Representation, and Tautologies

CS 214 - Chapter 1 4

Why Study Formal Logic?

• Natural languages are ambiguous• Formal logical proofs are based on the structure of

logical expressions, or well-formed formulas, not the semantics– Do conclusions follow necessarily from the truth of a set of

initial statements. This is deductive reasoning– A valid deduction can still be wrong, however, if the logical

statements that are its initial assumptions are actually false.

CS 214 - Chapter 1 5

Applications of Formal Logic

• Proof of program correctness – Not easy, but can be done in limited cases

• Digital circuit design• Formal specification of computer systems or

programming languages– Conditional statements are based on logic

CS 214 - Chapter 1 6

Formal Logic: 1.1 – Overview

• Contents– Connectives and Truth Values– Tautologies– Logical connectives in the real world

• Objectives– Learn to use formal symbols of propositional logic– Find the truth value of expressions in

propositional logic

CS 214 - Chapter 1 7

Statements, Connectives, and Truth Tables

• Statement (proposition): a sentence that is either true or false (but not both at the same time)– e.g. “Jane is a doctor” but not “Are you happy?” or “It is

pretty”– Often used to represent facts

• TRUE and FALSE (T/F, 1/0) are absolute – not “mostly true” or “almost always false”

• Simple statements are represented by letters from the beginning of the alphabet: A, B, C, …

CS 214 - Chapter 1 8

Statements, Connectives, and Truth Tables

• Logical connectives are used to combine several simple statements into compound statements.– e.g., “The sun is shining and the temperature is 80”

• AND and OR are common connectors - binary– If A and B are two simple statements, then

A B or A B are compound statements. • NOT is a logical modifier that changes the truth

value of whatever it modifies (unary connective)– If A is true, then A’ (or !A ) is false

CS 214 - Chapter 1 9

Connectives and Truth TablesA B A ^ B

T T T

T F F

F T F

F F F

A B A v B

T T TT F TF T TF F F

CONJUNCTION DISJUNCTION

A ! A

T F

F T

NEGATION

• Truth tables compute the value of logical expressions based on the truth values of their components.

• They consist of one column for each variable (statement letters, in our case) and one column for the result of each logical computation that the table represents.

• The number of rows is a function of the number of variables. There is one row for each possible combination of truth values for the variables. For example with two variables, A & B, the combinations are A = T, B = T, A = T, B = F, etc.• For two variables, 22 = 4 rows, for 3 variables, 23 rows, …

CS 214 - Chapter 1 10

Connectives and Truth Tables• Implication is a logical connective that

represents the combination “If A then B”• In logic it is represented as “A → B”, read as “A

implies B”• A is the antecedent, B is the consequent

• Logic interpretation somewhat different from natural language interpretation • Here we ask “is it true that A implies B?” The

result depends on the truth values of A and B• If A is false, what can we conclude?

CS 214 - Chapter 1 11

Example• What if– A = “you make an A on the final exam”

B = “you will get an A in the course” – A → B

“If you make an A on the final exam you will get an A in the course”

– When is this statement true, and when is it false?

• What is the truth value of A → B if A = T and B = T ? If A = T and B = F? If A = F and B = T? If A = F and B = F?

CS 214 - Chapter 1 12

Connectives and Truth TablesA B A→B

T T T

T F F

F T T ??

F F T ??

B A B→AT T T

T F F F T T ??

F F T ??

A→B B→A (A→B) && (B→A)T T TF T FT F FT T T

• Logical values are always either true or false, never “I don’t know”, so by convention we assume that if the antecedent of an implication is false the consequent is true. See previous slide.

• The equivalence relation is written as A ↔ B. A & B are equivalent if it is true that whenever “A implies B” is true, it is also true that “B implies A”. Another way to state this relation is “B is true if and only if A is true” or “A is true if and only if B is true”

• Notice that A ↔ B only when A and B have the same truth value.

Equivalence 1

A B A ↔ B

T T T

T F F

F T F

F F T

Equivalence 2simplified

CS 214 - Chapter 1 13

English to Logic

• See Table 1.5 for correspondence between words in English and logical connectives.

• Work some examples on pages 4 & 5

CS 214 - Chapter 1 14

Well-formed Formulas (wff’s)• The basic tokens in logical statements are the statement letters,

connector symbols AND, OR, NEGATION, IMPLICATION, & parentheses• Syntax is governed by precedence rules; from highest to lowest they

are– Negation– AND and OR– Implication– Equivalence

• Parentheses can override the normal order, just as in programming languages.

• Syntactically correct statements are sometimes called well-formed formulas (wff)

CS 214 - Chapter 1 15

Examples of wff’s

• A B’ represents A (B’), not (A B)’• A B → C means (A B) → C• Well formed formulas are represented by

letters from the end of the alphabet: P, Q, R, …– For example, A B → C can be written as P → Q

• It is often easier to simplify around the main connector (the operator that is evaluated last, or that has the lowest precedence).

CS 214 - Chapter 1 16

Tautologies & Contradictions

• A tautology is a statement that is always true, regardless of the truth values assigned to its variables– Example: A A’

• A contradiction is a statement that is always false– Example: A A’

• Contradictions are usually represented by 0 and tautologies by 1

CS 214 - Chapter 1 17

Truth Table for a Tautology

CS 214 - Chapter 1 18

Tautological EquivalencesCommutativity A B B A A B B A Associativity (A B ) C A (B C) (A B ) C A (B C) Distribution A (B C) A (B C)

(A B ) (A C ) (A B ) (A C ) Identity A 0 A A 1 AComplement A A’ 1 A A’ 0

• Equivalents: the left side may be substituted for the right, and vice versa• Tautologies: the equivalences above are also tautologies; always true, regardless of the truth values assigned to A, B, C. (See Table 1.9 on page 9 for examples)• Similar relations exist in mathematics (6 + 3 = 3 + 6, for example)• For each pair of relations, the relation on the left is the dual of the relation on the right – and vice versa• It’s useful to be familiar with equivalences because in constructing logical arguments (or even writing conditions in a computer program), one may be easier to understand than another.

CS 214 - Chapter 1 19

DeMorgan’s Laws

(A B)’ A’ B’ (A B)’ A’ B’

• DeMorgan’s laws are helpful in forming the negation of compound statements.

• Example: suppose – P is “ice cream is cold and sweet” – Negation? “Ice cream is not cold and sweet”– No; P should really be “ice cream is cold and ice cream is sweet”.– The negation is “Ice cream is not cold OR ice cream is not sweet”– Be careful to think in terms of complete statements – this is an

example of fuzzy natural language meaning, a reason for using logical notation to avoid ambiguity.

CS 214 - Chapter 1 20

Why Do We Care?

• Equivalences allow us to choose the easiest way to write a particular logical condition

• Logical connectives are useful in building precise descriptions of things – example: refining a web search– e.g. recipe AND chicken AND easy

(or “recipe + chicken + easy” )

CS 214 - Chapter 1 21

Algorithm

• An algorithm is a set of instructions that can be mechanically executed in a finite amount of time in order to solve some problem.

• Important features:– Finiteness– “Mechanical” : the steps are clearly described and

can be executed by hand or on a computer• Algorithms are often described in pseudocode– See the example on page 12: an algorithm to determine if,

given two wffs P and Q, is P → Q a tautology.

CS 214 - Chapter 1 22

Preview of 1.2 – Propositional Logic

• In this section we’ll see how to use wffs to perform deductive reasoning.

• Propositional logic (also called propositional calculus or statement logic) is a formal system for reaching logical conclusions derived from a given set of statements, or facts.

• First homework will be assigned.