Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove split-on-every-assert by introducing ghost array input #171

Merged
merged 2 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Distributions/Uniform/Interface.dfy
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ module Uniform.Interface {
ensures u < n
ensures Model.Sample(n as nat)(old(s)) == Monad.Result(u as nat, s)

method UniformIntervalSample32(a: int32, b: int32) returns (u: int32)
method UniformIntervalSample32<T>(a: int32, b: int32, ghost arr: array<T>) returns (u: int32)
modifies `s
decreases *
requires 0 < b as int - a as int < 0x8000_0000
ensures a <= u < b
ensures Model.IntervalSample(a as int, b as int)(old(s)) == Monad.Result(u as int, s)
ensures old(arr[..]) == arr[..]
{
var v := UniformSample32(b-a);
assert Model.Sample(b as int - a as int)(old(s)) == Monad.Result(v as nat, s);
Expand Down
5 changes: 3 additions & 2 deletions src/Util/FisherYates/Implementation.dfy
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module FisherYates.Implementation {

trait {:termination false} Trait extends Interface.Trait {

method {:vcs_split_on_every_assert} Shuffle<T>(a: array<T>)
method Shuffle<T>(a: array<T>)
decreases *
modifies `s, a
requires a.Length < 0x8000_0000
Expand All @@ -26,9 +26,10 @@ module FisherYates.Implementation {
invariant Equivalence.LoopInvariant(prevI, i, a, prevASeq, old(a[..]), old(s), prevS, s) // ghost
{
prevI, prevASeq, prevS := i, a[..], s; // ghost
var j := UniformIntervalSample32(i, a.Length as nat32);
var j := UniformIntervalSample32(i, a.Length as nat32, a);
assert prevASeq == a[..]; // ghost
Swap(a, i, j);
assert Equivalence.LoopInvariant(prevI, i+1, a, prevASeq, old(a[..]), old(s), prevS, s); // ghost
}
} else {
Equivalence.ShuffleElseClause(a, old(a[..]), old(s), s); // ghost
Expand Down
4 changes: 2 additions & 2 deletions src/interop/java/Full/Random.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public java.math.BigInteger UniformIntervalSample(java.math.BigInteger a, java.m
return Uniform.Interface._Companion_Trait.UniformIntervalSample(this, a, b);
}

public int UniformIntervalSample32(int a, int b) {
return Uniform.Interface._Companion_Trait32.UniformIntervalSample32(this, a, b);
public <__T> int UniformIntervalSample32(dafny.TypeDescriptor<__T> _td___T, int a, int b) {
return Uniform.Interface._Companion_Trait32.UniformIntervalSample32(_td___T, this, a, b);
}

public java.math.BigInteger UniformSample(java.math.BigInteger n) {
Expand Down