CoCoA:HowTo:Plot order ideals

From ApCoCoAWiki

About

At the CoCoA Summer School 2005 there was a discussion about the possibility to plot order ideals. An order ideal is simply the complement of an ideal's leading term ideal, otherwise it could be described as a vector space basis of the quotient space P/I consisting of monomials (this is exactly the B in Macaulay's Basis Theorem with respect to the notation of Kreuzer's & Robbiano's book).

The question was, if there is any software to visualize this order ideals for polynomial rings in two or three indeterminates. During the school, Anna Bigatti and Daniel Heldt developed tools to plot order ideals.

These tools use CoCoa 4 and either POV-Ray or Latex. The code uses CoCoA's QuotientBasis command, to get a list of all terms to draw and than draws this terms (or selects which of them should be drawn and which are invisible, in case of the latex pictures).


The code to plot the order ideals is given in the next sections:

CoCoA & Latex Code (1. Version)

Both functions (this and the next one) get as input a zero-dimensional ideal. The output is some text, containing the latex picture enviroment. simply render this to get a picture of your order ideal. You can even change the point of view of the model, by changing V1, V2, V3 and L1, L2, L3. How this exactly works can be figured out quite easily, having a look at a latex documentation for the picture enviroment.

 Define BorderTeX(I)
 String:='\begin{picture}(300,300)';

 // define your coordinate system:
 Offset := Vector(150,150);
 V1 := Vector(-1,-1);
 V2 := Vector(0,1);   
 V3 := Vector(1,0);
 L1 := 14;
 L2 := 20;
 L3 := 20;

 // get the Vectorspace-Basis of P/I:

 B := QuotientBasis(I);

 // check what to paint for what Basis Element:

 // Check for all Elements in Basis what to draw:
 ForEach El_B In B Do
   L := Log(El_B);   
   Start := Offset + L1*L[1]*V1 + L2*L[2]V2 + L3*L[3]*V3;
  
   If Not(Indet(1)*Indet(2)*El_B IsIn B) And L[3] > 0 Then
     Line := '\put('+Sprint(Start[1])+','+Sprint(Start[2])+')
 {\line('+Sprint(-V3[1])+','+Sprint(-V3[2])+'){'+Sprint(L3)+'}}';
     String := String + Line;
   EndIf;   
   If Not(Indet(1)*Indet(3)*El_B IsIn B) And L[2] > 0 Then
     Line := '\put('+Sprint(Start[1])+','+Sprint(Start[2])+')
 {\line('+Sprint(-V2[1])+','+Sprint(-V2[2])+'){'+Sprint(L2)+'}}';
     String := String + Line;
   EndIf;   
   If Not(Indet(2)*Indet(3)*El_B IsIn B) And L[1] > 0 Then
     Line := '\put('+Sprint(Start[1])+','+Sprint(Start[2])+')
 {\line('+Sprint(-V1[1])+','+Sprint(-V1[2])+'){'+Sprint(L1)+'}}';
     String := String + Line;
   EndIf;   
  
 EndForEach;
 
 Return String+'\end{picture}';
 EndDefine;

code by dheldt 08:37, 22 Jun 2005 (CEST)

CoCoA & Latex Code (2. Version)

I created another version, a little bit more sophisticated. It contains coordinate axis and scales the picture enviroment to the right size. The code for this is:

 Define Border(I)
  
  //////////////////////////////////////////////////////////////////////////////
  // define your coordinate system:
  Offset := Vector(150,150);
  V1 := Vector(-1,-1);    L1 := 14;
  V2 := Vector(0,1);   L2 := 20;
  V3 := Vector(1,0);   L3 := 20;
 
  Max1 := 0;
  Max2 := 0;
  Max3 := 0;
    
  //////////////////////////////////////////////////////////////////////////////
  // get the Vectorspace-Basis of P/I:   
  B := QuotientBasis(I);
   
  //////////////////////////////////////////////////////////////////////////////
  // Compute picture's size:
  ForEach El_B In B Do
     L := Log(El_B);   
     If L[1] > Max1 Then Max1 := L[1]; EndIf;
     If L[2] > Max2 Then Max2 := L[2]; EndIf;
     If L[3] > Max3 Then Max3 := L[3]; EndIf;
  EndForEach;
    
  Max1:= Max1 + 1; Max2 := Max2 +1; Max3 := Max3 +1;
 
  Width  := Sum([ Abs(LC((Max1+3)*L1*V1[1])),Abs(LC((Max2+3)*L2*V2[1])),Abs(LC((Max3+3)*L3*V3[1])) ]);
  Height := Sum([ Abs(LC((Max1+3)*L1*V1[2])),Abs(LC((Max2+3)*L2*V2[2])),Abs(LC((Max3+3)*L3*V3[2])) ]);
 
  String:='\begin{picture}('+Sprint(Width)+','+Sprint(Height)+')';
 
  //////////////////////////////////////////////////////////////////////////////
  // Compute Offset / (0,0,0):
  Offset:=Vector(Abs(Min([ LC((Max1+3)*L1*V1[1]),LC((Max2+3)*L2*V2[1]),LC((Max3+3)*L3*V3[1])])),
               Abs(Min([ LC((Max1+3)*L1*V1[2]),LC((Max2+3)*L2*V2[2]),LC((Max3+3)*L3*V3[2])])));
 
  //////////////////////////////////////////////////////////////////////////////
  // Check for all Elements in Basis what to draw:
  ForEach El_B In B Do
     L := Log(El_B);   
     Start := Offset + L1*L[1]*V1 + L2*L[2]V2 + L3*L[3]*V3;
     
     If Not(Indet(1)*Indet(2)*El_B IsIn B) And L[3] > 0 Then
           Line := '\put('+Sprint(Start[1])+','+Sprint(Start[2])+')
                   {\line('+Sprint(-V3[1])+','+Sprint(-V3[2])+'){'+Sprint(L3)+'}}';
           String := String + Line;
     EndIf;   
     If Not(Indet(1)*Indet(3)*El_B IsIn B) And L[2] > 0 Then
           Line := '\put('+Sprint(Start[1])+','+Sprint(Start[2])+')
                   {\line('+Sprint(-V2[1])+','+Sprint(-V2[2])+'){'+Sprint(L2)+'}}';
           String := String + Line;
     EndIf;   
     If Not(Indet(2)*Indet(3)*El_B IsIn B) And L[1] > 0 Then
           Line := '\put('+Sprint(Start[1])+','+Sprint(Start[2])+')
                   {\line('+Sprint(-V1[1])+','+Sprint(-V1[2])+'){'+Sprint(L1)+'}}';
           String := String + Line;
     EndIf;   
  EndForEach;
 
  //////////////////////////////////////////////////////////////////////////////
  // Draw the three axis and the indeterminates names:
 
  Start := Offset + Max1 * V1 * L1;
  String := String + '\put('+Sprint(Start[1])+','+Sprint(Start[2])+')
                   {\vector('+Sprint(V1[1])+','+Sprint(V1[2])+'){'+Sprint(2*L1)+'}}';
            
  String := String + '\put('+Sprint(Start[1]+3*L1*V1[1])+','+Sprint(Start[2]+3*L1*V1[2])+')
                   {$\displaystyle ' +Sprint(Indet(1))+'$}';
 
  Start := Offset + Max2 * V2 * L2;
  String := String + '\put('+Sprint(Start[1])+','+Sprint(Start[2])+')
                   {\vector('+Sprint(V2[1])+','+Sprint(V2[2])+'){'+Sprint(2*L2)+'}}';
 
  String := String + '\put('+Sprint(Start[1]+3*L2*V2[1])+','+Sprint(Start[2]+3*L2*V2[2])+')
                   {$\displaystyle ' +Sprint(Indet(2))+'$}';
 
  Start := Offset + Max3 * V3 * L3;
  String := String + '\put('+Sprint(Start[1])+','+Sprint(Start[2])+')
                   {\vector('+Sprint(V3[1])+','+Sprint(V3[2])+'){'+Sprint(2*L3)+'}}';
 
  String := String + '\put('+Sprint(Start[1]+3*L3*V3[1])+','+Sprint(Start[2]+3*L3*V3[2])+')
                   {$\displaystyle ' +Sprint(Indet(3))+'$}';
 
  Return String+'\end{picture}';
 EndDefine;

code by dheldt 08:37, 22 Jun 2005 (CEST)

Latex Framework

As a framework where to copy&paste the output to, you can use the following latex code:

 \documentclass[12pt,a4paper]{article}
 
 \usepackage{umlaut,a4wide,amsmath,amssymb,stmaryrd,color,graphicx,fancyhdr,multicol}
 \usepackage[latin1]{inputenc}
 \setlength{\parindent}{0mm}
 
 \begin{document}
 
 % Copy output here!
 
 \end{document}

code by dheldt 08:37, 22 Jun 2005 (CEST)

CoCoA & POV-Ray Code

This function returns some POV-Ray code to plot the quotient ideal of the input ideal (not necessarily zero-dimensional). The output of QuotientBasisPOV should be saved into a file called "monomials.inc" (see the example below), in order to be included by QuotienBasis.pov:

 Define NewLine()
   Return "
 ";
 EndDefine; -- NewLine
 
 Define QuotientBasisPOV(I)
   If NumIndets()<>3 Then Error("QuotientBasisPOV: ring must have 3 indeterminates"); EndIf;
   String := "";
   GENS := Interreduced(Gens(I));
   -----
   XMax := Max([Deg(T, Indet(1)) | T In GENS]);
   YMax := Max([Deg(T, Indet(2)) | T In GENS]);
   ZMax := Max([Deg(T, Indet(3)) | T In GENS]);
   XYZMax := Max(XMax, YMax, ZMax);
   -----
   String := String + "#declare CamZoom="
   + Sprint(100/Isqrt(XYZMax)) +";"
   + NewLine();
   String := String + "#declare CamEye=<0,"
   + Sprint(ZMax/4) +",0>;"
   + NewLine();
 
   -----
   G1 := [Indet(1)^(XMax+1), Indet(2)^(YMax+1), Indet(3)^(ZMax+1)];
   G2 := [G1[1]*Indet(1), G1[2]*Indet(2), G1[3]*Indet(3)];
 --  G2 := [Indet(1)^(XYZMax+2), Indet(2)^(XYZMax+2), Indet(3)^(XYZMax+2)];
   ----- axes
   String := String + "#declare AxisTags = union {" + NewLine();
     Line := "object {object AxisTag(""x"") translate <"
     +Sprint(XMax+3) + ",0,0.1> }" + NewLine();
     String := String + Line;
     Line := "object {object AxisTag(""y"") translate <0,"
     +Sprint(YMax+3) + ",0.1> }" + NewLine();
     String := String + Line;
     Line := "object {object AxisTag(""z"") translate <0,0.1,"
     +Sprint(ZMax+3) + "> }" + NewLine();
     String := String + Line;
   String :=  String + "}" + NewLine();
   ----- Generators
   String := String + "#declare Generators = union {" + NewLine();
   ForEach G In GENS Do
     L := Log(G);
     Line := "union { object{Generator} ";
     String := String + Line;
     Line := "object Exponents(""" +
     + Sprint(L[1]) + " " + Sprint(L[2]) + " " + Sprint(L[3])
     + """) translate <"
     +Sprint(L[1]) + "," + Sprint(L[2]) + "," + Sprint(L[3])
     +"> }" + NewLine();
     String := String + Line;
   EndForEach;
   String :=  String + "}" + NewLine();
   ----- Monomials
   B := QuotientBasis(I+Ideal(G1)); 
   String := String + "#declare Monomials = union {" + NewLine();
   ForEach El_B In B Do
     L := Log(El_B);
     Line := "object{ SolidCube() translate <"+
     Sprint(L[1]) + "," + Sprint(L[2]) + "," + Sprint(L[3])
     +"> }" + NewLine();
     String := String + Line;
   EndForEach;
   String :=  String + "}" + NewLine();
   ---- InftyMonomials
   B := Diff(QuotientBasis(I+Ideal(G2)), QuotientBasis(I+Ideal(G1)));
   String := String + "#declare InftyMonomials = union {" + NewLine();
   ForEach El_B In B Do
     L := Log(El_B);
     Line := "object{ SolidCube() translate <"+
     Sprint(L[1]) + "," + Sprint(L[2]) + "," + Sprint(L[3])
     +"> }" + NewLine();
     String := String + Line;
   EndForEach;
   String :=  String + "}" + NewLine();
   ---- 
   Return String;
 EndDefine; -- QuotientBasisPOV
 
 /*
 -- EXAMPLE --
 Use Q[x,y,z];
 
 I := Ideal(x^10yz^6, x^7y^2z^3, xy^3z^4, x^3y^3z^3, xy^4z^4, y^6);
 F := OpenOFile("/Users/bigatti/Desktop/POV-Anna/monomials.inc", "w");
 PrintLn QuotientBasisPOV(I) On F;
 */

code by bigatti, 27 Jun 2005

POV-Ray Framework

This is the file QuotientBasis.pov, the file including "monomials.inc". You should run it with POV-Ray with antialiasing on.

 // Copyright (c) 2005  Anna Bigatti
 // You are free to use any part of this example in your own programs.
 
 // ------------------------------
 #include "colors.inc"
 #include "functions.inc"
 #include "textures.inc"
 #include "metals.inc"
 #include "glass.inc"
 
 global_settings{
     max_trace_level 50
     adc_bailout 0.01
 }
 
 // ------------------------------
 // Set settings
 // ------------------------------
 #declare CamLoc=<500,500,-500>;
 #declare AspectRatio=4/3;
 
 light_source{<500,400,-200> color White*5}
 //plane{y,0 texture{pigment{rgbf <0.89, 0.98, 1.0, 0.95>}finish{F_Glass5}} hollow}
 
 
 //------------------------------
 // colours
 //------------------------------
 sky_sphere{ pigment{ color Gray90 } }
 
 #declare P_X = rgbf <0.04, 0.25, 0, 0>;
 #declare P_Y = rgbf <0.30, 0.35, 0, 0>;
 #declare P_Z = rgbf <0.05, 0.05, 0.4, 0>;
 #declare P_Cube =      rgbf <0.01, 0.01, .3, 0>;
 #declare P_ClearCube = rgbf <0.4, 0.5, .6, .9>;
 #declare P_Exponent =  rgbt <.2,1,.2,.0>;
 
 
 #declare Generator =  sphere{0, .2 texture {T_Brass_2A} }
 
 #declare Axes = union {
 cylinder { <0, 0, 0>, <500, 0, 0>, 0.05 pigment {color P_X} }
 cylinder { <0, 0, 0>, <0, 500, 0>, 0.05 pigment {color P_Y}  }
 cylinder { <0, 0, 0>, <0, 0, 500>, 0.05 pigment {color P_Z}  }
 }
 
 // ------------------------------
 // creates the cube
 // ------------------------------
 #macro SolidCube()
 union{
     #declare sB=0.48;
     #declare rB=0.02;
     union{
         cylinder{-sB*x,sB*x,rB translate <0,sB,sB> pigment {color P_X}}
         cylinder{-sB*x,sB*x,rB translate <0,-sB,sB> pigment {color P_X}}
         cylinder{-sB*x,sB*x,rB translate <0,sB,-sB> pigment {color P_X}}
         cylinder{-sB*x,sB*x,rB translate <0,-sB,-sB> pigment {color P_X}}
         cylinder{-sB*y,sB*y,rB translate <sB,0,sB>  pigment {color P_Y}}
         cylinder{-sB*y,sB*y,rB translate <sB,0,-sB> pigment {color P_Y}}
         cylinder{-sB*y,sB*y,rB translate <-sB,0,sB> pigment {color P_Y}}
         cylinder{-sB*y,sB*y,rB translate <-sB,0,-sB> pigment {color P_Y}}
         cylinder{-sB*z,sB*z,rB translate <sB,sB,0> pigment {color P_Z}}
         cylinder{-sB*z,sB*z,rB translate <sB,-sB,0> pigment {color P_Z}}
         cylinder{-sB*z,sB*z,rB translate <-sB,sB,0> pigment {color P_Z}}
         cylinder{-sB*z,sB*z,rB translate <-sB,-sB,0> pigment {color P_Z}}
         sphere{0,rB translate <sB,sB,sB>}
         sphere{0,rB translate <sB,sB,-sB>}
         sphere{0,rB translate <sB,-sB,sB>}
         sphere{0,rB translate <sB,-sB,-sB>}
         sphere{0,rB translate <-sB,sB,sB>}
         sphere{0,rB translate <-sB,sB,-sB>}
         sphere{0,rB translate <-sB,-sB,sB>}
         sphere{0,rB translate <-sB,-sB,-sB>}
     }
 
     box{-0.45,0.45 interior{ior 1.1} }
     
   translate <sB-rB, sB-rB, sB-rB>
 }
 #end
 
 
 #macro Exponents(Exp)
 {text { 
   ttf "crystal.ttf", 
   Exp, 
   .03,  
   <-.1,0,0>     
   scale < .7, .7,.7>   
   matrix <
   0, 1, 0.7,
   0, 0, 0.7,
   1, 0, 0,
   .7, 0, 0.4>
   pigment {color P_Exponent}
   no_reflection
   no_shadow
 }} 
 #end
 
 #macro AxisTag(Exp)
 {text { 
   ttf "crystal.ttf", 
   Exp,
   .03,  
   <-.1,0,0>     
 //  scale < .7, .7,.7>   
   matrix <
   0, 1, 0.7,
   0, 0, 0.7,
   1, 0, 0,
   0, 0, 0.1>
   pigment {color Gray20}
   no_reflection
   no_shadow
 }} 
 #end
 
 // ------------------------------
 // scene
 // ------------------------------
 #include "monomials.inc"     // place the cubes
 
 camera {
         location CamLoc
         direction z*CamZoom
         right x*AspectRatio
         look_at CamEye
 }
 
 union{
   object {Generators}
   object {Axes}
   object {AxisTags}
   object {Monomials  texture{pigment{color P_Cube}}}
   object {InftyMonomials  texture{pigment{color P_ClearCube}}}
   matrix <
   0, 0, -1,
   1, 0, 0,
   0, 1, 0,
   0, 0, 0
 >
 
 }

code by bigatti, 27 Jun 2005