I have experimented a bit with the model() function, but I think the
subs() function
is the function I was looking for.
The code is now roughly like that:
# User enters expression
expr = sympify('2*a*b*c+a*b')
# User suggests variable subs
usersubs = [['a*b*c', 'y'], ['a*b', 'x']]
for usersub in usersubs:
expr = expr.subs(usersub[0], usersub[1])
print expr
Thanks for your help!
On 21 Sep., 01:07, Aaron Meurer <[email protected]> wrote:
> I don't know enough about what you are doing to know if this will work
> for that, but for this, you can just use subs to replace b*c with a
>
> In [7]: (2*b*c).subs(b*c, a)
> Out[7]: 2⋅a
>
> Aaron Meurer
>
>
>
>
>
>
>
> On Tue, Sep 20, 2011 at 1:47 PM, dennis <[email protected]> wrote:
> > Hi,
>
> > i have some symbols which are related to each other. For example:
>
> > a = Symbol('a')
> > b = Symbol('b')
> > c = Symbol('c')
>
> > a = b*c
>
> > Now simplifying 2*b*c will of course result in 2*b*c
>
> > print 2*b*c
> > output: 2*b*c
> > (2 different symbols)
>
> > Can I somehow say that I prefer a solution with less symbols, so that
> > it results in:
>
> > print 2*b*c
> > output: 2*a
> > (1 symbol)
>
> > I hope my explanation of what I am trying to achieve is precise enough.
>
> > --
> > 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
> > athttp://groups.google.com/group/sympy?hl=en.
--
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.