Compute the weakest precondition for the following statements
A. if (x == y) x=x*3
else x=x+1 {x < 0}
B. x = 3 * (y + x);
y= 3*x ; {y > 6}
Compute the weakest precondition for the following statements A. if (x == y) x=x*3 else x=x+1...
Compute the weakest precondition for each of the following assignment statements and postconditions: a = 2 * (b - 1) - 1 {a > 0} b = (c + 10) / 3 {b > 6} Prove that the following grammar is ambiguous (show 2 trees): <S> → <A> <A> → <A> + <A> | <id> <id> → a | b | c
how do you solve this? em sets: Compute the weakest precondition for the following sequence of assignment statements and their postconditions (3pts]: a = 3 * (2 * b + a); b = 2 * a - 1 {b > 5}
3. Find the weakest precondition for the following sequence of statements and its post-condition: a-2b + 1; b = a - 3; {b > 2)
2. (15 marks) Consider the following program: >> Precondition: x and y E Z. Postcondition: Return the sum x + y. add(x, y): 1. if x == 0: 2. return y 3. elif x > 0: 4. return add(x - 1, y) + 1 5. else: 6. return add(x + 1, y) - 1 Prove that this program is correct in terms of its specification.
17. hy the correctness of the following program segment with the precondition and postcondition shown {x60 if x > 0 then y = 2 ** else y=(-2) *x end if {y >0} 18. Verify the correctness of the following program segment to compute x, the absolute value of x, for a nonzero number x. {r* 0 if x >= 0 then abs = r else abs = -x end if
5) Consider the following Verilog code if (A) y- 1 else if (B) y-2 else if (C) y 3 else if (D) y 4 else у 0; Show what would most likely be synthesized. 6) Rewrite the code from the previous problem as a case statement. Show what would be synthesized if the parallel case synthesis directive is used. 5) Consider the following Verilog code if (A) y- 1 else if (B) y-2 else if (C) y 3 else if...
Let X be exponentially distributed with parameter 3. a) Compute P(X > 6 | X > 2). b) Compute E(7e-12x+8+ 5). c) Let Y be independent from X. Suppose the PDF for Y is f(x) = 2x for 0 ≤ x ≤ 1 (and 0 else). Find the PDF of X + Y.
Divide and Conquer & Algorithm Design 5. (20 points) Consider the following algorithm Precondition: S is a sorted list index mystery (index low, index high, const Array S[], number x) if low S high then mid = (low + high) / 2 if x = Smid] then return mid elsif x < s[mid] then return mystery (low, mid-1, s, x) else return mystery (mid+1, high, s, x) else return 0 end What does the recursive algorithm above compute? Explain why?
y-y+2 ; eise iflxc4) Output: else System.out.printin(y) 8. int x-5, y-3 if (xs 10) x x-2 else x-x+2; Output: System.out printin(y): 9. int x -8; while (x 0) system, out .printin ("ні") ; output: - 10. int x 5 do ) while (x > 23) System.out println(x): output: 11. int x 25, y 8 System.out.println (x+ y) 12. int [1 arrayi 12, 4, 6, 8, 10) int value 0; for (int a 0; a array1.1ength; a++) Output value + arrayl...