1 / 19

Discrete Structures Lecture 3 Assignment

Discrete Structures Lecture 3 Assignment. Review Problem. (1.8) Leibniz: X = Y E[z:=X] = E[z:=Y] Suppose: X = a + b; Y = 4•w; E = 2•x + z 2 Complete the following inference rule: a + b = 4•w 2•x + (a + b) 2 = ?.

Download Presentation

Discrete Structures Lecture 3 Assignment

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Discrete Structures Lecture 3 Assignment

  2. Review Problem (1.8) Leibniz: X = Y E[z:=X] = E[z:=Y] Suppose: X = a + b; Y = 4•w; E = 2•x + z2 Complete the following inference rule: a + b = 4•w 2•x + (a + b)2 = ?

  3. Proofs using Leibniz Leibniz (1.5) allows us to “substitute for equals” in an expression without changing the value of that expression. E[z:=X] = <X=Y> E[z:=Y]

  4. Example ProofMary has twice as many apples as John. Mary throws half of her apples away, because they are rotten, and John eats one of his. Mary still has twice as many apples as John. How many apples did Mary and John have initially? (0.1) m=2•jandm/2=2•(j-1) (1.9) 2•x/2 = x m/2 = 2•(j-1) = < m=2•j, by (0.1) > (2•j)/2 = 2•(j-1) = <unnecessary parentheses> 2•j/2 = 2•(j-1) = < (1.9), with x:= j > j = 2•(j-1) = <Arithmetic> j = 2j - 2 j = 2 eventually will find j=2 and m=4

  5. Proof Pitfalls Do not get sloppy about the proof format. Be careful not to: • Omit the hint. • Omit the = symbol in the left-hand column. • Indent the expressions being manipulated instead of the hints. • Fail to align the beginnings of the expressions or beginnings of the hints.

  6. The Assignment Statement Execution of the assignment statement (1.10)x:= E evaluates the expression E and stores the result in variable x. state: (z,3), (m,11), (s,35) s := z + m state: (z,3), (m,11), (s,14)

  7. Pre- and Post- Conditions We can judge the effect of assignment statements by thinking about pre-conditions and post-conditions. Precondition: Condition that holds before the execution of the statement. Postcondition: Condition that holds after the execution of the statement.

  8. Hoare Triples Hoare triple: (1.11){P} S {Q} A Hoare triple is valid iff execution of the statement S in any state in which the precondition holds results in a state in which the postcondition holds. (Note: iff stands for "if and only if" X iff Y means: X is true if Y is true and Y is true if X is true.)

  9. Examples of Hoare Triples Valid Hoare triples: {x=0} x:=x+1 {x>0} {x+4>11} x:=x+1 {x>0} Hoare triple which is not valid: {x=-6} x:=x+1 {x>0}

  10. Assignment Statement Definition (1.12){R[x:=E]} x:=E {R} x := 5 {x=5} {(x=5)[x:=5]} x := 5 {x=5} {(5=5)} x := 5 {x=5} { T } x := 5 {x=5}

  11. Assignment Statement Definition (1.12){R[x:=E]} x:=E {R} x := 5 {x!=5} {(x!=5)[x:=5]} x := 5 {x!=5} {(5!=5)} x := 5 {x!=5} { F } x := 5 {x!=5}

  12. Assignment Statement Definition (1.12){R[x:=E]} x:=E {R} x := x+1 {x < 0} {(x<0)[x := x+1]} x := x+1 {x < 0} {(x+1)<0} x := x+1 {x < 0} {x < -1} x := x+1 {x < 0}

  13. Assignment Statement Definition (1.12){R[x:=E]} x:=E {R} x := x•x {x4 = 10} {(x4=10)[x:=x•x]} x := x•x {x4 = 10} {(x•x)4=10}x := x•x {x4 = 10} {x8 = 10} {x= 1.231144413} x:=x•x {x4 = 10}

  14. Assignment Statement Summary (1.12){R[x:=E]} x:=E {R} {T} x := 5 {x = 5} {F} x := 5 {x != 5} {x <-1} x := x+1 {x < 0} {x = 1.231144413} {x8 = 10} x:=x•x {x4 = 10}

  15. Multiple Assignment {R[x,y:=E,F]} x,y:= E,F {R} { ? } x,y := x-y,x+y{x+y = C} to get precondition: replace x with x - y and y with x + y in R => (x - y + x + y = C) => (x + x = C) => (2x = C) {2x=C} x,y := x-y, x+y{x+y=C}

  16. Sequential Assignment {(R[y:=F])[x:=E]} x:=E; y:=F {R} {?} x:=x-y; y:=x+y{x+y=C} replace y with x+y in R (x + y = C)[y := x + y] => (x + x + y = C) => (2x + y = C) now have: {?} x:=x-y; {2x+y=C}y:=x+y{x+y=C}

  17. Sequential Assignment continued {?} x:=x-y; {2x+y=C}y:=x+y{x+y=C} {?} x:=x-y; {2x+y=C} replace x with x-y in new R (2x+y= C)[x := x - y] => (2(x-y) + y = C) => (2x-2y + y = C) => (2x- y = C) {2x-y=C} x:=x-y; y:=x+y{x+y=C}

  18. Multiple Assignment Practice {R[x,y:=E,F]} x,y:= E,F {R} { ? } a,b := b+2, a-3 {a•b> 10}

  19. Sequential Assignment Practice {(R[y:=F])[x:=E]} x:=E; y:=F {R} {?} a:=b+2; b:=a-3 {a•b> 10}

More Related