Skip to content

Commit

Permalink
Merge pull request #175 from NethermindEth/aemartinez/fix-subgoal-com…
Browse files Browse the repository at this point in the history
…bination

Fix combination of subgoals
  • Loading branch information
langfield authored Feb 13, 2023
2 parents 83c2728 + 0906708 commit 6ae29be
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/Horus/Preprocessor.hs
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,22 @@ instance Show Model where

solve :: Integer -> Text -> PreprocessorL SolverResult
solve fPrime smtQuery = do
optimizeQuery smtQuery >>= foldlM combineResult (Unknown Nothing)
combinedRes <- optimizeQuery smtQuery >>= foldlM combineResult (False, Unsat)
pure $ case combinedRes of
(_, Sat mbModel) -> Sat mbModel
(_, Unknown mbReason) -> Unknown mbReason
(True, Unsat) -> Unknown $ Just "All solvers failed on at least one goal."
(False, Unsat) -> Unsat
where
combineResult (Sat mbModel) _ = pure (Sat mbModel)
combineResult Unsat subgoal = do
result <- computeResult subgoal
pure $ case result of
Sat mbModel -> Sat mbModel
_ -> Unsat
combineResult Unknown{} subgoal = computeResult subgoal
combineResult :: (Bool, SolverResult) -> Goal -> PreprocessorL (Bool, SolverResult)
-- The combined value (Bool, SolverResult) means (was there an unknown, SolverResult so far)
combineResult (hadUnknown, Sat mbModel) _ = pure (hadUnknown, Sat mbModel)
combineResult (hadUnknown, Unsat) subgoal = do
res <- computeResult subgoal
pure (hadUnknown, res)
combineResult (_, Unknown{}) subgoal = do
res <- computeResult subgoal
pure (True, res)

computeResult subgoal = do
result <- runSolver =<< runZ3 (goalToSExpr subgoal)
Expand Down

0 comments on commit 6ae29be

Please sign in to comment.