DOC PREVIEW
Berkeley COMPSCI 70 - Lecture 4

This preview shows page 1-2 out of 7 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS 70 Discrete Mathematics for CSFall 2003 Wagner Lecture 4This lecture completes our general introduction to proof methods. We begin with examples of inductionprinciples for domains other than the natural numbers, including strings, trees, and pairs of numbers. Wethen introduce the general principle of well-founded induction, which yields as special cases all sorts ofinduction principles for all sorts of domains.Induction over things besides numbersPersons other than pure mathematicians often write programs that manipulate objects other than naturalnumbers—for example, strings, lists, trees, arrays, hash tables, programs, airline schedules, and so on. Sofar, the examples of induction we have seen deal with induction over the natural numbers. How does thishelp with these other domains?One answer is that we can do inductive proofs over natural numbers that correspond to the size of theobjects under consideration. Suppose we want to prove that ∀s P(s) for the domain of strings. Then defineSTRINGSa proposition on natural numbers as follows:Q(n) is the property that every string s of length n satisfies P(s).Then a proof that ∀n Q(n) by induction on n establishes that ∀s P(s).Similarly, we can prove things about trees by induction on the depth of the tree, or about programs byinduction on the number of symbols in the program. These inductions can become quite cumbersome andunnatural. Let’s suppose we had never heard of the natural numbers; could we still do anything with stringsand trees and programs? It turns out that we can define very natural induction principles for these sorts ofobjects without mentioning numbers at all.An induction principle for stringsLet’s write a recursive algorithm for reversing a string and show that it works correctly.First, we will need to say what strings are. The elements of a string are symbols drawn from a set ofSYMBOLSsymbols called an alphabet, which is usually denoted Σ. For example, if Σ={a,b}, then strings can consistALPHABETof sequences of as and bs. Σ∗denotes the set of all possible strings on the alphabet Σ, and always includesthe empty string, which is denotedλ. Every symbol of Σ is also a string of length 1. (Note: this property inparticular distinguishes strings from lists; but in general reasoning about strings is quite similar to reasoningabout lists.)The basic way to construct strings is by concatenation. If s1and s2are strings, then their concatenation isCONCATENATIONalso a string and is written s1s2or s1· s2if punctuation is needed for clarity. Concatenation is defined asfollows:Axiom 4.1 (Concatenation):CS 70, Fall 2003, Lecture 4 1∀s∈Σ∗λ· s = s·λ= s∀a∈Σ ∀s1,s2∈Σ∗(a· s1) · s2= a· (s1· s2)Just as Peano did for the natural numbers, we now provide axioms concerning what strings are, then westate an induction principle that allows proofs for all strings. Strings satisfy the following axioms:Axiom 4.2 (Strings):The empty string is a string:λ∈Σ∗Joining any symbol to a string gives a string: ∀a∈ Σ ∀s∈Σ∗a· s ∈ Σ∗Because these axioms do not strictly define strings, we need an induction principle to construct proofs overall strings:Axiom 4.3 (String Induction):For any property P,if P(λ) and ∀a∈Σ ∀s∈Σ∗(P(s) =⇒ P(a· s)),then ∀s∈Σ∗P(s).This is a simple instance of structural induction, where a set of axioms defines the way in which objectsSTRUCTURALINDUCTIONin a set are constructed and an induction principle uses the construction step repeatedly to cover the entiredomain. Here, “·” is the constructor for the domain of strings, just as “+1” is the constructor for the naturalCONSTRUCTORnumbers.Notice that numbers appear nowhere in these axioms. We can do proofs thinking only about the objects inquestion. Let’s define a function that reverses a string and prove that it works.Axiom 4.4 (Reverse):r(λ) =λ∀a∈Σ ∀s∈Σ∗r(a· s) = r(s) · aWe would like to say something like “for every string s, r(s) reverses it.” To make this a precise theorem,we’ll need some independent, non-recursive way to say what we mean by reversing! There are several waysto do this, of which the easiest is to take advantage of “dot dot dot” notation:Theorem 4.1: ∀s∈Σ∗, let s=a1a2...an; then r(s)=an...a2a1Proof: The proof is by induction over the strings on the alphabet Σ. Let P(s) be the proposition that ifs=a1a2...an, then r(s)=an...a2a1.• Base case: prove P(λ).P(λ) is the proposition that r(λ)=λ, which is true by definition.• Inductive step: prove P(s) =⇒ P(a· s) for all a∈ Σ, s∈Σ∗.1. The inductive hypothesis states that, for some arbitrary string s, if s=a1a2...an, then r(s) =an...a2a1.2. To prove: for every symbol a, r(a· s) =an...a2a1a.3. By the axiom for reverse,r(a· s) = r(s) · a by the reverse axiom= an...a2a1a by the inductive hypothesisCS 70, Fall 2003, Lecture 4 2Hence, by the string induction principle, for every string s, r(s) reverses it. 2We could alternatively have proven this theorem by induction over the length of the input string. It is anexcellent exercise to work out the details of how to do this, and compare to the above method.Induction over binary treesTrees are a fundamental data structure in computer science, underlying efficient implementations in manyareas including databases, graphics, compilers, editors, optimization, game-playing, and so on. Trees arealso used to represent expressions in formal languages. Here we study their most basic form: the binarytree. Binary trees include lists (as in Lisp and Scheme), which have nil as the rightmost leaf.BINARY TREEIn the theory of binary trees, we begin with atoms, which are trees with no branches. A is the set of atoms,ATOMSwhich may or may not be finite. We construct trees (T) using the • (cons) operator. (In practice, any objectcan be an atom as long as it’s distinguishable as one.)Axiom 4.5 (Binary Trees):Every atom is a tree: ∀a∈A [a ∈ T]Consing any two trees gives a tree: ∀t1,t2∈T [t1•t2∈ T]The induction principle for trees says that if P holds for all atoms, and if the truth of P for any two treesimplies the truth of P for their composition, then P holds for all trees:Axiom 4.6 (Binary Tree Induction):For any property P,if ∀a∈A P(a)and ∀t1,t2∈T [P(t1) ∧ P(t2) =⇒ P(t1•t2)]then ∀t ∈ T P(t).Many useful predicates and functions can be defined on trees, including• leaf(a,t) is true iff atom a is a leaf of tree


View Full Document

Berkeley COMPSCI 70 - Lecture 4

Documents in this Course
Notes 1

Notes 1

12 pages

Note 2

Note 2

6 pages

Notes

Notes

6 pages

Notes

Notes

7 pages

Note 10

Note 10

8 pages

n20

n20

10 pages

n19

n19

10 pages

n18

n18

10 pages

n17

n17

6 pages

n16

n16

9 pages

n15

n15

10 pages

n14

n14

9 pages

n13

n13

6 pages

n12

n12

7 pages

n11

n11

6 pages

n10

n10

8 pages

n9

n9

5 pages

n8

n8

7 pages

n7

n7

8 pages

n6

n6

5 pages

n5

n5

8 pages

n4

n4

7 pages

n3

n3

10 pages

n2

n2

7 pages

n1

n1

5 pages

Load more
Download Lecture 4
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture 4 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 4 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?