Changeset 6f2edc in git for Singular/LIB


Ignore:
Timestamp:
Apr 28, 1997, 9:27:25 PM (27 years ago)
Author:
Olaf Bachmann <obachman@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
8c5a578cc8481c8a133a58030c4c4c8227d82bb1
Parents:
6d09c564c80f079b501f7187cf6984d040603849
Message:
Mon Apr 28 21:00:07 1997  Olaf Bachmann
<obachman@ratchwum.mathematik.uni-kl.de (Olaf Bachmann)>

     * dunno why I am committing these libs -- have not modified any
       of them


git-svn-id: file:///usr/local/Singular/svn/trunk@205 2c84dea3-7e68-4137-9b89-c4e89433aadc
Location:
Singular/LIB
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • Singular/LIB/deform.lib

    r6d09c56 r6f2edc  
    1 // $Id: deform.lib,v 1.1.1.1 1997-04-25 15:13:25 obachman Exp $
    2 //(BM+GMG)
     1// $Id: deform.lib,v 1.2 1997-04-28 19:27:15 obachman Exp $
     2//(BM/GMG, last modified 22.06.96)
    33///////////////////////////////////////////////////////////////////////////////
    44LIBRARY:  deform.lib    PROCEDURES FOR COMPUTING MINIVERSAL DEFORMATION
    55
    66 miniversal(id[,deg]);  miniversal deformation of an isolated singularity id
    7  
     7
    88  SUB-PROCEDURES        used by main procedure:
    99  apply_col(A,B);       put A into col-nf and apply same col-operations to B
     
    1515LIB "inout.lib";
    1616LIB "general.lib";
    17 LIB "sing.lib"; 
     17LIB "sing.lib";
    1818LIB "matrix.lib";
    1919///////////////////////////////////////////////////////////////////////////////
    2020
    2121proc miniversal (ideal id,list #)
    22 USAGE:   miniversal(id[,d,na,va,o,iv]); id=ideal, d=integer, 
     22USAGE:   miniversal(id[,d,na,va,o,iv]); id=ideal, d=integer,
    2323         na,va,o=strings, iv=intvec of positive integers
    2424COMUPTE: miniversal deformation of id up to degree d (default d=100)
     
    2626         the basering by new variables given by va (deformation parameters).
    2727         -- The new vars come before the old vars
    28          -- The characteristic of `na`is the characteristic of the basering.
    29          -- The new vars are derived from va. If va is a single letter, say 
    30             va="T", and if n<=26 then T and the following n-1 letters from 
    31             T..Z..T (resp. T(1..n) if n>26) are taken as additional variables. 
    32             If va is a single letter followed by (, say va="x(", the new 
     28         -- The characteristic of `na`   is the characteristic of the basering.
     29         -- The new vars are derived from va. If va is a single letter, say
     30            va="T", and if n<=26 then T and the following n-1 letters from
     31            T..Z..T (resp. T(1..n) if n>26) are taken as additional variables.
     32            If va is a single letter followed by (, say va="x(", the new
    3333            variables are x(1),...,x(n) (default va="A").
    3434         -- The ordering is the product ordering between the ordering of r and
    35             an ordering derived from `o`, which has to be local!! (default: 
    36             o="ds") [and iv (a weight vector)]. 
     35            an ordering derived from `o`, which has to be local!! (default:
     36            o="ds") [and iv (a weight vector)].
    3737            Type 'help extendring' for a more detailed explanation of the
    38             ordering 
    39          -- Even if na,va,o are given, d and/or iv may be ommited. Then the 
     38            ordering
     39         -- Even if na,va,o are given, d and/or iv may be ommited. Then the
    4040            default values d=100, iv=0 (i.e. all weights = 1) are used.
    4141         The procedure creates also two ideals:
    4242            ideal jetJ - defining the miniversal base space (in `na`)
    4343            ideal jetF - defining miniversal total space (in `na`)
    44 NOTE:    int printlevel=2;  shows what is going on
    45          int printlevel=3;  shows also memory usage
    46          This proc uses 'execute' or calls a procedure using 'execute'.
    47          If you use it in your own proc, let the local names of your proc
     44NOTE:    printlevel >=0: display dimT1,T2 and explain created objects (default)
     45         printlevel >=1: show partial + final result during computation
     46         printlevel >=2: show also memory and time usage
     47         printlevel >=3: test and show obstructions
     48         printlevel >=4: create a file 'minbaseout' and (over) write part of
     49                         ideal of miniversal base up to current degree into it
     50         This proc uses 'execute' or calls a procedure using 'execute'.
     51         If you use it in your own proc, let the local names of your proc
    4852         start with @ (see the file HelpForProc)
    49 EXAMPLE: example miniversal; shows an example 
     53EXAMPLE: example miniversal; shows an example
    5054{
    5155//------- initialisation ------------------------------------------------------
    52    int @d,@deg,@t1,@t2,@colR,@noObstr;
     56   int @d,@deg,@t1,@t2,@colR,@noObstr,@j;
     57   int p = printlevel-voice+3;  // p=printlevel+1 (default: p=1)
    5358   intvec @iv,@jv;
    5459   string @na,@va,@o;
     
    6065   if( size(#)==4 ) { @deg=#[1]; @na=#[2];  @va=#[3]; @o=#[4];}
    6166   if( size(#)==5 ) { @deg=#[1]; @na=#[2];  @va=#[3]; @o=#[4]; @iv=#[5]; }
    62    if( find(@o,"s")==0 ) 
     67   if( find(@o,"s")==0 )
    6368   { "// ordering must be an s-ordering, please change!"; return();}
    64  
    65   def @Pn = basering; 
    66    string @ords = ordstr(@Pn);   
     69
     70  def @Pn = basering;
     71   string @ords = ordstr(@Pn);
    6772   id = simplify(id,10);
    6873   int @rowR = size(id);
    6974   if( @rowR<=1 )
    70    { 
     75   {
    7176      "// hypersurface, use proc deform from sing.lib";
    7277      return();
    73    }   
     78   }
    7479//------- change ordering if not correct --------------------------------------
    7580   @t1=1;
    76    for( @d=1;@d<=nvars(@Pn);@d++ ) { @t1=@t1*(lead(1+var(@d))==var(@d)); }
     81   for( @d=1;@d<=nvars(@Pn);@d=@d+1 ) { @t1=@t1*(lead(1+var(@d))==var(@d)); }
    7782   if( @t1==0 )
    7883   {
    79       if( @ords[size(@ords)]!="c" and @ords[size(@ords)]!="C" ) 
    80       { 
     84      if( @ords[size(@ords)]!="c" and @ords[size(@ords)]!="C" )
     85      {
    8186         if( @ords[1]=="c" ) { @ords=@ords[3,size(@ords)-2]+",c"; @t1=1;}
    8287         if( @ords[1]=="C" ) { @ords=@ords[3,size(@ords)-2]+",C"; @t1=1;}
    8388      }
    84       if( @t1==1 ) 
    85       { 
     89      if( @t1==1 )
     90      {
    8691         changeord("@On",@ords,@Pn);
    8792         ideal id  = imap(@Pn,id);
     
    9095   if( defined(@On)==0 ) { def @On=@Pn; setring @On; }
    9196//-------  reproduce T12 -------------------------------------------------------
    92    list   Ls   = T12(id,1); 
    93    matrix Ro   = Ls[4];                         //syz(i)
    94    matrix InfD = Ls[3];                         //matrix of inf. deformations
    95    matrix PreO = Ls[5];                         //present. mat of Syz/Kos^*
    96    module PreT = Ls[2];                         //present. module of modT2
    97    @t1 = Ls[8];                                 //vdim of T1
    98    @t2 = Ls[9];                                 //vdim of T2
     97   list   Ls   = T12(id,1);
     98   matrix Ro   = Ls[6];                         //syz(i)
     99   matrix InfD = Ls[5];                         //matrix of inf. deformations
     100   matrix PreO = Ls[7];                         //present. mat of Syz/Kos^*
     101   module PreT = Ls[9];                         //present. module of modT2
     102   @t1 = Ls[3];                                 //vdim of T1
     103   @t2 = Ls[4];                                 //vdim of T2
    99104   kill Ls;
    100    dbpri(2,"","// ___ matrix of infinitesimal deformations:",InfD);
    101    @colR = ncols(Ro);                 
     105   dbprint(p-1,"","// ___ matrix of infinitesimal deformations:",InfD);
     106   @colR = ncols(Ro);
    102107   ideal i0 = std(id);
    103108  qring @Ox = i0;                               //ring of singularity to deform
    104    matrix Cup,lCup; module PreT;
     109   matrix Cup,lCup;
    105110   ideal testid;
    106111   matrix Ro   = fetch(@On,Ro);
    107112   matrix PreO = fetch(@On,PreO);
     113   module PreT = fetch(@On,PreT);
    108114//---- create new ring with @t1=dim T1 additional variables and initialize ----
    109115
     
    116122   export jetF;
    117123   matrix Fo = matrix(jetF);                    //initial equations
    118    matrix Rs = imap(@On,Ro);                    //deformed syzygies
     124   matrix Ro = imap(@On,Ro);
     125   matrix Rs = imap(@On,Ro);                    //deformed syzygies
    119126   ideal  jetJ;                                 //(jet)ideal of minversal defor
    120127   export jetJ;
     
    132139   jetF= Fs;
    133140   F_R = Fs*Rs;
    134    if (@t2<=0) { @d=0; }                         //finished, if "T2=0" 
     141   if (@t2<=0) { @d=0; }                         //finished, if "T2=0"
    135142//------- start the loop ------------------------------------------------------
    136    for (@d=1;@d<=@deg;@d++)
    137    {
    138       dbpri(2,"","// ___ start computation in degree "+string(@d)+":");
    139       dbpri(3,"memory="+string(kmemory())+"k");
     143   for (@d=1;@d<=@deg;@d=@d+1)
     144   {
     145      dbprint(p-1,"","// ___ start computation in degree "+string(@d)+":");
     146      dbprint(p-2,"// memory = "+string(kmemory())+"k");
    140147//------- lift relation to next degree ----------------------------------------
    141       F_r = reduce_s(F_R,Jo,@d+1); 
     148      F_r = reduce_s(F_R,Jo,@d+1);
    142149      Cup = matrix(jet(F_r,@d,@jv),1,@colR);
    143150      Rn  = (-1)*lift(Fo,Cup);
    144151      Rs  = Rs + Rn;
    145       F_R = F_R + Fs*Rn; 
     152      F_R = F_R + Fs*Rn;
    146153//------- test: already finished? ---------------------------------------------
    147154      testid = simplify(reduce(ideal(F_R),Jo),10);
    148155      if (testid[1]==0)
    149       {
    150          "// computation finished in degree "+string(@d);
    151          if( @d==@deg )
    152          {"// degree bound reached, result may not yet be complete!";}
     156      {  dbprint(p,"// ___ computation finished in degree "+string(@d));
     157         if( @d==@deg )
     158         { dbprint(p,"// ___ degree bound reached, result may not yet be complete!");}
    153159         break;
    154160      }
    155161//------- compute obstruction-matrix  -----------------------------------------
    156       F_r = reduce_s(F_R,Jo,@d+1); 
    157       Cup = matrix(jet(F_r,@d+1,@jv),1,@colR); 
     162      F_r = reduce_s(F_R,Jo,@d+1);
     163      Cup = matrix(jet(F_r,@d+1,@jv),1,@colR);
    158164      Test= Cup;
    159       dbpri(2,"","// ___ obstruction vector:",ideal(Cup));
     165      dbprint(p-3,"","// ___ obstruction vector:",ideal(Cup));
    160166      Cup,Mon = coef_ideal(Cup,@t1);
    161167//------- express obstructions in kbase of T2  --------------------------------
     
    163169      Cup  = imap(`@na`,Cup);
    164170      lCup = lift(PreO,Cup);
    165       PreT = fetch(@On,PreT);
    166171      lCup = lift_kbase(lCup,PreT);
    167172      @t2   = nrows(lCup);
    168       dbpri(2,"","// ___ obstructions in kbase of T2:",lCup);
    169       testid = simplify(ideal(lCup),10);           // test no obstructions
     173      dbprint(p-3,"","// ___ obstructions in kbase of T2:",lCup);
     174      testid = simplify(ideal(lCup),10);               // test no obstructions
    170175      if (testid[1]==0)
    171       { @noObstr=1; } else { @noObstr=0; }
    172 //------- compute ideal of minversal(its k-jet) -------------------------------
     176      { @noObstr=1;dbprint(p-3,"// ___ no obstruction"); } else { @noObstr=0; }
     177      @j=size(module(gauss_col(lCup)));                // test:full obstruction
     178      if (@j==ncols(lCup))
     179      {  dbprint(p,"","// nothing to lift!",
     180         "// ___ miniversal base, defined by jetJ, is a fat point!");
     181         break;
     182      }
     183//------- compute ideal of minversal base (its k-jet) -------------------------
    173184   setring `@na`;
    174       if (@noObstr==0)                              //case of non-zero obstr.     
     185      if (@noObstr==0)                              //case of non-zero obstr.
    175186      {
    176187         lCup = imap(@Ox,lCup);
    177188         Jo   = lCup*transpose(Mon);
    178          jetJ = matrix(jetJ,1,@t2)+matrix(Jo,1,@t2);
    179          dbpri(2,"","// ___ degree-"+string(@d+1)+"-part of ideal of miniversal base"+":",Jo);
     189         jetJ = matrix(jetJ,1,@t2)+matrix(Jo,1,@t2);
     190         dbprint(p-1,"","// ___ degree-"+string(@d+1)+"-part of ideal of miniversal base"+":",Jo);
     191         if( p-1>=4 )
     192         { write (">minbaseout","// part of ideal of miniversal base up to degree <= "+string(@d+1)+":",jetJ); }
    180193         Jo = std(jetJ);
    181 //------- choose a defining system --------------------------------------------
    182          @iv,Cup = defining_system(lCup,Cup);
    183          dbpri(2,"","// ___ number of cols of defining system:",@iv);
    184 //------- lift the equations --------------------------------------------------
    185          if (sum(@iv)==0)
    186          {
    187             "// nothing to lift!";
    188             "// miniversal base, defined by jetJ, is a fat point!";break;
    189          }
    190    setring @Ox;
    191          Cup = imap(`@na`,Cup);
    192          Cup = submat(Cup,1..nrows(Cup),@iv);
    193          dbpri(2,"","// ___ matrix of defining system:",Cup);
    194       }
    195       else                                         // case of zero obstructions
    196       {       
    197    setring @Ox;
    198          Cup = imap(`@na`,Cup);
    199       }   
    200       Cup = lift(transpose(Ro),module(Cup));
    201    setring `@na`;
    202       Cup = imap(@Ox,Cup);
    203       if (@noObstr==0)
    204       {  Mon = submat(Mon,1..nrows(Mon),@iv); }
    205       Fn  = (-1)*transpose(Cup*transpose(Mon));
     194      }
     195      F_r = reduce_s(F_R,Jo,@d+1);
     196      Cup = matrix(jet(F_r,@d+1,@jv),1,@colR);
     197//---------------- repeat test: jetJ ok in deg d+1? --------------------------
     198      if( (p-1>=3) && (@noObstr==0) )
     199      {
     200         lCup,Mon = coef_ideal(Cup,@t1);
     201      setring @Ox;
     202         Cup  = imap(`@na`,Cup);
     203         lCup = lift(PreO,Cup);
     204         lCup = lift_kbase(lCup,PreT);
     205         dbprint(p-3,"","// ____ test: jetJ ok iff all entries are 0",lCup);
     206      setring `@na`;
     207      }
     208//---------------- lift equations F -----------------------------------------
     209      if (defined(Qrg)) {kill Qrg;}
     210  qring Qrg = std(ideal(Fo));
     211      def Ro=fetch(`@na`,Ro);
     212      def Cup=fetch(`@na`,Cup);
     213      def Fn = lift(transpose(Ro),transpose(Cup));
     214      Fn=(-1)*transpose(Fn);
     215  setring `@na`;
     216      Fn  = fetch(Qrg,Fn);
    206217      Fs  = Fs+Fn;
    207       F_R = F_R+Fn*Rs; 
     218      F_R = F_R+Fn*Rs;
    208219      jetF = matrix(Fs);
    209       dbpri(2,"","// ___ degree-"+string(@d+1)+"-part of deformed equations:",Fn);
    210    } 
     220      dbprint(p-1,"","// ___ degree-"+string(@d+1)+"-part of deformed equations:",Fn);
     221   }
    211222//---------  end loop and final output ---------------------------------------
    212   "";
    213   "// ___ Equations of miniversal base space ___";jetJ; "";
    214   "// ___ Equations of miniversal total space ___";jetF; "";
    215   "// Result belongs to ring",@na,"(total space of miniversal deformation).";
    216   "// Make",@na,"the basering and list objects defined in",@na,"by typing:";
    217   "   setring",@na,"; show("+@na+");";
    218   "   listvar(ideal);";
    219   kill @On; 
     223dbprint(p-1,"","// ___ Equations of miniversal base space ___",jetJ,
     224            "","// ___ Equations of miniversal total space ___",jetF);
     225dbprint(p,"","// Result belongs to ring "+@na+".",
     226       "// Equations of total space of miniversal deformation are ",
     227       "// given by jetF, equations of miniversal base space by jetJ.",
     228       "// Make "+@na+" the basering and list objects defined in "+@na+" by typing:",
     229       "   setring "+@na+"; show("+@na+");","   listvar(ideal);");
     230  kill @On;
    220231  return();
    221232}
    222 example 
     233example
    223234{ "EXAMPLE:"; echo = 2;
    224    ring r1=0,(x,y,z,u,v),ds;
    225    matrix m[2][4]=x,y,z,u,y,z,u,v;
    226    ideal i=minor(m,2);          //cone over rational normal curve of degree 4
     235   int p          = printlevel;
     236   ring r1        = 0,(x,y,z,u,v),ds;
     237   matrix m[2][4] = x,y,z,u,y,z,u,v;
     238   ideal i        = minor(m,2);          //cone over rational normal curve of degree 4
    227239   miniversal(i,"R","T(");
    228    // hit return-key to continue;
    229    // pause;
    230    ring  r = 0,(x,y,z),ds;
    231    ideal i = x2,xy,yz,zx;
    232    printlevel = 2;
    233    miniversal(i);"";
    234    kill printlevel;
    235 // NOTE: rings R and Ont are still alive!
    236 
    237 ///////////////////////////////////////////////////////////////////////////////
    238 
    239 proc apply_col (matrix A, matrix B)
     240   setring R;"";
     241   // ___ Equations of miniversal base space ___:
     242   jetJ;"";
     243   // ___ Equations of miniversal total space ___:
     244   jetF;"";
     245   ring  r        = 0,(x,y,z),ds;
     246   ideal i        = x2,xy,yz,zx;
     247   printlevel     = 3;
     248   miniversal(i);"";
     249   printlevel     = p;
     250   // NOTE: rings R and Ont are still alive!
     251}
     252///////////////////////////////////////////////////////////////////////////////
     253
     254proc apply_col (matrix A, matrix B)
    240255USAGE:   apply_col(A,B);  A,B=matrices
    241 ASSUME:  A = constant matrix in row-reduced (upper triangular) normal form, 
     256ASSUME:  A = constant matrix in row-reduced (upper triangular) normal form,
    242257         B = matrix of same size
    243258COMUPTE: apply to B those col-operations which reduce A into col-reduced nf
    244259RETURN:  two transformed matrices: col-reduced A, transformed B
    245 EXAMPLE: example apply_col; shows an example 
     260EXAMPLE: example apply_col; shows an example
    246261{
    247262   int i,j,k;
     
    251266   matrix C  = concat(transpose(A),transpose(B));
    252267   module mC = transpose(C);
    253    for( k=1;k<=r;k++ )
     268   for( k=1;k<=r;k=k+1 )
    254269   {
    255270      j=1;
    256       while( C[j,k]==0 && j<c ) { j++; }
    257       for( i=j+1;i<=c;i++ )
     271      while( C[j,k]==0 && j<c ) { j=j+1; }
     272      for( i=j+1;i<=c;i=i+1 )
    258273      {
    259274         m = C[i,k];
    260          mC[i] = mC[i]-m*mC[j]; 
     275         mC[i] = mC[i]-m*mC[j];
    261276      }
    262277   }
     
    266281   return(transpose(a),transpose(b));
    267282}
    268 example 
     283example
    269284{ "EXAMPLE:"; echo = 2;
    270285   ring R=0,(x,y,z),dp;
     
    279294///////////////////////////////////////////////////////////////////////////////
    280295
    281 proc defining_system (matrix A,matrix B) 
     296proc defining_system (matrix A,matrix B)
    282297USAGE:   defining_system(A,B);  A,B=matrices
    283298ASSUME:  A a constant matrix
     
    287302RETURN:  two objects: intvec iv, matrix M (the transformed matrix B)
    288303         The columns of M with index from iv are a defining sytem
    289 EXAMPLE: example defining_system; shows an example 
     304EXAMPLE: example defining_system; shows an example
    290305{
    291306   int    k,l;
     
    295310   int rg = ncols(A);
    296311   A,B    = apply_col(A,B);                // special columne-reduction
    297    for( k=1;k<=rg;k++ )                  // collect zero-cols of B
    298    {
    299       if( A[k]==0) {l++;iv[l]=k;}        // test if kth column is 0
     312   for( k=1;k<=rg;k=k+1 )                  // collect zero-cols of B
     313   {
     314      if( A[k]==0) {l=l+1;iv[l]=k;}        // test if kth column is 0
    300315   }                                       // collect indices of 0-columns in iv
    301316   return(iv,B);
    302317}
    303 example 
     318example
    304319{ "EXAMPLE:"; echo = 2;
    305320   ring R=0,(x,y,z),dp;
     
    323338  int d,k;
    324339  ideal j0 = std(j);
    325   for (k=1;k<=m;k++)
     340  for (k=1;k<=m;k=k+1)
    326341  {
    327342    if (deg(i[k])>=0)
     
    333348  return(i);
    334349}
    335 example 
     350example
    336351{ "EXAMPLE:"; echo = 2;
    337352   ring r = 0,(x,y),ds;
    338353   poly f = x7+y7+(x-y)^2*x^2*y^2;
    339354   ideal j = jacob(f);
    340    reduce_s(f,j,10); 
     355   reduce_s(f,j,10);
    341356}
    342357///////////////////////////////////////////////////////////////////////////////
     
    344359proc lift_kbase (N, M)
    345360USAGE:   lift_kbase(N,M); N,M=poly/ideal/vector/module
    346 RETURN:  matrix A, coefficient matrix expressing N as linear combination of 
    347          k-basis of M. Let the k-basis have k elements and A c columns.
     361RETURN:  matrix A, coefficient matrix expressing N as linear combination of
     362         k-basis of M. Let the k-basis have k elements and size(N)=c columns.
    348363         Then A satisfies:
    349364             matrix(reduce(N,std(M)),k,c) = matrix(kbase(std(M)))*A
    350 ASSUME:  dim(M)=0 and the monomial ordering is a well ordering or the last 
     365ASSUME:  dim(M)=0 and the monomial ordering is a well ordering or the last
    351366         block of the ordering is c or C
    352367EXAMPLE: example lift_kbase; shows an example
     
    360375//------- check wether ordering is correct ------------------------------------
    361376   k=1;
    362    for( l=1;l<=nvars(basering);l++ ) { k=k*(lead(1+var(l))==var(l)); }
     377   for( l=1;l<=nvars(basering);l=l+1 ) { k=k*(lead(1+var(l))==var(l)); }
    363378   if( k==0 )
    364379   {
    365       if( ords[size(ords)]!="c" and ords[size(ords)]!="C" ) 
    366       { 
     380      if( ords[size(ords)]!="c" and ords[size(ords)]!="C" )
     381      {
    367382         "// change ordering!";
    368          "// ordering "+ordstr(basering)+" not implemented for this proc"; 
    369          return(); 
     383         "// ordering "+ordstr(basering)+" not implemented for this proc";
     384         return();
    370385      }
    371386   }
     
    377392   if( d<1 )
    378393   { "// second argument in `lift_kbase` has vdim",d; return(); }
    379 //----------  compute kbase and reduce(N,M) ----------------------------------- 
     394//----------  compute kbase and reduce(N,M) -----------------------------------
    380395   kb = kbase(M);
    381396   col = ncols(N);
    382397   N = reduce(N,M);
     398   N = matrix(N,nrows(N),col);
    383399//----------  collecting coefficients of reduce(N,M) --------------------------
    384400   matrix result[d][col];
     
    389405      {
    390406         for( k=1;k<=d;k=k+1 )
    391          { 
     407         {
    392408            p = kb[k];
    393             q = lead(v); 
     409            q = lead(v);
    394410            if( size(p-q)<2 )
    395411            {
     
    399415               else { k=0; }
    400416            }
    401          }   
     417         }
    402418      }
    403419   }
    404420//---------  final test -------------------------------------------------------
    405421   testm = matrix(N,nrows(kb),ncols(result))- matrix(kb)*result;
    406    if( size(module(testm))!=0 ) 
    407    { 
     422   if( size(module(testm))!=0 )
     423   {
    408424      "// proc `lift_kbase` did'nt work correctly!";
    409425      "// Please inform tthe authors";
     
    413429}
    414430example
    415 {
    416   "EXAMPLE:";     echo=2;
     431{"EXAMPLE:";     echo=2;
    417432  ring R=0,(x,y),ds;
    418433  module M=[x2,xy],[y2,xy],[0,xx],[0,yy];
     
    432447ASSUME:  M=matrix with only one row and without any constant term
    433448COMPUTE: coef_matrices with respect to first s variables
    434 RETURN:  2 matrices: 
     449RETURN:  2 matrices:
    435450         matrix of coefficients (each column is formed by the coefficients
    436            of M with respect to some monomial) 
    437          row-matrix of corresponding monomials 
     451           of M with respect to some monomial)
     452         row-matrix of corresponding monomials
    438453EXAMPLE: example coef_ideal; shows an example
    439454{
    440455  int   k,l,n,z;
    441456  int   cM = ncols(M);
    442   ideal flatM = M; 
     457  ideal flatM = M;
    443458  ideal monId,flat;
    444459  poly  mon = product(maxideal(1),1..s);
    445460//--------- collect all monomials (!=1) ---------------------------------------
    446   for (k=1;k<=cM;k++)
     461  for (k=1;k<=cM;k=k+1)
    447462  {
    448463    matrix mci(k) = coef(flatM[k],mon);
     
    450465    if (flat[1]!=1)
    451466    { monId = monId,flat;}
    452   } 
     467  }
    453468  monId = monId+ideal(0);
    454469  k=size(monId);
    455470  matrix BIG[cM][k];
    456471//---------  create coef_matrices  --------------------------------------------
    457   for (n=1;n<=k;n++)
     472  for (n=1;n<=k;n=n+1)
    458473  {
    459     for (l=1;l<=cM;l++)
     474    for (l=1;l<=cM;l=l+1)
    460475    {
    461       for (z=1;z<=ncols(mci(l));z++)
     476      for (z=1;z<=ncols(mci(l));z=z+1)
    462477      {
    463478        if(mci(l)[1,z]==monId[n])
    464479        { BIG[l,n] = mci(l)[2,z];}
    465       }   
     480      }
    466481    }
    467   } 
     482  }
    468483  return(BIG,matrix(monId));
    469 } 
    470 example 
     484}
     485example
    471486{ "EXAMPLE:"; echo = 2;
    472487  ring Z = 0,(A,B,C,x,y,z),ds;
    473   int  s = 3; 
     488  int  s = 3;
    474489  matrix M[1][4]=A+yB,2C,3AA,4BB+5CC;
    475490  print(M);
     
    480495}
    481496///////////////////////////////////////////////////////////////////////////////
    482 ----------
    483 
    484 "example in r1: i=cone rational normal curve d=4";
    485 int d=4;
    486 ring r1=0,(x,y,z,u,v),ds;
    487 matrix m[2][4]=x,y,z,u,y,z,u,v;
    488 ideal i=minor(m,2);
    489 i=minbase(i);
    490 i;pause;
    491 int t=timer;miniversal(i);timer-t;
    492 ----------
    493 
    494 "example: in r4 i=cone rational normal curve d=5";
    495 int d=5;
    496 ring s=0,(x,y,z,u,v,w),ds;
    497 matrix m[2][5]=x,y,z,u,v,y,z,u,v,w;
    498 ideal i=minor(m,2);
    499 i=minbase(i);
    500 i;pause;
    501 
    502 ----------
    503 
    504 "Example: in r5 i=L_n^n,   n=4;";
    505 ring r5=0,(x,y,z,u),ds;
    506 ideal i;
    507 i=xy,xz,xu,yz,yu,zu;
    508 i;pause;
    509 
    510 ----------
    511 
    512 "Example 1 : cyclic quotient  in ws   
    513       (type setring r1;sud(i);)";
    514 ring r1=0,(x,y,z,u,v),ws(4,3,2,3,4);
    515 ideal i=xz-y2,yz2-xu,xv-yzu,yu-z3,z2u-yv,zv-u2;
    516 i;
    517 
    518 "Example 2: same in wp
    519       (ringr r2)";
    520 ring r2=0,(x,y,z,u,v),wp(4,3,2,3,4);
    521 ideal i=xz-y2,yz2-xu,xv-yzu,yu-z3,z2u-yv,zv-u2;
    522 i;
    523 
    524 "Example 3: same in ls";
    525 ring r3=0,(x,y,z,u,v),ls;
    526 ideal i=xz-y2,yz2-xu,xv-yzu,yu-z3,z2u-yv,zv-u2;
    527 i;
    528 
    529 "Example 4: by chance for testing";
    530 ring r4=0,(x,y,z),ds;
    531 ideal i=xy,yz,xz+y3,x2+y2+z3;
    532 i;
    533 
  • Singular/LIB/elim.lib

    r6d09c56 r6f2edc  
    1 // $Id: elim.lib,v 1.1.1.1 1997-04-25 15:13:25 obachman Exp $
    2 //system("random",787422842);
    3 //(GMG)
     1// $Id: elim.lib,v 1.2 1997-04-28 19:27:16 obachman Exp $
     2// system("random",787422842);
     3// (GMG, last modified 22.06.96)
    44///////////////////////////////////////////////////////////////////////////////
    55
    66LIBRARY:  elim.lib      PROCEDURES FOR ELIMINATIOM, SATURATION AND BLOWING UP
    77
    8  blowup0(j[,s1,s2]);    create presentation of blownup ring of ideal j 
     8 blowup0(j[,s1,s2]);    create presentation of blownup ring of ideal j
    99 elim(id,n,m);          variable n..m eliminated from id (ideal/module)
    10  elim1(id,p);           p=product of vars to be eliminated from id 
     10 elim1(id,p);           p=product of vars to be eliminated from id
    1111 nselect(id,n[,m]);     select generators not containing nth [..mth] variable
    12  sat(id,j);             saturated quotient of ideal/module id by ideal j 
     12 sat(id,j);             saturated quotient of ideal/module id by ideal j
    1313 select(id,n[,m]);      select generators containing nth [..mth] variable
    1414           (parameters in square brackets [] are optional)
     
    2020
    2121proc blowup0 (ideal j,list #)
    22 USAGE:   blowup0(j[,s1,s2]); j ideal, s1,s2 nonempty strings 
    23 CREATE:  Create a presentation of the blowup ring of j 
     22USAGE:   blowup0(j[,s1,s2]); j ideal, s1,s2 nonempty strings
     23CREATE:  Create a presentation of the blowup ring of j
    2424RETURN:  no return value
    2525NOTE:    s1 and s2 are used to give names to the blownup ring and the blownup
    2626         ideal (default: s1="j", s2="A")
    2727         Assume R = char,x(1..n),ord is the basering of j, and s1="j", s2="A"
    28          then the procedure creates a new basering with name Bl_jR
     28         then the procedure creates a new ring with name Bl_jR
    2929         (equal to R[A,B,...])
    30                Bl_jR = char,(A,B,...,x(1..n)),(dp(k),ord) 
    31          with k=ncols(j) new variables A,B,... and ordering wp(d1..dk) if j is 
     30               Bl_jR = char,(A,B,...,x(1..n)),(dp(k),ord)
     31         with k=ncols(j) new variables A,B,... and ordering wp(d1..dk) if j is
    3232         homogeneous with deg(j[i])=di resp. dp otherwise for these vars.
    33          If k>26 or size(s2)>1, say s2="A()", the new vars are A(1),...,A(k). 
     33         If k>26 or size(s2)>1, say s2="A()", the new vars are A(1),...,A(k).
    3434         Let j_ be the kernel of the ring map Bl_jR -> R defined by A(i)->j[i],
    3535         x(i)->x(i), then the quotient ring Bl_jR/j_ is the blowup ring of j
    3636         in R (being isomorphic to R+j+j^2+...). Moreover the procedure creates
    37          a std basis of j_ with name j_ and Bl_jR as basering.
    38 EXAMPLE: example blowup0; shows an example
     37         a std basis of j_ with name j_ in Bl_jR.
     38         This proc uses 'execute' or calls a procedure using 'execute'.
     39DISPLAY: printlevel >=0: explain created objects (default)
     40EXAMPLE: example blowup0; shows examples
    3941{
    4042   string bsr = nameof(basering);
    4143   def br = basering;
    42    string cr, vr, o = charstr(br), varstr(br), ordstr(br);
    43    int n, k = nvars(br), ncols(j);
    44    int i;
     44   string cr,vr,o = charstr(br),varstr(br),ordstr(br);
     45   int n,k,i = nvars(br),ncols(j),0;
     46   int p = printlevel-voice+3;  // p=printlevel+1 (default: p=1)
    4547//---------------- create coordinate ring of blown up space -------------------
    4648   if( size(#)==0 ) { #[1] = "j"; #[2] = "A"; }
     
    4850   if( k<=26 and size(#[2])==1 ) { string nv = A_Z(#[2],k)+","; }
    4951   else { string nv = (#[2])[1]+"(1.."+string(k)+"),"; }
    50    if( ishomog(j) )
    51    { 
     52   if( is_homog(j) )
     53   {
    5254      intvec v=1;
    53       for( i=1; i<=k; i++) { v[i+1]=deg(j[i]); }
     55      for( i=1; i<=k; i=i+1) { v[i+1]=deg(j[i]); }
    5456      string nor = "),(wp(v),";
    5557   }
     
    5860//---------- map to new ring, eliminate and create blown up ideal -------------
    5961   ideal j=imap(br,j);
    60    for( i=1; i<=k; i++) { j[i]=var(1+i)-t*j[i]; }
     62   for( i=1; i<=k; i=i+1) { j[i]=var(1+i)-t*j[i]; }
    6163   j=eliminate(j,t);
    6264   v=v[2..size(v)];
     
    6567   export basering;
    6668   export `#[1]+"_"`;
    67    keepring basering;
     69   //keepring basering;
     70   setring br;
    6871//------------------- some comments about usage and names  --------------------
    69    if( voice ==2 )
    70    {
    71 "// NOTE:";
    72 "// basering is now Bl_"+#[1]+bsr+" (equal to "+bsr+"["+nv[1,size(nv)-1]+"])";
    73 "// it contains the ideal "+#[1]+"_ , such that";
    74 "//             Bl_"+#[1]+bsr+"/"+#[1]+"_ is the blowup ring";
    75 "// For blowing-up another ideal in "+bsr+" type first:";
    76 "//             setring "+bsr+";";
    77    }
     72dbprint(p,"",
     73"// The proc created the ring Bl_"+#[1]+bsr+" (equal to "+bsr+"["+nv[1,size(nv)-1]+"])",
     74"// it contains the ideal "+#[1]+"_ , such that",
     75"//             Bl_"+#[1]+bsr+"/"+#[1]+"_ is the blowup ring",
     76"// show(Bl_"+#[1]+bsr+"); shows this ring.",
     77"// Make Bl_"+#[1]+bsr+" the basering and see "+#[1]+"_ by typing:",
     78"   setring Bl_"+#[1]+bsr+";","   "+#[1]+"_;");
    7879   return();
    7980}
    80 example 
     81example
    8182{ "EXAMPLE:"; echo = 2;
    8283   ring R=0,(x,y),dp;
    83    poly f=y2+x3; ideal j=jacob(f); 
     84   poly f=y2+x3; ideal j=jacob(f);
    8485   blowup0(j);
    85    type basering; "";
    86 // NOTE:
    87 // basering is now Bl_jR (equal to R[A,B])
    88 // it contains the ideal j_ , such that
    89 //             Bl_jR/j_ is the blowup ring
    90 // For blowing-up another ideal in R type first:
    91 //             setring R;
    92    type j_; "";
     86   show(Bl_jR);
     87   setring Bl_jR;
     88   j_;"";
    9389   ring r=32003,(x,y,z),ds;
    9490   blowup0(maxideal(1),"m","T()");
    95    type basering; "";
    96 // NOTE:
    97 // basering is now Bl_mr (equal to r[T(1..3)])
    98 // it contains the ideal m_ , such that
    99 //             Bl_mr/m_ is the blowup ring
    100 // For blowing-up another ideal in r type first:
    101 //             setring r;
     91   show(Bl_mr);
     92   setring Bl_mr;
    10293   m_;
    103    kill Bl_jR, Bl_mr; 
     94   kill Bl_jR, Bl_mr;
    10495}
    10596///////////////////////////////////////////////////////////////////////////////
    10697
    10798proc elim (id, int n, int m)
    108 USAGE:   elim(id,n,m);  id ideal/module, n,m integers
    109 RETURNS: ideal/module obtained from id by eliminating variables n..m
    110 NOTE:    no special monomial ordering is required, result is a SB with
    111          respect to ordering dp (resp. ls) if the first var not to be
    112          eliminated belongs to a -p (resp. -s) blockordering
    113 EXAMPLE: example elim; shows an example
     99USAGE:   elim(id,n,m);  id ideal/module, n,m integers
     100RETURNS: ideal/module obtained from id by eliminating variables n..m
     101NOTE:    no special monomial ordering is required, result is a SB with
     102         respect to ordering dp (resp. ls) if the first var not to be
     103         eliminated belongs to a -p (resp. -s) blockordering
     104         This proc uses 'execute' or calls a procedure using 'execute'.
     105EXAMPLE: example elim; shows examples
    114106{
    115107//---- get variables to be eliminated and create string for new ordering ------
    116108   int ii; poly vars=1;
    117    for( ii=n; ii<=m; ii=ii+1 ) { vars=vars*var(ii); }   
     109   for( ii=n; ii<=m; ii=ii+1 ) { vars=vars*var(ii); }
    118110   if( n>1 ) { poly p = 1+var(1); }
    119111   else { poly p = 1+var(m+1); }
     
    122114//-------------- create new ring and map objects to new ring ------------------
    123115   def br = basering;
    124    string str = "ring newr = ("+charstr(br)+"),("+varstr(br)+ordering;
     116   string str = "ring @newr = ("+charstr(br)+"),("+varstr(br)+ordering;
    125117   execute(str);
    126118   def i = imap(br,id);
     
    129121   i = eliminate(i,vars);
    130122   setring br;
    131    return(imap(newr,i));
    132 }
    133 example 
     123   return(imap(@newr,i));
     124}
     125example
    134126{ "EXAMPLE:"; echo = 2;
    135127   ring r=0,(x,y,u,v,w),dp;
    136128   ideal i=x-u,y-u2,w-u3,v-x+y3;
    137    elim(i,3,4); 
     129   elim(i,3,4);
    138130   module m=i*gen(1)+i*gen(2);
    139    m=elim(m,3,4);show(m); 
    140 }
    141 /////////////////////////////////////////////////////////////////////////////// 
     131   m=elim(m,3,4);show(m);
     132}
     133///////////////////////////////////////////////////////////////////////////////
    142134
    143135proc elim1 (id, poly vars)
     
    147139         respect to ordering dp (resp. ls) if the first var not to be
    148140         eliminated belongs to a -p (resp. -s) blockordering
    149 EXAMPLE: example elim1; shows an example
     141         This proc uses 'execute' or calls a procedure using 'execute'.
     142EXAMPLE: example elim1; shows examples
    150143{
    151144//---- get variables to be eliminated and create string for new ordering ------
    152    int ii;                       
    153    for( ii=1; ii<=nvars(basering); ii++ )
    154    {   
    155       if( vars/var(ii)==0 ) { poly p = 1+var(ii); }
    156       break;
     145   int ii;
     146   for( ii=1; ii<=nvars(basering); ii=ii+1 )
     147   {
     148      if( vars/var(ii)==0 ) { poly p = 1+var(ii); break;}
    157149   }
    158150   if( ord(p)==0 ) { string ordering = "),ls;"; }
     
    160152//-------------- create new ring and map objects to new ring ------------------
    161153   def br = basering;
    162    string str = "ring newr = "+charstr(br)+",("+varstr(br)+ordering;
     154   string str = "ring @newr = ("+charstr(br)+"),("+varstr(br)+ordering;
    163155   execute(str);
    164156   def id = fetch(br,id);
     
    167159   id = eliminate(id,vars);
    168160   setring br;
    169    return(imap(newr,id));
    170 }
    171 example 
     161   return(imap(@newr,id));
     162}
     163example
    172164{ "EXAMPLE:"; echo = 2;
    173165   ring r=0,(x,y,t,s,z),dp;
    174166   ideal i=x-t,y-t2,z-t3,s-x+y3;
    175    elim1(i,ts); 
     167   elim1(i,ts);
    176168   module m=i*gen(1)+i*gen(2);
    177    m=elim1(m,st); show(m); 
    178 }
    179 /////////////////////////////////////////////////////////////////////////////// 
     169   m=elim1(m,st); show(m);
     170}
     171///////////////////////////////////////////////////////////////////////////////
    180172
    181173proc nselect (id, int n, list#)
    182174USAGE:   nselect(id,n[,m]); id a module or ideal, n, m integers
    183175RETURN:  generators of id not containing the variable n [up to m]
    184 EXAMPLE: example nselect; shows an example
    185 {
     176EXAMPLE: example nselect; shows examples
     177{
     178   int j,k;
    186179   if( size(#)==0 ) { #[1]=n; }
    187    int j,k;
    188    for( k=1; k<=ncols(id); k++ )
    189    { 
    190       for( j=n; j<=#[1]; j++ )
    191       {
    192          if( size(id[k]/var(j))!=0) { id[k]=0; break; }
     180   for( k=1; k<=ncols(id); k=k+1 )
     181   {  for( j=n; j<=#[1]; j=j+1 )
     182      {  if( size(id[k]/var(j))!=0) { id[k]=0; break; }
    193183      }
    194184   }
    195185   return(simplify(id,2));
    196186}
    197 example 
     187example
    198188{ "EXAMPLE:"; echo = 2;
    199189   ring r=0,(x,y,t,s,z),(c,dp);
    200190   ideal i=x-y,y-z2,z-t3,s-x+y3;
    201191   nselect(i,3);
    202    module m=i*(gen(1)+gen(2)); 
     192   module m=i*(gen(1)+gen(2));
    203193   show(m);
    204194   show(nselect(m,3,4));
     
    207197
    208198proc sat (id, ideal j)
    209 USAGE:   sat(id,j);  id ideal or module, j ideal
    210 RETURN:  saturation of id with respect to j (= union_(k=1...) of id:j^k)
    211 NOTE:    result is a std basis in the basering
     199USAGE:   sat(id,j);  id=ideal/module, j=ideal
     200RETURN:  list of an ideal/module [1] and an integer [2]:
     201         [1] = saturation of id with respect to j (= union_(k=1...) of id:j^k)
     202         [2] = saturation exponent (= min( k | id:j^k = id:j^(k+1) ))
     203NOTE:    [1] is a standard basis in the basering
     204DISPLAY: saturation exponent during computation if printlevel >=1
    212205EXAMPLE: example sat; shows an example
    213206{
    214207   int ii,kk;
    215    def i=id; id=std(id);
     208   def i=id;
     209   id=std(id);
     210   int p = printlevel-voice+3;  // p=printlevel+1 (default: p=1)
    216211   while( ii<=size(i) )
    217    {   
    218       if( voice==2 )
    219       {"// start quotient:",kk+1;}
     212   {
     213      dbprint(p-1,"// compute quotient "+string(kk+1));
    220214      i=quotient(id,j);
    221       for( ii=1; ii<=size(i); ii++ )
     215      for( ii=1; ii<=size(i); ii=ii+1 )
    222216      {
    223217         if( reduce(i[ii],id)!=0 ) break;
     
    225219      id=std(i); kk=kk+1;
    226220   }
    227    if( voice==2 )
    228    {"//  saturation becomes stable after",kk-1,"iteration(s)";"";}
    229    return (id);
    230 }
    231 example
    232 { "EXAMPLE:"; echo = 2;
    233    ring r=2,(x,y,z),dp;
    234    poly F=x5+y5+(x-y)^2*xyz;
    235    ideal j= jacob(F);
    236    sat(j,maxideal(1));
     221   dbprint(p-1,"// saturation becomes stable after "+string(kk-1)+" iteration(s)","");
     222   list L = id,kk-1;
     223   return (L);
     224}
     225example
     226{ "EXAMPLE:"; echo = 2;
     227   int p      = printlevel;
     228   ring r     = 2,(x,y,z),dp;
     229   poly F     = x5+y5+(x-y)^2*xyz;
     230   ideal j    = jacob(F);
     231   sat(j,maxideal(1));
     232   printlevel = 2;
     233   sat(j,maxideal(2));
     234   printlevel = p;
    237235}
    238236///////////////////////////////////////////////////////////////////////////////
     
    241239USAGE:   select(id,n[,m]); id ideal/module, n, m integers
    242240RETURN:  generators of id containing the variable n [up to m]
    243 EXAMPLE: example select; shows an example
     241EXAMPLE: example select; shows examples
    244242{
    245243   if( size(#)==0 ) { #[1]=n; }
    246244   int j,k;
    247    for( k=1; k<=ncols(id); k++ )
    248    { 
    249       for( j=n; j<=#[1]; j++ )
    250       {
    251          if( size(id[k]/var(j))==0) { id[k]=0; break; }
     245   for( k=1; k<=ncols(id); k=k+1 )
     246   {  for( j=n; j<=#[1]; j=j+1 )
     247      {   if( size(id[k]/var(j))==0) { id[k]=0; break; }
    252248      }
    253249   }
    254    return(id+id);
    255 }
    256 example 
     250   return(simplify(id,2));
     251}
     252example
    257253{ "EXAMPLE:"; echo = 2;
    258254   ring r=0,(x,y,t,s,z),(c,dp);
    259255   ideal i=x-y,y-z2,z-t3,s-x+y3;
    260256   ideal j=select(i,1);
    261    module m=i*(gen(1)+gen(2)); show(m);
    262    show(select(m,1,2));
    263 }
    264 ///////////////////////////////////////////////////////////////////////////////
    265 
     257   j;
     258   module m=i*(gen(1)+gen(2));
     259   m;
     260   select(m,1,2);
     261}
     262///////////////////////////////////////////////////////////////////////////////
  • Singular/LIB/factor.lib

    r6d09c56 r6f2edc  
    1 // $Id: factor.lib,v 1.1.1.1 1997-04-25 15:13:26 obachman Exp $
     1// $Id: factor.lib,v 1.2 1997-04-28 19:27:17 obachman Exp $
    22//(RS)
    33///////////////////////////////////////////////////////////////////////////////
  • Singular/LIB/general.lib

    r6d09c56 r6f2edc  
    1 // $Id: general.lib,v 1.1.1.1 1997-04-25 15:13:26 obachman Exp $
     1// $Id: general.lib,v 1.2 1997-04-28 19:27:17 obachman Exp $
    22//system("random",787422842);
    33//(GMG, last modified 22.06.96)
     
    2020 sum(vector/id/..[,v]); add components of vector/ideal/...[with indices v]
    2121           (parameters in square brackets [] are optional)
    22 
     22 wich(command);         searches for command and returns absolute
     23                        path, if found
    2324LIB "inout.lib";
    2425///////////////////////////////////////////////////////////////////////////////
     
    187188proc killall
    188189USAGE:   killall(); (no parameter)
    189          killall("proc");
     190         killall("type_name");
     191         killall("not", "type_name");
    190192COMPUTE: killall(); kills all user-defined variables but not loaded procedures
    191          killall("proc"); kills all loaded procedures
     193         killall("type_name"); kills all user-defined variables, of type "type_name"
     194         killall("not", "type_name"); kills all user-defined
     195         variables, except those of type "type_name" and except loaded procedures
    192196RETURN:  no return value
    193197NOTE:    killall should never be used inside a procedure
     
    201205         if( L[joni]!="LIB" and typeof(`L[joni]`)!="proc" ) { kill `L[joni]`; }
    202206      }
    203       return();
    204    }
    205    if( #[1] == "proc" )
    206    {
    207       for ( joni=size(L); joni>0; joni-- )
    208       {
    209          if( L[joni]=="LIB" or typeof(`L[joni]`)=="proc" ) { kill `L[joni]`; }
    210       }
    211    }
    212 }
    213 example
    214 { "EXAMPLE:"; echo = 2;
    215    ring rtest; ideal i=x,y,z; number n=37; string str="hi";
    216    export rtest,i,n,str;     //this makes the local variables global
     207   }
     208   else
     209   {
     210     if( size(#)==1 )
     211     {
     212       if( #[1] == "proc" )
     213       {
     214          for ( joni=size(L); joni>0; joni-- )
     215          {
     216             if( L[joni]=="LIB" or typeof(`L[joni]`)=="proc" )
     217               { kill `L[joni]`; }
     218          }
     219       }
     220       else
     221       {
     222          for ( ; joni>2; joni-- )
     223          {
     224            if(typeof(`L[joni]`)==#[1] and L[joni]!="LIB" and typeof(`L[joni]`)!="proc") { kill `L[joni]`; }
     225          }
     226        }
     227     }
     228     else
     229     {
     230        for ( ; joni>2; joni-- )
     231        {
     232          if(typeof(`L[joni]`)!=#[2] and L[joni]!="LIB" and typeof(`L[joni]`)!="proc") { kill `L[joni]`; }
     233        }
     234     }
     235  }
     236  return();
     237}
     238example
     239{ "EXAMPLE:"; echo = 2;
     240   ring rtest; ideal i=x,y,z; number n=37; string str="hi"; int j = 3;
     241   export rtest,i,n,str,j;     //this makes the local variables global
    217242   listvar(all);
    218    killall();
     243   killall("string"); // kills all string variables
     244   listvar(all);
     245   killall("not", "int"); // kills all variables except int's (and procs)
     246   listvar(all);
     247   killall(); // kills all vars except loaded procs
    219248   listvar(all);
    220249}
     
    590619}
    591620///////////////////////////////////////////////////////////////////////////////
     621
     622proc which (command)
     623USAGE:    which(command); command = string expression
     624RETURN:   Absolute pathname of command, if found in search path.
     625          Empty string, otherwise.
     626NOTE:     Based on the Unix command 'which'.
     627EXAMPLE:  example which; shows an example
     628{
     629   int rs;
     630   int i;
     631   string fn = "/tmp/which_" + string(system("pid"));
     632   string pn;
     633   if( typeof(command) != "string")
     634   {
     635        return pn;
     636   }
     637   i = system("sh", "which " + command + " > " + fn);
     638   pn = read(fn);
     639   pn[size(pn)] = "";
     640   i = 1;
     641   while ((pn[i] != " ") and (pn[i] != ""))
     642   {
     643     i = i+1;
     644   }
     645   if (pn[i] == " ") {pn[i] = "";}
     646   rs = system("sh", "ls " + pn + " > " + fn + " 2>&1 ");
     647   i = system("sh", "rm " + fn);
     648   if (rs == 0) {return (pn);}
     649   else
     650   {
     651     print (command + " not found ");
     652     return ("");
     653   }
     654}
     655example
     656{  "EXAMPLE:"; echo = 2;
     657    which("Singular");
     658}
     659///////////////////////////////////////////////////////////////////////////////
  • Singular/LIB/homog.lib

    r6d09c56 r6f2edc  
    1 // $Id: homog.lib,v 1.1.1.1 1997-04-25 15:13:26 obachman Exp $
     1// $Id: homog.lib,v 1.2 1997-04-28 19:27:18 obachman Exp $
    22//(BM 11/95)
    33///////////////////////////////////////////////////////////////////////////////
    4 LIBRARY:  homog.lib           homological algebra porcedures 
     4LIBRARY:  homog.lib           homological algebra porcedures
    55ext(<int>,<ideal>);             Ext^k(R/I,R),    I - ideal in basering R
    66Ext(<int>,<mod>,<mod>);         Ext^k(M,N),      M,N modules
     
    328328example
    329329{
    330   "EXAMPLE";   echo=2;  int printlevel=2;
     330  "EXAMPLE";   echo=2;  printlevel=2;
    331331  ring  r = 0,(x,y),(dp,C);
    332332  ideal i = x2-y3;
  • Singular/LIB/homolog.lib

    r6d09c56 r6f2edc  
    1 // $Id: homolog.lib,v 1.1.1.1 1997-04-25 15:13:26 obachman Exp $
    2 //(BM 11/95)
     1// $Id: homolog.lib,v 1.2 1997-04-28 19:27:19 obachman Exp $
     2//(BM/GMG, last modified 22.06.96)
    33///////////////////////////////////////////////////////////////////////////////
    44
    5 LIBRARY:  homolog.lib   PROCEDURES FOR HOMOLOGICAL ALGEBRA                             
    6 
    7 Ext_R(k,id);            Ext^k(R/id,R), id  = ideal
    8 Ext(k,M,N);             Ext^k(M,N),    M,N = modules
    9 Hom(M,N);               Hom(M,N),      M,N = modules
    10 kohom(A,k);             Hom(R^k,A), A = matrix
    11 kontrahom(A,k);         Hom(A,R^k), A = matrix
    12    
     5LIBRARY:  homolog.lib   PROCEDURES FOR HOMOLOGICAL ALGEBRA
     6
     7 cup(M);                cup: Ext^1(M',M') x Ext^1() --> Ext^2()
     8 cupproduct(M,N,P,p,q); cup: Ext^p(M',N') x Ext^q(N',P') --> Ext^p+q(M',P')
     9 Ext_R(k,M);            Ext^k(M',R),    M module, R basering, M'=coker(M)
     10 Ext(k,M,N);            Ext^k(M',N'),   M,N modules, M'=coker(M), N'=coker(N)
     11 Hom(M,N);              Hom(M',N'),     M,N modules, M'=coker(M), N'=coker(N)
     12 homology(A,B,M,N)      ker(B)/im(A),   homology of complex R^k--A->M'--B->N'
     13 kernel(A,M,N);         ker(M'--A->N')  M,N modules, A matrix
     14 kohom(A,k);            Hom(R^k,A),     A matrix over basering R
     15 kontrahom(A,k);        Hom(A,R^k),     A matrix over basering R
     16
     17LIB "general.lib";
     18LIB "deform.lib";
    1319LIB "matrix.lib";
     20LIB "poly.lib";
    1421///////////////////////////////////////////////////////////////////////////////
    1522
    16 proc Ext_R (int k, ideal I, list #)
    17 USAGE:   Ext_R(k,id[,any]);  k=integer, id=ideal
    18 DISPLAY: degree of Ext^k(P/id,P)
    19 RETURN:  Ext^k(P/id,P), presentation as a quotient of a free module.
    20          If a third argument is given (of any type) return a list of two
    21          modules:
    22            [1] = module Ext^k(P/id,P)
    23            [2] = SB of  Ext^k(P/id,P)
    24 EXAMPLE: example Ext_R; shows an example
     23proc cup (module M,list #)
     24USAGE:   cup(M,[,any,any]);  M=module
     25COMPUTE: cup-product Ext^1(M',M') x Ext^1(M',M') ---> Ext^2(M',M'),
     26         where M':=R^m/M, if M in R^m, R basering (i.e. M':=coker(matrix(M)))
     27         in case of a second argument: symmetrized cup-product
     28ASSUME:  all Ext's  are finite dimensional
     29RETURN:  matrix of the associated linear map,
     30         i.e. the columns of <matrix> present the coordinates of b_i & b_j
     31         (resp. (1/2)(b_i & b_j + b_j & b_i) in the symmetric version)
     32         with respect to a kbase of Ext^2,
     33         (where b_1,b_2,... is a kbase of Ext^1 and & denotes cup product)
     34         in case of  a third argument return a list:
     35               L[1] = matrix see above (and symmetric case)
     36               L[2] = matrix of kbase of Ext^1
     37               L[3] = matrix of kbase of Ext^2
     38NOTE:    printlevel >=1;  shows what is going on
     39         printlevel >=2;  shows result in another representation
     40         For computing cupproduct of M itself, apply proc to syz(M)!
     41EXAMPLE: example cup; shows examples
    2542{
    26    module m1,m2,ret,ret0;   
    27 //------------------ compute resolution of P/I --------------------------------
    28    mres(I,k+1,resI);
    29 //-----------------  apply Hom(_,P) at k-th place -----------------------------
    30    m2 = transpose(resI(k+1));   
    31    m1 = transpose(resI(k));
    32 //-----------------  ker(m2)/im(m1) -------------------------------------------
    33    m2 = simplify(m2,10);         
    34    if (m2[1]==0) { ret = m1; }
    35    else          { ret = modulo(syz(m2),m1); }
    36    ret0 = std(ret);
    37    "// degree of Ext^"+string(k)+"(P/I,P):";degree(ret0);
    38    if (size(#)>0) { return(ret,ret0); }
    39    return(ret);
     43//---------- initialization ---------------------------------------------------
     44   int    i,j,k,f0,f1,f2,f3,e1,e2;
     45   module M1,M2,A,B,C,ker,ima,ext1,ext2,ext10,ext20;
     46   matrix cup[1][0];
     47   matrix kb1,lift1,kb2,mA,mB,mC;
     48   ideal  tes1,tes2,null;
     49   int p = printlevel-voice+3;  // p=printlevel+1 (default: p=1)
     50//-----------------------------------------------------------------------------
     51//take a resolution of M<--F(0)<--- ...  <---F(3)
     52//apply Hom(-,M) and compute the Ext's
     53//-----------------------------------------------------------------------------
     54   list resM = res(M,3);
     55   M1 = resM[2];
     56   M2 = resM[3];
     57   f0 = nrows(M);
     58   f1 = ncols(M);
     59   f2 = ncols(M1);
     60   f3 = ncols(M2);
     61   tes1 = simplify(ideal(M),10);
     62   tes2=simplify(ideal(M1),10);
     63   if ((tes1[1]*tes2[1]==0) or (tes1[1]==1) or (tes2[1]==1))
     64   {
     65      dbprint(p,"// Ext == 0 , hence 'cup' is the zero-map");
     66      return(@cup);
     67   }
     68//------ compute Ext^1 --------------------------------------------------------
     69   B     = kohom(M,f2);
     70   A     = kontrahom(M1,f0);
     71   C     = intersect(A,B);
     72   C     = reduce(C,std(null));C = simplify(C,10);
     73   ker   = lift(A,C)+syz(A);
     74   ima   = kohom(M,f1);
     75   ima   = ima + kontrahom(M,f0);
     76   ext1  = modulo(ker,ima);
     77   ext10 = std(ext1);
     78   e1    = vdim(ext10);
     79   dbprint(p-1,"// vdim (Ext^1) = "+string(e1));
     80   if (e1 < 0)
     81   {
     82     "// Ext^1 not of finite dimension";
     83     return(cup);
     84   }
     85   kb1 = kbase(ext10);
     86   kb1 = matrix(ker)*kb1;
     87   dbprint(p-1,"// kbase of Ext^1(M,M)",
     88               "//  - the columns present the kbase elements in Hom(F(1),F(0))",
     89               "//  - F(*) a free resolution of M",kb1);
     90
     91//------ compute the liftings of Ext^1 ----------------------------------------
     92   mC = matrix(A)*kb1;
     93   lift1 =lift(B,mC);
     94   dbprint(p-1,"// lift kbase of Ext^1:",
     95    "//  - the columns present liftings of kbase elements into Hom(F(2),F(1))",
     96    "//  - F(*) a free resolution of M ",lift1);
     97
     98//------ compute Ext^2  -------------------------------------------------------
     99   B    = kohom(M,f3);
     100   A    = kontrahom(M2,f0);
     101   C    = intersect(A,B);
     102   C    = reduce(C,std(null));C = simplify(C,10);
     103   ker  = lift(A,C)+syz(A);
     104   ima  = kohom(M,f2);
     105   ima  = ima + kontrahom(M1,f0);
     106   ext2 = modulo(ker,ima);
     107   ext20= std(ext2);
     108   e2   = vdim(ext20);
     109   if (e2<0)
     110   {
     111     "// Ext^2 not of finite dimension";
     112     return(cup);
     113   }
     114   dbprint(p-1,"// vdim (Ext^2) = "+string(e2));
     115   kb2 = kbase(ext20);
     116   kb2 = matrix(ker)*kb2;
     117   dbprint(p-1,"// kbase of Ext^2(M,M)",
     118               "//  - the columns present the kbase elements in Hom(F(2),F(0))",
     119               "//  - F(*) is a a free resolution of M ",kb2);
     120//-------  compute: cup-products of base-elements -----------------------------
     121   for (i=1;i<=e1;i=i+1)
     122   {
     123     for (j=1;j<=e1;j=j+1)
     124     {
     125       mA = matrix(ideal(lift1[j]),f1,f2);
     126       mB = matrix(ideal(kb1[i]),f0,f1);
     127       mC = mB*mA;
     128       if (size(#)==0)
     129       {                                          //non symmestric
     130         mC = matrix(ideal(mC),f0*f2,1);
     131         cup= concat(cup,mC);
     132       }
     133       else                                       //symmetric version
     134       {
     135         if (j>=i)
     136         {
     137           if (j>i)
     138           {
     139             mA = matrix(ideal(lift1[i]),f1,f2);
     140             mB = matrix(ideal(kb1[j]),f0,f1);
     141             mC = mC+mB*mA;mC=(1/2)*mC;
     142           }
     143           mC = matrix(ideal(mC),f0*f2,1);
     144           cup= concat(cup,mC);
     145         }
     146       }
     147     }
     148   }
     149   dbprint(p-1,"// matrix of cup-products (in Ext^2)",cup,"////// end level 2 //////");
     150//------- comptute: presentation of base-elements -----------------------------
     151   cup = lift(ker,cup);
     152   cup = lift_kbase(cup,ext20);
     153   if( p>2 )
     154   {
     155     "// the associated matrices of the bilinear mapping 'cup' ";
     156     "// corresponding to the kbase elements of Ext^2(M,M) are shown,";
     157     "//  i.e. the rows of the final matrix are written as matrix of";
     158     "//  a bilinear form on Ext^1 x Ext^1";
     159     matrix BL[e1][e1];
     160     for (k=1;k<=e2;k=k+1)
     161     {
     162       "//_____"+string(k)+". component:";
     163       for (i=1;i<=e1;i=i+1)
     164       {
     165         for (j=1;j<=e1;j=j+1)
     166         {
     167           if (size(#)==0) { BL[i,j]=cup[k,j+e1*(i-1)]; }
     168           else
     169           {
     170             if (i<=j)
     171             {
     172               BL[i,j]=cup[k,j+e1*(i-1)-binomial(i,2)];
     173               BL[j,i]=BL[i,j];
     174             }
     175           }
     176         }
     177       }
     178       print(BL);
     179     }
     180     "////// end level 3 //////";
     181   }
     182   if (size(#)>2) { return(cup,kb1,kb2);}
     183   else {return(cup);}
    40184}
    41185example
    42 { "EXAMPLE:";     echo=2;
    43    ring r=0,(x,y,z),dp;
    44    ideal  i = x2y,y2z,z3x;
    45    module E = Ext_R(1,i);"";
    46    E = Ext_R(2,i);
    47    show(E);"";
    48    list LE = Ext_R(3,i,"");
    49    kbase(LE[2]);"";
    50    E = Ext_R(4,i);
     186{"EXAMPLE";  echo=2;
     187  int p      = printlevel;
     188  ring  rr   = 32003,(x,y,z),(dp,C);
     189  ideal  I   = x4+y3+z2;
     190  qring  o   = std(I);
     191  module M   = [x,y,0,z],[y2,-x3,z,0],[z,0,-y,-x3],[0,z,x,-y2];
     192  print(cup(M));
     193  print(cup(M,1));
     194  // 2nd EXAMPLE  (shows what is going on)
     195  printlevel = 3;
     196  ring   r   = 0,(x,y),(dp,C);
     197  ideal  i   = x2-y3;
     198  qring  q   = std(i);
     199  module M   = [-x,y],[-y2,x];
     200  print(cup(M));
     201  printlevel = p;
    51202}
    52203///////////////////////////////////////////////////////////////////////////////
    53204
    54 proc Ext (int k, module M, module N, list #)
    55 USAGE:   Ext(k,M,N[,any]);  k=integer, M,N=modules
    56 DISPLAY: degree of Ext^k(M,N)
    57 RETURN:  Ext^k(M,N), presentation as a quotient of a free module.
    58          If a third argument is given (of any type) return a list of two
    59          modules:
    60            [1] = module Ext^k(M,N)
    61            [2] = SB of  Ext^k(M,N)
    62 EXAMPLE: example Ext; shows an example
     205proc cupproduct (module M,N,P,int p,q,list #)
     206USAGE:   cupproduct(M,N,P,p,q[,any]);  M,N,P modules, p,q integers
     207COMPUTE: cup-product Ext^p(M',N') x Ext^q(N',P') ---> Ext^p+q(M',P')
     208         where M':=R^m/M, if M in R^m, R basering (i.e. M':=coker(matrix(M)))
     209ASSUME:  all Ext's  are of finite dimension
     210RETURN:  matrix of the associated linear map Ext^p(tensor)Ext^q-->Ext^p+q
     211         i.e. the columnes of <matrix> present the coordinates of
     212         the cup products (b_i & c_j) with respect to a kbase of Ext^p+q
     213         (b_i resp. c_j are choosen bases of Ext^p resp. Ext^q)
     214         in case of a 6th argument:
     215            return a list
     216            L[1] = matrix (see above)
     217            L[2] = matrix of kbase of Ext^p(M',N')
     218            L[3] = matrix of kbase of Ext^q(N',P')
     219            L[4] = matrix of kbase of Ext^p+q(N',P')
     220NOTE:    printlevel >=1;  shows what is going on
     221         printlevel >=2;  shows result in another representation
     222         For computing cupproduct of M,N itself, apply proc to syz(M),syz(N)!
     223EXAMPLE: example cupproduct; shows examples
    63224{
    64    module A,B,C,M1,M2,ker,imag,extMN,extMN0;
    65    ideal  test1,test2;
    66 //----------  resolution of M  and N ------------------------------------------
    67   if (k>0)
    68   {
    69      mres(M,k+1,resM);
    70      M1 = resM(k);
    71      M2 = resM(k+1);
    72      test1 = simplify(ideal(M1),10);
    73      test2 = simplify(ideal(N),10);
    74      if ((test1[1]==0) or (test2[1]==0))
    75         { "//Ext(M,N)=0";return(extMN); }
    76      else
    77      { 
    78        test1 = simplify(ideal(M2),10);
    79        if (test1[1]==0)                             //Ker(Hom(m2,N))
    80           { ker = freemodule(ncols(M1)*nrows(N));}
    81        else
    82        {
    83           A   = kontrahom(M2,nrows(N));
    84           B   = kohom(N,ncols(M2));
    85           C   = intersect(A,B);
    86           C   = reduce(C,std(ideal(0)));C=simplify(C,10);
    87           ker = lift(A,C)+syz(A);   
    88        }
    89        imag  = kohom(N,ncols(M1));
    90        A     = kontrahom(M1,nrows(N));
    91        imag  = imag+A;                              //im(Hom(m1,M))
    92        extMN = modulo(ker,imag);
    93        extMN0= std(extMN);
    94        "// degree of Ext^"+string(k)+"(M,N):";degree(extMN0);
     225//---------- initialization ---------------------------------------------------
     226   int    e1,e2,e3,i,j,k,f0,f1,f2;
     227   module M1,M2,N1,N2,P1,P2,A,B,C,ker,ima,extMN,extMN0,extMP,
     228          extMP0,extNP,extNP0;
     229   matrix cup[1][0];
     230   matrix kbMN,kbMP,kbNP,lift1,mA,mB,mC;
     231   ideal  test1,test2,null;
     232   int pp = printlevel-voice+3;  // pp=printlevel+1 (default: p=1)
     233//-----------------------------------------------------------------------------
     234//compute resolutions of M and N
     235//                     M<--F(0)<--- ...  <---F(p+q+1)
     236//                     N<--G(0)<--- ...  <---G(q+1)
     237//-----------------------------------------------------------------------------
     238   list resM = res(M,p+q+1);
     239   M1 = resM[p];
     240   M2 = resM[p+1];
     241   list resN = res(N,q+1);
     242   N1 = resN[q];
     243   N2 = resN[q+1];
     244   P1 = resM[p+q];
     245   P2 = resM[p+q+1];
     246//-------test: Ext==0?---------------------------------------------------------
     247   test1 = simplify(ideal(M1),10);
     248   test2 = simplify(ideal(N),10);
     249   if (test1[1]==0) { dbprint(pp,"//Ext(M,N)=0");return(cup); }
     250   test1 = simplify(ideal(N1),10);
     251   test2 = simplify(ideal(P),10);
     252   if (test1[1]==0) { dbprint(pp,"//Ext(N,P)=0");return(cup); }
     253   test1 = simplify(ideal(P1),10);
     254   if (test1[1]==0) { dbprint(pp,"//Ext(M,P)=0");return(cup); }
     255 //------ compute kbases of Ext's ---------------------------------------------
     256 //------ Ext(M,N)
     257   test1 = simplify(ideal(M2),10);
     258   if (test1[1]==0) { ker = freemodule(ncols(M1)*nrows(N));}
     259   else
     260   {
     261     A   = kontrahom(M2,nrows(N));
     262     B   = kohom(N,ncols(M2));
     263     C   = intersect(A,B);
     264     C   = reduce(C,std(ideal(0)));C=simplify(C,10);
     265     ker = lift(A,C)+syz(A);
     266   }
     267   ima   = kohom(N,ncols(M1));
     268   A     = kontrahom(M1,nrows(N));
     269   ima   = ima+A;
     270   extMN = modulo(ker,ima);
     271   extMN0= std(extMN);
     272   e1    = vdim(extMN0);
     273   dbprint(pp-1,"// vdim Ext(M,N) = "+string(e1));
     274   if (e1 < 0)
     275   {
     276     "// Ext(M,N) not of finite dimension";
     277     return(cup);
     278   }
     279   kbMN  = kbase(extMN0);
     280   kbMN = matrix(ker)*kbMN;
     281   dbprint(pp-1,"// kbase of Ext^p(M,N)",
     282          "//  - the columns present the kbase elements in Hom(F(p),G(0))",
     283          "//  - F(*),G(*) are free resolutions of M and N",kbMN);
     284//------- Ext(N,P)
     285   test1 = simplify(ideal(N2),10);
     286   if (test1[1]==0) {  ker = freemodule(ncols(N1)*nrows(P)); }
     287   else
     288   {
     289     A = kontrahom(N2,nrows(P));
     290     B = kohom(P,ncols(N2));
     291     C = intersect(A,B);
     292     C = reduce(C,std(ideal(0)));C=simplify(C,10);
     293     ker = lift(A,C)+syz(A);
     294   }
     295   ima   = kohom(P,ncols(N1));
     296   A     = kontrahom(N1,nrows(P));
     297   ima   = ima+A;
     298   extNP = modulo(ker,ima);
     299   extNP0= std(extNP);
     300   e2    = vdim(extNP0);
     301   dbprint(pp-1,"// vdim Ext(N,P) = "+string(e2));
     302   if (e2 < 0)
     303   {
     304     "// Ext(N,P) not of finite dimension";
     305     return(cup);
     306   }
     307   kbNP  = kbase(extNP0);
     308   kbNP  = matrix(ker)*kbNP;
     309   dbprint(pp-1,"// kbase of Ext(N,P):",kbNP,
     310          "// kbase of Ext^q(N,P)",
     311          "//  - the columns present the kbase elements in Hom(G(q),H(0))",
     312          "//  - G(*),H(*) are free resolutions of N and P",kbNP);
     313
     314//------ Ext(M,P)
     315   test1 = simplify(ideal(P2),10);
     316   if (test1[1]==0) { ker = freemodule(ncols(P1)*nrows(P)); }
     317   else
     318   {
     319     A = kontrahom(P2,nrows(P));
     320     B = kohom(P,ncols(P2));
     321     C = intersect(A,B);
     322     C = reduce(C,std(ideal(0)));C=simplify(C,10);
     323     ker = lift(A,C)+syz(A);
     324   }
     325   ima   = kohom(P,ncols(P1));
     326   A     = kontrahom(P1,nrows(P));
     327   ima   = ima+A;
     328   extMP = modulo(ker,ima);
     329   extMP0= std(extMP);
     330   e3    = vdim(extMP0);
     331   dbprint(pp-1,"// vdim Ext(M,P) = "+string(e3));
     332   if (e3 < 0)
     333   {
     334     "// Ext(M,P) not of finite dimension";
     335     return(cup);
     336   }
     337   kbMP  = kbase(extMP0);
     338   kbMP  = matrix(ker)*kbMP;
     339   dbprint(pp-1,"// kbase of Ext^p+q(M,P)",
     340          "//  - the columns present the kbase elements in Hom(F(p+q),H(0))",
     341          "//  - F(*),H(*) are free resolutions of M and P",kbMP);
     342//----- lift kbase of Ext(M,N) ------------------------------------------------
     343   lift1 = kbMN;
     344   for (i=1;i<=q;i=i+1)
     345   {
     346     mA = kontrahom(resM[p+i],nrows(resN[i]));
     347     mB = kohom(resN[i],ncols(resM[p+i]));
     348     lift1 = lift(mB,mA*lift1);
     349   }
     350   dbprint(pp-1,"// lifting of kbase of Ext^p(M,N)",
     351   "//  - the columns present the lifting of kbase elements in Hom(F(p+q),G(q))",lift1);
     352//-------  compute: cup-products of base-elements -----------------------------
     353   f0 = nrows(P);
     354   f1 = ncols(N1);
     355   f2 = ncols(resM[p+q]);
     356   for (i=1;i<=e1;i=i+1)
     357   {
     358     for (j=1;j<=e2;j=j+1)
     359     {
     360       mA = matrix(ideal(lift1[j]),f1,f2);
     361       mB = matrix(ideal(kbMP[i]),f0,f1);
     362       mC = mB*mA;
     363       mC = matrix(ideal(mC),f0*f2,1);
     364       cup= concat(cup,mC);
    95365     }
    96   }
    97   else { extMN,extMN0 = Hom(M,N,1); }
    98   if (size(#)>0) { return(extMN,extMN0); }
    99   return(extMN );
     366   }
     367   dbprint(pp-1,"// matrix of cup-products (in Ext^p+q)",cup,"////// end level 2 //////");
     368//------- comptute: presentation of base-elements -----------------------------
     369   cup = lift(ker,cup);
     370   cup = lift_kbase(cup,extMP0);
     371//------- special output ------------------------------------------------------
     372   if (pp>2)
     373   {
     374     "// the associated matrices of the bilinear mapping 'cup' ";
     375     "// corresponding to the kbase elements of Ext^p+q(M,P) are shown,";
     376     "//  i.e. the rows of the final matrix are written as matrix of";
     377     "//  a bilinear form on Ext^p x Ext^q";
     378     matrix BL[e1][e2];
     379     for (k=1;k<=e3;k=k+1)
     380     {
     381       "//----"+string(k)+". component:";
     382       for (i=1;i<=e1;i=i+1)
     383       {
     384         for (j=1;j<=e2;j=j+1)
     385         {
     386           BL[i,j]=cup[k,j+e1*(i-1)];
     387         }
     388        }
     389        print(BL);
     390      }
     391     "////// end level 3 //////";
     392   }
     393   if (size(#)) { return(cup,kbMN,kbNP,kbMP);}
     394   else         { return(cup); }
    100395}
    101396example
    102 { "EXAMPLE:"; echo=2;
    103    ring r=0,(x,y),(c,dp);
    104    ideal i=x2-y3;
    105    qring qr=std(i);
    106    module M=[-x,y],[-y2,x];
    107    list EXT1=Ext(1,M,M,"");
    108    kbase(EXT1[2]);
    109 }
    110 ////////////////////////////////////////////////////////////////////////////////
    111 
    112 proc Hom (module M, module N, list #)
    113 USAGE:   Hom(M,N);  M,N=modules
    114 DISPLAY: degree of Hom(M,N);
    115 RETURN:  Hom(M,N), presentation as a quotient of a free module.
    116          If a third argument is given (of any type) return a list of two
    117          modules:
    118            [1] = module Hom(M,N)
    119            [2] = SB of  Hom(M,N)
    120 EXAMPLE: example Hom; shows an example
     397{"EXAMPLE";  echo=2;
     398  int p      = printlevel;
     399  ring  rr   = 32003,(x,y,z),(dp,C);
     400  ideal  I   = x4+y3+z2;
     401  qring  o   = std(I);
     402  module M   = [x,y,0,z],[y2,-x3,z,0],[z,0,-y,-x3],[0,z,x,-y2];
     403  print(cupproduct(M,M,M,1,3));
     404  printlevel = 3;
     405  list l     = (cupproduct(M,M,M,1,3,"any"));
     406  show(l[1]);show(l[2]);
     407  printlevel = p;
     408}
     409///////////////////////////////////////////////////////////////////////////////
     410
     411proc Ext_R (intvec v, module M, list #)
     412USAGE:   Ext_R(v,M[,p]);  v=int/intvec , M=module, p=int
     413COMPUTE: A presentation of Ext^k(M',R); for k=v[1],v[2],..., M'=coker(M).
     414         Let ...--> F2 --> F1 --M-> F0-->M'-->0 be a free resolution of M'. If
     415         0 <-- F0* <-A1-- F1* <-A2-- F2* <-A3--... denotes the dual sequence,
     416         Fi*=Hom(Fi,R), then Ext^k = ker(Ak)/im(Ak+1) is presented as in the
     417         following exact sequences:
     418                 Fk-1* <-Ak-- Fk* <-syz(Ak)-- R^p
     419                 Fk*/im(Ak+1) <-syz(Ak)-- R^p <-Ext^k-- R^q
     420         Hence Ext^k=modulo(syz(Ak),Ak+1) presents Ext^k(M',R);
     421RETURN:  Ext^k, of type module, a presentation of Ext^k(M',R) if v is of type
     422         int, resp. a list of Ext^k (k=v[1],v[2],...) if v is of type intvec.
     423         In case of a third argument of type int return a list:
     424           [1] = module Ext^k/list of Ext^k
     425           [2] = SB of Ext^k/list of SB of Ext^k
     426           [3] = matrix/list of matrices, each representing kbase of Ext^k
     427                 (if finite dimensional)
     428DISPLAY: printlevel >=0: degree of Ext^k for each k  (default)
     429         printlevel >=1: Ak, Ak+1 and kbase of Ext^k in Fk*
     430NOTE:    In order to compute Ext^k(M,R) use the command Ext_R(k,syz(M));
     431         or the 2 commands: list L=mres(M,2);  Ext_R(k,L[2]);
     432EXAMPLE: example Ext_R; shows examples
     433{
     434
     435//Bemerkung (nur fuer internen Gebrauch): Ext_R(v,M[,"sres",p]); bewirkt folgendes:
     436// Es wird der input mit sres statt mres aufgeloest. Bei den bisherigen Versuchen
     437// ist dies insgesamt langsamer, da sres zu gro§e Objekte zurueckliefert.
     438// Der Versuch, auch spaeter sres statt mres zu verwenden, ist ganz aufgegeben,
     439// da mit sres spaeter syz und modulo viel laenger dauern!
     440// In case M is known to be a SB, set attrib(M,"isSB",1); in order to
     441// avoid  unnecessary SB computations
     442
     443//------------ initialisation -------------------------------------------------
     444  module m1,m2,ret,ret0;
     445  matrix ker,kb;
     446  list L1,L2,L3,L,resl,K;
     447  int k,max,ii,t1,t2;
     448  int s = size(v);
     449  intvec v1 = sort(v)[1];
     450  max = v1[s];                 // the maximum integer occuring in intvec v
     451  int p = printlevel-voice+3;  // p=printlevel+1 (default: p=1)
     452  // --------------- Variante mit sres
     453  for( ii=1; ii<=size(#); ii++ )
     454  {
     455    t2=1; // return a list if t2=1
     456    if( typeof(#[ii])=="string" )
     457    {
     458      if ( #[ii]=="sres" ) { t1=1; t2=0; } // use sres instead of mres if t1=1
     459    }
     460  }
     461//----------------- compute resolution of coker(M) ----------------------------
     462  if( max<0 ) { dbprint(p,"// Ext^i=0 for i<0!"); return([1]); }
     463  if( t1==1 )
     464  {
     465    if( attrib(M,"isSB")==0 ) { M=std(M); }
     466    resl = sres(M,max+1);
     467  }
     468  else { resl = mres(M,max+1); }
     469  for( ii=1; ii<=s; ii++ )
     470  {
     471//-----------------  apply Hom(_,R) at k-th place -----------------------------
     472    k=v[ii];
     473    if( k<0 )                   // Ext^k=0 for negative k
     474    {
     475      dbprint(p-1,"// Ext^i=0 for i<0!");
     476      ret    = gen(1);
     477      ret0   = std(ret);
     478      L1[ii] = ret;
     479      L2[ii] = ret0;
     480      L3[ii] = matrix(kbase(ret0));
     481      dbprint(p,"// degree of Ext^"+string(k)+":");
     482      if( p>=0 ) { degree(ret0);"";}
     483    }
     484    else
     485    {
     486      m2 = transpose(resl[k+1]);
     487      if( k==0 ) { m1=0*gen(nrows(m2)); }
     488      else { m1 = transpose(resl[k]); }
     489//----------------- presentation of ker(m2)/im(m1) ----------------------------
     490      ker = syz(m2);
     491      ret = modulo(ker,m1);
     492      dbprint(p-1,"// Computing Ext^"+string(k)+":",
     493         "// Let 0<--coker(M)<--F0<--F1<--F2<--... be a resolution of M,",
     494         "// then F"+string(k)+"*-->F"+string(k+1)+"* is given by:",m2,
     495         "// and F"+string(k-1)+"*-->F"+string(k)+"* is given by:",m1,"");
     496      ret0 = std(ret);
     497      dbprint(p,"// degree of Ext^"+string(k)+":");
     498      if( p>0 ) { degree(ret0);"";}
     499      if( t2 )
     500      {
     501         if( vdim(ret0)>=0 )
     502         {
     503            kb = kbase(ret0);
     504            if ( size(ker)!=0 ) { kb = matrix(ker)*kb; }
     505            dbprint(p-1,
     506            "// columns of matrix are kbase of Ext^"+string(k)+" in F"+string(k)+"*:",kb,"");
     507            L3[ii] = kb;
     508         }
     509         L2[ii] = ret0;
     510      }
     511      L1[ii] = ret;
     512    }
     513  }
     514  if( t2 )
     515  {
     516     if( s>1 ) { L = L1,L2,L3; return(L); }
     517     else { L = ret,ret0,kb; return(L); }
     518  }
     519  else
     520  {
     521     if( s>1 ) { return(L1); }
     522     else { return(ret); }
     523  }
     524}
     525example
     526{"EXAMPLE:";     echo=2;
     527  int p      = printlevel;
     528  printlevel = 1;
     529  ring r     = 0,(x,y,z),dp;
     530  ideal i    = x2y,y2z,z3x;
     531  module E   = Ext_R(1,i);       //computes Ext^1(r/i,r)
     532  is_zero(E);
     533  module m   = [x],[0,y];
     534  list L     = Ext_R(2..3,m);    //computes Ext^i(r^2/m,r), i=2,3
     535  show(L);"";
     536  qring R    = std(x2+yz);
     537  intvec v   = 0,2,4;
     538  printlevel = 2;                //shows what is going on
     539  ideal i    = x,y,z;            //computes Ext^i(r/(x,y,z),r/(x2+yz)), i=0,2,4
     540  list L     = Ext_R(v,i,1);     //over the qring R=r/(x2+yz), std and kbase
     541  printlevel = p;
     542}
     543///////////////////////////////////////////////////////////////////////////////
     544
     545proc Ext (intvec v, module M, module N, list #)
     546USAGE:   Ext(v,M,N[,any]);  v=int/intvec, M,N=modules
     547COMPUTE: A presentation of Ext^k(M',N'); for k=v[1],v[2],... where
     548         M'=coker(M) and N'=coker(N). Let
     549         0<--M'<-- F0 <-M-- F1 <-- F2 <--...  resp. 0<--N'<-- G0 <--N- G1 be
     550         a free resolution of M' resp. a presentations of N'. Consider
     551                      0                  0                  0
     552                      |^                 |^                 |^
     553               --> Hom(Fk-1,N') -Ak-> Hom(Fk,N') -Ak+1-> Hom(Fk+1,N')
     554                      |^                 |^                 |^
     555               --> Hom(Fk-1,G0) -Ak-> Hom(Fk,G0) -Ak+1-> Hom(Fk+1,G0)
     556                                         |^                 |^
     557                                         |C                 |B
     558                                      Hom(Fk,G1) -----> Hom(Fk+1,G1)
     559         (Ak,Ak+1 induced by M and B,C induced by N).
     560         Let K=modulo(Ak+1,B), J=module(Ak)+module(C) and Ext=modulo(K,J),
     561         then we have exact sequences
     562                  R^p  --K-> Hom(Fk,G0) --Ak+1-> Hom(Fk+1,G0)/im(B)
     563         R^q -Ext-> R^p --K->Hom(Fk,G0)/im(Ak)+im(C) --Ak+1->Hom(Fk+1,G0)/im(B)
     564         Hence Ext presents Ext^k(M',N')
     565RETURN:  Ext, of type module, a presentation of Ext^k(M',N') if v is of type
     566         int, resp. a list of Ext^k (k=v[1],v[2],...) if v is of type intvec.
     567         In case of a third argument of any type return a list:
     568           [1] = module Ext/list of Ext^k
     569           [2] = SB of Ext/list of SB of Ext^k
     570           [3] = matrix/list of matrices, each representing a kbase of Ext^k
     571                 (if finite dimensional)
     572DISPLAY: printlevel >=0: degree of Ext^k for each k  (default)
     573         printlevel >=1: Ak, Ak+1 and kbase of Ext^k in Hom(Fk,G0)
     574                            (if finite dimensional)
     575NOTE:    In order to compute Ext^k(M,N) use the command Ext(k,syz(M),syz(N));
     576         or: list P=mres(M,2); list Q=mres(N,2); Ext(k,P[2],Q[2]);
     577EXAMPLE: example Ext;   shows examples
    121578{
    122579//---------- initialisation ---------------------------------------------------
    123    module A,B,C,ker,imag,homMN,homMN0;
    124    ideal  tes;
    125    tes = simplify(ideal(M),10);
    126    if (tes[1]==0)
    127    {
    128       "// Hom(ring,N)=N";
    129       if (size(#)>0) { return(N,std(N)); }
    130       return(N);
    131    }
    132    tes = simplify(ideal(N),10); 
    133    if (tes[1]==0)
    134    {
    135       "// Hom(M,ring)=M^*";
    136       homMN = transpose(M);
    137       if (size(#)>0) { return(homMN,std(homMN));}
    138       return(homMN);
    139    }
    140    B = kohom(N,ncols(M));
    141    A = kontrahom(M,nrows(N));
    142    C = intersect(A,B);
    143    C = reduce(C,std(ideal(0)));C=simplify(C,10);
    144    ker   = lift(A,C)+syz(A);                              //ker(Hom(m,N))
    145    imag  = kohom(N,ncols(M));                             //im(Hom(M,n))
    146    homMN = modulo(ker,imag);
    147    homMN0= std(homMN);
    148    "// degree of Hom(M,N):";degree(homMN0);
    149    if (size(#)>0) { return(homMN,homMN0); }
    150    return(homMN);
     580  int k,max,ii,l,row,col;
     581  module A,B,C,D,M1,M2,N1,ker,imag,extMN,extMN0;
     582  matrix kb;
     583  list L1,L2,L3,L,resM,K;
     584  ideal  test1;
     585  intmat Be;
     586  int s = size(v);
     587  intvec v1 = sort(v)[1];
     588  max = v1[s];                      // the maximum integer occuring in intvec v
     589  int p = printlevel-voice+3;       // p=printlevel+1 (default: p=1)
     590//---------- test: coker(N)=basering, coker(N)=0 ? ----------------------------
     591  if( max<0 ) { dbprint(p,"// Ext^i=0 for i<0!"); return([1]); }
     592  N1 = std(N);
     593  if( size(N1)==0 )      //coker(N)=basering, in this case proc Ext_R is faster
     594  { printlevel=printlevel+1;
     595    if( size(#)==0 )
     596    { def E = Ext_R(v,M);
     597      printlevel=printlevel-1;
     598      return(E);
     599    }
     600    else
     601    { def E = Ext_R(v,M,#[1]);
     602       printlevel=printlevel-1;
     603       return(E);
     604     }
     605  }
     606  if( dim(N1)==-1 )                          //coker(N)=0, all Ext-groups are 0
     607  { dbprint(p-1,"2nd module presents 0, hence Ext^k=0, for all k");
     608    for( ii=1; ii<=s; ii++ )
     609    { k=v[ii];
     610      extMN    = gen(1);
     611      extMN0   = std(extMN);
     612      L1[ii] = extMN;
     613      L2[ii] = extMN0;
     614      L3[ii] = matrix(kbase(extMN0));
     615      if( p>0 ) { "// degree of Ext^"+string(k)+":"; degree(extMN0);""; }
     616    }
     617  }
     618  else
     619  {
     620    if( size(N1) < size(N) ) { N=N1;}
     621    row = nrows(N);
     622//---------- resolution of M -------------------------------------------------
     623    resM = mres(M,max+1);
     624    for( ii=1; ii<=s; ii++ )
     625    { k=v[ii];
     626      if( k<0  )                                    // Ext^k is 0 for negative k
     627      { dbprint(p-1,"// Ext^k=0 for k<0!");
     628        extMN    = gen(1);
     629        extMN0   = std(extMN);
     630        L1[ii] = extMN;
     631        L2[ii] = extMN0;
     632        L3[ii] = matrix(kbase(extMN0));
     633        if( p>0 ) { "// degree of Ext^"+string(k)+":"; degree(extMN0);""; }
     634      }
     635      else
     636      { M2 = resM[k+1];
     637        if( k==0 ) { M1=0*gen(nrows(M2)); }
     638        else { M1 = resM[k]; }
     639        col = ncols(M1);
     640        D = kohom(N,col);
     641//---------- computing homology ----------------------------------------------
     642        imag  = kontrahom(M1,row);
     643        A     = kontrahom(M2,row);
     644        B     = kohom(N,ncols(M2));
     645        ker   = modulo(A,B);
     646        imag  = imag,D;
     647        extMN = modulo(ker,imag);
     648        dbprint(p-1,"// Computing Ext^"+string(k)+":",
     649         "// Let 0<--coker(M)<--F0<--F1<--F2<--... be a resolution of coker(M),",
     650         "// and 0<--coker(N)<--G0<--G1 a presentation of coker(N),",
     651         "// then Hom(F"+string(k)+",G0)-->Hom(F"+string(k+1)+",G0) is given by:",A,
     652         "// and Hom(F"+string(k-1)+",G0) + Hom(F"+string(k)+",G1)-->Hom(F"+string(k)+",G0) is given by:",imag,"");
     653        extMN0 = std(extMN);
     654        if( p>0 ) { "// degree of Ext^"+string(k)+":"; degree(extMN0);""; }
     655//---------- more information -------------------------------------------------
     656        if( size(#)>0 )
     657        { if( vdim(extMN0) >= 0 )
     658          { kb = kbase(extMN0);
     659            if ( size(ker)!=0) { kb = matrix(ker)*kb; }
     660            dbpri(p-1,"// columns of matrix are kbase of Ext^"+
     661                     string(k)+" in Hom(F"+string(k)+",G0)",kb,"");
     662            if( p>0 )
     663            { for (l=1;l<=ncols(kb);l=l+1)
     664              {
     665                "// element",l,"of kbase of Ext^"+string(k)+" in Hom(F"+string(k)+",G0)";
     666                "// as matrix: F"+string(k)+"-->G0";
     667                print(matrix(ideal(kb[l]),row,col));
     668              }
     669              "";
     670            }
     671            L3[ii] = matrix(kb);
     672          }
     673          L2[ii] = extMN0;
     674        }
     675        L1[ii] = extMN;
     676      }
     677    }
     678  }
     679  if( size(#) )
     680  {  if( s>1 ) { L = L1,L2,L3; return(L); }
     681     else { L = extMN,extMN0,matrix(kb); return(L); }
     682  }
     683  else
     684  {  if( s>1 ) { return(L1); }
     685     else { return(extMN); }
     686  }
    151687}
    152688example
    153 { "EXAMPLE:";  echo = 2;
    154    ring r=0,(x,y),(c,dp);
    155    ideal i=x2-y3;
    156    qring q=std(i);
    157    module M=[-x,y],[-y2,x];
    158    module hom=Hom(M,M);
    159    print(hom); newline;
    160    ring s=3,(x,y,z),(c,dp);
    161    ideal i=x2+y5+z4;i=jacob(i);
    162    qring rq=std(i);
    163    matrix M[2][2]=xy,x3,5y,z2,x2;
    164    matrix N[4][4]=x,y,z,x2,xyx2y,y3,xz2,x2z,z3;
    165    print(M);
    166    print(N);
    167    print(Hom(M,N));
     689{"EXAMPLE:";   echo=2;
     690  int p      = printlevel;
     691  printlevel = 1;
     692  ring r     = 0,(x,y),dp;
     693  ideal i    = x2-y3;
     694  ideal j    = x2-y5;
     695  list E     = Ext(0..2,i,j);    // Ext^k(r/i,r/j) for k=0,1,2 over r
     696  qring R    = std(i);
     697  ideal j    = fetch(r,j);
     698  module M   = [-x,y],[-y2,x];
     699  printlevel = 2;
     700  module E1  = Ext(1,M,j);       // Ext^1(R^2/M,R/j) over R=r/i
     701  list l     = Ext(4,M,M,1);     // Ext^4(R^2/M,R^2/M) over R=r/i
     702  printlevel = p;
    168703}
    169704////////////////////////////////////////////////////////////////////////////////
    170705
    171 proc qmod (module M, module N)
    172 USAGE:   qmod(M,N); M,N=modules, N a submodule of M
    173 COMPUTE: presentation S of M/N, i.e. M/N<<--F<--[S], F free of rank = size(M)
    174 RETURN:  module  S
    175 {     
    176   return(lift(M,N)+syz(M));
     706proc Hom (module M, module N, list #)
     707USAGE:   Hom(M,N,[any]);  M,N=modules
     708COMPUTE: A presentation of Hom(M',N'), M'=coker(M), N'=coker(N) as follows:
     709         Let ...-->F1 --M-> F0-->M'-->0 and ...-->G1 --N-> G0-->N'-->0  be
     710         presentations of M' and N'. Consider
     711                                         0               0
     712                                         |^              |^
     713              0 --> Hom(M',N') ----> Hom(F0,N') ----> Hom(F1,N')
     714                                         |^              |^
     715         (A:  induced by M)          Hom(F0,G0) --A-> Hom(F1,G0)
     716                                         |^              |^
     717         (B,C:induced by N)              |C              |B
     718                                     Hom(F0,G1) ----> Hom(F1,G1)
     719
     720         Let D=modulo(A,B) and Hom=modulo(D,C), then we have exact sequences
     721              R^p  --D-> Hom(F0,G0) --A-> Hom(F1,G0)/im(B)
     722              R^q -Hom-> R^p --D-> Hom(F0,G0)/im(C) --A-> Hom(F1,G0)/im(B).
     723         Hence Hom presents Hom(M',N')
     724RETURN:  Hom, of type module, presentation of Hom(M',N') or,
     725         in case of 3 arguments, a list:
     726           [1] = Hom
     727           [2] = SB of Hom
     728           [3] = kbase of coker(Hom) (if finite dimensional), represented by
     729                 elements in Hom(F0,G0) via mapping D
     730DISPLAY: printlevel >=0: degree of Hom  (default)
     731         printlevel >=1: D and C and kbase of coker(Hom) in Hom(F0,G0)
     732         printlevel >=2: elements of kbase of coker(Hom) as matrix :F0-->G0
     733NOTE:    DISPLAY is as described only for a direct call of 'Hom'. Calling 'Hom'
     734         from another proc has the same effect as decreasing printlevel by 1.
     735EXAMPLE: example Hom;  shows examples
     736{
     737//---------- initialisation ---------------------------------------------------
     738  int l,p;
     739  matrix kb;
     740  module A,B,C,D,homMN,homMN0;
     741  list L;
     742//---------- computation of Hom -----------------------------------------------
     743  B = kohom(N,ncols(M));
     744  A = kontrahom(M,nrows(N));
     745  C = kohom(N,nrows(M));
     746  D = modulo(A,B);
     747  homMN = modulo(D,C);
     748  homMN0= std(homMN);
     749  p = printlevel-voice+3;       // p=printlevel+1 (default: p=1)
     750  if( p>=0 ) { "// degree of Hom:"; degree(homMN0); ""; }
     751  dbprint(p-1,"// given ...--> F1 --M-> F0 -->M'--> 0 and ...--> G1 --N-> G0 -->N'--> 0,",
     752         "// show D=ker(Hom(F0,G0) --> Hom(F1,G0)/im(Hom(F1,G1) --> Hom(F1,G0)))",D,
     753         "// show C=im(Hom(F0,G1) --> Hom(F0,G0))",C,"");
     754//---------- extra output if size(#)>0 ----------------------------------------
     755  if( size(#)>0 )
     756  {  if( vdim(homMN0)>0 )
     757     {  kb = kbase(homMN0);
     758        kb = matrix(D)*kb;
     759        if( p>2 )
     760        {  for (l=1;l<=ncols(kb);l=l+1)
     761           {
     762             "// element",l,"of kbase of Hom in Hom(F0,G0) as matrix: F0-->G0:";
     763             print(matrix(ideal(kb[l]),nrows(N),nrows(M)));
     764           }
     765        }
     766        else
     767       { dbprint(p-1,"// columns of matrix are kbase of Hom in Hom(F0,G0)",kb); }
     768        L=homMN,homMN0,kb; return(L);
     769     }
     770     L=homMN,homMN0; return(L);
     771  }
     772  return(homMN);
     773}
     774example
     775{"EXAMPLE:";  echo = 2;
     776  int p     = printlevel;
     777  printlevel= 1;   //in 'example proc' printlevel has to be increased by 1
     778  ring r    = 0,(x,y),dp;
     779  ideal i   = x2-y3,xy;
     780  qring q   = std(i);
     781  ideal i   = fetch(r,i);
     782  module M  = [-x,y],[-y2,x],[x3];
     783  module H  = Hom(M,i);
     784  print(H);
     785  printlevel= 2;
     786  list L    = Hom(M,i,1);"";
     787  ring s    = 3,(x,y,z),(c,dp);
     788  ideal i   = jacob(ideal(x2+y5+z4));
     789  qring rq=std(i);
     790  matrix M[2][2]=xy,x3,5y,4z,x2;
     791  matrix N[3][2]=x2,x,y3,3xz,x2z,z;
     792  print(M);
     793  print(N);
     794  list l=Hom(M,N,1);
     795  printlevel = p;
     796}
     797////////////////////////////////////////////////////////////////////////////////
     798
     799proc homology (matrix A,matrix B,module M,module N,list #)
     800USAGE:   homology(A,B,M,N);
     801COMPUTE: Let M and N be submodules of R^m and R^n presenting M'=R^m/M, N'=R^n/N
     802         (R=basering) and let A,B matrices inducing maps R^k--A-->R^m--B-->R^n.
     803         Compute a presentation R^q --H-> R^m of the module
     804              ker(B)/im(A) := ker(M'/im(A) --B--> N'/im(BM)+im(BA)).
     805         If B induces a map M'--B-->N' (i.e BM=0) and if R^k--A-->M'--B-->N' is
     806         a complex (i.e. BA=0) then ker(B)/im(A) is the homology of this complex
     807RETURN:  module H, a presentation of ker(B)/im(A)
     808NOTE:    homology returns a free module of rank m if ker(B)=im(A)
     809EXAMPLE: example homology; shows examples
     810{
     811  module ker,ima;
     812  ker = modulo(B,N);
     813  ima = A,M;
     814  return(modulo(ker,ima));
     815}
     816example
     817{"EXAMPLE";    echo=2;
     818  ring r;
     819  ideal id=maxideal(4);
     820  qring qr=std(id);
     821  module N=maxideal(3)*freemodule(2);
     822  module M=maxideal(2)*freemodule(2);
     823  module B=[2x,0],[x,y],[z2,y];
     824  module A=M;
     825  degree(std(homology(A,B,M,N)));"";
     826  ring s=0,x,ds;
     827  qring qs=std(x4);
     828  module A=[x];module B=A;
     829  module M=[x3];module N=M;
     830  homology(A,B,M,N);
    177831}
    178832//////////////////////////////////////////////////////////////////////////////
    179833
     834proc kernel (matrix A,module M,module N)
     835USAGE:   kernel(A,M,N);
     836COMPUTE: Let M and N be submodules of R^m and R^n presenting M'=R^m/M, N'=R^n/N
     837         (R=basering) and let A:R^m-->R^n a matrix inducing a map A':M'-->N'.
     838         Compute a presentation K of ker(A') as in the commutative diagram:
     839                       ker(A') --->  M' --A'--> N'
     840                           |^        |^         |^
     841                           |         |          |
     842                          R^r  ---> R^m --A--> R^n
     843                           |^        |^         |^
     844                           |K        |M         |N
     845                           |         |          |
     846                          R^s  ---> R^p -----> R^q
     847RETURN:  module K, a presentation of ker(A')
     848EXAMPLE: example kernel; shows examples
     849{
     850  module M1 = modulo(A,N);
     851  return(modulo(M1,M));
     852}
     853example
     854{"EXAMPLE";    echo=2;
     855  ring r;
     856  module N=[2x,x],[0,y];
     857  module M=maxideal(1)*freemodule(2);
     858  matrix A[2][2]=2x,0,x,y,z2,y;
     859  module K=kernel(A,M,N);
     860  degree(std(K));
     861  print(K);
     862}
     863////////////////////////////////////////////////////////////////////////////////
     864
     865proc kohom (matrix M, int j)
     866USAGE:   kohom(A,k); A=matrix, k=integer
     867RETURN:  matrix Hom(R^k,A) i.e. let A be a matrix defining a map: F1 --> F2 of
     868         free R-modules, the matrix of Hom(R^k,F1)-->Hom(R^k,F2) is computed
     869EXAMPLE: example kohom; shows an example
     870{
     871  if (j==1)
     872  { return(M);}
     873  if (j>1)
     874  { return(outer(M,diag(1,j))); }
     875  else { return(0);}
     876}
     877example
     878{"EXAMPLE:";   echo=2;
     879  ring r;
     880  matrix n[2][3]=x,y,5,z,77,33;
     881  print(kohom(n,3));
     882}
     883/////////////////////////////////////////////////////////////////////////////////
     884
    180885proc kontrahom (matrix M, int j)
    181 USAGE:   qmod(M,N); M,N=modules, N a submodule of M
    182886USAGE:   kontrahom(A,k); A=matrix, k=integer
    183 RETURN:  Hom(A,P^k), i.e. let A be a matrix defining a map: F1 --> F2 of free
    184          P-modules, the matrix of Hom(F2,P^k)-->Hom(F1,P^k) is computed
     887RETURN:  matrix Hom(A,R^k), i.e. let A be a matrix defining a map: F1 --> F2 of
     888         free  R-modules, the matrix of Hom(F2,R^k)-->Hom(F1,R^k) is computed
    185889EXAMPLE: example kontrahom; shows an example
    186890{
    187   return(transpose(outer(diag(1,j),M)));
     891if (j==1)
     892  { return(transpose(M));}
     893  if (j>1)
     894  { return(transpose(outer(diag(1,j),M)));}
     895  else { return(0);}
    188896}
    189897example
    190 { "EXAMPLE:";  echo=2;
    191    ring r;
    192    matrix n[2][3]=x,y,5,z,77,33;
    193    print(kontrahom(n,3));
     898{"EXAMPLE:";  echo=2;
     899  ring r;
     900  matrix n[2][3]=x,y,5,z,77,33;
     901  print(kontrahom(n,3));
    194902}
    195903///////////////////////////////////////////////////////////////////////////////
    196 
    197 proc kohom (matrix M, int j)
    198 USAGE:   kohom(A,k); A=matrix, k=integer
    199 RETURN:  Hom(P^k,A) i.e. let A be a matrix defining a map: F1 --> F2 of free
    200          P-modules, the matrix of Hom(P^k,F1)-->Hom(P^k,F2) is computed
    201 EXAMPLE: example kohom; shows an example
    202 {
    203     return(outer(M,diag(1,j))); 
    204 }
    205 example
    206 { "EXAMPLE:";   echo=2;
    207    ring r;
    208    matrix n[2][3]=x,y,5,z,77,33;
    209    print(kohom(n,3));         
    210 }
    211 ///////////////////////////////////////////////////////////////////////////////
    212 
  • Singular/LIB/inout.lib

    r6d09c56 r6f2edc  
    1 // $Id: inout.lib,v 1.1.1.1 1997-04-25 15:13:26 obachman Exp $
    2 //system("random",787422842);
    3 //(GMG,BM)
    4 ///////////////////////////////////////////////////////////////////////////////
    5 
    6 LIBRARY:  inout.lib     PROCEDURES FOR MANIPULATING IN- AND OUTPUT       
     1// $Id: inout.lib,v 1.2 1997-04-28 19:27:20 obachman Exp $
     2// system("random",787422842);
     3// (GMG/BM, last modified 22.06.96)
     4///////////////////////////////////////////////////////////////////////////////
     5
     6LIBRARY:  inout.lib     PROCEDURES FOR MANIPULATING IN- AND OUTPUT
    77
    88 allprint(list);        print list if ALLprint is defined, with pause if >0
     
    1919///////////////////////////////////////////////////////////////////////////////
    2020
    21 proc allprint (list #) 
     21proc allprint (list #)
    2222USAGE:   allprint(L);  L list
    2323CREATE:  display L[1], L[2], ... if an integer with name ALLprint is defined,
    24          makes "pause",   if ALLprint > 0 
     24         makes "pause",   if ALLprint > 0
    2525         listvar(matrix), if ALLprint = 2
    2626RETURN:  no return value
     
    3030   {
    3131      int i;
    32       for( i=1; i<=size(#); i++ ) { print(#[i]); }
     32      for( i=1; i<=size(#); i=i+1 ) { print(#[i]); }
    3333      if( ALLprint==2 ) { pause; listvar(matrix); }
    3434      if( ALLprint >0 ) { pause; }
    35    } 
     35   }
    3636   return();
    37 }   
     37}
    3838example
    3939{ "EXAMPLE:"; echo = 2;
     
    4343   allprint("M =",M);
    4444   kill ALLprint;
    45 } 
     45}
    4646///////////////////////////////////////////////////////////////////////////////
    4747
     
    5252RETURN:  no return value
    5353NOTE:    this is uesful to control the printing of comments or partial results
    54          in a procedure, e.g. for debugging a procedure. 
     54         in a procedure, e.g. for debugging a procedure.
    5555         It is similair but not the same as the internal function dbprint
    5656EXAMPLE: example dbpri; shows an example
    5757{
    58    int i; 
     58   int i;
    5959   if( defined(printlevel)==0 ) { int printlevel; export printlevel; }
    6060   if( n<=printlevel )
    6161   {
    62       for( i=1; i<=size(#); i++ ) {  print(#[i]); }
     62      for( i=1; i<=size(#); i=i+1 ) {  print(#[i]); }
    6363   }
    6464   return();
    65 }   
     65}
    6666example
    6767{ "EXAMPLE:"; echo = 2;
    6868   ring s;
    69    module M=freemodule(3); 
     69   module M=freemodule(3);
    7070   dbpri(0,"M =",M);
    7171}
    7272///////////////////////////////////////////////////////////////////////////////
    7373
    74 proc lprint 
     74proc lprint
    7575USAGE:   lprint(id[,n]);  id poly/ideal/vector/module/matrix, n integer
    76 RETURN:  string of id in a format fitting into lines of size n; if only one 
    77          argument is present, n = pagewidth 
     76RETURN:  string of id in a format fitting into lines of size n; if only one
     77         argument is present, n = pagewidth
    7878NOTE:    id is printed columnwise, each column separated by a blank line;
    7979         hence lprint(transpose(id)); displays a matrix id in a format which
     
    8585   matrix M = matrix(#[1]);
    8686   poly p,h,L; string s1,s,S; int jj,ii,a;
    87    for (jj=1; jj<=ncols(M); jj++)
    88    {   
    89       for (ii=1; ii<=nrows(M); ii++)
     87   for (jj=1; jj<=ncols(M); jj=jj+1)
     88   {
     89      for (ii=1; ii<=nrows(M); ii=ii+1)
    9090      {
    9191         a=2;
     
    9696            while (p != 0)
    9797            {
    98                if (a+size(string(h+L)) > n) 
    99                { 
     98               if (a+size(string(h+L)) > n)
     99               {
    100100                  s = string(h);
    101101                  if (a != 0) { s = "  "+s; }
     
    109109         }
    110110         if (ii != nrows(M)) { s = s+","; S=S+newline+s; }
    111          else 
     111         else
    112112         {
    113113            if (jj != ncols(M)) { s = s+","; S=S+newline+s+newline;}
     
    132132   // above) as input in order to reproduce m (by defining m1):
    133133   execute("matrix M[2][3]="+s+";");
    134    module m1 = transpose(M); 
     134   module m1 = transpose(M);
    135135   m-m1;
    136136}
     
    142142         if n is given, only the first n characters of each colum are shown
    143143RETURN:  no return value
    144 EXAMPLE: example pmat; shows an example 
     144EXAMPLE: example pmat; shows an example
    145145{
    146146//------------- main case: input is a matrix, no second argument---------------
    147147   if ( size(#)==0)
    148    { 
     148   {
    149149      int elems,mlen,slen,c,r;
    150150   //-------------- count maximal size of each column, and sum up -------------
    151       for ( c=1; c<=ncols(m); c++)
     151      for ( c=1; c<=ncols(m); c=c+1)
    152152      {  int len(c);
    153          for (r=1; r<=nrows(m); r++)
     153         for (r=1; r<=nrows(m); r=r+1)
    154154         {
    155155            elems = elems+1;
     
    163163      string aus; string sep = " ";
    164164      if (mlen >= pagewidth) { sep = newline; }
    165       for (r=1; r<nrows(m); r++)
     165      for (r=1; r<nrows(m); r=r+1)
    166166      {  elems = r; aus = "";
    167          for (c=1; c<=ncols(m); c++)
     167         for (c=1; c<=ncols(m); c=c+1)
    168168         {
    169169            aus = aus + s(elems)[1,len(c)] + sep;
     
    174174   //--------------- print last row (no comma after last entry) ---------------
    175175      aus = ""; elems = nrows(m);
    176       for (c=1; c<ncols(m); c++)
     176      for (c=1; c<ncols(m); c=c+1)
    177177      {
    178178         aus = aus + s(elems)[1,len(c)] + sep;
     
    185185   if ( typeof(#[1])=="int" )
    186186   {  string aus,tmp; int ll,c,r;
    187       for ( r=1; r<=nrows(m); r++)
     187      for ( r=1; r<=nrows(m); r=r+1)
    188188      {  aus = "";
    189          for (c=1; c<=ncols(m); c++)
    190          { 
    191             tmp=string(m[r,c]); 
    192             aus=aus+tmp[1,#[1]]+" "; 
     189         for (c=1; c<=ncols(m); c=c+1)
     190         {
     191            tmp=string(m[r,c]);
     192            aus=aus+tmp[1,#[1]]+" ";
    193193         }
    194194         aus;
     
    207207///////////////////////////////////////////////////////////////////////////////
    208208
    209 proc rMacaulay 
     209proc rMacaulay
    210210USAGE:   rMacaulay(s[,n]);  s string, n integer
    211211RETURN:  a string which should be readable by Singular if s is a string read
    212212         by Singular from a file which was produced by Macaulay_1 (='Macaulay
    213          classic'). If a second argument is present the first n lines of the 
    214          file are deleted (which is useful if the file was prodeuced e.g. by 
    215          the putstd command of Macaulay) 
     213         classic'). If a second argument is present the first n lines of the
     214         file are deleted (which is useful if the file was prodeuced e.g. by
     215         the putstd command of Macaulay)
    216216NOTE:    This does not always work with 'cut and paste' since, coming
    217          from the screen, the character \ is treated differently 
    218 EXAMPLE: example rMacaulay; shows an example 
     217         from the screen, the character \ is treated differently
     218EXAMPLE: example rMacaulay; shows an example
    219219{
    220220   int n;
     
    223223//------------------------ delete first n=#[2] lines --------------------------
    224224   int ii=find(s0,newline); int jj;
    225    for ( jj=1; jj<=n; jj++)
     225   for ( jj=1; jj<=n; jj=jj+1)
    226226   {
    227227      s0 = s0[ii+1,size(s0)-ii];
     
    243243      ii = find(s0,newline);
    244244   }
    245    jj=jj+1; 
     245   jj=jj+1;
    246246   string s(jj) = s0;
    247247//------------ delete blanks and \ at end of each string and add , ------------
     
    261261      s1 = ""; s2 = s(ii);
    262262      kk = find(s(ii)," "); ll=kk+1;
    263       while( kk!=0 ) 
     263      while( kk!=0 )
    264264      {
    265265         while( s2[ll]==" ") { ll=ll+1; }
     
    299299example
    300300{  "EXAMPLE:"; echo = 2;
    301    // Assume there exists a file 'Macid' with the following ideal in Macaulay 
     301   // Assume there exists a file 'Macid' with the following ideal in Macaulay
    302302   // format:"
    303    // x[0]3-101/74x[0]2x[1]+7371x[0]x[1]2-13/83x[1]3-x[0]2x[2] \ 
     303   // x[0]3-101/74x[0]2x[1]+7371x[0]x[1]2-13/83x[1]3-x[0]2x[2] \
    304304   //     -4/71x[0]x[1]x[2]-65/64x[1]2x[2]-49/111x[0]x[2]2-x[1]x[2]2 \
    305    //     -747x[2]3+6072x[0]2x[3] 
    306    // You can read this file into Singular and assign it to the string s1 by: 
     305   //     -747x[2]3+6072x[0]2x[3]
     306   // You can read this file into Singular and assign it to the string s1 by:
    307307   // string s1 = read("Macid");
    308308   // This is equivalent to";
     
    314314   // You may wish to assign s1 to a Singular ideal id:
    315315   string sid = "ideal id =",rMacaulay(s1),";";
    316    ring r = 0,x(0..3),dp; 
     316   ring r = 0,x(0..3),dp;
    317317   execute sid;
    318318   id; "";
     
    330330///////////////////////////////////////////////////////////////////////////////
    331331
    332 proc show  
     332proc show (id, list #)
    333333USAGE:   show(id);   id any object of basering or of type ring/qring
    334          show(R,s);  R=ring, s=string (`s` = name of an object belonging to R)
    335 CREATE:  display id resp.`s` in a compact format together with some information
     334         show(R,s);  R=ring, s=string (s = name of an object belonging to R)
     335CREATE:  display id/s in a compact format together with some information
    336336RETURN:  no return value
    337337NOTE:    objects of type string, int, intvec, intmat belong to any ring.
    338          id may be a ring or a qring. In this case the minimal polynomial is 
    339          displayed, and, for a qring, also the defining ideal.
    340          id must not be of type list
    341 CAUTION: show(R,s) does not work inside a procedure 
     338         id may be a ring or a qring. In this case the minimal polynomial is
     339         displayed, and, for a qring, also the defining ideal
     340         id may be of type list but the list must not contain a ring
     341CAUTION: show(R,s) does not work inside a procedure
    342342EXAMPLE: example show; shows an example
    343 { 
     343{
    344344//------------- use funny names in order to avoid name conflicts --------------
     345   int @li@, @ii;
     346   string @s@,@@s;
    345347   int @short@=short; short=1;
    346    string @s@;
    347348//----------------------------- check syntax ----------------------------------
    348    if( size(#)==1 )
    349    {
    350        def @id@ = #[1]; 
    351    }
    352    if( size(#)==2 )
    353    {
    354       if( typeof(#[1])=="ring" or typeof(#[1])=="qring")
    355       {
    356          def @R@ = #[1];
    357          setring @R@;
    358          def @id@=`#[2]`;   
    359       }
    360    }
    361    if( defined(@id@)!=voice ) { "// wrong syntax, type help show;";  return(); }   
     349   if( size(#)!= 0 )
     350   {
     351      if( typeof(#[1])=="int" ) { @li@=#[1]; }
     352   }
     353   if ( typeof(id)!="list" )
     354   {
     355      if( size(#)==0 )
     356      {
     357          def @id@ = id;
     358      }
     359      if( size(#)==1 )
     360      {
     361         if( typeof(#[1])=="int" )
     362         {
     363             def @id@ = id;
     364         }
     365         if( typeof(#[1])=="string" )
     366         {
     367            if( typeof(id)=="ring" or typeof(id)=="qring")
     368            {
     369               def @R@ = id;
     370               setring @R@;
     371               def @id@=`#[1]`;
     372            }
     373         }
     374      }
     375   }
     376//----------------------- case: id is of type list ----------------------------
     377   if ( typeof(id)=="list" )
     378   {
     379      @@s = tab(@li@)+"// list, "+string(size(id))+" element(s):";
     380      @@s;
     381      for ( @ii=1; @ii<=size(id); @ii++ )
     382      {
     383         if( typeof(id[@ii])!="none" )
     384         {
     385            def @id(@ii) = id[@ii];
     386            show(@id(@ii),@li@+3);
     387         }
     388         else { tab(@li@+2),"//",id[@ii]; }
     389      }
     390      short=@short@; return();
     391    }
     392   if( defined(@id@)!=voice ) { "// wrong syntax, type help show;";  return(); }
    362393//-------------------- case: @id@ belongs to any ring -------------------------
    363394   if( typeof(@id@)=="string" or typeof(@id@)=="int" or typeof(@id@)=="intvec"
    364        or typeof(@id@)=="intmat" or typeof(@id@)=="list" ) 
    365    {
    366       "//", typeof(@id@);
     395       or typeof(@id@)=="intmat" or typeof(@id@)=="list" )
     396   {
     397      if( typeof(@id@)!="intmat" )
     398      {
     399         @@s = tab(@li@)+"// "+typeof(@id@)+", size "+string(size(@id@));
     400         @@s;
     401      }
     402      if( typeof(@id@)=="intmat" )
     403      {
     404         @@s = tab(@li@)+"// "+typeof(@id@)+", "+string(nrows(@id@))+" rows, "
     405               + string(ncols(@id@))+" columns";
     406         @@s;
     407      }
    367408      @id@;
    368       short=@short@; return(); 
     409      short=@short@; return();
    369410   }
    370411//-------------------- case: @id@ belongs to basering -------------------------
    371412   if( typeof(@id@)=="poly" or typeof(@id@)=="ideal" or typeof(@id@)=="matrix" )
    372413   {
    373       if( typeof(@id@)=="ideal" ) { @s@=", "+string(ncols(@id@))+" generators";}
    374       if( typeof(@id@)=="matrix") { @s@=", "+string(nrows(@id@))+"x"+string(ncols(@id@));}
    375       "// "+ typeof(@id@)+ @s@;
    376       print(matrix(@id@)); short=@short@; return();
     414      if( typeof(@id@)=="ideal" )
     415      {
     416         @s@=", "+string(ncols(@id@))+" generator(s)";
     417      }
     418      if( typeof(@id@)=="matrix")
     419      {
     420         @s@=", "+string(nrows(@id@))+"x"+string(ncols(@id@));
     421      }
     422      @@s = tab(@li@)+"// "+ typeof(@id@)+ @s@;
     423      @@s;
     424      print(matrix(@id@));
     425      short=@short@; return();
    377426   }
    378427   if( typeof(@id@)=="vector" )
    379428   {
    380       "//", typeof(@id@);
    381       print(@id@);  short=@short@; return();
     429      @@s = tab(@li@)+"// "+typeof(@id@);
     430      @@s;
     431      print(@id@);
     432      short=@short@; return();
    382433   }
    383434   if( typeof(@id@)=="module" )
    384435   {
    385       @s@=", "+string(ncols(@id@))+" generators";
    386       "// "+ typeof(@id@)+ @s@;
     436      @s@=", "+string(ncols(@id@))+" generator(s)";
     437      @@s = tab(@li@)+"// "+ typeof(@id@)+ @s@;
     438      @@s;
    387439      int @n@;
    388       for( @n@=1; @n@<=ncols(@id@); @n@++ ) { print(@id@[@n@]); }
     440      for( @n@=1; @n@<=ncols(@id@); @n@=@n@+1 ) { print(@id@[@n@]); }
    389441      short=@short@; return();
    390442   }
    391    if( typeof(@id@)=="number" ) { "//", typeof(@id@); @id@; short=@short@; return(); }
    392    if( typeof(@id@)=="map" )
    393    {
     443   if( typeof(@id@)=="number" )
     444   {
     445      @@s = tab(@li@)+"//", typeof(@id@);
     446      @@s;
     447      @id@; short=@short@; return();
     448   }
     449   if( typeof(@id@)=="map" )
     450   {
    394451      def @map = @id@;
    395       "// nth variable of preimage ring is mapped to nth component of map";
    396       if( size(#)==1 ) { type @map; }
    397       if( size(#)==2 ) { type `#[2]`; }
     452      @@s = tab(@li@)+"// i-th variable of preimage ring is mapped to @map[i]";
     453      @@s;
     454      if( size(#)==0 ) { type @map; }
     455      if( size(#)==1 )
     456      {
     457         if( typeof(#[1])=="int" )    { type @map; }
     458         if( typeof(#[1])=="string" ) { type `#[1]`; }
     459      }
    398460      short=@short@; return();
    399461   }
    400462//---------------------- case: @id@ is a ring/qring ---------------------------
    401    if( typeof(@id@)=="ring" or typeof(@id@)=="qring" ) 
    402    { 
     463   if( typeof(@id@)=="ring" or typeof(@id@)=="qring" )
     464   {
    403465      setring @id@;
    404466      string s="("+charstr(@id@)+"),("+varstr(@id@)+"),("+ordstr(@id@)+");";
    405       if( typeof(@id@)=="ring" ) 
    406       { 
    407          "// ring:",s;
    408          "// minpoly =", minpoly;
     467      if( typeof(@id@)=="ring" )
     468      {
     469         @@s = tab(@li@)+"// ring:"; @@s,s;
     470         @@s = tab(@li@)+"// minpoly ="; @@s,minpoly;
    409471      }
    410472      if( typeof(@id@)=="qring" )
    411       {
    412          "// qring:",s;
    413          "// minpoly =", minpoly;
    414          "// quotient ring from ideal:"; ideal(@id@);
    415       }
    416       short=@short@; return();
     473      {
     474         @@s = tab(@li@)+"// qring:"; @@s,s;
     475         @@s = tab(@li@)+"// minpoly ="; @@s, minpoly;
     476         @@s = tab(@li@)+"// quotient ring from ideal:"; @@s;
     477         ideal(@id@);
     478      }
     479      short=@short@; //return();
    417480   }
    418481}
     
    422485    show(r);
    423486    ideal i=x^3+y^5-6*z^3,xy,x3-y2;
    424     show(i);
     487    show(i,3);
    425488    vector v=x*gen(1)+y*gen(3);
    426     show(v);
    427     module m=v,2*v+gen(4);
    428     show(m);   
    429     ring S=(0,T),(a,b,c,d),ws(1,2,3,4); 
    430     minpoly = T2+1;
    431     ideal i=a2+b,c2+T2*d2; i=std(i);
    432     qring Q=i; 
    433     show(Q); 
     489    module m=v,2*v+gen(4);
     490    list L = i,v,m;
     491    show(L);
     492    ring S=(0,T),(a,b,c,d),ws(1,2,3,4);
     493    minpoly = T^2+1;
     494    ideal i=a2+b,c2+T^2*d2; i=std(i);
     495    qring Q=i;
     496    show(Q);
    434497    map F=r,a2,b^2,3*c3;
    435498    show(F);
     
    444507          (default: n=pagewidth)
    445508NOTE:     may be used in connection with lprint
    446 EXAMPLE:  example split; shows an example 
     509EXAMPLE:  example split; shows an example
    447510{
    448511   string line,re; int p,l;
    449    if( size(#)==0 ) { int n=pagewidth; } 
     512   if( size(#)==0 ) { int n=pagewidth; }
    450513   else { int n=#[1]; }
    451514   if( s[size(s),1] != newline ) { s=s+newline; }
     
    461524      }
    462525      re=re+line[p,l-1]+"\\"+newline;
    463       l=size(line); 
     526      l=size(line);
    464527      if( l>=size(s) ) break;
    465528      s=s[l+1,size(s)-l];
     
    494557
    495558proc writelist (string fil, string nam, list L)
    496 USAGE:   writelist(fil,nam,L);  fil,nam=strings (file name, list name), L=list
     559USAGE:   writelist(fil,nam,L);  fil,nam=strings (file-name, list-name), L=list
    497560CREATE:  a file with name `fil`, write the content of the list L into it and
    498561         call the list `nam`.
    499562RETURN:  no return value
    500 NOTE:    The syntax of writelist uses and is similar to the the syntax of the
     563NOTE:    The syntax of writelist uses and is similar to the syntax of the
    501564         write command of Singular which does not manage lists properly.
    502          If, say, (fil,nam) = ("listfile","L1"),  writelist creates (resp. 
    503          appends if listfile exists) a file with name listfile and stores 
    504          there the list L under the name L1. The Singular command 
    505          execute(read("listfile")); assignes the content of L (stored in 
     565         If, say, (fil,nam) = ("listfile","L1"),  writelist creates (resp.
     566         appends if listfile exists) a file with name listfile and stores
     567         there the list L under the name L1. The Singular command
     568         execute(read("listfile")); assignes the content of L (stored in
    506569         listfile) to a list L1.
    507          On a UNIX system, overwrite an existing file if fil=">...", resp. 
     570         On a UNIX system, overwrite an existing file if fil=">...", resp.
    508571         append if fil=">>...".
    509572EXAMPLE: example writelist; shows an example
    510573{
    511574   int i;
    512    write fil,"list "+nam+";";
     575   write(fil,"list "+nam+";");
    513576   if( fil[1]==">" ) { fil=fil[2..size(fil)]; }
    514577   if( fil[1]==">" ) { fil=fil[2..size(fil)]; }
    515    for( i=1;i<=size(L);i++ )
    516    {
    517      write fil,"   "+nam+"["+string(i)+"]=",string(L[i])+";";
     578   for( i=1;i<=size(L);i=i+1 )
     579   {
     580     write(fil,"   "+nam+"["+string(i)+"]=",string(L[i])+";");
    518581   }
    519582   return();
     
    529592   writelist("L","L",L);
    530593   read("L");
    531    // You might wish to remove the just created files `zumSpass` and `L`!
    532 }
    533 ///////////////////////////////////////////////////////////////////////////////
     594   system("sh","/bin/rm L zumSpass");
     595   // Under UNIX, this removes the files 'L' and 'zumSpass'
     596   // Type help system; to get more information about the shell escape
     597   // If your operating system does not accept the shell escape, you
     598   // have to remove the just created files 'zumSpass' and 'L' directly
     599}
     600///////////////////////////////////////////////////////////////////////////////
  • Singular/LIB/matrix.lib

    r6d09c56 r6f2edc  
    1 // $Id: matrix.lib,v 1.1.1.1 1997-04-25 15:13:26 obachman Exp $
    2 //(GMG+BM)
     1// $Id: matrix.lib,v 1.2 1997-04-28 19:27:22 obachman Exp $
     2// (GMG/BM, last modified 22.06.96)
    33///////////////////////////////////////////////////////////////////////////////
    4 LIBRARY:  matrix.lib    PROCEDURES FOR MATRIX OPERATIONS                         
     4LIBRARY:  matrix.lib    PROCEDURES FOR MATRIX OPERATIONS
    55
    66 compress(A);           matrix, zero columns from A deleted
     
    99 dsum(A1,A2,..);        matrix, direct sum of matrices A1,A2,...
    1010 flatten(A);            ideal, generated by entries of matrix A
     11 genericmat(n,m[,id]);  generic nxm matrix [entries from id]
    1112 is_complex(c);         1 if list c is a complex, 0 if not
    1213 outer(A,B);            matrix, outer product of matrices A and B
    1314 skewmat(n[,id]);       generic skew-symmetric nxn matrix [entries from id]
    14  submat(A,r,c);         submatrix of A with rows/cols specified by intvec r/c 
     15 submat(A,r,c);         submatrix of A with rows/cols specified by intvec r/c
    1516 symmat(n[,id]);        generic symmetric nxn matrix [entries from id]
    1617 tensor(A,B);           matrix, tensor product of matrices A nd B
     
    3233
    3334proc compress (A)
    34 USAGE:   compress(A); A matrix/intmat/ideal/module
    35 RETURN:  matrix/intmat/ideal/module, zero columns/generators from A deleted
     35USAGE:   compress(A); A matrix/ideal/module/intmat/intvec
     36RETURN:  same type, zero columns/generators from A deleted
     37         (in an intvec zero elements are deleted)
    3638EXAMPLE: example compress; shows an example
    3739{
    38    if( typeof(A)=="matrix" ) { return(matrix(simplify(A,2))); } 
    39    if( typeof(A)=="intmat" )
     40   if( typeof(A)=="matrix" ) { return(matrix(simplify(A,2))); }
     41   if( typeof(A)=="intmat" or typeof(A)=="intvec" )
    4042   {
    4143      ring r=0,x,lp;
    42       module m=module(matrix(A));
    43       int c= size(m);
    44       intmat B[nrows(A)][c];
     44      if( typeof(A)=="intvec" ) { intmat C=transpose(A); kill A; intmat A=C; }
     45      module m = matrix(A);
     46      intmat B[nrows(A)][size(m)];
    4547      int i,j;
    46       for( i=1; i<=ncols(A); i++ )
    47       { 
    48          if( m[i]!=[0] ) 
    49          { 
     48      for( i=1; i<=ncols(A); i=i+1 )
     49      {
     50         if( m[i]!=[0] )
     51         {
    5052            j=j+1;
    5153            B[1..nrows(A),j]=A[1..nrows(A),i];
    5254         }
    5355      }
     56      if( defined(C) ) { return(intvec(B)); }
    5457      return(B);
    5558    }
     
    6669   intmat B[3][4]=1,0,3,0,4,0,5,0,6,0,7,0;
    6770   compress(B);
     71   intvec C=0,0,1,2,0,3;
     72   compress(C);
    6873}
    6974////////////////////////////////////////////////////////////////////////////////
    7075proc concat (list #)
    71 USAGE:   concat(A1,A2,..); A1,A2,... matrices 
    72 RETURN:  matrix, concatenation of A1,A2,... . Number of rows of result matrix is 
     76USAGE:   concat(A1,A2,..); A1,A2,... matrices
     77RETURN:  matrix, concatenation of A1,A2,... . Number of rows of result matrix is
    7378         max(nrows(A1),nrows(A2),...)
    7479EXAMPLE: example concat; shows an example
     
    7681   int i;
    7782   module B=module(#[1]);
    78    for( i=2; i<=size(#); i++ ) { B=B,module(#[i]); }
     83   for( i=2; i<=size(#); i=i+1 ) { B=B,module(#[i]); }
    7984   return(matrix(B));
    8085}
     
    9297
    9398proc diag (list #)
    94 USAGE:   diag(p,n); p poly, n integer 
     99USAGE:   diag(p,n); p poly, n integer
    95100         diag(A);   A matrix
    96101RETURN:  diag(p,n): diagonal matrix, p times unitmatrix of size n
    97          diag(A)  : n*mxn*m diagonal matrix with entries all the entries of  the
     102         diag(A)  : n*mxn*m diagonal matrix with entries all the entries of the
    98103                    nxm matrix A, taken from the 1st row, 2nd row etc of A
    99104EXAMPLE: example diag; shows an example
     
    104109      int i; ideal id=#[1];
    105110      int n=ncols(id); matrix A[n][n];
    106       for( i=1; i<=n; i++ ) { A[i,i]=id[i]; }
     111      for( i=1; i<=n; i=i+1 ) { A[i,i]=id[i]; }
    107112   }
    108113   return(A);
     
    118123////////////////////////////////////////////////////////////////////////////////
    119124
    120 proc flatten (matrix A)
    121 USAGE:   flatten(A); A matrix
    122 RETURN:  ideal, generated by all entries from A
    123 EXAMPLE: example flatten; shows an example
    124 {
    125    return(ideal(A));
    126 }
    127 example
    128 { "EXAMPLE:"; echo = 2;
    129    ring r=0,(x,y,z),ds;
    130    matrix A[3][3]=1,2,3,x,y,z,7,8,9;
    131    print(A);
    132    flatten(A);
    133 }
    134 ////////////////////////////////////////////////////////////////////////////////
    135 
    136125proc dsum (list #)
    137 USAGE:   dsum(A1,A2,..); A1,A2,... matrices 
     126USAGE:   dsum(A1,A2,..); A1,A2,... matrices
    138127RETURN:  matrix, direct sum of A1,A2,...
    139128EXAMPLE: example dsum; shows an example
     
    141130   int i,N,a;
    142131   list L;
    143    for( i=1; i<=size(#); i++ ) { N=N+nrows(#[i]); }
    144    for( i=1; i<=size(#); i++ )
    145    { 
    146       matrix B[N][ncols(#[i])]; 
     132   for( i=1; i<=size(#); i=i+1 ) { N=N+nrows(#[i]); }
     133   for( i=1; i<=size(#); i=i+1 )
     134   {
     135      matrix B[N][ncols(#[i])];
    147136      B[a+1..a+nrows(#[i]),1..ncols(#[i])]=#[i];
    148137      a=a+nrows(#[i]);
     
    162151   print(dsum(A,B,C));
    163152}
     153////////////////////////////////////////////////////////////////////////////////
     154
     155proc flatten (matrix A)
     156USAGE:   flatten(A); A matrix
     157RETURN:  ideal, generated by all entries from A
     158EXAMPLE: example flatten; shows an example
     159{
     160   return(ideal(A));
     161}
     162example
     163{ "EXAMPLE:"; echo = 2;
     164   ring r=0,(x,y,z),ds;
     165   matrix A[3][3]=1,2,3,x,y,z,7,8,9;
     166   print(A);
     167   flatten(A);
     168}
     169////////////////////////////////////////////////////////////////////////////////
     170
     171proc genericmat (int n,int m,list #)
     172USAGE:   genericmat(n,m[,id]);  n,m=integers, id=ideal
     173RETURN:  nxm matrix, with entries from id (default: id=maxideal(1))
     174NOTE:    if id has less than nxm elements, the matrix is filled with 0's,
     175         genericmat(n,m); creates the generic nxm matrix
     176EXAMPLE: example genericmat; shows an example
     177{
     178   if( size(#)==0 ) { ideal id=maxideal(1); }
     179   if( size(#)==1 ) { ideal id=#[1]; }
     180   if( size(#)>=2 ) { "// give 3 arguments, 3-rd argument must be an ideal"; }
     181   matrix B[n][m]=id;
     182   return(B);
     183}
     184example
     185{ "EXAMPLE:"; echo = 2;
     186   ring R=0,x(1..16),lp;
     187   print(genericmat(4,4));    // the generic 4x4 matrix
     188   changevar("R1",A_Z("a",4),R);
     189   matrix A=genericmat(4,5,maxideal(1)^3);
     190   print(A);
     191   int n,m=4,3;
     192   ideal i = ideal(randommat(1,n*m,maxideal(1),9));
     193   print(genericmat(n,m,i));  // matrix of generic linear forms
     194   kill R1;
     195}
    164196///////////////////////////////////////////////////////////////////////////////
    165197
    166198proc is_complex (list c)
    167199USAGE:   is_complex(c); c = list of size-compatible modules or matrices
    168 RETURN:  1 if c[i]*c[i+1]=0 for all i, 0 if not. 
     200RETURN:  1 if c[i]*c[i+1]=0 for all i, 0 if not.
    169201NOTE:    Ideals are treated internally as 1-line matrices
    170202EXAMPLE: example is_complex; shows an example
     
    186218}
    187219example
    188 { "EXAMPLE:";   echo = 2; 
    189    ring r=32003,(x,y,z),ds; 
    190    ideal i=x4+y5+z6,xyz,yx2+xz2+zy7; 
     220{ "EXAMPLE:";   echo = 2;
     221   ring r=32003,(x,y,z),ds;
     222   ideal i=x4+y5+z6,xyz,yx2+xz2+zy7;
    191223   list L=res(i,0);
    192224   is_complex(L);
     
    202234{
    203235   int i,j; list L;
    204    int N=nrows(A)*nrows(B);
    205    matrix C[N][ncols(B)];
    206    for( i=1; i<=ncols(A); i++ )
    207    {
    208       for( j=1; j<=nrows(A); j++ )
    209       {
    210          C[(j-1)*nrows(B)+1..j*nrows(B),1..ncols(B)]=A[j,i]*B;
    211       }
    212       L[i]=C;
    213    }
    214    return(concat(L));
     236   int triv = nrows(B)*ncols(B);
     237   if( triv==1 )
     238   {
     239     return(B[1,1]*A);
     240   }
     241   else
     242   {
     243     int N = nrows(A)*nrows(B);
     244     matrix C[N][ncols(B)];
     245     for( i=1; i<=ncols(A); i=i+1 )
     246     {
     247       for( j=1; j<=nrows(A); j=j+1 )
     248       {
     249          C[(j-1)*nrows(B)+1..j*nrows(B),1..ncols(B)]=A[j,i]*B;
     250       }
     251       L[i]=C;
     252     }
     253     return(concat(L));
     254   }
    215255}
    216256example
     
    227267proc skewmat (int n, list #)
    228268USAGE:   skewmat(n[,id]);  n integer, id ideal
    229 RETURN:  skew-symmetric nxn matrix, with entries from id 
     269RETURN:  skew-symmetric nxn matrix, with entries from id
    230270         (default: id=maxideal(1))
    231271NOTE:    if id has less than n*(n-1)/2 elements, the matrix is filled with 0's,
     
    238278   id = id,B[1..n,1..n];
    239279   int i,j;
    240    for( i=0; i<=n-2; i++ )
    241    { 
    242       B[i+1,i+2..n]=id[j+1..j+n-i-1]; 
    243       j=j+n-i-1; 
     280   for( i=0; i<=n-2; i=i+1 )
     281   {
     282      B[i+1,i+2..n]=id[j+1..j+n-i-1];
     283      j=j+n-i-1;
    244284   }
    245285   matrix A=transpose(B);
     
    263303proc submat (matrix A, intvec r, intvec c)
    264304USAGE:   submat(A,r,c);  A=matrix, r,c=intvec
    265 RETURN:  matrix, submatrix of A with rows specified by intvec r and columns 
     305RETURN:  matrix, submatrix of A with rows specified by intvec r and columns
    266306         specified by intvec c
    267307EXAMPLE: example submat; shows an example
     
    293333   id = id,B[1..n,1..n];
    294334   int i,j;
    295    for( i=0; i<=n-1; i++ )
    296    { 
    297       B[i+1,i+1..n]=id[j+1..j+n-i]; 
    298       j=j+n-i; 
     335   for( i=0; i<=n-1; i=i+1 )
     336   {
     337      B[i+1,i+1..n]=id[j+1..j+n-i];
     338      j=j+n-i;
    299339   }
    300340   matrix A=transpose(B);
    301    for( i=1; i<=n; i++ ) {  A[i,i]=0; }
     341   for( i=1; i<=n; i=i+1 ) {  A[i,i]=0; }
    302342   B=A+B;
    303343   return(B);
     
    306346{ "EXAMPLE:"; echo = 2;
    307347   ring R=0,x(1..10),lp;
    308    print(symmat(4));    // the generic symmetric matrix 
     348   print(symmat(4));    // the generic symmetric matrix
    309349   changevar("R1",A_Z("a",5),R);
    310350   matrix A=symmat(5,maxideal(1)^2);
     
    324364   int i,j;
    325365   matrix C=B;
    326    for( i=2; i<=nrows(A); i++ ) { C=dsum(C,B); }
     366   for( i=2; i<=nrows(A); i=i+1 ) { C=dsum(C,B); }
    327367   matrix D[nrows(C)][ncols(A)*nrows(B)];
    328    for( j=1; j<=nrows(B); j++ )
    329    {
    330       for( i=1; i<=nrows(A); i++ )
     368   for( j=1; j<=nrows(B); j=j+1 )
     369   {
     370      for( i=1; i<=nrows(A); i=i+1 )
    331371      {
    332372         D[(i-1)*nrows(B)+j,(j-1)*ncols(A)+1..j*ncols(A)]=A[i,1..ncols(A)];
     
    362402///////////////////////////////////////////////////////////////////////////////
    363403
    364 proc gauss_col (matrix m)
     404proc gauss_col (matrix A)
    365405USAGE:   gauss_col(A); A=matrix with constant coefficients
    366 RETURN:  matrix = col-reduced normal form of A
     406RETURN:  matrix = col-reduced lower-triagonal normal form of A
     407NOTE:    the procedure sets the global option-command: option(noredSB);
    367408EXAMPLE: example gauss_col; shows an example
    368409{
    369410   def R=basering;
    370    changeord("@R","ds,c",R);   
     411   changeord("@R","ds,c",R);
    371412   option(redSB); option(nointStrategy);
    372    matrix m = imap(R,m);
    373    m = matrix(std(m),nrows(m),ncols(m));
    374    setring R;   
    375    m=imap(@R,m);
     413   matrix A = imap(R,A);
     414   A = matrix(std(A),nrows(A),ncols(A));
     415   setring R;
     416   A=imap(@R,A);
    376417   option(noredSB);
    377418   kill @R;
    378    return(m);
    379 
    380 example
    381 { "EXAMPLE:"; echo = 2;
    382    ring S;
    383    matrix M[3][4] = 1,3,2,4,2,6,4,8,1,3,4,4;
    384    print(M);
    385    print(gauss_col(M));
     419   return(A);
     420}
     421example
     422{ "EXAMPLE:"; echo = 2;
     423   ring S=0,x,dp;
     424   matrix A[5][4] =  3, 1,1,-1,
     425                    13, 8,6,-7,
     426                    14,10,6,-7,
     427                     7, 4,3,-3,
     428                     2, 1,0, 3;
     429   print(gauss_col(A));
    386430}
    387431///////////////////////////////////////////////////////////////////////////////
    388432
    389 proc gauss_row (matrix m)
     433proc gauss_row (matrix A)
    390434USAGE:   gauss_row(A); A=matrix with constant coefficients
    391 RETURN:  matrix = row-reduced normal form of A
     435RETURN:  matrix = row-reduced upper-triangular normal form of A
     436NOTE:    may be used to solve a system of linear equations
     437         see proc 'linearsolve' from 'solve.lib' for a different method
     438         the procedure sets the global option-command: option(noredSB);
    392439EXAMPLE: example gauss_row; shows an example
    393440{
    394    m = gauss_col(transpose(m));
    395    return(transpose(m));
    396 
    397 example
    398 { "EXAMPLE:"; echo = 2;
    399    ring S;
    400    matrix M[3][4] = 1,3,2,4,2,6,4,8,1,3,4,4;
    401    print(M);
    402    print(gauss_row(M));
     441   A = gauss_col(transpose(A));
     442   return(transpose(A));
     443}
     444example
     445{ "EXAMPLE:"; echo = 2;
     446   ring S=0,x,dp;
     447   matrix A[4][5] =  3, 1,1,-1,2,
     448                    13, 8,6,-7,1,
     449                    14,10,6,-7,1,
     450                     7, 4,3,-3,3;
     451   print(gauss_row(A));
    403452}
    404453////////////////////////////////////////////////////////////////////////////////
  • Singular/LIB/poly.lib

    r6d09c56 r6f2edc  
    1 // $Id: poly.lib,v 1.1.1.1 1997-04-25 15:13:26 obachman Exp $
     1// $Id: poly.lib,v 1.2 1997-04-28 19:27:22 obachman Exp $
    22//system("random",787422842);
    3 //(GMG)
    4 ///////////////////////////////////////////////////////////////////////////////
    5 
    6 LIBRARY:  poly.lib      PROCEDURES FOR MANIPULATING POLYS AND IDEALS       
    7 
    8  ishomog(poly/...);     int, =1 resp. =0 if input is homogeneous resp. not
    9  maxcoef(poly/...);     maximal length of coefficient occuring in poly/...
     3//(GMG, last modified 22.06.96)
     4///////////////////////////////////////////////////////////////////////////////
     5
     6LIBRARY:  poly.lib      PROCEDURES FOR MANIPULATING POLYS, IDEALS, MODULES
     7
     8 cyclic(int);           ideal of cyclic n-roots
     9 freerank(poly/...)     rank of coker(input) if coker is free else -1
     10 is_homog(poly/...);    int, =1 resp. =0 if input is homogeneous resp. not
     11 is_zero(poly/...);     int, =1 resp. =0 if coker(input) is 0 resp. not
     12 maxcoef(poly/...);     maximal length of coefficient occuring in poly/...
    1013 maxdeg(poly/...);      int/intmat = degree/s of terms of maximal order
     14 maxdeg1(poly/...);     int = [weighted] maximal degree of input
    1115 mindeg(poly/...);      int/intmat = degree/s of terms of minimal order
     16 mindeg1(poly/...);     int = [weighted] minimal degree of input
    1217 normalize(poly/...);   normalize poly/... such that leading coefficient is 1
    1318           (parameters in square brackets [] are optional)
     
    1621///////////////////////////////////////////////////////////////////////////////
    1722
    18 proc ishomog (id)
    19 USAGE:   ishomog(id);  id  poly/ideal/vector/module/matrix
     23proc cyclic (int n)
     24USAGE:   cyclic(n);  n integer
     25RETURN:  ideal of cyclic n-roots from 1-st n variables of basering
     26EXAMPLE: example cyclic; shows examples
     27{
     28//----------------------------- procedure body --------------------------------
     29   ideal m = maxideal(1);
     30   m = m[1..n],m[1..n];
     31   int i,j;
     32   ideal s; poly t;
     33   for ( j=0; j<=n-2; j=j+1 )
     34   {
     35      t=0;
     36      for( i=1;i<=n;i=i+1 ) { t=t+product(m,i..i+j); }
     37      s=s+t;
     38   }
     39   s=s,product(m,1..n)-1;
     40   return (s);
     41}
     42//-------------------------------- examples -----------------------------------
     43example
     44{ "EXAMPLE:"; echo = 2;
     45   ring r=0,(u,v,w,x,y,z),lp;
     46   cyclic(nvars(basering));
     47   homog(cyclic(5),z);
     48}
     49///////////////////////////////////////////////////////////////////////////////
     50
     51proc freerank
     52USAGE:   freerank(M[,any]);  M=poly/ideal/vector/module/matrix
     53COMPUTE: rank of module presented by M in case it is free. By definition this
     54         is vdim(coker(M)/m*coker(M)) if coker(M) is free, where m = maximal
     55         ideal of basering and M is considered as matrix (the 0-module is
     56         free of rank 0)
     57RETURN:  rank of coker(M) if coker(M) is free and -1 else;
     58         in case of a second argument return a list:
     59                L[1] = rank of coker(M) or -1
     60                L[2] = minbase(M)
     61NOTE:    freerank(syz(M)); computes the rank of M if M is free (and -1 else)
     62         //* Zur Zeit noch ein Bug, da erste Bettizahl falsch berechnet wird:
     63         //betti(0) ist -1 statt 0
     64EXAMPLE: example freerank; shows examples
     65{
     66  int rk;
     67  def M = simplify(#[1],10);
     68  list mre = mres(M,2);
     69  intmat B = betti(mre);
     70  if ( ncols(B)>1 ) { rk = -1; }
     71  else { rk = sum(B[1..nrows(B),1]); }
     72  if (size(#) == 2) { list L=rk,mre[1]; return(L);}
     73  return(rk);
     74}
     75example
     76{"EXAMPLE";   echo=2;
     77  ring r;
     78  ideal i=x;
     79  module M=[x,0,1],[-x,0,-1];
     80  freerank(M);           // should be -1, coker(M) is not free
     81                         // [1] should be 1, coker(syz(M))=M is free of rank 1
     82  freerank(syz (M),"");  // [2] should be gen(2)+gen(1) (minimal relation of M)
     83  freerank(i);
     84  freerank(syz(i));      //* bug, should be 1, coker(syz(i))=i is free of rank 1
     85}
     86///////////////////////////////////////////////////////////////////////////////
     87
     88proc is_homog (id)
     89USAGE:   is_homog(id);  id  poly/ideal/vector/module/matrix
    2090RETURN:  integer which is 1 if input is homogeneous (resp. weighted homogeneous
    2191         if the monomial ordering consists of one block of type ws,Ws,wp or Wp,
     
    2494         degree, a module/matrix is homogeneous if all column vectors are
    2595         homogeneous
    26          //*** ergaenzen, wenn Matrizen Spalten Gewichte haben
    27 EXAMPLE: example ishomog; shows an example
    28 {
     96         //*** ergaenzen, wenn Matrizen-Spalten Gewichte haben
     97EXAMPLE: example is_homog; shows examples
     98{
     99//----------------------------- procedure body --------------------------------
    29100   module M = module(matrix(id));
    30101   M = simplify(M,2);                        // remove 0-columns
    31102   intvec v = ringweights(basering);
    32103   int i,j=1,1;
    33    for (i=1; i<=ncols(M); i++)
     104   for (i=1; i<=ncols(M); i=i+1)
    34105   {
    35106      if( M[i]!=jet(M[i],deg(lead(M[i])),v)-jet(M[i],deg(lead(M[i]))-1,v))
     
    38109   return(1);
    39110}
     111//-------------------------------- examples -----------------------------------
    40112example
    41113{ "EXAMPLE:"; echo = 2;
    42114   ring r = 0,(x,y,z),wp(1,2,3);
    43    ishomog(x5-yz+y3);
     115   is_homog(x5-yz+y3);
    44116   ideal i = x6+y3+z2, x9-z3;
    45    ishomog(i);
     117   is_homog(i);
    46118   ring s = 0,(a,b,c),ds;
    47119   vector v = [a2,0,ac+bc];
    48120   vector w = [a3,b3,c4];
    49    ishomog(v);
    50    ishomog(w);
    51 }
    52 ///////////////////////////////////////////////////////////////////////////////
     121   is_homog(v);
     122   is_homog(w);
     123}
     124///////////////////////////////////////////////////////////////////////////////
     125
     126proc is_zero
     127USAGE:   is_zero(M[,any]); M=poly/ideal/vector/module/matrix
     128RETURN:  integer, 1 if coker(M)=0 resp. 0 if coker(M)!=0, where M is considered
     129         as matrix
     130         if a second argument is given, return a list:
     131                L[1] = 1 if coker(M)=0 resp. 0 if coker(M)!=0
     132                L[2] = dim(M)
     133EXAMPLE: example is_zero; shows examples
     134{
     135  int d=dim(std(#[1]));
     136  int a = ( d==-1 );
     137  if( size(#) >1 ) { list L=a,d; return(L); }
     138  return(a);
     139}
     140example
     141{ "EXAMPLE:";   echo=2;
     142  ring r;
     143  module m = [x],[y],[1,z];
     144  is_zero(m,1);
     145  qring q = std(ideal(x2+y3+z2));
     146  ideal j = x2+y3+z2-37;
     147  is_zero(j);
     148}
     149////////////////////////////////////////////////////////////////////////////////
    53150
    54151proc maxcoef (f)
    55152USAGE:   maxcoef(f);  f  poly/ideal/vector/module/matrix
    56 RETURN:  maximal length of coefficient of f of type int (by counting the 
     153RETURN:  maximal length of coefficient of f of type int (by counting the
    57154         length of the string of each coefficient)
    58 EXAMPLE: example maxcoef; shows an example
    59 {
     155EXAMPLE: example maxcoef; shows examples
     156{
     157//----------------------------- procedure body --------------------------------
    60158   int max,s,ii,jj; string t;
    61159   ideal i = ideal(matrix(f));
    62    i = simplify(i,6);         //* delete 0's and keep first of equal elements
     160   i = simplify(i,6);            // delete 0's and keep first of equal elements
    63161   poly m = var(1); matrix C;
    64    for (ii=2;ii<=nvars(basering);ii++) { m = m*var(ii); }
    65    for (ii=1; ii<=size(i); ii++)
     162   for (ii=2;ii<=nvars(basering);ii=ii+1) { m = m*var(ii); }
     163   for (ii=1; ii<=size(i); ii=ii+1)
    66164   {
    67165      C = coef(i[ii],m);
    68       for (jj=1; jj<=ncols(C); jj++)
     166      for (jj=1; jj<=ncols(C); jj=jj+1)
    69167      {
    70168         t = string(C[2,jj]);  s = size(t);
     
    75173   return(max);
    76174}
     175//-------------------------------- examples -----------------------------------
    77176example
    78177{ "EXAMPLE:"; echo = 2;
     
    80179   poly g = 345x2-1234567890y+7/4z;
    81180   maxcoef(g);
    82    ideal i = g,10/1234567890;   
    83    maxcoef(i); 
    84    // since i[2]=1/123456789 
    85 }
    86 ///////////////////////////////////////////////////////////////////////////////
    87 
    88 proc maxdeg (id) 
     181   ideal i = g,10/1234567890;
     182   maxcoef(i);
     183   // since i[2]=1/123456789
     184}
     185///////////////////////////////////////////////////////////////////////////////
     186
     187proc maxdeg (id)
    89188USAGE:   maxdeg(id);  id  poly/ideal/vector/module/matrix
    90 RETURN:  maximal degree/s of monomials of id independent of ring ordering
    91          (maxdeg of each variable is 1)
     189RETURN:  int/intmat, each component equals maximal degree of monomials in the
     190         corresponding component of id, independent of ring ordering
     191         (maxdeg of each var is 1)
    92192         of type int if id is of type poly, of type intmat else
    93 EXAMPLE: example maxdeg; shows an example
    94 {
    95 //------------------- find maximal degree of given component ------------------
     193NOTE:    proc maxdeg1 returns 1 integer, the absolut maximum; moreover, it has
     194         an option for computing weighted degrees
     195EXAMPLE: example maxdeg; shows examples
     196{
     197   //-------- subprocedure to find maximal degree of given component ----------
    96198   proc findmaxdeg
    97199   {
     
    117219   int r,c = nrows(M), ncols(M); int i,j;
    118220   intmat m[r][c];
    119    for (i=r; i>0; i--)
    120    {
    121       for (j=c; j>0; j--) { m[i,j] = findmaxdeg(M[i,j]); }
    122    }
    123    if( typeof(id)=="poly" ) { return(m[1,1]); }
     221   for (i=r; i>0; i=i-1)
     222   {
     223      for (j=c; j>0; j=j-1) { m[i,j] = findmaxdeg(M[i,j]); }
     224   }
     225   if (typeof(id)=="poly") { return(m[1,1]); }
    124226   return(m);
    125227}
     228//-------------------------------- examples -----------------------------------
    126229example
    127230{ "EXAMPLE:"; echo = 2;
    128231   ring r = 0,(x,y,z),wp(-1,-2,-3);
    129232   poly f = x+y2+z3;
    130    deg(f);               //deg returns weighted degree (in case of 1 block)!
     233   deg(f);               //deg; returns weighted degree (in case of 1 block)!
    131234   maxdeg(f);
    132235   matrix m[2][2]=f+x10,1,0,f^2;
     
    135238///////////////////////////////////////////////////////////////////////////////
    136239
     240proc maxdeg1 (id,list #)
     241USAGE:   maxdeg1(id[,v]);  id=poly/ideal/vector/module/matrix, v=intvec
     242RETURN:  integer, maximal [weighted] degree of monomials of id independent of
     243         ring ordering, maxdeg1 of i-th variable is v[i] (default: v=1..1).
     244NOTE:    This proc returns one integer while maxdeg returns, in general,
     245         a matrix of integers. For one polynomial and if no intvec v is given
     246         maxdeg is faster
     247EXAMPLE: example maxdeg1; shows examples
     248{
     249   //-------- subprocedure to find maximal degree of given component ----------
     250   proc findmaxdeg
     251   {
     252      poly c = #[1];
     253      if (c==0) { return(-1); }
     254      intvec v = #[2];
     255   //--- guess upper 'o' and lower 'u' bound, in case of negative weights -----
     256      int d = (deg(c)>=0)*deg(c)-(deg(c)<0)*deg(c);
     257      int i = d;
     258      if ( c == jet(c,-1,v))      //case: maxdeg is negative
     259      {
     260         i = -d;
     261         while ( c == jet(c,i,v) ) { i = 2*(i-1); }
     262         int o = (d != -i)*((i/ 2)+2) - 1;
     263         int u = i+1;
     264         int e = -1;
     265      }
     266      else                        //case: maxdeg is nonnegative
     267      {
     268         while ( c != jet(c,i,v) ) { i = 2*(i+1); }
     269         int o = i-1;
     270         int u = (d != i)*((i/ 2)-1);
     271         int e = 1;
     272      }
     273   //----------------------- "quick search" for maxdeg ------------------------
     274      while ( ( c==jet(c,i,v) )*( c!=jet(c,i-1,v) ) == 0 )
     275      {
     276         i = (o+e+u)/ 2;
     277         if ( c!=jet(c,i,v) ) { u = i+1; }
     278         else { o = i-1; }
     279      }
     280      return(i);
     281   }
     282//------------------------------ main program ---------------------------------
     283   ideal M = simplify(ideal(matrix(id)),8);   //delete scalar multiples from id
     284   int c = ncols(M);
     285   int i,n;
     286   if( size(#)==0 )
     287   {
     288      int m = maxdeg(M[c]);
     289      for (i=c-1; i>0; i=i-1)
     290      {
     291          n = maxdeg(M[i]);
     292          m = (m>=n)*m + (m<n)*n;             //let m be the maximum of m and n
     293      }
     294   }
     295   else
     296   {
     297      intvec v=#[1];                          //weight vector for the variables
     298      int m = findmaxdeg(M[c],v);
     299      for (i=c-1; i>0; i--)
     300      {
     301         n = findmaxdeg(M[i],v);
     302         if( n>m ) { m=n; }
     303      }
     304   }
     305   return(m);
     306}
     307//-------------------------------- examples -----------------------------------
     308example
     309{ "EXAMPLE:"; echo = 2;
     310   ring r = 0,(x,y,z),wp(-1,-2,-3);
     311   poly f = x+y2+z3;
     312   deg(f);                  //deg returns weighted degree (in case of 1 block)!
     313   maxdeg1(f);
     314   intvec v = ringweights(r);
     315   maxdeg1(f,v);                             //weighted maximal degree
     316   matrix m[2][2]=f+x10,1,0,f^2;
     317   maxdeg1(m,v);                             //absolut weighted maximal degree
     318}
     319///////////////////////////////////////////////////////////////////////////////
     320
    137321proc mindeg (id)
    138322USAGE:   mindeg(id);  id  poly/ideal/vector/module/matrix
    139 RETURN:  minimal degree/s of monomials of id independent of ring ordering
    140          (mindeg of each variable is 1)
    141          of type int if id is of type poly, of type intmat else
    142 EXAMPLE: example mindeg; shows an example
    143 {
    144 //------------------- find minimal degree of given component ------------------
     323RETURN:  minimal degree/s of monomials of id, independent of ring ordering
     324         (mindeg of each variable is 1) of type int if id of type poly, else
     325         of type intmat.
     326NOTE:    proc mindeg1 returns one integer, the absolut minimum; moreover it
     327         has an option for computing weighted degrees.
     328EXAMPLE: example mindeg; shows examples
     329{
     330   //--------- subprocedure to find minimal degree of given component ---------
    145331   proc findmindeg
    146332   {
     
    153339      int o = i-1;
    154340      int u = (d != i)*((i/ 2)-1);
    155 //----------------------- "quick search" for mindeg --------------------------
     341   //----------------------- "quick search" for mindeg ------------------------
    156342      while ( (jet(c,u)==0)*(jet(c,o)!=0) )
    157343      {
     
    167353   int r,c = nrows(M), ncols(M); int i,j;
    168354   intmat m[r][c];
    169    for (i=r; i>0; i--)
    170    {
    171       for (j=c; j>0; j--) { m[i,j] = findmindeg(M[i,j]); }
     355   for (i=r; i>0; i=i-1)
     356   {
     357      for (j=c; j>0; j=j-1) { m[i,j] = findmindeg(M[i,j]); }
    172358   }
    173359   if (typeof(id)=="poly") { return(m[1,1]); }
    174360   return(m);
    175361}
     362//-------------------------------- examples -----------------------------------
    176363example
    177364{ "EXAMPLE:"; echo = 2;
    178365   ring r = 0,(x,y,z),ls;
    179366   poly f = x5+y2+z3;
    180    ord(f);                // ord returns weighted order of leading term!         
    181    mindeg(f);
     367   ord(f);                      // ord returns weighted order of leading term!
     368   mindeg(f);                   // computes minimal degree
    182369   matrix m[2][2]=x10,1,0,f^2;
    183    mindeg(m);
     370   mindeg(m);                   // computes matrix of minimum degrees
     371}
     372///////////////////////////////////////////////////////////////////////////////
     373
     374proc mindeg1 (id, list #)
     375USAGE:   mindeg1(id[,v]);  id=poly/ideal/vector/module/matrix, v=intvec
     376RETURN:  integer, minimal [weighted] degree of monomials of id independent of
     377         ring ordering, mindeg1 of i-th variable is v[i] (default v=1..1).
     378NOTE:    This proc returns one integer while mindeg returns, in general,
     379         a matrix of integers. For one polynomial and if no intvec v is given
     380         mindeg is faster.
     381EXAMPLE: example mindeg1; shows examples
     382{
     383   //--------- subprocedure to find minimal degree of given component ---------
     384   proc findmindeg
     385   {
     386      poly c = #[1];
     387      intvec v = #[2];
     388      if (c==0) { return(-1); }
     389   //--- guess upper 'o' and lower 'u' bound, in case of negative weights -----
     390      int d = (ord(c)>=0)*ord(c)-(ord(c)<0)*ord(c);
     391      int i = d;
     392      if ( jet(c,-1,v) !=0 )      //case: mindeg is negative
     393      {
     394         i = -d;
     395         while ( jet(c,i,v) != 0 ) { i = 2*(i-1); }
     396         int o = (d != -i)*((i/ 2)+2) - 1;
     397         int u = i+1;
     398         int e = -1; i=u;
     399      }
     400      else                        //case: inded is nonnegative
     401      {
     402         while ( jet(c,i,v) == 0 ) { i = 2*(i+1); }
     403         int o = i-1;
     404         int u = (d != i)*((i/ 2)-1);
     405         int e = 1; i=u;
     406      }
     407   //----------------------- "quick search" for mindeg ------------------------
     408      while ( (jet(c,i-1,v)==0)*(jet(c,i,v)!=0) == 0 )
     409      {
     410         i = (o+e+u)/ 2;
     411         if (jet(c,i,v)==0) { u = i+1; }
     412         else { o = i-1; }
     413      }
     414      return(i);
     415   }
     416//------------------------------ main program ---------------------------------
     417   ideal M = simplify(ideal(matrix(id)),8);   //delete scalar multiples from id
     418   int c = ncols(M);
     419   int i,n;
     420   if( size(#)==0 )
     421   {
     422      int m = mindeg(M[c]);
     423      for (i=c-1; i>0; i=i-1)
     424      {
     425          n = mindeg(M[i]);
     426          m = (m<=n)*m + (m>n)*n;             //let m be the maximum of m and n
     427      }
     428   }
     429   else
     430   {
     431      intvec v=#[1];                          //weight vector for the variables
     432      int m = findmindeg(M[c],v);
     433      for (i=c-1; i>0; i=i-1)
     434      {
     435         n = findmindeg(M[i],v);
     436         m = (m<=n)*m + (m>n)*n;              //let m be the maximum of m and n
     437      }
     438   }
     439   return(m);
     440}
     441//-------------------------------- examples -----------------------------------
     442example
     443{ "EXAMPLE:"; echo = 2;
     444   ring r = 0,(x,y,z),ls;
     445   poly f = x5+y2+z3;
     446   ord(f);                      // ord returns weighted order of leading term!
     447   intvec v = 1,-3,2;
     448   mindeg1(f,v);                // computes minimal weighted degree
     449   matrix m[2][2]=x10,1,0,f^2;
     450   mindeg1(m,1..3);             // computes absolut minimum of weighted degrees
    184451}
    185452///////////////////////////////////////////////////////////////////////////////
     
    189456RETURN:  object of same type with leading coefficient equal to 1
    190457EXAMPLE: example normalize; shows an example
    191 { 
     458{
    192459   return(simplify(id,1));
    193460}
     461//-------------------------------- examples -----------------------------------
    194462example
    195463{  "EXAMPLE:"; echo = 2;
     
    202470   module m=[9xy,0,3z3],[4z,6y,2x];
    203471   normalize(m);
    204    normalize(matrix(m));  // by automatic type conversion to module!
    205 }
    206 ///////////////////////////////////////////////////////////////////////////////
     472   normalize(matrix(m));             // by automatic type conversion to module!
     473}
     474///////////////////////////////////////////////////////////////////////////////
     475
  • Singular/LIB/random.lib

    r6d09c56 r6f2edc  
    1 // $Id: random.lib,v 1.1.1.1 1997-04-25 15:13:26 obachman Exp $
     1// $Id: random.lib,v 1.2 1997-04-28 19:27:23 obachman Exp $
    22//system("random",787422842);
    3 //(GMG+BM)
     3//(GMG/BM, last modified 22.06.96)
    44///////////////////////////////////////////////////////////////////////////////
    55
     
    2020
    2121proc genericid (id, list #)
    22 USAGE:   genericid(id,[,p,b]);  id ideal/module, p,b integers
    23 RETURN:  system of generators of id which are generic, sparse, trigonal linear
     22USAGE:   genericid(id,[,p,b]);  id ideal/module, k,p,b integers
     23RETURN:  system of generators of id which are generic, sparse, triagonal linear
    2424         combinations of given generators with coefficients in [1,b] and
    2525         sparsety p percent, bigger p being sparser (default: p=75, b=30000)
     
    3232   if( size(#)==0 ) { int p=75; int b=30000; }
    3333//---------------- use sparsetriag for creation of genericid ------------------
    34    def i = simplify(id,10);                         
     34   def i = simplify(id,10);
    3535   i = i*sparsetriag(ncols(i),ncols(i),p,b);
    3636   return(i);
    37 }               
    38 example
    39 { "EXAMPLE:"; echo = 2;
    40    ring r=0,(t,x,y,z),ds; 
    41    ideal i= x3+y4,z4+yx,t+x+y+z;         
    42    genericid(i,0,10);         
    43    module m=[x,0,0,0],[0,y2,0,0],[0,0,z3,0],[0,0,0,t4]; 
     37}
     38example
     39{ "EXAMPLE:"; echo = 2;
     40   ring r=0,(t,x,y,z),ds;
     41   ideal i= x3+y4,z4+yx,t+x+y+z;
     42   genericid(i,0,10);
     43   module m=[x,0,0,0],[0,y2,0,0],[0,0,z3,0],[0,0,0,t4];
    4444   print(genericid(m));
    4545}
     
    5959   if( size(#)==0 ) { int k=size(id); int b=30000; }
    6060//--------------------------- create randomid ---------------------------------
    61    def i = id;                         
     61   def i = id;
    6262   i = matrix(id)*random(b,ncols(id),k);
    6363   return(i);
    64 }               
    65 example
    66 { "EXAMPLE:"; echo = 2;
    67    ring r=0,(x,y,z),dp;           
    68    randomid(maxideal(2),2,9);         
    69    module m=[x,0,1],[0,y2,0],[y,0,z3]; 
     64}
     65example
     66{ "EXAMPLE:"; echo = 2;
     67   ring r=0,(x,y,z),dp;
     68   randomid(maxideal(2),2,9);
     69   module m=[x,0,1],[0,y2,0],[y,0,z3];
    7070   show(randomid(m));
    7171}
     
    8888   int g=ncols(id);
    8989   matrix rand[n][m]; matrix ra[1][m];
    90    for (int k=1; k<=n; k++)
     90   for (int k=1; k<=n; k=k+1)
    9191   {
    9292      ra = id*random(b,g,m);
     
    102102   A=randommat(2,3);
    103103   print(A);
    104 }               
     104}
    105105///////////////////////////////////////////////////////////////////////////////
    106106
    107107proc sparseid (int k, int u, list #)
    108108USAGE:   sparseid(k,u[,o,p,b]);  k,u,o,p,b integers
    109 RETURN:  ideal having k generators in each degree d, u<=d<=o, p percent of 
    110          terms in degree d are 0, the remaining have random coefficients 
     109RETURN:  ideal having k generators in each degree d, u<=d<=o, p percent of
     110         terms in degree d are 0, the remaining have random coefficients
    111111         in the interval [1,b], (default: o=u=d, p=75, b=30000)
    112112EXAMPLE: example sparseid; shows an example
     
    119119//------------------ use sparsemat for creation of sparseid -------------------
    120120   int ii; ideal i; intmat m;
    121    for ( ii=u; ii<=o; ii++)
    122    { 
     121   for ( ii=u; ii<=o; ii=ii+1)
     122   {
    123123       m = sparsemat(size(maxideal(ii)),k,p,b);
    124124       i = i+ideal(matrix(maxideal(ii))*m);
     
    131131   sparseid(3,4);"";
    132132   sparseid(2,2,5,90,9);
    133 }               
     133}
    134134///////////////////////////////////////////////////////////////////////////////
    135135
     
    153153   if( p<40 )
    154154   {
    155       for( ii=1; ii<=t; ii++ )
     155      for( ii=1; ii<=t; ii=ii+1 )
    156156      { r=( random(1,100)>p ); v[1,ii]=r*random(1,b); h=h+r; }
    157157   }
     
    173173example
    174174{ "EXAMPLE:"; echo = 2;
    175    sparsemat(5,5);
    176    sparsemat(5,5,95);
    177    sparsemat(5,5,5);
     175   sparsemat(5,5);"";
     176   sparsemat(5,5,95);"";
     177   sparsemat(5,5,5);"";
    178178   sparsemat(5,5,50,100);
    179 }               
     179}
    180180///////////////////////////////////////////////////////////////////////////////
    181181
     
    183183USAGE:   sparsepoly(u[,o,p,b]);  u,o,p,b integers
    184184RETURN:  poly having only terms in degree d, u<=d<=o, p percent of the terms
    185          in degree d are 0, the remaining have random coefficients in [1,b), 
     185         in degree d are 0, the remaining have random coefficients in [1,b),
    186186         (defaults: o=u=d, p=75, b=30000)
    187187EXAMPLE:  example sparsepoly; shows an example
     
    194194   int ii; poly f;
    195195//----------------- use sparseid for creation of sparsepoly -------------------
    196    for( ii=u; ii<=o; ii++ ) { f=f+sparseid(1,ii,ii,p,b)[1]; }
     196   for( ii=u; ii<=o; ii=ii+1 ) { f=f+sparseid(1,ii,ii,p,b)[1]; }
    197197   return(f);
    198198}
     
    202202   sparsepoly(5);"";
    203203   sparsepoly(3,5,90,9);
    204 }               
     204}
    205205///////////////////////////////////////////////////////////////////////////////
    206206
     
    222222   if( n<=m ) { min=n-1; M[n,n]=1; }
    223223   else { min=m; }
    224    for( ii=1; ii<=min; ii++ )
     224   for( ii=1; ii<=min; ii=ii+1 )
    225225   {
    226226      l=r+1; r=r+n-ii;
     
    231231example
    232232{ "EXAMPLE:"; echo = 2;
    233    sparsetriag(5,7);
    234    sparsetriag(7,5,90);
    235    sparsetriag(5,5,0);
     233   sparsetriag(5,7);"";
     234   sparsetriag(7,5,90);"";
     235   sparsetriag(5,5,0);"";
    236236   sparsetriag(5,5,50,100);
    237 }               
    238 ///////////////////////////////////////////////////////////////////////////////
     237}
     238///////////////////////////////////////////////////////////////////////////////
  • Singular/LIB/redfac.lib

    r6d09c56 r6f2edc  
    1 // $Id: redfac.lib,v 1.1.1.1 1997-04-25 15:13:26 obachman Exp $
     1// $Id: redfac.lib,v 1.2 1997-04-28 19:27:24 obachman Exp $
    22//(RS)
    33///////////////////////////////////////////////////////////////////////////////
  • Singular/LIB/ring.lib

    r6d09c56 r6f2edc  
    1 // $Id: ring.lib,v 1.1.1.1 1997-04-25 15:13:27 obachman Exp $
    2 //(GMG, 95/11/3)
    3 ///////////////////////////////////////////////////////////////////////////////
    4 
    5 LIBRARY:  ring.lib      PROCEDURES FOR MANIPULATING RINGS AND MAPS       
     1// $Id: ring.lib,v 1.2 1997-04-28 19:27:25 obachman Exp $
     2//(GMG, last modified 03.11.95)
     3///////////////////////////////////////////////////////////////////////////////
     4
     5LIBRARY:  ring.lib      PROCEDURES FOR MANIPULATING RINGS AND MAPS
    66
    77 changechar("R",c[,r]); make a copy R of basering [ring r] with new char c
     
    2525USAGE:   changechar(newr,c[,r]);  newr,c=strings, r=ring
    2626CREATE:  create a new ring with name `newr` and make it the basering if r is
    27          an existing ring [default: r=basering]. 
     27         an existing ring [default: r=basering].
    2828         The new ring differs from the old ring only in the characteristic.
    29          If, say, (newr,c) = ("R","0,A") and the ring r exists, the new 
     29         If, say, (newr,c) = ("R","0,A") and the ring r exists, the new
    3030         basering will have name R characteristic 0 and one parameter A.
    3131RETURN:  No return value
    3232NOTE:    Works for qrings if map from old_char to new_char is implemented
    33          This proc uses 'execute' or calls a procedure using 'execute'. 
    34          If you use it in your own proc, let the local names of your proc 
     33         This proc uses 'execute' or calls a procedure using 'execute'.
     34         If you use it in your own proc, let the local names of your proc
    3535         start with @ (see the file HelpForProc)
    3636EXAMPLE: example changechar; shows an example
     
    4040   setring @r;
    4141   ideal i = ideal(@r); int @q = size(i);
    42    if( @q!=0 ) 
     42   if( @q!=0 )
    4343      { string @s = "@newr1"; }
    44    else 
     44   else
    4545      { string @s = newr; }
    4646   string @newring = @s+"=("+c+"),("+varstr(@r)+"),("+ordstr(@r)+");";
     
    5151      ideal i = phi(i);
    5252      attrib(i,"isSB",1);         //*** attrib funktioniert ?
    53       execute("qring "+newr+"=i;");   
     53      execute("qring "+newr+"=i;");
    5454   }
    5555   export(`newr`);
     
    7070USAGE:   changeord(newr,o[,r]);  newr,o=strings, r=ring/qring
    7171CREATE:  create a new ring with name `newr` and make it the basering if r is
    72          an existing ring/qring [default: r=basering]. 
     72         an existing ring/qring [default: r=basering].
    7373         The new ring differs from the old ring only in the ordering. If, say,
    74          (newr,o) = ("R","wp(2,3),dp") and the ring r exists and has >=3 
     74         (newr,o) = ("R","wp(2,3),dp") and the ring r exists and has >=3
    7575         variables, the new basering will have name R and ordering wp(2,3),dp.
    7676RETURN:  No return value
    77 NOTE:    This proc uses 'execute' or calls a procedure using 'execute'. 
    78          If you use it in your own proc, let the local names of your proc 
     77NOTE:    This proc uses 'execute' or calls a procedure using 'execute'.
     78         If you use it in your own proc, let the local names of your proc
    7979         start with @ (see the file HelpForProc)
    8080EXAMPLE: example changeord; shows an example
     
    8484   setring @r;
    8585   ideal i = ideal(@r); int @q = size(i);
    86    if( @q!=0 ) 
     86   if( @q!=0 )
    8787      { string @s = "@newr1"; }
    88    else 
     88   else
    8989      { string @s = newr; }
    9090   string @newring = @s+"=("+charstr(@r)+"),("+varstr(@r)+"),("+o+");";
     
    9595      ideal i = phi(i);
    9696      attrib(i,"isSB",1);         //*** attrib funktioniert ?
    97       execute("qring "+newr+"=i;");   
     97      execute("qring "+newr+"=i;");
    9898   }
    9999   export(`newr`);
     
    116116USAGE:   changevar(newr,vars[,r]);  newr,vars=strings, r=ring/qring
    117117CREATE:  creates a new ring with name `newr` and makes it the basering if r
    118          is an existing ring/qring [default: r=basering]. 
     118         is an existing ring/qring [default: r=basering].
    119119         The new ring differs from the old ring only in the variables. If,
    120          say, (newr,vars) = ("R","t()") and the ring r exists and has n 
    121          variables, the new basering will have name R and variables 
     120         say, (newr,vars) = ("R","t()") and the ring r exists and has n
     121         variables, the new basering will have name R and variables
    122122         t(1),...,t(n).
    123          If vars = "a,b,c,d", the new ring will have the variables a,b,c,d. 
     123         If vars = "a,b,c,d", the new ring will have the variables a,b,c,d.
    124124RETURN:  No return value
    125125NOTE:    This procedure is useful in connection with the procedure ringtensor,
    126126         when a conflict between variable names must be avoided.
    127          This proc uses 'execute' or calls a procedure using 'execute'. 
    128          If you use it in your own proc, let the local names of your proc 
     127         This proc uses 'execute' or calls a procedure using 'execute'.
     128         If you use it in your own proc, let the local names of your proc
    129129         start with @ (see the file HelpForProc)
    130130EXAMPLE: example changevar; shows an example
     
    134134   setring @r;
    135135   ideal i = ideal(@r); int @q = size(i);
    136    if( @q!=0 ) 
     136   if( @q!=0 )
    137137      { string @s = "@newr1"; }
    138    else 
     138   else
    139139      { string @s = newr; }
    140140   string @newring = @s+"=("+charstr(@r)+"),(";
    141141   if( vars[size(vars)-1]=="(" and vars[size(vars)]==")" )
    142    { 
    143       @newring = @newring+vars[1,size(vars)-2]+"(1.."+string(nvars(@r))+")"; 
     142   {
     143      @newring = @newring+vars[1,size(vars)-2]+"(1.."+string(nvars(@r))+")";
    144144   }
    145145   else { @newring = @newring+vars; }
     
    151151      ideal i = phi(i);
    152152      attrib(i,"isSB",1);         //*** attrib funktioniert ?
    153       execute("qring "+newr+"=i;");   
     153      execute("qring "+newr+"=i;");
    154154   }
    155155   export(`newr`);
     
    174174CREATE:  Define a ring with name 's1', characteristic 's2', ordering 's4' and
    175175         n variables with names derived from s3 and make it the basering.
    176          If s3 is a single letter, say s3="a", and if n<=26 then a and the 
    177          following n-1 letters from the alphabeth (cyclic order) are taken as 
    178          variables. If n>26 or if s3 is a single letter followed by (, say 
    179          s3="T(", the variables are T(1),...,T(n). 
     176         If s3 is a single letter, say s3="a", and if n<=26 then a and the
     177         following n-1 letters from the alphabeth (cyclic order) are taken as
     178         variables. If n>26 or if s3 is a single letter followed by (, say
     179         s3="T(", the variables are T(1),...,T(n).
    180180RETURN:  No return value
    181181NOTE:    This proc is useful for defining a ring in a procedure.
    182          This proc uses 'execute' or calls a procedure using 'execute'. 
    183          If you use it in your own proc, let the local names of your proc 
     182         This proc uses 'execute' or calls a procedure using 'execute'.
     183         If you use it in your own proc, let the local names of your proc
    184184         start with @ (see the file HelpForProc)
    185185EXAMPLE: example defring; shows an example
     
    258258   execute("keepring P"+string(n)+";");
    259259   //the next comment is only shown if defringp is not called by another proc
    260    if (voice==2) { "// basering is now:",s; }   
    261 }   
     260   if (voice==2) { "// basering is now:",s; }
     261}
    262262example
    263263{ "EXAMPLE:"; echo = 2;
     
    269269
    270270proc extendring (string na, int n, string va, string o, list #)
    271 USAGE:   extendring(na,n,va,o[iv,i,r]);  na,va,o=strings, 
     271USAGE:   extendring(na,n,va,o[iv,i,r]);  na,va,o=strings,
    272272         n,i=integers, r=ring, iv=intvec of positive integers or iv=0
    273273CREATE:  Define a ring with name `na` which extends the ring r by adding n new
     
    275275         the basering [default: (i,r)=(0,basering)]
    276276         -- The characteristic is the characteristic of r
    277          -- The new vars are derived from va. If va is a single letter, say 
    278             va="T", and if n<=26 then T and the following n-1 letters from 
    279             T..Z..T (resp. T(1..n) if n>26) are taken as additional variables. 
    280             If va is a single letter followed by (, say va="x(", the new 
     277         -- The new vars are derived from va. If va is a single letter, say
     278            va="T", and if n<=26 then T and the following n-1 letters from
     279            T..Z..T (resp. T(1..n) if n>26) are taken as additional variables.
     280            If va is a single letter followed by (, say va="x(", the new
    281281            variables are x(1),...,x(n)
    282282         -- The ordering is the product ordering between the ordering of r and
    283283            an ordering derived from `o` [and iv]
    284          -  If o contains a 'c' or a 'C' in front resp. at the end this is 
     284         -  If o contains a 'c' or a 'C' in front resp. at the end this is
    285285            taken for the whole ordering in front resp. at the end. If o does
    286286            not contain a 'c' or a 'C' the same rule applies to ordstr(r).
    287287         -  If no intvec iv is given, or if iv=0, o may be any allowed ordstr,
    288288            like "ds" or "dp(2),wp(1,2,3),Ds(2)" or "ds(a),dp(b),ls" if a and b
    289             are globally (!) defined integers and if a+b+1<=n 
    290             If, however, a and b are local to a proc calling extendring, the 
    291             intvec iv must be used to let extendring know the values of a and b 
     289            are globally (!) defined integers and if a+b+1<=n
     290            If, however, a and b are local to a proc calling extendring, the
     291            intvec iv must be used to let extendring know the values of a and b
    292292         -  If an intvec iv !=0 is given, iv[1],iv[2],... is taken for the 1st,
    293             2nd,... block of o, if o contains no substring "w" or "W" i.e. no 
    294             weighted ordering (in the above case o="ds,dp,ls" and iv=a,b). 
    295             If o contains a weighted ordering (only one (!) weighted block is 
    296             allowed) iv[1] is taken as size for the weight-vector, the next 
     293            2nd,... block of o, if o contains no substring "w" or "W" i.e. no
     294            weighted ordering (in the above case o="ds,dp,ls" and iv=a,b).
     295            If o contains a weighted ordering (only one (!) weighted block is
     296            allowed) iv[1] is taken as size for the weight-vector, the next
    297297            iv[1] values of iv are taken as weights and the remaining values of
    298             iv as block-size for the remaining non-weighted blocks. 
    299             e.g. o="dp,ws,Dp,ds", iv=3,2,3,4,2,5 creates the ordering 
     298            iv as block-size for the remaining non-weighted blocks.
     299            e.g. o="dp,ws,Dp,ds", iv=3,2,3,4,2,5 creates the ordering
    300300            dp(2),ws(2,3,4),Dp(5),ds
    301301RETURN:  No return value
    302302NOTE:    This proc is useful for adding deformation parameters.
    303          This proc uses 'execute' or calls a procedure using 'execute'. 
    304          If you use it in your own proc, let the local names of your proc 
     303         This proc uses 'execute' or calls a procedure using 'execute'.
     304         If you use it in your own proc, let the local names of your proc
    305305         start with @ (see the file HelpForProc)
    306306EXAMPLE: example extendring; shows an example
    307307{
    308308//--------------- initialization and place c/C of ordering properly -----------
    309    string @o1,@o2,@ro,@wstr,@v,@newring; 
     309   string @o1,@o2,@ro,@wstr,@v,@newring;
    310310   int @i,@w,@ii,@k;
    311311   intvec @iv,@iw;
     
    331331   }
    332332   @ro=ordstr(@r);
    333    if( @ro[1]=="c" or @ro[1]=="C" ) 
     333   if( @ro[1]=="c" or @ro[1]=="C" )
    334334      { @v=@ro[1,2]; @ro=@ro[3..size(@ro)]; }
    335    else                         
     335   else
    336336      { @wstr=@ro[size(@ro)-1,2]; @ro=@ro[1..size(@ro)-2]; }
    337337   if( @k==0) { @o1=@v; @o2=@wstr; }
     
    341341      @k=n;                               //@k counts no of vars not yet ordered
    342342      @w=find(o,"w")+find(o,"W");o=o+" ";
    343       if( @w!=0 ) 
    344       { 
    345          @wstr=o[@w..@w+1]; 
     343      if( @w!=0 )
     344      {
     345         @wstr=o[@w..@w+1];
    346346         o=o[1,@w-1]+"@"+o[@w+2,size(o)];
    347347         @iw=@iv[2..@iv[1]+1];
    348348         @wstr=@wstr+"("+string(@iw)+")";
    349          @k=@k-@iv[1];                     
     349         @k=@k-@iv[1];
    350350         @iv=@iv[@iv[1]+2..size(@iv)];
    351351         @w=0;
    352352      }
    353       for( @ii=1; @ii<=size(@iv); @ii++ )
     353      for( @ii=1; @ii<=size(@iv); @ii=@ii+1 )
    354354      {
    355355         if( find(o,",",@w+1)!=0 )
     
    357357            @w=find(o,",",@w+1);
    358358            if( o[@w-1]!="@" )
    359             { 
    360                o=o[1,@w-1]+"("+string(@iv[@ii])+")"+o[@w,size(o)]; 
     359            {
     360               o=o[1,@w-1]+"("+string(@iv[@ii])+")"+o[@w,size(o)];
    361361               @w=find(o,",",@w+1);
    362362               @k=@k-@iv[@ii];
     
    373373   if( n>26 or va[2]=="(" ) { @v = va[1]+"(1.."+string(n)+")"; }
    374374   else                     { @v = A_Z(va,n); }
    375    if( @i==0 ) 
    376    { 
    377       @v=@v+","+varstr(@r); 
    378       o=@o1+o+","+@ro+@o2; 
    379    }
    380    else 
    381    { 
    382       @v=varstr(@r)+","+@v; 
    383       o=@o1+@ro+","+o+@o2; 
     375   if( @i==0 )
     376   {
     377      @v=@v+","+varstr(@r);
     378      o=@o1+o+","+@ro+@o2;
     379   }
     380   else
     381   {
     382      @v=varstr(@r)+","+@v;
     383      o=@o1+@ro+","+o+@o2;
    384384   }
    385385   @newring=@newring+@v+"),("+o+");";
     
    394394{ "EXAMPLE:"; echo = 2;
    395395   ring r=0,(x,y,z),ds;
    396    show(r);"";       
     396   show(r);"";
    397397   //no intvec given, no blocksize given: blocksize is derived from no of vars
    398    int t=5; 
     398   int t=5;
    399399   extendring("R1",t,"a","dp");         //t global: "dp" -> "dp(5)"
    400400   show(R1); "";
     
    411411   //the remaining variables, if intvec has too many components, the last
    412412   //ones are ignored
    413    intvec v=3,2,3,4,1,3;           
    414    extendring("R4",10,"A","ds,ws,Dp,dp",v,0,r); 
    415          //v covers 3 blocks: v[1] (=3) : no of components of ws   
     413   intvec v=3,2,3,4,1,3;
     414   extendring("R4",10,"A","ds,ws,Dp,dp",v,0,r);
     415         //v covers 3 blocks: v[1] (=3) : no of components of ws
    416416         //next v[1] values (=v[2..4]) give weights
    417417         //remaining components of v are used for the remaining blocks
     
    421421///////////////////////////////////////////////////////////////////////////////
    422422
    423 proc fetchall (R, list #) 
     423proc fetchall (R, list #)
    424424USAGE:   fetchall(R[,s]);  R=ring/qring, s=string
    425425CREATE:  fetch all objects of ring R (of type poly/ideal/vector/module/number/
     
    427427         If no 3rd argument is present, the names are the same as in R. If,
    428428         say, f is a poly in R and the 3rd argument is the string "R", then f
    429          is maped to f_R etc. 
     429         is maped to f_R etc.
    430430RETURN:  no return value
    431431NOTE:    As fetch, this procedure maps the 1st, 2nd, ... variable of R to the
    432          1st, 2nd, ... variable of the basering. 
     432         1st, 2nd, ... variable of the basering.
    433433         The 3rd argument is useful in order to avoid conflicts of names, the
    434434         empty string is allowed
    435435CAUTION: fetchall does not work inside a procedure
    436          //***at the moment it does not work if R contains a map 
     436         //***at the moment it does not work if R contains a map
    437437EXAMPLE: example fetchall; shows an example
    438 { 
     438{
    439439   list @L@=names(R);
    440440   int @ii@; string @s@;
    441441   if( size(#) > 0 ) { @s@=@s@+"_"+#[1]; }
    442    for( @ii@=size(@L@); @ii@>0; @ii@-- )
    443    { 
     442   for( @ii@=size(@L@); @ii@>0; @ii@=@ii@-1 )
     443   {
    444444      execute("def "+@L@[@ii@]+@s@+"=fetch(R,`@L@[@ii@]`);");
    445445      execute("export "+@L@[@ii@]+@s@+";");
     
    465465///////////////////////////////////////////////////////////////////////////////
    466466
    467 proc imapall (R, list #) 
     467proc imapall (R, list #)
    468468USAGE:   imapall(R[,s]);  R=ring/qring, s=string
    469469CREATE:  map all objects of ring R (of type poly/ideal/vector/module/number/
     
    471471         If no 3rd argument is present, the names are the same as in R. If,
    472472         say, f is a poly in R and the 3rd argument is the string "R", then f
    473          is maped to f_R etc. 
     473         is maped to f_R etc.
    474474RETURN:  no return value
    475475NOTE:    As imap, this procedure maps the variables of R to the variables with
     
    478478         empty string is allowed
    479479CAUTION: imapall does not work inside a procedure
    480          //***at the moment it does not work if R contains a map 
     480         //***at the moment it does not work if R contains a map
    481481EXAMPLE: example imapall; shows an example
    482 { 
     482{
    483483   list @L@=names(R);
    484484   int @ii@; string @s@;
    485485   if( size(#) > 0 ) { @s@=@s@+"_"+#[1]; }
    486    for( @ii@=size(@L@); @ii@>0; @ii@-- )
    487    { 
     486   for( @ii@=size(@L@); @ii@>0; @ii@=@ii@-1 )
     487   {
    488488         execute("def "+@L@[@ii@]+@s@+"=imap(R,`@L@[@ii@]`);");
    489489         execute("export "+@L@[@ii@]+@s@+";");
     
    509509///////////////////////////////////////////////////////////////////////////////
    510510
    511 proc mapall (R, ideal i, list #) 
     511proc mapall (R, ideal i, list #)
    512512USAGE:   mapall(R,i[,s]);  R=ring/qring, i=ideal of basering, s=string
    513 CREATE:  map all objects of ring R (of type poly/ideal/vector/module/number/ 
     513CREATE:  map all objects of ring R (of type poly/ideal/vector/module/number/
    514514         matrix, map) into the basering, by mapping the jth variable of R to
    515515         the jth generator of the ideal i. If no 3rd argument is present, the
    516          names are the same as in R. If, say, f is a poly in R and the 3rd 
    517          argument is the string "R", then f is maped to f_R etc. 
     516         names are the same as in R. If, say, f is a poly in R and the 3rd
     517         argument is the string "R", then f is maped to f_R etc.
    518518RETURN:  no return value
    519519NOTE:    This procedure has the same effect as defining a map, say psi, by
    520520         map psi=R,i; and then applying psi to all objects of R. In particular,
    521521         maps from R to some ring S are composed with psi, creating thus a map
    522          from the basering to S. 
     522         from the basering to S.
    523523         mapall may be combined with copyring to change vars for all objects.
    524524         The 3rd argument is useful in order to avoid conflicts of names, the
    525525         empty string is allowed
    526 CAUTION: mapall does not work inside a procedure 
     526CAUTION: mapall does not work inside a procedure
    527527EXAMPLE: example mapall; shows an example
    528 { 
     528{
    529529   list @L@=names(R); map @psi@ = R,i;
    530530   int @ii@; string @s@;
    531531   if( size(#) > 0 ) { @s@=@s@+"_"+#[1]; }
    532    for( @ii@=size(@L@); @ii@>0; @ii@-- )
    533    { 
     532   for( @ii@=size(@L@); @ii@>0; @ii@=@ii@-1 )
     533   {
    534534      execute("def "+@L@[@ii@]+@s@+"=@psi@(`@L@[@ii@]`);");
    535535      execute("export "+@L@[@ii@]+@s@+";");
     
    544544"   ideal j=x,y,z;";
    545545"   matrix M[2][3]=1,2,3,x,y,z;";
    546 "   map phi=R,x2,y2,z2; "; 
     546"   map phi=R,x2,y2,z2; ";
    547547"   ring S=0,(a,b,c),ds;";
    548548"   ideal i=c,a,b;";
     
    565565USAGE:   ringtensor(s,r1,r2,...); s=string, r1,r2,...=rings
    566566CREATE:  A new base ring with name `s` if r1,r2,... are existing rings.
    567          If, say, s = "R" and the rings r1,r2,... exist, the new ring will 
    568          have name R, variables from all rings r1,r2,... and as monomial 
     567         If, say, s = "R" and the rings r1,r2,... exist, the new ring will
     568         have name R, variables from all rings r1,r2,... and as monomial
    569569         ordering the block (product) ordering of r1,r2,... . Hence, R
    570570         is the tensor product of the rings r1,r2,... with ordering matrix
     
    576576         variable with name x in r1, there is no access to x in r2).
    577577         The procedure works also for quotient rings ri, if the characteristic
    578          of ri is compatible with the characteristic of r1 (i.e. if imap from 
     578         of ri is compatible with the characteristic of r1 (i.e. if imap from
    579579         ri to r1 is implemented)
    580          This proc uses 'execute' or calls a procedure using 'execute'. 
    581          If you use it in your own proc, let the local names of your proc 
     580         This proc uses 'execute' or calls a procedure using 'execute'.
     581         If you use it in your own proc, let the local names of your proc
    582582         start with @ (see the file HelpForProc)
    583583EXAMPLE: example ringtensor; shows an example
     
    587587   string @vars,@order,@oi,@s1;
    588588//---- gather variables, orderings and ideals (of qrings) from given rings ----
    589    for(@ii=1; @ii<=@n; @ii++)
    590    {
    591       if( ordstr(#[@ii])[1]=="C" or ordstr(#[@ii])[1]=="c" ) 
     589   for(@ii=1; @ii<=@n; @ii=@ii+1)
     590   {
     591      if( ordstr(#[@ii])[1]=="C" or ordstr(#[@ii])[1]=="c" )
    592592           { @oi=ordstr(#[@ii])[3,size(ordstr(#[@ii]))-2]; }
    593593      else { @oi=ordstr(#[@ii])[1,size(ordstr(#[@ii]))-2]; }
     
    596596      def @r(@ii)=#[@ii];
    597597      setring @r(@ii);
    598       ideal i(@ii)=ideal(@r(@ii)); 
     598      ideal i(@ii)=ideal(@r(@ii));
    599599      int @q(@ii)=size(i(@ii));
    600600      @q=@q+@q(@ii);
     
    610610   {
    611611      ideal i;
    612       for(@ii=1; @ii<=@n; @ii++)
     612      for(@ii=1; @ii<=@n; @ii=@ii+1)
    613613      {
    614614         if( @q(@ii)!=0 )
     
    618618      }
    619619      i=std(i);
    620       execute("qring "+s+"=i;");   
     620      execute("qring "+s+"=i;");
    621621   }
    622622//----------------------- export and keep created ring ------------------------
     
    626626   return();
    627627}
    628 example 
     628example
    629629{ "EXAMPLE:"; echo = 2;
    630630   ring r=32003,(x,y,u,v),dp;
    631631   ring s=0,(a,b,c),wp(1,2,3);
    632632   ring t=0,x(1..5),(c,ls);
    633    ringtensor("R",r,s,t);   
     633   ringtensor("R",r,s,t);
    634634   type R;"";
    635635   setring s;
     
    639639   changevar("T","d,e,f,g,h",t); //set T (change vars of t to d..h) the basering
    640640   qring qT=std(d2+e2-f3);       //create qring of T mod d2+e2-f3
    641    ringtensor("Q",s,qS,t,qT);     
     641   ringtensor("Q",s,qS,t,qT);
    642642   type Q;
    643643   kill R,Q,S,T;
  • Singular/LIB/sing.lib

    r6d09c56 r6f2edc  
    1 // $Id: sing.lib,v 1.1.1.1 1997-04-25 15:13:27 obachman Exp $
     1// $Id: sing.lib,v 1.2 1997-04-28 19:27:25 obachman Exp $
    22//system("random",787422842);
    3 //(GMG+BM)
    4 ///////////////////////////////////////////////////////////////////////////////
    5 
    6 LIBRARY:  sing.lib      PROCEDURES FOR SINGULARITIES         
     3//(GMG/BM, last modified 26.06.96)
     4///////////////////////////////////////////////////////////////////////////////
     5
     6LIBRARY:  sing.lib      PROCEDURES FOR SINGULARITIES
    77
    88 deform(i);             infinitesimal deformations of ideal i
     
    2222 T12(i);                T1- and T2-module of ideal i
    2323
    24 LIB "inout.lib"; 
     24LIB "inout.lib";
    2525LIB "random.lib";
    2626///////////////////////////////////////////////////////////////////////////////
    2727
    2828proc deform (ideal id)
    29 USAGE:   deform(id);  id = ideal or poly
     29USAGE:   deform(id); id=ideal or poly
    3030RETURN:  matrix, columns are kbase of infinitesimal deformations
    31 EXAMPLE: example deform; shows an example 
    32 { 
     31EXAMPLE: example deform; shows an example
     32{
    3333   list L=T1(id,"");
    34    return(L[2]*kbase(std(L[1])));
    35 }
    36 example
    37 { "EXAMPLE:"; echo = 2;
    38    ring r=32003,(x,y,z),ds;
    39    ideal i=xy,xz,yz;
    40    matrix T=deform(i);print(T);
    41    print(deform(x3+y5+z2));
     34   def K=L[1]; attrib(K,"isSB",1);
     35   return(L[2]*kbase(K));
     36}
     37example
     38{ "EXAMPLE:"; echo = 2;
     39   ring r   = 32003,(x,y,z),ds;
     40   ideal i  = xy,xz,yz;
     41   matrix T = deform(i);
     42   print(T);
     43   print(deform(x3+y5+z2));
    4244}
    4345///////////////////////////////////////////////////////////////////////////////
     
    5254example
    5355{ "EXAMPLE:"; echo = 2;
    54    ring r=32003,(x,y,z),ds;
    55    ideal i= x5+y6+z6,x2+2y2+3z2;
     56   ring r  = 32003,(x,y,z),ds;
     57   ideal i = x5+y6+z6,x2+2y2+3z2;
    5658   dim_slocus(i);
    5759}
     
    5961
    6062proc is_active (poly f, id)
    61 USAGE:   is_active(f,id); f poly, id ideal or module 
     63USAGE:   is_active(f,id); f poly, id ideal or module
    6264RETURN:  1 if f is an active element modulo id (i.e. dim(id)=dim(id+f*R^n)+1,
    6365         if id is a submodule of R^n) resp. 0 if f is not active.
    64          The basering may be a quotient ring 
     66         The basering may be a quotient ring
    6567NOTE:    regular parameters are active but not vice versa (id may have embedded
    6668         components). proc is_reg tests whether f is a regular parameter
    6769EXAMPLE: example is_active; shows an example
    6870{
    69    if( size(id)==0 ) { return(1); } 
     71   if( size(id)==0 ) { return(1); }
    7072   if( typeof(id)=="ideal" ) { ideal m=f; }
    71    if( typeof(id)=="module" ) { module m=f*freemodule(rank(id)); }
     73   if( typeof(id)=="module" ) { module m=f*freemodule(nrows(id)); }
    7274   return(dim(std(id))-dim(std(id+m)));
    7375}
    7476example
    7577{ "EXAMPLE:"; echo = 2;
    76    ring r=32003,(x,y,z),ds;
    77    ideal i=yx3+y,yz3+y3z;
    78    poly f=x;
     78   ring r   =32003,(x,y,z),ds;
     79   ideal i  = yx3+y,yz3+y3z;
     80   poly f   = x;
    7981   is_active(f,i);
    80    qring q = std(x4y5);
    81    poly f=x;
    82    module m=[yx3+x,yx3+y3x];
     82   qring q  = std(x4y5);
     83   poly f   = x;
     84   module m = [yx3+x,yx3+y3x];
    8385   is_active(f,m);
    8486}
     
    8890USAGE:   is_ci(i); i ideal
    8991RETURN:  intvec = sequence of dimensions of ideals (j[1],...,j[k]), for
    90          k=1,...,size(j), where j is minimal base of i. i is a complete
    91          intersection if last number equals nvars-size(i) 
    92 NOTE:    dim(0-ideal) = -1. You may first apply simplify(i,10); in order to
    93          delete zeroes and multiples from set of generators
     92         k=1,...,size(j), where j is minimal base of i. i is a complete
     93         intersection if last number equals nvars-size(i)
     94NOTE:    dim(0-ideal) = -1. You may first apply simplify(i,10); in order to
     95         delete zeroes and multiples from set of generators
     96         printlevel >=0: display comments (default)
    9497EXAMPLE: example is_ci; shows an example
    9598{
     
    97100   i=minbase(i);
    98101   int s = ncols(i);
     102   int p = printlevel-voice+3;  // p=printlevel+1 (default: p=1)
    99103//--------------------------- compute dimensions ------------------------------
    100    for( n=1; n<=s; n++ )
    101    { 
     104   for( n=1; n<=s; n=n+1 )
     105   {
    102106      id = i[1..n];
    103107      dimvec[n] = dim(std(id));
    104108   }
    105109   n = dimvec[s];
    106 //--------------------------- output ------------------------------------------     
    107    if( defined(printlevel) )
    108    {
    109       if( n+s !=nvars(basering) )
    110       { dbprint(printlevel,"// no complete intersection"); }
    111       if( n+s ==nvars(basering) )
    112       { dbprint(printlevel,"// complete intersection of dim "+string(n)); }
    113       dbprint(printlevel,"// dim-sequence:");
    114    }
    115    if( voice==2 )
    116    {
    117       if( n+s !=nvars(basering)) {"// no complete intersection"; }
    118       if( n+s ==nvars(basering)) {"// complete intersection of dim",n;}
    119       "// dim-sequence:";
    120    }
     110//--------------------------- output ------------------------------------------
     111   if( n+s != nvars(basering) )
     112   { dbprint(p,"// no complete intersection"); }
     113   if( n+s == nvars(basering) )
     114   { dbprint(p,"// complete intersection of dim "+string(n)); }
     115   dbprint(p,"// dim-sequence:");
    121116   return(dimvec);
    122117}
    123118example
    124 { "EXAMPLE:";   echo = 2; 
    125    int printlevel=2;                // this forces the proc to display comments
    126    export printlevel;             
    127    ring r=32003,(x,y,z),ds;
    128    ideal i=x4+y5+z6,xyz,yx2+xz2+zy7;
     119{ "EXAMPLE:"; echo = 2;
     120   int p      = printlevel;
     121   printlevel = 1;                // display comments
     122   ring r     = 32003,(x,y,z),ds;
     123   ideal i    = x4+y5+z6,xyz,yx2+xz2+zy7;
    129124   is_ci(i);
    130    i=xy,yz;
    131    is_ci(i); 
    132    kill printlevel;
     125   i          = xy,yz;
     126   is_ci(i);
     127   printlevel = p;
    133128}
    134129///////////////////////////////////////////////////////////////////////////////
     
    139134         generated by id[1]..id[i], k = 1..size(id); dim(0-ideal) = -1;
    140135         id defines an isolated singularity if last number is 0
     136NOTE:    printlevel >=0: display comments (default)
    141137EXAMPLE: example is_is; shows an example
    142138{
    143139  int l; intvec dims; ideal j;
     140  int p = printlevel-voice+3;  // p=printlevel+1 (default: p=1)
    144141//--------------------------- compute dimensions ------------------------------
    145    for( l=1; l<=ncols(i); l++ )
    146    {
    147      j = i[1..l]; 
     142   for( l=1; l<=ncols(i); l=l+1 )
     143   {
     144     j = i[1..l];
    148145     dims[l] = dim(std(slocus(j)));
    149146   }
    150    if( voice==2 ) {"// dim of singular locus =",dims[size(dims)],"dim-sequence:";
    151                    "// isolated singularity if last number is 0"; }
     147   dbprint(p,"// dim of singular locus = "+string(dims[size(dims)]),
     148             "// isolated singularity if last number is 0 in dim-sequence:");
    152149   return(dims);
    153150}
    154151example
    155152{ "EXAMPLE:"; echo = 2;
    156    ring r=32003,(x,y,z),ds;
    157    ideal i=x2y,x4+y5+z6,yx2+xz2+zy7;
     153   int p      = printlevel;
     154   printlevel = 1;
     155   ring r     = 32003,(x,y,z),ds;
     156   ideal i    = x2y,x4+y5+z6,yx2+xz2+zy7;
    158157   is_is(i);
    159 // isolated singularity if last number is 0
    160    poly f=xy+yz;
     158   poly f     = xy+yz;
    161159   is_is(f);
    162 // isolated singularity if last number is 0
     160   printlevel = p;
    163161}
    164162///////////////////////////////////////////////////////////////////////////////
     
    177175   id=std(id);
    178176   d=size(q);
    179    for( ii=1; ii<=d; ii++ )
     177   for( ii=1; ii<=d; ii=ii+1 )
    180178   {
    181179      if( reduce(q[ii],id)!=0 )
     
    184182   return(1);
    185183}
    186 example
    187 { "EXAMPLE:"; echo = 2;
    188    ring r=32003,(x,y),ds;
    189    ideal i=x8,y8;ideal j=(x+y)^4;
    190    i=intersect(i,j); poly f=xy;
     184example
     185{ "EXAMPLE:"; echo = 2;
     186   ring r  = 32003,(x,y),ds;
     187   ideal i = x8,y8;
     188   ideal j = (x+y)^4;
     189   i       = intersect(i,j);
     190   poly f  = xy;
    191191   is_reg(f,i);
    192192}
     
    198198NOTE:    let R be the basering and id a submodule of R^n. The procedure checks
    199199         injectivity of multiplication with i[k] on R^n/id+i[1..k-1].
    200          The basering may be a quotient ring
     200         The basering may be a quotient ring
     201         printlevel >=0: display comments (default)
     202         printlevel >=1: display comments during computation
    201203EXAMPLE: example is_regs; shows an example
    202204{
     205   int d,ii,r;
     206   int p = printlevel-voice+3;  // p=printlevel+1 (default: p=1)
    203207   if( size(#)==0 ) { ideal id; }
    204208   else { def id=#[1]; }
    205209   if( size(i)==0 ) { return(0); }
    206    int d,ii,r;
    207    d=size(i);
     210   d=size(i);
    208211   if( typeof(id)=="ideal" ) { ideal m=1; }
    209    if( typeof(id)=="module" ) { module m=freemodule(rank(id)); }
    210    for( ii=1; ii<=d; ii++ )
    211    { 
    212       if( voice==2 )
     212   if( typeof(id)=="module" ) { module m=freemodule(nrows(id)); }
     213   for( ii=1; ii<=d; ii=ii+1 )
     214   {
     215      if( p>=2 )
    213216      { "// checking whether element",ii,"is regular mod 1 ..",ii-1; }
    214       if( is_reg(i[ii],id)==0 )
    215       {
    216          if( voice==2 )
    217          {
    218             "// elements 1 ..",ii-1,"are regular,",
    219             ii,"is not regular mod 1 ..",ii-1;
    220          }
    221          return(0);
     217      if( is_reg(i[ii],id)==0 )
     218      {
     219        dbprint(p,"// elements 1.."+string(ii-1)+" are regular, " +
     220                string(ii)+" is not regular mod 1.."+string(ii-1));
     221         return(0);
    222222      }
    223       id=id+i[ii]*m; 
    224    }
    225    if( voice==2 ) { "// elements are a regular sequence of length",d; }
     223      id=id+i[ii]*m;
     224   }
     225   if( p>=1 ) { "// elements are a regular sequence of length",d; }
    226226   return(1);
    227227}
    228 example
    229 { "EXAMPLE:"; echo = 2;
    230    ring r1=32003,(x,y,z),ds;
    231    ideal i=x8,y8,(x+y)^4;
     228example
     229{ "EXAMPLE:"; echo = 2;
     230   int p      = printlevel;
     231   printlevel = 1;
     232   ring r1    = 32003,(x,y,z),ds;
     233   ideal i    = x8,y8,(x+y)^4;
    232234   is_regs(i);
    233    module m=[x,0,y];
    234    i=x8,(x+z)^4;;
     235   module m   = [x,0,y];
     236   i          = x8,(x+z)^4;;
    235237   is_regs(i,m);
     238   printlevel = p;
    236239}
    237240///////////////////////////////////////////////////////////////////////////////
     
    240243USAGE:   milnor(i); i ideal or poly
    241244RETURN:  Milnor number of i, if i is ICIS (isolated complete intersection
    242          singularity) in generic form, resp. -1 if not 
     245         singularity) in generic form, resp. -1 if not
    243246NOTE:    use proc nf_icis to put generators in generic form
     247         printlevel >=0: display comments (default)
    244248EXAMPLE: example milnor; shows an example
    245 { 
    246   i = simplify(i,10);     //delete zeroes and multiples from set of generators     
     249{
     250  i = simplify(i,10);     //delete zeroes and multiples from set of generators
    247251  int n = size(i);
    248252  int l,q,m_nr;  ideal t;  intvec disc;
    249 //---------------------------- hypersurface case ------------------------------   
    250   if( n==1 )     
     253  int p = printlevel-voice+3;  // p=printlevel+1 (default: p=1)
     254//---------------------------- hypersurface case ------------------------------
     255  if( n==1 )
    251256  {
    252257     i = std(jacob(i[1]));
    253      m_nr = vdim(i);       
    254      if( m_nr<0 and voice==2 ) { "// no isolated singularity"; }
    255      return(m_nr); 
     258     m_nr = vdim(i);
     259     if( m_nr<0 and p>=1 ) { "// no isolated singularity"; }
     260     return(m_nr);
    256261  }
    257262//------------ isolated complete intersection singularity (ICIS) --------------
    258263  for( l=n; l>0; l=l-1)
    259   {
    260       t      = minor(jacob(i),l);
    261       i[l]   = 0;
     264  {   t      = minor(jacob(i),l);
     265      i[l]   = 0;
    262266      q      = vdim(std(i+t));
    263267      disc[l]= q;
    264268      if( q ==-1 )
    265       {
    266          if( voice==2 )
     269      {  if( p>=1 )
    267270            {  "// not in generic form or no ICIS; use proc nf_icis to put";
    268             "// generators in generic form and then try milnor again!";  } 
     271            "// generators in generic form and then try milnor again!";  }
    269272         return(q);
    270273      }
    271       m_nr = q-m_nr; 
     274      m_nr = q-m_nr;
    272275  }
    273 //---------------------------- change sign ------------------------------------     
    274   if (m_nr < 0) { m_nr=-m_nr; } 
    275   if( voice==2 ) { "//sequence of discriminant numbers:",disc; }
     276//---------------------------- change sign ------------------------------------
     277  if (m_nr < 0) { m_nr=-m_nr; }
     278  if( p>=1 ) { "//sequence of discriminant numbers:",disc; }
    276279  return(m_nr);
    277280}
    278281example
    279282{ "EXAMPLE:"; echo = 2;
    280    ring r=32003,(x,y,z),ds;
    281    ideal j=x5+y6+z6,x2+2y2+3z2,xyz+yx;
     283   int p      = printlevel;
     284   printlevel = 1;
     285   ring r     = 32003,(x,y,z),ds;
     286   ideal j    = x5+y6+z6,x2+2y2+3z2,xyz+yx;
    282287   milnor(j);
    283    poly f=x7+y7+(x-y)^2*x2y2+z2;
    284    milnor(f);
     288   poly f     = x7+y7+(x-y)^2*x2y2+z2;
     289   milnor(f);
     290   printlevel = p;
    285291}
    286292///////////////////////////////////////////////////////////////////////////////
     
    291297         (isolated complete intersection singularity), return i if not
    292298NOTE:    this proc is useful in connection with proc milnor
     299         printlevel >=0: display comments (default)
    293300EXAMPLE: example nf_icis; shows an example
    294301{
    295302   i = simplify(i,10);  //delete zeroes and multiples from set of generators
    296    int p,b = 100,0; 
     303   int p,b = 100,0;
    297304   int n = size(i);
    298305   matrix mat=freemodule(n);
    299 //---------------------------- test: complete intersection? -------------------     
     306   int P = printlevel-voice+3;  // P=printlevel+1 (default: P=1)
     307//---------------------------- test: complete intersection? -------------------
    300308   intvec sl = is_ci(i);
    301    if( n+sl[n] != nvars(basering) ) 
    302    { 
    303     if( voice==2 ) { "// no complete intersection"; }
    304     return(i);
    305    }
    306 //--------------- test: isolated singularity in generic form? -----------------     
     309   if( n+sl[n] != nvars(basering) )
     310   {
     311      dbprint(P,"// no complete intersection");
     312      return(i);
     313   }
     314//--------------- test: isolated singularity in generic form? -----------------
    307315   sl = is_is(i);
    308316   if ( sl[n] != 0 )
    309317   {
    310       if( voice==2 ) { "// no isolated singularity"; }
     318      dbprint(P,"// no isolated singularity");
    311319      return(i);
    312320   }
    313 //------------ produce generic linear combinations of generators --------------   
     321//------------ produce generic linear combinations of generators --------------
    314322   int prob;
    315    while ( sum(sl) != 0 ) 
     323   while ( sum(sl) != 0 )
    316324   {  prob=prob+1;
    317       p=p-25; b=b+10; 
     325      p=p-25; b=b+10;
    318326      i = genericid(i,p,b);          // proc genericid from random.lib
    319327      sl = is_is(i);
    320328   }
    321    if( voice==2 ) { "// ICIS in generic form after",prob,"genericity loop(s)";}
    322    return(i);   
    323 }
    324 example
    325 { "EXAMPLE:"; echo = 2;
    326    ring r=32003,(x,y,z),ds;
    327    ideal i=x3+y4,z4+yx;   
    328    nf_icis(i);     
    329    ideal j=x3+y4,xy,yz;
     329   dbprint(P,"// ICIS in generic form after "+string(prob)+" genericity loop(s)");
     330   return(i);
     331}
     332example
     333{ "EXAMPLE:"; echo = 2;
     334   int p      = printlevel;
     335   printlevel = 1;
     336   ring r     = 32003,(x,y,z),ds;
     337   ideal i    = x3+y4,z4+yx;
     338   nf_icis(i);
     339   ideal j    = x3+y4,xy,yz;
    330340   nf_icis(j);
     341   printlevel = p;
    331342}
    332343///////////////////////////////////////////////////////////////////////////////
     
    340351  int cod  = nvars(basering)-dim(std(i));
    341352  i        = i+minor(jacob(i),cod);
    342   return(i);   
    343 }
    344 example
    345 { "EXAMPLE:"; echo = 2;
    346    ring r=32003,(x,y,z),ds;
    347    ideal i= x5+y6+z6,x2+2y2+3z2;
     353  return(i);
     354}
     355example
     356{ "EXAMPLE:"; echo = 2;
     357   ring r  = 32003,(x,y,z),ds;
     358   ideal i = x5+y6+z6,x2+2y2+3z2;
    348359   dim(std(slocus(i)));
    349360}
     
    351362
    352363proc Tjurina (id, list #)
    353 USAGE:   Tjurina(id[,<any>]);  id ideal or poly (assume: id=ICIS)
    354 RETURN:  Tjurina(id): standard basis of Tjurina-module of id, displays Tjurina
    355          number
    356          Tjurina(id,...): If a second argument is present (of any type) return
    357          a list of 4 objects: [1]=Tjurina number (int), [2]=basis of miniversal
    358          deformation (module), [3]=SB of Tjurina module (module), [4]=Tjurina
    359          module (module)
    360 NOTE:    if id is a poly the output will be of type ideal rather than module
    361 EXAMPLE: example Tjurina; shows an example
     364USAGE:   Tjurina(id[,<any>]);  id=ideal or poly
     365ASSUME:  id=ICIS (isolated complete intersection singularity)
     366RETURN:  standard basis of Tjurina-module of id,
     367         of type module if id=ideal, resp. of type ideal if id=poly.
     368         If a second argument is present (of any type) return a list:
     369           [1] = Tjurina number,
     370           [2] = k-basis of miniversal deformation,
     371           [3] = SB of Tjurina module,
     372           [4] = Tjurina module
     373DISPLAY: Tjurina number if printlevel >= 0 (default)
     374NOTE:    Tjurina number = -1 implies that id is not an ICIS
     375EXAMPLE: example Tjurina; shows examples
    362376{
    363377//---------------------------- initialisation ---------------------------------
    364   def i = simplify(id,10);         
     378  def i = simplify(id,10);
    365379  int tau,n = 0,size(i);
    366380  if( size(ideal(i))==1 ) { def m=i; }  // hypersurface case
     
    370384  def st1 = std(t1);                    // SB of Tjurina module/ideal
    371385  tau = vdim(st1);                      // Tjurina number
    372   def kB = kbase(st1);                  // basis of miniversal deformation
    373   if( voice==2 )  { "// Tjurina number =",tau; }
    374   if( size(#)>0 ) { return(tau,kB,st1,t1); }
     386  dbprint(printlevel-voice+3,"// Tjurina number = "+string(tau));
     387  if( size(#)>0 )
     388  {
     389     def kB = kbase(st1);               // basis of miniversal deformation
     390     return(tau,kB,st1,t1);
     391  }
    375392  return(st1);
    376393}
    377394example
    378395{ "EXAMPLE:"; echo = 2;
    379    ring r=0,(x,y,z),ds;
    380    poly f = x5+y6+z7+xyz;        // singularity T[5,6,7]
    381    list T = Tjurina(f,"");
    382    show(T[1]);                   // Tjurina number, should be 16
    383    show(T[2]);                   // basis of miniversal deformation
    384    show(T[3]);                   // SB of Tjurina ideal
    385    show(T[4]); "";               // Tjurina ideal
    386    ideal j=x2+y2+z2,x2+2y2+3z2;
    387    show(kbase(Tjurina(j)));      // basis of miniversal deformation
    388    hilb(Tjurina(j));             // Hilbert series of Tjurina module
     396   int p      = printlevel;
     397   printlevel = 1;
     398   ring r     = 0,(x,y,z),ds;
     399   poly f     = x5+y6+z7+xyz;        // singularity T[5,6,7]
     400   list T     = Tjurina(f,"");
     401   show(T[1]);                       // Tjurina number, should be 16
     402   show(T[2]);                       // basis of miniversal deformation
     403   show(T[3]);                       // SB of Tjurina ideal
     404   show(T[4]); "";                   // Tjurina ideal
     405   ideal j    = x2+y2+z2,x2+2y2+3z2;
     406   show(kbase(Tjurina(j)));          // basis of miniversal deformation
     407   hilb(Tjurina(j));                 // Hilbert series of Tjurina module
     408   printlevel = p;
    389409}
    390410///////////////////////////////////////////////////////////////////////////////
    391411
    392412proc tjurina (ideal i)
    393 USAGE:   tjurina(id);  id ideal or poly (assume: id=ICIS)
     413USAGE:   tjurina(id);  id=ideal or poly
     414ASSUME:  id=ICIS (isolated complete intersection singularity)
    394415RETURN:  int = Tjurina number of id
     416NOTE:    Tjurina number = -1 implies that id is not an ICIS
    395417EXAMPLE: example tjurina; shows an example
    396418{
    397    return(vdim(Tjurina(i))); 
     419   return(vdim(Tjurina(i)));
    398420}
    399421example
     
    401423   ring r=32003,(x,y,z),(c,ds);
    402424   ideal j=x2+y2+z2,x2+2y2+3z2;
    403    tjurina(j); 
     425   tjurina(j);
    404426}
    405427///////////////////////////////////////////////////////////////////////////////
     
    407429proc T1 (ideal id, list #)
    408430USAGE:   T1(id[,<any>]);  id = ideal or poly
    409 RETURN:  T1(id): T1-module of id or T1-ideal if id is a poly. This is a
     431RETURN:  T1(id): of type module/ideal if id is of type ideal/poly.
     432         We call T1(id) the T1-module of id. It is a std basis of the
    410433         presentation of 1st order deformations of P/id, if P is the basering.
    411          T1(id,...): If a second argument is present (of any type) return a
    412          list of 3 modules:
    413             [1]= presentation of infinitesimal deformations of id (=T1(id))
     434         If a second argument is present (of any type) return a list of
     435         3 modules:
     436            [1]= T1(id)
    414437            [2]= generators of normal bundle of id, lifted to P
    415             [3]= module of relations of [2], lifted to P ([2]*[3]=0 mod id)
    416          The list contains all non-easy objects which must be computed anyway
     438            [3]= module of relations of [2], lifted to P
     439                 (note: transpose[3]*[2]=0 mod id)
     440         The list contains all non-easy objects which must be computed
    417441         to get T1(id).
    418          The situation is described in detail in the procedure T1_expl
    419          from library explain.lib
    420 NOTE:    T1(id) itself is usually of minor importance, nevertheless, from it
    421          all relevant information can be obtained. Since no standard basis is
    422          computed, the user has first to compute a standard basis before
    423          applying vdim or hilb etc.. For example, matrix([2])*(kbase(std([1])))
    424          represents a basis of 1st order semiuniversal deformation of id
    425          (use proc 'deform', to get this in a direct and convenient way).
    426          If the input is weighted homogeneous with weights w1,...,wn, use
    427          ordering wp(w1..wn), even in the local case, which is equivalent but
    428          faster than ws(w1..wn).
     442DISPLAY: k-dimension of T1(id) if printlevel >= 0 (default)
     443NOTE:    T1(id) itself is usually of minor importance. Nevertheless, from it
     444         all relevant information can be obtained. The most important are
     445         probably vdim(T1(id)); (which computes the Tjurina number),
     446         hilb(T1(id)); and kbase(T1(id));
     447         If T1 is called with two argument, then matrix([2])*(kbase([1]))
     448         represents a basis of 1st order semiuniversal deformation of id
     449         (use proc 'deform', to get this in a direct way).
    429450         For a complete intersection the proc Tjurina is faster
    430451EXAMPLE: example T1; shows an example
     
    432453   ideal J=simplify(id,10);
    433454//--------------------------- hypersurface case -------------------------------
    434   if( size(J)<2 )
    435   {
    436      ideal t1=J[1],jacob(J[1]); module nb=[1]; module pnb;
     455  if( size(J)<2 )
     456  {
     457     ideal t1  = std(J+jacob(J[1]));
     458     module nb = [1]; module pnb;
     459     dbprint(printlevel-voice+3,"// dim T1 = "+string(vdim(t1)));
    437460     if( size(#)>0 ) { return(t1*gen(1),nb,pnb); }
    438461     return(t1);
     
    440463//--------------------------- presentation of J -------------------------------
    441464   int rk;
    442   def P=basering;
     465  def P = basering;
    443466   module jac, t1;
    444    jac=jacob(J);                 // jacobian matrix of J converted to module
    445    res(J,2,A);                   // compute presentation of J
    446    t1=transpose(A(2));           // transposed 1st syzygy module of J
     467   jac  = jacob(J);                 // jacobian matrix of J converted to module
     468   res(J,2,A);                      // compute presentation of J
     469                                    // A(2) = 1st syzygy module of J
    447470//---------- go to quotient ring mod J and compute normal bundle --------------
    448   qring  R=std(J);
    449    module jac=fetch(P,jac);
    450    module t1=fetch(P,t1);       
    451    res(t1,3,B);                  // resolve t1, B(2)=(J/J^2)*=normal_bdl
    452    t1=lift(B(2),jac)+B(3);       // pres. of normal_bdl/trivial_deformations
    453    rk=rank(t1);
     471  qring  R    = std(J);
     472   module jac = fetch(P,jac);
     473   module t1  = transpose(fetch(P,A(2)));
     474   res(t1,2,B);                     // resolve t1, B(2)=(J/J^2)*=normal_bdl
     475   t1         = modulo(B(2),jac);   // pres. of normal_bdl/trivial_deformations
     476   rk=nrows(t1);
    454477//-------------------------- pull back to basering ----------------------------
    455478  setring P;
    456479   t1 = fetch(R,t1)+J*freemodule(rk);  // T1-module, presentation of T1
    457    if( size(#)>0 )
    458    {
    459       module B2 = fetch(R,B(2));        // (generators of) normal bundle
    460       module B3 = fetch(R,B(3));        // presentation of normal bundle
    461       return(t1,B2,B3);
    462    }
    463    return(t1); 
    464 }
    465 example
    466 { "EXAMPLE:"; echo = 2;
    467    ring r=32003,(x,y,z),(c,ds);
    468    ideal i=xy,xz,yz;
    469    module T=T1(i);
    470    vdim(std(T));                 // Tjurina number = dim_K(T1), should be 3
     480   t1 = std(t1);
     481   dbprint(printlevel-voice+3,"// dim T1 = "+string(vdim(t1)));
     482   if( size(#)>0 )
     483   {
     484      module B2 = fetch(R,B(2));        // presentation of normal bundle
     485      list L = t1,B2,A(2);
     486      attrib(L[1],"isSB",1);
     487      return(L);
     488   }
     489   return(t1);
     490}
     491example
     492{ "EXAMPLE:"; echo = 2;
     493   int p      = printlevel;
     494   printlevel = 1;
     495   ring r     = 32003,(x,y,z),(c,ds);
     496   ideal i    = xy,xz,yz;
     497   module T   = T1(i);
     498   vdim(T);                      // Tjurina number = dim_K(T1), should be 3
    471499   list L=T1(i,"");
    472    module kB = kbase(std(L[1]));
     500   module kB  = kbase(L[1]);
    473501   print(L[2]*kB);               // basis of 1st order miniversal deformation
    474    size(L[1]);                   // number of generators of T1-module
    475    show(L[2]);                   // (generators of) normal bundle
    476    print(L[3]);                  // relation matrix of normal bundle (mod i)
    477    print(L[2]*L[3]);             // should be 0 (mod i)
     502   show(L[2]);                   // presentation of normal bundle
     503   print(L[3]);                  // relations of i
     504   print(transpose(L[3])*L[2]);  // should be 0 (mod i)
     505   printlevel = p;
    478506}
    479507///////////////////////////////////////////////////////////////////////////////
     
    481509proc T2 (ideal id, list #)
    482510USAGE:   T2(id[,<any>]);  id = ideal
    483 RETURN:  T2(id): T2-module of id . This is a presentation of the module of
    484            obstructions of R=P/id, if P is the basering.
    485          T2(id,...): If a second argument is present (of any type) return a
    486          list of 6 modules and 1 ideal:
    487             [1]= presentation of module of obstructions (=T2(id))
     511RETURN:  T2(id): T2-module of id . This is a std basis of a presentation of
     512         the module of obstructions of R=P/id, if P is the basering.
     513         If a second argument is present (of any type) return a list of
     514         4 modules and 1 ideal:
     515            [1]= T2(id)
    488516            [2]= standard basis of id (ideal)
    489517            [3]= module of relations of id (=1st syzygy module of id)
    490             [4]= presentation of [3] (=2nd syzygy module of id)
    491             [5]= lifting of Koszul relations kos, kos=module([3]*matrix([5]))
    492             [6]= generators of Hom_P([3]/kos,R), lifted to P
    493             [7]= relations of Hom_P([3]/kos,R), lifted to P
    494          The list contains all non-easy objects which must be computed anyway
    495          to get T2(id). The situation is described in detail in the procedure
    496          T2_expl from library explain.lib
    497 NOTE:    Since no standard basis is computed, the user has first to compute a
    498          standard basis before applying vdim or hilb etc.. 
    499          If the input is weighted homogeneous with weights w1,...,wn, use
    500          ordering wp(w1..wn), even in the local case, which is equivalent but
    501          faster than ws(w1..wn).
    502          Use proc miniversal to get equations of miniversal deformation;
     518            [4]= presentation of syz/kos
     519            [5]= relations of Hom_P([3]/kos,R), lifted to P
     520         The list contains all non-easy objects which must be computed
     521         to get T2(id).
     522DISPLAY: k-dimension of T2(id) if printlevel >= 0 (default)
     523NOTE:    The most important information is probably vdim(T2(id)).
     524         Use proc miniversal to get equations of miniversal deformation.
    503525EXAMPLE: example T2; shows an example
    504526{
    505527//--------------------------- initialisation ----------------------------------
    506528  def P = basering;
    507    ideal J = simplify(id,10);
    508    module kos,L0,t2;
     529   ideal J = id;
     530   module kos,SK,B2,t2;
     531   list L;
    509532   int n,rk;
    510 //------------------- presentation of non-trivial syzygies -------------------- 
    511    res(J,3,A);                            // resolve J, A(2)=syz
     533//------------------- presentation of non-trivial syzygies --------------------
     534   res(J,2,A);                            // resolve J, A(2)=syz
    512535   kos  = koszul(2,J);                    // module of Koszul relations
    513    L0 = lift(A(2),kos);                   // lift Koszul relations to syz
    514    t2   = L0+A(3);                        // presentation of syz/kos
     536   SK   = modulo(A(2),kos);               // presentation of syz/kos
    515537   ideal J0 = std(J);                     // standard basis of J
    516 //*** sollte bei der Berechnung von res mit anfallen, zu aendern!!
     538//?*** sollte bei der Berechnung von res mit anfallen, zu aendern!!
    517539//---------------------- fetch to quotient ring mod J -------------------------
    518540  qring R = J0;                           // make P/J the basering
    519    module A2' = transpose(fetch(P,A(2))); // dual of syz 
    520    module t2  = transpose(fetch(P,t2));   // dual of syz/kos
    521    res(t2,3,B);                           // resolve t2   
    522    t2 = lift(B(2),A2')+B(3);              // presentation of T2
    523    rk = rank(t2);
     541   module A2' = transpose(fetch(P,A(2))); // dual of syz
     542   module t2  = transpose(fetch(P,SK));   // dual of syz/kos
     543   res(t2,2,B);                           // resolve (syz/kos)*
     544   t2 = modulo(B(2),A2');                 // presentation of T2
     545   rk = nrows(t2);
    524546//---------------------  fetch back to basering -------------------------------
    525547  setring P;
    526548   t2 = fetch(R,t2)+J*freemodule(rk);
    527    if( size(#)>0 )
    528    {
    529       module B2 = fetch(R,B(2));        // generators of Hom_P(syz/kos,R)
    530       module B3 = fetch(R,B(3));        // relations of Hom_P(syz/kos,R)
    531       return(t2,J0,A(2),A(3),L0,B2,B3);
    532    }
    533    return(t2); 
    534 }
    535 example
    536 { "EXAMPLE:"; echo = 2;
    537    ring  r = 32003,(x,y),(c,dp);
    538    ideal j = x6-y4,x6y6,x2y4-x5y2;
    539    module T= std(T2(j));
    540    vdim(T);hilb(T);
    541    ring r1=0,(x,y,z),dp;
    542    ideal id=xy,xz,yz;
    543    list L=T2(id,"");
    544    vdim(std(L[1]));                      // vdim of T2
    545    L[4];                                 // 2nd syzygy module of ideal
     549   t2 = std(t2);
     550   dbprint(printlevel-voice+3,"// dim T2 = "+string(vdim(t2)));
     551   if( size(#)>0 )
     552   {
     553      B2 = fetch(R,B(2));        // generators of Hom_P(syz/kos,R)
     554      L  = t2,J0,A(2),SK,B2;
     555      return(L);
     556   }
     557   return(t2);
     558}
     559example
     560{ "EXAMPLE:"; echo = 2;
     561   int p      = printlevel;
     562   printlevel = 1;
     563   ring  r    = 32003,(x,y),(c,dp);
     564   ideal j    = x6-y4,x6y6,x2y4-x5y2;
     565   module T   = T2(j);
     566   vdim(T);
     567   hilb(T);"";
     568   ring r1    = 0,(x,y,z),dp;
     569   ideal id   = xy,xz,yz;
     570   list L     = T2(id,"");
     571   vdim(L[1]);                           // vdim of T2
     572   print(L[3]);                          // syzygy module of id
     573   printlevel = p;
    546574}
    547575///////////////////////////////////////////////////////////////////////////////
     
    549577proc T12 (ideal i, list #)
    550578USAGE:   T12(i[,any]);  i = ideal
    551 DISPLAY: dim T1 and dim T2  of i
    552 RETURN:  T12(i): list of 2 modules:
    553              presentation of T1-module =T1(i) , 1st order deformations 
    554              presentation of T2-module =T2(i) , obstructions of R=P/i
    555          T12(i,...): If a second argument is present (of any type) return
    556          a list of 9 modules, matrices, integers:
    557              [1]= presentation of T1 (module)
    558              [2]= presentation of T2 (module)
    559              [3]= matrix, whose cols present infinitesimal deformations
    560              [4]= matrix, whose cols are generators of relations of i     
    561              [5]= matrix, presenting Hom_P([4]/kos,R), lifted to P
    562              [6]= standard basis of T1-module
    563              [7]= standard basis of T2-module
    564              [8]= vdim of T1
    565              [9]= vdim of T2
     579RETURN:  T12(i): list of 2 modules:
     580             std basis of T1-module =T1(i), 1st order deformations
     581             std basid of T2-module =T2(i), obstructions of R=P/i
     582         If a second argument is present (of any type) return a list of
     583         9 modules, matrices, integers:
     584             [1]= standard basis of T1-module
     585             [2]= standard basis of T2-module
     586             [3]= vdim of T1
     587             [4]= vdim of T2
     588             [5]= matrix, whose cols present infinitesimal deformations
     589             [6]= matrix, whose cols are generators of relations of i (=syz(i))
     590             [7]= matrix, presenting Hom_P(syz/kos,R), lifted to P
     591             [8]= presentation of T1-module, no std basis
     592             [9]= presentation of T2-module, no std basis
     593DISPLAY: k-dimension of T1 and T2 if printlevel >= 0 (default)
    566594NOTE:    Use proc miniversal from deform.lib to get miniversal deformation of i,
    567595         the list contains all objects used by proc miniversal
     
    572600  def P = basering;
    573601   i = simplify(i,10);
    574    if (size(i)<2)
    575    {
    576      "// hypersurface, use proc 'Tjurina'";
    577      //return([1]);
    578    }
    579    module jac,t1,t2,kos,sbt1,sbt2;
    580    matrix L3,L4,L5;
     602   module jac,t1,t2,sbt1,sbt2;
     603   matrix Kos,Syz,SK,kbT1,Sx;
     604   list L;
    581605   ideal  i0 = std(i);
    582606//-------------------- presentation of non-trivial syzygies -------------------
    583    list I= res(i,3);                            // resolve i
    584    L4  = matrix(I[2]);                          // syz(i)
     607   list I= res(i,2);                            // resolve i
     608   Syz  = matrix(I[2]);                         // syz(i)
    585609   jac = jacob(i);                              // jacobi ideal
    586    t1  = transpose(I[2]);                       // dual of syzygies
    587    kos = koszul(2,i);                           // koszul-relations
    588    t2  = lift(I[2],kos)+I[3];                   // presentation of syz/kos
     610   Kos = koszul(2,i);                           // koszul-relations
     611   SK  = modulo(Syz,Kos);                       // presentation of syz/kos
    589612//--------------------- fetch to quotient ring  mod i -------------------------
    590613  qring   Ox  = i0;                             // make P/i the basering
    591    module jac = fetch(P,jac);
    592    module t1  = fetch(P,t1);                    // Hom(syz,R)
    593    module t2  = transpose(fetch(P,t2));         // Hom(syz/kos,R)
    594    list resS  = res(t1,3);
    595    list resR  = res(t2,3);
    596    t2 = lift(resR[2],t1)+resR[3];               // presentation of T2
    597    r2 = rank(t2);
    598    t1 = lift(resS[2],jac)+resS[3];              // presentation of T1
    599    r1 = rank(t1);
    600    matrix L3  = resS[2];
    601    matrix L5  = resR[2];
     614   module Jac = fetch(P,jac);
     615   matrix No  = transpose(fetch(P,Syz));        // ker(No) = Hom(syz,Ox)
     616   module So  = transpose(fetch(P,SK));         // Hom(syz/kos,R)
     617   list resS  = res(So,2);
     618   matrix Sx  = resS[2];
     619   list resN  = res(No,2);
     620   matrix Nx  = resN[2];
     621   module T2  = modulo(Sx,No);                  // presentation of T2
     622   r2         = nrows(T2);
     623   module T1  = modulo(Nx,Jac);                 // presentation of T1
     624   r1         = nrows(T1);
    602625//------------------------ pull back to basering ------------------------------
    603626  setring P;
    604    t1   = fetch(Ox,t1)+i*freemodule(r1);
    605    t2   = fetch(Ox,t2)+i*freemodule(r2);
     627   t1   = fetch(Ox,T1)+i*freemodule(r1);
     628   t2   = fetch(Ox,T2)+i*freemodule(r2);
    606629   sbt1 = std(t1);
    607630   d1   = vdim(sbt1);
    608    sbt2=std(t2);
     631   sbt2 = std(t2);
    609632   d2   = vdim(sbt2);
    610    "// dim T1  = ",d1;
    611    "// dim T2  = ",d2;
     633   dbprint(printlevel-voice+3,"// dim T1 = "+string(d1),"// dim T2 = "+string(d2));
    612634   if  ( size(#)>0)
    613635   {
    614      L3 = fetch(Ox,L3)*kbase(sbt1);
    615      L5 = fetch(Ox,L5);
    616      return(t1,t2,L3,L4,L5,sbt1,sbt2,d1,d2);
    617    }
    618    return(t1,t2);
    619 }
    620 example
    621 { "EXAMPLE:"; echo = 2;
    622    ring r=200,(x,y,z,u,v),(c,ws(4,3,2,3,4));
    623    ideal i=xz-y2,yz2-xu,xv-yzu,yu-z3,z2u-yv,zv-u2;
    624    //a cyclic quotient singularity
    625    list L = T12(i,1);
    626    print(L[3]);
    627 }
    628 ///////////////////////////////////////////////////////////////////////////////
     636      kbT1 = fetch(Ox,Nx)*kbase(sbt1);
     637      Sx   = fetch(Ox,Sx);
     638      L = sbt1,sbt2,d1,d2,kbT1,Syz,Sx,t1,t2;
     639      return(L);
     640   }
     641   L = sbt1,sbt2;
     642   return(L);
     643}
     644example
     645{ "EXAMPLE:"; echo = 2;
     646   int p      = printlevel;
     647   printlevel = 1;
     648   ring r     = 200,(x,y,z,u,v),(c,ws(4,3,2,3,4));
     649   ideal i    = xz-y2,yz2-xu,xv-yzu,yu-z3,z2u-yv,zv-u2;
     650                            //a cyclic quotient singularity
     651   list L     = T12(i,1);
     652   print(L[5]);             //matrix of infin. deformations
     653   printlevel = p;
     654}
     655///////////////////////////////////////////////////////////////////////////////
Note: See TracChangeset for help on using the changeset viewer.