ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 31 Oct 2015 19:42:58 +0100Reliable integer root function?https://ask.sagemath.org/question/30375/reliable-integer-root-function/Does Sage have an integer_root(x, n) function which reliable (!) returns floor(root(x,n)) for n-th roots? I think that
it should be offered as a Sage function if not.
This seems to work:
def integer_root(x, n): return gp('sqrtnint(%d,%d)' %(x,n))
Integer n-th root of x, where x is non-negative integer.
// Related: question 10730.
**Edit:** The answer of castor below shows a second way to define such a function:
def integer_root(x, n): return ZZ(x).nth_root(n, truncate_mode=1)[0]
Which version will be faster?Peter LuschnySat, 31 Oct 2015 19:42:58 +0100https://ask.sagemath.org/question/30375/Is there a simple way to deal with computing real nth roots for n a natural number?https://ask.sagemath.org/question/10730/is-there-a-simple-way-to-deal-with-computing-real-nth-roots-for-n-a-natural-number/I am trying to use the nth root for natural numbers in computations and display the result as a decimal to four places.
I can't find a simple reference for these functions. Is there an nroot(x,n) function?Martin FlashmanTue, 12 Nov 2013 19:07:58 +0100https://ask.sagemath.org/question/10730/