Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagesmc
Path: blob/master/src/ext/pari/simon/resultant3.gp
8820 views
1
\\ Ce fichier gp contient des fonctions pour calculer
2
\\ le resultant de trois polynomes p1,p2,p3 homogenes
3
\\ en trois variables (toujours x,y,z), ainsi que
4
\\ le discriminant d'un polynome homogene en ces trois variables.
5
\\ L'algorithme utilise est celui du sous-resultant.
6
\\
7
\\ ***********************************************
8
\\ * Auteur: Denis SIMON *
9
\\ * mail: [email protected] *
10
\\ * date: 12 Dec 2003 *
11
\\ ***********************************************
12
\\
13
\\ exemple d'utilisation :
14
\\
15
\\ ? p1=x^2-3*z^2+y*z;p2=x-y+15*z;p3=y^2*x+z^3-x*y*z+x^2*z;
16
\\ ? resultant3([p1,p2,p3])
17
\\ %2 = 521784
18
\\ ? discriminant3(p3)
19
\\ %3 = -63
20
\\
21
\\ la fonction hom sert a rendre homogene un polynome en x et y:
22
\\ ? ell=y^2-y-x^3+x^2;
23
\\ ? discriminant3(hom(ell))
24
\\ %5 = -11
25
\\
26
\\
27
28
{hom(p)=
29
p=subst(subst(z^100*p,x,x/z),y,y/z);
30
p/=z^myvaluation(p,z);
31
return(p);
32
}
33
\\
34
\\ degre d'un polynome homogene.
35
\\
36
{degreetot(p)=
37
local(auxdeg,auxp);
38
auxdeg=poldegree(p,x);auxp=pollead(p,x);
39
auxdeg+=poldegree(auxp,y);auxp=pollead(auxp,y);
40
auxdeg+=poldegree(auxp,z);auxp=pollead(auxp,z);
41
return(auxdeg);
42
}
43
\\
44
{ex(vec,i,j)=
45
local(aux);
46
aux=vec[i];vec[i]=vec[j];vec[j]=aux;
47
return(vec);
48
}
49
{myvaluation(p,var)=
50
local(valp);
51
valp=0;
52
while(polcoeff(p,valp,var)==0,valp++);
53
return(valp);
54
}
55
{myvaluation2(p,var)=
56
local(pp,valp);
57
pp=p;
58
valp=0;
59
while(subst(pp,var,0)==0,valp++;pp/=var);
60
return(valp);
61
}
62
{mycontent(p)=
63
local(vz,co,dco);
64
vz=myvaluation(p,z);
65
p=subst(p,z,1);
66
co=content(p);
67
dco=poldegree(co,y);
68
if(dco,co=subst(co,y,y/z)*z^dco);
69
return(co*z^vz);
70
}
71
{resultant2(p,q)=
72
local(dp,dq,valp,valq,auxr,auxp,auxq,res);
73
if(p==0 || q==0,return(0));
74
dp=degreetot(p);dq=degreetot(q);
75
valp=myvaluation(p,y);
76
valq=myvaluation(q,y);
77
if(valp && valq,return(0));
78
auxr=1;
79
if(valp,
80
if(dq%2 && valp%2,auxr=-1);
81
auxr*=pollead(q,x)^valp);
82
if(valq,auxr=pollead(p,x)^valq);
83
auxp=subst(p,y,1);
84
auxq=subst(q,y,1);
85
res=auxr*polresultant(auxp,auxq,x);
86
return(res);
87
}
88
{resultantcomp(vp=[x,y,z])=
89
\\ les vp[i] sont des pol homogenes en x,y et z.
90
\\ vp[3] ne depend que de y et z.
91
local(p,q,rt,dp,dq,drt,vy,vz,lrt,lp,res,aux,res2,dres2);
92
p=vp[1];q=vp[2];rt=vp[3];
93
if(p==0 || q==0 || rt==0,return(0));
94
dp=degreetot(p);dq=degreetot(q);drt=degreetot(rt);
95
if(drt==0,return(rt^(dp*dq)));
96
vy=myvaluation(rt,y);vz=myvaluation(rt,z);
97
rt=subst(rt,y,1);if(vz,rt/=z^vz);
98
lrt=polcoeff(rt,drt,z);lp=polcoeff(p,dp,x);
99
res=1;
100
if(lp==0,
101
aux=p;p=q;q=aux;
102
aux=dp;dp=dq;dq=aux;
103
if(dp%2 && dq%2 && drt%2,res=-res);
104
lp=polcoeff(p,dp,x);
105
if(lp==0,return(0)));
106
if(vy,
107
if(dp%2 && dq%2, res2=-1,res2=1);
108
res2*=resultant2(subst(subst(p,y,0),z,y),subst(subst(q,y,0),z,y));
109
if(res2==0,return(0));
110
res*=res2^vy);
111
if(vz,
112
res2=resultant2(subst(p,z,0),subst(q,z,0));
113
if(res2==0,return(0));
114
res*=res2^vz);
115
drt-=(vy+vz);
116
if(drt==0,return(res*rt^(dp*dq)));
117
res2=polresultant(subst(p,y,1),subst(q,y,1),x);
118
dres2=poldegree(res2,z);
119
res2=polresultant(rt,res2,z);
120
res*=res2;
121
if(dq!=poldegree(subst(q,y,1),x),res*=lp^(drt*(dq-poldegree(subst(q,y,1),x))));
122
if(dres2!=dp*dq,res*=pollead(rt,z)^(dp*dq-dres2));
123
return(res);
124
}
125
{resultant3(vp=[x,y,z],fl)=
126
\\ resultant de 3 polynomes homogenes en x,y,z.
127
\\ fl=1 pour afficher des resultats intermediaires.
128
\\ on travaille sur la variable x.
129
local(vdt,vdx,prodd,s,denom,nume,lp,p0,q0,r0,dd,cq,rm,res);
130
131
for(i=1,3,if(vp[i]==0,return(0)));
132
vdt=vector(3,i,degreetot(vp[i]));
133
vdx=vector(3,i,poldegree(vp[i],x));
134
if(vecmin(vdt-vdx),return(0));
135
\\ en effet, dans ce cas, les polynomes sont dans l'ideal <y,z>
136
137
prodd=prod(i=1,3,vdt[i]);
138
s=1;
139
denom=1;nume=1;
140
\\ on echange pour que vdx[1] >= vdx[2] >= vdx[3]
141
if(vdx[1]<vdx[2] || (vdx[1]==vdx[2] && vdt[1]<vdt[2]),
142
vp=ex(vp,1,2);vdx=ex(vdx,1,2);vdt=ex(vdt,1,2);if(prodd%2,s=-s));
143
if(vdx[1]<vdx[3] || (vdx[1]==vdx[3] && vdt[1]<vdt[3]),
144
vp=ex(vp,1,3);vdx=ex(vdx,1,3);vdt=ex(vdt,1,3);if(prodd%2,s=-s));
145
if(vdx[2]<vdx[3] || (vdx[2]==vdx[3] && vdt[2]<vdt[3]),
146
vp=ex(vp,2,3);vdx=ex(vdx,2,3);vdt=ex(vdt,2,3);if(prodd%2,s=-s));
147
148
\\ cas particulier ou vp[3] est constant
149
if(vdt[3]==0,return(vp[3]^(vdt[1]*vdt[2])*s));
150
151
\\ on fait un echange pour que vp[1] contienne le monome x^vdt[1]
152
lp=polcoeff(vp[1],vdt[1],x);
153
if(lp==0,
154
lp=polcoeff(vp[2],vdt[2],x);
155
if(lp==0,
156
lp=polcoeff(vp[3],vdt[3],x);
157
if(lp==0,return(0));
158
vp=ex(vp,1,3);vdx=ex(vdx,1,3);vdt=ex(vdt,1,3);if(prodd%2,s=-s)
159
, vp=ex(vp,1,2);vdx=ex(vdx,1,2);vdt=ex(vdt,1,2);if(prodd%2,s=-s)));
160
161
\\ on supprime de vp[1] les puissances de x
162
p0=polcoeff(vp[1],0,x);q0=polcoeff(vp[2],0,x);r0=polcoeff(vp[3],0,x);
163
while(p0==0,
164
vp[1]/=x;vdx[1]-=1;vdt[1]-=1;p0=polcoeff(vp[1],0,x);
165
nume*=resultant2(subst(subst(q0,y,x),z,y),subst(subst(r0,y,x),z,y)));
166
167
if(nume==0,return(0));
168
dd=vecmax(vdx)+1;
169
while(vdx[3],
170
171
if(fl,print("vp="vp));
172
if(fl,print("vdx="vdx));
173
if(fl,print("vdt="vdt));
174
if(fl,print([nume,denom]));
175
176
if(denom==0,print(" ERREUR ");return(x));
177
if(nume==0,return(0));
178
for(i=2,3,if(vp[i]==0,return(0)));
179
180
q0=polcoeff(vp[2],0,x);
181
if(q0==0, \\ si vp[2] est divisible par x
182
vp[2]/=x;vdx[2]-=1;vdt[2]-=1;
183
nume*=resultant2(subst(subst(r0,y,x),z,y),subst(subst(p0,y,x),z,y));next);
184
r0=polcoeff(vp[3],0,x);
185
if(r0==0, \\ si vp[3] est divisible par x
186
vp[3]/=x;vdx[3]-=1;vdt[3]-=1;
187
nume*=resultant2(subst(subst(p0,y,x),z,y),subst(subst(q0,y,x),z,y));next);
188
189
\\ on enleve le contenu
190
cq=mycontent(vp[2]);
191
if(cq!=1,
192
nume*=resultantcomp([vp[3],vp[1],cq]);
193
vp[2]/=cq;vdt[2]-=poldegree(cq);next);
194
cq=mycontent(vp[3]);
195
if(cq!=1,
196
nume*=resultantcomp([vp[1],vp[2],cq]);
197
vp[3]/=cq;vdt[3]-=poldegree(cq);next);
198
199
rm=pollead(vp[3],x);\\ le coefficient dominant de vp[3].
200
res=resultantcomp([vp[1],vp[3]-rm*x^vdx[3],rm]);
201
if(res==0,print1("cas non traite");return(x));\\ ce cas est-il possible ?
202
if(vdt[1]%2 && vdt[3]%2 && degreetot(rm)%2, res=-res);
203
\\ on baisse le degre de vp[2] en retranchant des multiples de vp[3].
204
while(vdx[3]<=vdx[2],
205
delta=vdx[2]-vdx[3];
206
lp=pollead(vp[2],x);
207
vp[2]=simplify(rm*vp[2]-lp*vp[3]*x^delta);
208
vdx[2]=poldegree(vp[2],x);
209
denom*=res
210
);
211
vdt[2]=degreetot(vp[2]);
212
213
prodd=prod(i=1,3,vdt[i]);
214
vp=ex(vp,2,3);vdx=ex(vdx,2,3);
215
vdt=ex(vdt,2,3);
216
if(prodd%2,s=-s);
217
);
218
vp[3]=polcoeff(vp[3],0,x);
219
nume*=resultantcomp(vp);
220
if(fl,print([nume,denom]));
221
return(simplify(s*nume/denom));
222
}
223
\\
224
\\ discriminant d'un pol homogene en 3 variables x, y et z.
225
\\
226
{
227
discriminant3(p,fl)=
228
local(dp,normal,re);
229
dp=degreetot(p);
230
normal=dp^(dp^2-3*dp+3)*(-1)^(dp*(dp-1)/2);
231
re=resultant3([deriv(p,x),deriv(p,y),deriv(p,z)],fl);
232
if(re==x,return(0));
233
return(re/normal);
234
}
235
236
237
238
239
240
241
242