%mathpiper,def="jSolveUniPoly"

//Retract("jSolveUniPoly",*);

10 # jSolveUniPoly( _lhs==_rhs, var_IsAtom ) <--
[
   jSolveUniPoly(lhs-rhs,var);
];

15 # jSolveUniPoly( poly_IsPolynomial, var_IsAtom )_(Length(VarList(poly))=1) <--
[
   If(InVerboseMode(),Tell(jSolveUniPoly,{poly,var}));
   Local(factorList,f,fac,mult,ii,answer);
   factorList := Factors(poly);
   If(InVerboseMode(),Tell("   ",factorList));
   answer := {};
   ForEach(f,factorList)
    [
        {fac,mult} := f;
        soln := Solve(fac,var);
        If(InVerboseMode(),[Tell("      ",{fac,mult});Tell("      ",soln);]);
        ForEach(ii,1 .. mult)
         [  DestructiveAppend(answer,soln); ];
    ];
    answer;
];

20 # jSolveUniPoly( poly_IsPolynomial, var_IsAtom ) <-- Failed;


%/mathpiper

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




%mathpiper_docs,name="jSolveUniPoly",categories="User Functions;Solvers (Symbolic)"
*CMD jSolveUniPoly --- solve (find the roots of) a strictly univariate polynomial using JAS
*STD
*CALL
	jSolveUniPoly(eq, var)

*PARMS

{eq} -- equation to solve

{var} -- variable to solve for

*DESC

This command tries to solve the polynomial equation by factoring. 
If {eq} does not contain the {==} operator, it is assumed that the 
user wants to solve $eq ==0$. 
The result is a list of equations of the form {var == value}, each
representing a solution of the given equation. The {Where} operator
can be used to substitute this solution in another expression. If the
given equation {eq} does not have any solutions, or if {jSolveUniPoly} is
unable to find any, then an empty list is returned.

*SEE Solve, PSolve, Where, ==
%/mathpiper_docs

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


