Question: predicate zeros 1 ( s: seq ) { forall i , j :: 0 = i | s | && 0 = j | s
predicate zeross: seq
forall i j :: i s && j s && i j si sj
predicate zeross: seq
forall i :: i s && si forall j :: j i sj
lemma ValidateZerosEquivalences: seq
ensures zeross zeross
Prove zeros implies zeros
if zeross
forall i :: i s && si forall j :: j i sj
Assume i s and si
assume i s && si;
Prove forall j :: j i sj
forall j :: j i sj
assume j i; Assume the range for j
From zeros definition: If sj then si which contradicts si
assert sj;
Prove zeros implies zeros
if zeross
forall i j :: i j ssi sj
Assume i j s and prove si sj
assume i j s;
if si
If si then zeros guarantees that sj
assert sj;
else
Otherwise, si implies the condition is already satisfied
assert si;
method ZeroSortSeqs: seq returns t: seq
ensures zerost
ensures t sfilterx x sfilterx x
var zeros : sfilterx x ;
var nonZeros : sfilterx x ;
t : zeros nonZeros;
lemma ValidateZeroSortSeqs: seq, t: seq
requires t ZeroSortSeqs
ensures zerost
ensures multisett multisets
assert zerost;
assert multisett multisets;
this is my code ; this is the error ; question is attached; it is not a syntax error there is no missiring there is something wrong with the code pls help me figure it out make sure your code is right before you senf it to me
n the Linear Sort chapter in the lecture slides, a predicate zerosfirst and method ZeroSort are shown. 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 methods 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.
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
