Skip to content

Commit

Permalink
Add SquareFreeQ.
Browse files Browse the repository at this point in the history
  • Loading branch information
corywalker committed Jul 11, 2017
1 parent 1399b4c commit 23ae3a0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions expreduce/builtin_power.go
Expand Up @@ -271,5 +271,6 @@ func GetPowerDefinitions() (defs []Definition) {
defs = append(defs, Definition{
Name: "PolynomialGCD",
})
defs = append(defs, Definition{Name: "SquareFreeQ"})
return
}
19 changes: 19 additions & 0 deletions expreduce/resources/power.m
Expand Up @@ -366,3 +366,22 @@
ESameTest[-5-a+a^2, PolynomialGCD[15+13 a-a^2-2 a^3,5+a-a^2]]
]
};

SquareFreeQ::usage = "`SquareFreeQ[expr]` returns True if `expr` is a square-free polynomial.";
(*only works for univariate polynomials, does not support numbers *)
SquareFreeQ[ex_] := Module[{f = ex, expF, polyvar, fprime},
If[Length[Variables[f]] != 1, Return[False]];
expF = Expand[f];
polyvar = Variables[expF][[1]];
If[! PolynomialQ[expF, polyvar], Return[False]];
fprime = D[expF, polyvar];
PolynomialGCD[expF, fprime] === 1];
Attributes[SquareFreeQ] = {Protected, ReadProtected};
Tests`SquareFreeQ = {
ESimpleExamples[
ESameTest[False, SquareFreeQ[(x+1)(x+2)^2//Expand]],
ESameTest[True, SquareFreeQ[(x + 1) (x + 2)]],
ESameTest[True, SquareFreeQ[(2 x + 3) (x + 2) // Expand]],
ESameTest[False, SquareFreeQ[(2 x + 3)^2]]
]
};

0 comments on commit 23ae3a0

Please sign in to comment.