| Crates.io | raa_tt |
| lib.rs | raa_tt |
| version | 0.9.1 |
| created_at | 2023-11-01 18:21:53.129283+00 |
| updated_at | 2025-12-18 18:00:15.603867+00 |
| description | Proves sentences of propositional calculus |
| homepage | |
| repository | https://github.com/jsinger67/raa_tt |
| max_upload_size | |
| id | 1021485 |
| size | 249,609 |
A sophisticated Rust library and CLI tool for proving sentences of propositional calculus using the analytic tableaux method (truth trees). This implementation provides both a high-performance library API and an intuitive command-line interface for logical reasoning and educational purposes.
๐ฌ Advanced Proof Engine
๐ Truth Table Generation
๐ฏ Dual Interface
โก High Performance
๐งฎ Rich Grammar Support
๐ Developer-Friendly
# Install the tool
cargo install raa_tt
# Prove a simple tautology
raa_tt -s "p | !p"
# Analyze a complex formula with truth table
raa_tt -s "((p -> q) & (r -> s) & (p | r)) -> (q | s)" -t
# Process formulas from a file
raa_tt -f formula.txt -q
use raa_tt::{
prover::{Prover, ProveResult},
proposition::Proposition,
raa_tt_parser::parse,
raa_tt_grammar::RaaTtGrammar,
};
// Parse and prove a formula
let mut grammar = RaaTtGrammar::new();
parse("p -> (q -> p)", "example", &mut grammar)?;
let proposition: Proposition = (&grammar.raa_tt.unwrap().raa_tt_list[0].biconditional).into();
let prover = Prover::new();
let result = prover.prove(&proposition)?;
match result {
ProveResult::Proven => println!("Tautology: Always true"),
ProveResult::Falsified => println!("Contradiction: Always false"),
ProveResult::Contingent => println!("Contingent: Depends on variables"),
_ => unreachable!(),
}
From crates.io (Recommended):
cargo install raa_tt
From source:
git clone https://github.com/jsinger67/raa_tt.git
cd raa_tt
cargo install --path .
Add to your Cargo.toml:
[dependencies]
raa_tt = "0.8.0"
# Clone repository
git clone https://github.com/jsinger67/raa_tt.git
cd raa_tt
# Run tests
cargo test
# Run benchmarks
cargo bench
# Build documentation
cargo doc --open
The raa_tt parser supports a rich grammar for propositional logic expressions with standard operator precedence.
| Operator | Symbol | Description | Precedence | Example |
|---|---|---|---|---|
| Negation | ! |
NOT | 1 (highest) | !p |
| Conjunction | & |
AND | 2 | p & q |
| Disjunction | | |
OR | 3 | p | q |
| Implication | -> |
IF...THEN | 4 | p -> q |
| Biimplication | <-> |
IF AND ONLY IF | 5 (lowest) | p <-> q |
Variables: Start with lowercase letter, followed by letters, digits, or underscores
p, q1, var_name, proposition_aP, 1var, -nameParentheses: Use () for grouping and overriding precedence
(p | q) & r vs p | (q & r)Comments: Line comments start with //
Basic Operations:
p // Simple atom
!p // Negation
p & q // Conjunction
p | q // Disjunction
p -> q // Implication
p <-> q // Biimplication
Complex Expressions:
// Modus Ponens
(p & (p -> q)) -> q
// Law of Excluded Middle
p | !p
// De Morgan's Law
!(p & q) <-> (!p | !q)
// Complex nested formula
((p -> q) & (q -> r)) -> (p -> r)
Precedence Examples:
!p & q // Equivalent to (!p) & q
p | q & r // Equivalent to p | (q & r)
p -> q | r // Equivalent to p -> (q | r)
p & q -> r // Equivalent to (p & q) -> r
p <-> q -> r // Equivalent to p <-> (q -> r)
# Test a tautology
raa_tt -s "p -> p"
# Output: p -> p is Logically True
# Test a contradiction
raa_tt -s "p & !p"
# Output: p & !p is Logically False
# Test a contingent formula
raa_tt -s "p & q"
# Output: p & q is Contingent
# Generate truth table for a formula
raa_tt -s "p -> q" -t
# Output includes:
# (p -> q) is Contingent
# p | q | (p -> q) |
# -------------------
# F | F | T |
# F | T | T |
# T | F | F |
# T | T | T |
# Create a file with formulas
echo "p | !p" > formulas.txt
echo "(p -> q) & p -> q" >> formulas.txt
# Process the file
raa_tt -f formulas.txt
# Quiet mode (minimal output)
raa_tt -f formulas.txt -q
# Complex formula with debugging
RUST_LOG=raa_tt=debug raa_tt -s "((p -> q) & (q -> r)) -> (p -> r)"
# Batch processing with truth tables
raa_tt -f complex_formulas.txt -t > results.txt
use raa_tt::{
prover::{Prover, ProveResult},
proposition::Proposition,
conjunction::Conjunction,
implication::Implication,
negation::Negation,
};
// Create propositions programmatically
let modus_ponens = Proposition::Implication(Implication {
left: Box::new(Proposition::Conjunction(Conjunction {
left: Box::new("p".into()),
right: Box::new(Proposition::Implication(Implication {
left: Box::new("p".into()),
right: Box::new("q".into()),
})),
})),
right: Box::new("q".into()),
});
let prover = Prover::new();
let result = prover.prove(&modus_ponens)?;
assert_eq!(result, ProveResult::Proven);
use raa_tt::{
raa_tt_parser::parse,
raa_tt_grammar::RaaTtGrammar,
prover::Prover,
};
fn prove_formula(formula: &str) -> Result<ProveResult, Box<dyn std::error::Error>> {
let mut grammar = RaaTtGrammar::new();
parse(formula, &"input".into(), &mut grammar)?;
let proposition = (&grammar.raa_tt.unwrap().raa_tt_list[0].biconditional).into();
let prover = Prover::new();
Ok(prover.prove(&proposition)?)
}
// Usage
let result = prove_formula("(p -> q) & p -> q")?;
println!("Formula is: {}", result);
use raa_tt::{
table_generator::TableGenerator,
proposition::Proposition,
conjunction::Conjunction,
};
let proposition = Proposition::Conjunction(Conjunction {
left: Box::new("p".into()),
right: Box::new("q".into()),
});
let generator = TableGenerator::new();
let truth_table = generator.generate_truth_table(&proposition)?;
println!("{}", truth_table);
use raa_tt::errors::{RaaError, Result};
fn safe_prove(formula: &str) -> Result<ProveResult> {
// ... parsing and proving logic
match result {
Err(RaaError::TooManyVariables { current, max, .. }) => {
eprintln!("Too many variables: {} (max: {})", current, max);
Err(result.unwrap_err())
},
Err(RaaError::UndefinedVariable { name }) => {
eprintln!("Undefined variable: {}", name);
Err(result.unwrap_err())
},
_ => result,
}
}
Propositional logic is a branch of mathematical logic that deals with propositions and their relationships through logical connectives. A proposition is a declarative statement that is either true or false.
Key Concepts:
The truth tree method is a decision procedure for propositional logic that systematically explores logical relationships by:
Transformation Rules:
| Formula Type | Decomposition |
|---|---|
| A โง B | Add A and B to current branch |
| A โจ B | Create two branches: one with A, one with B |
| A โ B | Create two branches: one with ยฌA, one with B |
| A โ B | Create two branches: (AโงB) and (ยฌAโงยฌB) |
| ยฌ(A โง B) | Add ยฌA and ยฌB to current branch |
| ยฌ(A โจ B) | Create two branches: one with ยฌA, one with ยฌB |
| ยฌยฌA | Add A to current branch |
The raa_tt library is built around several key components:
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ Parser โ โ Prover โ โ TableGenerator โ
โ โ โ โ โ โ
โ โข Grammar โโโโโถโ โข Truth Trees โ โ โข Truth Tables โ
โ โข Tokenization โ โ โข Branch Logic โ โ โข Enumeration โ
โ โข AST Building โ โ โข Contradiction โ โ โข Formatting โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ โ โ
โผ โผ โผ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ Proposition โ โ ProveResult โ โ TruthTable โ
โ โ โ โ โ โ
โ โข Atoms โ โ โข Proven โ โ โข Variables โ
โ โข Operators โ โ โข Falsified โ โ โข Rows โ
โ โข Expressions โ โ โข Contingent โ โ โข Evaluation โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
Time Complexity:
Prover: O(2^n) worst case, where n is the number of variables
Truth Table: O(2^n ร m) where m is formula evaluation complexity
Space Complexity:
The library provides comprehensive error handling through the RaaError enum:
pub enum RaaError {
VoidExpression, // Internal logic error
TooManyVariables { ... }, // Variable limit exceeded
UndefinedVariable { name }, // Reference to undefined variable
FormatError { source }, // Display/formatting error
}
raa_tt includes a comprehensive benchmark suite to monitor performance and detect regressions. See BENCHMARKS.md for detailed information.
Run benchmarks:
# All benchmarks
cargo bench
# Specific components
cargo bench --bench prover_benchmarks
cargo bench --bench table_generator_benchmarks
Prover Performance:
Truth Table Performance:
Memory Limits:
-q flag for batch processingProver: Main proving engine
impl Prover {
pub fn new() -> Self // Create new prover
pub fn prove(&self, proposition: &Proposition) -> Result<ProveResult> // Prove formula
}
ProveResult: Proving outcomes
pub enum ProveResult {
Proven, // Tautology (always true)
Falsified, // Contradiction (always false)
Contingent, // Depends on variable assignments
}
Proposition: Logical expressions
pub enum Proposition {
Atom(String), // Propositional variable
Negation(Negation), // ยฌP
Conjunction(Conjunction), // P โง Q
Disjunction(Disjunction), // P โจ Q
Implication(Implication), // P โ Q
BiImplication(BiImplication), // P โ Q
Void, // Internal use
}
TableGenerator: Truth table creation
impl TableGenerator {
pub fn new() -> Self // Create generator
pub fn generate_truth_table(&self, proposition: &Proposition) -> Result<TruthTable>
}
use raa_tt::{raa_tt_parser::parse, raa_tt_grammar::RaaTtGrammar};
let mut grammar = RaaTtGrammar::new();
parse(input, &file_name, &mut grammar)?;
let propositions = grammar.raa_tt.unwrap().raa_tt_list;
For complete API documentation, run:
cargo doc --open
raa_tt/
โโโ src/
โ โโโ lib.rs # Library root
โ โโโ prover.rs # Truth tree prover
โ โโโ proposition.rs # Logical expressions
โ โโโ table_generator.rs # Truth table generator
โ โโโ truth_table.rs # Truth table representation
โ โโโ errors.rs # Error types
โ โโโ raa_tt_parser.rs # Generated parser
โ โโโ raa_tt_grammar.rs # Grammar implementation
โ โโโ conjunction.rs # AND operator
โ โโโ disjunction.rs # OR operator
โ โโโ implication.rs # IMPLIES operator
โ โโโ bi_implication.rs # IFF operator
โ โโโ negation.rs # NOT operator
โ โโโ bin/
โ โโโ raa_tt/
โ โโโ main.rs # CLI entry point
โ โโโ arguments.rs # CLI argument parsing
โโโ tests/
โ โโโ integration_tests.rs # Integration tests
โโโ benches/
โ โโโ prover_benchmarks.rs # Prover performance tests
โ โโโ table_generator_benchmarks.rs # Table performance tests
โโโ raa_tt.par # Grammar definition
โโโ build.rs # Build script
โโโ README.md # This file
# Clone repository
git clone https://github.com/jsinger67/raa_tt.git
cd raa_tt
# Build library
cargo build --release
# Build CLI tool
cargo build --release --bin raa_tt
# Install locally
cargo install --path .
# Unit tests
cargo test
# Integration tests
cargo test --test integration_tests
# Documentation tests
cargo test --doc
# All tests with output
cargo test -- --nocapture
The grammar is defined in raa_tt.par and processed by the Parol parser generator:
# Regenerate parser (if modifying grammar)
parol -f ./raa_tt.par -e ./raa_tt-exp.par -p ./src/raa_tt_parser.rs \
-a ./src/raa_tt_grammar_trait.rs -t RaaTtGrammar -m raa_tt_grammar \
--trim --disable-recovery --minbox
Enable detailed logging to explore the algorithm:
PowerShell:
$env:RUST_LOG="raa_tt=trace,raa_tt::raa_tt_grammar_trait=error"
raa_tt -s "your_formula_here"
Bash/Zsh:
RUST_LOG="raa_tt=debug" raa_tt -s "your_formula_here"
Log Levels:
error: Critical errors onlywarn: Warnings and errorsinfo: General informationdebug: Detailed debugging infotrace: Exhaustive algorithm traces"Too many variables for truth table generation"
Error: Too many variables for truth table generation.
Current: 17 variables, Maximum allowed: 16 variables.
Solution: Use the prover instead of truth tables for complex formulas, or simplify the expression.
"Variable X not defined"
Error: Variable X not defined
Solution: Ensure all variables use lowercase letters and valid naming conventions.
Parser errors
Error occurred: Parse error at line 1, column 5
Solution: Check grammar syntax, operator precedence, and parentheses matching.
Slow proving for complex formulas:
Memory issues with truth tables:
cargo doc --opentests/ directoryRUST_LOG=debugWe welcome contributions! Here's how to get started:
Fork and clone the repository
Set up development environment:
git clone https://github.com/your-username/raa_tt.git
cd raa_tt
cargo build
cargo test
Install development tools:
rustup component add rustfmt clippy
cargo install cargo-tarpaulin # For coverage
Code Style:
cargo fmt before committingcargo clippy warningsPull Request Process:
git checkout -b feature/your-featurecargo testcargo benchAreas for Contribution:
Please be respectful and constructive in all interactions. We're committed to providing a welcoming environment for all contributors.
This project is licensed under either of:
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Changelog: See CHANGELOG.md for version history and release notes.
Performance Benchmarks: Detailed benchmark information available in BENCHMARKS.md.