{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# HW2sol - 1 1What do we get if we add all the redundant...

This preview shows pages 1–4. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1) 1What do we get if we add all the redundant parentheses back to [Em.(0 5 m < n /\ Vj.0 5 j M < m e a[0] S GU] A 0-le S a[m])) ‘3’ (Elm.((0 g m < n) /\ (Vj.(((0 g j) /\ 2) (3' < Ml) —> (WM 5 aLil) A (GM 5 almlDDD Give a deﬁnition of predicate functions P(x,y) and Q(x,y) such that [Vm.§|n.P(m,n) /\ Q(m,n) is false but (Vm.(§n.P(m, n)) /\ Ep tensive proof of the truth and falsity of the If P(3;,y) (:> a: < y and Q(;r,y) (1} .Q(m, 33)) is true. (You don’t have to provide an ex- predicates, but it should be obvious to the grader). at > y then for all In you can not ﬁnd a n such that n1<n and n1>n but for all n1 you can ﬁnd a n such that m<n and ﬁnd a p such that n1>p (n=n1+1 and p=In-1). Question 3 Find a predicate equivalent to —(E Answer : —.(: {i} (Hm—{Wynn 5 y) V V241: 2 2)) 4:} (Va-(Vyrr 5 y) A —-(Vz.a: 2 2)) {i} (V\$.(Ely.a: > y) A 32.3: < z) Question 4 Write out the deﬁnition of a predicate function LT(b,m, n, p) that is true iff every element of b[m],b[m + 1],...1 and b[n — 1] is < ever}.r element of b[n],b[n + 1]1 ..., and b[p.1]. Assume 0 5 m 5 n 5 p and that b is of size 5 p. (Note the elements in b[m..n — 1] don’t have to be E.g., if b[0..5] is 3, 2,6,4,9,8, then LT(b, 0, 2, 6) is true sorted, nor do the elements in b[n..p— 1]. m.(Vy.x 5 y) V V2.2: 2 z)that has no uses of —._ x.(Vy.;c 5 3;) V V2.3," 2 2) but LT(b,O,3,6) is false (because b[2] isn’t < b[3]). Answer : LT(b,m, mp) {i} (W (Vj ((m 5 i < n) /\ (n 5 j < p) —> (3;:[3'] < b[j])))) Question 5 Assume we’ve deﬁned a function 000(3), m, n, as) = the number of occurrences of {c in the array segment b[m..n — 1]. (E.g., if b[O..5] is 4, —1, 2,4, 2,4, then occ(b,0, 6, 4) = 3, occ(b, 0, 1,4) = 1, and occ(b, 0, 0,4) = 0.) Use occ to deﬁne a predicate perm(b, 5', m,n) is true iff b[m..n — 1] and b’[m..n — 1] are permutations ofeach other. Answer : perm(b, 5', m,n) «e» (Va: (m 5 :1: < n —> ooc(b, m,n, b[acl) : occUJ’, m, n, b[xDD 6. [E- = 2*3 points] Explain why each of the following is not a proper state. (a) x = 1 A x = 2 A y = 4 (b) b[O] = 1 A b[2] = 3 [c] b[O] = 17 A b[1] = 12.5 (assume for a moment that we’ve added floating-point numbers to our expressions, and integers and floatingpoint values have different types]. a) In this case x has two values and for being a proper state each variable only can have one. b) You have to define the complete array to be a proper state, in this case a definition of b[l] is missing. c] Each element of the same array must be of the same type, in this case one is integer and the other is floatingpoint. 7) Let U1: 1': 1 A k : 2 A1; : 5 AND] : 18A b[1] : 12 A b[2] : 5, and let the expression 61 be (1': k? 1: : b[1']) 1. Draw a graphical representation of crl. 2. What is 01 [k »—> 0101' — 1)](81)? 2- 01 [k H 0106 H 1)](61) = Ulik H (671(k) H 01(0)](61) MUCH [2— 1)](81) ”HIGH 11(61) 01(9) 5 8) Let 21H:>5[0] =b[y/2] Ab[y/2] =1:sz Bay/\y = 2. 1. Write out the deﬁnition of a state equivalent to 1,!) (textually, as a conjunction of bindings). 2. 1Why would ¢[b[[}] 1—» 8] be a reasonable update for tb but 1,!)[b[8] »—> 0] would not ? 1. 1,15% b[0] =b[y/2] Ab[y/2] =\$A\$= 3\$yAy = 2 @340] =5[1]/\b[1] =\$A\$=6Ay=2 @340] =b[1]/\b[1] =6Ax=6Ay= 2 @b[0]=6/\b[1] =6Azc=6Ay=2 2. 1,!)[b[0] »—> 8] is a reasonable update because 5 is deﬁned, it’s a continuous and homogeneous array. 1b[b[8] »—> 0] is not a reasonable update because b[2]...b[7] aren’t deﬁned. 9) Our expressions have a ”visible variable” property : For any states CI and T and expression 6, if 0(1)) 2 7(1)) for every variable 1.! that appears in 8, then 0(8) 2 1'03). For each of the following constructs, say whether adding it to our expressions would break the visible variable property. 1. A randbéto function that randomly returns 0 or 1. 2. A + —|— ’2: expression that changes the state by adding 1 to the value of U and then yields the new value of v. 1. Tandbéto function randomly yelds 0 or 1. So when we evaluate 0(1)) and 7(0) the value returned can be randomly U or 1. So the ”visible variable” property is broken. 2. If our states have the ”visible variable” property then incrementing the variable of the two states conserve the property. ...
View Full Document

{[ snackBarMessage ]}