Comment #5 on issue 1966 by [email protected]: Add evaluate option to sympify
http://code.google.com/p/sympy/issues/detail?id=1966

Here is a little routine that now works pretty much as expected with a sample session.

def lg():
    """Prompt for an equation and then prompt for 'change patterns' which
    use a variable in an expression to indicate what should happen to the
    equation, e.g. i + 1 would mean to add 1 to both sides of the equation.
A function can be used as `expand(i)` (or simply `expand`) to expand both
    sides of the equation.
    """
    from sympy.parsing.sympy_parser import standard_transformations,\
    implicit_multiplication_application, parse_expr
    transformations = (standard_transformations +
    (implicit_multiplication_application,))
    s = raw_input("equation: ")
    eq = Eq(*[parse_expr(a, transformations=transformations, evaluate=False)
    for a in s.split('=')])
    while 1:
        print eq
        if not isinstance(eq, Equality):
            break
        s = raw_input('> ')
        if s == '.':
            break
        try:
e = parse_expr(s, transformations=transformations, evaluate=False)
            if isinstance(e, (FunctionClass, Lambda, type(lambda:1))):
                eq = eq.func(*[e(a) for a in eq.args])
            else:
                i = e.free_symbols - eq.free_symbols
                if len(i) != 1:
                    raise ValueError
                i = i.pop()
                f = lambda side: e.subs(i, side)
                eq = eq.func(*[f(a) for a in eq.args])
        except:
print('not understood: did you use a variable to represent each side?')


lg()
equation: 2(x+1)=4(1-2)+x
2*(x + 1) == x + 4*(-2 + 1)
i/2
x + 1 == x/2 + 2*(-2 + 1)
i-1
x == x/2 + 2*(-2 + 1) - 1
expand
x == x/2 - 3
expand(i)
x == x/2 - 3
i-x/2
x/2 == -3
i*2
x == -6
.
lg()
equation: x=2(1+2)
x == 2*(1 + 2)
i/2
x/2 == 1 + 2
i-3
x/2 - 3 == 0
i+3
x/2 == 3
i*2
x == 6



--
You received this message because this project is configured to send all issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

--
You received this message because you are subscribed to the Google Groups 
"sympy-issues" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy-issues.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to