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
//! Expression optimization passes.
//!
//! This module provides various optimization passes for TLExpr expressions:
//!
//! - **Negation optimization**: Apply De Morgan's laws and eliminate double negations
//! - **Constant folding**: Evaluate constant expressions at compile time
//! - **Algebraic simplification**: Apply mathematical identities (x+0=x, x*1=x, etc.)
//! - **Strength reduction**: Replace expensive operations with cheaper equivalents
//! - **Distributivity**: Factor or expand expressions based on cost analysis
//! - **Quantifier optimization**: Hoist loop-invariant code, reorder quantifiers
//! - **Dead code elimination**: Remove unreachable code and simplify constant conditions
//! - **Complexity analysis**: Estimate computational cost and memory usage
//! - **Cost-based optimization**: Explore rewrites and select optimal execution plan
//! - **Pipeline**: Multi-pass optimization combining all passes intelligently
//!
//! # Quick Start
//!
//! For most use cases, use the unified optimization pipeline:
//!
//! ```
//! use tensorlogic_compiler::optimize::{OptimizationPipeline, PipelineConfig};
//! use tensorlogic_ir::{TLExpr, Term};
//!
//! let pipeline = OptimizationPipeline::new();
//! let expr = TLExpr::add(
//! TLExpr::mul(TLExpr::Constant(2.0), TLExpr::Constant(3.0)),
//! TLExpr::Constant(0.0)
//! );
//! let (optimized, stats) = pipeline.optimize(&expr);
//! ```
//!
//! For fine-grained control, use individual passes:
//!
//! ```
//! use tensorlogic_compiler::optimize::{fold_constants, simplify_algebraic, reduce_strength};
//! use tensorlogic_ir::TLExpr;
//!
//! let expr = TLExpr::add(TLExpr::Constant(2.0), TLExpr::Constant(3.0));
//! let (step1, _) = fold_constants(&expr);
//! let (step2, _) = simplify_algebraic(&step1);
//! let (optimized, _) = reduce_strength(&step2);
//! ```
//!
//! # Analysis Tools
//!
//! The module also provides analysis tools for expressions:
//!
//! ```
//! use tensorlogic_compiler::optimize::analyze_complexity;
//! use tensorlogic_compiler::CompilerContext;
//! use tensorlogic_ir::{TLExpr, Term};
//!
//! let expr = TLExpr::mul(
//! TLExpr::add(TLExpr::Constant(1.0), TLExpr::Constant(2.0)),
//! TLExpr::Constant(3.0)
//! );
//! let complexity = analyze_complexity(&expr);
//! println!("Operations: {}", complexity.total_operations());
//! println!("Cost: {:.2}", complexity.total_cost());
//! ```
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;