Lab
Lab
PROBLEM:
Let Elem be the set of all integers in the range 0..M (for some
constant M) which we call "elements". Let Arr be the set of all
"arrays" of length N (for some constant N) of "element" values.
Let Index be the set of all integers in the range -1..N (which
includes all valid array indices 0..N-1 but also -1 and N).
Now consider the following problem: given an array "a" with n>0
elements that has no duplicates in the first "n" positions, remove
from "a" the greatest element; this results in an array that has
n-1 elements. For example, for N=5 and M=3, the legal inputs
a=[2,3,0,1,0] and n=4 result in the output b=[2,0,1,0,0].
Since "a" has no duplicates in the first "n" positions,
"b" is uniquely determined.
YOUR TASKS:
DELIVERABLES:
For this clear the terminal by pressing the "Clear Output" button
abeled by a broom, modify and save the file (which results in the
"Computing..." output) and then run the two operations.
3. A screenshot of the visualization window for operation testOut2a()
which displays the evaluation of the formula "output()" on an
*illegal* output (yielding the truth value "false"). Make sure
Please note that the label "n:t" at each arrow denotes the
number "n" of the subformula to which the arrow points and
its truth value "t"; numbering starts with 0, so the first
subformula is the one with label n=0 (subformulas may be
shuffled by the automatic layout of the graph).
Important: hover with the mouse pointer over each node to see
the values of the variables on which each subformula depends and
the truth value of the subformula. Use this information
to explain the overall result.
*/
// ================================================================
// perform here your changes
// ================================================================
val N = 5;
val M = 3;
pred array(a:Arr,n:Index)
requires n ≥ 0;
⇔
// formulate here "a has n elements"
⊤
;
pred nodup(a:Arr,n:Index)
requires n ≥ 0;
⇔
// formulate here "a has no duplicates in the first n positions"
⊤
;
pred input(a:Arr,n:Index) ⇔
// formulate here the input condition
⊤
;
pred output(a:Arr,n:Index,b:Arr)
requires n > 0;
⇔
// formulate here the output condition
⊤
;
// ================================================================
// no more changes needed below (except for testOut2a())
// ================================================================
// ================================================================
// end of file
// ================================================================