SquareFreeQ[expr]
gives True if expr is a square-free polynomial or number, and False otherwise.
SquareFreeQ[expr,vars]
gives True if expr is square free with respect to the variables vars.
SquareFreeQ
SquareFreeQ[expr]
gives True if expr is a square-free polynomial or number, and False otherwise.
SquareFreeQ[expr,vars]
gives True if expr is square free with respect to the variables vars.
Details and Options
- SquareFreeQ is typically used to test whether a number or a polynomial is square free.
- An integer n is square free if it is divisible by no perfect square other than 1.
- SquareFreeQ[expr] returns False unless expr is manifestly square free.
- With the setting GaussianIntegers->True, SquareFreeQ tests whether expr is Gaussian square free.
- For integers m and n, SquareFreeQ[m+I n] automatically works over Gaussian integers.
- The following options can be given:
-
GaussianIntegers Automatic whether to allow Gaussian integers Modulus 0 modulus for polynomial coefficients
Examples
open all close allBasic Examples (2)
Scope (5)
SquareFreeQ works over integers:
SquareFreeQ[20]SquareFreeQ[3 + 2I]SquareFreeQ[2, GaussianIntegers -> True]SquareFreeQ[2 / 3]SquareFreeQ[6 + 6x + x ^ 2]SquareFreeQ[x ^ 3 - x ^ 2y]Specify the variable in a polynomial:
SquareFreeQ[x y ^ 2, x]SquareFreeQ[x y ^ 2, y]Polynomials over a finite field:
SquareFreeQ[x ^ 2 + 1, Modulus -> 2]SquareFreeQ[10 ^ 70 + 3]Options (2)
GaussianIntegers (1)
Applications (8)
Basic Applications (3)
Highlight square-free numbers:
Multicolumn[If[SquareFreeQ[#], Style[#, Red, Bold], #]& /@ Range[100], 10, ...]Generate random square-free integers:
randomSquareFree[m_] := Table[Times@@Union[RandomPrime[{2, 1000}, RandomInteger[{1, 5}]]], {m}];randomSquareFree[5]AllTrue[%, SquareFreeQ]Square-free Gaussian integers:
ArrayPlot[Table[Boole[SquareFreeQ[x + I y, GaussianIntegers -> True]], {x, 300}, {y, 300}]]Number Theory (5)
The central binomial coefficients Binomial[2n,n] are not square free for
:
And @@ Table[Not[SquareFreeQ[Binomial[2n, n]]], {n, 5, 2 ^ 10}]Find the fraction of the first
numbers that are square free:
Length@Select[Range[10 ^ 5], SquareFreeQ] / 10 ^ 5//N1 / Zeta[2]//NThe polynomial p[x]/PolynomialGCD[p[x],p'[x]] is always square free:
p = (x + 1) ^ 3(x + 2) ^ 2(x + 3) ^ 2;q = p / PolynomialGCD[p, D[p, x]]//FullSimplifySquareFreeQ[q]The distribution of square-free numbers over integers:
data = Select[Range[100], SquareFreeQ];𝒟 = EmpiricalDistribution[data];DiscretePlot[Evaluate[CDF[𝒟, x]], {x, 1, 100}, ExtentSize -> Right]The distribution of square-free numbers over the Gaussian integers:
data = {Re[#], Im[#]}& /@ Select[Flatten[Table[a + b I, {a, 500}, {b, 500}]], SquareFreeQ];𝒟 = EmpiricalDistribution[data];DiscretePlot3D[Evaluate[CDF[𝒟, {x, y}]], {x, 1, 5}, {y, 1, 5}, ExtentSize -> Right]Properties & Relations (8)
A number that is divisible by a square is not square free:
Divisible[12, 4]SquareFreeQ[12]In the prime factorization of a square-free number, the exponents of primes are all 1:
SquareFreeQ[210]FactorInteger[210]PrimeNu is equal to PrimeOmega for square-free numbers:
SquareFreeQ[14]PrimeNu[14] == PrimeOmega[14]MoebiusMu is zero for non-square-free integers:
SquareFreeQ[12]MoebiusMu[12]Numbers that are prime powers and square free are prime numbers:
PrimePowerQ[17] && SquareFreeQ[17]PrimeQ[17]The discriminant of a quadratic non-square-free polynomial is 0:
SquareFreeQ[x ^ 2 - 2x + 1, x]Discriminant[x ^ 2 - 2x + 1, x]Square factors can be found using FactorSquareFreeList:
SquareFreeQ[Expand[(x + 1) ^ 3(x + 2) ^ 2(x + 3) ^ 2]]FactorSquareFreeList[Expand[(x + 1) ^ 3(x + 2) ^ 2(x + 3) ^ 2]]Simplify symbolic expressions:
Simplify[SquareFreeQ[a ^ 2], a∈Integers]Neat Examples (3)
Plot the prime numbers that are the sum of three squares:
ArrayMesh[Boole[Table[SquareFreeQ[a ^ 2 + b ^ 2 + c ^ 2], {a, 10}, {b, 10}, {c, 10}]]]Square-free Gaussian integers:
ArrayPlot[Table[Boole[SquareFreeQ[x + I y]], {x, 50}, {y, 50}]]Plot the Ulam spiral of square-free numbers:
ulam[n_] := Partition[Permute[Range[n ^ 2], Accumulate[Take[Flatten[{{n ^ 2 + 1} / 2, Table
[(-1) ^ j i, {j, n}, {i, {-1, n}}, {j}]}], n ^ 2]]], n];ArrayPlot[ulam[101]MapAt[Boole[SquareFreeQ[#]]&, ulam[101], {All, All}], ColorFunction -> "Rainbow", ColorRules -> {0 -> White}]Related Guides
History
Text
Wolfram Research (2007), SquareFreeQ, Wolfram Language function, https://reference.wolfram.com/language/ref/SquareFreeQ.html.
CMS
Wolfram Language. 2007. "SquareFreeQ." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/SquareFreeQ.html.
APA
Wolfram Language. (2007). SquareFreeQ. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/SquareFreeQ.html
BibTeX
@misc{reference.wolfram_2026_squarefreeq, author="Wolfram Research", title="{SquareFreeQ}", year="2007", howpublished="\url{https://reference.wolfram.com/language/ref/SquareFreeQ.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_squarefreeq, organization={Wolfram Research}, title={SquareFreeQ}, year={2007}, url={https://reference.wolfram.com/language/ref/SquareFreeQ.html}, note=[Accessed: 13-June-2026]}