4 extern void sort_stack(int);
6 static void roots2(void);
7 static void roots3(void);
8 static void mini_solve(void);
24 if (car(p2
) == symbol(SETQ
) || car(p2
) == symbol(TESTEQ
)) {
34 if (car(p2
) == symbol(SETQ
) || car(p2
) == symbol(TESTEQ
)) {
49 if (p2
== symbol(NIL
))
58 stop("roots: 1st argument is not a polynomial");
74 stop("roots: the polynomial is not factorable, try nroots");
80 p1
->u
.tensor
->ndim
= 1;
81 p1
->u
.tensor
->dim
[0] = n
;
82 for (i
= 0; i
< n
; i
++)
83 p1
->u
.tensor
->elem
[i
] = stack
[h
+ i
];
103 if (car(p1
) == symbol(MULTIPLY
)) {
126 if (car(p1
) == symbol(POWER
) && ispoly(cadr(p1
), p2
) && isposint(caddr(p1
))) {
130 } else if (ispoly(p1
, p2
)) {
138 //-----------------------------------------------------------------------------
140 // Input: stack[tos - 2] polynomial
142 // stack[tos - 1] dependent symbol
144 // Output: stack roots on stack
146 // (input args are popped first)
148 //-----------------------------------------------------------------------------
178 // AX^2 + BX + C, X = (-B +/- (B^2 - 4AC)^(1/2)) / (2A)
242 "roots(6+11*x+6*x^2+x^3)",
245 "roots(a*x^2+b*x+c)",
246 "(-b/(2*a)-(-4*a*c+b^2)^(1/2)/(2*a),-b/(2*a)+(-4*a*c+b^2)^(1/2)/(2*a))",
248 "roots(3+7*x+5*x^2+x^3)",
251 "roots(x^3+x^2+x+1)",
255 "Stop: roots: the polynomial is not factorable, try nroots",
260 "roots(3 x + 12 == 24)",
263 "y=roots(x^2+b*x+c/k)[1]",
269 "y=roots(x^2+b*x+c/k)[2]",
275 "y=roots(a*x^2+b*x+c/4)[1]",
281 "y=roots(a*x^2+b*x+c/4)[2]",
294 test(__FILE__
, s
, sizeof s
/ sizeof (char *));