void factorpoly(void) { save(); p2 = pop(); p1 = pop(); if (!find(p1, p2)) { push(p1); restore(); return; } if (!ispoly(p1, p2)) { push(p1); restore(); return; } if (!issymbol(p2)) { push(p1); restore(); return; } push(p1); push(p2); yyfactorpoly(); restore(); }
static void roots3(void) { save(); p2 = pop(); p1 = pop(); if (car(p1) == symbol(POWER) && ispoly(cadr(p1), p2) && isposint(caddr(p1))) { push(cadr(p1)); push(p2); mini_solve(); } else if (ispoly(p1, p2)) { push(p1); push(p2); mini_solve(); } restore(); }
void eval_roots(void) { // A == B -> A - B p2 = cadr(p1); if (car(p2) == symbol(SETQ) || car(p2) == symbol(TESTEQ)) { push(cadr(p2)); eval(); push(caddr(p2)); eval(); subtract(); } else { push(p2); eval(); p2 = pop(); if (car(p2) == symbol(SETQ) || car(p2) == symbol(TESTEQ)) { push(cadr(p2)); eval(); push(caddr(p2)); eval(); subtract(); } else push(p2); } // 2nd arg, x push(caddr(p1)); eval(); p2 = pop(); if (p2 == symbol(NIL)) guess(); else push(p2); p2 = pop(); p1 = pop(); if (!ispoly(p1, p2)) stop("roots: 1st argument is not a polynomial"); push(p1); push(p2); roots(); }
void eval_nroots(void) { volatile int h, i, k, n; push(cadr(p1)); eval(); push(caddr(p1)); eval(); p2 = pop(); if (p2 == symbol(NIL)) guess(); else push(p2); p2 = pop(); p1 = pop(); if (!ispoly(p1, p2)) stop("nroots: polynomial?"); // mark the stack h = tos; // get the coefficients push(p1); push(p2); n = coeff(); if (n > YMAX) stop("nroots: degree?"); // convert the coefficients to real and imaginary doubles for (i = 0; i < n; i++) { push(stack[h + i]); real(); yyfloat(); eval(); p1 = pop(); push(stack[h + i]); imag(); yyfloat(); eval(); p2 = pop(); if (!isdouble(p1) || !isdouble(p2)) stop("nroots: coefficients?"); c[i].r = p1->u.d; c[i].i = p2->u.d; } // pop the coefficients tos = h; // n is the number of coefficients, n = deg(p) + 1 monic(n); for (k = n; k > 1; k--) { findroot(k); if (fabs(a.r) < DELTA) a.r = 0.0; if (fabs(a.i) < DELTA) a.i = 0.0; push_double(a.r); push_double(a.i); push(imaginaryunit); multiply(); add(); divpoly(k); } // now make n equal to the number of roots n = tos - h; if (n > 1) { sort_stack(n); p1 = alloc_tensor(n); p1->u.tensor->ndim = 1; p1->u.tensor->dim[0] = n; for (i = 0; i < n; i++) p1->u.tensor->elem[i] = stack[h + i]; tos = h; push(p1); } }