Unformatted text preview: Johny Nguyen September 16th, 2009 CS 473 Homework 1 Downey PROBLEM 1 Draw directed graphs representing relations of the following types: (a) Reflexive, transitive and antisymmetric. Antisymmetry of R means that (∀a,b) if (a,b) ∈ R and a≠b, then (b,a)∉R. (b) Reflexive, transitive, and neither symmetric nor antisymmetric. PROBLEM 2 What is the reflexive, transitive closure R* of R = {(a,b) ,(a,d) ,(d,c) ,(d,e)}? Express R* as a set, and also draw a directed graph representing the relation R*. R* = {(a,a), (b,b), (c,c), (d,d), (e,e), (a,e), (a,c), (a,b), (a,d), (d,c), (d,e)} PROBLEM 3 i. ii. iii. A(n, 0) = n + 1 A(0, m + 1) = A(1, m) A (n + 1 , m + 1 )= A ( A (n , m + 1 ) , m ) A(n,m) = A( A(n − 1, m) , m − 1) (a) A(n,1) = A( A(n
1, 1), 0) A(n,1) = A(n
1, 1) + 1 by (i) A(n
1, 1) = A(n
2,1) + 1 A(n,1) = A(n
2,1) + 2 A(n,1) = A(n
k,1) + k, Let k = n A(n
1) = A(0,1) + n A(n,1) = A(1,0) + n A(n,1) = 2 + n Proof: QED Base: n = 1. A(1,1) = 2 + 1 = 3 A(1,1) = A(1
1,1) + 1 = A(0,1) + 1 = A(1,0) + 1 = 2 + 1 = 3 by (ii) Inductive: Suppose A(k, 1) = k + 2, then A(k+1,1) = (k + 1) + 2 = k + 3. A(k+1,1) = A((k+1)
1,1) + 1 = A(k,1) + 1 A(k+1,1) = A(k,1) + 1 = (k+2) + 1, By Inductive Hypothesis A(k+1,1) = k + 3. (b) A(n,2) = A( A(n
1, 2), 1) A(n,2) = A(n
1,2) + 2 by (a) A(n
1,2) + 2 = A(n
2,2) + 2 A(n,2) = (A(n
2,2) + 2) + 2 = A(n
2,2) + 2*2 A(n
2,2) = A(n
3,2) + 2 A(n,2) = (A(n
3,2) + 2) + 2*2 = A(n
3,2) + 3*2 A(n,2) = A(n
k,2) + 2k, Let k = n A(n,2) = A(0,2) + 2n A(n,2) = A(1,1) + 2n A(n,2) = 3 + 2n Proof: Base: n = 1. A(1,2) = 3 + (2*1) = 3 + 2 = 5 A(1,2) = A(1
1,2) + 2 = A(0,2) + 2 = A(1,1) + 2 = 3 +2 = 5 by (ii) by (a) Inductive: Suppose A(k,2) = 2k + 3, then A(k+1,2) =2(k + 1) + 3. A(k+1,2) = A((k+1)
1,2) + 2 A(k+1,2) = A(k,2) + 2 = (2k + 3) + 2, By Inductive Hypothesis A(k+1,2) = (2k + 2) + 3 = 2(k + 1) + 3 QED (c) A(n,3) = A( A(n
1, 3), 2) = 2A(n
1,3) + 3 A(n
1,3) = 2(n
2,3) + 3 A(n,3) = 22A(n
2,3) + 21*3 + 3 A(n
1,3) = 2(n
3,3) + 3 A(n,3) = 23A(n
3,3) + 22*3 + 21*3 + 20*3 = 2kA(n
k,3) + 3 ∑ 2 i . Let k = n i=0 k −1 A(n,3) = 2 n A(n
n,3) + 3 ∑ 2 i = 2
i=0 n −1 n A(0,3) + 3 ∑ 2 i = 2 A(1,2) + 3 ∑ 2 i i=0 i=0 € € n −1 n n −1 A(n,3) = 5*2 + 3 ∑ 2 i €
i=0 n n −1 by (b) € Proof: Base: n = 1. A(1,3) = 5*21 + 3 ∑ 2 i = 5*2 + 3 = 10 + 3 = 13 i=0 € n −1 A(1,3) = 2A(0,3) + 3 = 2A(1,2) + 3 = 2*5 + 3 = 13 €
k
k −1 i Inductive: Suppose A(k,3) = 5*2 + 3 ∑ 2 then A(k+1,3) = 5*2 + 3 ∑ 2 i . i=0 i=0 k −1 k+1 k A(k+1,3) = 2A(k,3) + 3 = 2(5*2k + 3 ∑ 2 i ) + 3 €
i=0 k −1 € A(k+1,3) = 5*21*2k + 2*3 ∑ 2 i + 3 i=0 €
1 0 i i A(k+1,3) = 5*2 + 3( ∑ 2
€
i=0 k k+1 k −1 i ∑ 2 ∑ 2 ) i=0 i=0 A(k+1,3) = 5*2k+1 + 3 ∑ 2 i € €
i=0 € QED
€ PROBLEM 4 Theorem: All marbles have the same color. Proof: Let A be any set of n marbles, where n≥1. The proof is by induction on n. Base: If n = 1 all marbles in A clearly have the same color. Step: Assume that if A is any set of k marbles, then all marbles in A have the same color. Let A’ be a set of k + 1 marbles, where k≥1. Remove one marble m from A’. We are then left with a set A’’ of k marbles. By the induction hypothesis, A’’ has all marbles of the same color. Remove from A’’ a second marble m’, and then add back to A’’ the marble m originally removed. We again have a set of k marbles, which by the induction hypothesis has marbles all the same color. Thus the two marbles m, m’ removed must have been the same color, and so the set A’ must contain marbles all the same color. By the principle of induction, applied to the above basis and step, we conclude that in any set of n≥1 marbles, all marbles are the same color. QED. Problem: In the proof the statement, “Remove from A’’ a second marble m’, and then add back to A’’ the marble m originally removed” is invalid. It is not safe to assume that A’’ is guaranteed to have another marble to take away. Also, the statement, “Thus the two marbles m, m’ removed must have been the same color, and so the set A’ must contain marbles all the same color” is invalid. Lets say m had “all the same color” with red. Lets say m’ had “all the same color” with blue. The Inductive hypothesis provided both of these to be true separately, but clearly those are not the same color together. PROBLEM 5 (a) {ε}* = {ε}. Proof: a. {ε}* ⊆ {ε}. {ε}* = {ε} ⇒ {ε}* ⊆ {ε}. b. {ε} ⊆ {ε}*. {ε}* Contains all combinations of {ε}, which includes ε. ⇒ {ε} ⊆ {ε}*. (b) For any language L, L* L* = L*. Proof: a. L*L* ⊆ L*. L* = {w : (∃k ≥ 0)(∃w1, ..., w k ∈ L) w = w1w 2 ...w k } L* L* = { x ⋅ y : x ∈ L * ∧ y ∈ L*} € € • L* contains every possible concatenation over the language L, by definition. • L*L* contains every possible concatenation over L*, which contains every possible concatenation over the language L. • Every concatenation in L*L* is contained in L* ⇒ L*L* ⊆ L*. b. L* ⊆ L*L*. L* = {w : (∃k ≥ 0)(∃w1, ..., w k ∈ L) w = w1w 2 ...w k } L* L* = { x ⋅ y : x ∈ L * ∧ y ∈ L*} € € • L* contains every possible concatenation over the language L, by definition. • L*L* contains every possible concatenation over L*, which contains every possible concatenation over the language L. • Every concatenation in L* is contained in L*L* ⇒ L* ⊆ L*L*. (c) For any language L, L* = (L*)*. Proof a. L* ⊆ (L*) *. • L* contains every possible concatenation over the language L, by definition. • (L*)* = (L* )* = {w : (∃k ≥ 0)(∃w1w 2 ...w k ∈ L* )w = w1w 2 ...w 3 } • (L*)* contains all the elements in L*. ⇒ L* ⊆ (L*)*. b. (L*)* ⊆ L*. € • L* contains every possible concatenation over the language L, by definition. • (L*)* = (L* )* = {w : (∃k ≥ 0)(∃w1w 2 ...w k ∈ L* )w = w1w 2 ...w 3 } • Both (L*)* and L* have every possible combinations of strings over the language L. ⇒ (L*)* ⊆ L*. € PROBLEM 6 In the Scheme programming language†, the syntactic category of ‘‘Numbers’’ is (partially) defined as follows‡: <num> → <prefix><real> <real> → <sign><ureal> <ureal> → <uint>  <uint>/<uint>  <decimal> <uint> → <digit>+ <prefix> → e  #d <digit> → 0  . . .  9 <decimal> → <uint><exp>  .<digit>+<suffix>  <digit>+.<digit>*<suffix> <suffix> → e  <exp> <exp> → <marker><sign><digit>+ <sign> → e  + 
<marker> → e  s  f  d  l → (The markers s, f, d, l override the default floating point (e) representation, in implementations that support short, single precision, double and long.) Problem: Draw the state diagram that recognizes a well
formed <num> in Scheme. Your machine can be non
deterministic. To save space, label edges—where possible—with a class of symbols, such as <digit>, rather than introducing an edge for each symbol. ...
View
Full Document
 Spring '10
 Roberts
 the00

Click to edit the document details