Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" Optimizations of the expression tree representation for better CSE opportunities. """ from __future__ import print_function, division
from sympy.core import Add, Basic, Mul from sympy.core.basic import preorder_traversal from sympy.core.singleton import S from sympy.utilities.iterables import default_sort_key
def sub_pre(e): """ Replace y - x with -(x - y) if -1 can be extracted from y - x. """
# make it canonical
# repeat again for persisting Adds but mark these with a leading 1, -1 # e.g. y - x -> 1*-1*(x - y)
def sub_post(e): """ Replace 1*-1*x with -x. """ node.args[0] is S.One and node.args[1] is S.NegativeOne:
|