1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
//! TensorLogic CLI Library
//!
//! **Version**: 0.1.0-alpha.2 | **Status**: Production Ready
//!
//! This library provides programmatic access to the TensorLogic CLI functionality,
//! allowing you to use the parser, executor, optimizer, and other components
//! directly from Rust code without shelling out to the command-line interface.
//!
//! # Features
//!
//! - **Expression Parsing**: Parse logical expressions into TensorLogic IR
//! - **Compilation**: Compile expressions to einsum graphs with various strategies
//! - **Execution**: Execute compiled graphs with multiple backends
//! - **Optimization**: Apply optimization passes to improve performance
//! - **Analysis**: Analyze graph complexity and computational costs
//! - **Benchmarking**: Measure compilation and execution performance
//! - **Format Conversion**: Convert between different input/output formats
//!
//! # Quick Start
//!
//! ```rust,no_run
//! use tensorlogic_cli::{parser, CompilationContext};
//! use tensorlogic_compiler::{compile_to_einsum_with_context, CompilationConfig};
//!
//! // Parse an expression
//! let expr = parser::parse_expression("pred1(x) AND pred2(x, y)").unwrap();
//!
//! // Create compiler context with configuration
//! let config = CompilationConfig::soft_differentiable();
//! let mut ctx = CompilationContext::with_config(config);
//! ctx.add_domain("D", 100);
//!
//! // Compile to einsum graph
//! let graph = compile_to_einsum_with_context(&expr, &mut ctx).unwrap();
//!
//! // Execute the graph (requires appropriate setup)
//! // let result = executor::execute_graph(&graph, &backend_config).unwrap();
//! ```
//!
//! # Module Overview
//!
//! - [`parser`]: Parse logical expressions from strings
//! - [`executor`]: Execute compiled einsum graphs
//! - [`optimize`]: Apply optimization passes
//! - [`benchmark`]: Performance benchmarking utilities
//! - [`analysis`]: Graph analysis and metrics
//! - [`conversion`]: Format conversion utilities
//! - `config`: Configuration management (internal)
//! - [`output`]: Output formatting and colors
//!
//! # Library Mode Benefits
//!
//! Using TensorLogic as a library instead of a CLI provides:
//!
//! - **Better Performance**: No process spawning overhead
//! - **Type Safety**: Compile-time error checking
//! - **Integration**: Direct embedding in Rust applications
//! - **Flexibility**: Fine-grained control over compilation and execution
//! - **Testing**: Easier unit and integration testing
//!
//! # Example: Full Compilation Pipeline
//!
//! ```rust,no_run
//! use tensorlogic_cli::{parser, analysis, CompilationContext};
//! use tensorlogic_compiler::{compile_to_einsum_with_context, CompilationConfig};
//!
//! // Parse expression
//! let expr = parser::parse_expression(
//! "EXISTS x IN Person. (pred1(x) AND pred2(x, y))"
//! ).unwrap();
//!
//! // Setup compilation context
//! let config = CompilationConfig::soft_differentiable();
//! let mut ctx = CompilationContext::with_config(config);
//! ctx.add_domain("Person", 100);
//! ctx.add_domain("D", 100);
//!
//! // Compile
//! let graph = compile_to_einsum_with_context(&expr, &mut ctx).unwrap();
//!
//! // Analyze complexity
//! let metrics = analysis::GraphMetrics::analyze(&graph);
//! println!("Graph has {} tensors and {} nodes", metrics.tensor_count, metrics.node_count);
//! println!("Estimated FLOPs: {}", metrics.estimated_flops);
//! ```
// Re-export core TensorLogic types for convenience
pub use tensorlogic_adapters;
pub use tensorlogic_compiler;
pub use tensorlogic_infer;
pub use tensorlogic_ir;
pub use tensorlogic_scirs_backend;
// Export public modules
// Re-export config types (but keep internal config logic private)
pub use ;
// Internal modules (not part of public API)
pub
pub
pub
pub
pub
/// Type alias for compilation context used throughout the library
pub type CompilationContext = CompilerContext;
/// Type alias for einsum graphs
pub type EinsumGraph = EinsumGraph;
/// Type alias for TensorLogic expressions
pub type TLExpr = TLExpr;
/// Library result type
pub type Result<T> = Result;
/// Library version
pub const VERSION: &str = env!;
/// Library name
pub const NAME: &str = env!;