Examlex

Solved

The Following While Loop Is Annotated with a Pre- and Post-Condition

question 21

Essay

The following while loop is annotated with a pre- and post-condition and also a loop invariant.
Use the loop invariant theorem to prove the correctness of the loop with respect to the pre- and post-conditions.
[[ Pre-condition: product =A[1]= A [ 1 ] and i=1]i = 1 ] while (im)( i \neq m )
1. i:=i+1i : = i + 1
2. product := product. A[i]A [ i ]
end while
[[ Post-condition: product =A[1]A[2]A[m]]= A [ 1 ] \cdot A [ 2 ] \cdots A [ m ] ]
loop invariant: I(n)I ( n ) is "i=n+1" i = n + 1 and product :=A[1]A[2]A[n+1]": = A [ 1 ] \cdot A [ 2 ] \cdots A [ n + 1 ] "


Definitions:

Ghrelin

A hormone produced by the stomach that stimulates appetite.

Intrinsic Motivation

The drive to engage in activities for their inherent satisfaction rather than for some separable consequence.

Optimal Level of Arousal

A theory suggesting that individuals have a preferred level of stimulation or arousal that they seek to maintain by increasing or decreasing stimulation.

Classical Conditioning

An educational method that happens by linking an external stimulus with a stimulus that occurs naturally.

Related Questions