1 | /////////////////////////////////////////////////////////////////////////////// |
---|
2 | version="version divisors.lib 4.1.2.0 Feb_2019 "; // $Id$ |
---|
3 | category = "Commutative Algebra"; |
---|
4 | info=" |
---|
5 | LIBRARY: divisors.lib Divisors and P-Divisors |
---|
6 | |
---|
7 | AUTHORS: Janko Boehm boehm@mathematik.uni-kl.de |
---|
8 | @* Lars Kastner kastner@math.fu-berlin.de |
---|
9 | @* Benjamin Lorenz blorenz@math.uni-frankfurt.de |
---|
10 | @* Hans Schoenemann hannes@mathematik.uni-kl.de |
---|
11 | @* Yue Ren ren@mathematik.uni-kl.de |
---|
12 | |
---|
13 | OVERVIEW: |
---|
14 | |
---|
15 | We implement a class divisor on an algebraic variety and methods |
---|
16 | for computing with them. Divisors are represented by tuples of ideals |
---|
17 | defining the positive and the negative part. In particular, we implement the group |
---|
18 | structure on divisors, computing global sections and testing linear |
---|
19 | equivalence. |
---|
20 | |
---|
21 | In addition to this we provide a class formaldivisor which implements |
---|
22 | integer formal sums of divisors (not necessarily prime). A formal divisor |
---|
23 | can be evaluated to a divisor, and a divisor can be decomposed into |
---|
24 | a formal sum. |
---|
25 | |
---|
26 | Finally we provide a class pdivisor which implements polyhedral formal sums of |
---|
27 | divisors (P-divisors) where the coefficients are assumed to be polyhedra with fixed tail cone. |
---|
28 | There is a function to evaluate a P-divisor on a vector in the dual of the tail cone. The |
---|
29 | result will be a formal divisor. |
---|
30 | |
---|
31 | |
---|
32 | REFERENCES: |
---|
33 | |
---|
34 | For the class divisor we closely follow Macaulay2's tutorial on divisors. |
---|
35 | |
---|
36 | |
---|
37 | PROCEDURES: |
---|
38 | |
---|
39 | makeDivisor(ideal,ideal) create a divisor |
---|
40 | divisorplus(divisor,divisor) add two divisors |
---|
41 | multdivisor(int,divisor) multiply a divisor by an interger |
---|
42 | negativedivisor(divisor) compute the negative of the divisor |
---|
43 | normalForm(divisor) normal form of a divisor |
---|
44 | isEqualDivisor(divisor,divisor) test whether two divisors are equal |
---|
45 | globalSections(divisor) compute the global sections of a divisor |
---|
46 | degreeDivisor(divisor) degree of a divisor |
---|
47 | linearlyEquivalent(divisor,divisor) test whether two divisors a linearly equivalent |
---|
48 | effective(divisor) compute an effective divisor |
---|
49 | linearly equivalent to a divisor |
---|
50 | |
---|
51 | makeFormalDivisor(list) make a formal integer sum of divisors |
---|
52 | evaluateFormalDivisor(formaldivisor) evalutate a formal sum of divisors to a divisor |
---|
53 | formaldivisorplus(formaldivisor,formaldivisor) add two formal divisors |
---|
54 | negativeformaldivisor(formaldivisor) compute the negative of the formal divisor |
---|
55 | multformaldivisor(int,formaldivisor) multiply a formal divisor by an interger |
---|
56 | degreeFormalDivisor(formaldivisor) degree of a formal divisor |
---|
57 | |
---|
58 | makePDivisor(List) make a formal polyhedral sum of divisors |
---|
59 | evaluatePDivisor(pdivisor,intvec) evaluate a polyhedral divisor |
---|
60 | to an integer formal divisor |
---|
61 | pdivisorplus(pdivisor,pdivisor) add two polyhedral divisors |
---|
62 | |
---|
63 | |
---|
64 | "; |
---|
65 | |
---|
66 | |
---|
67 | //////////////////////////////////////////////////////////////////////////////// |
---|
68 | |
---|
69 | LIB "primdec.lib"; |
---|
70 | |
---|
71 | proc mod_init() |
---|
72 | { |
---|
73 | LIB"customstd.so"; |
---|
74 | load("polymake.lib","try"); |
---|
75 | newstruct("divisor","ideal den,ideal num"); |
---|
76 | newstruct("formaldivisor","list summands"); |
---|
77 | newstruct("pdivisor","list summands, cone tail"); |
---|
78 | |
---|
79 | system("install","divisor","print",divisor_print,1); |
---|
80 | system("install","divisor","+",divisorplus,2); |
---|
81 | system("install","divisor","*",proxymultdivisor,2); |
---|
82 | system("install","formaldivisor","print",formaldivisor_print,1); |
---|
83 | system("install","formaldivisor","+",formaldivisorplus,2); |
---|
84 | system("install","formaldivisor","*",proxymultformaldivisor,2); |
---|
85 | system("install","pdivisor","+",pdivisorplus,2); |
---|
86 | } |
---|
87 | |
---|
88 | |
---|
89 | |
---|
90 | proc divisor_print(divisor D) |
---|
91 | "USAGE: divisor_print(D); D; D = divisor. @* |
---|
92 | ASSUME: D is a divisor. |
---|
93 | RETURN: Will print D. |
---|
94 | KEYWORDS: divisors |
---|
95 | EXAMPLE: example divisor_print; shows an example |
---|
96 | " |
---|
97 | { |
---|
98 | "("+string(D.num)+") - ("+string(D.den)+")"; |
---|
99 | } |
---|
100 | example |
---|
101 | { "EXAMPLE:"; |
---|
102 | ring r=31991,(x,y,z),dp; |
---|
103 | ideal I = y^2*z - x*(x-z)*(x+3*z); |
---|
104 | qring Q = std(I); |
---|
105 | divisor P = makeDivisor(ideal(x,z),ideal(1)); |
---|
106 | P; |
---|
107 | } |
---|
108 | |
---|
109 | |
---|
110 | proc formaldivisor_print(formaldivisor fD) |
---|
111 | "USAGE: formaldivisor_print(D); D; D = formaldivisor. @* |
---|
112 | ASSUME: fD is a formaldivisor. |
---|
113 | RETURN: Will print fD. |
---|
114 | KEYWORDS: divisors |
---|
115 | EXAMPLE: example formaldivisor_print; shows an example |
---|
116 | " |
---|
117 | { |
---|
118 | int i; string s; list L=fD.summands; |
---|
119 | list cd; int c; divisor d; |
---|
120 | string linebreak = |
---|
121 | " |
---|
122 | "; |
---|
123 | for (i=1; i<=size(L); i++) |
---|
124 | { |
---|
125 | cd=L[i]; c=cd[1]; d=cd[2]; |
---|
126 | if (i>1 && c>=0) { s = s + "+"; } |
---|
127 | s = s + string(c)+"*( ("+string(d.num)+") - ("+string(d.den)+") )"; |
---|
128 | if (i!=size(L)) { s = s + linebreak; } |
---|
129 | } |
---|
130 | s; |
---|
131 | } |
---|
132 | example |
---|
133 | { "EXAMPLE:"; |
---|
134 | ring r=31991,(x,y,z),dp; |
---|
135 | ideal I = y^2*z - x*(x-z)*(x+3*z); |
---|
136 | qring Q = std(I); |
---|
137 | divisor P = makeDivisor(ideal(x,z),ideal(1)); |
---|
138 | P; |
---|
139 | } |
---|
140 | |
---|
141 | |
---|
142 | //////////////////////////////////////////////////////////////////////////////// |
---|
143 | // divisors as numerator and denomiator ideals |
---|
144 | |
---|
145 | proc makeDivisor(ideal I, ideal J) |
---|
146 | "USAGE: makeDivisor(I ,J); I = ideal, J = ideal. @* |
---|
147 | ASSUME: I and J are ideals in a qring Q of a smooth irreducible variety X |
---|
148 | such that any ideal in Q satisfies the S2 condition. |
---|
149 | RETURN: a divisor on X |
---|
150 | THEORY: The procedure will eliminate all components which are not of codimension 1. |
---|
151 | The S2 condition requires that every proper nonzero principal ideal |
---|
152 | has pure codimension 1. |
---|
153 | KEYWORDS: divisors |
---|
154 | EXAMPLE: example makeDivisor; shows an example |
---|
155 | " |
---|
156 | { |
---|
157 | divisor C; |
---|
158 | C.num = purify1(I); |
---|
159 | C.den = purify1(J); |
---|
160 | return(C); |
---|
161 | } |
---|
162 | |
---|
163 | example |
---|
164 | { "EXAMPLE:"; |
---|
165 | ring r=31991,(x,y,z),dp; |
---|
166 | ideal I = y^2*z - x*(x-z)*(x+3*z); |
---|
167 | qring Q = std(I); |
---|
168 | divisor P = makeDivisor(ideal(x,z),ideal(1)); |
---|
169 | } |
---|
170 | |
---|
171 | |
---|
172 | proc divisorplus(divisor A, divisor B) |
---|
173 | "USAGE: divisorplus(A ,B); A + B; A = divisor, B = divisor. @* |
---|
174 | ASSUME: A and B are divisors on X. |
---|
175 | RETURN: a divisor on X |
---|
176 | THEORY: The procedure will compute the product of the numerator |
---|
177 | and denominator ideals, respectively. |
---|
178 | KEYWORDS: divisors |
---|
179 | EXAMPLE: example divisorplus; shows an example |
---|
180 | " |
---|
181 | { |
---|
182 | return(makeDivisor(interred(A.num*B.num),interred(A.den*B.den))); |
---|
183 | } |
---|
184 | example |
---|
185 | { "EXAMPLE:"; |
---|
186 | ring r=31991,(x,y,z),dp; |
---|
187 | ideal I = y^2*z - x*(x-z)*(x+3*z); |
---|
188 | qring Q = std(I); |
---|
189 | divisor A = makeDivisor(ideal(x,z),ideal(1)); |
---|
190 | divisor B = makeDivisor(ideal(x,y),ideal(1)); |
---|
191 | A+B; |
---|
192 | } |
---|
193 | |
---|
194 | |
---|
195 | proc multdivisor(int n, divisor A) |
---|
196 | "USAGE: multdivisor(n ,A); A*n; n = integer, A = divisor.@* |
---|
197 | ASSUME: n is an integer and A is a divisor on X. |
---|
198 | RETURN: a divisor on X |
---|
199 | THEORY: The procedure will compute the n-th power of the numerator |
---|
200 | and denominator ideals, respectively. |
---|
201 | KEYWORDS: divisors |
---|
202 | EXAMPLE: example multdivisor; shows an example |
---|
203 | " |
---|
204 | { |
---|
205 | if (n<0) {return(multdivisor(-n,negativedivisor(A)));} |
---|
206 | return(makeDivisor(interred((A.num)^n),interred((A.den)^n))); |
---|
207 | } |
---|
208 | example |
---|
209 | { "EXAMPLE:"; |
---|
210 | ring r=31991,(x,y,z),dp; |
---|
211 | ideal I = y^2*z - x*(x-z)*(x+3*z); |
---|
212 | qring Q = std(I); |
---|
213 | divisor A = makeDivisor(ideal(x,z),ideal(1)); |
---|
214 | A; |
---|
215 | divisor D = multdivisor(4,A); |
---|
216 | D; |
---|
217 | A*4; |
---|
218 | } |
---|
219 | |
---|
220 | |
---|
221 | /*** |
---|
222 | * For operator overloading, which needs a procedure which takes a divisor first |
---|
223 | * and integer second. |
---|
224 | **/ |
---|
225 | proc proxymultdivisor(divisor A, int n) |
---|
226 | { |
---|
227 | if (n<0) {return(multdivisor(-n,negativedivisor(A)));} |
---|
228 | return(makeDivisor(interred((A.num)^n),interred((A.den)^n))); |
---|
229 | } |
---|
230 | |
---|
231 | |
---|
232 | proc negativedivisor(divisor A) |
---|
233 | "USAGE: negativedivisor(A); A*(-1); A = divisor.@* |
---|
234 | ASSUME: A is a divisor on X. |
---|
235 | RETURN: a divisor on X |
---|
236 | THEORY: The procedure will interchange the numerator and denominator ideals. |
---|
237 | KEYWORDS: divisors |
---|
238 | EXAMPLE: example negativedivisor; shows an example |
---|
239 | " |
---|
240 | { |
---|
241 | divisor B; |
---|
242 | B.num=A.den; |
---|
243 | B.den=A.num; |
---|
244 | return(B); |
---|
245 | } |
---|
246 | example |
---|
247 | { "EXAMPLE:"; |
---|
248 | ring r=31991,(x,y,z),dp; |
---|
249 | ideal I = y^2*z - x*(x-z)*(x+3*z); |
---|
250 | qring Q = std(I); |
---|
251 | divisor A = makeDivisor(ideal(x,z),ideal(1)); |
---|
252 | A; |
---|
253 | divisor D = negativedivisor(A); |
---|
254 | D; |
---|
255 | } |
---|
256 | |
---|
257 | |
---|
258 | proc normalForm(divisor A) |
---|
259 | "USAGE: normalForm(A); A = divisor.@* |
---|
260 | ASSUME: A is a divisor on X. |
---|
261 | RETURN: different representative of the same divisor on X |
---|
262 | THEORY: The procedure will cancel common components of numerator and denominator. |
---|
263 | KEYWORDS: divisors |
---|
264 | EXAMPLE: example normalForm; shows an example |
---|
265 | " |
---|
266 | { |
---|
267 | divisor B; |
---|
268 | B.num=quotient(A.num,A.den); |
---|
269 | B.den=quotient(A.den,A.num); |
---|
270 | return(B); |
---|
271 | } |
---|
272 | example |
---|
273 | { "EXAMPLE:"; |
---|
274 | ring r=31991,(x,y,z),dp; |
---|
275 | ideal I = y^2*z - x*(x-z)*(x+3*z); |
---|
276 | qring Q = std(I); |
---|
277 | divisor A = makeDivisor(ideal(x,z),ideal(1)); |
---|
278 | divisor B = makeDivisor(ideal(x,y),ideal(1)); |
---|
279 | divisor D = (A+B)+multdivisor(-1,B); |
---|
280 | D; |
---|
281 | normalForm(D); |
---|
282 | } |
---|
283 | |
---|
284 | |
---|
285 | |
---|
286 | |
---|
287 | static proc isEqualIdeal(ideal A,ideal B){ |
---|
288 | return((size(NF(A,std(B)))==0) && (size(NF(B,std(A)))==0)); |
---|
289 | } |
---|
290 | |
---|
291 | |
---|
292 | proc isEqualDivisor(divisor A,divisor B) |
---|
293 | "USAGE: isEqualDivisor(A,B); A = divisor, B = divisor.@* |
---|
294 | ASSUME: A and B are divisors on X. |
---|
295 | RETURN: int 0 or 1, checks equality of A and B. |
---|
296 | THEORY: The procedure will compute the normal forms of A and B and compare. |
---|
297 | KEYWORDS: divisors |
---|
298 | EXAMPLE: example isEqualDivisor; shows an example |
---|
299 | " |
---|
300 | { |
---|
301 | A=normalForm(A); |
---|
302 | B=normalForm(B); |
---|
303 | return((isEqualIdeal(A.num,B.num)) && (isEqualIdeal(A.den,B.den))); |
---|
304 | } |
---|
305 | example |
---|
306 | { "EXAMPLE:"; |
---|
307 | ring r=31991,(x,y,z),dp; |
---|
308 | ideal I = y^2*z - x*(x-z)*(x+3*z); |
---|
309 | qring Q = std(I); |
---|
310 | divisor A = makeDivisor(ideal(x,z),ideal(1)); |
---|
311 | divisor B = makeDivisor(ideal(x,y),ideal(1)); |
---|
312 | divisor D = (A+B)+multdivisor(-1,B); |
---|
313 | isEqualDivisor(A,D); |
---|
314 | } |
---|
315 | |
---|
316 | |
---|
317 | static proc purify1(ideal I) |
---|
318 | { |
---|
319 | I = simplify(I,2); |
---|
320 | if (I[1]==0){ERROR("expected a non-zero ideal");} |
---|
321 | ideal f = I[1]; |
---|
322 | return(minbase(quotient(f,quotient(f,I)))); |
---|
323 | } |
---|
324 | |
---|
325 | |
---|
326 | static proc basis(ideal I,int d) |
---|
327 | { |
---|
328 | I=simplify(jet(intersect(I,maxideal(d)),d),2); |
---|
329 | return(I)} |
---|
330 | |
---|
331 | //basis(ideal(x,y^3),2); |
---|
332 | |
---|
333 | |
---|
334 | proc globalSections(divisor D) |
---|
335 | "USAGE: globalSections(A); A = divisor.@* |
---|
336 | ASSUME: A is a divisor on X. |
---|
337 | RETURN: a list with a basis of the space of global sections of D. |
---|
338 | THEORY: We assume that the qring of X satisfies the S2-condition and that X is smooth. We compute sat((f*J) : I) /f |
---|
339 | where D = (I)-(J). |
---|
340 | KEYWORDS: divisors |
---|
341 | EXAMPLE: example globalSections; shows an example |
---|
342 | " |
---|
343 | { |
---|
344 | poly f =(simplify(D.num,2))[1]; |
---|
345 | ideal LD = basis(purify1(quotient(f*D.den,D.num)),deg(f)); |
---|
346 | list L = simplify(LD,2),f; |
---|
347 | return(L); |
---|
348 | } |
---|
349 | example |
---|
350 | { "EXAMPLE:"; |
---|
351 | ring r=31991,(x,y,z),dp; |
---|
352 | ideal I = y^2*z - x*(x-z)*(x+3*z); |
---|
353 | qring Q = std(I); |
---|
354 | divisor P = makeDivisor(ideal(x,z),ideal(1)); |
---|
355 | divisor D = multdivisor(4,P); |
---|
356 | globalSections(D); |
---|
357 | } |
---|
358 | |
---|
359 | |
---|
360 | static proc sectionIdeal(poly f, poly g, divisor D){ |
---|
361 | return(purify1(quotient(quotient(f*D.num,g), D.den))); |
---|
362 | } |
---|
363 | |
---|
364 | proc degreeDivisor(divisor A) |
---|
365 | "USAGE: degreeDivisor(A); A = divisor.@* |
---|
366 | ASSUME: A is a divisor on X. |
---|
367 | RETURN: The degree of A. |
---|
368 | THEORY: We compute difference of the degrees of the numerator and denominator ideals. |
---|
369 | KEYWORDS: divisors |
---|
370 | EXAMPLE: example degreeDivisor; shows an example |
---|
371 | " |
---|
372 | { |
---|
373 | return( mult(std(A.num))-mult(std(A.den))); |
---|
374 | } |
---|
375 | example |
---|
376 | { "EXAMPLE:"; |
---|
377 | ring r=31991,(x,y,z),dp; |
---|
378 | ideal I = y^2*z - x*(x-z)*(x+3*z); |
---|
379 | qring Q = std(I); |
---|
380 | divisor P = makeDivisor(ideal(x,z),ideal(1)); |
---|
381 | degreeDivisor(P); |
---|
382 | } |
---|
383 | |
---|
384 | proc linearlyEquivalent(divisor A, divisor B) |
---|
385 | "USAGE: linearlyEquivalent(A,B); A = divisor, B = divisor.@* |
---|
386 | ASSUME: A and B are divisors on X. |
---|
387 | RETURN: list if A and B a linearly equivalent and int 0 otherwise. |
---|
388 | THEORY: Checks whether A-B is principle. If yes, returns a list L=(f,g) where |
---|
389 | A - B = (f/g). |
---|
390 | KEYWORDS: divisors |
---|
391 | EXAMPLE: example linearlyEquivalent; shows an example |
---|
392 | " |
---|
393 | { |
---|
394 | divisor F = normalForm(divisorplus(A,negativedivisor(B))); |
---|
395 | list LB = globalSections(F); |
---|
396 | if (size(LB[1])!=1) {return(0);} |
---|
397 | ideal V = sectionIdeal(LB[1][1,1],LB[2],F); |
---|
398 | if (isEqualIdeal(V,ideal(1))==1) {return(list(LB[1][1,1],LB[2]));} |
---|
399 | return(0); |
---|
400 | } |
---|
401 | example |
---|
402 | { "EXAMPLE:"; |
---|
403 | ring r=31991,(x,y,z),dp; |
---|
404 | ideal I = y^2*z - x*(x-z)*(x+3*z); |
---|
405 | qring Q = std(I); |
---|
406 | divisor A = makeDivisor(ideal(x,z),ideal(1)); |
---|
407 | divisor B = makeDivisor(ideal(x,y),ideal(1)); |
---|
408 | linearlyEquivalent(A,B); |
---|
409 | linearlyEquivalent(multdivisor(2,A),multdivisor(2,B)); |
---|
410 | } |
---|
411 | |
---|
412 | |
---|
413 | proc effective(divisor A) |
---|
414 | "USAGE: effective(A); A = divisor.@* |
---|
415 | ASSUME: A is a divisor on X which is linearly equivalent to an effective divisor. |
---|
416 | RETURN: divisor on X. |
---|
417 | THEORY: We compute an effective divisor linearly equivalent to A. |
---|
418 | KEYWORDS: divisors |
---|
419 | EXAMPLE: example effective; shows an example |
---|
420 | " |
---|
421 | { |
---|
422 | list LB = globalSections(A); |
---|
423 | if (size(LB[1])==0) {ERROR("the divisor is not linearly equivalent to an effective divisor");} |
---|
424 | ideal V = sectionIdeal(LB[1][1,1],LB[2],A); |
---|
425 | return(makeDivisor(V,ideal(1))); |
---|
426 | } |
---|
427 | example |
---|
428 | { "EXAMPLE:"; |
---|
429 | ring r=31991,(x,y,z),dp; |
---|
430 | ideal I = y^2*z - x*(x-z)*(x+3*z); |
---|
431 | qring Q = std(I); |
---|
432 | divisor A = makeDivisor(ideal(x,z),ideal(1)); |
---|
433 | divisor B = makeDivisor(ideal(x,y),ideal(1)); |
---|
434 | divisor D = divisorplus(multdivisor(2,B),negativedivisor(A)); |
---|
435 | effective(D); |
---|
436 | } |
---|
437 | |
---|
438 | |
---|
439 | |
---|
440 | //////////////////////////////////////////////////////////////////////////////// |
---|
441 | // formal sums of divisors |
---|
442 | |
---|
443 | proc makeFormalDivisor(list L) |
---|
444 | "USAGE: makeFormalDivisor(L); L = list.@* |
---|
445 | ASSUME: L is a list of tuples of an integer and a divisor. |
---|
446 | RETURN: a formal divisor on X |
---|
447 | THEORY: Represents an integer formal sum of divisors. |
---|
448 | KEYWORDS: divisors |
---|
449 | EXAMPLE: example makeFormalDivisor; shows an example |
---|
450 | " |
---|
451 | { |
---|
452 | formaldivisor C; |
---|
453 | C.summands = L; |
---|
454 | return(C); |
---|
455 | } |
---|
456 | example |
---|
457 | { "EXAMPLE:"; |
---|
458 | ring r=31991,(x,y,z),dp; |
---|
459 | ideal I = y^2*z - x*(x-z)*(x+3*z); |
---|
460 | qring Q = std(I); |
---|
461 | divisor A = makeDivisor(ideal(x,z),ideal(1)); |
---|
462 | divisor B = makeDivisor(ideal(x,y),ideal(1)); |
---|
463 | makeFormalDivisor(list(list(-5,A),list(2,B))); |
---|
464 | } |
---|
465 | |
---|
466 | |
---|
467 | proc evaluateFormalDivisor(formaldivisor D) |
---|
468 | "USAGE: evaluateFormalDivisor(D); D = formal divisor.@* |
---|
469 | ASSUME: D is a formal divisor on X. |
---|
470 | RETURN: a divisor on X |
---|
471 | THEORY: Will evaluate the formal sum. |
---|
472 | KEYWORDS: divisors |
---|
473 | EXAMPLE: example evaluateFormalDivisor; shows an example |
---|
474 | " |
---|
475 | { |
---|
476 | list L = D.summands; |
---|
477 | if (size(L)==0) {return(makeDivisor(ideal(1),ideal(1)));} |
---|
478 | int i; |
---|
479 | divisor E = multdivisor(L[1][1],L[1][2]); |
---|
480 | for ( i=2; i <= size(L); i++ ) |
---|
481 | { |
---|
482 | E = divisorplus(E, multdivisor(L[i][1],L[i][2])); |
---|
483 | } |
---|
484 | return(E); |
---|
485 | } |
---|
486 | example |
---|
487 | { "EXAMPLE:"; |
---|
488 | ring r=31991,(x,y,z),dp; |
---|
489 | ideal I = y^2*z - x*(x-z)*(x+3*z); |
---|
490 | qring Q = std(I); |
---|
491 | divisor A = makeDivisor(ideal(x,z),ideal(1)); |
---|
492 | divisor B = makeDivisor(ideal(x,y),ideal(1)); |
---|
493 | formaldivisor fE= makeFormalDivisor(list(list(-5,A),list(2,B))); |
---|
494 | evaluateFormalDivisor(fE); |
---|
495 | } |
---|
496 | |
---|
497 | |
---|
498 | |
---|
499 | static proc position(divisor I,list L){ |
---|
500 | int i; |
---|
501 | for (i=1; i <=size(L); i++){ |
---|
502 | if (isEqualDivisor(I,L[i][2])==1) {return(i);} |
---|
503 | } |
---|
504 | return(0);} |
---|
505 | |
---|
506 | |
---|
507 | proc formaldivisorplus(formaldivisor A, formaldivisor B) |
---|
508 | "USAGE: formaldivisorplus(A ,B); A + B; A = formaldivisor, B = formaldivisor. @* |
---|
509 | ASSUME: A and B are formal divisors on X. |
---|
510 | RETURN: a formal divisor on X |
---|
511 | THEORY: The procedure will add the formal sums. |
---|
512 | KEYWORDS: divisors |
---|
513 | EXAMPLE: example formaldivisorplus; shows an example |
---|
514 | " |
---|
515 | { |
---|
516 | formaldivisor C; |
---|
517 | int i,p; |
---|
518 | int j=1; |
---|
519 | list L; |
---|
520 | list LA=A.summands; |
---|
521 | list LB=B.summands; |
---|
522 | for (i=1; i<=size(LA);i++){ |
---|
523 | p=position(LA[i][2],L); |
---|
524 | if (p==0) { |
---|
525 | L[j]=list(); |
---|
526 | L[j][2]=LA[i][2]; |
---|
527 | L[j][1]=LA[i][1]; |
---|
528 | j=j+1; |
---|
529 | } else { |
---|
530 | L[p][1]=L[p][1]+LA[i][1]; |
---|
531 | }; |
---|
532 | } |
---|
533 | for (i=1; i<=size(LB);i++){ |
---|
534 | p=position(LB[i][2],L); |
---|
535 | if (p==0) { |
---|
536 | L[j]=list(); |
---|
537 | L[j][2]=LB[i][2]; |
---|
538 | L[j][1]=LB[i][1]; |
---|
539 | j=j+1; |
---|
540 | } else { |
---|
541 | L[p][1]=L[p][1]+LB[i][1]; |
---|
542 | }; |
---|
543 | } |
---|
544 | //C.summands = (A.summands)+(B.summands); |
---|
545 | return(L); |
---|
546 | } |
---|
547 | example |
---|
548 | { "EXAMPLE:"; |
---|
549 | ring r=31991,(x,y,z),dp; |
---|
550 | ideal I = y^2*z - x*(x-z)*(x+3*z); |
---|
551 | qring Q = std(I); |
---|
552 | divisor A = makeDivisor(ideal(x,z),ideal(1)); |
---|
553 | divisor B = makeDivisor(ideal(x,y),ideal(1)); |
---|
554 | divisor C = makeDivisor(ideal(x-z,y),ideal(1)); |
---|
555 | formaldivisor fE= makeFormalDivisor(list(list(-5,A),list(2,B))); |
---|
556 | formaldivisor fE2= makeFormalDivisor(list(list(-5,A),list(2,C))); |
---|
557 | formaldivisorplus(fE,fE2); |
---|
558 | } |
---|
559 | |
---|
560 | |
---|
561 | proc degreeFormalDivisor(formaldivisor A) |
---|
562 | "USAGE: degreeFormalDivisor(A); A = formaldivisor.@* |
---|
563 | ASSUME: A is a formaldivisor on X. |
---|
564 | RETURN: The degree of A. |
---|
565 | THEORY: We compute degrees of the summands and return the weighted sum. |
---|
566 | KEYWORDS: divisors |
---|
567 | EXAMPLE: example degreeFormalDivisor; shows an example |
---|
568 | " |
---|
569 | { |
---|
570 | int i,s; |
---|
571 | list L = A.summands; |
---|
572 | for (i=1;i<=size(L);i++){ |
---|
573 | s=s+L[i][1]*degreeDivisor(L[i][2]); |
---|
574 | } |
---|
575 | return(s); |
---|
576 | } |
---|
577 | example |
---|
578 | { "EXAMPLE:"; |
---|
579 | ring r=31991,(x,y,z),dp; |
---|
580 | ideal I = y^2*z - x*(x-z)*(x+3*z); |
---|
581 | qring Q = std(I); |
---|
582 | divisor A = makeDivisor(ideal(x,z),ideal(1)); |
---|
583 | divisor B = makeDivisor(ideal(x,y),ideal(1)); |
---|
584 | formaldivisor fE= makeFormalDivisor(list(list(-5,A),list(2,B))); |
---|
585 | degreeFormalDivisor(fE); |
---|
586 | } |
---|
587 | |
---|
588 | |
---|
589 | proc multformaldivisor(int n,formaldivisor A) |
---|
590 | "USAGE: multformaldivisor(n ,A); A*n; n = integer, A = formaldivisor.@* |
---|
591 | ASSUME: n is an integer and A is a formal divisor on X. |
---|
592 | RETURN: a formal divisor on X |
---|
593 | THEORY: The procedure will multiply the formal sum with n. |
---|
594 | KEYWORDS: divisors |
---|
595 | EXAMPLE: example multformaldivisor; shows an example |
---|
596 | " |
---|
597 | { |
---|
598 | formaldivisor B; |
---|
599 | list L=A.summands; |
---|
600 | int i; |
---|
601 | for (i=1;i<=size(L);i++){ |
---|
602 | L[i][1]=n*L[i][1]; |
---|
603 | } |
---|
604 | B.summands=L; |
---|
605 | return(B); |
---|
606 | } |
---|
607 | example |
---|
608 | { "EXAMPLE:"; |
---|
609 | ring r=31991,(x,y,z),dp; |
---|
610 | ideal I = y^2*z - x*(x-z)*(x+3*z); |
---|
611 | qring Q = std(I); |
---|
612 | divisor A = makeDivisor(ideal(x,z),ideal(1)); |
---|
613 | divisor B = makeDivisor(ideal(x,y),ideal(1)); |
---|
614 | formaldivisor fE= makeFormalDivisor(list(list(-5,A),list(2,B))); |
---|
615 | fE*2; |
---|
616 | } |
---|
617 | |
---|
618 | |
---|
619 | /*** |
---|
620 | * For operator overloading, which needs a procedure which takes a divisor first |
---|
621 | * and integer second. |
---|
622 | **/ |
---|
623 | proc proxymultformaldivisor(formaldivisor A, int n) |
---|
624 | { |
---|
625 | formaldivisor B; |
---|
626 | list L=A.summands; |
---|
627 | int i; |
---|
628 | for (i=1;i<=size(L);i++){ |
---|
629 | L[i][1]=n*L[i][1]; |
---|
630 | } |
---|
631 | B.summands=L; |
---|
632 | return(B); |
---|
633 | } |
---|
634 | |
---|
635 | |
---|
636 | |
---|
637 | proc negativeformaldivisor(formaldivisor A) |
---|
638 | "USAGE: negativeformaldivisor(A); A = formaldivisor.@* |
---|
639 | ASSUME: A is a formaldivisor on X. |
---|
640 | RETURN: a formal divisor on X |
---|
641 | THEORY: The procedure will change the signs of the coefficients. |
---|
642 | KEYWORDS: divisors |
---|
643 | EXAMPLE: example negativeformaldivisor; shows an example |
---|
644 | " |
---|
645 | { |
---|
646 | formaldivisor B; |
---|
647 | list L=A.summands; |
---|
648 | int i; |
---|
649 | for (i=1;i<=size(L);i++){ |
---|
650 | L[i][1]=-L[i][1]; |
---|
651 | } |
---|
652 | B.summands=L; |
---|
653 | return(B); |
---|
654 | } |
---|
655 | example |
---|
656 | { "EXAMPLE:"; |
---|
657 | ring r=31991,(x,y,z),dp; |
---|
658 | ideal I = y^2*z - x*(x-z)*(x+3*z); |
---|
659 | qring Q = std(I); |
---|
660 | divisor A = makeDivisor(ideal(x,z),ideal(1)); |
---|
661 | divisor B = makeDivisor(ideal(x,y),ideal(1)); |
---|
662 | formaldivisor fE= makeFormalDivisor(list(list(-5,A),list(2,B))); |
---|
663 | negativeformaldivisor(fE); |
---|
664 | } |
---|
665 | |
---|
666 | |
---|
667 | static proc primDecDivisor(divisor D) |
---|
668 | "decompose a divisor into a formal divisor of primary divisors" |
---|
669 | { |
---|
670 | formaldivisor E; |
---|
671 | ideal I = D.num; |
---|
672 | ideal J = D.den; |
---|
673 | list L; |
---|
674 | int i; |
---|
675 | int j = 1; |
---|
676 | list LI = primdecGTZ(I); |
---|
677 | for (i=1;i<=size(LI);i++){ |
---|
678 | LI[i][2]; |
---|
679 | L[j]=list(1,makeDivisor(LI[i][1],ideal(1))); |
---|
680 | j=j+1; |
---|
681 | }; |
---|
682 | list LJ = primdecGTZ(J); |
---|
683 | for (i=1;i<=size(LJ);i++){ |
---|
684 | LJ[i][2]; |
---|
685 | L[j]=list(-1,makeDivisor(LJ[i][1],ideal(1))); |
---|
686 | j=j+1; |
---|
687 | }; |
---|
688 | E.summands=L; |
---|
689 | return(E);} |
---|
690 | |
---|
691 | |
---|
692 | |
---|
693 | |
---|
694 | //////////////////////////////////////////////////////////////////////////////// |
---|
695 | // P-divisors |
---|
696 | |
---|
697 | proc makePDivisor(list L) |
---|
698 | "USAGE: makePDivisor(L); L = list.@* |
---|
699 | ASSUME: L is a list of tuples of a integral polyhedron and a divisor such that |
---|
700 | all polyhedra have the same tail cone. |
---|
701 | RETURN: a pdivisor on X |
---|
702 | THEORY: Represents an polyhedral formal sum of divisors. |
---|
703 | KEYWORDS: divisors, polyhedra |
---|
704 | EXAMPLE: example makePDivisor; shows an example |
---|
705 | " |
---|
706 | { |
---|
707 | pdivisor P; |
---|
708 | list CP = decomposePolyhedron(L[1][1]); |
---|
709 | P.tail = CP[1]; |
---|
710 | list LP; |
---|
711 | LP[1]=list(CP[2],L[1][2]); |
---|
712 | int i; |
---|
713 | for (i=2; i<=size(L);i++){ |
---|
714 | CP = decomposePolyhedron(L[i][1]); |
---|
715 | if (!(CP[1]==P.tail)) {ERROR("All P-coefficients should have the same tail cone");} |
---|
716 | LP[i]=list(CP[2],L[i][2]); |
---|
717 | } |
---|
718 | P.summands = LP; |
---|
719 | return(P); |
---|
720 | } |
---|
721 | example |
---|
722 | { "EXAMPLE:"; |
---|
723 | ring r=31991,(x,y,z),dp; |
---|
724 | ideal I = y^2*z - x*(x-z)*(x+3*z); |
---|
725 | qring Q = std(I); |
---|
726 | divisor A = makeDivisor(ideal(x,z),ideal(1)); |
---|
727 | divisor B = makeDivisor(ideal(x,y),ideal(1)); |
---|
728 | intmat M[4][4]= 1,4,0,0, |
---|
729 | 1,0,3,0, |
---|
730 | 0,0,0,2, |
---|
731 | 1,1,1,1; |
---|
732 | polytope PP = polytopeViaPoints(M); |
---|
733 | makePDivisor(list(list(PP,A),list(PP,B))); |
---|
734 | } |
---|
735 | |
---|
736 | static proc decomposePolyhedron(polytope P){ |
---|
737 | bigintmat rays = vertices(P); |
---|
738 | bigintmat rays2 = rays; |
---|
739 | int i,j; |
---|
740 | for (i=1; i<=nrows(rays);i++){ |
---|
741 | if (rays[i,1]==1) { |
---|
742 | for (j=1; j<=ncols(rays);j++){ |
---|
743 | rays[i,j]=0; |
---|
744 | } |
---|
745 | } else { |
---|
746 | for (j=1; j<=ncols(rays);j++){ |
---|
747 | rays2[i,j]=0; |
---|
748 | } |
---|
749 | } |
---|
750 | } |
---|
751 | cone C = coneViaPoints(rays); |
---|
752 | polytope C2 = polytopeViaPoints(rays2); |
---|
753 | return(list(C,C2)); |
---|
754 | } |
---|
755 | |
---|
756 | |
---|
757 | proc evaluatePDivisor(pdivisor D,intvec v) |
---|
758 | "USAGE: evaluatePDivisor(D,v); D = pdivisor, v = intvec.@* |
---|
759 | ASSUME: D is a polyhedral divisor on X and v is a point in the dual of the |
---|
760 | tailcone of the coefficients. |
---|
761 | RETURN: a formal divisor on X |
---|
762 | THEORY: Will evaluate the polyhedral sum to an integer formal sum. |
---|
763 | KEYWORDS: divisors, polyhedra |
---|
764 | EXAMPLE: example evaluatePDivisor; shows an example |
---|
765 | " |
---|
766 | { |
---|
767 | formaldivisor vD; |
---|
768 | list L = D.summands; |
---|
769 | cone C = D.tail; |
---|
770 | cone dC = dualCone(C); |
---|
771 | list vL; |
---|
772 | int i; |
---|
773 | intvec vv = 0,v; |
---|
774 | if (!(containsInSupport(dC,vv))) |
---|
775 | {ERROR("the linear form given should be in the dual tail cone");} |
---|
776 | for (i=1; i<=size(L);i++){ |
---|
777 | vL[i]=list(); |
---|
778 | vL[i][2]=L[i][2]; |
---|
779 | vL[i][1]=Polymake::minimalValue(L[i][1],vv); |
---|
780 | } |
---|
781 | vD.summands = vL; |
---|
782 | return(vD);} |
---|
783 | example |
---|
784 | { "EXAMPLE:"; |
---|
785 | LIB("polymake.so"); |
---|
786 | ring r=31991,(x,y,z),dp; |
---|
787 | ideal I = y^2*z - x*(x-z)*(x+3*z); |
---|
788 | qring Q = std(I); |
---|
789 | divisor A = makeDivisor(ideal(x,z),ideal(1)); |
---|
790 | divisor B = makeDivisor(ideal(x,y),ideal(1)); |
---|
791 | intmat M[4][4]= 1,4,0,0, |
---|
792 | 1,0,3,0, |
---|
793 | 0,0,0,2, |
---|
794 | 1,1,1,1; |
---|
795 | polytope PP = polytopeViaPoints(M); |
---|
796 | pdivisor pD = makePDivisor(list(list(PP,A),list(PP,B))); |
---|
797 | intvec v=1,1,1; |
---|
798 | evaluatePDivisor(pD,v); |
---|
799 | } |
---|
800 | |
---|
801 | |
---|
802 | |
---|
803 | |
---|
804 | |
---|
805 | proc pdivisorplus(pdivisor A, pdivisor B) |
---|
806 | "USAGE: pdivisorplus(A ,B); A + B; A = pdivisor, B = pdivisor. @* |
---|
807 | ASSUME: A and B are polyhedral divisors on X. |
---|
808 | RETURN: a pdivisor on X |
---|
809 | THEORY: The procedure will add the polyhedral formal sums by doing Minkowski sums. |
---|
810 | KEYWORDS: divisors, polyhedra |
---|
811 | EXAMPLE: example pdivisorplus; shows an example |
---|
812 | " |
---|
813 | { |
---|
814 | pdivisor C; |
---|
815 | int i,p; |
---|
816 | int j=1; |
---|
817 | if (!(A.tail==B.tail)) {ERROR("tail cones should be equal");} |
---|
818 | list L; |
---|
819 | list LA=A.summands; |
---|
820 | list LB=B.summands; |
---|
821 | for (i=1; i<=size(LA);i++){ |
---|
822 | p=position(LA[i][2],L); |
---|
823 | if (p==0) { |
---|
824 | L[j]=list(); |
---|
825 | L[j][2]=LA[i][2]; |
---|
826 | L[j][1]=LA[i][1]; |
---|
827 | j=j+1; |
---|
828 | } else { |
---|
829 | L[p][1]=Polymake::minkowskiSum(L[p][1],LA[i][1]); |
---|
830 | }; |
---|
831 | } |
---|
832 | for (i=1; i<=size(LB);i++){ |
---|
833 | p=position(LB[i][2],L); |
---|
834 | if (p==0) { |
---|
835 | L[j]=list(); |
---|
836 | L[j][2]=LB[i][2]; |
---|
837 | L[j][1]=LB[i][1]; |
---|
838 | j=j+1; |
---|
839 | } else { |
---|
840 | L[p][1]=Polymake::minkowskiSum(L[p][1],LB[i][1]); |
---|
841 | }; |
---|
842 | } |
---|
843 | C.summands = L; |
---|
844 | C.tail = A.tail; |
---|
845 | return(C); |
---|
846 | } |
---|
847 | example |
---|
848 | { "EXAMPLE:"; |
---|
849 | LIB("polymake.so"); |
---|
850 | ring r=31991,(x,y,z),dp; |
---|
851 | ideal I = y^2*z - x*(x-z)*(x+3*z); |
---|
852 | qring Q = std(I); |
---|
853 | divisor A = makeDivisor(ideal(x,z),ideal(1)); |
---|
854 | divisor B = makeDivisor(ideal(x,y),ideal(1)); |
---|
855 | intmat M[4][4]= 1,4,0,0, |
---|
856 | 1,0,3,0, |
---|
857 | 0,0,0,2, |
---|
858 | 1,1,1,1; |
---|
859 | polytope PP = polytopeViaPoints(M); |
---|
860 | pdivisor pD = makePDivisor(list(list(PP,A),list(PP,B))); |
---|
861 | pdivisorplus(pD,pD); |
---|
862 | } |
---|
863 | |
---|
864 | |
---|