aboutsummaryrefslogtreecommitdiff
path: root/symbolic/optimizations.py
blob: 93dad09f5dab142f1e5767fb515c2d0838b7aedc (plain)
1
2
3
4
5
6
7
8
9
10
from sympy import *

from sympy.codegen.rewriting import ReplaceOptim

expand_square = ReplaceOptim(
    lambda e: e.is_Pow and e.exp.is_integer and e.exp == 2,
    lambda p: UnevaluatedExpr(Mul(p.base, p.base, evaluate = False))
)

custom = [ (expand_square, expand_square) ] + cse_main.basic_optimizations