lecture 12.pptx rebotics artifical intellegence

momnamunir44 12 views 11 slides Oct 03, 2024
Slide 1
Slide 1 of 11
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11

About This Presentation

rebotics


Slide Content

MIRPUR UNIVERSITY OF SCIENCE AND TECHNOLOGY DEPARMENT OF SOFTWARE ENGINEERING

Formal Correctness of Loops (lecture # 12) Engr. Afzal Ahmed (Lecturer)

Loop Invariants 6/5/2021 Formal Methods in Software Engineering 3 LECTURE CONTENTS

s = 0; for i := 1 to n do s = s + a[i]; 6/5/2021 Formal Methods in Software Engineering 4 Loop Invariants What is the ‘loop invariant’? s is the sum of elements from a[1] to a[i] immediately before i is incremented!

Let W be while B do S condition for termination of the loop P  (not B) P 1  B and wp(S,P )  wp(S, not B) P k  B and wp(S, P k-1 ) wp(W, true)  wp(W, not B)  (k: k  0: P k ) 6/5/2021 Formal Methods in Software Engineering 5 Weakest Precondition for While Statement {P} while B do S {Q}

{P} while B do S {Q} The invariant condition {I} while B do S {I and not B} 6/5/2021 Formal Methods in Software Engineering 6 Weakest Precondition for While Statement

a = 0; i = 0; while (i < N) a = a + i++; Loop Invariant: a = 6/5/2021 Formal Methods in Software Engineering 7 Loop Invariant

wp(if x>2 then y:=1 else y:=-1, (y > 0)) wp(x:=x+2; y:=y-2, (x+y = 0)) Find the Precondition of following WP(if a<X and a>Y then Swap(), X=Y0 and Y=X0) 6/5/2021 Formal Methods in Software Engineering 8 Quiz 1

WP(k:=5; x:=2*y; y:=x-4, w*y = z+x) WP(if x is even then x:= x+1, x not % 2) Find the pre condition for following. WP(if a>x Swap(),(X=Y0 and Y=X0)) 6/5/2021 Formal Methods in Software Engineering 9 Quiz 2

[1]. Alagar, Vangalur S., and Kasilingam Periyasamy.  Specification of software systems . Springer Science & Business Media, 2011. 6/5/2021 Formal Methods in Software Engineering 10 References

Thanks
Tags