770 likes | 778 Views
CS100: Discrete structures. Lecture 1: Logic. Lecture Overview. Statement Logical Connectives Conjunction Disjunction Propositions Conditional Bio-conditional Converse Inverse Contrapositive Laws of Logic Quantifiers Universal Existential. What is a Statement ?.
E N D
CS100: Discrete structures Lecture 1: Logic
Lecture Overview • Statement • Logical Connectives • Conjunction • Disjunction • Propositions • Conditional • Bio-conditional • Converse • Inverse • Contrapositive • Laws of Logic • Quantifiers • Universal • Existential Computer Science Department
What is a Statement ? • A statement is a sentence having a form that is typically used to express acts • Examples: • My name is Rawan • I like orange • 4 – 2 = 3 • Do you live in Riyadh? Computer Science Department
1.1 Propositional Logic • A proposition is a declarative sentence (a sentence that declares a fact) that is either true or false, but not both. • Are the following sentences propositions? • Riyadh is the capital of K.S.A. • Read this carefully. • 2+2=3 • x+1=2 • What time is it • Take two books . • The sun will rise tomorrow . (Yes) (No Because it is not declarative sentence) (Yes) (No Because it is neither true or false) (No Because it is not declarative sentence) (No Because it is not declarative sentence) (Yes) Computer Science Department
Logical Connectives and Compound Statement • In mathematics, the letters x, y, z, … are used to donate numerical variables that can be replaced by real numbers. • Those variables can then be combined with the familiar operations +, -, x, ÷. • In logic, the letters p, q, r, s, … denote the propositionalvariables; that can be replaced by a statements. Computer Science Department
1.1 Propositional Logic • Propositional Logic:the area of logic that deals with propositions • Propositional Variables: variables that represent propositions: p, q, r, s • E.g. Proposition p – “Today is Friday.” • Truth values: T, F Computer Science Department
1.1 Propositional Logic • Examples • Find the negation of the following propositions and express this in simple English. • “Today is Friday.” • “At least 10 inches of rain fell today in Miami” . • DEFINITION 1 • Let p be a proposition. The negation of p, denoted by ¬p, is the statement “It is not the case that p.” • The proposition ¬p is read “not p.” The truth value of the negation of p, ¬p is the opposite of the truth value of p. Solution: The negation is “It is not the case that today is Friday.” In simple English, “Today is not Friday.” or “It is not Friday today.” Solution: The negation is “It is not the case that at least 10 inches of rain fell today in Miami.”In simple English, “Less than 10 inches of rain fell today in Miami.”
1.1 Propositional Logic Exercise .. • Give the negation of the following: • p: 2 + 3 > 1 • q: It is cold . • r: 2+3 ≠5 • g: 2 is a positive integer • ¬ p: 2 + 3 ≤ 1 • ¬ q: It is not cold. • ¬ r: 2 + 3 = 5 • ¬ g: 2 is not a positive integer .OR ¬g: 2 is a negative integer .
1.1 Propositional Logic • Truth table: • Logical operators are used to form new propositions from two or more existing propositions. The logical operators are also called connectives.
1.1 Propositional Logic • 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. Computer Science Department
1.1 Propositional Logic • Example • Find the conjunction of the propositions p and q where p is the proposition “Today is Friday.” and q is the proposition “It is raining today.”, and the truth value of the conjunction. Solution: The conjunction is the proposition “Today is Friday and it is raining today” OR “Today is Friday but it is raining.” The proposition is: TRUE on rainy Fridays. FALSE on any day that is not a Friday and on Fridays when it does not rain . Computer Science Department
1.1 Propositional Logic • Note: inclusive or: The disjunction is true when at least one of the two propositions is true. • DEFINITION 3 • 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. • E.g. “Students who have taken calculus or computer science can take this class.” – those who take one OR both classes. Computer Science Department
1.1 Propositional Logic • Example • Find the disjunction of the propositions p and q where p is the proposition “Today is Friday.” and q is the proposition “It is raining today.”, and the truth value of the conjunction. Solution: The conjunction is the proposition “Today is Friday or it is raining today” The proposition is: TRUE whether today is Fridaysor a rainy day including rainy Fridays FALSE on days that are not a Fridays and when it does not rain . Computer Science Department
1.1 Propositional Logic exclusive or : The disjunction is true only when one of the proposition is true. • E.g. “Students who have taken calculus or computer science, but not both, can take this class.” – only those who take ONE of them. Computer Science Department
1.1 Propositional Logic • DEFINITION 4 • Let p and q be propositions. The exclusive orof p and q, denoted by , is the proposition that is true when exactly one of p and q is true and is false otherwise.
1.1 Propositional Logic Conditional Statements • DEFINITION 5 • Let p and q be propositions. The conditional statementp → q, is the proposition “if p, then q.” The conditional statement is false when p is true and q is false, and true otherwise. In the conditional statement p → q, p is called the hypothesis (or antecedent or premise) and q is called the conclusion (or consequence). • A conditional statement is also called an implication. • Example: “If I am elected, then I will lower taxes.” p → q implication: elected, lower taxes. T T | T not elected, lower taxes. F T | T not elected, not lower taxes. F F | T elected, not lower taxes. T F | F
1.1 Propositional Logic • Example: • Let p be the statement “Maria learns discrete mathematics.” and q the statement “Maria will find a good job.” Express the statement p → q as a statement in English. Solution: Any of the following - “If Maria learns discrete mathematics, then she will find a good job. “Maria will find a good job when she learns discrete mathematics.” “For Maria to get a good job, it is sufficient for her to learn discrete mathematics.” “Maria will find a good job unless she does not learn discrete mathematics.” Computer Science Department
1.1 Propositional Logic • Other conditional statements: • Converse of p→q : q→p • Contrapositive of p→q : ¬ q→¬ p • Inverse ofp→q : ¬ p→¬ q • Equivalent Statements: • Statements with the same truth table values. • Converse and Inverse are equivalents. • Contrapositive and p → qare equivalents. Computer Science Department
1.1 Propositional Logic • p ↔ q has the same truth value as(p → q) Λ (q → p) • “if and only if” can be expressed by “iff” • Example: • Let p be the statement “You can take the flight” and let qbe thestatement “You buy a ticket.” Then p ↔ q is the statement “You can take the flight if and only if you buy a ticket.” Implication: If you buy a ticket you can take the flight. If you don’t buy a ticket you cannot take the flight. • DEFINITION 6 • Let p and q be propositions. The biconditional statementp ↔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. Computer Science Department
1.1 Propositional Logic Exercise .. • Let p and q be the propositions p : I bought a lottery ticket this week. q : I won the million dollar jackpot on Friday. • Express each of these propositions as an English sentence. I did not buy a lottery ticket this week. If I did not buy a lottery ticket this week, then I did not win the million dollar jackpot on Friday. I did not buy a lottery ticket this week, and I did not win the million dollar jackpot on Friday.
1.1 Propositional Logic Truth Tables of Compound Propositions • We can use connectives to build up complicated compound propositions involving any number of propositional variables, then use truth tables to determine the truth value of these compound propositions. • Example: Construct the truth table of the compound proposition (pν ¬q) → (pΛq)
Types of statements • A statements that is true for all possible values of its propositional variables is called tautology • A statement that is always false is called contradiction • A statement that can be either true or false, depending of the values of its propositional variables, is called a contingency Computer Science Department
1.1 Propositional Logic Precedence of Logical Operators • We can use parentheses to specify the order in which logical operators in a compound proposition are to be applied. • To reduce the number of parentheses, the precedence order is defined for logical operators. E.g. ¬pΛq = (¬p ) Λq pΛqνr = (pΛq ) νr pνqΛr = pν (qΛr)
1.1 Propositional Logic Exercise .. • find the truth table of the following proposition p ˄ ( ¬( q ˅ ¬p))
1.1 Propositional Logic Translating English Sentences • English (and every other human language) is often ambiguous. Translating sentences into compound statements removes the ambiguity. • Example: How can this English sentence be translated into a logical expression? “You cannot ride the roller coaster if you are under 4 feet tall and you are not older than 16 years old.” Solution: Let q, r, and s represent “You can ride the roller coaster,” “You are under 4 feet tall,” and “You are older than 16 years old.” The sentence can be translated into: (rΛ ¬ s) → ¬q.
1.1 Propositional Logic • Example: How can this English sentence be translated into a logical expression? “You can access the Internet from campus only if you are a computer science major or you are not a freshman.” Solution: Let a, c, and f represent “You can access the Internet from campus,” “You are a computer science major,” and “You are a freshman.” The sentence can be translated into: a → (cν ¬f ) .
1.1 Propositional Logic Exercise .. • Write the following statement in logic : • If I do not study discrete structure and I go to movie , then I am in a good mood . Solution : p: I study discrete structure , q: I go to movie , r: I am in a good mood (¬p ˄ q )➝ r
1.1 Propositional Logic Logic and Bit Operations • Computers represent information using bits. • A bit (Binary Digit) is a symbol with two possible values, 0 and 1. • By convention, 1 represents T (true) and 0 represents F (false). • A variable is called a Boolean variable if its value is either true or false. • Bit operation – replace true by 1 and false by 0 in logical operations.
1.1 Propositional Logic • Example: Find the bitwise OR, bitwise AND, and bitwise XOR of the bit string 01 1011 0110 and 11 0001 1101. • DEFINITION 7 • Abit stringis a sequence of zero or more bits. The length of this string is the number of bits in the string. Solution: 01 1011 0110 11 0001 1101 ------------------- 11 1011 1111 bitwise OR 01 0001 0100 bitwise AND 10 1010 1011 bitwise XOR Computer Science Department
1.2 Propositional Equivalences Introduction • DEFINITION 1 • A compound proposition that is always true, no matter what the truth values of the propositions that occurs in it, is called atautology. A compound proposition that is always false is called a contradiction. A compound proposition that is neither a tautology or a contradiction is called a contingency.
1.2 Propositional Equivalences Logical Equivalences • Compound propositions that have the same truth values in all possible cases are called logically equivalent. • Example: Show that ¬pνq and p → q are logically equivalent. • DEFINITION 2 • The compound propositions p and q are called logicallyequivalent • if p ↔ q is a tautology. The notation p≡ q denotes that p and q are logically equivalent.
1.2 Propositional Equivalences Exercise .. • Show that thisstatements ((p ˄ q) → (p ˅ q))is tautology , by using The truth table :
Laws of Logic • Identity Laws • p v F ≡ p • p ^ T ≡p • Domination Laws • p v T ≡ T • P ^ F ≡ F Computer Science Department
Laws of Logic • Idempotent Laws • p v p ≡ p • p ^ p ≡ p • Double Negation Law • ¬(¬p) ≡ p • Commutative Laws • p v q ≡ q v p • p ^ q ≡ q ^ p Computer Science Department
Laws of Logic • Association Laws • (p v q ) v r ≡ p v (q v r) • Distributive Laws • p v (q ^ r ) ≡ (p v q) ^ (p v r) • p ^ (q v r) ≡ (p ^ q) v (p ^ r) Computer Science Department
Contd. • De Morgan’s Laws • ~ (p v q) ≡ ~p ^ ~q • ~ (p ^ q) ≡ ~p v ~q • Absorption Laws • p v (p ^ q) ≡p • p ^(p vq) ≡ p Computer Science Department
Contd. • Complement Laws • p v ~p ≡ T p ^ ~p ≡ F • ~ ~p ≡ p ~ T ≡ F , ~F ≡ T • p → q ≡ ¬p ˅ q • ¬(p → q ) ≡ pΛ¬q • Note: See tables 7 & 8 page 25 Computer Science Department
1.2 Propositional Equivalences • Example: Show that ¬(p → q ) and pΛ¬q are logically equivalent. Solution: ¬(p → q ) ≡ ¬(¬pνq) ≡ ¬(¬p) Λ¬q (by the second De Morgan law) ≡ pΛ¬q (by the double negation law) Constructing New Logical Equivalences
1.2 Propositional Equivalences • Example: Show that (pΛq) → (pνq) is a tautology. Solution: To show that this statement is a tautology, we will use logical equivalences to demonstrate that it is logically equivalent to T. (pΛq) → (pνq) ≡ ¬ (pΛq) ν (pνq) ≡ (¬ pν¬q) ν (pνq) (by the first De Morgan law) ≡ (¬ pν p) ν(¬ qν q) (by the associative and communicative law for disjunction) ≡ T ν T ≡ T • Note: The above examples can also be done using truth tables.
Exercises • Simplify the following statement (p v q ) ^ ~p • Show that ~p ^ (~q ^ r) v (q ^ r) v (p ^ r) ≡ r (p → q) v (p → r) ≡p → qvr Computer Science Department
Exercises – Continue • (p v q ) ^ ~p • ≡~p ^ ( p v q ) • ≡ ( ~p ^ p ) v ( ~ p ^ q ) • ≡ F v ( ~p ^ q ) • ≡~p ^ q Computer Science Department
Exercises – Continue • ~p ^ (~q ^ r) v (q ^ r) v (p ^ r) ≡ r • ≡~p ^ r^ (~q v q)v (p ^ r) • ≡ ~p ^ r ^ T v (p ^ r) • ≡~p ^ r v (p ^ r) • ≡(~p ^ r) v (p ^ r) • ≡r ^ (~p v p) • ≡r ^ T • ≡r Computer Science Department
Exercises – Continue • (p → q) v (p → r) ≡ p → q v r • ≡ • ≡ • ≡ • ≡ • ≡ • ≡ Computer Science Department
Exercises – Continue • Show that this statements (¬ q˄ (p q) ¬p istautology , by using The laws of logic : • ≡ ¬ (¬ q ˄ (p q ) ˅ ¬p • ≡ ¬ (¬ q ˄ (¬p ˅ q ) ˅ ¬p • ≡ q ˅ ¬ (¬p ˅ q ) ˅ ¬p • ≡ (¬p ˅ q ) ˅ ¬ (¬p ˅ q ) • ≡ T Computer Science Department
Exercises – Continue • Without using truth tables prove the statement (P ∧( P ➝ q)) ➝ q is tautology. (P ∧( P ➝ q)) ➝ q Computer Science Department
1.5 Rules of Inference page 63 Valid Arguments in Propositional Logic: • DEFINITION 1 • An argument in propositional logic is a sequence of propositions. All but the final proposition in the final argument are called premises and the final proposition is called the conclusion.. • An argument is valid of the truth of all its premises implies that the conclusion is true. • An argument form in propositional logic is a sequence of compound propositions involving propositional variables. Computer Science Department
1.5 Rules of Inference page 63 Example: “If you have access to the network, then you can change your grade” “You have access to the network” -------------------------------------------------- ∴ “You can change your grade” Valid Argument Computer Science Department
Rules of Inference for Propositional Logic: • We can always use a truth table to show that an argument form is valid. • This is a tedious approach. • when, for example, an argument involves 9 different propositional variables. • To use a truth table to show this argument is valid. • It requires 2⁹= 512 different rows !!!!!!! Computer Science Department
Rules of Inference: • Fortunately, we do not have to resort to truth tables. • Instead we can first establish the validity of some simple argument forms, called rules of inference. • These rules of inference can then be used to construct more complicated valid argument forms. Computer Science Department