| Crates.io | tensorlogic-cli |
| lib.rs | tensorlogic-cli |
| version | 0.1.0-alpha.2 |
| created_at | 2025-11-07 23:13:56.636551+00 |
| updated_at | 2026-01-03 21:11:23.900826+00 |
| description | TensorLogic command-line interface and library for compiling logical expressions to tensor graphs |
| homepage | https://github.com/cool-japan/tensorlogic |
| repository | https://github.com/cool-japan/tensorlogic |
| max_upload_size | |
| id | 1922329 |
| size | 640,130 |
Command-line interface for TensorLogic compilation
A comprehensive command-line tool for compiling logical expressions to tensor graphs using TensorLogic.
.tensorlogicrccargo install tensorlogic-cli
git clone https://github.com/cool-japan/tensorlogic.git
cd tensorlogic
cargo install --path crates/tensorlogic-cli
cargo build -p tensorlogic-cli --release
# Binary at target/release/tensorlogic
tensorlogic "knows(x, y)"
tensorlogic 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
# expressions.txt contains one expression per line
tensorlogic batch expressions.txt
tensorlogic watch my_expression.tl
tensorlogic [OPTIONS] <INPUT>
tensorlogic <SUBCOMMAND>
| 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 |
repl - Interactive REPLStart an interactive Read-Eval-Print Loop for exploring TensorLogic.
tensorlogic repl
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 historybatch - Batch ProcessingProcess multiple expressions from files (one expression per line).
tensorlogic batch file1.txt file2.txt
Features:
# prefix)watch - File WatchingWatch a file and recompile on changes.
tensorlogic watch expression.tl
Features:
completion - Shell CompletionGenerate shell completion scripts.
# Bash
tensorlogic completion bash > /etc/bash_completion.d/tensorlogic
# Zsh
tensorlogic completion zsh > ~/.zsh/completion/_tensorlogic
# Fish
tensorlogic completion fish > ~/.config/fish/completions/tensorlogic.fish
# PowerShell
tensorlogic completion powershell > tensorlogic.ps1
config - Configuration ManagementManage configuration files.
# Show current configuration
tensorlogic config show
# Show config file path
tensorlogic config path
# Initialize default config
tensorlogic config init
# Edit configuration
tensorlogic config edit
TensorLogic CLI supports persistent configuration via .tensorlogicrc (TOML format).
Search order:
TENSORLOGIC_CONFIG environment variable.tensorlogicrc in current directory.tensorlogicrc in home directoryExample configuration:
# Default compilation strategy
strategy = "soft_differentiable"
# Enable colored output
colored = true
# Enable validation by default
validate = false
# Default domains
[domains]
Person = 100
City = 50
# REPL settings
[repl]
prompt = "tensorlogic> "
history_file = ".tensorlogic_history"
max_history = 1000
auto_save = true
# Watch mode settings
[watch]
debounce_ms = 500
clear_screen = true
show_timestamps = true
tensorlogic config init
Direct expression input with enhanced syntax:
tensorlogic "knows(x, y) AND likes(y, z)"
Supported syntax:
pred(x, y, ...)AND (&, &&, β§), OR (|, ||, β¨), NOT (~, !, Β¬), IMPLIES (->, =>, β)EXISTS x IN Domain. expr (β), FORALL x IN Domain. expr (β)+, -, * (Γ), / (Γ·)= (==), <, >, <= (β€), >= (β₯), != (β )IF cond THEN x ELSE y(...) for groupingExamples:
# Basic predicate
tensorlogic "person(x)"
# Logical operations
tensorlogic "p(x) AND q(y) OR r(z)"
# Quantifiers
tensorlogic "EXISTS x IN Person. knows(x, alice)"
tensorlogic "FORALL x IN Person. likes(x, pizza)"
# Arithmetic
tensorlogic "age(x) + 10"
# Comparisons
tensorlogic "age(x) > 18"
# Conditional
tensorlogic "IF age(x) >= 18 THEN adult(x) ELSE child(x)"
# Complex expression
tensorlogic "(p(x) OR q(y)) AND (r(z) -> s(w))"
tensorlogic --input-format json expression.json
{
"And": {
"left": {
"Pred": {
"name": "knows",
"args": [{"Var": "x"}, {"Var": "y"}]
}
},
"right": {
"Pred": {
"name": "likes",
"args": [{"Var": "y"}, {"Var": "z"}]
}
}
}
}
tensorlogic --input-format yaml expression.yaml
And:
left:
Pred:
name: knows
args:
- Var: x
- Var: y
right:
Pred:
name: likes
args:
- Var: y
- Var: z
echo '{"Pred": {"name": "test", "args": []}}' | tensorlogic --input-format json -
Human-readable graph structure:
tensorlogic "knows(x, y)" --output-format graph
Generate Graphviz DOT for visualization:
tensorlogic "knows(x, y)" --output-format dot > graph.dot
dot -Tpng graph.dot -o graph.png
Machine-readable JSON output:
tensorlogic "knows(x, y)" --output-format json
Graph statistics and metrics:
tensorlogic "knows(x, y) AND likes(y, z)" --output-format stats
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
Choose from 6 preset strategies:
For neural network training with smooth gradients:
tensorlogic --strategy soft_differentiable "p AND q"
For discrete Boolean logic:
tensorlogic --strategy hard_boolean "p AND q"
GΓΆdel fuzzy logic (min/max operations):
tensorlogic --strategy fuzzy_godel "p AND q"
Product fuzzy logic (probabilistic):
tensorlogic --strategy fuzzy_product "p AND q"
Εukasiewicz fuzzy logic (bounded):
tensorlogic --strategy fuzzy_lukasiewicz "p AND q"
Probabilistic interpretation:
tensorlogic --strategy probabilistic "p AND q"
Define domains for variables:
tensorlogic --domain Person:100 --domain City:50 "lives_in(x, c)"
Multiple domains:
tensorlogic \
--domain Person:100 \
--domain Location:50 \
--domain Event:20 \
"attends(p, e) AND located_at(e, l)"
Enable detailed analysis with --analyze:
tensorlogic "complex(expression)" --analyze
Output includes:
Enable graph validation:
tensorlogic "knows(x, y)" --validate
Checks:
Enable detailed debug output:
tensorlogic "knows(x, y)" --debug
Shows:
tensorlogic "knows(alice, bob)"
tensorlogic "knows(x, y) AND likes(y, z)"
tensorlogic --domain Person:100 "EXISTS x IN Person. knows(x, bob)"
tensorlogic "knows(x, y) -> likes(x, y)"
tensorlogic "age(x) + 10 > 30"
tensorlogic "IF age(x) >= 18 THEN adult(x) ELSE child(x)"
tensorlogic "knows(x, y) AND likes(y, z)" \
--output-format dot \
--validate > graph.dot
dot -Tpng graph.dot -o graph.png
tensorlogic \
"FORALL x IN Person. (knows(x, y) -> likes(x, y))" \
--domain Person:100 \
--strategy fuzzy_godel \
--output-format stats \
--analyze \
--validate
cat > expressions.txt << EOF
knows(x, y)
likes(y, z)
knows(x, y) AND likes(y, z)
EXISTS x. knows(x, bob)
FORALL x. person(x) -> mortal(x)
EOF
tensorlogic batch expressions.txt
tensorlogic repl
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
Generate PNG visualization:
tensorlogic "knows(x, y)" --output-format dot | dot -Tpng -o graph.png
Extract tensor count:
tensorlogic "knows(x, y)" --output-format json | jq '.tensors | length'
#!/bin/bash
EXPR="knows(x, y) AND likes(y, z)"
if tensorlogic "$EXPR" --output-format stats --validate --quiet; then
echo "β Compilation successful"
else
echo "β Compilation failed"
exit 1
fi
.PHONY: compile watch
compile:
tensorlogic expression.tl --validate --analyze
watch:
tensorlogic watch expression.tl
Make sure ~/.cargo/bin is in your PATH:
export PATH="$HOME/.cargo/bin:$PATH"
Use --debug to see detailed parsing information:
tensorlogic "your expression" --debug
Check free variables and domains:
tensorlogic "EXISTS x. p(x, y)" \
--domain Domain:10 \
--debug \
--validate
Show current configuration:
tensorlogic config show
Show config file path:
tensorlogic config path
Reinitialize configuration:
tensorlogic config init
| Variable | Description |
|---|---|
TENSORLOGIC_CONFIG |
Custom config file path |
EDITOR |
Editor for config edit command (default: vi) |
Example:
export TENSORLOGIC_CONFIG=~/.config/tensorlogic.toml
export EDITOR=nano
tensorlogic config edit
-q) in scripts--no-color) for log files--analyze) to identify bottleneckscargo build -p tensorlogic-cli
cargo test -p tensorlogic-cli
cargo run -p tensorlogic-cli -- --help
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
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
Licensed under Apache 2.0 License. See LICENSE for details.
Part of the COOLJAPAN Ecosystem
For questions and support, please open an issue on GitHub.