Hi Bill and Alan,
> > I am teaching an adult who is struggling (and I mean struggling) to
> > learn how to expand and simplify algebraic expressions. I have been
> > using sympy to produce solutions for randomly produced examples using
> > '.expand.' But there has to be a better way of getting expressions
> > 'in' to sympy.
> >
> > I have been writing things like
> >
> > (5*(3*x-10)-4*(6-2*x)). expand()
> >
> > How can I pass a string such as '5*(3*x-10)-4*(6-2*x)' to /expand/ for
> > processing, please?
> >
> > Bill
> >
> > --
> > Bill Bell, C.D.P.
> > Blog: http://unsymptomatictoo.blogspot.com/
> > LinkedIn profile - http://www.linkedin.com/in/williambell
> > >
> >
> >
> Sorry I left out the last line in the previous email -
>
> #!/usr/bin/python
>
> from sympy import *
>
> import sys,string,os
>
> def new_symbol(sym):
> name = sym
> setattr(sys.modules[__name__],name,Symbol(name))
> return
>
> for name in string.lowercase:
> new_symbol(name)
>
> while 1:
> symstr = sys.stdin.readline()
> A = eval(symstr)
> print A.expand()
you can do either as Alan suggested, or just use sympify:
$ bin/isympy
Python 2.4.4 console for SymPy 0.5.7-hg. These commands were executed:
>>> from __future__ import division
>>> from sympy import *
>>> x, y, z = symbols('xyz')
>>> k, m, n = symbols('kmn', integer=True)
>>> Basic.set_repr_level(2) # pretty print output; Use "1" for python output
>>> pprint_try_use_unicode() # use unicode pretty print when available
In [1]: sympify('5*(3*x-10)-4*(6-2*x)')
Out[1]: -74 + 23*x
Is this what you wanted to do?
Ondrej
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sympy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sympy?hl=en
-~----------~----~----~----~------~----~------~--~---