version 1.9, 2006/11/08 07:34:33 |
version 1.10, 2018/03/29 01:32:50 |
|
|
* DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, |
* DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, |
* PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. |
* PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. |
* |
* |
* $OpenXM: OpenXM_contrib2/asir2000/builtin/pdiv.c,v 1.8 2004/06/30 04:29:38 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/builtin/pdiv.c,v 1.9 2006/11/08 07:34:33 noro Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
#include "parse.h" |
#include "parse.h" |
|
|
void Pudiv(); |
void Pudiv(); |
|
|
struct ftab pdiv_tab[] = { |
struct ftab pdiv_tab[] = { |
{"sdiv",Psdiv,-3}, |
{"sdiv",Psdiv,-3}, |
{"srem",Psrem,-3}, |
{"srem",Psrem,-3}, |
{"prem",Pprem,-3}, |
{"prem",Pprem,-3}, |
{"sdiv_gf2n",Psdiv_gf2n,2}, |
{"sdiv_gf2n",Psdiv_gf2n,2}, |
{"srem_gf2n",Psrem_gf2n,2}, |
{"srem_gf2n",Psrem_gf2n,2}, |
{"gcd_gf2n",Pgcd_gf2n,2}, |
{"gcd_gf2n",Pgcd_gf2n,2}, |
{"sqr",Psqr,-3}, |
{"sqr",Psqr,-3}, |
{"tdiv",Ptdiv,-3}, |
{"tdiv",Ptdiv,-3}, |
{"udiv",Pudiv,2}, |
{"udiv",Pudiv,2}, |
{"sdivm",Psdivm,-4}, |
{"sdivm",Psdivm,-4}, |
{"sremm",Psremm,-4}, |
{"sremm",Psremm,-4}, |
{"sqrm",Psqrm,-4}, |
{"sqrm",Psqrm,-4}, |
{"inva_mod",Pinva_mod,3}, |
{"inva_mod",Pinva_mod,3}, |
{"srem_mod",Psrem_mod,3}, |
{"srem_mod",Psrem_mod,3}, |
{"ugcd",Pugcd,2}, |
{"ugcd",Pugcd,2}, |
{"urem",Purem,2}, |
{"urem",Purem,2}, |
{0,0,0}, |
{0,0,0}, |
}; |
}; |
|
|
void Psdiv(arg,rp) |
void Psdiv(arg,rp) |
NODE arg; |
NODE arg; |
Obj *rp; |
Obj *rp; |
{ |
{ |
P q,r,dnd,dnd1,dvr,dvr1; |
P q,r,dnd,dnd1,dvr,dvr1; |
V v; |
V v; |
VL vl; |
VL vl; |
|
|
asir_assert(ARG0(arg),O_P,"sdiv"); |
asir_assert(ARG0(arg),O_P,"sdiv"); |
asir_assert(ARG1(arg),O_P,"sdiv"); |
asir_assert(ARG1(arg),O_P,"sdiv"); |
dnd = (P)ARG0(arg); dvr = (P)ARG1(arg); |
dnd = (P)ARG0(arg); dvr = (P)ARG1(arg); |
if ( argc(arg) == 3 ) { |
if ( argc(arg) == 3 ) { |
v = VR((P)ARG2(arg)); |
v = VR((P)ARG2(arg)); |
change_mvar(CO,dnd,v,&dnd1); change_mvar(CO,dvr,v,&dvr1); |
change_mvar(CO,dnd,v,&dnd1); change_mvar(CO,dvr,v,&dvr1); |
reordvar(CO,v,&vl); |
reordvar(CO,v,&vl); |
divsrp(vl,dnd1,dvr1,&q,&r); |
divsrp(vl,dnd1,dvr1,&q,&r); |
restore_mvar(CO,q,v,(P *)rp); |
restore_mvar(CO,q,v,(P *)rp); |
} else |
} else |
divsrp(CO,dnd,dvr,(P *)rp,&r); |
divsrp(CO,dnd,dvr,(P *)rp,&r); |
} |
} |
|
|
void Psrem(arg,rp) |
void Psrem(arg,rp) |
NODE arg; |
NODE arg; |
Obj *rp; |
Obj *rp; |
{ |
{ |
P q,r,dnd,dnd1,dvr,dvr1; |
P q,r,dnd,dnd1,dvr,dvr1; |
V v; |
V v; |
VL vl; |
VL vl; |
|
|
asir_assert(ARG0(arg),O_P,"srem"); |
asir_assert(ARG0(arg),O_P,"srem"); |
asir_assert(ARG1(arg),O_P,"srem"); |
asir_assert(ARG1(arg),O_P,"srem"); |
dnd = (P)ARG0(arg); dvr = (P)ARG1(arg); |
dnd = (P)ARG0(arg); dvr = (P)ARG1(arg); |
if ( argc(arg) == 3 ) { |
if ( argc(arg) == 3 ) { |
v = VR((P)ARG2(arg)); |
v = VR((P)ARG2(arg)); |
change_mvar(CO,dnd,v,&dnd1); change_mvar(CO,dvr,v,&dvr1); |
change_mvar(CO,dnd,v,&dnd1); change_mvar(CO,dvr,v,&dvr1); |
reordvar(CO,v,&vl); |
reordvar(CO,v,&vl); |
divsrp(vl,dnd1,dvr1,&q,&r); |
divsrp(vl,dnd1,dvr1,&q,&r); |
restore_mvar(CO,r,v,(P *)rp); |
restore_mvar(CO,r,v,(P *)rp); |
} else |
} else |
divsrp(CO,dnd,dvr,&q,(P *)rp); |
divsrp(CO,dnd,dvr,&q,(P *)rp); |
} |
} |
|
|
void Pprem(arg,rp) |
void Pprem(arg,rp) |
NODE arg; |
NODE arg; |
P *rp; |
P *rp; |
{ |
{ |
P q,r,dnd,dnd1,dvr,dvr1; |
P q,r,dnd,dnd1,dvr,dvr1; |
V v; |
V v; |
VL vl; |
VL vl; |
|
|
asir_assert(ARG0(arg),O_P,"prem"); |
asir_assert(ARG0(arg),O_P,"prem"); |
asir_assert(ARG1(arg),O_P,"prem"); |
asir_assert(ARG1(arg),O_P,"prem"); |
dnd = (P)ARG0(arg); dvr = (P)ARG1(arg); |
dnd = (P)ARG0(arg); dvr = (P)ARG1(arg); |
if ( !dvr ) error("prem : division by 0"); |
if ( !dvr ) error("prem : division by 0"); |
if ( !dnd ) { |
if ( !dnd ) { |
*rp = 0; return; |
*rp = 0; return; |
} |
} |
if ( argc(arg) == 3 ) { |
if ( argc(arg) == 3 ) { |
v = VR((P)ARG2(arg)); |
v = VR((P)ARG2(arg)); |
change_mvar(CO,dnd,v,&dnd1); change_mvar(CO,dvr,v,&dvr1); |
change_mvar(CO,dnd,v,&dnd1); change_mvar(CO,dvr,v,&dvr1); |
reordvar(CO,v,&vl); |
reordvar(CO,v,&vl); |
premp(vl,dnd1,dvr1,&r); |
premp(vl,dnd1,dvr1,&r); |
restore_mvar(CO,r,v,rp); |
restore_mvar(CO,r,v,rp); |
} else |
} else |
premp(CO,dnd,dvr,rp); |
premp(CO,dnd,dvr,rp); |
} |
} |
|
|
void Psqr(arg,rp) |
void Psqr(arg,rp) |
NODE arg; |
NODE arg; |
LIST *rp; |
LIST *rp; |
{ |
{ |
P q,q1,r,r1,dnd,dnd1,dvr,dvr1; |
P q,q1,r,r1,dnd,dnd1,dvr,dvr1; |
NODE n,tn; |
NODE n,tn; |
V v; |
V v; |
VL vl; |
VL vl; |
|
|
asir_assert(ARG0(arg),O_P,"sqr"); |
asir_assert(ARG0(arg),O_P,"sqr"); |
asir_assert(ARG1(arg),O_P,"sqr"); |
asir_assert(ARG1(arg),O_P,"sqr"); |
dnd = (P)ARG0(arg); dvr = (P)ARG1(arg); |
dnd = (P)ARG0(arg); dvr = (P)ARG1(arg); |
if ( argc(arg) == 3 ) { |
if ( argc(arg) == 3 ) { |
v = VR((P)ARG2(arg)); |
v = VR((P)ARG2(arg)); |
change_mvar(CO,dnd,v,&dnd1); change_mvar(CO,dvr,v,&dvr1); |
change_mvar(CO,dnd,v,&dnd1); change_mvar(CO,dvr,v,&dvr1); |
reordvar(CO,v,&vl); |
reordvar(CO,v,&vl); |
divsrp(vl,dnd1,dvr1,&q1,&r1); |
divsrp(vl,dnd1,dvr1,&q1,&r1); |
restore_mvar(CO,q1,v,&q); restore_mvar(CO,r1,v,&r); |
restore_mvar(CO,q1,v,&q); restore_mvar(CO,r1,v,&r); |
} else |
} else |
divsrp(CO,dnd,dvr,&q,&r); |
divsrp(CO,dnd,dvr,&q,&r); |
MKNODE(tn,r,0); MKNODE(n,q,tn); MKLIST(*rp,n); |
MKNODE(tn,r,0); MKNODE(n,q,tn); MKLIST(*rp,n); |
} |
} |
|
|
void Psdiv_gf2n(arg,rp) |
void Psdiv_gf2n(arg,rp) |
NODE arg; |
NODE arg; |
GF2N *rp; |
GF2N *rp; |
{ |
{ |
GF2N dnd,dvr; |
GF2N dnd,dvr; |
UP2 q,r; |
UP2 q,r; |
|
|
dnd = (GF2N)ARG0(arg); dvr = (GF2N)ARG1(arg); |
dnd = (GF2N)ARG0(arg); dvr = (GF2N)ARG1(arg); |
if ( !dvr ) |
if ( !dvr ) |
error("sdiv_gf2n : division by 0"); |
error("sdiv_gf2n : division by 0"); |
else if ( !dnd ) |
else if ( !dnd ) |
*rp = 0; |
*rp = 0; |
else { |
else { |
qrup2(dnd->body,dvr->body,&q,&r); |
qrup2(dnd->body,dvr->body,&q,&r); |
MKGF2N(q,*rp); |
MKGF2N(q,*rp); |
} |
} |
} |
} |
|
|
void Psrem_gf2n(arg,rp) |
void Psrem_gf2n(arg,rp) |
NODE arg; |
NODE arg; |
GF2N *rp; |
GF2N *rp; |
{ |
{ |
GF2N dnd,dvr; |
GF2N dnd,dvr; |
UP2 q,r; |
UP2 q,r; |
|
|
dnd = (GF2N)ARG0(arg); dvr = (GF2N)ARG1(arg); |
dnd = (GF2N)ARG0(arg); dvr = (GF2N)ARG1(arg); |
if ( !dvr ) |
if ( !dvr ) |
error("srem_gf2n : division by 0"); |
error("srem_gf2n : division by 0"); |
else if ( !dnd ) |
else if ( !dnd ) |
*rp = 0; |
*rp = 0; |
else { |
else { |
qrup2(dnd->body,dvr->body,&q,&r); |
qrup2(dnd->body,dvr->body,&q,&r); |
MKGF2N(r,*rp); |
MKGF2N(r,*rp); |
} |
} |
} |
} |
|
|
void Pgcd_gf2n(arg,rp) |
void Pgcd_gf2n(arg,rp) |
NODE arg; |
NODE arg; |
GF2N *rp; |
GF2N *rp; |
{ |
{ |
GF2N p1,p2; |
GF2N p1,p2; |
UP2 gcd; |
UP2 gcd; |
|
|
p1 = (GF2N)ARG0(arg); p2 = (GF2N)ARG1(arg); |
p1 = (GF2N)ARG0(arg); p2 = (GF2N)ARG1(arg); |
if ( !p1 ) |
if ( !p1 ) |
*rp = p2; |
*rp = p2; |
else if ( !p2 ) |
else if ( !p2 ) |
*rp = p1; |
*rp = p1; |
else { |
else { |
gcdup2(p1->body,p2->body,&gcd); |
gcdup2(p1->body,p2->body,&gcd); |
MKGF2N(gcd,*rp); |
MKGF2N(gcd,*rp); |
} |
} |
} |
} |
|
|
void Ptdiv(arg,rp) |
void Ptdiv(arg,rp) |
NODE arg; |
NODE arg; |
P *rp; |
P *rp; |
{ |
{ |
P p1,p2,q1,q2,q,c1,c2,c; |
P p1,p2,q1,q2,q,c1,c2,c; |
int m; |
int m; |
|
|
p1 = (P)ARG0(arg); p2 = (P)ARG1(arg); |
p1 = (P)ARG0(arg); p2 = (P)ARG1(arg); |
asir_assert(p1,O_P,"tdiv"); |
asir_assert(p1,O_P,"tdiv"); |
asir_assert(p2,O_P,"tdiv"); |
asir_assert(p2,O_P,"tdiv"); |
if ( !p1 || !p2 ) |
if ( !p1 || !p2 ) |
*rp = 0; |
*rp = 0; |
else if ( (OID(p1) > O_P) || (OID(p2) > O_P ) ) |
else if ( (OID(p1) > O_P) || (OID(p2) > O_P ) ) |
*rp = 0; |
*rp = 0; |
else if ( argc(arg) == 3 ) { |
else if ( argc(arg) == 3 ) { |
m = QTOS((Q)ARG2(arg)); |
m = QTOS((Q)ARG2(arg)); |
ptomp(m,p1,&q1); ptomp(m,p2,&q2); |
ptomp(m,p1,&q1); ptomp(m,p2,&q2); |
if ( divtmp(CO,m,q1,q2,&q) ) |
if ( divtmp(CO,m,q1,q2,&q) ) |
mptop(q,rp); |
mptop(q,rp); |
else |
else |
*rp = 0; |
*rp = 0; |
} else if ( qpcheck((Obj)p1) && qpcheck((Obj)p2) ) { |
} else if ( qpcheck((Obj)p1) && qpcheck((Obj)p2) ) { |
ptozp(p1,1,(Q *)&c1,&q1); ptozp(p2,1,(Q *)&c2,&q2); |
ptozp(p1,1,(Q *)&c1,&q1); ptozp(p2,1,(Q *)&c2,&q2); |
if ( divtpz(CO,q1,q2,&q) ) { |
if ( divtpz(CO,q1,q2,&q) ) { |
divq((Q)c1,(Q)c2,(Q *)&c); mulp(CO,q,c,rp); |
divq((Q)c1,(Q)c2,(Q *)&c); mulp(CO,q,c,rp); |
} else |
} else |
*rp = 0; |
*rp = 0; |
} else { |
} else { |
if ( !divtp(CO,p1,p2,rp) ) |
if ( !divtp(CO,p1,p2,rp) ) |
*rp = 0; |
*rp = 0; |
} |
} |
} |
} |
|
|
void Pudiv(arg,rp) |
void Pudiv(arg,rp) |
NODE arg; |
NODE arg; |
LIST *rp; |
LIST *rp; |
{ |
{ |
P q,r,dnd,dvr; |
P q,r,dnd,dvr; |
NODE n,tn; |
NODE n,tn; |
|
|
asir_assert(ARG0(arg),O_P,"udiv"); |
asir_assert(ARG0(arg),O_P,"udiv"); |
asir_assert(ARG1(arg),O_P,"udiv"); |
asir_assert(ARG1(arg),O_P,"udiv"); |
dnd = (P)ARG0(arg); dvr = (P)ARG1(arg); |
dnd = (P)ARG0(arg); dvr = (P)ARG1(arg); |
udivpz(dnd,dvr,&q,&r); |
udivpz(dnd,dvr,&q,&r); |
MKNODE(tn,r,0); MKNODE(n,q,tn); MKLIST(*rp,n); |
MKNODE(tn,r,0); MKNODE(n,q,tn); MKLIST(*rp,n); |
} |
} |
|
|
void Psdivm(arg,rp) |
void Psdivm(arg,rp) |
NODE arg; |
NODE arg; |
Obj *rp; |
Obj *rp; |
{ |
{ |
P q,r,dnd,dnd1,dndm,dvr,dvr1,dvrm,t; |
P q,r,dnd,dnd1,dndm,dvr,dvr1,dvrm,t; |
V v; |
V v; |
VL vl; |
VL vl; |
int m; |
int m; |
|
|
asir_assert(ARG0(arg),O_P,"sdivm"); |
asir_assert(ARG0(arg),O_P,"sdivm"); |
asir_assert(ARG1(arg),O_P,"sdivm"); |
asir_assert(ARG1(arg),O_P,"sdivm"); |
asir_assert(ARG2(arg),O_N,"sdivm"); |
asir_assert(ARG2(arg),O_N,"sdivm"); |
dnd = (P)ARG0(arg); dvr = (P)ARG1(arg); m = QTOS((Q)ARG2(arg)); |
dnd = (P)ARG0(arg); dvr = (P)ARG1(arg); m = QTOS((Q)ARG2(arg)); |
if ( argc(arg) == 4 ) { |
if ( argc(arg) == 4 ) { |
v = VR((P)ARG3(arg)); |
v = VR((P)ARG3(arg)); |
change_mvar(CO,dnd,v,&dnd1); change_mvar(CO,dvr,v,&dvr1); |
change_mvar(CO,dnd,v,&dnd1); change_mvar(CO,dvr,v,&dvr1); |
reordvar(CO,v,&vl); |
reordvar(CO,v,&vl); |
ptomp(m,dnd1,&dndm); ptomp(m,dvr1,&dvrm); |
ptomp(m,dnd1,&dndm); ptomp(m,dvr1,&dvrm); |
divsrmp(vl,m,dndm,dvrm,&t,&r); mptop(t,&q); |
divsrmp(vl,m,dndm,dvrm,&t,&r); mptop(t,&q); |
restore_mvar(CO,q,v,(P *)rp); |
restore_mvar(CO,q,v,(P *)rp); |
} else { |
} else { |
ptomp(m,dnd,&dndm); ptomp(m,dvr,&dvrm); |
ptomp(m,dnd,&dndm); ptomp(m,dvr,&dvrm); |
divsrmp(CO,m,dndm,dvrm,&t,&r); mptop(t,(P *)rp); |
divsrmp(CO,m,dndm,dvrm,&t,&r); mptop(t,(P *)rp); |
} |
} |
} |
} |
|
|
void Psremm(arg,rp) |
void Psremm(arg,rp) |
NODE arg; |
NODE arg; |
Obj *rp; |
Obj *rp; |
{ |
{ |
P q,r,dnd,dnd1,dndm,dvr,dvr1,dvrm,t; |
P q,r,dnd,dnd1,dndm,dvr,dvr1,dvrm,t; |
V v; |
V v; |
VL vl; |
VL vl; |
int m; |
int m; |
|
|
asir_assert(ARG0(arg),O_P,"sremm"); |
asir_assert(ARG0(arg),O_P,"sremm"); |
asir_assert(ARG1(arg),O_P,"sremm"); |
asir_assert(ARG1(arg),O_P,"sremm"); |
asir_assert(ARG2(arg),O_N,"sremm"); |
asir_assert(ARG2(arg),O_N,"sremm"); |
dnd = (P)ARG0(arg); dvr = (P)ARG1(arg); m = QTOS((Q)ARG2(arg)); |
dnd = (P)ARG0(arg); dvr = (P)ARG1(arg); m = QTOS((Q)ARG2(arg)); |
if ( argc(arg) == 4 ) { |
if ( argc(arg) == 4 ) { |
v = VR((P)ARG3(arg)); |
v = VR((P)ARG3(arg)); |
change_mvar(CO,dnd,v,&dnd1); change_mvar(CO,dvr,v,&dvr1); |
change_mvar(CO,dnd,v,&dnd1); change_mvar(CO,dvr,v,&dvr1); |
reordvar(CO,v,&vl); |
reordvar(CO,v,&vl); |
ptomp(m,dnd1,&dndm); ptomp(m,dvr1,&dvrm); |
ptomp(m,dnd1,&dndm); ptomp(m,dvr1,&dvrm); |
divsrmp(vl,m,dndm,dvrm,&q,&t); mptop(t,&r); |
divsrmp(vl,m,dndm,dvrm,&q,&t); mptop(t,&r); |
restore_mvar(CO,r,v,(P *)rp); |
restore_mvar(CO,r,v,(P *)rp); |
} else { |
} else { |
ptomp(m,dnd,&dndm); ptomp(m,dvr,&dvrm); |
ptomp(m,dnd,&dndm); ptomp(m,dvr,&dvrm); |
divsrmp(CO,m,dndm,dvrm,&q,&t); mptop(t,(P *)rp); |
divsrmp(CO,m,dndm,dvrm,&q,&t); mptop(t,(P *)rp); |
} |
} |
} |
} |
|
|
void Psqrm(arg,rp) |
void Psqrm(arg,rp) |
NODE arg; |
NODE arg; |
LIST *rp; |
LIST *rp; |
{ |
{ |
P q,q1,r,r1,dnd,dnd1,dndm,dvr,dvr1,dvrm; |
P q,q1,r,r1,dnd,dnd1,dndm,dvr,dvr1,dvrm; |
NODE n,tn; |
NODE n,tn; |
V v; |
V v; |
VL vl; |
VL vl; |
int m; |
int m; |
|
|
asir_assert(ARG0(arg),O_P,"sqrm"); |
asir_assert(ARG0(arg),O_P,"sqrm"); |
asir_assert(ARG1(arg),O_P,"sqrm"); |
asir_assert(ARG1(arg),O_P,"sqrm"); |
asir_assert(ARG2(arg),O_N,"sqrm"); |
asir_assert(ARG2(arg),O_N,"sqrm"); |
dnd = (P)ARG0(arg); dvr = (P)ARG1(arg); m = QTOS((Q)ARG2(arg)); |
dnd = (P)ARG0(arg); dvr = (P)ARG1(arg); m = QTOS((Q)ARG2(arg)); |
if ( argc(arg) == 4 ) { |
if ( argc(arg) == 4 ) { |
v = VR((P)ARG3(arg)); |
v = VR((P)ARG3(arg)); |
change_mvar(CO,dnd,v,&dnd1); change_mvar(CO,dvr,v,&dvr1); |
change_mvar(CO,dnd,v,&dnd1); change_mvar(CO,dvr,v,&dvr1); |
reordvar(CO,v,&vl); |
reordvar(CO,v,&vl); |
ptomp(m,dnd1,&dndm); ptomp(m,dvr1,&dvrm); |
ptomp(m,dnd1,&dndm); ptomp(m,dvr1,&dvrm); |
divsrmp(vl,m,dndm,dvrm,&q,&r); mptop(q,&q1); mptop(r,&r1); |
divsrmp(vl,m,dndm,dvrm,&q,&r); mptop(q,&q1); mptop(r,&r1); |
restore_mvar(CO,q1,v,&q); restore_mvar(CO,r1,v,&r); |
restore_mvar(CO,q1,v,&q); restore_mvar(CO,r1,v,&r); |
} else { |
} else { |
ptomp(m,dnd,&dndm); ptomp(m,dvr,&dvrm); |
ptomp(m,dnd,&dndm); ptomp(m,dvr,&dvrm); |
divsrmp(CO,m,dndm,dvrm,&q1,&r1); mptop(q1,&q); mptop(r1,&r); |
divsrmp(CO,m,dndm,dvrm,&q1,&r1); mptop(q1,&q); mptop(r1,&r); |
} |
} |
MKNODE(tn,r,0); MKNODE(n,q,tn); MKLIST(*rp,n); |
MKNODE(tn,r,0); MKNODE(n,q,tn); MKLIST(*rp,n); |
} |
} |
|
|
void Pinva_mod(arg,rp) |
void Pinva_mod(arg,rp) |
NODE arg; |
NODE arg; |
P *rp; |
P *rp; |
{ |
{ |
P dp,f; |
P dp,f; |
Q q; |
Q q; |
int n,i; |
int n,i; |
int mod; |
int mod; |
V v; |
V v; |
UM wf,wdp,winv; |
UM wf,wdp,winv; |
|
|
asir_assert(ARG0(arg),O_P,"gcda_mod"); |
asir_assert(ARG0(arg),O_P,"gcda_mod"); |
asir_assert(ARG1(arg),O_N,"gcda_mod"); |
asir_assert(ARG1(arg),O_N,"gcda_mod"); |
asir_assert(ARG2(arg),O_P,"gcda_mod"); |
asir_assert(ARG2(arg),O_P,"gcda_mod"); |
dp = (P)ARG0(arg); |
dp = (P)ARG0(arg); |
mod = QTOS((Q)ARG1(arg)); |
mod = QTOS((Q)ARG1(arg)); |
f = (P)ARG2(arg); |
f = (P)ARG2(arg); |
if ( NUM(f) ) { |
if ( NUM(f) ) { |
i = invm(rem(NM((Q)f),mod),mod); |
i = invm(rem(NM((Q)f),mod),mod); |
STOQ(i,q); *rp = (P)q; |
STOQ(i,q); *rp = (P)q; |
} else { |
} else { |
v = VR(dp); |
v = VR(dp); |
n = MAX(UDEG(dp),UDEG(f)); |
n = MAX(UDEG(dp),UDEG(f)); |
wf = W_UMALLOC(n); wdp = W_UMALLOC(n); |
wf = W_UMALLOC(n); wdp = W_UMALLOC(n); |
winv = W_UMALLOC(n); |
winv = W_UMALLOC(n); |
ptoum(mod,f,wf); ptoum(mod,dp,wdp); |
ptoum(mod,f,wf); ptoum(mod,dp,wdp); |
invum(mod,wdp,wf,winv); |
invum(mod,wdp,wf,winv); |
if ( DEG(winv) < 0 ) |
if ( DEG(winv) < 0 ) |
*rp = 0; |
*rp = 0; |
else { |
else { |
umtop(v,winv,rp); |
umtop(v,winv,rp); |
} |
} |
} |
} |
} |
} |
|
|
void Psrem_mod(arg,rp) |
void Psrem_mod(arg,rp) |
NODE arg; |
NODE arg; |
P *rp; |
P *rp; |
{ |
{ |
P p1,p2; |
P p1,p2; |
int n,dr; |
int n,dr; |
int mod; |
int mod; |
V v; |
V v; |
UM wp1,wp2,q; |
UM wp1,wp2,q; |
|
|
asir_assert(ARG0(arg),O_P,"srem_mod"); |
asir_assert(ARG0(arg),O_P,"srem_mod"); |
asir_assert(ARG1(arg),O_P,"srem_mod"); |
asir_assert(ARG1(arg),O_P,"srem_mod"); |
asir_assert(ARG2(arg),O_N,"srem_mod"); |
asir_assert(ARG2(arg),O_N,"srem_mod"); |
p1 = (P)ARG0(arg); p2 = (P)ARG1(arg); mod = QTOS((Q)ARG2(arg)); |
p1 = (P)ARG0(arg); p2 = (P)ARG1(arg); mod = QTOS((Q)ARG2(arg)); |
if ( !p1 || NUM(p1) ) |
if ( !p1 || NUM(p1) ) |
*rp = p1; |
*rp = p1; |
else { |
else { |
v = VR(p1); |
v = VR(p1); |
n = MAX(UDEG(p1),UDEG(p2)); |
n = MAX(UDEG(p1),UDEG(p2)); |
wp1 = W_UMALLOC(n); wp2 = W_UMALLOC(n); q = W_UMALLOC(n); |
wp1 = W_UMALLOC(n); wp2 = W_UMALLOC(n); q = W_UMALLOC(n); |
ptoum(mod,p1,wp1); ptoum(mod,p2,wp2); |
ptoum(mod,p1,wp1); ptoum(mod,p2,wp2); |
dr = divum(mod,wp1,wp2,q); |
dr = divum(mod,wp1,wp2,q); |
if ( ( DEG(wp1) = dr ) == -1 ) |
if ( ( DEG(wp1) = dr ) == -1 ) |
*rp = 0; |
*rp = 0; |
else |
else |
umtop(v,wp1,rp); |
umtop(v,wp1,rp); |
} |
} |
} |
} |
|
|
void Purem(arg,rp) |
void Purem(arg,rp) |
NODE arg; |
NODE arg; |
P *rp; |
P *rp; |
{ |
{ |
asir_assert(ARG0(arg),O_P,"urem"); |
asir_assert(ARG0(arg),O_P,"urem"); |
asir_assert(ARG1(arg),O_P,"urem"); |
asir_assert(ARG1(arg),O_P,"urem"); |
uremp((P)ARG0(arg),(P)ARG1(arg),rp); |
uremp((P)ARG0(arg),(P)ARG1(arg),rp); |
} |
} |
|
|
void Pugcd(arg,rp) |
void Pugcd(arg,rp) |
NODE arg; |
NODE arg; |
P *rp; |
P *rp; |
{ |
{ |
asir_assert(ARG0(arg),O_P,"ugcd"); |
asir_assert(ARG0(arg),O_P,"ugcd"); |
asir_assert(ARG1(arg),O_P,"ugcd"); |
asir_assert(ARG1(arg),O_P,"ugcd"); |
ugcdp((P)ARG0(arg),(P)ARG1(arg),rp); |
ugcdp((P)ARG0(arg),(P)ARG1(arg),rp); |
} |
} |
|
|
void invum(mod,dp,f,inv) |
void invum(mod,dp,f,inv) |
int mod; |
int mod; |
UM dp,f,inv; |
UM dp,f,inv; |
{ |
{ |
UM g1,g2,a1,a2,a3,wm,q,tum; |
UM g1,g2,a1,a2,a3,wm,q,tum; |
int d,dr; |
int d,dr; |
|
|
d = DEG(dp)+DEG(f)+10; |
d = DEG(dp)+DEG(f)+10; |
g1 = W_UMALLOC(d); g2 = W_UMALLOC(d); a1 = W_UMALLOC(d); |
g1 = W_UMALLOC(d); g2 = W_UMALLOC(d); a1 = W_UMALLOC(d); |
a2 = W_UMALLOC(d); a3 = W_UMALLOC(d); wm = W_UMALLOC(d); |
a2 = W_UMALLOC(d); a3 = W_UMALLOC(d); wm = W_UMALLOC(d); |
q = W_UMALLOC(d); |
q = W_UMALLOC(d); |
DEG(a1) = 0; COEF(a1)[0] = 1; DEG(a2) = -1; |
DEG(a1) = 0; COEF(a1)[0] = 1; DEG(a2) = -1; |
cpyum(f,g1); cpyum(dp,g2); |
cpyum(f,g1); cpyum(dp,g2); |
while ( 1 ) { |
while ( 1 ) { |
dr = divum(mod,g1,g2,q); tum = g1; g1 = g2; g2 = tum; |
dr = divum(mod,g1,g2,q); tum = g1; g1 = g2; g2 = tum; |
if ( ( DEG(g2) = dr ) == -1 ) |
if ( ( DEG(g2) = dr ) == -1 ) |
break; |
break; |
mulum(mod,a2,q,wm); subum(mod,a1,wm,a3); dr = divum(mod,a3,dp,q); |
mulum(mod,a2,q,wm); subum(mod,a1,wm,a3); dr = divum(mod,a3,dp,q); |
tum = a1; a1 = a2; a2 = a3; a3 = tum; DEG(a3) = dr; |
tum = a1; a1 = a2; a2 = a3; a3 = tum; DEG(a3) = dr; |
} |
} |
if ( DEG(g1) != 0 ) |
if ( DEG(g1) != 0 ) |
DEG(inv) = -1; |
DEG(inv) = -1; |
else if ( COEF(g1)[0] != 1 ) |
else if ( COEF(g1)[0] != 1 ) |
mulsum(mod,a2,invm(COEF(g1)[0],mod),inv); |
mulsum(mod,a2,invm(COEF(g1)[0],mod),inv); |
else |
else |
cpyum(a2,inv); |
cpyum(a2,inv); |
} |
} |