hatt: A truth table generator for classical propositional logic.

[ bsd3, library, logic, program ] [ Propose Tags ] [ Report a vulnerability ]

Hatt is a command-line program which prints truth tables for expressions in classical propositional logic, and a library allowing its parser, evaluator and truth table generator to be used in other programs.


[Skip to Readme]

Modules

[Index]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1, 0.2, 0.3, 1.0, 1.1, 1.1.1, 1.2.0, 1.2.1, 1.3.0, 1.3.1, 1.4.0, 1.4.0.1, 1.4.0.2, 1.5.0.0, 1.5.0.2, 1.5.0.3
Dependencies base (>=4 && <5), cmdargs (>=0.6 && <0.7), containers (>=0.3 && <0.4), parsec (>=2.1 && <2.2) [details]
License BSD-3-Clause
Copyright (c) 2011 Benedict Eastaugh
Author Benedict Eastaugh
Maintainer benedict@eastaugh.net
Category Logic
Home page https://github.com/beastaugh/hatt
Source repo head: git clone git://github.com/beastaugh/hatt.git
Uploaded by BenedictEastaugh at 2011-03-20T17:27:41Z
Distributions
Reverse Dependencies 1 direct, 0 indirect [details]
Executables hatt
Downloads 11695 total (44 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for hatt-1.1

[back to package description]

Hatt

Hatt is a command-line program which prints truth tables for expressions in classical propositional logic, and a library allowing its parser, evaluator and truth table generator to be used in other programs.

Installation

Hatt is available from Hackage. To install it with cabal-install, update your list of known packages and then install Hatt.

$ cabal update
$ cabal install hatt

To build it from source, cd into the directory containing the Hatt source files, including hatt.cabal, and run cabal install.

Valid Hatt expressions

The following are all valid expression forms which can be parsed by Hatt, where ϕ and ψ are metalinguistic variables standing in for any valid expression. The parser isn't as smart about parentheses as it could be, so you have to follow these rules quite literally. This shouldn't be a great hardship, but it does mean that, for example, while (A -> B) is a valid expression, A -> B isn't.

  • Variables: P, Q, a, b etc.---basically anything in the character class [a-zA-Z]
  • Negation:
  • Conjunction: (ϕ & ψ)
  • Disjunction: (ϕ | ψ)
  • Conditional: (ϕ -> ψ)
  • Biconditional: (ϕ <-> ψ)

Using the hatt command-line program

The default mode is interactive: you start the program, enter expressions at the prompt, and their truth tables are printed. Here's an example session.

$ hatt
Entering interactive mode. Type `help` if you don't know what to do!
> help
Hatt's interactive mode has a couple of commands.

help
  Print this help text.

pretty
  Pretty-print expressions using Unicode logic symbols. Only employ this
  option if your console is Unicode-aware. If pretty-printing is already
  enabled, using this command will disable it.

exit
  Quit the program.

If you don't type in a command, the program will assume you're writing a
logical expression to be evaluated and attempt to parse it.

For example, if you enter "(A -> B)" at the prompt, Hatt will print the
truth table for that expression. Here's an example console session.

    > (A | B)
    A B | (A ∨ B)
    -------------
    T T | T
    T F | T
    F T | T
    F F | F
    > foobar
    Error: parse error at (line 1, column 1):
    unexpected "f"
    expecting white space, "(" or "~"
   > exit

If none of this makes any sense, try reading the README file.
> (A -> B)
A B | (A -> B)
--------------
T T | F
T F | F
F T | F
F F | T
> exit

The --evaluate flag lets you pass a single expression to be evaluated directly.

$ hatt --evaluate="(P -> (Q | ~R))"
P Q R | (P -> (Q | ~R))
-----------------------
T T T | F
T T F | F
T F T | F
T F F | F
F T T | F
F T F | F
F F T | T
F F F | F

By default, hatt will print ASCII representations of expressions. If you have a Unicode-capable terminal, try passing the --pretty option to pretty-print expressions using the the more common logical symbols.

$ hatt --evaluate="(P -> (Q | ~R))" --pretty
P Q R | (P → (Q ∨ ¬R))
----------------------
T T T | F
T T F | F
T F T | F
T F F | F
F T T | F
F T F | F
F F T | T
F F F | F

You can enable pretty-printing while in interactive mode by using the pretty command.

Using Hatt in other programs

Hatt exposes the Data.Logic.Propositional module, which provides a simple API for parsing, evaluating, and printing truth tables.