1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
|
/*===========================================================================
R <- IPRESPRS(r,A,B)
Integral polynomial resultant, subresultant polynomial remainder
sequence algorithm.
Inputs
r : a BETA-digit, r > 0.
A,B : in Z[X1,...,Xr], A and B non-zero, deg(A) >= deg(B).
Outputs
R : the resultant of A and B, computed using the
(non-modular) subresultant prs algorithm.
===========================================================================*/
#ifdef _OLD_
Word IPRESPRS(Word r, Word A, Word B)
{
Word G1,G2,G3,Gh3,R,S,d0,d1,g1,h0,h1,hs0,hs1,i,n1,n2,n3,rp,a,b;
Step1: /* Initialize. */
a = PDEG(A);
b = PDEG(B);
if (a < b) {
G1 = B;
G2 = A; }
else {
G1 = A;
G2 = B; }
if (b == 0) {
R = 1; /* Added 2/97 */
for(i = 1; i < r; i++) R = LIST2(0,R); /* Added 2/97 */
goto Return; } /* Added 2/97 */
n1 = PDEG(G1);
n2 = PDEG(G2);
d0 = 0;
d1 = n1 - n2;
rp = r - 1;
i = 1;
Step2: /* Compute Gh_{i+2}. */
Gh3 = IPPSR(r,G1,G2);
if (Gh3 == 0) {
if (PDEG(S) > 0)
R = 0;
else {
R = PLDCF(S);
if (a < b) {
if (ODD(a) && ODD(b))
R = IPNEG(rp,R); } }
goto Return; }
if (EVEN(d1) == 1)
Gh3 = IPNEG(r,Gh3);
n3 = PDEG(Gh3);
Step3: /* Compute hi. */
if (i > 1) {
g1 = PLDCF(G1);
h1 = IPEXP(rp,g1,d0);
if (i > 2) {
hs0 = IPEXP(rp,h0,d0 - 1);
h1 = IPQ(rp,h1,hs0);
hs0 = 0; } }
Step4: /* Compute G_{i+2}. */
if (i == 1)
G3 = Gh3;
else {
hs1 = IPEXP(rp,h1,d1);
hs1 = IPPROD(rp,g1,hs1);
hs1 = LIST2(0,hs1);
G3 = IPQ(r,Gh3,hs1);
hs1 = 0;
Gh3 = 0; }
Step5: /* Update. */
S = G3;
n1 = n2;
n2 = n3;
d0 = d1;
d1 = n1 - n2;
G1 = G2;
G2 = G3;
if (i > 1)
h0 = h1;
i = i + 1;
goto Step2;
Return: /* Prepare for return. */
return(R);
}
#else
/*===========================================================================
R <- IPRESPRS(r,A,B)
Integral polynomial resultant, polynomial remainder sequence method.
Inputs
r : a BETA-digit, r > 0.
A, B : integral polynomials having positive degrees.
Output
R : the resultant of A and B.
===========================================================================*/
Word IPRESPRS(r,A,B)
BDigit r;
Word A,B;
{
Word G1,G2,G3,Gh3,R,g1,g2,gs1,gs2,h0,h1,h2,hs0,hs1;
BDigit d0,d1,i,n1,n2,n3,rp;
Step1: /* Initialize. */
if (PDEG(A) >= PDEG(B)) {
G1 = A;
G2 = B; }
else {
G1 = B;
G2 = A; }
n1 = PDEG(G1);
n2 = PDEG(G2);
d0 = 0;
d1 = n1 - n2;
rp = r - 1;
i = 1;
Step2: /* Compute Gh_{i+2} and n_{i+2}. */
Gh3 = IPPSR(r,G1,G2);
if (Gh3 == 0) {
R = 0;
goto Return; }
if (EVEN(d1))
Gh3 = IPNEG(r,Gh3);
n3 = PDEG(Gh3);
Step3: /* Compute h_i. */
if (i > 1) {
g1 = PLDCF(G1);
h1 = IPEXP(rp,g1,d0);
if (i > 2) {
hs0 = IPEXP(rp,h0,d0 - 1);
h1 = IPEQ(rp,h1,hs0); } }
Step4: /* Compute G_{i+2}. */
if (i == 1)
G3 = Gh3;
else {
hs1 = IPEXP(rp,h1,d1);
hs1 = IPPROD(rp,g1,hs1);
hs1 = PMON(hs1,0);
G3 = IPEQ(r,Gh3,hs1); }
Step5: /* Update. */
n1 = n2;
n2 = n3;
d0 = d1;
d1 = n1 - n2;
G1 = G2;
G2 = G3;
if (i > 1)
h0 = h1;
i = i + 1;
if (n2 > 0)
goto Step2;
Step6: /* Finish. */
g1 = PLDCF(G1);
g2 = PLDCF(G2);
if (d1 == 1)
R = g2;
else {
if (i == 2) {
R = IPEXP(rp,g2,d1);
if (d0 != 1) {
gs1 = IPEXP(rp,g1,d0 * d1 - d0);
R = IPEQ(rp,R,gs1); } }
else {
if (d0 == 1)
h1 = g1;
else {
hs0 = IPEXP(rp,h0,d0-1);
gs1 = IPEXP(rp,g1,d0);
h1 = IPEQ(rp,gs1,hs0); }
hs1 = IPEXP(rp,h1,d1-1);
gs2 = IPEXP(rp,g2,d1);
h2 = IPEQ(rp,gs2,hs1);
R = IPPROD(rp,g2,h2);
R = IPEQ(rp,R,g2); } }
Return: /* Return R. */
return(R);
}
#endif
|