[RFC] real roots

53 views
Skip to first unread message

Chris Smith

unread,
Jan 13, 2015, 4:14:37 PM1/13/15
to sy...@googlegroups.com

In PR 8814 I write, 


Something has to be done to allow one to compute real_root(float, odd) as real. At first I thought to handle this in real_root, but then I thought it might be better to catch it in _eval_power itself. Which do you think is better:

# This is how a negative rational base behaves:

>>> root(S('-1/10'),3)
(-1)**(1/3)*10**(2/3)/10

# Now, for a negative float...

>>> root(S('-.1'),3)
0.464158883361278*(-1)**(1/3)  # <-- should a negative float give this (a)
>>> _.n()
0.232079441680639 + 0.401973384383085*I  # <-- or this (b)?

The SymPy  trend is to fully evaluate an expression if args are numbers, but by selecting the principle root in the case of Pow, the user looses the option to select the real branch post-calc. (Hence, I favor not fully evaluating in this case, selecting behavior (a).) If the power is not an odd rational, the usual, fully evaluated result is obtained.


/c

Aaron Meurer

unread,
Jan 13, 2015, 4:20:46 PM1/13/15
to sy...@googlegroups.com
Without commenting on your proposal, I'd like to point out that point of the principal nths root is that all other nth roots are the powers of that root. 

Aaron Meurer

--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/da5b3c19-ef67-4bcd-b5c3-b6c167bd378d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Chris Smith

unread,
Jan 14, 2015, 1:02:47 AM1/14/15
to sy...@googlegroups.com
By allowing the (-1)**(1/3) to remain we leave open (as with Rational bases) the option of getting to the real root with real_root. I wish we had a good mechanism to check if something like root(x, 3) + 2 == 0 when substituting in -8 for x. It is for this reason that the following returns no solution:

>>> solve(root(x,3)+2)
[]

Aaron Meurer

unread,
Jan 14, 2015, 12:08:28 PM1/14/15
to sy...@googlegroups.com
On Wed, Jan 14, 2015 at 12:02 AM, Chris Smith <smi...@gmail.com> wrote:
By allowing the (-1)**(1/3) to remain we leave open (as with Rational bases) the option of getting to the real root with real_root. I wish we had a good mechanism to check if something like root(x, 3) + 2 == 0 when substituting in -8 for x. It is for this reason that the following returns no solution:

>>> solve(root(x,3)+2)
[]

I suppose this is right. There is no x that when plugged in to that equation, gives 0. Maybe 8*exp_polar(3*pi*I) could be considered a solution. 

Aaron Meurer
 
Reply all
Reply to author
Forward
0 new messages