Model Solutions for hw2. 1. Deduce: Law of Mon. using (7.3),(7.4) and basic laws in Ch. 2. Suppose the hyp. q->r. w(q)->w(r) = w(q^r)->w(r) by hyp. and metathm = (w(q)^w(r))->w(r) by Dist. of Conj. = ~(w(q)^w(r)) v w(r) by Implication = ~w(q) v ~w(r) v w(r) by DeMorgan = ~w(q) v T by Ex. Mid. = T by Or-Simp. Deduce: Dist. of Disj. using (7.3),(7.4), and basic laws. w(q) v w(r) -> w(q v r) = ~(w(q) v w(r)) v w(q v r) by Imp. = (~w(q) ^ ~w(r)) v w(q v r) by DeMorgan = (~w(q) v w (q v r)) ^ (~w(r) v w(q v r)) by Dist. = (~w(q ^ (q v r)) v w(q v r)) ^ (~w(r) v w(q v r)) by And-Simp. = (~(w(q) ^ w(q v r)) v w(q v r)) ^ (~w(r) v w(q v r)) by Dist. of Conj. = (~w(q) v ~w(q v r) v w(q v r)) ^ (~w(r) v w(q v r)) by DeMorgan = (~w(q) v T) ^ (~w(r) v w (q v r)) Ex. Middle = T ^ (~w(r) v w(q v r)) by or-simp. = ~w(r) v w(q v r) by and-simp. = ~w(r^(q v r)) v w(q v r) by and-simp = ~(w(r) ^ w(q v r)) v w(q v r) by dist. of conj. = ~w(r) v ~w(q v r) v w(q v r) by DeMorgan = ~w(r) v T by Ex. Middle = T or-simp. 7.5 There are many possibilities. One example is let S=abort. Then wp(abort,R) v wp(abort, ~R) = f v f by def of abort = f by or-simp 8.2 (7.3) wp(abort, f) = f by def of abort (7.4) wp(abort,q) ^ wp(abort,r) = f ^ f by def of abort = f by and-simp = wp(abort,q ^ r) by def of abort (7.7) wp(abort,q) v wp(abort,r) =f v f by def of abort =f by or-simp =wp(abort,q v r) by def of abort 8.5 TST (To Show That) : wp("s1;s2",q) v wp("s1;s2",r) = wp("s1;s2",q v r) given that s1 and s2 satisfy 7.7. wp("s1;s2",q) v wp("s1;s2",r) = wp(s1,wp(s2,q)) v wp(s1,wp(s2,r)) by def. 8.3 = wp(s1,wp(s2,q) v wp(s2,r)) by 7.7 and since s1 satisfies 7.7 = wp(s1,wp(s2,q v r)) by 7.7 and since s2 satisfies 7.7 = wp("s1;s2", q v r) by def. 8.3 9.2.1 Most of them got this. 9.2.2 Consider R = y>0 ^ x >=0, e1 = -y, e2=x, and state s = {x=1,y=0} wp(x,y:=-y,x,y>0^x>=0) = x>0 ^ -y >= 0 by def of multiple asgnmnt. In s, this is T. wp(x:=-y,y:=x,y>0 ^ x>=0) = wp(x:=-y,wp(y:=x,y>0^x>=0)) by def of sequential = wp(x:=-y,x>0 ^ x>=0) by def of asnmnt and text sub = -y>0 ^ -y >=0 by def of asnmnt and text sub. In s, this is F. wp(y:=x,x:=-y,y>0^x>=0) =wp(y:=x,wp(x:=-y,y>0^x>=0)) by def of seq =wp(y:=x,y>0^-y>=0) by def of asnmnt and text sub. = x>0 ^-x>=0 by def of asnmnt and text sub. In s, this is F. 10.2 Show IF satisfies (7.3) provided the subcommands do. wp(IF,F) = BB ^ (A i: 1 <=i<=n:Bi=>wp(Si,F)) by def of IF and in the future of this proof I will refer to this expression as * There are 2 cases to consider. Case 1: Every Bi is F. Then we have * = F ^ (A i: 1 <= i <= n: Bi=>wp(Si,R)) by or-simp = F by and-simp. Case 2: ow. (not every Bi is F) Then we have * = T ^ (A i: 1<=i<=n:Bi=>wp(Si,F)) or-simp. = T ^ (A i: 1<=i<=n:Bi=>F) because we're given that the subcommands satisfy (7.3) = T ^ ((~B1 v F) ^ (~B2 v F) ^ ... ^ (~Bn v F)) expand quantifier and by law of implication = T ^ (~B1 ^ ~B2 ^ ... ^ ~Bn) by or-simp. = T ^ ~T ^ (...) by Comm., Assoc., and Description of this Case = F by Contradiction, And-Simp. Show IF satisfies (7.4) provided the subcommands do. wp(IF, q) ^ wp(IF, r) =bb ^ (b1=>wp(s1,q)^...^bn=>wp(sn,q)) ^ bb ^ (b1=>wp(s1,r)^...^bn=>wp(sn,r)) by def of IF = bb ^ (b1=>wp(s1,q)^b1=>wp(s1,r)^...^bn=>wp(sn,q)^bn=>wp(sn,r)) by and-simp., comm., and assoc. = bb ^ (b1=>wp(s1,q^r)^...^bn=>wp(sn,q^r)) by Lemma (see below) and given that subcommands satisfy (7.4) = wp(IF,q^r) by def of IF Lemma: b1=>a ^ b1=>b = b1=>a^b proof of Lemma: b1=>a ^ b1=>b =(~b1 v a) ^ (~b1 v b) by law of implication = ~b1 v (a ^ b) by Distributive law = b1=>a^b by Implication 10.4 wp(s4,a>0^b>0) =(a>b v b>a) ^ (a>b)=>wp(a:=a-b,a>0^b>0) ^ (b>a)=>wp(b:=b-a,a>0^b>0) by def of IF = (a>b v b>a) ^ (a>b)=>(a-b>0 ^ b>0) ^ (b>a)=>(a>0 ^ b-a>0) by def of asnmnt and text sub. = (a!=b) ^ (a>0 ^ b>0) by Math Simplification 10.7 Using Thm 10.5, prove that the following proof outline is t. q: {x>0 ^ z+y*x=a*b} s1:if odd(x)->z,x:=z+y,x-1 || even(x)->skip fi; s2: y,x:=2*y,x/2 r: {x>=0 ^ z+y*x=a*b} wp("s1;s2",r) = wp(s1,wp(s2,r)) by def of seq. = wp(s1,wp(y,x:=2*y,x/2,x>=0 ^ z+y*x=a*b) by Sub. = wp(s1,(x/2>=0 ^ z+2*y*x/2=a*b)) by def of multiple asnmnt and text sub. = wp(s1,(x>=0 ^ z+y*x=a*b)) simplifying x/2 <=> x>=0 and cancel the 2's Now, by Thm 10.5 it will suffice TST: (1) q=>odd(x) v even(x) = t (2) q ^ odd(x) =>wp(z,x:=z+y,x-1,x>=0^z+y*x=a*b)= t (3) q ^ even(x) =>wp(skip,x>=0^z+y*x=a*b)= t TST (1): q=>odd(x) v even(x) =~q v (odd(x) v even(x)) by Implication = ~q v t by Ex. Middle and odd(x) is the negation of even(x) = t by or-simp. TST (2): q ^ odd(x) => wp(z,x:=z+y,x-1,x>=0 ^ z+y*x=a*b) = q ^ odd(x) => (x-1>=0 ^ z+y+y*(x-1)=a*b) by def of mult. asnmnt and text sub. = q ^ odd(x) => (x>=0 ^ z+y*x=a*b) by simplification: x-1>=0 <=> x>0 and cancel the y's = ~(q ^ odd(x)) v q by substituting q and implication = ~q v ~odd(x) v q DeMorgan = t by Ex. Middle and or-simp. TST (3): q ^ even(x) => wp(skip,x>=0 ^ z+y*x=a*b) = q ^ even(x) => (x>=0 ^ z+y*x=a*b) by def of skip = x>0 ^ z+y*x=a*b ^ even(x) => (x>=0 ^ z+y*x=a*b) substituting for q = ~x>0 v ~(z+y*x=a*b) v ~even(x) v ((x>0 v x=0) ^ z+y*x=a*b) by Implication, DeMorgan, x>=0 <=> x>0 v x=0 = ~(x>0) v ~(z+y*x=a*b) v ~even(x) v (x>0 ^ z+y*x=a*b) v (x=0 ^ z+y*x=a*b) by Dist. Law = ~(x>0 ^ z+y*x=a*b) v ~even(x) v (x>0 ^ z+y*x=a*b) v (x=0 ^ z+y*x=a*b) by Assoc, DeMorgan = t by Comm, Excl. Middle, or-simp 11.1 wp(do od, R) = (E k: 0 <= k: H_k(R)) by Def. of DO H_0(R) = ~bb ^ R = R since by definition, the ~emptydisjunction = t and by And-simp. Proceeding by Induction, H_k(R) = R v wp(if fi, H_(k-1)(R)) = R v wp(if fi,R) by Induction = R v f, by 10.1 (done in class) = R by or-simp. So (E k: 0 <= k: H_k(R)) = (E k: 0 <= k: R) = R. It resembles a skip command.