%mathpiper,def="SquareFree"

//Retract("SquareFree",*);


10 # SquareFree(_p)_(Length(VarList(p))!=1) <-- Check(False,"Argument","Input must be Univariate");

12 # SquareFree(_p) <-- SquareFree(p,VarList(p)[1]);

14 # SquareFree(_p,_var)_(Not IsPolynomial(p,var)) <-- Check(False,"Argument","Input must be Univariate Polynomial");

16 # SquareFree(_p,_var) <--
[
  /*
  Local(dp,gcd);
  dp:=MakeMultiNomial(`(Differentiate(var)(@p)),{var});

  p:=MakeMultiNomial(p,{var});
  gcd:=MultiGcd(p,dp);
  NormalForm(MultiDivide(p,{gcd})[1][1]);
  */
  Quotient(p,Gcd(p,(`(Differentiate(@var)(@p)))));
];

%/mathpiper

    %output,preserve="false"
      Result: True
.   %/output

    

  
    



%mathpiper_docs,name="SquareFree",categories="User Functions;Polynomials (Operations)"
*CMD SquareFree --- return the square-free part of a univariate polynomial
*STD
*CALL
	SquareFree(p)

*PARMS

{p} - a univariate polynomial

*DESC

Given a polynomial 
$$ p = p[1]^n[1]* ... * p[m]^n[m] $$
with irreducible polynomials $ p[i] $,
return the square-free version part (with all the factors having
multiplicity 1):
$$ p[1]* ... * p[m] $$

Throws "argument" exception if input is not a univariate polynomial.

*E.G.

In> Expand((x+1)^5)
Result: x^5+5*x^4+10*x^3+10*x^2+5*x+1;
In> SquareFree(%)
Result: (x+1)/5;
In> Monic(%)
Result: x+1;

*SEE FindRealRoots, RealRootsCount, MinimumBound, MaximumBound, Factor
%/mathpiper_docs

    %output,preserve="false"
      
.   %/output


