0

I am making a symbolic computation library which supports symbolic polynomials (both univariate and multivariate) and among other things I would like to support (possibly truncated) nth root (radical) computation of a (univariate or multivariate) polynomial since this computation is needed for some other things.

So lets say we have a polynomial $p(X) = \sum_{i}{a_{i}X^{i}}$ and I need an algorithm for $\sqrt[n]{p(X)}$.

I have found this post on computing the square root of a polynomial but I dont quite get it but also I would like an algorithm for nth root.

Library can compute all primitive operations of polynomials (both univariate and multivariate) on a general ring of coeffcients (ie add/sub/mul/div/mod/pow/derivative). (For reference library is on github)

Please provide a step-by-step algorithm in your answer or a link to such algorithm so I can test it.

PS. I tried using a variant of Newton's method for computing nth root and adapted it to polynomial operations but result is completely off, not even close.

Note: If polynomial is not a perfect nth power then a truncated power series can be computed up to some limit (eg truncated Taylor series) as an approximation. For example the square root algorithm on PlanetMath computes the Taylor series if poly is not perfect power of 2.

if poly is not a perfect nth power or power series approximation cannot be computed is fine for me if algorithm throws an error.

Thank you.

Nikos M.
  • 2,158
  • 2
    Are you aware that in general the $n^{th}$ root does not simplify ? What do you call a truncated root ? What would be $\sqrt{x+1}$ ?? –  Feb 18 '20 at 08:07
  • Yes of course, if poly is not a perfect nth power, then a truncated power series (up to some imit) can be computed (ie the Taylor series truncated) – Nikos M. Feb 18 '20 at 08:21
  • 2
    What would be $\sqrt{x^2+x}$ ? –  Feb 18 '20 at 08:23
  • @YvesDaoust, of cousre a non perfect nth power can be only approximated up to some limit (eg truincated taylor series is fine for me) – Nikos M. Feb 18 '20 at 08:24
  • 3
    What would be $\sqrt{x^2+x}$ ? –  Feb 18 '20 at 08:25
  • @YvesDaoust, again a truncated taylor expansion (up to some limit) is fine for my needs – Nikos M. Feb 18 '20 at 08:26
  • 3
    What is the Taylor series for $\sqrt{x^2+x}$ ??? –  Feb 18 '20 at 08:27
  • @YvesDaoust, then in that case algorithm can throw an error I dont mind as long as I can compute perfect powers and approximations (truncated taylor series) and ignore those that do not have one – Nikos M. Feb 18 '20 at 08:29
  • 1
    The square root algorithm generalizes to $n^{th}$ root. For the case of the exact root, the degree must be a multiple of $n$. You take the $n^{th}$ root of the leading term and subtract its $n^{th}$ power from the polynomial. Then cancel the next term with a second power if you can, and subtract the binomial to the $n^{th}$... –  Feb 18 '20 at 08:49
  • For Taylor, it may be better to take the constant term apart and develop $\sqrt[n]{p_0+x q(x)}$ using the scalar formula. –  Feb 18 '20 at 08:49
  • @YvesDaoust, can you expand your comment into an answer with an algorithm. I am aware that the square root algorithm readily generalises to nth root, however I have trouble understanding it correctly, so that is why I am asking for a step-by-step guidance. Thanks – Nikos M. Feb 18 '20 at 08:53

2 Answers2

2

Suggestion:

Write $p(x)$ as $p_0(x)(1+x\,q(x))$ and compute

$$\sqrt[n]{p(x)}=\sqrt[n]{p_0(x)}\sum_{k=0}^d\binom{1/n}kx^k(q(x))^k.$$

You don't need to fully compute the powers of $q$, you can stop at the highest power that does not exceed $d-k$.

Lehs
  • 13,791
  • 4
  • 25
  • 77
  • what is $d$? the degree of the polynomial? If so what about multivariate polys, which degree whould be used? is there a computationaly more efficient method (ie one that generalises the square root algorithm)? – Nikos M. Feb 18 '20 at 08:58
  • @NikosM.: what makes you think that this is inefficient ? –  Feb 18 '20 at 09:00
  • I would not like to compute binomial coefiicients all the time. Also $1/n$ would be a rational and my binomial routines only work with (big) integers. – Nikos M. Feb 18 '20 at 09:01
  • Ok I missed $q(x)$ from above. – Nikos M. Feb 18 '20 at 09:05
  • Is it possible to generalise the square root algorthm that uses primitive operations only (and roots of coefficients and monomials)? I have those already. If you can do that I can accept the answer – Nikos M. Feb 18 '20 at 09:08
  • 1
    @NikosM.: computing those binomial coefficients is nothing compare to the whole workload. They are fractions. –  Feb 18 '20 at 09:11
  • Polynomial operations and powers of polynomials indeed use much computing power (although algorithms are optimised), yet I feel although the formula is correct that the binomial coeffs can be avoided or maybe computed recursively with only one operation per iteration. Still I am looking for a generalisation of square root algorithm but with step-by-step explanation as the references I have found (included in the question) are unclear to me. – Nikos M. Feb 18 '20 at 09:14
  • I just noticed that the formula gives $0$ for the square root $p(x)=x^2$ as $p_0$ is zero – Nikos M. Feb 18 '20 at 09:17
  • @NikosM.: of course. –  Feb 18 '20 at 11:05
  • I managed to understand the square root / long division algorithm and also generalise it to k-th root, see my answer – Nikos M. Feb 19 '20 at 10:45
1

I managed to decipher the square root algorithm referenced in the question and generalise it to n-th root algorithm.

Algorithm: Compute nth root/radical of polynomial $p(X) = \sum_{i}a_iX^i$

Preliminary: Arrange the polynomial from lowest degree term up to highest degree term or if multivariate do same according to some monomial ordering (eg LEX). $LT(p(X))$ refers to the leading term according to monomial order and $TT(p(X))$ refers to the tail / last term according to monomial order. Algorithm works both if LT is used instead of TT below but with TT power series approximation (if $p(X)$ is not a perfect nth power) is easier to compute up to any desired accuracy. $maxdeg(p(X))$ refers to maximum power that exists in $p(X)$ in any variable (if multivariate). $maxterms$ is a user-defined limit and refers to maximum amount of terms to be computed if a power series approximation is the result. Eg up to $6$ terms of Taylor series expansion (if possible).

  • Check: If $p(X)=0$ or $p(X)=1$ return $p(X)$
  • Init: $i \leftarrow 0, nterms \leftarrow 0, \text{ } r_{i}(X) \leftarrow \sqrt[n]{TT(p(X))}$
  • Step 1: if $nterms \geq maxterms$ return $r_{i}(X)$ else goto to Step 2
  • Step 2: $d_{i}(X) \leftarrow p(X)-r_{i}(X)^{n}$
  • step 3: if $d_{i}(X)=0$ return $r_{i}(X)$ else goto to Step 4
  • Step 4: $q_{i}(X) \leftarrow TT(d_{i}(X)) \text{ }/\text{ } TT(nr_{i}(X)^{n-1})$
  • Step 5: if $q_{i}(X)=0$ return $r_{i}(X)$ else goto to Step 6
  • Step 6: $r_{i+1}(X) \leftarrow r_{i}(X) + q_{i}(X)$
  • Step 7: if $n \cdot maxdeg(r_{i+1}(X)) > maxdeg(p(X))$ this means that $p(X)$ is not a perfect nth power and that a power series approximation is being computed. $nterms \leftarrow nterms+1$
  • Step 8: set $i \leftarrow i+1$ and goto Step 1

Optionally one can normalise returned $r(X)$ to have positive leading term coefficient if $n$ is a multiple of $2$, since in that case both $r(X)$ and $-r(X)$ are roots.

My library is updated on github to use the above algorithm for computing nth radicals of polynomials.

Above algorithm correctly passes the example tests:

$p \in Q[x]$

$\sqrt{x^2} = x$

$\sqrt{(x^2)^2} = x^2$

$\sqrt[5]{(x+1)^5} = x+1$

$\sqrt{9x^4+6x^3-11x^2-4x+4} = -3x^2-x+2$

$\sqrt{x+1}=\frac{7}{256}x^5-\frac{5}{128}x^4+\frac{1}{16}x^3-\frac{1}{8}x^2+\frac{1}{2}x+1$ (truncated Taylor series up to maxterms)

$p \in Q[x, y]$

$\sqrt{4x^2-12xy+9y^2} = -2x+3y$

Nikos M.
  • 2,158