HsSymMath ========= Interactive mathematical languages written in haskell ## Logic.hs ## Formal logic parser ### Command line ### Currently the command line will take a logical expression as an argument and print out its corresponding truth table. ``` $ ./Logic Enter Command > TruthTable: a&b+c->~a&b 'a' 'b' 'c' | (((a&b)+c)->(~a&b)) True True True | False True True False | False True False True | False True False False | True False True True | True False True False | True False False True | False False False False | True Enter Command > ToNand: a&b->c (((((a|b)|(a|b))|((a|b)|(a|b)))|(((a|b)|(a|b))|((a|b)|(a|b))))|(c|c)) Enter Command > ToNor: a&b->c (((((a/a)/(b/b))/((a/a)/(b/b)))/c)/((((a/a)/(b/b))/((a/a)/(b/b)))/c)) ``` ### Code ### ```haskell > And (Atom 'a') (Not (Atom 'b')) (a&~b) > truthTable $ And (Atom 'a') (Not (Atom 'b')) 'a' 'b' | (a&~b) True True | False True False | True False True | False False False | False > toNand $ And (Atom 'a') (Not (Atom 'b')) ((a|(b|b))|(a|(b|b))) > toNor $ And (Atom 'a') (Not (Atom 'b')) ((a/a)/((b/b)/(b/b))) > let exp = And (Atom 'a') (Not (Atom 'b')) > exp == toNand exp True > exp == toNor exp True > exp == toNor (toNand exp) True ```