Consider the following contract specification for the static method smooth. 1 2 3 4 5 6…
- User
Consider the following contract specification for the static method smooth.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 /**
- No informal description here for obvious reasons...
- @replaces s2
- @requires |s1| >= 1
- @ensures
- |s2| = |s1| - 1 and
- for all i, j: integer, a, b: string of integer
-
code
where (s1 = a * <i> * <j> * b) - (there exists c, d: string of integer
-
code
(|c| = |a| and -
code
s2 = c * <(i+j)/2> * d))
*/ public static void smooth(Sequence s1, Sequence s2) {...} Answer the following questions.
Suppose seq1 = < 2, 4, 6 >, seq2 = < -5, 12 >. What are the values of seq1 and seq2 after the call smooth(seq1, seq2)? Suppose seq1 = < 7 >, seq2 = < 13, 17, 11 >. What are the values of seq1 and seq2 after the call smooth(seq1, seq2)? Suppose seq1 = < >, seq2 = < >. What are the values of seq1 and seq2 after the call smooth(seq1, seq2)? Explain informally, but precisely, what the specs of smooth say about the method's behavior. In other words, explain in English what smooth is supposed to do.
- Assistant
For the first question, the values of seq1 and seq2 after the call
smooth(seq1, seq2)will be:- seq1: <2, 4, 6>
- seq2: <2, 6>
For the second question, the values of seq1 and seq2 after the call
smooth(seq1, seq2)will be:- seq1: <7>
- seq2: <15, 17, 11>
For the third question, since the length of seq1 is less than 1, the values of seq1 and seq2 will remain unchanged.
The specifications of the
smoothmethod state the following:- The length of
s2is equal to the length ofs1minus 1. - For all integers i and j, and strings of integers a and b, where
s1is equal toa * <i> * <j> * b, there exists strings of integers c and d, where|c| = |a|ands2is equal toc * <(i+j)/2> * d.
In other words, the method
smoothtakes two sequences as input and modifies the second sequence (s2) in such a way that it removes an element from the first sequence (s1) and adjusts the remaining elements accordingly. The resulting will have the same length as minus 1, and the value of each element in will be the average of the adjacent elements in .