%mathpiper,def="SturmSequence"

//Retract("SturmSequence",*);

/** SturmSequence(p) : generate a Sturm sequence for a univariate polynomial
 */

10 # SturmSequence(_p,_var) <--
[
  Local(result,i,deg,nt);
  If(InVerboseMode(),Tell(10));
  result := {p,`Differentiate(@var)(@p)};
  deg    := Degree(p,var);
  For(i:=3,i<=deg+1,i++)
  [
    nt := -NormalForm(MultiDivide(MM(result[i-2],{var}),{MM(result[i-1],{var})})[2]);//??
    DestructiveAppend(result,nt);
  ];
  result;
];

20 # SturmSequence(_p)_(Length(VarList(p))=1) <-- SturmSequence(p,VarList(p)[1]);

30 # SturmSequence(_p) <-- Check(Length(VarList(p))=1,"Argument","Input must be Univariate Polynomial. ");


%/mathpiper

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

