latex truth table: easy part
This commit is contained in:
parent
1a2c2fb50f
commit
d7d1e0cb05
1 changed files with 32 additions and 0 deletions
32
Main.hs
32
Main.hs
|
@ -1,6 +1,7 @@
|
|||
import Control.Applicative (Applicative, Alternative(..))
|
||||
import Data.Char (isAlphaNum)
|
||||
import Data.Functor (Functor)
|
||||
import Data.List (intercalate)
|
||||
import Data.Maybe (fromJust)
|
||||
import qualified Data.Map as M
|
||||
import qualified Data.Set as S
|
||||
|
@ -205,3 +206,34 @@ serialize = aux
|
|||
latex (Iff s1 s2) = connective "\\leftrightarrow " (latex s1) (latex s2)
|
||||
|
||||
connective token s1 s2 = "(" <> s1 <> token <> s2 <> ")"
|
||||
|
||||
truthtable :: Statement -> String
|
||||
truthtable s = open <> header <> "\\hline\n" <> body <> close
|
||||
where
|
||||
open =
|
||||
"\\begin{tabular}{" <>
|
||||
replicate (length atomsList) 'c' <>
|
||||
"|" <>
|
||||
replicate (length serial) 'c' <>
|
||||
"}\n"
|
||||
|
||||
close = "\\end{tabular}\n\n"
|
||||
|
||||
serial = serialize Latex s
|
||||
|
||||
atomsList :: [String]
|
||||
atomsList = S.toAscList $ atoms s
|
||||
|
||||
header :: String
|
||||
header = intercalate "&" atomsList <> " \\\\\n"
|
||||
|
||||
body = concat $ map line $ enumerate atomsList
|
||||
|
||||
line assignments =
|
||||
intercalate "&" (bools assignments) <>
|
||||
intercalate " & " (parts assignments) <>
|
||||
" \\\\\n"
|
||||
|
||||
bools assignments = [if bool then "1" else "0" | (key, bool) <- assignments]
|
||||
|
||||
parts assignments = [""]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue