Propositional Logic

crates.io CI

A rust library for generating the truth table of any single compound proposition.

only has one dependency: cli_table

Usage

truth_table! macro

this macro only creates and returns the truth table.

```rust use propositionallogic::prelude::*; use clitable::{print_stdout, TableStruct};

let compound_proposition = |p, q, r| -> bool { iff(q, (p && !q) || (!p && q)) && r };

// giving it a function (any function with boolean input and output works, technically) let table: TableStruct = truthtable!(|p, q, r| => compoundproposition);

// giving it an inline proposition (similar to a closure) let table: TableStruct = truthtable!(|p, q, r| => inlinecompound_proposition -> { iff(q, (p && !q) || (!p && q)) && r });

// giving it both (you can give it as many as you want) let table: TableStruct = truthtable!(|p, q, r| => { compoundproposition, inlinecompoundproposition -> { iff(q, (p && !q) || (!p && q)) && r } });

assert!(printstdout(table).isok()); ```

Outputs:

text +-------+-------+-------+----------------------+-----------------------------+ | p | q | r | compound_proposition | inline_compound_proposition | +-------+-------+-------+----------------------+-----------------------------+ | true | true | true | false | false | +-------+-------+-------+----------------------+-----------------------------+ | true | true | false | false | false | +-------+-------+-------+----------------------+-----------------------------+ | true | false | true | false | false | +-------+-------+-------+----------------------+-----------------------------+ | true | false | false | false | false | +-------+-------+-------+----------------------+-----------------------------+ | false | true | true | true | true | +-------+-------+-------+----------------------+-----------------------------+ | false | true | false | false | false | +-------+-------+-------+----------------------+-----------------------------+ | false | false | true | true | true | +-------+-------+-------+----------------------+-----------------------------+ | false | false | false | false | false | +-------+-------+-------+----------------------+-----------------------------+

printtruthtable! macro

```rust use propositional_logic::prelude::*;

let compound_proposition = |p, q| -> bool { iff(q, p) };

// giving it a function (any function with boolean input and output works, technically) printtruthtable!(|p, q| => compoundproposition); println!(); // giving it an inline proposition (similar to a closure) printtruthtable!(|p| => inlinecompoundproposition -> { not(p) }); println!(); // giving it both (you can give it as many as you want, but every item must have a comma at the end (even the last one)) printtruthtable!(|p,q| => { compoundproposition, inlinecompoundproposition -> { not(p) }, }); ```

Output:

```text +-------+-------+----------------------+ | p | q | compound_proposition | +-------+-------+----------------------+ | true | true | true | +-------+-------+----------------------+ | true | false | false | +-------+-------+----------------------+ | false | true | false | +-------+-------+----------------------+ | false | false | true | +-------+-------+----------------------+

+-------+-----------------------------+ | p | inlinecompoundproposition | +-------+-----------------------------+ | true | false | +-------+-----------------------------+ | false | true | +-------+-----------------------------+

+-------+-------+----------------------+-----------------------------+ | p | q | compoundproposition | inlinecompound_proposition | +-------+-------+----------------------+-----------------------------+ | true | true | true | false | +-------+-------+----------------------+-----------------------------+ | true | false | false | false | +-------+-------+----------------------+-----------------------------+ | false | true | false | true | +-------+-------+----------------------+-----------------------------+ | false | false | true | true | +-------+-------+----------------------+-----------------------------+ ```