You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
gcd : [8] -> [8] -> [8]
gcd a b = if(b == 0) then a
else gcd b (a%b)
We can use :exhaust to prove the following property about gcd, but :prove never returns.
Main> :exhaust \x -> gcd 0 x == x
Using exhaustive testing.
passed 256 tests.
Q.E.D.
Main> :prove \x -> gcd 0 x == x
<break>
The termination condition of gcd is that b = 0. Since, for the above proof, b is symbolic, both branches of the if statement are followed because we can't determine whether or not b is 0. The second time through the recursion, a takes on the symbolic value of b, and now b takes on 0%b, which (as seen below) is 0, so the recursion should terminate.
Main> :prove \x -> 0%(x:[8]) == 0
Q.E.D.
I figure that the implementation of % in the symbolic execution engine could to be strengthened by ensuring that constant values are propagated when available, helping avoid symbolic termination problems.
The text was updated successfully, but these errors were encountered:
Note that this example works fine with :set iteSolver=on.
The SBV library implements various optimizations of this kind, e.g. 0 * x = 0, 0 + x = x. It should be a simple matter to add a special-case rule for sRem 0 x = 0 to the SBV library, and contribute the patch upstream.
In reality, I find such "optimizations" to hardly ever pay off. As Brian mentioned, using 'iteSolver' (or sBranch in SBV parlance) is probably the right thing to do in such cases.
Consider gcd:
We can use
:exhaust
to prove the following property aboutgcd
, but:prove
never returns.The termination condition of
gcd
is thatb = 0
. Since, for the above proof,b
is symbolic, both branches of theif
statement are followed because we can't determine whether or notb
is0
. The second time through the recursion,a
takes on the symbolic value ofb
, and nowb
takes on0%b
, which (as seen below) is0
, so the recursion should terminate.I figure that the implementation of
%
in the symbolic execution engine could to be strengthened by ensuring that constant values are propagated when available, helping avoid symbolic termination problems.The text was updated successfully, but these errors were encountered: