[Haskell-cafe] Boolean formula: part2

Dmitry Bogatov KAction at gnu.org
Wed Sep 17 19:48:49 UTC 2014


Hello!  I have following code:

buildFormulas :: [Variable] -> Int -> [Formula]
buildFormulas vars 0 = map Var vars
buildFormulas vars n = join $
    forM [0 .. n - 1 ] $ \i -> do
        x <- buildFormulas vars i
        y <- buildFormulas vars (n - i - 1)
        z <- buildFormulas vars (n - 1)
        let t1 = case z of
              (Negation _) -> []
              _ -> [Negation z]
        t1 ++ [conj x y, impl x y, disj x y]

It is correct, typechecks, but it is insanely slow (calculating
take 35 (buildFormulas [P, Q, R] 5) hangs my computer).

My guess is that it builds too much before returning first results.
Can you suggest more efficent way enumerate formulas of set of variables?




--
Best regards, Dmitry Bogatov <KAction at gnu.org>,
Free Software supporter, esperantisto and netiquette guardian.
GPG: 54B7F00D
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140917/3aff6c2b/attachment.sig>


More information about the Haskell-Cafe mailing list