This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients belopolsky, mark.dickinson, rhettinger, serhiy.storchaka, skrah, steven.daprano, tim.peters
Date 2016-06-20.20:19:57
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1466453998.45.0.507252447891.issue27353@psf.upfronthosting.co.za>
In-reply-to
Content
If this ends up going forward (and I'm don't believe a good case has been made), I would prefer the function to be called "nth_root" which is unequivocal and readable (it is also close to what Matlab uses: http://www.mathworks.com/help/matlab/ref/nthroot.html )

It seems that Matlab's reason for inclusion doesn't have anything to do with precision; instead, they say "While power is a more efficient function for computing the roots of numbers, in cases where both real and complex roots exist, power returns only the complex roots. In these cases, use nthroot to obtain the real roots."   Mathematica uses Surd[n, x] for that purpose.

Outside of Matlab and Mathematica, I'm not seeing this function elsewhere (on my calculator, in Java math, etc.).  This suggests that the need is minimal.

As an alternative, we could follow the model used in the itertools module and include "recipes" for functions that don't meet that bar for inclusion in the standard library.   Here's one recipe I found after a few seconds of googling:

    from decimal import Decimal, getcontext
     
    def nthroot (n, A, precision):
        getcontext().prec = precision
     
        n = Decimal(n)
        x_0 = A / n #step 1: make a while guess.
        x_1 = 1     #need it to exist before step 2
        while True:
            #step 2:
            x_0, x_1 = x_1, (1 / n)*((n - 1)*x_0 + (A / (x_0 ** (n - 1))))
            if x_0 == x_1:
                return x_1

Out of Steven's original suggestions, I most prefer "leave nth_root in statistics as a private function".
History
Date User Action Args
2016-06-20 20:19:58rhettingersetrecipients: + rhettinger, tim.peters, mark.dickinson, belopolsky, steven.daprano, skrah, serhiy.storchaka
2016-06-20 20:19:58rhettingersetmessageid: <1466453998.45.0.507252447891.issue27353@psf.upfronthosting.co.za>
2016-06-20 20:19:58rhettingerlinkissue27353 messages
2016-06-20 20:19:57rhettingercreate