以下代码(使用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时也是如此。
发布于 2015-03-30 00:40:58
[在提供适当支持的Hackage (http://hackage.haskell.org/package/sbv)上发布sbv4.4之后更新。]
假设您拥有SBV >= 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.发布于 2015-03-26 17:19:14
根据这些注释,以下代码只生成一个解决方案:
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.https://stackoverflow.com/questions/29283304
复制相似问题