raa_tt - Propositional Logic Prover
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.
Table of Contents
- Features
- Quick Start
- Installation
- Grammar Reference
- Usage Examples
- Mathematical Background
- Algorithm & Architecture
- Performance
- API Documentation
- Development
- Troubleshooting
- Contributing
- License
Features
๐ฌ Advanced Proof Engine
- Analytic tableaux (truth tree) method for logical proving
- Systematic detection of tautologies, contradictions, and contingent formulas
- Efficient branch pruning and contradiction detection
๐ Truth Table Generation
- Complete truth table computation for verification
- Configurable variable limits (up to 16 variables)
- Memory-efficient implementation with safety checks
๐ฏ Dual Interface
- Library: Programmatic API for integration into Rust applications
- CLI Tool: User-friendly command-line interface with rich output
โก High Performance
- Optimized for complex logical formulas
- Comprehensive benchmark suite included
- Early contradiction detection for faster proving
๐งฎ Rich Grammar Support
- Complete propositional logic syntax
- Operator precedence following mathematical conventions
- Support for all standard logical connectives
๐ Developer-Friendly
- Extensive documentation with examples
- Detailed error handling and reporting
- Debug logging for algorithm exploration
Quick Start
CLI Usage
# 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
Library Usage
use ;
// Parse and prove a formula
let mut grammar = new;
parse?;
let proposition: Proposition = .into;
let prover = new;
let result = prover.prove?;
match result
Installation
As a CLI Tool
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 .
As a Library Dependency
Add to your Cargo.toml:
[]
= "0.8.0"
Development Setup
# 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
Grammar Reference
The raa_tt parser supports a rich grammar for propositional logic expressions with standard operator precedence.
Logical Operators
| 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 and Syntax
-
Variables: Start with lowercase letter, followed by letters, digits, or underscores
- Valid:
p,q1,var_name,proposition_a - Invalid:
P,1var,-name
- Valid:
-
Parentheses: Use
()for grouping and overriding precedence(p | q) & rvsp | (q & r)
-
Comments: Line comments start with
//
Grammar Examples
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)
Usage Examples
Command Line Interface
Basic Proving
# 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
Truth Table Generation
# 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 |
File Input
# 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
Advanced Usage
# 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
Library Usage
Basic Proving
use ;
// Create propositions programmatically
let modus_ponens = Implication;
let prover = new;
let result = prover.prove?;
assert_eq!;
Parsing Text Formulas
use ;
// Usage
let result = prove_formula?;
println!;
Truth Table Generation
use ;
let proposition = Conjunction;
let generator = new;
let truth_table = generator.generate_truth_table?;
println!;
Error Handling
use ;
Mathematical Background
Propositional Logic
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:
- Tautology: A formula that is always true regardless of variable assignments
- Contradiction: A formula that is always false regardless of variable assignments
- Contingent: A formula whose truth value depends on the specific variable assignments
Truth Trees (Analytic Tableaux)
The truth tree method is a decision procedure for propositional logic that systematically explores logical relationships by:
- Assumption: Starting with the negation of the formula to be proved
- Decomposition: Breaking complex formulas into simpler components
- Branching: Creating separate paths for disjunctive cases
- Closure: Identifying contradictions (P โง ยฌP) to close branches
- Resolution: Determining the formula's logical status
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 |
Algorithm & Architecture
Core Components
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 โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
Complexity Analysis
Time Complexity:
-
Prover: O(2^n) worst case, where n is the number of variables
- Many formulas resolve faster due to early contradiction detection
- Tautologies often prove quickly through systematic closure
-
Truth Table: O(2^n ร m) where m is formula evaluation complexity
- Guaranteed exponential growth with variable count
- 16-variable limit prevents excessive memory usage
Space Complexity:
- Prover: O(2^n) for tree structure in worst case
- Truth Table: O(2^n ร n) for complete table storage
Error Handling
The library provides comprehensive error handling through the RaaError enum:
Performance
Benchmark Suite
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
Performance Characteristics
Prover Performance:
- Simple propositions: Sub-millisecond
- Complex nested formulas: Milliseconds to seconds
- Worst-case scenarios: May exhibit exponential behavior
Truth Table Performance:
- 1-8 variables: Very fast (< 1ms to ~10ms)
- 9-12 variables: Moderate (10ms to ~100ms)
- 13-16 variables: Slower but acceptable (100ms to several seconds)
Memory Limits:
- Truth tables limited to 16 variables (65,536 rows)
- Automatic memory estimation and warnings
- Graceful error handling for exceeded limits
Optimization Tips
- Use the prover for large formulas: Truth trees often faster than truth tables
- Simplify complex expressions: Break down into smaller sub-formulas
- Leverage operator precedence: Reduce parentheses for cleaner expressions
- Enable quiet mode: Use
-qflag for batch processing
API Documentation
Core Types
Prover: Main proving engine
ProveResult: Proving outcomes
Proposition: Logical expressions
TableGenerator: Truth table creation
Parser API
use ;
let mut grammar = new;
parse?;
let propositions = grammar.raa_tt.unwrap.raa_tt_list;
For complete API documentation, run:
cargo doc --open
Development
Project Structure
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
Building from Source
# 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 .
Running Tests
# Unit tests
cargo test
# Integration tests
cargo test --test integration_tests
# Documentation tests
cargo test --doc
# All tests with output
cargo test -- --nocapture
Grammar Development
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
Debugging and Logging
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"
Log Levels:
error: Critical errors onlywarn: Warnings and errorsinfo: General informationdebug: Detailed debugging infotrace: Exhaustive algorithm traces
Troubleshooting
Common Issues
"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.
Performance Issues
Slow proving for complex formulas:
- Break down into smaller sub-expressions
- Use logical equivalences to simplify
- Check for deeply nested operators
Memory issues with truth tables:
- Reduce number of variables (< 13 recommended for interactive use)
- Use prover for logical validation instead of truth tables
- Consider SAT solvers for very large problems
Getting Help
- Check the documentation:
cargo doc --open - Review examples: See
tests/directory - Enable debug logging: Use
RUST_LOG=debug - File an issue: GitHub Issues
Contributing
We welcome contributions! Here's how to get started:
Development Setup
-
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
Contribution Guidelines
Code Style:
- Run
cargo fmtbefore committing - Fix all
cargo clippywarnings - Add tests for new functionality
- Update documentation for public APIs
Pull Request Process:
- Create a feature branch:
git checkout -b feature/your-feature - Make your changes with tests
- Run the full test suite:
cargo test - Run benchmarks if affecting performance:
cargo bench - Update documentation if needed
- Submit a pull request with clear description
Areas for Contribution:
- Performance optimizations
- Additional logical operators
- Enhanced error messages
- Documentation improvements
- Example programs
- Educational materials
Code of Conduct
Please be respectful and constructive in all interactions. We're committed to providing a welcoming environment for all contributors.
License
This project is licensed under either of:
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
at your option.
Contribution
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.
Credits
- Parol for the parser generator
Changelog: See CHANGELOG.md for version history and release notes.
Performance Benchmarks: Detailed benchmark information available in BENCHMARKS.md.