Question: 1 . Rewrite the predicate zerosfirst to handle a sequence of integers instead of an array. Call this new predicate zeros 1 . 2 .
Rewrite the predicate zerosfirst to handle a sequence of integers instead of an array. Call this new predicate zeros
Write another predicate, called zeros which has the same signature as zeros 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.
Validate that zeros and zeros are equivalent. Call this validator anything you like that Dafny accepts.
Rewrite the method ZeroSort from this chapter to sort a sequence of integers instead of an array. The signature of the rewritten 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 zeros in the specification of this method to verify the method's correctness
Write a validator that shows ZeroSortSeq has correctly sorted and not corrupted the input sequence. Use the second predicate zeros 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 exdfy which should contain Dafny predicate zeros predicate zeros the alidator proving equivalence, method ZeroSortSeq and the method's validator.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
