350 likes | 408 Views
Section 1.1. Logic. Proposition. Statement that is either true or false can’t be both in English, must contain a form of “to be” Examples: Cate Sheller is President of the United States CS1 is a prerequisite for this class I am breathing. Many statements are not propositions.
E N D
Section 1.1 Logic
Proposition • Statement that is either true or false • can’t be both • in English, must contain a form of “to be” • Examples: • Cate Sheller is President of the United States • CS1 is a prerequisite for this class • I am breathing
Many statements are not propositions ... • Give me liberty or give me death • ax2 + bx + c = 0 • See Spot run • Who am I and why am I here?
Representing propositions • Can use letter to represent proposition; think of letter as logical variable • Typically use p to represent first proposition, q for second, r for third, etc. • Truth value of a proposition is T (true) or F(false)
Negation • Logical opposite of a proposition • If p is a proposition, not p is its negation • Not p is usually denoted: p
Truth table • Graphical display of relationships between truth values of propositions • Shows all possible values of propositions, or combinations of propositions p p T F F T
Logical Operators • Negation is an example of a logical operation; the negation operator is unary, meaning it operates on one logical variable (like unary arithmetic negation) • Connectives are operators that operate on two (or more) propositions
Conjunction • Conjunction of 2 propositions is true if and only if both propositions are true • Denoted with the symbol • If p and q are propositions, p q means p AND q • Remember - looks like A for And
Examples Let p = 2 + 2 = 4 q = “It is raining” r = “ I am in class now” What is the value of: p q p r r q p r p r (p r)
Truth table for p q p q p q T T T T F F F T F F F F
Disjunction • Disjunction of two propositions is false only if both propositions are false • Denoted with this symbol: • If p and q are propositions, p q means p OR q • Mnemonic: looks like OAR in the water (sort of)
Examples Let p = 2 + 2 = 4 q = “It is raining” r = “ I am in class now” What is the value of: p q p r r q p r p r (p r)
Truth table for disjunction p q p q T T T T F T F T T F F F
Inclusive vs. exclusive OR • Disjunction means or in the inclusive sense; includes the possibility that both propositions are true, and can be true at the same time • For example, you may take this class if you have taken Calculus I or you have the instructor’s permission - in other words, you can take it if you have either, or both
Exclusive OR • The exclusive or of two propositions is true when exactly one of the propositions is true, false otherwise • Exclusive or is denoted with this symbol: • For p and q, p q means p XOR q • Mnemonic: looks like sideways X inside an O
English examples • I am either in class or in my office • The meal comes with soup or salad • You can have your cake or you can eat it
Examples Let p = 2 + 2 = 4 q = “It is raining” r = “ I am in class now” What is the value of: p q p r r q p r p r (p r)
Truth table for p q p q T T F T F T F T T F F F
Implication • The implication of two propositions depends on the ordering of the propositions • The first proposition is calls the premise (or hypothesis or antecedent) and the second is the conclusion (or consequence) • An implication is false when the premise is true but the conclusion is false, and true in all other cases
Implication • Implication is denoted with the symbol • For p and q, p q can be read as: • if p then q • p implies q • q if p • p only if q • q whenever p • q is necessary for p • p is sufficient for q • if p, q
Implication • Note that a false premise always leads to a true implication, regardless of the truth value of the conclusion • Implication does not necessarily mean a cause and effect relationship between the premise and the conclusion
Implications in English • If Cate lives in Iowa, then Discrete Math is a 3-credit class • Since p (I live in Iowa) and q (this is a 3-credit class) are both true, p q is true even though p and q are unrelated statements
Implications in English • If the sky is brown, then 2+2=5 • Since p (sky is brown) and q (2+2=5) are both false, the implication p q is true • Remember, you can conclude anything from a false premise
If/then vs. implication • In programming, the if/then logic structure is not the same as implication, though the two are related • In a program, if the premise (if expression) is true, the statements following the premise will executed, otherwise not • There is no “conclusion,” so it’s not an implication
Examples Let p = 2 + 2 = 4 q = “It is raining” r = “ I am in class now” What is the value of: p q p r r q p r p r (p r)
Truth table for p q p q T T T T F F F T T F F T
Converse & contrapositive • For the implication p q, the converse is q p • For the implication p q, the contrapositive is q p
Biconditional • A biconditional is a proposition that is true when p and q have the same truth values (both true or both false) • For p and q, the biconditional is denoted as p q, which can be read as: • p if and only if q • p is necessary and sufficient for q • if p then q, and conversely
Examples Let p = 2 + 2 = 4 q = “It is raining” r = “ I am in class now” What is the value of: p q p r r q p r p r (p r)
Truth table for p q p q T T T T F F F T F F F T
Compound propositions • Can build compound propositions by combining simple propositions using negation and connectives • Use parentheses to specify order or operations • Negation takes precedence over connectives
Examples Let p = 2 + 2 = 4 q = “It is raining” r = “ I am in class now” What is the value of: (p q) ( p r) (r q) (p r) (p r ) (p r)
Logic & Bit Operations • A bit string is a sequence of 1s and 0s - the number of bits in the string is the length of the string • Bit operations correspond to logical operations with 1 representing T and 0 representing F
Bit operation examples Let s1 = 10011100 s2 = 11000110 s1 OR s2 = 11011110 s1 AND s2 = 10000100 s1 XOR s2 = 01011010
Section 1.1 Logic - ends -