Professional Documents
Culture Documents
Lab3 201903482
Lab3 201903482
***This piece of work was done under the University of Botswana policy. And I therefore affirm that this
was individual work. ***
Specifications
4. Write a simple specification for each of the functions in question
a) Sumt(m,n) which gives the sum of first n natural numbers that are divisible by m. [Hint: may
assume m is a natural number.]
sumt : ℕ x ℕ → ℕ
sumt: (Integer m, Integer n): Integer
Purpose: computes natural numbers divisible by m up to n
check if m is divisible by n
Precondition: (n >= 0) && (m >= 1)
Post condition: m + sumt(n-1) iff [x|x <- [1...n]]
c isHex(c)
e) prodt(n) which gives the product of the first n natural numbers. [Hint: the product identity is 1.]
prodt: ℕ -> ℕ
prodt(integer n):integer
Precondition: n>=0
Postcondition:{n+ prodt ( n−1 ) iff n> 1
{1 otherwise
a.isIn:Char*String->Bool
isin(Char c,String w):Bool
purpose:checks if charater c in word w
precondition :c/=null && w/=null
postcondition:if c`elem` w then true else false
g) isHexWord
isHexWord:String ->Bool
isHexWord(String w):Bool
precondition:w/=null
| false otherwise
h)
Base Case
Inductive Hypothesis
Inductive Step
isDiv(m,-1) ⋀ isDiv(m, k)
True ⋀ isDiv(m, k)
P(k + 0) isDiv(m, )
isDiv(m,) ⋀ isDiv(m, k)
True ⋀ isDiv(m, k)
P(k + 1) isDiv(k + 1)
isDiv(m,1) ⋀ isDiv(m, k)
True ⋀ isDiv(m, k)