TensorLogic CLI
Command-line interface for TensorLogic compilation
A comprehensive command-line tool for compiling logical expressions to tensor graphs using TensorLogic.
Features
- π Multiple Modes: Interactive REPL, batch processing, watch mode
- π Rich Input Formats: Expression strings, JSON, YAML, stdin
- π Multiple Output Formats: Graph, DOT, JSON, statistics
- βοΈ 6 Compilation Strategies: Differentiable, Boolean, fuzzy logic variants
- π¨ Colored Output: Beautiful terminal output with status indicators
- π Graph Analysis: Complexity metrics, FLOP estimation, memory analysis
- π Configuration Files: Persistent settings via
.tensorlogicrc - π File Watching: Auto-recompilation on file changes
- π¦ Batch Processing: Process multiple expressions with progress bars
- π Shell Completion: Bash, Zsh, Fish, PowerShell support
- π― Enhanced Parser: Arithmetic, comparisons, conditionals, Unicode operators
Installation
From crates.io
From source
Development build
# Binary at target/release/tensorlogic
Quick Start
Basic Compilation
Interactive REPL
TensorLogic Interactive REPL
Type '.help' for available commands, '.exit' to quit
tensorlogic> knows(x, y) AND likes(y, z)
β Compilation successful
3 tensors, 3 nodes, depth 2
Batch Processing
# expressions.txt contains one expression per line
Watch Mode
Usage
Command Structure
Main Options
| Option | Description |
|---|---|
-f, --input-format <FORMAT> |
Input format: expr, json, yaml (default: expr) |
-o, --output <FILE> |
Output file (default: stdout) |
-F, --output-format <FORMAT> |
Output format: graph, dot, json, stats (default: graph) |
-s, --strategy <STRATEGY> |
Compilation strategy |
-d, --domain <NAME:SIZE> |
Define domain (can be repeated) |
--validate |
Enable graph validation |
--debug |
Enable debug output |
-a, --analyze |
Show graph analysis metrics |
-q, --quiet |
Quiet mode (minimal output) |
--no-color |
Disable colored output |
--no-config |
Don't load configuration file |
Subcommands
repl - Interactive REPL
Start an interactive Read-Eval-Print Loop for exploring TensorLogic.
REPL Commands:
.help- Show help.exit- Exit REPL.clear- Clear screen.context- Show compiler context.domain <name> <size>- Add domain.strategy [name]- Show/set strategy.validate- Toggle validation.debug- Toggle debug mode.history- Show command history
batch - Batch Processing
Process multiple expressions from files (one expression per line).
Features:
- Progress bar with elapsed time
- Summary statistics (successes/failures)
- Line-by-line error reporting
- Comments support (
#prefix)
watch - File Watching
Watch a file and recompile on changes.
Features:
- Auto-recompilation on file save
- Debounced updates (configurable)
- Clear screen on reload (configurable)
- Timestamp display
completion - Shell Completion
Generate shell completion scripts.
# Bash
# Zsh
# Fish
# PowerShell
config - Configuration Management
Manage configuration files.
# Show current configuration
# Show config file path
# Initialize default config
# Edit configuration
Configuration File
TensorLogic CLI supports persistent configuration via .tensorlogicrc (TOML format).
Search order:
TENSORLOGIC_CONFIGenvironment variable.tensorlogicrcin current directory.tensorlogicrcin home directory
Example configuration:
# Default compilation strategy
= "soft_differentiable"
# Enable colored output
= true
# Enable validation by default
= false
# Default domains
[]
= 100
= 50
# REPL settings
[]
= "tensorlogic> "
= ".tensorlogic_history"
= 1000
= true
# Watch mode settings
[]
= 500
= true
= true
Initialize Configuration
Input Formats
1. Expression String (Default)
Direct expression input with enhanced syntax:
Supported syntax:
- Predicates:
pred(x, y, ...) - Logical:
AND(&,&&,β§),OR(|,||,β¨),NOT(~,!,Β¬),IMPLIES(->,=>,β) - Quantifiers:
EXISTS x IN Domain. expr(β),FORALL x IN Domain. expr(β) - Arithmetic:
+,-,*(Γ),/(Γ·) - Comparisons:
=(==),<,>,<=(β€),>=(β₯),!=(β) - Conditional:
IF cond THEN x ELSE y - Parentheses:
(...)for grouping
Examples:
# Basic predicate
# Logical operations
# Quantifiers
# Arithmetic
# Comparisons
# Conditional
# Complex expression
2. JSON Input
3. YAML Input
And:
left:
Pred:
name: knows
args:
- Var: x
- Var: y
right:
Pred:
name: likes
args:
- Var: y
- Var: z
4. Stdin Input
|
Output Formats
1. Graph (Default)
Human-readable graph structure:
2. DOT Format
Generate Graphviz DOT for visualization:
3. JSON
Machine-readable JSON output:
4. Statistics
Graph statistics and metrics:
Output:
Graph Statistics:
Tensors: 3
Nodes: 3
Inputs: 2
Outputs: 1
Depth: 2
Avg Fanout: 1.00
Operation Breakdown:
Einsum: 2
ElemBinary: 1
Estimated Complexity:
FLOPs: 6000
Memory: 24000 bytes
Compilation Strategies
Choose from 6 preset strategies:
1. Soft Differentiable (Default)
For neural network training with smooth gradients:
- AND: Element-wise product
- OR: Probabilistic sum
- NOT: Complement (1 - x)
2. Hard Boolean
For discrete Boolean logic:
- AND: Minimum
- OR: Maximum
- NOT: Complement
3. Fuzzy GΓΆdel
GΓΆdel fuzzy logic (min/max operations):
4. Fuzzy Product
Product fuzzy logic (probabilistic):
5. Fuzzy Εukasiewicz
Εukasiewicz fuzzy logic (bounded):
6. Probabilistic
Probabilistic interpretation:
Domain Definitions
Define domains for variables:
Multiple domains:
Graph Analysis
Enable detailed analysis with --analyze:
Output includes:
- Tensor and node counts
- Graph depth (longest path)
- Average fanout (outputs per node)
- Operation breakdown (Einsum, element-wise, reduction)
- Estimated FLOPs (computational cost)
- Estimated memory usage
Validation
Enable graph validation:
Checks:
- Free variable consistency
- Arity validation
- Type checking
- Graph structure validity
Debug Mode
Enable detailed debug output:
Shows:
- Parsed expression (AST)
- Compiler context (domains, strategies)
- Intermediate compilation steps
- Final graph structure
- Validation results
Examples
Example 1: Simple Predicate
Example 2: Logical Conjunction
Example 3: Quantifier
Example 4: Implication
Example 5: Arithmetic and Comparison
Example 6: Conditional Expression
Example 7: Visualization
Example 8: Complex Expression with Analysis
Example 9: Batch Processing with Progress
Example 10: Interactive REPL Session
tensorlogic> .domain Person 100
β Added domain 'Person' with size 100
tensorlogic> .strategy fuzzy_godel
β Strategy set to: fuzzy_godel
tensorlogic> EXISTS x IN Person. knows(x, alice)
β Compilation successful
2 tensors, 2 nodes, depth 2
tensorlogic> .history
1: .domain Person 100
2: .strategy fuzzy_godel
3: EXISTS x IN Person. knows(x, alice)
tensorlogic> .exit
Integration
With Graphviz
Generate PNG visualization:
|
With jq (JSON Processing)
Extract tensor count:
|
In Scripts
#!/bin/bash
EXPR="knows(x, y) AND likes(y, z)"
if ; then
else
fi
With Make
:
:
:
Troubleshooting
Command Not Found
Make sure ~/.cargo/bin is in your PATH:
Parsing Errors
Use --debug to see detailed parsing information:
Validation Failures
Check free variables and domains:
Configuration Issues
Show current configuration:
Show config file path:
Reinitialize configuration:
Environment Variables
| Variable | Description |
|---|---|
TENSORLOGIC_CONFIG |
Custom config file path |
EDITOR |
Editor for config edit command (default: vi) |
Example:
Performance Tips
- Use batch mode for multiple expressions
- Enable validation only when needed
- Use quiet mode (
-q) in scripts - Disable colors (
--no-color) for log files - Use analysis (
--analyze) to identify bottlenecks
Development
Building
Testing
Running from Source
Code Structure
src/
βββ main.rs - Main entry point and command routing
βββ cli.rs - Clap CLI definitions
βββ config.rs - Configuration file support
βββ parser.rs - Enhanced expression parser
βββ output.rs - Colored output formatting
βββ analysis.rs - Graph metrics and analysis
βββ repl.rs - Interactive REPL mode
βββ batch.rs - Batch processing
βββ watch.rs - File watching
βββ completion.rs - Shell completion generation
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
License
Licensed under Apache 2.0 License. See LICENSE for details.
See Also
- Main README: README.md
- Project Guide: CLAUDE.md
- Meta Crate: tensorlogic
- Compiler Documentation: tensorlogic-compiler
- IR Documentation: tensorlogic-ir
Resources
- Repository: https://github.com/cool-japan/tensorlogic
- Documentation: https://docs.rs/tensorlogic-cli
- Issues: https://github.com/cool-japan/tensorlogic/issues
Part of the COOLJAPAN Ecosystem
For questions and support, please open an issue on GitHub.