Function: algdep
Section: linear_algebra
C-Name: algdep0
Prototype: GLD0,L,
Help: algdep(x,k,{flag=0}): algebraic relations up to degree n of x, using
 lindep([1,x,...,x^(k-1)], flag).
Doc: \sidx{algebraic dependence}
 $x$ being real/complex, or $p$-adic, finds a polynomial of degree at most
 $k$ with integer coefficients having $x$ as approximate root. Note that the
 polynomial which is obtained is not necessarily the ``correct'' one. In fact
 it is not even guaranteed to be irreducible. One can check the closeness
 either by a polynomial evaluation (use \tet{subst}), or by computing the
 roots of the polynomial given by \kbd{algdep} (use \tet{polroots}).

 Internally, \tet{lindep}$([1,x,\ldots,x^k], \fl)$ is used.
 A non-zero value of $\fl$ may improve on the default behavior
 if the input number is known to a \emph{huge} accuracy, and you suspect the
 last bits are incorrect  (this truncates the number, throwing away the least
 significant bits), but default values are usually sufficient:
 \bprog
 ? \p200
 ? algdep(2^(1/6)+3^(1/5), 30);      \\ wrong in 0.8s
 ? algdep(2^(1/6)+3^(1/5), 30, 100); \\ wrong in 0.4s
 ? algdep(2^(1/6)+3^(1/5), 30, 170); \\ right in 0.8s
 ? algdep(2^(1/6)+3^(1/5), 30, 200); \\ wrong in 1.0s
 ? \p250
 ? algdep(2^(1/6)+3^(1/5), 30);      \\ right in 1.0s
 ? algdep(2^(1/6)+3^(1/5), 30, 200); \\ right in 1.0s
 ? \p500
 ? algdep(2^(1/6)+3^(1/5), 30);      \\ right in 2.9s
 ? \p1000
 ? algdep(2^(1/6)+3^(1/5), 30);      \\ right in 10.6s
 @eprog\noindent
 The changes in \kbd{defaultprecision} only affect the quality of the
 initial approximation to $2^{1/6} + 3^{1/5}$, \kbd{algdep} itself uses
 exact operations (the size of its operands depend on the accuracy of the
 input of course: more accurate input means slower operations).

 Proceeding by increments of 5 digits of accuracy, \kbd{algdep} with default
 flag produces its first correct result at 205 digits, and from then on a
 steady stream of correct results.

 The above example is the test case studied in a 2000 paper by Borwein and
 Lisonek: Applications of integer relation algorithms, \emph{Discrete Math.},
 {\bf 217}, p.~65--82. The version of PARI tested there was 1.39, which
 succeeded reliably from precision 265 on, in about 200 as much time as the
 current version.

Variant: Also available is \fun{GEN}{algdep}{GEN x, long k} ($\fl=0$).
