On Mon, Aug 3, 2009 at 10:27 PM, Alemi<[email protected]> wrote:
>
> Hi,
>
> I'm looking to use SymPy for a project I'm working on and I have a
> couple questions.
>
> The first is that I think I might want to disable the flattening of
> equations by default.  I looked at the code and tried to change the
> core, especially add.py and operations.py but couldn't quite hack it.
> I guess, the first question would be whether there would be a simple
> way to do this, and the second would be that if I did dive deeper and
> disable the flatten by default but maintained the same object
> structure, would this screw with any of the more sophisticated
> mathematical operations, i.e. do any of the other functions rely on
> expressions being in their flattened form to function correctly.

Yes, you can disable it and store the expressions in the tree form,
e.g. a+b+c would get into (a+b) + c which would be

Add(Add(a, b), c)

In fact, you can do that now too already with the evaluate=False keyword:

In [1]: var("a b c")
Out[1]: (a, b, c)

In [2]: Add(Add(a, b), c, evaluate=False)
Out[2]: c + a + b

In [3]: print_tree(Add(Add(a, b), c, evaluate=False))
Add: c + a + b
evaluate: False
+-Add: a + b
| +-Symbol: b
| | comparable: False
| +-Symbol: a
|   comparable: False
+-Symbol: c
  comparable: False


If this is the default, then yes, I suspect some algorithms might stop
working -- the best thing is to just run tests and see.

Why do you want to disable the flattening? How would you compare the
two nonflattened expressions if they are equal? If you know some fast
algorithm for that, I'd be interested.

>
> The second question is whether there is any interest in adding support
> for equations much like SAGE does, i.e. store 'x+2==3' as an object
> itself with the equals operator and a bunch of methods like
> add_to_both_sides and the like.  If not, do you think I could throw
> that together without interfering too much with how SymPy does its own
> thing?  Any tips before I embark?

Yes, look at the Eq class, it does exactly that. If you have some
additions to that class, it'd be awesome, currently it can't do much.

In [8]: Eq?
Type:           function
Base Class:     <type 'function'>
String Form:    <function Eq at 0x24f3d70>
Namespace:      Interactive
File:           /home/ondrej/repos/sympy/sympy/core/relational.py
Definition:     Eq(a, b=0)
Docstring:
    A handy wrapper around the Relational class.
    Eq(a,b)

    Example:
    >>> from sympy import *
    >>> x,y = symbols('xy')
    >>> Eq(y, x+x**2)
    y == x + x**2


As to having == returning Eq by default, we used to do that, but as it
was slow. But you can I think quite trivially enable it, just change
the __eq__ in Basic and implement __nonzero__ in Eq I think. We can
have some switch for it, so that people who want this behavior can
have it.

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
-~----------~----~----~----~------~----~------~--~---

Reply via email to