You are on page 1of 67

Foundations of Computer

Science (COSC-3302),
Lecture 1 (prepared after
Chapter 1 of Martins 2011
Stefan Andrei
textbook)

04/22/16

COSC-3302, Lecture 1

Foundations of Computer
Science
COSC-3302 is a 3 credit points module with the
following grading percentages:

Active Participation in class (Stars): 10%


Assignments: 30%
Exam 1: 20%
Exam 2: 20%
Exam 3: 20%

Module homepage: Blackboard

04/22/16

COSC-3302, Lecture 1

Course Etiquette

Code of conduct
no copying
for details, see webpage

You are encouraged to attend to all lectures,


tutorials, and so on.
You are encouraged to ask questions.
You are encouraged to offer answers.

04/22/16

COSC-3302, Lecture 1

Contact Information and


Textbooks

Associate Professor and Ph.D.:

Stefan Andrei, Stefan.Andrei@lamar.edu


Office hours: 2:30pm-3:30pm on TuTh and
anytime with an email appointment

Lectures based on the book:

04/22/16

John C. Martin, Introduction to Languages and the


Theory of Computation, 4th Edition, McGraw Hill, 2011,
ISBN 9780073191461

COSC-3302, Lecture 1

Overview of This Course


1.1. Mathematical Tools and Techniques (Chapter 1)
1.2. Finite Automata and the Languages they Accept (Chapter 2)
1.3. Regular Expressions, Nondeterminism, and Kleenes Theorem (Chapter 3)
Exam 1
2.1. Context-Free Languages (Chapter 4)
2.2. Pushdown Automata (Chapter 5)
2.3. Context-Free and Non-Context-Free Languages (Chapter 6)
Exam 2
3.1. Turing Machines (Chapter 7)
3.2. Recursively Enumerable Languages (Chapter 8)
3.3. Undecidable Problems (Chapter 9)
3.4. Computable Functions (Chapter 10)
3.5. Introduction to Computational Complexity (Chapter 11)
Exam 3
04/22/16

COSC-3302, Lecture 1

Course Objectives

This is an introductory course for foundations of


computer science.

is a notation for end of definition, theorem,


lemma, proof, note, or example.

Preliminary review

introduction of the mathematics and logic for the course.


programs and computable functions,
primitive recursive functions,
the universal programs,
Turing machines and
regular languages.

04/22/16

COSC-3302, Lecture 1

Lecture Structure

Reminder of last lecture


Overview
Content (new notions + examples)
Summary
Reading suggestions
Coming up next

04/22/16

COSC-3302, Lecture 1

Mathematical Tools and


Techniques
1.
2.
3.
4.
5.
6.

Logic and Proofs


Sets
Functions and Equivalence Relations
Languages
Recursive Definitions
Structural Induction

04/22/16

COSC-3302, Lecture 1

Logic and Proofs

Logic involves propositions which have truth


values, either true or false:

0 = 1 is a proposition whose value is false


peanut butter is a source of protein is true
(get star) Is 7 a prime number?
(get star) Is 27 a prime number?

A proposition containing a free variable can


be true or false, depending on the value of
the variable.

How about x - 1 is prime?


Partial answer: true for x = 8, false for x = 10

04/22/16

COSC-3302, Lecture 1

Logic and Proofs (contd.)

Compound propositions are constructed


using the logical connectives , , , ,
and

04/22/16

COSC-3302, Lecture 1

10

Logic and Proofs (contd.)

The truth value of p is the opposite of


the truth value of p.
Truth tables show possible combinations
of p and q.

04/22/16

pq

pq

pq

pq

COSC-3302, Lecture 1

11

Logic and Proofs (contd.)

Example: For a proposition like (p q) (p


q), fill in the table in the order shown.

Column 3 is the negation of column 2,


Column 4 is the conjunction of columns 1 and 3.

04/22/16

(p q)

(p
q)

COSC-3302, Lecture 1

12

Logic and Proofs (contd.)

A tautology is a proposition that is always true:

A contradiction is a proposition that is always false:

Example: p p

Two propositions P and Q are said to be logically


equivalent if they always have the same truth
value.

Example: p p

This is written as P Q

A proposition P is said to logically imply a


proposition Q if, whenever P is true, Q is also true.

This is written as P Q

04/22/16

COSC-3302, Lecture 1

13

Logic and Proofs (contd.)

P Q and P Q look similar; however,


P Q is a proposition; it has a truth value
P Q is a meta-statement, an assertion about the
relationship between propositions P and Q
P Q means that P Q is a tautology.
Comparison (example): In object-oriented programming,
P Q may denote that class P is derived from class Q
(statement), while P Q may denote that object of
class P may be substituted/cast for object of class Q
during the run-time execution (true/false answer).
Obviously, if class P is derived from class Q, then object
of class P may be substituted/cast for object of class Q.
Similarly, P Q means that P Q is a tautology.
04/22/16

COSC-3302, Lecture 1

14

Logic and Proofs (contd.)

Logical identities can be used to simplify


compound propositions:

The commutative laws:


pqqp
pqqp

The associative laws:


p (q r) (p q) r
p (q r) (p q) r

The distributive laws:


p (q r) (p q) (p r)
p (q r) (p q) (p r)

04/22/16

COSC-3302, Lecture 1

15

Logic and Proofs (contd.)

Logical identities (contd.)

The De Morgan laws


(p q) p q
(p q) p q

An equivalent formulation of the conditional


(p q) (p q)
The contrapositive of a conditional
(p q) (q p)

An equivalent formulation of the biconditional


(p q) (p q) (q p)

04/22/16

COSC-3302, Lecture 1

16

Logic and Proofs (contd.)

The truth value of a proposition like x - 1 is


prime depends on the value of x.
We can use logical quantifiers, (for every/all) or
(for some/exists) to obtain statements that are no
longer statements about specific elements in the
domain, but statements about the domain itself

x (x - 1 is prime)
x (x - 1 is prime)

The first proposition is true if x 1 is prime for every


value of x in the domain;
The second proposition is true if x 1 is prime for
some (at least one) value of x.

04/22/16

COSC-3302, Lecture 1

17

Logic and Proofs (contd.)

In statements with more than one


quantifier, order matters:

Example: x (y (x < y)) and y (x (x < y))


are not logically equivalent.
The first says that for every x there is some
larger y (perhaps depending on x);
The second says that there is a single value y
that is larger than every x.

Here are two identities involving the


negation of a quantified statement:
(x (P(x)) x (P(x))
(x (P(x)) x (P(x))

04/22/16

COSC-3302, Lecture 1

18

Logic and Proofs (contd.)

A proof is a series of statements, each


of which is derived from:

Initial assumptions
Statements that have been derived
previously
Generally accepted facts

The derivations use principles of logical


reasoning.

04/22/16

COSC-3302, Lecture 1

19

Logic and Proofs (contd.)

A direct, constructive proof:

Prove that for every two integers a and b, if a and b


are odd, then ab is odd.
Use the definition of odd to restate this as follows:
If there exist integers i and j so that a = 2i +1 and
b = 2j +1, then there exists k such that ab =
2k +1.
Proof: ab = (2i + 1)(2j + 1)
= 4ij + 2i + 2j + 1
= 2(2ij + i + j) + 1.

If we let k be (2ij + i + j), we have the result we


want.
04/22/16

COSC-3302, Lecture 1

20

Logic and Proofs (contd.)

An indirect proof:

Prove that for every three positive integers i, j, and


n, if ij = n, then i n or j n.
Prove the contrapositive: assume there exist i, j,
and n such that (i n j n).
By De Morgan, this implies (i n) (j n), or
(i > n) (j > n).
Therefore i j > n n = n, which implies that i j n.

This is a direct proof of the contrapositive


statement, and thus an indirect proof of the
original statement.

04/22/16

COSC-3302, Lecture 1

21

Logic and Proofs (contd.)

A proof by contradiction that 2 is irrational.

Assume that there exist positive integers m and


n such that m/n = 2.
Then, by dividing m and n by all common
factors, we get p and q with no common factors
such that
p/q = 2.
Then all these statements are true: p = q2; p2
= 2q2; p2 is even; p is even; p = 2r; p2 = 4r2; q2 =
2r2; q is even.
Therefore, p and q have the common factor 2.
This is a contradiction, which shows that the
assumption is false.

04/22/16

COSC-3302, Lecture 1

22

Logic and Proofs (contd.)

A proof by cases:

If we can enumerate all of the possible


cases, and prove that the statement is true
in each case, then we have proven the
statement.
For example, if we want to prove that one
proposition P implies another proposition Q,
then looking at the truth tables for P and Q
gives us one way of enumerating all the
possible cases.

04/22/16

COSC-3302, Lecture 1

23

Sets

A finite set can be described by listing its


elements.
Example: A = {1, 2, 4, 8}

Sometimes we use ellipses:


B = {0, 3, 6, 9, }
C = {13, 14, 15, , 71}
E = {0, 3, 5, 6, 8, 9, } (what set is this? Hint:
Look 2 slides ahead).

More generally, we can use a defining property


B = {x | x is a nonnegative integer multiple of 3}
C = {x | x is an integer and 13 x 71}
B = {3y | y is a nonnegative integer}

04/22/16

COSC-3302, Lecture 1

24

Sets (contd.)

x A means that x is an element of A.

A B means that A is a subset of B.

Similarly, x A means that x is not an element of A.


i.e., every element of A is also an element of B.

The empty set is denoted by .


The order of elements when we write a set is not
significant.
Example: {0, 1} = {1, 0}.
Repetition has no effect: {0, 0, 1, 1, 1, 2} = {0, 1,
2}.
To show that A = B, we need to show that A B and
that B A.
04/22/16

COSC-3302, Lecture 1

25

Sets (contd.)

A few sets will come up frequently:

is the set of natural numbers, or


nonnegative integers
is the set of all integers
is the set of all real numbers
+ is the set of nonnegative real numbers

Now we can write B and E from above


more concisely:
B = {3y | y }
E = {3i + 5j | i, j }

04/22/16

COSC-3302, Lecture 1

26

Sets (contd.)

The union, intersection and difference of


two sets are defined as follows:
A B = {x | x A x B}
A B = {x | x A x B}
A - B = {x | x A x B}

Examples:
{1, 2, 3, 5} {2, 4, 6} = {1, 2, 3, 4, 5, 6}
{1, 2, 3, 5} {2, 4, 6} = {2}
{1, 2, 3, 5} - {2, 4, 6} = {1, 3, 5}

04/22/16

COSC-3302, Lecture 1

27

Sets (contd.)

The complement of a set

We assume that A is a subset of some universal


set U
Then the complement of A, written A, is U - A
We think of A as the set of everything that is
not in A
What this means, however, can be very different
depending on the choice of U ; for example, what
{0, 1} means depends on whether {0, 1} is
thought of as a subset of , , or .

04/22/16

COSC-3302, Lecture 1

28

Sets (contd.)

Many useful set identities are analogous to


the logical identities.

Union and intersection are commutative and


associative, and distribute across each other.

Two sets are disjoint if their intersection is


empty.
A collection of sets is pairwise disjoint if
every two distinct sets in the collection are
disjoint.
A partition of a set S is a collection of
pairwise disjoint sets whose union is S.

04/22/16

COSC-3302, Lecture 1

29

Sets (contd.)

We can describe the union of a set of sets:

Similarly for intersection:

{Ai | 0 i n} = {x | x Ai for some i with 0 i n}.


{Ai | 0 i n} = {x | x Ai for every i with 0 i n}.

The set of all subsets of a set A is called the power


set of A and is written 2A.

2A = { X | X A }.
Example:
2{a,b,c} = {, {a}, {b}, {c}, {a,b}, {a,c}, {b,c},
{a,b,c}}.
Note: the empty set and the set A itself are in As power
set.
Example: How much is 2{a,b,c,d}?

04/22/16

COSC-3302, Lecture 1

30

Sets (contd.)

The Cartesian product of two sets A and


B, denoted A B, is the set of all
ordered pairs with first element from A
and second element from B.
A B = {(a, b) | a A and b B}.
We can generalize this to ordered k-tuples:
A1 A2 Ak = {(a1, a2, , ak | ai Ai for
each i}.

04/22/16

COSC-3302, Lecture 1

31

Functions and Equivalence


Relations

f : A B means that f is a function from A to B.

To each element of A, one element of B is assigned.


A is the domain of the function and B the codomain.

Examples:
1.
2.

f : defined by the formula f(x) = x.


g : 2 2 defined by g(A) = A {0}.

f and g are equal if and only if they have the


same domain and codomain and f (x) = g(x) for
every x in the domain.
Partial functions from A to B may assign values to
only some elements of A.

04/22/16

COSC-3302, Lecture 1

32

Functions and Equivalence


Relations (contd.)

The range of a function is the set of elements of the


codomain that are actually values of the function.

{ f (x) | x A} (a subset of the codomain B).

04/22/16

COSC-3302, Lecture 1

33

Functions and Equivalence


Relations (contd.)

If f : A B is a bijection then we can


define the inverse function f -1 from B to
A by these two formulas: for every x
A and y B,

f -1( f(x) ) = x

f (f -1(y)) = y.

It is easy to check that f


bijection.

04/22/16

COSC-3302, Lecture 1

-1

is also a

34

Functions and Equivalence


Relations (contd.)

An n-ary operation on a set A is a function that


assigns to every ordered n-tuple of elements of
A an element of A.
Unary and binary operations are of most
interest:

Binary operations on the integers include addition.


For every set S, binary operations on 2S include
union and intersection.
Unary operations include negation (on the set of
integers, for example) and complementation (on the
set 2A).

04/22/16

COSC-3302, Lecture 1

35

Functions and Equivalence


Relations (contd.)

For a unary or binary operation on a set A.

We say that a subset A1 of A is closed under the


operation if the result of applying the operation
to elements of A1 is an element of A1.

If A = 2 and A1 is the set of nonempty subsets


of A, then A1 is closed under union but not
under intersection.
The set of even natural numbers is closed
under addition and multiplication.
The set of odd natural numbers is closed under
multiplication but not addition.

04/22/16

COSC-3302, Lecture 1

36

Functions and Equivalence


Relations (contd.)

Relations

We can express relationships several


ways: If R is a relation on a set, we can
write a is related to b as a R b or as
(a, b) R.

04/22/16

COSC-3302, Lecture 1

37

Functions and Equivalence


Relations (contd.)

Examples:

The equality relation (a relation on any set);


The relation on A containing all ordered pairs;
The relation of congruence mod n on the set .

04/22/16

COSC-3302, Lecture 1

38

Functions and Equivalence


Relations (contd.)

We may drop the subscript and just say [x] if there is


no opportunity for confusion.
Theorem: If R is an equivalence relation on A, the
equivalence classes with respect to R form a partition
of A, and two elements of A are equivalent if and only
if they are elements of the same equivalence class.

04/22/16

COSC-3302, Lecture 1

39

Languages

An alphabet is a finite set of symbols usually


denoted by .

Examples: {a, b}, {0, 1}, {A, B, C, , Z}

A string over is a finite sequence of symbols.


|x| stands for the length of the string x.
na(x) is the number of occurrences of a in the
string x.
The null string is a string over any alphabet
.
|| = 0

04/22/16

COSC-3302, Lecture 1

40

Languages (contd.)

The set of all strings over is *.


Example: {a, b}* = {, a, b, aa, ab, ba, bb, aaa,
aab,}
(get a *) Enumerate {a, b, c}*.
A language over is a subset of *.
Examples:

The empty language


{, a, aab}, a finite language.
The palindromes over {a, b} (strings like , a, and
baabaab that read the same backwards as forwards).
{x {a, b}* | na(x) > nb(x)}.
{x {a, b}* | |x| 2 and x begins and ends with b}.

04/22/16

COSC-3302, Lecture 1

41

Languages (contd.)

Definition: xy is the concatenation of the two


strings x and y; this is the basic operation on
strings.

Example: If x = ab and y = bab then xy = abbab and yx


= babab
For every string x, x = x = x
|xy| = |x| + |y|

Concatenation is associative, i.e., (xy)z = x(yz), so


we can write xyz without worrying about how
terms are grouped.
If s = tuv then t is a prefix of s, v is a suffix, and u
is a substring.

Every string is a prefix (and suffix, and substring) of


itself.

04/22/16

COSC-3302, Lecture 1

42

Languages (contd.)

For languages L1, and L2 over :

If L *, the complement of L is a language, * - L.


For languages L1, L2 over :

L1 L2, L1 L2, and L1 L2 are also languages over

L1L2 is the language {xy | x L1 and y L2}.

We use exponential notation ak = aaaa, where


there are k occurrences of a.
This also applies to strings (xk = xxxx) and
languages (Lk = LLLL).
a0 = x0 = , L0 = {} (for every a , x *, L
*).

04/22/16

COSC-3302, Lecture 1

43

Languages (contd.)

If L is a language over , then L* denotes the


language of all strings that can be obtained
by concatenating zero or more strings in L.

This operation is known as the Kleene star.

L* = {Lk | k }.
L* for every language L, since L0 = {}.
Strings are finite, and languages may not be,
but to use a language we need a finite
description:

L1 = {ab, bab}* {b} {ba}*{ab}*.

L2 = {x {a, b}* | na(x) > nb(x)}.

04/22/16

COSC-3302, Lecture 1

44

Recursive Definitions

A recursive definition of a set has a basis


statement that specifies at least one member
of the set, and a recursive part that specifies
how additional members of the set can be
generated in terms of given members.
The prototypical example is , the set of
natural numbers.
It can be defined as follows:

Basis statement: 0 .
Recursive part: if n then n+1 .
Every element of can be obtained from the
first two statements.

04/22/16

COSC-3302, Lecture 1

45

Recursive Definitions
(contd.)
Summary:

The third statement in the definition of is what


says that is the smallest set that contains 0 and is
closed under the successor operation (addition by
1).
The statement that the set being defined is the
smallest is frequently omitted but always
understood.

Example: the subset B = { 2i 5j | i, j }.

1B
For every n B, 2n B
For every n B, 5n B

04/22/16

COSC-3302, Lecture 1

46

Recursive Definitions
(contd.)
We denote by F the subset of 2

{a, b}*

defined

by:

, {}, {a}, {b} F


if L1, L2 F then L1 L2 F
if L1, L2 F then L1L2 F

F is the smallest set of languages that

contains the languages , {}, {a}, and {b}


and is closed under union and concatenation.
It is easy to see that F is the set of all finite
languages over {a, b}.

04/22/16

COSC-3302, Lecture 1

47

Recursive Definitions

(contd.)
Example (real-world): The set of cities
reachable from city s.

Suppose that C is a finite set of cities, and the


relation R is defined on C so that c R d means
there is a nonstop commercial flight from c to d.
For a city s C, we would like to describe r(s),
the set of cities reachable from s by taking zero
or more nonstop flights.
We can define r(s) this way:

s r(s).

if c r(s) and c R d then d r(s).

04/22/16

COSC-3302, Lecture 1

48

Structural Induction

Consider again the language Expr:

a Expr.
For every x and every y in Expr, x y and x y are in
Expr (where x y and x y are the strings x+y, x*y).
For every x Expr, (x) Expr (where (x) is (x) ).

Note: this seems like unnecessarily confusing


notation (why do we need the operator symbols
, , and , when we already have the
operators + and *?).
The reason is that + and * are operations on
numbers, but were talking about strings, not
numbers.
In this discussion +, *, (, and ) are just symbols
in the alphabet.

04/22/16

COSC-3302, Lecture 1

49

Structural Induction (contd.)

To prove that every string x Expr satisfies a condition


P(x), use structural induction, that is, to show that:
P(a) is true;
For every x and every y in Expr, if P(x) and P(y) are
true, then P(x y) and P(x y) are true;
For every x Expr, if P(x) is true, then P((x)) is true.
In other words, show that the set of elements x
satisfying the property P contains a and is closed under
, , and .
This set must then contain every element in the
smallest set that contains a and is closed under the
operations, i.e., every element in Expr.

04/22/16

COSC-3302, Lecture 1

50

Structural Induction (contd.)

The recursive definition of Expr consists of

A basis part ( a Expr ).


Three recursive parts, the first of the form:
If x, y Expr then x y Expr.

The basis step of the proof is to show that


P(a) is true.
The induction hypothesis is that x, y Expr
and that P(x) and P(y) are true.
The first case of the induction step is to show
that P(x y) is true. (Similarly for the other 2
operations).

04/22/16

COSC-3302, Lecture 1

51

Structural Induction (contd.)

Examples: a + b has 3 symbols.


How many symbols does c*(a + b) have?
7 symbols.
Let us consider P(x) is x has odd length, where x Expr.
The basis step of the proof is to show that a has odd length,
and this is clearly true: |a| = 1.
The induction hypothesis is that x, y Expr and that x and y
have odd length (i.e., |x| and |y| are odd).
The three cases in the induction step are to show that
x y, x y, and (x) have odd length.
These are all true, because:
|x y| = | x + y | = |x| + |y| + 1, and odd + odd + 1 = odd
(1 because of +).
|x y| = | x*y | = |x| + |y| + 1 (1 because of *).

|(x)| = |(x)| = |x| + 2, and odd + 2 = odd (2 because of (


and ))

04/22/16

COSC-3302, Lecture 1

52

Structural Induction (contd.)

Mathematical induction is simply structural


induction based on the recursive definition
of given earlier.
This is used to prove statements of the form
for every integer n n0, P(n).

Basis step: prove the statement P(n) for n = n0.

Induction hypothesis: k is an integer n0 and


P(k) is true.
Induction step: show using the induction
hypothesis that P(k+1) is true.

04/22/16

COSC-3302, Lecture 1

53

Structural Induction (contd.)

Exercise: For every n , every set A with n


elements, 2A has exactly 2n elements.

04/22/16

Basis: for every set A with 0 elements, 2 A has


20 elements; this is true because only has
zero elements, and 2 = {}, which has one
element.
Induction hypothesis: k , and for every set
A with k elements, 2A has 2k elements.
Induction step: to show that for every set A
with k+1 elements, 2A has 2k+1 elements.

COSC-3302, Lecture 1

54

Structural Induction (contd.)

Prove: For every n , and every set A with


n elements, 2A has exactly 2n elements
(contd.)

Proof of induction step:

04/22/16

Let A be a set with k + 1 elements, and let a be


any element of A (there is one, since k + 1 1).
Then A - {a} has k elements, and 2A-{a} has 2k
elements by the induction hypothesis;
therefore, A has 2k subsets that do not contain
a and 2k subsets that do contain a, for a total of
2k+1 subsets.
COSC-3302, Lecture 1

55

Structural Induction (contd.)

Strong induction is another form of induction.


Exercise: Prove that for every n 2, n is
either prime or a product of two or more
primes.

Let us strengthen the statement: for n 2, every


number m such that 2 m n is either prime or
a product of two or more primes.
The reason for this, as well see, is that it gives us
a stronger induction hypothesis but does not
actually require that we prove any more than we
would have anyway.

04/22/16

COSC-3302, Lecture 1

56

Structural Induction
(contd.)

Proof:

04/22/16

Basis step: To show that every m satisfying


2 m 2 is either prime or a
product of primes. This reduces to showing
that 2 is, and 2 is prime.
Induction hypothesis: k 2, and for every m
satisfying 2 m k, m is either a prime or
a product of primes.
Statement to prove in induction step: For
every m satisfying 2 m k + 1, m is
either prime or a product of primes.
COSC-3302, Lecture 1

57

Structural Induction (contd.)

Proof of induction step: For every m with 2 m


k, we already have the conclusion we want, from
the induction hypothesis.

The only additional statement we need to prove is


that k + 1 is either prime or a product of primes.

If k + 1 is prime, were done; if not, k + 1 is the


product of two smaller numbers, both bigger
than 1.

By the (stronger) induction hypothesis, both are


prime or the product of primes.
Therefore (in either case), k + 1 is the product of
primes.

04/22/16

COSC-3302, Lecture 1

58

Structural Induction (contd.)

The language Balanced was defined as follows:

Balanced
If x, y Balanced, then xy Balanced and (x)
Balanced

Let us prove that x Balanced if and only if


B(x) is true, where B(x) is x contains equal
numbers of left and right parentheses, and no
prefix of x contains more right than left.
The only if part is straightforward; use
structural induction, based on the definition of
Balanced.

04/22/16

COSC-3302, Lecture 1

59

Structural Induction
(contd.)
The basis step is to show that B() is true.

This is clear, because has no symbols and no


nonnull prefixes.

The induction hypothesis is that x, y


Balanced and both B(x) and B(y) are true.
We must show that B(xy) and B( (x) ) are true.

Both xy and (x) have equal numbers of left and right


parentheses, because x and y do.
A prefix of xy is either a prefix of x, or xz for some
prefix z of y; a prefix of (x) other than (x) is or (z,
for some prefix z of x.
In all these cases, the statement is true by the
induction hypothesis.

04/22/16

COSC-3302, Lecture 1

60

Structural Induction (contd.)

For the reverse (the if part), use induction on


the length of the string.
Prove: For every n , if x is a string of
parentheses so that |x| = n and B(x) is true then
x Balanced.

Basis: if |x| = 0 then x = , so x Balanced.


Induction hypothesis: k , and for every string x
of parentheses, if |x| k and B(x), then x
Balanced (since we say |x| k, were using strong
induction).
To prove: if |x| = k + 1 and B(x), then x
Balanced.
Proof: the details get a little involved; see book.

04/22/16

COSC-3302, Lecture 1

61

Structural Induction (contd.)

Sometimes making a statement stronger makes it


easier to prove.

Lets prove that no string in Expr contains ++ as a


substring.

The basis step is easy to prove, and so are the


induction steps for x*y and (x).
In the case of x + y, what if x ends with + or y
begins with +?
Strengthen the statement: prove that no string
contains ++ as a substring, or begins or ends with
+.

Now the stronger induction hypothesis makes it possible


to complete the proof.

04/22/16

COSC-3302, Lecture 1

62

Structural Induction (contd.)

Recursive definitions of sets lead naturally to ways of


defining functions on those sets.
Example: if we define a function f at 0, and then
define f (n+1) assuming that f (n) is defined, then f is
effectively defined over .
(get a *) Define n! = 1 2 n in a recursive
way.
The factorial function is defined this way:
f(0) = 1; f(n+1) = (n+1) * f(n).
Definitions like these are particularly well suited to
induction proofs of properties of the corresponding
functions.
04/22/16

COSC-3302, Lecture 1

63

Summary
1.
2.
3.
4.
5.
6.

Logic and Proofs


Sets
Functions and Equivalence Relations
Languages
Recursive Definitions
Structural Induction

04/22/16

COSC-3302, Lecture 1

64

Reading suggestions

From [Martin; 2011]


Chapter 1 (Mathematical Tools and Techniques)

04/22/16

COSC-3302, Lecture 1

65

Coming up next

From [Martin; 2011]:


Chapter 2 (Finite Automata and the Languages
they Accept)

04/22/16

COSC-3302, Lecture 1

66

Thank you for your


attention!
Questions?

04/22/16

COSC-3302, Lecture 1

67

You might also like