source: git/Singular/LIB/divisors.lib @ 6391eb

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