1Function: issquarefree
2Section: number_theoretical
3C-Name: issquarefree
4Prototype: lG
5Help: issquarefree(x): true(1) if x is squarefree, false(0) if not.
6Description:
7 (gen):bool       issquarefree($1)
8Doc: true (1) if $x$ is squarefree, false (0) if not. Here $x$ can be an
9 integer or a polynomial with coefficients in an integral domain.
10 \bprog
11 ? issquarefree(12)
12 %1 = 0
13 ? issquarefree(6)
14 %2 = 1
15 ? issquarefree(x^3+x^2)
16 %3 = 0
17 ? issquarefree(Mod(1,4)*(x^2+x+1))    \\ Z/4Z is not a domain !
18  ***   at top-level: issquarefree(Mod(1,4)*(x^2+x+1))
19  ***                 ^--------------------------------
20  *** issquarefree: impossible inverse in Fp_inv: Mod(2, 4).
21 @eprog\noindent A polynomial is declared squarefree if \kbd{gcd}$(x,x')$ is
22 $1$. In particular a nonzero polynomial with inexact coefficients is
23 considered to be squarefree. Note that this may be inconsistent with
24 \kbd{factor}, which first rounds the input to some exact approximation before
25 factoring in the apropriate domain; this is correct when the input is not
26 close to an inseparable polynomial (the resultant of $x$ and $x'$ is not
27 close to $0$).
28
29 An integer can be input in factored form as in arithmetic functions.
30 \bprog
31 ? issquarefree(factor(6))
32 %1 = 1
33 \\ count squarefree integers up to 10^8
34 ? c = 0; for(d = 1, 10^8, if (issquarefree(d), c++)); c
35 time = 3min, 2,590 ms.
36 %2 = 60792694
37 ? c = 0; forfactored(d = 1, 10^8, if (issquarefree(d), c++)); c
38 time = 45,348 ms. \\ faster !
39 %3 = 60792694
40 @eprog
41