logic gates

Download Logic  gates

Post on 14-Nov-2014

55 views

Category:

Documents

0 download

Embed Size (px)

TRANSCRIPT

LOGIC

Introduction to logic

What is logic? Why is it useful? Types of logic Propositional logic Predicate logic

Introduction to logic

What is logic? Why is it useful? Types of logic Propositional logic Predicate logic

What is logic?

Logic is the beginning of wisdom, not the end

What is logic?

Logic : The branch of philosophy concerned with analysing the patterns of reasoning by which a conclusion is drawn from a set of premises, without reference to meaning or context

Why study logic?

Logic is concerned with two key skills, which any computer engineer or scientist should have:

Abstraction Formalisation

Why is logic important?

Logic is a formalisation of reasoning. Logic is a formal language for deducing knowledge from a small number of explicitly stated premises (or hypotheses, axioms, facts) Logic provides a formal framework for representing knowledge Logic differentiates between the structure and content of an argument

What is proposition?Def: A proposition is a statement that is either true or false. or A proposition is a declarative sentence that is either true or false,but not both. e.g. It is raining in Delhi. e.g. The square of 5 is 16. Some propositions may not be easily verified: e.g. The universe is infinite.

Topic #1.0 Propositional Logic: Operators

The Negation OperatorThe negation operator (NOT) transforms a prop. into its logical negation. E.g. If p = I have brown hair. then p = I do not have brown hair. The truth table for NOT: p p T F T : True; F : False F T : means is defined asOperand column Result column

Logic Notation for propositions: Truth Values If its true, denoted by T; If its false, denoted by F Used in truth tables:P T F P F T

Compound PropositionsComposite Composed of subpropositions & various connectives Primitive or not composite E.g. This book is good and cheap

Propositional VariableSymbol representing any proposition real variable (x) not propositon but can be replaced by a proposition

Basic Logical Operators1. Conjunction , pq (and) 2. Disjunction, pq (or) 3. Negation p(not)

Topic #1.0 Propositional Logic: Operators

The Conjunction OperatorThe binary conjunction operator (AND) combines two propositions to form their logical conjunction. E.g. If p=I will have salad for lunch. and q=I will have soup for dinner., then pq=I will have salad for lunch and I will have soup for dinner.

Logic More with Truth Tables: conjunction If you have propositions p and q, the proposition p and q is true when theyre both true, and false otherwise:P T T F F Q T F T F P^Q T F F F

Topic #1.0 Propositional Logic: Operators

The Disjunction OperatorThe binary disjunction operator (OR) combines two propositions to form their logical disjunction. p=My car has a bad engine. q=My car has a bad carburetor. pq=Either my car has a bad engine, or my car has a bad carburetor.

After the downwardpointing axe of splits the wood, you can take 1 piece OR the other, or both.

Logic More with Truth Tables: disjunction If you have propositions p and q, the proposition p or q is false when theyre both false, and true otherwise:P T T F F Q T F T F PvQ T T T F

Propositional calculus. truth tables for logical connectives

P ~P P Q T F F T T T T F F T F F

PQ PQ T F F F T T T F

ExampleIf p represents This book is good and q represents This book is cheap, write the following sentences in symbolic form: (a) This book is good and cheap. (b) This book is costly but good (c) This book is neither good nor cheap (d) This book is not good but cheap (e) This book is good or cheap (a) pq (b)(q) p (c)(p) (q) (d)( p)q (e)pq

The Implication (conditional) Operator

Topic #1.0 Propositional Logic: Operators

The implication p q states that p implies q. I.e., If p is true, then q is true; but if p is not true, then q could be either true or false. E.g., let p = You study hard. q = You will get a good grade. p q = If you study hard, then you will get a good grade.

Logic More with Truth Tables: implication p q If you have propositions p and q, the implication p q of p and q is false when p is true and q is false and is true otherwise:p T T F F q T F T F p T F T T q

Logic

More with Truth Tables: implication p

q

Other ways to refer to this implication: q if p if p, q q whenever p p only if q q is necessary for p If p, then q p is sufficient for q p implies q p T T F F q T F T F p T F T T q

More with Truth Tables: implication p q In other words, p is the hypothesis (or antecedent or premise); and q is the conclusion (or consequence)

Logic

p T T F F

q T F T F

p T F T T

q

Topic #1.0 Propositional Logic: Operators

The biconditional operatorThe biconditional p q states that p is true if and only if (IFF) q is true. p = Bush wins the 2005 election. q = Bush will be president for all of 2006. p q = If, and only if, Bush wins the 2005 election, Bush will be president for all of 2006.2005 2006 Im still here!

More with Tables: biconditional p q True when p and q have the same truth values and is false otherwise Other ways to express it: p IFF q; p is necessary and sufficient for q; if p then q, and vice versap T T F F q T F T F p T F F T q

PropositionLet P(p,q,........) denote an expression constructed from logical variables p,q,......., which take on the value True(T) or False(F), and the logical connectives , , and E.g. P(p,q) = (p q) pq (p q) p q q T T F F T F T F F T F T F T F F T F T T

Well-Formed Formulas(wff)(i) If P is a propositional variable then it is wff. (ii) If x is wff , then ~ x is a wff. (iii) If x and y are wff , then (xy), (xy), (xy), (xy)are wffs. (iv) A string of symbols is a wff iff it is obtained by finitely many applications of (i)-(iii) A wff is not a proposition , but if we substitute the proposition in place of propositional variable , we get a proposition.

Another method of constructing a truth tablep T T F F step q T F T F T F T T 4 (p T T F F 1 F T F F 3 F T F T 2 q) T F T F 1

Propositional calculus cont. Truth tables for common sentences (PQ)=(~Q~P) /contrapositive equivalenceP Q ~Q ~P PQ ~Q~P T T T F F T F F F T F T F F T T T F T T T F T T

Propositional calculus cont. Truth tables for common sentences (~PQ)=(PQ) and (P Q)=(~P Q)/disjunctive equivalence

P Q ~P ~P P Q P Q ~P Q Q T T T F F T F F F F T T T T T F T T T F T F T T T F T T

Construct truth table for pq and (pq)

Logic - EquivalencesPropositional Equivalences In mathematical arguments, you can replace a statement or proposition with another statement or proposition with the same truth value Tautology: A compound proposition (combination of propositions using logical operators) that is always True, no matter what the truth values of the propositions that are in it Contradiction: a compound proposition that is always false Contingency: proposition that is neither a tautology or a contradiction

Logic - Equivalences Propositional Equivalencesp T F F T p pv T T p F F p^ p

Contingency

tautology

contradiction

Principle of SubstitutionLet P(p,q,.......) be a tautology , and let P1(p,q,......),P2(p,q,......),...... be any propositions. Since P(p,q,........) does not depend upon the particular truth values of its variables p,q,..., we can substitute P1 for p , P2 for q, in the tautology P(p,q,.....) and still have tautology.

Theorem- If P(p,q,....) is a tautology, then P(P1,P2,.....) is a tautology for any propositions P1,P2,..........

Logical EquivalenceP(p,q,.....) Q(p,q,........) (if identical truth tables) e.g. p p, ppp

Show that (pq) (p q) p

PROPOSITIONAL EQUIVALENCESShow ( p V q ) using truth tables. and p q are logically equivalent

p T T F F

q T F T F

pVq T T T F

(p V q) F F F T

p q F F T T F T F T

(p q) F F F T

Logically equivalent using truth tables

Logic - EquivalencesLogical Equivalences: compound propositionsthat have the same truth value in all possible cases words, denotes logical equivalence between p and q, for example.p q pvq T T T T F F T F F T T F (p v q) p F F F F T F T T q F T F T p^ F F F T q Truth Table for (p v q) and p ^ q

These are logically equivalent

other tautologies: commutative law:PQ = Q P PQ=QP

associative law:P(QR) = (PQ)R P(QR) = (PQ)R

distributive law:P(QR) = (PQ)(PR) P(QR) = (PQ)(PR)

deMorgan's Law:(PQ) = (PQ) (PQ) = (PQ)

Logic - Equivalences(Laws of Algebra) Logical Equivalences: (T denotes any propositionthat is always true, F denotes one that is always false) p^T p identity laws pvF p pvT T domination laws p^F F pvp p idempotent laws p^p p ( p) p double negation laws pvq qvp commutative laws

Logic - Equivalences(Laws of Algebra) Logical Equivalences: (T denotes any proposition that is always true, F denotes one that is always false)

(p v q) v r (p ^ q) ^ r (p v (q ^ r) p ^ (q v r) (p ^ q) (p v q)

p v (q v r) p ^ (q ^ r) (p v q) ^ (p v r) (p ^ q) v (p ^ r) pv q p^ q

Associative laws Distributive laws DeMorgans Laws

These laws can be used to prove whether different compound propositions are logically equivalent

Useful Law # 1 Useful Law # 2

p V p T p p F

Useful Law # 3

p

q pVq

PROPOSITIONAL EQUIVALENCESProve (p V (p q)) p q,

This is easy to prove using the truth table. But now we want to prove it using the logical equivalences.

PROPOSITIONAL EQUIVALENCESProve (p V (p q)) p q,

Some guidance in proving using logical equivalences. 1. Do impl