This directory contains comprehensive Jupyter notebooks demonstrating the TensorLogic Python API.
# Install TensorLogic Python bindings
cd crates/pytensorlogic
maturin develop
# Install tutorial dependencies
pip install jupyter matplotlib numpy
cd crates/pytensorlogic/tutorials
jupyter notebook
Level: Beginner Duration: 45-60 minutes Topics:
- Basic logical expressions (predicates, AND, OR, NOT)
- Compilation and execution workflow
- Compilation strategies (soft, hard, fuzzy, probabilistic)
- Quantifiers (EXISTS, FORALL)
- Arithmetic operations (add, sub, mul, div)
- Comparison operations (eq, lt, gt, lte, gte)
- Conditional expressions (IF-THEN-ELSE)
- Complex nested expressions (De Morgan's laws, implication)
- Adapter types (DomainInfo, PredicateInfo, SymbolTable, CompilerContext)
- Practical example: Social network reasoning
Learning Outcomes:
- Understand the TensorLogic compilation model
- Create and execute logical expressions
- Choose appropriate compilation strategies
- Visualize results with matplotlib
Level: Advanced Duration: 60-90 minutes Topics:
- Multi-arity predicates (binary, ternary, n-ary)
- Relational reasoning (transitive closure, path queries)
- Nested quantifiers (double, triple quantification)
- Performance optimization and benchmarking
- Graph inspection and analysis
- Strategy selection guide with use cases
- Integration patterns (iterative reasoning, multi-rule systems)
- Error handling and debugging techniques
- Best practices and performance tips
- Type safety patterns
Learning Outcomes:
- Master complex relational queries
- Optimize performance for production use
- Build robust integration pipelines
- Debug compilation and execution issues
- Apply best practices for maintainable code
Each notebook follows this structure:
- Setup - Import dependencies and verify installation
- Conceptual Introduction - Explain the topic with examples
- Code Examples - Executable code demonstrating features
- Visualizations - Plots and diagrams for understanding
- Practice - Exercises and challenges (where applicable)
- Summary - Key takeaways and next steps
jupyter notebook
Open the desired notebook and execute cells interactively.
jupyter nbconvert --to notebook --execute 01_getting_started.ipynb
This executes the notebook and saves the output.
jupyter nbconvert --to python 01_getting_started.ipynb
python 01_getting_started.py
Converts the notebook to a Python script for non-interactive execution.
- Execute cells in order - Notebooks have state, cells depend on previous execution
- Experiment - Modify examples to test understanding
- Visualize - Use matplotlib to understand tensor operations
- Debug - Use the debug helpers provided in advanced tutorials
- Read tests - The
tests/directory has additional examples - Ask questions - File issues on GitHub for clarification
Solution:
cd crates/pytensorlogic
maturin develop
Solution: Ensure you have Rust toolchain installed:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Solution: Install kernel dependencies:
pip install ipykernel
python -m ipykernel install --user
Solution: For notebook:
%matplotlib inline
For JupyterLab:
pip install jupyterlab
- API Reference: See
pytensorlogic.pyifor complete type signatures - Test Suite:
tests/directory for comprehensive usage examples - Examples:
examples/directory for standalone demonstrations - Documentation:
README.mdandCLAUDE.mdin repository root - Paper: TensorLogic research paper (link in main README)
Found an error or have a suggestion? Please:
- Check existing issues on GitHub
- File a new issue with details
- Submit a pull request with fixes/improvements
We welcome contributions to improve these tutorials!
These tutorials are part of the TensorLogic project and are licensed under Apache-2.0.
Last Updated: 2025-11-04 Maintainer: COOLJAPAN ecosystem Feedback: https://github.com/cool-japan/tensorlogic/issues