Exercises 2 & 3 are based on those supplied by Prof. Janusz Laski from Oakland University.
[x | x in set {2,...,5} & x > 2]
[x | x in set {3,5,2,4} & x*x < 22]
L
has less than 5 distinct elements.L
has no duplicated elements.L1
and L2
are non-empty and are disjoint (i.e. they have no elements in common).inds
operator.seq of (seq of nat)
, write an expression which says that all the sequences in L are disjoint.Given are two arrays A[1..N] and B[1..N]. Translate the following into VDM-SL predicates and test them so both the true and false values will be returned.
HINT: Model the arrays as sequences.
In the following, consider a line as a sequence of characters. Specify and test the function
NumOfOccurr: ? -> ?
that returns the number of occurrences of character x
in sequence p
of type Line
.
Specify and test the function
NumOfDistinctEls: ? -> ?
that returns the number of distinct elements in p
of type Line
.
Specify and test function
Distance: ? * ?
which, given p
and q
of type Line
, returns the number of distinct characters that are either in p
or in q
but not in both.
Define the function Average
to take a sequence of real numbers and return the average of those numbers.
Define a function which reverses a sequence. Make two definitions: one using recusrsion and one using sequence comprehension.
Let’s revisit the solution made to Exercise 5 on sets and see how an alternative model using sequences would look.