0% found this document useful (0 votes)
16 views33 pages

01 Intro Logic

The document serves as an introduction and review of elementary logic for the COMP2600 course at the Australian National University. It covers topics such as formal reasoning, propositional logic, and quantifiers, while also outlining the course assessment structure and resources. The importance of studying logic in programming, communication, and clear thinking is emphasized throughout.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views33 pages

01 Intro Logic

The document serves as an introduction and review of elementary logic for the COMP2600 course at the Australian National University. It covers topics such as formal reasoning, propositional logic, and quantifiers, while also outlining the course assessment structure and resources. The importance of studying logic in programming, communication, and clear thinking is emphasized throughout.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

Introduction

and

A Review of Elementary Logic

COMP2600 — Formal Methods for Software Engineering

Clem Baker-Finch

Australian National University


Semester 2, 2009

COMP 2600 — Logic Review 1


What do we mean by FORMAL?

OED: Concerned with the form, rather than the matter, of reasoning.

The validity of logical arguments depends on their form, rather than their
content.

1. Abstracting away the content allows us to study reasoning as reasoning,


without the content getting in the way;

2. If we can express an argument formally, we (may) have more confidence


it is correct;

3. If we want to automate something, first we must formalise it.

COMP 2600 — Logic Review 2


Topics

 Logic and Natural Deduction


 Proving Properties of Functional Programs (Induction)
 Proving Properties of Imperative Programs
 Lambda Calculus, Types
 Automata, Languages and Parsing
 Turing Machines, Computability, . . .

COMP 2600 — Logic Review 3


Assessment

 Assignments: 4  9% each
 Participation: 4%
 Final Exam: 60%
 Final mark capped at Exam*(100/60)+10%

During week 7 or thereabouts, there will be a practice test during class time.
We will also work through solutions in a later class. The practice test will not
be for credit.

COMP 2600 — Logic Review 4


Things to Do:

 Register for a tutorial in Streams. Tutorials start in week 3.


 Check out the COMP2600 website
http://cs.anu.edu.au/Student/comp2600/
– Textbooks
– Tentative Schedule
– Forum

 Any Questions? . . . Ask me later.

COMP 2600 — Logic Review 5


Role of Haskell in 2600

 Until a few years ago, functional programming was introduced in 2600.


COMP1100 plays that role.

 Haskell is used in 2600: for study of inductive types, definitions, and


proofs.

 More on assumed knowledge in lecture 3.


 If needed see 1100 web pages.

COMP 2600 — Logic Review 6


History of Logic, the Science of Reasoning

 Aristotle (384–322BC), the “father of logic”: syllogistic logic.


 Universal calculus of Leibniz (1646–1716): symbolic logic (and binary
numerals).

 More symbolic logic by George Boole (1815–64): Boolean algebra.


 Principia Mathematica by Bertrand Russell: mathematical logic.
 Church, Turing, Curry, Goedel, Scott, Milner etc.: Formal frameworks for
presenting models of systems and for reasoning about them.

COMP 2600 — Logic Review 7


Why study logic?

Coolness: Logic is cool — trust me.

Hardware: Binary logic is logical.

Software: Programming languages have logical constructs.

Specification and semantics: The language of logic is unambiguous and


can be used to give meaning to programs.

Proof: Arguments should be logical.

Every day: Clearer thinking in every day situations. More effective


communication.

COMP 2600 — Logic Review 8


Propositions

 A proposition is a logical sentence.


 A proposition is either true or false, but not both.
 T F : Bool.
;

 Examples:
– I am the smartest person in the room.
– John had toast for breakfast.
– 2 + 2 = 5.

 Questions, commands and expletives are not propositions.

COMP 2600 — Logic Review 9


Definition by Truth table

Conjunction is defined to be the function specified by this table.

p q p^q
T T T
T F F
F T F
F F F

Disjunction, negation, implication are similarly defined.

COMP 2600 — Logic Review 10


Tautologies

A propositional formula is said to be a tautology if it is true for all possible


assignments of truth values to its variables.

p :p p_:p
T F T
F T T

In general, to prove a tautology, one can construct a truth table for the
proposition and checks that its column is all T’s.

COMP 2600 — Logic Review 11


Contradictions and Contingencies

Contradiction: A contradiction is a compound proposition which evaluates


to F for all values of its elementary propositions.

Contingency: A contingency is a compound proposition which may


evaluate to T or F for different values of its elementary propositions.

COMP 2600 — Logic Review 12


An Important Syntactic Matter

To avoid ambiguities and minimise parentheses, the logical operators can be


assigned a precedence:

 : (highest)
^
_
)
 , (lowest)
Examples:

 : p _ q ) r ^ s  ((: p ) _ q ) ) (r ^ s )
 p _ q ^ r  p _ (q ^ r )
COMP 2600 — Logic Review 13
(Algebraic) Laws of Propositional Calculus

Associative laws

 p _ (q _ r )  (p _ q ) _ r
 p ^ (q ^ r )  (p ^ q ) ^ r

Distributive laws

 p ^ (q _ r )  (p ^ q ) _ (p ^ r )
 p _ (q ^ r )  (p _ q ) ^ (p _ r )
These are just a representative few.

COMP 2600 — Logic Review 14


Formalising Arguments

That is, identifying the form of the argument. . .

 Consider the line of reasoning.


 Identify the propositions.
 Identify the connectives.
 Translate to symbols.

COMP 2600 — Logic Review 15


Argument Forms

An argument may be written as:

p1
..
.
pn
q
or (equivalently) as:

p ^ ^ pn ) ) q
( 1 :::

COMP 2600 — Logic Review 16


Typical Application

An argument expressed in English:

 If the professor is naked then the class is amused.


 If the class is amused and the material is organized then the class is
happy.

 The lecture is good if both the material is organized and the class is
happy.

 Therefore, the lecture is good if the professor is naked.

COMP 2600 — Logic Review 17


Typical Application (ctd)

Construct the propositional logic argument form.

Give a single propositional formula which, if it is a tautology, signifies the


argument form is valid.

Is the argument form valid?

COMP 2600 — Logic Review 18


Disjunctive Syllogism — Inference rule

One of Aristotle’ patterns of valid deduction:

p_q
:p
q

COMP 2600 — Logic Review 19


Disjunctive Syllogism — Example

The student was happy _ The student was awake


: The student was happy
The student was awake

COMP 2600 — Logic Review 20


Disjunctive Syllogism — Proof in the Algebraic Style

p _ q) ^ : p ) q
(

 : p ^ (p _ q ) ) q (commutativity)
 (: p ^ p ) _ (: p ^ q ) ) q (distribution)
 F _ (: p ^ q ) ) q (contradiction)
 :p^q ) q (or-simplification)
 : (: p ^ q ) _ q (implication)
 (p _ : q ) _ q (De Morgan)
 p _ (: q _ q ) (associativity)
 p_T (excluded middle)
T (or-simplification)

COMP 2600 — Logic Review 21


NOT a Disjunctive Syllogism — Example

The student was happy _ The student was awake


The student was happy

: The student was awake

This “reasoning” is INVALID.

COMP 2600 — Logic Review 22


Modus ponens — Inference rule

p)q
p
q

Modus Ponens is important!


(so important that you must know the Latin name)

COMP 2600 — Logic Review 23


Modus Ponens — Example

The student worked hard ) The student passed


The student worked hard

The student passed

COMP 2600 — Logic Review 24


NOT Modus Ponens — Example

The student worked hard ) The student passed


The student passed

The student worked hard

This “reasoning” is INVALID.

COMP 2600 — Logic Review 25


Limitations of propositional logic

Consider this “argument”:

Natural language Propositional logic


All COMP2600 students are happy. p
Lisa is a COMP2600 student. q
Therefore, Lisa is happy. )r
Useful? No! This is not a valid argument form in terms of propositional logic,
since p ^ q ) r is not a tautology. (There is no relationship between the
propositions.)

COMP 2600 — Logic Review 26


Lisa studies predicate calculus!

 What are the predicates?


p (x )  x is a COMP2600 student.
q (x )  x is happy.
 Now the argument looks like:
8 x p (x ) ) q (x )
:

p (Lisa)
) q (Lisa)
. . . which we might be able to deal with. . .

COMP 2600 — Logic Review 27


Predicates — Introduction

 Predicates are conventionally written as expressions containing


unbound variables, such as x 5.>

 A predicate is a mapping from some domain to a Boolean value, such as


p : N ! Bool where p (x )  x 5. >

 The domain of a predicate is some set of appropriate values for the


variable(x) in the predicate expression. In the above example the
domain of p is N.
 If a predicate contains more than one variable, then the elements of the
domain are tuples. That is x + y = 5 is the function p : N  N ! Bool
where p (x y )  (x + y = 5).
;

 Instantiating the variables in a predicate with values yields a proposition.


COMP 2600 — Logic Review 28
Universal quantification — Definitions

 General form: 8 x 2 D P (x ):
:

 8 x 2 D P (x ): means that for any x chosen from D , P (x ) is a true


:

proposition.

 In 8 x 2 D P (x ):
:

– 8 is the quantifier ;
– x is the bound variable;
– D is the domain;
– P (x ) is a predicate (possibly) involving the bound variable x .

COMP 2600 — Logic Review 29


Universal quantification — Abbreviations and rules

 The domain can be omitted if it can be inferred from the context:


8 x P (x ).
:

 8 x y 2 D P (x y ) is an abbreviation for 8 x 2 D (8 y 2 D P (x y ))
; : ; : : ;

 Unnecessary parenthesis may be omitted: 8 x 2 D 8 y 2 D P (x y ).


: : ;

 (8 x 8 y P (x y ))  (8 y 8 x P (x y )).
: : ; : : ;

For example, (8 x 8 y x + y = y + x )  (8 y 8 x x + y = y + x ).
: : : :

COMP 2600 — Logic Review 30


Existential quantification — Introduction

9
The existential quantifier is denoted by , and is pronounced for some or
there exists.

Examples:

 “Some students are happy”.


 “There is a happy student”.
 9 s 2 Student s is happy.
:

 9 x (9 y x + y = y x ).
: :

COMP 2600 — Logic Review 31


Existential quantification — Definitions

General form: 9 x 2 D P (x ):
:

9 x 2 D P (x ): means that for one or more x chosen from D , P (x ) is a


:

true proposition.

In 9 x 2 D P (x ):
:

 9 is the quantifier ;
 x is the bound variable;
 D is the domain;
 P (x ) is a predicate (possibly) involving the bound variable x .

COMP 2600 — Logic Review 32


References

 Discrete Mathematics with Applications, 3rd Edition, Susanna Epp


(the principal textbook for MATH1005 for years)

 The Logic Book, Merrie Bergmann


(text for PHIL logic course)

 Many others . . .

COMP 2600 — Logic Review 33

You might also like