Skip to content

Commit

Permalink
Merge pull request #14 from eliascarv/up-readme
Browse files Browse the repository at this point in the history
New README
  • Loading branch information
eliascarv authored May 11, 2022
2 parents 56d3492 + a8d52fc commit fc9728d
Showing 1 changed file with 135 additions and 78 deletions.
213 changes: 135 additions & 78 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,7 @@ julia>] add TruthTables

## Usage

To create a truth table use the `@truthtable` macro passing a proposition as an argument.
The `@truthtable` macro has a optional keyword argument: `full`,
if `full` is `true` the truth table will be created in expanded form.\
Some logical operators can be expressed using different symbols.
This is the list of symbols that can be used:

| Operator | Symbols |
|-----------|-------------|
| AND | `&&`, `&`, `` (`\wedge<tab>`) |
| OR | `\|\|`, `\|`, `` (`\vee<tab>`) |
| NOT | `!`, `~`, `¬` (`\neg<tab>`) |
| XOR | `` (`\xor<tab>`) |
| NAND | `` (`\nand<tab>`) |
| NOR | `` (`\nor<tab>`) |
| IMPLICATION | `-->` |
| EQUIVALENCE | `<-->`, `` (`\equiv<tab>`) |

Examples:
To create a truth table use the `@truthtable` macro passing a proposition as an argument:

```julia
julia> using TruthTables
Expand All @@ -48,25 +31,13 @@ TruthTable
truefalsetrue
falsefalsefalse
└───────┴───────┴───────┘
```

The `@truthtable` macro has an optional keyword argument: `full`,
if `full` is `true` the truth table will be created in expanded form:

julia> @truthtable p & (~q | r)
TruthTable
┌───────┬───────┬───────┬──────────────┐
│ p │ q │ r │ p (¬q r) │
├───────┼───────┼───────┼──────────────┤
truetruetruetrue
falsetruetruefalse
truefalsetruetrue
falsefalsetruefalse
truetruefalsefalse
falsetruefalsefalse
truefalsefalsetrue
falsefalsefalsefalse
└───────┴───────┴───────┴──────────────┘


julia> @truthtable p & (~q | r) full=true
```julia
julia> @truthtable p && (!q || r) full=true
TruthTable
┌───────┬───────┬───────┬───────┬────────┬──────────────┐
│ p │ q │ r │ ¬q │ ¬q r │ p (¬q r) │
Expand All @@ -80,59 +51,145 @@ TruthTable
truefalsefalsetruetruetrue
falsefalsefalsetruetruefalse
└───────┴───────┴───────┴───────┴────────┴──────────────┘
```

It is possible to change the way `TruthTable`s are displayed using `TruthTables.showmode!(mode)` function.
The mode argument can be one of these symbols: `:bool` (default), `:bit` or `:letter`.
Boolean values (`true` and `false`) will be displayed without formatting in `:bool` mode,
as `1` and `0` in `:bit` mode and as T and F in `:letter` mode.

```julia
julia> TruthTables.showmode!(:bit)
:bit

julia> @truthtable p q <--> r
julia> @truthtable p || q <--> r
TruthTable
┌───┬───┬───┬──────────────┐
│ p │ q │ r │ p q <--> r │
├───┼───┼───┼──────────────┤
1111
0111
1011
0010
1100
0100
1000
0001
└───┴───┴───┴──────────────┘

julia> @truthtable p || q <--> r full=true
TruthTable
┌───┬───┬───┬───────┬──────────────┐
│ p │ q │ r │ p q │ p q <--> r │
├───┼───┼───┼───────┼──────────────┤
11111
01111
10111
00100
11010
01010
10010
00001
└───┴───┴───┴───────┴──────────────┘

julia> TruthTables.showmode!(:letter)
:letter

julia> @truthtable !(p || q) <--> (!p && !q)
TruthTable
┌───┬───┬───────────────────────┐
│ p │ q │ ¬(p q) <--> ¬p ¬q │
├───┼───┼───────────────────────┤
│ T │ T │ T │
│ F │ T │ T │
│ T │ F │ T │
│ F │ F │ T │
└───┴───┴───────────────────────┘

julia> @truthtable !(p || q) <--> (!p && !q) full=true
TruthTable
┌───┬───┬───────┬──────────┬────┬────┬─────────┬───────────────────────┐
│ p │ q │ p q │ ¬(p q) │ ¬p │ ¬q │ ¬p ¬q │ ¬(p q) <--> ¬p ¬q │
├───┼───┼───────┼──────────┼────┼────┼─────────┼───────────────────────┤
│ T │ T │ T │ F │ F │ F │ F │ T │
│ F │ T │ T │ F │ T │ F │ F │ T │
│ T │ F │ T │ F │ F │ T │ F │ T │
│ F │ F │ F │ T │ T │ T │ T │ T │
└───┴───┴───────┴──────────┴────┴────┴─────────┴───────────────────────┘
```

Some logical operators can be expressed using different symbols.
This is the list of symbols that can be used:

| Operator | Symbols |
|-----------|-------------|
| AND | `&&`, `&`, `` (`\wedge<tab>`) |
| OR | `\|\|`, `\|`, `` (`\vee<tab>`) |
| NOT | `!`, `~`, `¬` (`\neg<tab>`) |
| XOR | `` (`\xor<tab>`) |
| NAND | `` (`\nand<tab>`) |
| NOR | `` (`\nor<tab>`) |
| IMPLICATION | `-->` |
| EQUIVALENCE | `<-->`, `` (`\equiv<tab>`) |

Examples:

```julia
julia> TruthTables.showmode!() # default show mode
:bool

julia> @truthtable ~p & (q | r)
TruthTable
┌───────┬───────┬───────┬──────────────┐
│ p │ q │ r │ p q <--> r
│ p │ q │ r │ ¬p (q r)
├───────┼───────┼───────┼──────────────┤
truetruetruetrue
truetruetruefalse
falsetruetruetrue
truefalsetruetrue
falsefalsetruefalse
truefalsetruefalse
falsefalsetruetrue
truetruefalsefalse
falsetruefalsefalse
falsetruefalsetrue
truefalsefalsefalse
falsefalsefalsetrue
falsefalsefalsefalse
└───────┴───────┴───────┴──────────────┘


julia> @truthtable p q <--> r full=true
julia> @truthtable ~p & (q | r) full=true
TruthTable
┌───────┬───────┬───────┬───────┬──────────────┐
│ p │ q │ r │ p q │ p q <--> r │
├───────┼───────┼───────┼───────┼──────────────┤
truetruetruetruetrue
falsetruetruetruetrue
truefalsetruetruetrue
falsefalsetruefalsefalse
truetruefalsetruefalse
falsetruefalsetruefalse
truefalsefalsetruefalse
falsefalsefalsefalsetrue
└───────┴───────┴───────┴───────┴──────────────┘


julia> @truthtable !(x || y) <--> (!x && !y)
┌───────┬───────┬───────┬───────┬───────┬──────────────┐
│ p │ q │ r │ ¬p │ q r │ ¬p (q r) │
├───────┼───────┼───────┼───────┼───────┼──────────────┤
truetruetruefalsetruefalse
falsetruetruetruetruetrue
truefalsetruefalsetruefalse
falsefalsetruetruetruetrue
truetruefalsefalsetruefalse
falsetruefalsetruetruetrue
truefalsefalsefalsefalsefalse
falsefalsefalsetruefalsefalse
└───────┴───────┴───────┴───────┴───────┴──────────────┘

julia> TruthTables.showmode!(:bit)
:bit

julia> @truthtable (p --> q) (¬p q)
TruthTable
┌───────┬───────┬───────────────────────┐
│ x │ y │ ¬(x y) <--> ¬x ¬y │
├───────┼───────┼───────────────────────┤
truetruetrue
falsetruetrue
truefalsetrue
falsefalsetrue
└───────┴───────┴───────────────────────┘


julia> @truthtable !(x || y) <--> (!x && !y) full=true
┌───┬───┬────────────────────┐
│ p │ q │ (p --> q) ¬p q │
├───┼───┼────────────────────┤
111
011
101
001
└───┴───┴────────────────────┘

julia> @truthtable (p --> q) (¬p q) full=true
TruthTable
┌───────┬───────┬───────┬──────────┬───────┬───────┬─────────┬───────────────────────┐
x │ y │ x y¬(x y) │ ¬x ¬y │ ¬x ¬y │ ¬(x y) <--> ¬x ¬y
├───────┼───────┼───────┼──────────┼───────┼───────┼─────────┼───────────────────────┤
truetruetruefalsefalsefalsefalse true
falsetruetruefalsetruefalsefalse true
truefalsetruefalsefalsetruefalsetrue
falsefalsefalsetruetruetruetrue true
└───────┴───────┴───────┴──────────┴───────┴───────┴─────────┴───────────────────────┘
┌───┬───┬─────────┬────┬────────┬────────────────────┐
p │ q │ p --> q¬p │ ¬p q(p --> q) ¬p q
├───┼───┼─────────┼────┼────────┼────────────────────┤
111 01 1
011 11 1
100 00 1
001 11 1
└───┴───┴─────────┴────┴────────┴────────────────────┘
```

0 comments on commit fc9728d

Please sign in to comment.