SBV is a Haskell framework, allowing high-level use of SMT solvers directly from Haskell. SBV is an acronym for "SMT Based Verification," and SMT is an acronym for "Satisfiability Modulo Theories."
Questions tagged [sbv]
39 questions
2
votes
1 answer
Efficient way to "keep turning the crank" on a stateful computation
I have a stateful process that is modelled as an i -> RWS r w s a. I want to feed it an input cmds :: [i]; currently I do that wholesale:
let play = runGame theGame . go
where
go [] = finished
go ((v, n):cmds) =…

Cactus
- 27,075
- 9
- 69
- 149
2
votes
1 answer
Combining Tuples in SBV?
Basically I'm wondering, is there any way to write a function of the following type with the SBV library:
(SBV a, SBV b) -> SBV (a,b)
This seems like it should be possible: if we have two symbolic values, we can make a new symbolic value, as a…

jmite
- 8,171
- 6
- 40
- 81
2
votes
1 answer
Encoding extended naturals in SBV
I'm experimenting with the following way of encoding extended naturals in SMT-LIB (I define a datatype analogous to Maybe Integer):
; extended integers -- if first field is true, then the value is infinity
(declare-datatypes () ((IntX (mk-int-x…

buggymcbugfix
- 321
- 1
- 11
2
votes
2 answers
Automatically deriving Provable for predicates over records in SBV
I'm in a situation where I have a data type like
data X = X {foo :: SInteger, bar :: SInteger}
and I want to prove e.g.
forAll_ $ \x -> foo x + bar x .== bar x + foo x
using haskell's sbv.
This doesn't compile because X -> SBool is not an instance…

Martin Bidlingmaier
- 141
- 3
1
vote
1 answer
Implementing the x86 PDEP/PEXT instructions efficiently in SMTlib
Is there a way to specify the PDEP/PEXT instructions efficiently in SMTlib bitvector syntax?
My best attempt for PEXT ends up with something to the tune of: "Iff bit N in mask is set, then bit count_bits(mask[0..N]) in the result is equal to bit N…

cmpxchg8b
- 661
- 5
- 16
1
vote
1 answer
Proving a simple list function applied four times is the identity
The following video contains a mathematical card trick due to Colm Mulcahy:
https://www.youtube.com/watch?v=dHzUQnRjbuM
The key operation in the trick is defined as follows:
COAT (Count Out And Transfer)
Given a packet of n cards, COATing k cards…

Theo H
- 131
- 10
1
vote
1 answer
What pattern is suitable for expressing Null value in a SBV formula
I am translating SQL predicate into Z3 language.
SQL predicate expression is very close to expressions in Z3:
where x + y > 0
====
(declare-const x Int)
(declare-const y Int)
(assert (> (+ x y) 0)))
but I don't see how to represent Null values.
In…

Daniil Iaitskov
- 5,525
- 8
- 39
- 49
1
vote
2 answers
Conditions on list comprehension using Haskell and SBV
I want to write a Haskell list comprehension with a condition on symbolic expressions (SBV). I reproduced the problem with the following small example.
import Data.SBV
allUs :: [SInteger]
allUs = [0,1,2]
f :: SInteger -> SBool
f 0 = sTrue
f 1…

sfx
- 103
- 9
1
vote
1 answer
Parallel solving in SBV with Z3
Referring to this answer, I'm trying the following to run Z3 in parallel from SBV:
runSMTWith z3{extraArgs = ["parallel.true"]} $ do ...
However, the above leads to the following exception:
*** Exception:
*** Data.SBV: fd:21: hGetLine: end of…

Jivan
- 21,522
- 15
- 80
- 131
1
vote
1 answer
Constrain a symbolic list on count of elements of a certain type in SBV
Using the SBV library, I'm trying to satisfy conditions on a symbolic list of states:
data State = Intro | Start | Content | Comma | Dot
mkSymbolicEnumeration ''State
-- examples of such lists
[Intro, Start, Content, Comma, Start, Comma, Content,…

Jivan
- 21,522
- 15
- 80
- 131
1
vote
1 answer
Symbolic `show` for `SInt16`
I am looking for a way to turn an SInt16 into an SString. For my use case, it is enough that it does the right thing for concrete values, i.e. I will only be looking at the SString result for concrete SInt16s.
I noticed there is a Show instance for…

Cactus
- 27,075
- 9
- 69
- 149
1
vote
2 answers
Optimisation with list solution: compiler error
I'm trying to solve an optimisation problem with sbv in Haskell, but get a compiler error.
The solution is a list of values, and I have a function to check the solution is valid (the constraint), and a function to calculate a number to minimize.
I…

8n8
- 1,233
- 1
- 8
- 21
1
vote
1 answer
How to use Data.SBV to help derive correct stack machine implementation?
Graham Hutton, in the 2nd edition of Programming in Haskell, spends the last 2 chapters on the topic of stack machine based implementation of an AST.
And he finishes by showing how to derive the correct implementation of that machine from the…

dbanas
- 1,707
- 14
- 24
1
vote
1 answer
Exception from Z3 running minimize example for Data.SBV
When running the example for the optimize function in the Data.SBV library for Haskell:
problem :: Goal
problem = optimize Lexicographic $ do [x1, x2] <- mapM sReal ["x1", "x2"]
constrain $ x1 + x2 .<= 10
constrain $ x1 - x2 .>=…

Matt Ahrens
- 129
- 7
0
votes
1 answer
PyExZ3 does not find all feasible paths of a program
A tiny example of PyExZ3 usage that I came up with did not work as expected.
Here is the example:
def d1(x,y):
if y < x - 2 :
return 7
else :
return 2
def d2(x,y):
if y > 3 :
return 10
else:
return 50
def d3(x,y):
if y <…

zajer
- 649
- 6
- 17