Work on issue 2206:plus-minus object

65 views
Skip to first unread message

Sachin Joglekar

unread,
Nov 7, 2012, 1:38:37 PM11/7/12
to sy...@googlegroups.com
@asmeurer,
I would like to start working on this, if no one else already has. We could create a class 'pm' which would return, as you suggested x for pm[0] and -x for pm[1]. We could go further and overload the different binary operators like +,-,* etc for pm such that-
x + y**2*(z+pm(c)) gives
[x+y**2*(z+c), x+y**2*(z-c)]
This list could then be used to access both the values. Moreover, two expressions with a single difference of plus or minus could be combined by recursively breaking down the expression and its sub-expressions to their args until we get the difference in sign. This would take some efforts, but can be done. (if this is not true, to_pm would return False)

Stefan Krastanov

unread,
Nov 7, 2012, 3:17:50 PM11/7/12
to sy...@googlegroups.com
I am unsure how this approach will inter-operate with the rest of
SymPy. For this object to be useful it must be able to work with the
rest of sympy's functions. For instance will this work with your idea:

solve(x+pm(y), x) ---> -pm(y)

There are many more questions, and I am a bit unsure whether this will
be useful (just my opinion), however they can wait. For now we can
focus on:

1. Is it useful?
2. Will it work seamlessly with the rest of sympy?
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/sympy/-/vLmyWg0SUW8J.
> To post to this group, send email to sy...@googlegroups.com.
> To unsubscribe from this group, send email to
> sympy+un...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/sympy?hl=en.

someone

unread,
Nov 7, 2012, 3:40:56 PM11/7/12
to sy...@googlegroups.com
Hi,

> I am unsure how this approach will inter-operate with the rest of
> SymPy. For this object to be useful it must be able to work with the
> rest of sympy's functions. For instance will this work with your idea:
>
> solve(x+pm(y), x) ---> -pm(y)
>
> There are many more questions, and I am a bit unsure whether this will
> be useful (just my opinion), however they can wait. For now we can
> focus on:
>
> 1. Is it useful?

Maybe. But only if it just works out of the box.

I think that it would be good to take a more general
approach and handle multi-valued expressions in the
same go. For example:

1^(1/3) --> mv

with

mv[0], mv[1], mv[2] the three roots.

This can be modelled by the RootOf object:

In [12]: RootOf(x**3-1, 0)
Out[12]: 1

In [13]: RootOf(x**3-1, 1)
Out[13]: -1/2 - sqrt(3)*I/2

In [14]: RootOf(x**3-1, 2)
Out[14]: -1/2 + sqrt(3)*I/2

However we can only extract explicit values here ...
Even simplest constants are not supported yet:

RootOf(x**3-a, 1)

[...]

PolynomialError: only univariate polynomials are allowed


Just my thoughts on the topic

Stefan Krastanov

unread,
Nov 7, 2012, 4:05:46 PM11/7/12
to sy...@googlegroups.com
> I think that it would be good to take a more general
> approach and handle multi-valued expressions in the
> same go. For example:

I am against this. It is like reimplementing in a complicated way,
what can be done simply with lists and for loops.


> However we can only extract explicit values here ...
> Even simplest constants are not supported yet:
>
> RootOf(x**3-a, 1)

Actually it works, you just need to be precise about the polynomial
you are working with (Poly(x**3-a, x))

Aaron Meurer

unread,
Nov 8, 2012, 12:09:29 AM11/8/12
to sy...@googlegroups.com
That only works because it can explicitly find the roots.  If it has to represent the roots symbolically, it can't do it, because algebraic functions are not yet supported in any way in the polys.  Try for example RootOf((Poly(x**5-a*x + b, x)), 0).

Aaron Meurer
 

--
You received this message because you are subscribed to the Google Groups "sympy" group.

Stefan Krastanov

unread,
Nov 8, 2012, 11:45:56 AM11/8/12
to sy...@googlegroups.com
>> > However we can only extract explicit values here ...
>> > Even simplest constants are not supported yet:
>> >
>> > RootOf(x**3-a, 1)
>>
>> Actually it works, you just need to be precise about the polynomial
>> you are working with (Poly(x**3-a, x))
>
>
> That only works because it can explicitly find the roots. If it has to
> represent the roots symbolically, it can't do it, because algebraic
> functions are not yet supported in any way in the polys. Try for example
> RootOf((Poly(x**5-a*x + b, x)), 0).

Sorry, I was unaware of this. I expected that it would return a RootOf
instance. Rather it raised "RootOf is not supported over ZZ[a,b]"
Reply all
Reply to author
Forward
0 new messages