How to automatically find counterexample #62
-
I'm trying to write a spec for Is there some way I could have defined the using Supposition
Base.map(f, x::Set) = Set(Iterators.map(f, x))
length_map(f, x) = length(map(f, x)) == length(x)
@check false_negative(f=Data.Just(abs), x=map(Set, Data.Vectors(Data.Integers{Int}(); max_size=8))) = length_map(f, x)
@check counterexample(f=Data.Just(abs), x=Data.Just(Set([-1,1]))) = length_map(f, x) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
On a 64-bit system, julia> data = map(Set, Data.Vectors(Data.Integers{Int8}(); max_size=8))
julia> @check false_negative(f=Data.Just(abs), x=data) = length_map(f, x)
Found counterexample
Context: false_negative
Arguments:
f::typeof(abs) = abs
x::Set{Int8} = Set(Int8[-127, 127]) This works because An alternative is to use a mapping that forces more collisions by tightening the result domain (i.e. one that is not injective): julia> data = map(Set, Data.Vectors(Data.Integers{Int}(); max_size=8));
julia> @check function false_negative(r=Data.Integers(1,500), x=data)
length_map(x) do s
rem(s, r)
end
end
Found counterexample
Context: false_negative
Arguments:
r::Int64 = 1
x::Set{Int64} = Set([-9223372036854775807, -9223372036854775808]) This has the effect that more initial values end up in the sets of possible collisions with each other, increasing the likelihood that Supposition.jl is able to find a collision. Note that both of these didn't find the final collision with |
Beta Was this translation helpful? Give feedback.
On a 64-bit system,$2^\mathrm{64}$ distinct values. The likelihood that two numbers with the same absolute value are picked is pretty small, about $1/2^\mathrm{63}$ if my Math is right (both 0 and
Int
hastypemin
already map to themselves, so are not relevant). Therefore, the easiest way to increase the likelihood of finding a collision is to use a smaller datatype, e.g.Int8
:This works because
abs
behaves the same…