Docsity

Logic-Software Engineering-Lecture 07 Slides-Computer Science, Slides of Software Engineering

Partial preview of the text

Download Logic-Software Engineering-Lecture 07 Slides-Computer Science and more Slides Software Engineering in PDF only on Docsity!

LECTURE 7: PROPOSITIONAL

LOGIC (1)

Software Engineering

1 What is a Logic?

  • When most people say ‘logic’, they mean either propositional logic or first-order predicate logic.
  • However, the precise definition is quite broad, and literally hundreds of logics have been studied by philosophers, computer scientists and mathematicians.
  • Any ‘formal system’ can be considered a logic if it has: - a well-defined syntax; - a well-defined semantics; and - a well-defined proof-theory.

2 Propositional Logic

  • The simplest, and most abstract logic we can study is called propositional logic.
  • Definition: A proposition is a statement that can be either true or false; it must be one or the other, and it cannot be both.
  • EXAMPLES. The following are propositions: - the reactor is on; - the wing-flaps are up; - John Major is prime minister. whereas the following are not: - are you going out somewhere? - 2+
  • It is possible to determine whether any given statement is a proposition by prefixing it with:

It is true that...

and seeing whether the result makes grammatical sense.

  • We now define atomic propositions. Intuitively, these are the set of smallest propositions.
  • Definition: An atomic proposition is one whose truth or falsity does not depend on the truth or falsity of any other proposition.
  • So all the above propositions are atomic.

2.1 The Connectives

  • Now, the study of atomic propositions is pretty boring. We therefore now introduce a number of connectives which will allow us to build up complex propositions.
  • The connectives we introduce are:

∧ and (& or .) ∨ or (| or +) ¬ not (∼) ⇒ implies (⊃ or →) ⇔ iff

  • (Some books use other notations; these are given in parentheses.)

And

  • Any two propositions can be combined to form a third proposition called the conjunction of the original propositions.
  • Definition: If p and q are arbitrary propositions, then the conjunction of p and q is written p ∧ q and will be true iff both p and q are true.

Or

  • Any two propositions can be combined by the word ‘or’ to form a third proposition called the disjunction of the originals.
  • Definition: If p and q are arbitrary propositions, then the disjunction of p and q is written p ∨ q and will be true iff either p is true, or q is true, or both p and q are true.
  • The operation of ∨ is summarised in the following truth table: p q p ∨ q F F F F T T T F T T T T
  • Definition: If p and q are arbitrary propositions, then the conditional of p and q is written p ⇒ q and will be true iff either p is false or q is true.
  • The truth table for ⇒ is:

p q p ⇒ q F F T F T T T F F T T T

  • The ⇒ operator is the hardest to understand of the operators we have considered so far, and yet it is extremely important.
  • If you find it difficult to understand, just remember that the p ⇒ q means ‘if p is true, then q is true’. If p is false, then we don’t care about q, and by default, make p ⇒ q evaluate to T in this case.
  • Terminology: if φ is the formula p ⇒ q, then p is the antecedent of φ and q is the consequent.
  • The truth table for ⇔ is:

p q p ⇔ q F F T F T F T F F T T T

  • If p ⇔ q is true, then p and q are said to be logically equivalent. They will be true under exactly the same circumstances.

Not

  • All of the connectives we have considered so far have been binary: they have taken two arguments.
  • The final connective we consider here is unary. It only takes one argument.
  • Any proposition can be prefixed by the word ‘not’ to form a second proposition called the negation of the original.
  • Definition: If p is an arbitrary proposition then the negation of p is written ¬p and will be true iff p is false.
  • Truth table for ¬:

p ¬p F T T F

3 Tautologies & Consistency

  • Given a particular formula, can you tell if it is true or not?
  • No — you usually need to know the truth values of the component atomic propositions in order to be able to tell whether a formula is true.
  • Definition: A valuation is a function which assigns a truth value to each primitive proposition.
  • In Modula-2, we might write:

PROCEDURE Val(p : AtomicProp): BOOLEAN;

  • Given a valuation, we can say for any formula whether it is true or false.
  • EXAMPLE. Suppose we have a valuation v, such that: v(p) = F v(q) = T v(r) = F Then we truth value of (p ∨ q) ⇒ r is evaluated by: (v(p) ∨ v(q)) ⇒ v(r) (1) = (F ∨ T) ⇒ F (2) = T ⇒ F (3) = F (4) Line (3) is justified since we know that F ∨ T = T. Line (4) is justified since T ⇒ F = F. If you can’t see this, look at the truth tables for ∨ and ⇒.