Induction II: Inductive Pictures

129
Induction II: Inductive Pictures Great Theoretical Ideas In Computer Science Steven Rudich CS 15-251 Spring 2004 Lecture 14 Feb 26, 2004 Carnegie Mellon University

description

Induction II: Inductive Pictures. Inductive Proof: “Standard” Induction “Least Counter-example” “All Previous” Induction Inductive Definition: Recurrences Recursive Programming. Theorem ? (k ¸ 0) 1+2+4+8+…+2 k = 2 k+1 -1 Try it out on small examples: 2 0 = 2 1 -1 - PowerPoint PPT Presentation

Transcript of Induction II: Inductive Pictures

Page 1: Induction II: Inductive Pictures

Induction II:Inductive Pictures

Great Theoretical Ideas In Computer Science

Steven Rudich

CS 15-251 Spring 2004

Lecture 14 Feb 26, 2004 Carnegie Mellon University

Page 2: Induction II: Inductive Pictures

Inductive Proof: “Standard” Induction

“Least Counter-example”“All Previous” Induction

Inductive Definition:Recurrences

Recursive Programming

Page 3: Induction II: Inductive Pictures

Theorem? (k¸0)1+2+4+8+…+2k = 2k+1 -1

Try it out on small examples:20 = 21 -120 + 21 = 22 -120 + 21 + 22 = 23 -1

Page 4: Induction II: Inductive Pictures

Sk´ “1+2+4+8+…+2k = 2k+1 -1”

Use induction to prove k¸0, Sk

Establish “Base Case”: S0. We have already check it.

Establish “Domino Property”: k¸0, Sk ) Sk+1

“Inductive Hypothesis” Sk:

1+2+4+8+…+2k = 2k+1 -1

Add 2k+1 to both sides:

1+2+4+8+…+2k + 2k+1= 2k+1 +2k+1 -11+2+4+8+…+2k + 2k+1= 2k+2 -1

Page 5: Induction II: Inductive Pictures

FUNDAMENTAL LEMMA OF THE POWERS OF TWO:

The sum of the first n powers of 2, is one less than the next power of 2.

Page 6: Induction II: Inductive Pictures

Yet another way of packaging inductive

reasoning is to define an “invariant”.

Invariant (adj.) 1. Not varying; constant.

2. (mathematics) Unaffected

by a designated operation, as a transformation of coordinates.

Page 7: Induction II: Inductive Pictures

Yet another way of packaging inductive

reasoning is to define an “invariant”.

Invariant (adj.)

3. (programming) A rule, such as the ordering an ordered list or heap, that applies throughout the life of a data structure or procedure.

Each change to the data structuremust maintain the correctness of the invariant.

Page 8: Induction II: Inductive Pictures

Invariant InductionSuppose we have a time varying

world state: W0, W1, W2, …Each state change is assumed to come from a list of permissible

operations. We seek to prove that statement S is true of all future

worlds. Argue that S is true of the initial world.

Show that if S is true of some world – then S remains true after one permissible operation is performed.

Page 9: Induction II: Inductive Pictures

Odd/Even Handshaking Theorem: Odd/Even Handshaking Theorem: At any party, at any point in time, define a At any party, at any point in time, define a person’s parity as ODD/EVEN according to person’s parity as ODD/EVEN according to the number of hands they have shaken.the number of hands they have shaken. Statement: The number of people of odd Statement: The number of people of odd

parity must be even.parity must be even.

Initial case: Zero hands have been shaken at the start of a party, so zero people have odd parity.

If 2 people of different parities shake, then they both swap parities and the odd parity count is unchanged. If 2 people of the same parity shake, they both change. But then the odd parity count changes by 2, and remains even.

Page 10: Induction II: Inductive Pictures

Inductive Definition of n!

[said n “factorial”]

0! = 1; n! = n*(n-1)!

Page 11: Induction II: Inductive Pictures

0! = 1; n! = n*(n-1)!

F:=1;For x = 1 to n do

F:=F*x;Return F

Program for n! ?

Page 12: Induction II: Inductive Pictures

0! = 1; n! = n*(n-1)!

F:=1;For x = 1 to n do

F:=F*x;Return F

Program for n! ?

n=0 returns 1n=1 returns 1n=2 returns 2

Page 13: Induction II: Inductive Pictures

0! = 1; n! = n*(n-1)!

F:=1;For x = 1 to n do

F:=F*x;Return F

Loop Invariant: F=x!True for x=0. If true after k times through – true after k+1 times through.

Page 14: Induction II: Inductive Pictures

Inductive Definition of T(n)

T(1) = 1T(n) = 4 T(n/2) + n

Notice that T(n) is inductively defined for positive powers of 2, and undefined on other values.

Page 15: Induction II: Inductive Pictures

Inductive Definition of T(n)

T(1) = 1T(n) = 4T(n/2) + n

Notice that T(n) is inductively defined for positive powers of 2, and undefined on other values.

T(1)=1 T(2)=6 T(4)=28 T(8)=120

Page 16: Induction II: Inductive Pictures

Guess a closed form formula for T(n).

Guess G(n)

G(n) = 2n2 - nLet the domain of G be the powers of two.

Page 17: Induction II: Inductive Pictures

Two equivalent functions?

G(n) = 2n2 - nLet the domain of G be the powers of two.

T(1) = 1T(n) = 4 T(n/2) + nDomain of T are the powers of two.

Page 18: Induction II: Inductive Pictures

Inductive Proof of EquivalenceInductive Proof of Equivalence

Base: G(1) = 1 and T(1) = 1

Induction Hypothesis:T(x) = G(x) for x < n

Hence: T(n/2) = G(n/2) = 2(n/2)2 – n/2

T(n) = 4 T(n/2) + n= 4 G(n/2) + n

= 4 [2(n/2)2 – n/2] + n= 2n2 – 2n + n= 2n2 – n= G(n)

G(n) = 2n2 - n

T(1) = 1T(n) = 4 T(n/2) + n

Page 19: Induction II: Inductive Pictures

We inductively proved the assertion that

G(n) =T(n).

Giving a formula for T with no sums or

recurrences is called solving the recurrence

T.

Page 20: Induction II: Inductive Pictures

Solving RecurrencesSolving RecurrencesGuess and VerifyGuess and Verify

Guess: G(n) = 2n2 – n

Verify: G(1) = 1 and G(n) = 4 G(n/2) + n

Similarly:T(1) = 1 and T(n) = 4 T(n/2) + n

So T(n) = G(n)

Page 21: Induction II: Inductive Pictures

Technique 2Technique 2Guess Form and Calculate CoefficientsGuess Form and Calculate Coefficients

Guess: T(n) = an2 + bn + c for some a,b,c

Calculate: T(1) = 1 a + b + c = 1

T(n) = 4 T(n/2) + n an2 + bn + c = 4 [a(n/2)2 + b(n/2) + c] + n = an2 + 2bn + 4c + n (b+1)n + 3c = 0

Therefore: b=-1 c=0 a=2

Page 22: Induction II: Inductive Pictures

A computer scientist not only deals with

numbers, but also with

•Finite Strings of symbols

•Very visual objects called graphs

•And especially, especially the special graphs called trees

Page 23: Induction II: Inductive Pictures

GRAPHSGRAPHS

b

roota

Page 24: Induction II: Inductive Pictures

Definition: GraphsDefinition: Graphs

A graph G = (V,E) consists of a finite set V of vertices (nodes) and a finite set E of edges. Each edge is a set {a, b} of two different vertices.

A graph may not have self loops or multiple edges.

Page 25: Induction II: Inductive Pictures

Definition: Directed GraphsDefinition: Directed Graphs

A graph G = (V,E) consists of a finite set V of vertices (nodes) and a finite set E of edges. Each edge is an ordered pair <a,b> of two different vertices.

Unless we say otherwise, our directed graphs will not have multi-edges, or self loops.

Page 26: Induction II: Inductive Pictures

Definition: TreeDefinition: TreeA tree is a directed graph with one special node called the root and the property that each node must a unique path from the root to itself.

Child: If <u,v>2E, we sav is a child of uParent: If <u,v>2E, we say u is the parent of uLeaf: If u has no children, we say u is leaf.Siblings: If u and v have the same parent, they are siblings.Descendants of u: The set of nodes reachable from u (including u). Sub-tree rooted at u: Descendants of u and all the edges between them where u has been designated as a root.

Page 27: Induction II: Inductive Pictures

Classic Visualization: TreeClassic Visualization: Tree

Inductive rule:If G is a single node

Viz(G) =

If G consists of root r with sub-trees T1, T2, …, Tk

Viz(G) =Vuz(T1)Viz(T2) Viz(Tk)

…..

Page 28: Induction II: Inductive Pictures

I own 3 beanies and 2 ties. How many beanie/tie

combos might I wear to the ball tonight?

Page 29: Induction II: Inductive Pictures
Page 30: Induction II: Inductive Pictures

A choice tree is a tree with an object called a “choice”

associated with each edge and a label on each leaf.

Choice TreeChoice Tree

Page 31: Induction II: Inductive Pictures

Definition: Labeled TreeDefinition: Labeled Tree

A tree node labeled by S is a tree T = <V,E> with an associated functionLabel1: V to S

A tree edge labeled by S is a tree T = <V,E> with an associated functionLabel2: E to S

Page 32: Induction II: Inductive Pictures

was very illuminating.

Let’s do something similar to illuminate the nature of

T(1)=1; T(n)= 4T(n/2) + n

Page 33: Induction II: Inductive Pictures

T(1)=1; T(n)= 4T(n/2) + n

For each n (power of 2),we will define a tree W(n) node labeled by Natural

numbers. W(n) will give us an incisive picture of T(n).

Page 34: Induction II: Inductive Pictures

Inductive Definition Of Labeled Tree W(n)Inductive Definition Of Labeled Tree W(n)

T(n) = n + 4 T(n/2)

n

W(n/2) W(n/2) W(n/2) W(n/2)

W(n) =

W(1)

T(1) = 1

1=

Page 35: Induction II: Inductive Pictures

Inductive Definition Of Labeled Tree W(n)Inductive Definition Of Labeled Tree W(n)

T(2) = 6

2W(2) =

W(1)

T(1) = 1

1=

1 1 1 1

Page 36: Induction II: Inductive Pictures

Inductive Definition Of Labeled Tree W(n)Inductive Definition Of Labeled Tree W(n)

T(4) = 28

4W(4) =

2

1 1 1 1

2

1 1 1 1

2

1 1 1 1

2

1 1 1 1

Page 37: Induction II: Inductive Pictures

Inductive Definition Of Labeled Tree W(n)Inductive Definition Of Labeled Tree W(n)

T(4) = 28

4W(4) =

2

1 1 1 1

2

1 1 1 1

2

1 1 1 1

2

1 1 1 1

NOTE: When we sum all the node labels on W(n), we get

T(n)

Page 38: Induction II: Inductive Pictures

Invariant: LabelSum W(n) = T(n)Invariant: LabelSum W(n) = T(n)

T(n) = n + 4 T(n/2)

n

W(n/2) W(n/2) W(n/2) W(n/2)

W(n) =

W(1)

T(1) = 1

1=

Page 39: Induction II: Inductive Pictures

n

W(n/2) W(n/2) W(n/2) W(n/2)

W(n) =

Page 40: Induction II: Inductive Pictures

n

W(n/2) W(n/2) W(n/2)

W(n) =

n/2

W(n/4)W(n/4)W(n/4)W(n/4)

Page 41: Induction II: Inductive Pictures

nW(n) =

n/2

W(n/4)W(n/4)W(n/4)W(n/4)

n/2

W(n/4)W(n/4)W(n/4)W(n/4)

n/2

W(n/4)W(n/4)W(n/4)W(n/4)

n/2

W(n/4)W(n/4)W(n/4)W(n/4)

Page 42: Induction II: Inductive Pictures

nW(n) =

n/2 n/2 n/2n/2

11111111111111111111111111111111 . . . . . . 111111111111111111111111111111111

n/4 n/4 n/4n/4n/4n/4n/4n/4n/4n/4n/4n/4n/4n/4n/4 n/4

Page 43: Induction II: Inductive Pictures

n

n/2 + n/2 + n/2 + n/2

Level i is the sum of 4i copies of n/2i

. . . . . . . . . . . . . . . . . . . . . . . . . .

1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1

n/4 + n/4 + n/4 + n/4 + n/4 + n/4 + n/4 + n/4 + n/4 + n/4 + n/4 + n/4 + n/4 + n/4 + n/4 + n/4

0

1

2

i

log n2

Page 44: Induction II: Inductive Pictures

= 1n

= 2n

= 4n

= 2in

= (n)n

n(1+2+4+8+ . . . +n) = n(2n-1) = 2n2-n

Level i is the sum of 4 i copies of n/ 2 i

1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1

. . . . . . . . . . . . . . . . . . . . . . . . . .

n/ 2 + n/ 2 + n/ 2 + n/ 2

n

n/ 4 + n/ 4 + n/ 4 + n/ 4 + n/ 4 + n/ 4 + n/ 4 + n/ 4 + n/ 4 + n/ 4 + n/ 4 + n/ 4 + n/ 4 + n/ 4 + n/ 4 + n/ 4

0

1

2

i

lo g n2

Page 45: Induction II: Inductive Pictures

Instead of T(1)=1; T(n)= 4T(n/2) + n

We could illuminateT(1)=1; T(n) = 2T(n/2) + 2

Page 46: Induction II: Inductive Pictures

T(n) = n + 2 T(n/2)

n

W(n/2) W(n/2)

W(n) =

W(1)

T(1) = 1

1=

Page 47: Induction II: Inductive Pictures

n

n/2 + n/2

Level i is the sum of 2i copies of n/2i

. . . . . . . . . . . . . . . . . . . . . . . . . .

1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1

0

1

2

i

log n2

Page 48: Induction II: Inductive Pictures

n

n

n

. . . . . . . . . . . . . . . . . . . . . . . . . .

n

0

1

2

i

log n2

Page 49: Induction II: Inductive Pictures

T(1)=1; T(n) = 2T(n/2) + n

Has closed form: nlog2(n) where n is a power of 2

Page 50: Induction II: Inductive Pictures

Representing a recurrence relation as a labeled tree is one of the basics tools you will have to put recurrence

relations in closed form.

Page 51: Induction II: Inductive Pictures

The Lindenmayer GameThe Lindenmayer Game

= {a,b}Start word: a

SUB(a) = ab SUB(b) = aFor each w = w1 w2 … wn

NEXT(w) = SUB(w1)SUB(w2)..SUB(wn)

Page 52: Induction II: Inductive Pictures

The Lindenmayer GameThe Lindenmayer Game

SUB(a) = ab SUB(b) = aFor each w = w1 w2 … wn

NEXT(w) = SUB(w1)SUB(w2)..SUB(wn)

Time 1: aTime 2: abTime 3: abaTime 4: abaabTime 5: abaababa

Page 53: Induction II: Inductive Pictures

The Lindenmayer GameThe Lindenmayer Game

SUB(a) = ab SUB(b) = aFor each w = w1 w2 … wn

NEXT(w) = SUB(w1)SUB(w2)..SUB(wn)

Time 1: aTime 2: abTime 3: abaTime 4: abaabTime 5: abaababa

How long are the strings as a function of

time?

Page 54: Induction II: Inductive Pictures

Aristid Lindenmayer (1925-1989)Aristid Lindenmayer (1925-1989)

1968 Invents L-systems in Theoretical Botany

Time 1: aTime 2: abTime 3: abaTime 4: abaabTime 5: abaababa

FIBONACCI(n) cells at time n

Page 55: Induction II: Inductive Pictures

The Koch GameThe Koch Game

= {F,+,-}Start word: F

SUB(F) = F+F--F+F SUB(+)=+ SUB(-)=-For each w = w1 w2 … wn

NEXT(w) = SUB(w1)SUB(w2)..SUB(wn)

Page 56: Induction II: Inductive Pictures

The Koch GameThe Koch Game

Gen 0:FGen 1: F+F--F+FGen 2: F+F--F+F+F+F--F+F--F+F--F+F+F+F--F+F

Page 57: Induction II: Inductive Pictures

The Koch GameThe Koch Game

Picture representation:

F draw forward one unit+ turn 60 degree left - turn 60 degrees right.

Gen 0: FGen 1: F+F--F+FGen 2: F+F--F+F+F+F--F+F--F+F--F+F+F+F--F+F

Page 58: Induction II: Inductive Pictures

The Koch GameThe Koch Game

F+F--F+F F+F--F+F

Page 59: Induction II: Inductive Pictures

The Koch GameThe Koch Game

F+F--F+F+F+F--F+F--F+F--F+F+F+F--F+F F+F--F+F+F+F--F+F--F+F--F+F+F+F--F+F

Page 60: Induction II: Inductive Pictures

Koch CurveKoch Curve

Page 61: Induction II: Inductive Pictures

Dragon Game

SUB(X) =X+YF+SUB(Y) = -FX-Y                                     Dragon

Curve:            

Page 62: Induction II: Inductive Pictures

Hilbert GameSUB(L)= +RF-LFL-FR+SUB(R)= -LF+RFR+FL-                                    

Hilbert Curve:            

Note: Make 90 degree turns instead of 60 degrees.          

Page 63: Induction II: Inductive Pictures

Hilbert’s Space Filling CurveHilbert’s Space Filling Curve

Page 64: Induction II: Inductive Pictures

Peano-Gossamer CurvePeano-Gossamer Curve

Page 65: Induction II: Inductive Pictures

Sierpinski TriangleSierpinski Triangle

Page 66: Induction II: Inductive Pictures

Lindenmayer 1968Lindenmayer 1968

SUB(F) = F[-F]F[+F][F]

Interpret the stuff inside brackets as a branch.

Page 67: Induction II: Inductive Pictures

Lindenmayer 1968Lindenmayer 1968

Page 68: Induction II: Inductive Pictures

Inductive LeafInductive Leaf

Page 69: Induction II: Inductive Pictures
Page 70: Induction II: Inductive Pictures

Here is another kind of inductive definition called a formal grammar.

Page 71: Induction II: Inductive Pictures

Formal Grammar:Formal Grammar:G = (T, V, S, P)G = (T, V, S, P)

A finite alphabet T called the terminal symbols.

A disjoint finite alphabet N of non-terminal symbols (or variable symbols). One symbol S in V is called the start symbol.

A finite set P of production rules of the form , where , 2 (N [ T)* and contains at least one non-terminal symbol.

Page 72: Induction II: Inductive Pictures

Example.Example.

Terminal Symbols: {a,b,c}Non-terminal symbols: {S, X}Start symbol: S

Production rules:S SSS aSS b

Page 73: Induction II: Inductive Pictures

Formal Grammar:Formal Grammar:G = (T, V, S, P)G = (T, V, S, P)

A finite set P of production rules of the form , where , 2 (N [ T)* and contains at least one non-terminal symbol.

Let x and y be strings over N[T.We say that y is produced in one step from x if there is a rule such that one occurrence of the substring is replaced with to obtain the string y. We denote this x 1 y

Page 74: Induction II: Inductive Pictures

S S 11 SSS SSS 11 bS bS 1 1 baba

Terminal Symbols: {a,b,c}Non-terminal symbols: {S, X}Start symbol: S

Production rules:S SSS aSS b

Page 75: Induction II: Inductive Pictures

Definition of x Definition of x kk y y

We know what x 1 y means.Define x 0 y only when x = y

Define x ->k to mean 9 z s.t. x->1z and z->k-1y

Define x*y to mean that there exists a k such that xk y .

Page 76: Induction II: Inductive Pictures

Language Produced By Language Produced By Formal Grammar GFormal Grammar G

LG = {x 2 T* | S*x }

= {x 2 T* | 9 k s.t. Skx }

The language of strings of terminal symbols that are eventually produced by the start symbol.

Page 77: Induction II: Inductive Pictures

Language = {a,b}Language = {a,b}++

Terminal Symbols: {a,b,c}Non-terminal symbols: {S, X}Start symbol: S

Production rules:S SSS aSS b

Page 78: Induction II: Inductive Pictures

Evaluating A Formal DerivationEvaluating A Formal Derivation

Let G be a formal grammar.A sequence D = S1, S2, …., Sk, f strings is called a formal derivation of if:

For 1· q · k-1 Sq 1 Sq+1

Page 79: Induction II: Inductive Pictures

Once you agree on a specific grammar G, it is trivial to verify proofs of membership in the language.

Page 80: Induction II: Inductive Pictures

G = BalancedG = Balanced

S ()S SSS (S)

Now let’s show Symbol Dude the following derivation:S, (S), (SS), (SS), (S()), ((())())

Page 81: Induction II: Inductive Pictures

Yo, dude! ((())()) is like totally Yo, dude! ((())()) is like totally balancedbalanced

XXh42TEhha

Page 82: Induction II: Inductive Pictures

Expressions in Propositional LogicExpressions in Propositional Logic

E True | False

x | y | z

E

(E Ç E)

(E Æ E)

Page 83: Induction II: Inductive Pictures

Yo, dude! Yo, dude! ::(x(xÆÆy) is like totally an y) is like totally an expression in propositional logic.expression in propositional logic.

XXh42TEhha

Page 84: Induction II: Inductive Pictures

Meaning:Meaning:The Part Symbol Dude IgnoresThe Part Symbol Dude Ignores

E True | False (constants)

x | y | z (variables)

E1 (not E1)

(E1 Ç E2) (E1 or E2)

(E1 Æ E2) (E1 and E2)

Page 85: Induction II: Inductive Pictures

Inductively Associate a Inductively Associate a MEANING M(E) of any expression EMEANING M(E) of any expression E

M(T) = T M(F)=F

M(: E) = not M(E)

M( (E1 Æ E2) = M(E1) and M(E2)

M( (E1 Ç E2) = M(E1) or M(E2)

not T = F not F =T

AND.

F and F = F F and T = F T and F – F T and T= T

Page 86: Induction II: Inductive Pictures

Expressions in Expressions in First OrderFirst Order Logic Logic

T x | y | z f(T1, T2, …, Tk) (functions) T = Terms

E R(T1, T2, …, Tk) (relation on terms)

E1 | (E1 Ç E2) | (E1 Æ E2)

8 x. E1 (universal quantifier)

9 x. E1 (existential quantifier)

Page 87: Induction II: Inductive Pictures

E.g., Number TheoryE.g., Number Theory

T x | y | z 0 (the zero function)

S(T1) (successor function)

(T1+T2) | (T1*T2)| (T1^T2) E (T1 = T2) | (T1 < T2 ) (relations between terms)

8 x. E1 | 9 x. E1

8 x. (S(S(x)) < S(x^S(S(0))))

= 8 x. ((x+2) < (x2 + 1))

Page 88: Induction II: Inductive Pictures

What about something even

more complex, like Java?

You can write down the entire grammar!

Page 89: Induction II: Inductive Pictures

Statements in JavaStatements in Java

S ;

Expression ;

{ S } | { }

if ( Expression ) then S1 else S2

do S while ( Expression ) ;

while ( Expression ) S ;

return ; | return Expression ;

Page 90: Induction II: Inductive Pictures

Expressions in JavaExpressions in Java

Expression Numeric Expression

Logical Expression

String Expression

Page 91: Induction II: Inductive Pictures

Numerical Expressions in JavaNumerical Expressions in Java

NE - NE | --NE | ++NE

NE -- | NE ++

NE += NE | NE -= NE

NE + NE | NE - NE

( NE )

Identifier…

Page 92: Induction II: Inductive Pictures

Programs in JavaPrograms in Java

Type Decleration

Class Decleration | Interface Decleration

Class Decleration

class Identifier extends ClassName

{ FieldDeclerationList }

Compilation Unit

Import Statement Type Decleration

Page 93: Induction II: Inductive Pictures

Now we will expand our notion of a legal move a bit to include things that are very intuitive.

Page 94: Induction II: Inductive Pictures

Symbol TemplatesSymbol Templates

Fix a finite alphabet .Fix a finite alphabet .Let {#} be a symbol not in [

Define a template for to be any finite string over [ .

Page 95: Induction II: Inductive Pictures

Template Example.Template Example.

= {a, b}= {X, Y}

Templates:

aaXXa XYXYabaXbaaa

Page 96: Induction II: Inductive Pictures

Template ExamplesTemplate Examples

= {a, b}= {X, Y, Z}

XYX matches aaabababaaabaaaabababaaaba has the form XYX

Page 97: Induction II: Inductive Pictures

Algebra Game TemplatesAlgebra Game Templates

X+Y = Y+X(X+y)+z = x+(y+z)(x*y)*z=x*(y*z)X*Y =Y*XX*(Y+Z) = (X*Y) + (X*Z)X+0 = XX*0= 0

Page 98: Induction II: Inductive Pictures

Algebra Game AllowsAlgebra Game Allowssubstitution too!substitution too!

Page 99: Induction II: Inductive Pictures

Example UBLExample UBL = { S, =} = { S, =}

One Axiom A: { S=S }

One Inference Rule:r() = SS

Proof: S=S, SS=SS, SSS=SSS

Page 100: Induction II: Inductive Pictures

Example UBL Example UBL = { S, =} = { S, =}

One Axiom A: { S=S }One Inference Rule: r() = SS

Proof that SSS=SSS: S=S, SS=SS, SSS=SSS

Page 101: Induction II: Inductive Pictures

Example UBL Example UBL = { S, =} = { S, =}

One Axiom A: { S=S }One Inference Rule: r() = SS

Proof that premise SSS=S implies SSSSS=SSS: SSS=S, SSSS=SS, SSSSS=SSS

Page 102: Induction II: Inductive Pictures

Example UBL Example UBL = { S, =} = { S, =}

One Axiom A: { S=S }One Inference Rule: r() = SSUBL is completely defined in syntactic terms. UBL is just a game of symbol pushing. Does it have a natural semantics?

Page 103: Induction II: Inductive Pictures

UBLUBL

UBL can be interpreted as

UNARY BALANCE LOGIC

Page 104: Induction II: Inductive Pictures

Propositional LogicPropositional Logic

Axioms = all strings of the form

Inference rules [Hilbert]:r1( ) =

r2() = [this is a relation, actually]

r3(( ) ) = ( )

Br( , : ) =

Page 105: Induction II: Inductive Pictures

Example: p, Example: p, :: p p q implies q q implies q

p, p q, q, :: p p q, q q, q q , q q , q

Inference rules [Hilbert] :r1( ) =

r2() = [this is a relation, actually]

r3(( ) ) = ( )

Br( , : ) =

Page 106: Induction II: Inductive Pictures

Propositional LogicPropositional Logic

Propostional logic and proof can be viewed as a symbol game, or view semantically.

: means NOT, means OR.An n-variable formula is a tautology if it evaluates to TRUE under all 2n truth assignments.

Page 107: Induction II: Inductive Pictures

Propositional LogicPropositional Logic

SOUND: Any formula that can be derived by the manipulation rules is indeed a tautology.

COMPLETE: All tautologies can be derived by the logic.

Page 108: Induction II: Inductive Pictures

First-order PredicatesFirst-order Predicates

Enhance our syntax to be give us the possibility of a richer semantics.

Page 109: Induction II: Inductive Pictures

Inductive Grammar Notation Inductive Grammar Notation

<integer> ::= <natural> | -<natural>

<natural> ::= <decimal digit> | <natural> <decimal digit>

<decimal digit> ::= 0|1|2|3|4|5|6|7|8|9

Page 110: Induction II: Inductive Pictures

Grammar: Grammar:

<operator> ::= + | - | * | /<expression> ::= <natural> | <natural> <operator> <natural>

<expression>::= (<expression) | - (<expression>) |(<expression>)<operator>(<expression>)

Page 111: Induction II: Inductive Pictures

Computer Language Syntax Computer Language Syntax

The syntax of computer languages can be defined by an inductive grammar. In fact, most languages can be defined by a restricted form of grammar, called BNF form.

Page 112: Induction II: Inductive Pictures

The Natural NumbersThe Natural Numbers

= { 0, S0, SS0, SSS0, . . .}

Inductive definition:

0 is a natural number called zero.Set notation: 0 2

If X is a natural number, then SX is a natural number called successor of X.Set notation: X 2 ) SX 2

Page 113: Induction II: Inductive Pictures

Inductive Definition of +Inductive Definition of +

= { 0, S0, SS0, SSS0, . . .}

Inductive definition of addition (+):

X, Y 2 )X “+” 0 = XX “+” SY = S(X”+”Y)

Page 114: Induction II: Inductive Pictures

Defining One to TenDefining One to Ten

“1” = S0; “2”= SS0; “3” = SSS0. “4” = SSSS0. “5” = SSSSS0; “6” = SSSSSS0; “7” = SSSSSSS0. “8” = SSSSSSSS0; “9=SSSSSSSSS0. “10” = SSSSSSSSSS0

Or…. “1” = S0. “2” = S1. “3” = S2. “4” = S5 …

Page 115: Induction II: Inductive Pictures

1 + 1 = 21 + 1 = 2

Proof:

1 + 1 = S0 + S0 = S(S0 + 0) = S(S0) = SS0 = 2

X, Y 2 )X “+” 0 = XX “+” SY = S(X”+”Y)

Page 116: Induction II: Inductive Pictures

Inductive Definition of *Inductive Definition of *

= { 0, S0, SS0, SSS0, . . .}

Inductive definition of times (*):

X, Y 2 )X “*” 0 = 0X “*” SY = (X”*”Y) + X

Page 117: Induction II: Inductive Pictures

Inductive Definition of ^Inductive Definition of ^

= { 0, S0, SS0, SSS0, . . .}

Inductive definition of raised to the (^):

X, Y 2 )X “^” 0 = 1 [or X0 = 1 ]X “^” SY = (X”^”Y) * X [or XSY = XY * X]

Page 118: Induction II: Inductive Pictures

Inductive Definition of Base 10 Inductive Definition of Base 10 Notation.Notation.

Base10( 10*X + 0) = Base10(X) “0”Base10( 10*X + 1) = Base10(X) “1” …Base10( 10*X + 1) = Base10(X) “9”

Base10(SSSSSSSSSSSS0) = Base10(SSSSSSSSSS0) 2 =1 2

Page 119: Induction II: Inductive Pictures

= { 0, 1, 2, 3, . . .}= { 0, 1, 2, 3, . . .}

Defining < for :

8 x,y 2 “x > y” is TRUE “y < x” is TRUE“x > y” is TRUE “y > x” is FALSE

“x+1 > 0” is TRUE“x+1 > y+1” is TRUE ) “x > y” is TRUE

Page 120: Induction II: Inductive Pictures

= { 0, 1, 2, 3, . . .}= { 0, 1, 2, 3, . . .}

Defining partial minus for :

8 x,y 2 x-0 = x x>y )

(x+1) – (y+1) = x-y

Page 121: Induction II: Inductive Pictures

a =a = [ [a DIV ba DIV b]*b + [a mod b]]*b + [a mod b]

Defining DIV and MOD for :

8 a,b 2 a<b )

a DIV b = 0 a¸b>0 )

a DIV b = 1 + (a-b) DIV b

a MOD b = a – [b*(a DIV b)]

The maximum number of times b goes into a without going over.

The remainder when a is divided by b.

Page 122: Induction II: Inductive Pictures

45 =45 = [ [45 DIV 1045 DIV 10]*10 + [ 45 MOD 10]]*10 + [ 45 MOD 10]= 4*10 + 5= 4*10 + 5

Defining DIV and MOD for :

8 a,b 2 a<b )

a DIV b = 0 a¸b>0 )

a DIV b = 1 + (a-b) DIV b

a MOD b = a – [b*(a DIV b)]

Page 123: Induction II: Inductive Pictures

Giuseppe Peano [1889]Giuseppe Peano [1889]Axiom’s For Axiom’s For

A1. Sx 0

A2. [Sx = Sy] ) [x=y]

A3. For any proposition P(x) where x2 . Mathematical Induction Applies To P:

[P(0) and 8 x2 , P(x)) P(Sx)]) 8 x P(x)

Page 124: Induction II: Inductive Pictures

Giuseppe Peano [1889]Giuseppe Peano [1889]Axiom’s For Axiom’s For

A1. Sx 0

A2. [Sx = Sy] ) [x=y]

A3. For any proposition P(x) where x2 .

Mathematical Induction Applies To P:[P(0) and 8 x2 , P(x)) P(Sx)]

) 8 x P(x) Inductive Definition of +:

x + 0 = xx + Sy = S(x + y)

Let’s prove the

Commutativity of addition: x +y = y+ x

Page 125: Induction II: Inductive Pictures

Lemma: 0 + x = xLemma: 0 + x = x

Let P(x) be the proposition that “0 + x = x”

P(0) is “0 + 0 = 0”Assume P(x): “0 + x = x” Show P(Sx):0+Sx = S(0+x) = S(x) = Sx

Page 126: Induction II: Inductive Pictures

Lemma: Sx + y = S(x+y)Lemma: Sx + y = S(x+y)

Let P(y) be the proposition that “8 x, Sx + y = S(x+y)”

P(0) is “8 x, Sx + 0 = S(x+0) = Sx”Assume P(y): “8 x, Sx+y = S(x+y)” Show P(Sy):Sx+Sy = S(Sx+y) = S(S(x+y) ) = S(x+Sy)

Page 127: Induction II: Inductive Pictures

Theorem: Commutative Theorem: Commutative Property Of Addition: x + y = Property Of Addition: x + y =

y + xy + x

Let P(y) be the proposition that “8 x, x + y = y + x”

P(0) is “8 x, x + 0 = 0 + x”Assume P(y): “8 x, x + y = y + x” Show P(Sy):x+Sy = S(x+y) = S(y+x) = Sy + x

Page 128: Induction II: Inductive Pictures

““God Made Induction On The God Made Induction On The Naturals. Everything Else Is The Naturals. Everything Else Is The

Work Of Man.”Work Of Man.”

= { 0, 1, 2, 3, . . .}

Peano Axioms: Gives us inductive reasoning.

Inductively Define: all of arithmetic, high school math, and beyond…

Peano

Page 129: Induction II: Inductive Pictures

ReferencesReferences

The Heritage of Thales, by W. S. Anglin and F. Lambek

The Book Of Numbers, by J. Conway and R. Guy

Programming Pearls, by J. Bentley

History of Mathematics, Histories of Problems, by The Inter-IREM Commission