2008-06-26 06:40:25 +02:00
|
|
|
/* Return the leading coefficient of a polynomial.
|
|
|
|
|
|
|
|
Example
|
|
|
|
|
|
|
|
leading(5x^2+x+1,x)
|
|
|
|
|
|
|
|
Result
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
The result is undefined if P is not a polynomial. */
|
2008-05-03 07:23:17 +02:00
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "defs.h"
|
|
|
|
|
|
|
|
void
|
|
|
|
eval_leading(void)
|
|
|
|
{
|
|
|
|
push(cadr(p1));
|
|
|
|
eval();
|
|
|
|
push(caddr(p1));
|
|
|
|
eval();
|
|
|
|
p1 = pop();
|
|
|
|
if (p1 == symbol(NIL))
|
|
|
|
guess();
|
|
|
|
else
|
|
|
|
push(p1);
|
|
|
|
leading();
|
|
|
|
}
|
|
|
|
|
|
|
|
#define P p1
|
|
|
|
#define X p2
|
|
|
|
#define N p3
|
|
|
|
|
|
|
|
void
|
|
|
|
leading(void)
|
|
|
|
{
|
|
|
|
save();
|
|
|
|
|
|
|
|
X = pop();
|
|
|
|
P = pop();
|
|
|
|
|
2008-05-04 00:08:04 +02:00
|
|
|
push(P); // N = degree of P
|
2008-05-03 07:23:17 +02:00
|
|
|
push(X);
|
|
|
|
degree();
|
|
|
|
N = pop();
|
|
|
|
|
2008-05-04 00:08:04 +02:00
|
|
|
push(P); // divide through by X ^ N
|
2008-05-03 07:23:17 +02:00
|
|
|
push(X);
|
|
|
|
push(N);
|
|
|
|
power();
|
|
|
|
divide();
|
|
|
|
|
2008-05-04 00:08:04 +02:00
|
|
|
push(X); // remove terms that depend on X
|
2008-05-03 07:23:17 +02:00
|
|
|
filter();
|
|
|
|
|
|
|
|
restore();
|
|
|
|
}
|