auto_contractor.expr_arithmetic — Symbolic Expression Arithmetic¶
Source: qlat/auto_contractor/expr_arithmetic.py
Note: Update this document when updating the source file.
Outline¶
Overview¶
expr_arithmetic provides a symbolic arithmetic layer for manipulating
expression coefficients in the auto-contractor framework. It represents
expressions as sums of Term objects, each containing a sympy coefficient
and a list of Factor objects (code segments or variables). The module
supports algebraic simplification, Python code compilation, and
variable tracking.
Core Classes¶
Factor¶
A leaf-level code segment or variable.
Attribute |
Type |
Description |
|---|---|---|
|
|
The string representation of the factor |
|
|
Variables found in the code |
|
|
|
f = Factor("a + b") # otype = "Expr"
f = Factor("x") # otype = "Var"
Term¶
A product of Factor objects multiplied by a coefficient.
Attribute |
Type |
Description |
|---|---|---|
|
number or sympy expr |
The scalar coefficient |
|
|
The symbolic factors |
Expr¶
A sum of Term objects. Supports arithmetic operators (+, -, *)
and simplification.
Attribute |
Type |
Description |
|---|---|---|
|
|
The summands |
Interface Functions¶
Function |
Description |
|---|---|
|
Convert |
|
Alias for |
|
Return |
|
Compile expression to Python code string |
|
Check if |
Simplification¶
Function |
Description |
|---|---|
|
Structure-only simplification (sort, combine, drop zeros) |
|
Sympy coefficient simplification + structure simplification |
Both return Expr or int (if the result is a pure scalar).
Examples¶
import qlat as q
q.begin_with_mpi([[1, 1, 1, 4]])
from qlat.auto_contractor.expr_arithmetic import mk_expr, mk_fac, simplified_ea
a = mk_expr(1)
b = mk_expr(2)
c = mk_expr(mk_fac("a + b"))
d = mk_expr(mk_fac("a + b"))
result = c * b + c + d * d
print(result)
result = simplified_ea(result)
print(result)
print(result.compile_py())
q.end_with_mpi()