Example #1
0
    def rule(n, k):
        coeff, rewrite = S.One, False

        cn, _n = n.as_coeff_Add()

        if _n and cn.is_Integer and cn:
            coeff *= _rf(_n + 1, cn) / _rf(_n - k + 1, cn)
            rewrite = True
            n = _n

        # this sort of binomial has already been removed by
        # rising factorials but is left here in case the order
        # of rule application is changed
        if k.is_Add:
            ck, _k = k.as_coeff_Add()
            if _k and ck.is_Integer and ck:
                coeff *= _rf(n - ck - _k + 1, ck) / _rf(_k + 1, ck)
                rewrite = True
                k = _k

        if count_ops(k) > count_ops(n - k):
            rewrite = True
            k = n - k

        if rewrite:
            return coeff * binomial(n, k)
Example #2
0
def remove_redundant_sols(sol1, sol2, x):
    """
    Helper function to remove redundant
    solutions to the differential equation.
    """
    # If y1 and y2 are redundant solutions, there is
    # some value of the arbitrary constant for which
    # they will be equal

    syms1 = sol1.atoms(Symbol, Dummy)
    syms2 = sol2.atoms(Symbol, Dummy)
    num1, den1 = [Poly(e, x, extension=True) for e in sol1.together().as_numer_denom()]
    num2, den2 = [Poly(e, x, extension=True) for e in sol2.together().as_numer_denom()]
    # Cross multiply
    e = num1*den2 - den1*num2
    # Check if there are any constants
    syms = list(e.atoms(Symbol, Dummy))
    if len(syms):
        # Find values of constants for which solutions are equal
        redn = linsolve(e.all_coeffs(), syms)
        if len(redn):
            # Return the general solution over a particular solution
            if len(syms1) > len(syms2):
                return sol2
            # If both have constants, return the lesser complex solution
            elif len(syms1) == len(syms2):
                return sol1 if count_ops(syms1) >= count_ops(syms2) else sol2
            else:
                return sol1
Example #3
0
    def rule(n, k):
        coeff, rewrite = S.One, False

        cn, _n = n.as_coeff_Add()

        if _n and cn.is_Integer and cn:
            coeff *= _rf(_n + 1, cn)/_rf(_n - k + 1, cn)
            rewrite = True
            n = _n

        # this sort of binomial has already been removed by
        # rising factorials but is left here in case the order
        # of rule application is changed
        if k.is_Add:
            ck, _k = k.as_coeff_Add()
            if _k and ck.is_Integer and ck:
                coeff *= _rf(n - ck - _k + 1, ck)/_rf(_k + 1, ck)
                rewrite = True
                k = _k

        if count_ops(k) > count_ops(n - k):
            rewrite = True
            k = n - k

        if rewrite:
            return coeff*binomial(n, k)
Example #4
0
def _sqrtdenest_rec(expr):
    """Helper that denests the square root of three or more surds.

    It returns the denested expression; if it cannot be denested it
    throws SqrtdenestStopIteration

    Algorithm: expr.base is in the extension Q_m = Q(sqrt(r_1),..,sqrt(r_k));
    split expr.base = a + b*sqrt(r_k), where `a` and `b` are on
    Q_(m-1) = Q(sqrt(r_1),..,sqrt(r_(k-1))); then a**2 - b**2*r_k is
    on Q_(m-1); denest sqrt(a**2 - b**2*r_k) and so on.
    See [1], section 6.

    Examples
    ========

    >>> from sympy import sqrt
    >>> from sympy.simplify.sqrtdenest import _sqrtdenest_rec
    >>> _sqrtdenest_rec(sqrt(-72*sqrt(2) + 158*sqrt(5) + 498))
    -sqrt(10) + sqrt(2) + 9 + 9*sqrt(5)
    >>> w=-6*sqrt(55)-6*sqrt(35)-2*sqrt(22)-2*sqrt(14)+2*sqrt(77)+6*sqrt(10)+65
    >>> _sqrtdenest_rec(sqrt(w))
    -sqrt(11) - sqrt(7) + sqrt(2) + 3*sqrt(5)
    """
    from sympy.simplify.radsimp import radsimp, rad_rationalize, split_surds

    if not expr.is_Pow:
        return sqrtdenest(expr)
    if expr.base < 0:
        return sqrt(-1) * _sqrtdenest_rec(sqrt(-expr.base))
    g, a, b = split_surds(expr.base)
    a = a * sqrt(g)
    if a < b:
        a, b = b, a
    c2 = _mexpand(a ** 2 - b ** 2)
    if len(c2.args) > 2:
        g, a1, b1 = split_surds(c2)
        a1 = a1 * sqrt(g)
        if a1 < b1:
            a1, b1 = b1, a1
        c2_1 = _mexpand(a1 ** 2 - b1 ** 2)
        c_1 = _sqrtdenest_rec(sqrt(c2_1))
        d_1 = _sqrtdenest_rec(sqrt(a1 + c_1))
        num, den = rad_rationalize(b1, d_1)
        c = _mexpand(d_1 / sqrt(2) + num / (den * sqrt(2)))
    else:
        c = _sqrtdenest1(sqrt(c2))

    if sqrt_depth(c) > 1:
        raise SqrtdenestStopIteration
    ac = a + c
    if len(ac.args) >= len(expr.args):
        if count_ops(ac) >= count_ops(expr.base):
            raise SqrtdenestStopIteration
    d = sqrtdenest(sqrt(ac))
    if sqrt_depth(d) > 1:
        raise SqrtdenestStopIteration
    num, den = rad_rationalize(b, d)
    r = d / sqrt(2) + num / (den * sqrt(2))
    r = radsimp(r)
    return _mexpand(r)
Example #5
0
def _sqrtdenest_rec(expr):
    """Helper that denests the square root of three or more surds.

    It returns the denested expression; if it cannot be denested it
    throws SqrtdenestStopIteration

    Algorithm: expr.base is in the extension Q_m = Q(sqrt(r_1),..,sqrt(r_k));
    split expr.base = a + b*sqrt(r_k), where `a` and `b` are on
    Q_(m-1) = Q(sqrt(r_1),..,sqrt(r_(k-1))); then a**2 - b**2*r_k is
    on Q_(m-1); denest sqrt(a**2 - b**2*r_k) and so on.
    See [1], section 6.

    Examples
    ========

    >>> from sympy import sqrt
    >>> from sympy.simplify.sqrtdenest import _sqrtdenest_rec
    >>> _sqrtdenest_rec(sqrt(-72*sqrt(2) + 158*sqrt(5) + 498))
    -sqrt(10) + sqrt(2) + 9 + 9*sqrt(5)
    >>> w=-6*sqrt(55)-6*sqrt(35)-2*sqrt(22)-2*sqrt(14)+2*sqrt(77)+6*sqrt(10)+65
    >>> _sqrtdenest_rec(sqrt(w))
    -sqrt(11) - sqrt(7) + sqrt(2) + 3*sqrt(5)
    """
    from sympy.simplify.simplify import radsimp, split_surds, rad_rationalize
    if not expr.is_Pow:
        return sqrtdenest(expr)
    if expr.base < 0:
        return sqrt(-1)*_sqrtdenest_rec(sqrt(-expr.base))
    g, a, b = split_surds(expr.base)
    a = a*sqrt(g)
    if a < b:
        a, b = b, a
    c2 = _mexpand(a**2 - b**2)
    if len(c2.args) > 2:
        g, a1, b1 = split_surds(c2)
        a1 = a1*sqrt(g)
        if a1 < b1:
            a1, b1 = b1, a1
        c2_1 = _mexpand(a1**2 - b1**2)
        c_1 = _sqrtdenest_rec(sqrt(c2_1))
        d_1 = _sqrtdenest_rec(sqrt(a1 + c_1))
        num, den = rad_rationalize(b1, d_1)
        c = _mexpand(d_1/sqrt(2) + num/(den*sqrt(2)))
    else:
        c = _sqrtdenest1(sqrt(c2))

    if sqrt_depth(c) > 1:
        raise SqrtdenestStopIteration
    ac = a + c
    if len(ac.args) >= len(expr.args):
        if count_ops(ac) >= count_ops(expr.base):
            raise SqrtdenestStopIteration
    d = sqrtdenest(sqrt(ac))
    if sqrt_depth(d) > 1:
        raise SqrtdenestStopIteration
    num, den = rad_rationalize(b, d)
    r = d/sqrt(2) + num/(den*sqrt(2))
    r = radsimp(r)
    return _mexpand(r)
Example #6
0
def _sqrtdenest1(expr, denester=True):
    """Return denested expr after denesting with simpler methods or, that
    failing, using the denester."""

    from sympy.simplify.simplify import radsimp

    if not is_sqrt(expr):
        return expr

    a = expr.base
    if a.is_Atom:
        return expr
    val = _sqrt_match(a)
    if not val:
        return expr

    a, b, r = val
    # try a quick numeric denesting
    d2 = _mexpand(a**2 - b**2 * r)
    if d2.is_Rational:
        if d2.is_positive:
            z = _sqrt_numeric_denest(a, b, r, d2)
            if z is not None:
                return z
        else:
            # fourth root case
            # sqrtdenest(sqrt(3 + 2*sqrt(3))) =
            # sqrt(2)*3**(1/4)/2 + sqrt(2)*3**(3/4)/2
            dr2 = _mexpand(-d2 * r)
            dr = sqrt(dr2)
            if dr.is_Rational:
                z = _sqrt_numeric_denest(_mexpand(b * r), a, r, dr2)
                if z is not None:
                    return z / root(r, 4)

    else:
        z = _sqrt_symbolic_denest(a, b, r)
        if z is not None:
            return z

    if not denester or not is_algebraic(expr):
        return expr

    res = sqrt_biquadratic_denest(expr, a, b, r, d2)
    if res:
        return res

    # now call to the denester
    av0 = [a, b, r, d2]
    z = _denester([radsimp(expr**2)], av0, 0, sqrt_depth(expr))[0]
    if av0[1] is None:
        return expr
    if z is not None:
        if sqrt_depth(z) == sqrt_depth(
                expr) and count_ops(z) > count_ops(expr):
            return expr
        return z
    return expr
Example #7
0
def test_eigen_slow():
    # issue 15125
    from sympy.core.function import count_ops
    q = Symbol("q", positive=True)
    m = Matrix([[-2, exp(-q), 1], [exp(q), -2, 1], [1, 1, -2]])
    assert count_ops(m.eigenvals(simplify=False)) > \
        count_ops(m.eigenvals(simplify=True))
    assert count_ops(m.eigenvals(simplify=lambda x: x)) > \
        count_ops(m.eigenvals(simplify=True))
Example #8
0
def _sqrtdenest1(expr, denester=True):
    """Return denested expr after denesting with simpler methods or, that
    failing, using the denester."""

    from sympy.simplify.simplify import radsimp

    if not is_sqrt(expr):
        return expr

    a = expr.base
    if a.is_Atom:
        return expr
    val = _sqrt_match(a)
    if not val:
        return expr

    a, b, r = val
    # try a quick numeric denesting
    d2 = _mexpand(a**2 - b**2*r)
    if d2.is_Rational:
        if d2.is_positive:
            z = _sqrt_numeric_denest(a, b, r, d2)
            if z is not None:
                return z
        else:
            # fourth root case
            # sqrtdenest(sqrt(3 + 2*sqrt(3))) =
            # sqrt(2)*3**(1/4)/2 + sqrt(2)*3**(3/4)/2
            dr2 = _mexpand(-d2*r)
            dr = sqrt(dr2)
            if dr.is_Rational:
                z = _sqrt_numeric_denest(_mexpand(b*r), a, r, dr2)
                if z is not None:
                    return z/root(r, 4)

    else:
        z = _sqrt_symbolic_denest(a, b, r)
        if z is not None:
            return z

    if not denester or not is_algebraic(expr):
        return expr

    res = sqrt_biquadratic_denest(expr, a, b, r, d2)
    if res:
        return res

    # now call to the denester
    av0 = [a, b, r, d2]
    z = _denester([radsimp(expr**2)], av0, 0, sqrt_depth(expr))[0]
    if av0[1] is None:
        return expr
    if z is not None:
        if sqrt_depth(z) == sqrt_depth(expr) and count_ops(z) > count_ops(expr):
            return expr
        return z
    return expr
Example #9
0
    def f(rv):
        if not rv.is_Mul:
            return rv
        rvd = rv.as_powers_dict()
        nd_fact_args = [[], []]  # numerator, denominator

        for k in rvd:
            if isinstance(k, factorial) and rvd[k].is_Integer:
                if rvd[k].is_positive:
                    nd_fact_args[0].extend([k.args[0]] * rvd[k])
                else:
                    nd_fact_args[1].extend([k.args[0]] * -rvd[k])
                rvd[k] = 0
        if not nd_fact_args[0] or not nd_fact_args[1]:
            return rv

        hit = False
        for m in range(2):
            i = 0
            while i < len(nd_fact_args[m]):
                ai = nd_fact_args[m][i]
                for j in range(i + 1, len(nd_fact_args[m])):
                    aj = nd_fact_args[m][j]

                    sum = ai + aj
                    if sum in nd_fact_args[1 - m]:
                        hit = True

                        nd_fact_args[1 - m].remove(sum)
                        del nd_fact_args[m][j]
                        del nd_fact_args[m][i]

                        rvd[binomial(
                            sum, ai if count_ops(ai) < count_ops(aj) else
                            aj)] += (-1 if m == 0 else 1)
                        break
                else:
                    i += 1

        if hit:
            return Mul(*([k**rvd[k] for k in rvd] +
                         [factorial(k) for k in nd_fact_args[0]])) / Mul(
                             *[factorial(k) for k in nd_fact_args[1]])
        return rv
Example #10
0
    def f(rv):
        if not rv.is_Mul:
            return rv
        rvd = rv.as_powers_dict()
        nd_fact_args = [[], []] # numerator, denominator

        for k in rvd:
            if isinstance(k, factorial) and rvd[k].is_Integer:
                if rvd[k].is_positive:
                    nd_fact_args[0].extend([k.args[0]]*rvd[k])
                else:
                    nd_fact_args[1].extend([k.args[0]]*-rvd[k])
                rvd[k] = 0
        if not nd_fact_args[0] or not nd_fact_args[1]:
            return rv

        hit = False
        for m in range(2):
            i = 0
            while i < len(nd_fact_args[m]):
                ai = nd_fact_args[m][i]
                for j in range(i + 1, len(nd_fact_args[m])):
                    aj = nd_fact_args[m][j]

                    sum = ai + aj
                    if sum in nd_fact_args[1 - m]:
                        hit = True

                        nd_fact_args[1 - m].remove(sum)
                        del nd_fact_args[m][j]
                        del nd_fact_args[m][i]

                        rvd[binomial(sum, ai if count_ops(ai) <
                                count_ops(aj) else aj)] += (
                                -1 if m == 0 else 1)
                        break
                else:
                    i += 1

        if hit:
            return Mul(*([k**rvd[k] for k in rvd] + [factorial(k)
                    for k in nd_fact_args[0]]))/Mul(*[factorial(k)
                    for k in nd_fact_args[1]])
        return rv
Example #11
0
def test_issue_2827_trigsimp_methods():
    measure1 = lambda expr: len(str(expr))
    measure2 = lambda expr: -count_ops(expr)
    # Return the most complicated result
    expr = (x + 1) / (x + sin(x)**2 + cos(x)**2)
    ans = Matrix([1])
    M = Matrix([expr])
    assert trigsimp(M, method='fu', measure=measure1) == ans
    assert trigsimp(M, method='fu', measure=measure2) != ans
    # all methods should work with Basic expressions even if they
    # aren't Expr
    M = Matrix.eye(1)
    assert all(
        trigsimp(M, method=m) == M for m in 'fu matching groebner old'.split())
    # watch for E in exptrigsimp, not only exp()
    eq = 1 / sqrt(E) + E
    assert exptrigsimp(eq) == eq
Example #12
0
def test_eigen():
    R = Rational

    assert eye(3).charpoly(x) == Poly((x - 1)**3, x)
    assert eye(3).charpoly(y) == Poly((y - 1)**3, y)

    M = Matrix([[1, 0, 0], [0, 1, 0], [0, 0, 1]])

    assert M.eigenvals(multiple=False) == {S.One: 3}
    assert M.eigenvals(multiple=True) == [1, 1, 1]

    assert M.eigenvects() == ([
        (1, 3, [Matrix([1, 0, 0]),
                Matrix([0, 1, 0]),
                Matrix([0, 0, 1])])
    ])

    assert M.left_eigenvects() == ([
        (1, 3, [Matrix([[1, 0, 0]]),
                Matrix([[0, 1, 0]]),
                Matrix([[0, 0, 1]])])
    ])

    M = Matrix([[0, 1, 1], [1, 0, 0], [1, 1, 1]])

    assert M.eigenvals() == {2 * S.One: 1, -S.One: 1, S.Zero: 1}

    assert M.eigenvects() == ([(-1, 1, [Matrix([-1, 1, 0])]),
                               (0, 1, [Matrix([0, -1, 1])]),
                               (2, 1, [Matrix([R(2, 3), R(1, 3), 1])])])

    assert M.left_eigenvects() == ([(-1, 1, [Matrix([[-2, 1, 1]])]),
                                    (0, 1, [Matrix([[-1, -1, 1]])]),
                                    (2, 1, [Matrix([[1, 1, 1]])])])

    a = Symbol('a')
    M = Matrix([[a, 0], [0, 1]])

    assert M.eigenvals() == {a: 1, S.One: 1}

    M = Matrix([[1, -1], [1, 3]])
    assert M.eigenvects() == ([(2, 2, [Matrix(2, 1, [-1, 1])])])
    assert M.left_eigenvects() == ([(2, 2, [Matrix([[1, 1]])])])

    M = Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
    a = R(15, 2)
    b = 3 * 33**R(1, 2)
    c = R(13, 2)
    d = (R(33, 8) + 3 * b / 8)
    e = (R(33, 8) - 3 * b / 8)

    def NS(e, n):
        return str(N(e, n))

    r = [
        (a - b / 2, 1, [
            Matrix([
                (12 + 24 / (c - b / 2)) / ((c - b / 2) * e) + 3 / (c - b / 2),
                (6 + 12 / (c - b / 2)) / e, 1
            ])
        ]),
        (0, 1, [Matrix([1, -2, 1])]),
        (a + b / 2, 1, [
            Matrix([
                (12 + 24 / (c + b / 2)) / ((c + b / 2) * d) + 3 / (c + b / 2),
                (6 + 12 / (c + b / 2)) / d, 1
            ])
        ]),
    ]
    r1 = [(NS(r[i][0], 2), NS(r[i][1], 2), [NS(j, 2) for j in r[i][2][0]])
          for i in range(len(r))]
    r = M.eigenvects()
    r2 = [(NS(r[i][0], 2), NS(r[i][1], 2), [NS(j, 2) for j in r[i][2][0]])
          for i in range(len(r))]
    assert sorted(r1) == sorted(r2)

    eps = Symbol('eps', real=True)

    M = Matrix([[abs(eps), I * eps], [-I * eps, abs(eps)]])

    assert M.eigenvects() == ([
        (0, 1, [Matrix([[-I * eps / abs(eps)], [1]])]),
        (2 * abs(eps), 1, [Matrix([[I * eps / abs(eps)], [1]])]),
    ])

    assert M.left_eigenvects() == ([
        (0, 1, [Matrix([[I * eps / Abs(eps), 1]])]),
        (2 * Abs(eps), 1, [Matrix([[-I * eps / Abs(eps), 1]])])
    ])

    M = Matrix(3, 3, [1, 2, 0, 0, 3, 0, 2, -4, 2])
    M._eigenvects = M.eigenvects(simplify=False)
    assert max(i.q for i in M._eigenvects[0][2][0]) > 1
    M._eigenvects = M.eigenvects(simplify=True)
    assert max(i.q for i in M._eigenvects[0][2][0]) == 1
    M = Matrix([[Rational(1, 4), 1], [1, 1]])
    assert M.eigenvects(simplify=True) == [
        (Rational(5, 8) - sqrt(73) / 8, 1,
         [Matrix([[-sqrt(73) / 8 - Rational(3, 8)], [1]])]),
        (Rational(5, 8) + sqrt(73) / 8, 1,
         [Matrix([[Rational(-3, 8) + sqrt(73) / 8], [1]])])
    ]
    assert M.eigenvects(simplify=False) == [
        (Rational(5, 8) - sqrt(73) / 8, 1,
         [Matrix([[-1 / (-Rational(3, 8) + sqrt(73) / 8)], [1]])]),
        (Rational(5, 8) + sqrt(73) / 8, 1,
         [Matrix([[8 / (3 + sqrt(73))], [1]])])
    ]

    m = Matrix([[1, .6, .6], [.6, .9, .9], [.9, .6, .6]])
    evals = {
        Rational(5, 4) - sqrt(385) / 20: 1,
        sqrt(385) / 20 + Rational(5, 4): 1,
        S.Zero: 1
    }
    assert m.eigenvals() == evals
    nevals = list(sorted(m.eigenvals(rational=False).keys()))
    sevals = list(sorted(evals.keys()))
    assert all(abs(nevals[i] - sevals[i]) < 1e-9 for i in range(len(nevals)))

    # issue 10719
    assert Matrix([]).eigenvals() == {}
    assert Matrix([]).eigenvects() == []

    # issue 15119
    raises(NonSquareMatrixError,
           lambda: Matrix([[1, 2], [0, 4], [0, 0]]).eigenvals())
    raises(NonSquareMatrixError,
           lambda: Matrix([[1, 0], [3, 4], [5, 6]]).eigenvals())
    raises(NonSquareMatrixError,
           lambda: Matrix([[1, 2, 3], [0, 5, 6]]).eigenvals())
    raises(NonSquareMatrixError,
           lambda: Matrix([[1, 0, 0], [4, 5, 0]]).eigenvals())
    raises(
        NonSquareMatrixError, lambda: Matrix([[1, 2, 3], [0, 5, 6]]).eigenvals(
            error_when_incomplete=False))
    raises(
        NonSquareMatrixError, lambda: Matrix([[1, 0, 0], [4, 5, 0]]).eigenvals(
            error_when_incomplete=False))

    # issue 15125
    from sympy.core.function import count_ops
    q = Symbol("q", positive=True)
    m = Matrix([[-2, exp(-q), 1], [exp(q), -2, 1], [1, 1, -2]])
    assert count_ops(m.eigenvals(simplify=False)) > count_ops(
        m.eigenvals(simplify=True))
    assert count_ops(m.eigenvals(simplify=lambda x: x)) > count_ops(
        m.eigenvals(simplify=True))

    assert isinstance(m.eigenvals(simplify=True, multiple=False), dict)
    assert isinstance(m.eigenvals(simplify=True, multiple=True), list)
    assert isinstance(m.eigenvals(simplify=lambda x: x, multiple=False), dict)
    assert isinstance(m.eigenvals(simplify=lambda x: x, multiple=True), list)
Example #13
0
 def check(eq):
     r, c = cse(eq)
     assert eq.count_ops() >= \
         len(r) + sum([i[1].count_ops() for i in r]) + \
         count_ops(c)
Example #14
0
 def check(eq):
     from sympy.core.function import count_ops
     r, c = cse(eq)
     assert eq.count_ops() >= \
         len(r) + sum([i[1].count_ops() for i in r]) + \
         count_ops(c)
Example #15
0
 def count(val):
     return count_ops(val, visual=True)
Example #16
0
 def count(val):
     return count_ops(val, visual=False)
Example #17
0
 def check(eq):
     from sympy.core.function import count_ops
     r, c = cse(eq)
     assert eq.count_ops() >= \
         len(r) + sum([i[1].count_ops() for i in r]) + \
         count_ops(c)
Example #18
0
def test_issue_12070():
    exprs = [x + y, 2 + x + y, x + y + z, 3 + x + y + z]
    subst, red = cse(exprs)
    assert 6 >= (len(subst) + sum([v.count_ops() for k, v in subst]) +
                 count_ops(red))
Example #19
0
@author: tuananh
'''
from sympy import simplify, cos, sin, symbols, log, exp
from sympy.core.function import count_ops


X1, X2 = symbols('X1 X2')

#SC - K4 - size 86
#a = (cos(exp(X1)) / (cos((cos(cos(((X1 * X1) + cos(cos(cos((X1 * log(exp(X1))))))))) + (exp(X1) + cos(cos((((sin(exp(X1)) / X1) + exp((exp(X1) * (X1 - X1)))) + (exp(X1) * (X1 - X1)))))))) + (cos((cos(cos(((sin(exp(X1)) / X1) + exp((exp(X1) * (X1 - X1)))))) + (exp(X1) + cos(cos(((X1 * X1) + cos(cos(cos((X1 * log(exp(X1)))))))))))) + ((cos((cos((sin(cos((exp(X1) + exp((exp(X1) * (X1 - X1)))))) / X1)) + (exp(X1) + exp((exp(X1) * (X1 - X1)))))) + (exp(X1) + (exp(X1) / X1))) * exp(cos((X1 * log(exp(X1)))))))))

#SC - K12 - size 38
#a = ((sin(X1) * ((X1 / cos(X2)) + cos((sin(X1) * (sin((log(exp(sin(X1))) - log(X1))) + sin((sin((((X1 / cos((X1 - log(X1)))) - log(X1)) - log(X1))) + sin((log(exp((sin(sin(X1)) / cos(log(X1))))) - (X2 - X2)))))))))) - (X1 + X2))

#SGXMSC K4 - size 135
a = (((1 / ((X1 / X1) + exp((0 - (1 / (1 * (X1 - X1))))))) * sin((((exp(((log(X1) - X1) - (sin(X1) - sin(sin(((X1 * X1) + (X1 * X1))))))) / X1) - sin((X1 + X1))) / (((cos(exp(X1)) + (1 - ((1 / (1 + exp((sin((X1 + X1)) - cos(X1))))) / (1 + exp((X1 - exp(X1))))))) + (X1 / (1 / (1 + exp((1 - ((X1 * X1) - ((1 / sin(X1)) / 1)))))))) - (sin((X1 - X1)) + log(X1))))) * (sin(exp(cos(((sin((X1 + X1)) + X1) / X1)))) / 1)) + ((1 - (1 / (1 + exp(((X1 / X1) - (sin(X1) - sin((X1 + X1)))))))) * sin(((sin(X1) - sin((X1 + X1))) / (((cos(X1) + (1 - ((1 / (1 + exp((sin((X1 * X1)) - cos(X1))))) / (1 + exp((sin((X1 + 1)) - (X1 * X1))))))) + (X1 / (1 / (1 + exp((cos(X1) - ((X1 * X1) - (((X1 / X1) / (X1 - X1)) / (X1 / exp(X1)))))))))) - (sin((X1 - X1)) + log(X1))))) * sin(exp(cos((1 + sin((X1 + X1))))))))
    

#SGXMSC K12 - size 128
#a = (((1 - (1 / (1 + exp((0 - cos((((X1 / X1) - X1) - cos((X1 * X1))))))))) * (((1 - (X1 / (cos(log(exp((((X1 / X1) - X1) - cos(X2))))) + exp((X1 - 0))))) * (log(exp((((X1 / X1) - X1) - cos((X1 * X1))))) - X2)) + (X1 * (X1 - X2) * sin(1)))) + ((1 / (1 + exp((0 - cos(sin(((1 / (1 + exp((cos(X2) - (cos(X1) / (X1 * X1)))))) * (X1 - (((sin(X1) / X1) - X1) - cos((X1 * X1)))) * sin((X1 - (1 / sin(1))))))))))) * ((1 - (1 / (1 + exp(((X1 - X1) - X2))))) * (((1 - ((sin(log(exp(cos(X1)))) / (1 + exp(exp(X1)))) / ((1 - (1 / (1 + exp(((X1 - X1) - X2))))) + exp((cos((X1 - X1)) - (X1 / (X1 - 0))))))) * (log(exp((((X1 / X1) - X1) - cos(X2)))) - X2)) + ((1 / (1 + exp((cos(sin(X1)) - (cos(X1) / (X1 * X1)))))) * (X1 - X2) * sin((1 - (1 / exp((((X1 / X1) - X1) - cos((X1 * X1)))))))))) * (cos((X1 * X1)) * (X1 * X1) * 0)))



#print a

y = simplify(a)

print 'size after simplify: ', count_ops(y)

print y