# Mathematical Logic Algorithm

• Apr 7th 2009, 08:19 PM
VENI
Mathematical Logic Algorithm
I need to write an algorithm with appropriate assertions and input and output specifications that gives the sum of n given numbers. Then I need to prove it. This is what I have, is it right?

Input: $n_{1},n_{2},...,n_{m}$
Output: $s$
Algorithm SUM
$\{n_{1},n_{2},...,n_{m}$ integers $, -\infty < n_{1},...,n_{m} < \infty \}$
$s \leftarrow 0; i \leftarrow 0$
Loop Invariant: $\{s=s+n_{i}, i=1,2,...,m \}$
Repeat until: $i=m$
$s \leftarrow s + n_{i}$
$i \leftarrow i + 1$
End repeat
Loop termination condition: $\{s=s+n_{i} \wedge i=m \}$
Output specification: $\{s= n_{1},n_{2},...,n_{m}\}$