Question: 1 . Rewrite the predicate zerosfirst to handle a sequence of integers instead of an array. Call this new predicate zeros 1 . 2 .

1. Rewrite the predicate zerosfirst to handle a sequence of integers instead of an array. Call this new predicate zeros1.
2. Write another predicate, called zeros2, which has the same signature as zeros1 and is true if every element in the sequence that is zero is preceded by only elements that are zero and is false otherwise. The predicate should be a precise translation of this statement.
3. Validate that zeros1 and zeros2 are equivalent. Call this validator anything you like that Dafny accepts.
4. Re-write the method ZeroSort from this chapter to sort a sequence of integers instead of an array. The signature of the re-written method should be:
method ZeroSortSeq (s:seq) returns (t:seq)
Notice this method returns the sorted sequence in \( t \). This is necessary because the input sequence \( s \) cannot be modified (unlike an array).
There are two conditions:
- use the same algorithm to sort the sequence as ZeroSort from lectures
- use predicate zeros1 in the specification of this method to verify the method's correctness
5. Write a validator that shows ZeroSortSeq has correctly sorted and not corrupted the input sequence. Use the second predicate zeros2 in the validator. You may call the validator anything you like that Dafny accepts.
You are not allowed to use arrays anywhere in this exercise, just sequences.
Submit the file ex2.dfy, which should contain 1) Dafny predicate zeros1,2) predicate zeros2,3) the alidator proving equivalence, 4) method ZeroSortSeq and 5) the method's validator.
1 . Rewrite the predicate zerosfirst to handle a

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!