以下代码(使用SBV):
{-# LANGUAGE ScopedTypeVariables #-}
import Data.SBV
main :: IO ()
main = do
res <- allSat zeros
putStrLn $ show res
zeros :: Predicate
zeros = do
z1 <- sDouble "Z1"
constrain $ z1 .== 0.0
return true
生成两个解决方案:
Solution #1:
Z1 = 0.0 :: SDouble
Solution #2:
Z1 = -0.0 :: SDouble
Found 2 different solutions.
如何消除无趣的-0.0
解决方案?我无法使用z1 ./= -0.0
,因为z1
为0.0
时也是如此。
答案 0 :(得分:3)
[在Hackage(http://hackage.haskell.org/package/sbv)上发布SBV 4.4之后更新,提供了适当的支持。]
假设你有SBV&gt; = 4.4,你现在可以:
Prelude Data.SBV> allSat $ \z -> z .== (0::SDouble)
Solution #1:
s0 = 0.0 :: Double
Solution #2:
s0 = -0.0 :: Double
Found 2 different solutions.
Prelude Data.SBV> allSat $ \z -> z .== (0::SDouble) &&& bnot (isNegativeZeroFP z)
Solution #1:
s0 = 0.0 :: Double
This is the only solution.
答案 1 :(得分:1)
根据评论,以下代码只生成一个解决方案:
zeros :: Predicate
zeros = do
z1 <- sDouble "Z1"
constrain $ z1 .== 0.0 &&& ((1 / z1) .> 0)
return true
输出:
Solution #1:
Z1 = 0.0 :: SDouble
This is the only solution.