Changeset 08d847 in git


Ignore:
Timestamp:
May 12, 2008, 4:55:16 PM (15 years ago)
Author:
Viktor Levandovskyy <levandov@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'a800fe4b3e9d37a38c5a10cc0ae9dfa0c15a4ee6')
Children:
69fb8d5542e0a6b5c38f18c4c9462982a9f00e03
Parents:
f7a73ed1209d4fc117e52cdbefbe3d5ce10759e2
Message:
*levandov: Serre and conversion tools


git-svn-id: file:///usr/local/Singular/svn/trunk@10712 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Singular/LIB/freegb.lib

    rf7a73ed r08d847  
    11//////////////////////////////////////////////////////////////////////////////
    2 version="$Id: freegb.lib,v 1.8 2008-03-13 19:26:16 levandov Exp $";
     2version="$Id: freegb.lib,v 1.9 2008-05-12 14:55:16 levandov Exp $";
    33category="Noncommutative";
    44info="
    5 LIBRARY: ratgb.lib  Twosided Noncommutative Groebner bases in Free Algebras
     5LIBRARY: freegb.lib  Twosided Noncommutative Groebner bases in Free Algebras
    66AUTHOR: Viktor Levandovskyy,     levandov@math.rwth-aachen.de
    77
    88PROCEDURES:
    99freegbasis(list L, int n);   compute two-sided Groebner basis of ideal, encoded via L, up to degree n
    10 lst2str(list L);         convert a list (of modules) into polynomials in free algebra
    11 mod2str(module M);       convert a module into a polynomial in free algebra
     10
     11freegbRing(int d);    creates a ring with d blocks of shifted original variables
     12
     13CONVERSION ROUTINES:
     14
     15lp2lstr(ideal K, def save): converts letter-place ideal to a list of modules
     16lst2str(list L[,int n]);            convert a list (of modules) into polynomials in free algebra
     17mod2str(module M[,int n]);  convert a module into a polynomial in free algebra
     18vct2str(module M[,int n]);  convert a vector into a word in free algebra
    1219"
    1320
     
    1926// V[1+i] = the corresponding symbol
    2027
     28LIB "discretize.lib"; // for replace
    2129LIB "qhmoduli.lib"; // for Max
    2230
     
    95103}
    96104
    97 proc lst2str(list L)
    98 "USAGE:  lst2str(L);  L a list of modules
     105proc lst2str(list L, list #)
     106"USAGE:  lst2str(L[,n]);  L a list of modules, n an optional integer
    99107RETURN:  list (of strings)
    100108PURPOSE: convert a list (of modules) into polynomials in free algebra
    101109EXAMPLE: example lst2str; shows examples
     110NOTE: if an optional integer is not 0, stars signs are used in multiplication
    102111"
    103112{
    104113  // returns a list of strings
    105114  // being sentences in words built from L
     115  // if #[1] = 1, use * between generators
     116  int useStar = 0;
     117  if ( size(#)>0 )
     118  {
     119    if (#[1])
     120    {
     121      useStar = 1;
     122    }
     123  }
    106124  int i;
    107125  int s    = size(L);
     
    111129    if ((typeof(L[i]) == "module") || (typeof(L[i]) == "matrix") )
    112130    {
    113       N[i] = mod2str(L[i]);
     131      N[i] = mod2str(L[i],useStar);
    114132    }
    115133    else
     
    129147  list L; L[1] = M; L[2] = N;
    130148  lst2str(L);
    131 }
    132 
    133 
    134 proc mod2str(module M)
    135 "USAGE:  mod2str(M);  M a module
     149  lst2str(L[1],1);
     150}
     151
     152
     153proc mod2str(module M, list #)
     154"USAGE:  mod2str(M[,n]);  M a module, n an optional integer
    136155RETURN:  string
    137 PURPOSE: convert a modules into a polynomial in free algebra
     156PURPOSE: convert a module into a polynomial in free algebra
    138157EXAMPLE: example mod2str; shows examples
     158NOTE: if an optional integer is not 0, stars signs are used in multiplication
    139159"
    140160{
    141161  // returns a string
    142162  // a sentence in words built from M
     163  // if #[1] = 1, use * between generators
     164  int useStar = 0;
     165  if ( size(#)>0 )
     166  {
     167    if (#[1])
     168    {
     169      useStar = 1;
     170    }
     171  }
    143172  int i;
    144173  int s    = ncols(M);
     
    147176  for(i=1; i<=s; i++)
    148177  {
    149     mp = vct2str(M[i]);
     178    mp = vct2str(M[i],useStar);
    150179    if (mp[1] == "-")
    151180    {
     
    169198  module M = [1,x,y,x,y],[-2,y,x,y,x],[6,x,y,y,x,y];
    170199  mod2str(M);
    171 }
    172 
    173 proc vct2str(vector v)
    174 {
     200  mod2str(M,1);
     201}
     202
     203proc vct2str(vector v, list #)
     204"USAGE:  vct2str(v[,n]);  v a vector, n an optional integer
     205RETURN:  string
     206PURPOSE: convert a vector into a word in free algebra
     207EXAMPLE: example vct2str; shows examples
     208NOTE: if an optional integer is not 0, stars signs are used in multiplication
     209"
     210{
     211  // if #[1] = 1, use * between generators
     212  int useStar = 0;
     213  if ( size(#)>0 )
     214  {
     215    if (#[1])
     216    {
     217      useStar = 1;
     218    }
     219  }
    175220  int ppl = printlevel-voice+2;
    176221  // for a word, encoded by v
     
    192237    if (p==1)
    193238    {
    194       vs = vs + string(v[i+1]);
     239      if (useStar && (size(vs) >0))       {   vs = vs + "*"; }
     240        vs = vs + string(v[i+1]);
    195241    }
    196242    else //power
     
    212258      for(j=1;j<=p;j++)
    213259      {
    214         vs = vs + vp;
     260         if (useStar && (size(vs) >0))       {   vs = vs + "*"; }
     261         vs = vs + vp;
    215262      }
    216263    }
     
    229276    }
    230277  }
     278  if (useStar && (size(scf) >0) && (scf!="-") )       {   scf = scf + "*"; }
    231279  vs = scf + vs;
    232280  return(vs);
     
    234282example
    235283{
     284  "EXAMPLE:"; echo = 2;
    236285  ring r = (0,a),(x,y3,z(1)),dp;
    237286  vector v = [-7,x,y3^4,x2,z(1)^3];
    238287  vct2str(v);
     288  vct2str(v,1);
    239289  vector w = [-7a^5+6a,x,y3,y3,x,z(1),z(1)];
    240290  vct2str(w);
     291  vct2str(w,1);
    241292}
    242293
     
    267318example
    268319{
     320  "EXAMPLE:"; echo = 2;
    269321  ring r = 0,(x,y),dp;
    270322  poly f = xy+1;
     
    282334proc id2words(ideal I, int d)
    283335{
     336  // NOT FINISHED
    284337  // input: ideal I of polys in letter-place notation
    285338  // in the ring with d real vars
     
    318371{
    319372  "EXAMPLE:"; echo = 2;
    320   ring r = 0,(x(1),y(1),z(1)),dp;
     373  ring r = 0,(x(1),y(1),z(1),x(2),y(2),z(2)),dp;
    321374  ideal I = x(1)*y(2) -z(1)*x(2);
    322375  id2words(I,3);
    323376}
    324 
    325 
    326377
    327378proc mono2word(poly p, int d)
     
    13841435  // t*h - h*t, t*f - f*t, t*e - e*t
    13851436}
     1437
     1438proc adem(int i, int j)
     1439{
     1440  // produces Adem relations for i<2j in char 0
     1441  // assume: 0<i<2j
     1442  // requires presence of vars up to i+j
     1443  if ( (i<0) || (i >= 2*j) )
     1444  {
     1445    ERROR("arguments out of range"); return(0);
     1446  }
     1447  ring @r = 0,(s(i+j..0)),lp;
     1448  poly p,q;
     1449  number n;
     1450  int ii = i div 2; int k;
     1451  // k=0 => s(0)=1
     1452  n = binomial(j-1,i);
     1453  q = n*s(i+j)*s(0);
     1454  printf("k=0, term=%s",q);
     1455  p = p + q;
     1456  for (k=1; k<= ii; k++)
     1457  {
     1458    n = binomial(j-k-1,i-2*k);
     1459    q = n*s(i+j-k)*s(k);;
     1460    printf("k=%s, term=%s",k,q);
     1461    p = p + q;
     1462  }
     1463  poly AdemRel = p;
     1464  export AdemRel;
     1465  return(@r);
     1466}
     1467example
     1468{
     1469  "EXAMPLE:"; echo = 2;
     1470  def A = adem(2,5);
     1471  setring A;
     1472  AdemRel;
     1473}
     1474
     1475/*
     14761,1: 0
     14771,2: s(3)*s(0) == s(3) -> def for s(3):=s(1)s(2)
     14782,1: adm
     14792,2: s(3)*s(1) == s(1)s(2)s(1)
     14801,3: 0 ( since 2*s(4)*s(0) = 0 mod 2)
     14813,1: adm
     14822,3: s(5)*s(0)+s(4)*s(1) == s(5)+s(4)*s(1)
     14833,2: 0
     14843,3: s(5)*s(1)
     14851,4: 3*s(5)*s(0) == s(5)  -> def for s(5):=s(1)*s(4)
     14864,1: adm
     14872,4: 3*s(6)*s(0)+s(5)*s(1) == s(6) + s(5)*s(1) == s(6) + s(1)*s(4)*s(1)
     14884,2: adm
     14894,3: s(5)*s(2)
     14903,4: s(7)*s(0)+2*s(6)*s(1) == s(7) -> def for s(7):=s(3)*s(4)
     14914,4: s(7)*s(1)+s(6)*s(2)
     1492*/
     1493
     1494/* s1,s2:
     1495s1*s1 =0, s2*s2 = s1*s2*s1
     1496*/
     1497
     1498/*
     1499try char 0:
     1500s1,s2:
     1501s1*s1 =0, s2*s2 = s1*s2*s1, s(1)*s(3)== s(1)*s(1)*s(3) == 0 = 2*s(4) ->def for s(4)
     1502hence 2==0! only in char 2
     1503 */
     1504
     1505proc adem2mod(int n)
     1506{
     1507  // Adem rels modulo 2 
     1508}
     1509
     1510proc stringpoly2lplace(string s)
     1511{
     1512  // decomposes sentence into terms
     1513  s = replace(s,newline,""); // get rid of newlines
     1514  s = replace(s," ",""); // get rid of empties
     1515  //arith symbols: +,-
     1516  // decompose into words with coeffs
     1517  list LS;
     1518  int i,j,ie,je,k,cnt;
     1519  // s[1]="-" situation
     1520  if (s[1]=="-")
     1521  {
     1522    LS = stringpoly2lplace(string(s[2..size(s)]));
     1523    LS[1] = string("-"+string(LS[1]));
     1524    return(LS);
     1525  }
     1526  i = find(s,"-",2);
     1527  // i==1 might happen if the 1st symbol coeff is negative
     1528  j = find(s,"+");
     1529  list LL;
     1530  if (i==j)
     1531  {
     1532    "return a monomial";
     1533    // that is both are 0 -> s is a monomial
     1534    LS[1] = s;
     1535    return(LS);
     1536  }
     1537  if (i==0)
     1538  {
     1539    "i==0 situation";
     1540    // no minuses at all => pluses only
     1541    cnt++;
     1542    LS[cnt] = string(s[1..j-1]);
     1543    s = s[j+1..size(s)];
     1544    while (s!= "")
     1545    {
     1546      j = find(s,"+");
     1547      cnt++;
     1548      if (j==0)
     1549      {
     1550        LS[cnt] = string(s);
     1551        s = "";
     1552      }
     1553      else
     1554      {
     1555        LS[cnt] = string(s[1..j-1]);
     1556        s = s[j+1..size(s)];
     1557      }
     1558    }
     1559    return(LS);
     1560  }
     1561  if (j==0)
     1562  {
     1563    "j==0 situation";
     1564    // no pluses at all except the lead coef => the rest are minuses only
     1565    cnt++;
     1566    LS[cnt] = string(s[1..i-1]);
     1567    s = s[i..size(s)];
     1568    while (s!= "")
     1569    {
     1570      i = find(s,"-",2);
     1571      cnt++;
     1572      if (i==0)
     1573      {
     1574        LS[cnt] = string(s);
     1575        s = "";
     1576      }
     1577      else
     1578      {
     1579        LS[cnt] = string(s[1..i-1]);
     1580        s = s[i..size(s)];
     1581      }
     1582    }
     1583    return(LS);
     1584  }
     1585  // now i, j are nonzero
     1586  if (i>j)
     1587  {
     1588    "i>j situation";
     1589    // + comes first, at place j
     1590    cnt++;
     1591    //    "cnt:"; cnt; "j:"; j;
     1592    LS[cnt] = string(s[1..j-1]);
     1593    s = s[j+1..size(s)];
     1594    LL = stringpoly2lplace(s);
     1595    LS = LS + LL;
     1596    kill LL;
     1597    return(LS);
     1598  }
     1599  else
     1600  {
     1601    "j>i situation";
     1602    // - might come first, at place i
     1603    if (i>1)
     1604    {
     1605      cnt++;
     1606      LS[cnt] = string(s[1..i-1]);
     1607      s = s[i..size(s)];
     1608    }
     1609    else
     1610    {
     1611      // i==1->  minus at leadcoef
     1612      ie = find(s,"-",i+1);
     1613      je = find(s,"+",i+1);
     1614      if (je == ie)
     1615      {
     1616         "ie=je situation";
     1617        //monomial
     1618        cnt++;
     1619        LS[cnt] = s;
     1620        return(LS);
     1621      }
     1622      if (je < ie)
     1623      {
     1624         "je<ie situation";
     1625        // + comes first
     1626        cnt++;
     1627        LS[cnt] = s[1..je-1];
     1628        s = s[je+1..size(s)];
     1629      }
     1630      else
     1631      {
     1632        // ie < je
     1633         "ie<je situation";
     1634        cnt++;
     1635        LS[cnt] = s[1..ie-1];
     1636        s = s[ie..size(s)];
     1637      }
     1638    }
     1639    "going into recursion with "+s;
     1640    LL = stringpoly2lplace(s);
     1641    LS = LS + LL;
     1642    return(LS);
     1643  }
     1644}
     1645example
     1646{
     1647  "EXAMPLE:"; echo = 2;
     1648  string s = "x*y+y*z+z*t"; // + only
     1649  stringpoly2lplace(s);
     1650  string s2 = "x*y - y*z-z*t*w*w"; // +1, - only
     1651  stringpoly2lplace(s2);
     1652  string s3 = "-x*y + y - 2*x +7*w*w*w";
     1653  stringpoly2lplace(s3);
     1654}
     1655
     1656proc addplaces(list L)
     1657{
     1658  // adds places to the list of strings
     1659  // according to their order in the list
     1660  int s = size(L);
     1661  int i;
     1662  for (i=1; i<=s; i++)
     1663  {
     1664    if (typeof(L[i]) == "string")
     1665    {
     1666      L[i] = L[i] + "(" + string(i) + ")";
     1667    }
     1668    else
     1669    {
     1670      ERROR("entry of type string expected");
     1671      return(0);
     1672    }
     1673  }
     1674  return(L);
     1675}
     1676example
     1677{
     1678  "EXAMPLE:"; echo = 2;
     1679  string a = "f1";   string b = "f2";
     1680  list L = a,b,a;
     1681  addplaces(L); 
     1682}
     1683
     1684proc sent2lplace(string s)
     1685{
     1686  list L =   stringpoly2lplace(s);
     1687  int i; int ss = size(L);
     1688  for(i=1; i<=ss; i++)
     1689  {
     1690    L[i] = str2lplace(L[i]);
     1691  }
     1692  return(L);
     1693}
     1694example
     1695{
     1696  "EXAMPLE:"; echo = 2;
     1697  ring r = 0,(f2,f1),dp;
     1698  string s = "f2*f1*f1 - 2*f1*f2*f1+ f1*f1*f2";
     1699  sent2lplace(s); 
     1700}
     1701
     1702proc testnumber(string s)
     1703{
     1704  string t;
     1705  if (s[1]=="-")
     1706  {
     1707    // two situations: either there's a negative number
     1708    t = s[2..size(s)];
     1709    if (testnumber(t))
     1710    {
     1711      //a negative number
     1712    }
     1713    else
     1714    {
     1715      // a variable times -1
     1716    }
     1717    // or just a "-" for -1
     1718  }
     1719  t = "ring @r=(";
     1720  t = t + charstr(basering)+"),";
     1721  t = t + string(var(1))+",dp;";
     1722  //  write(":w tstnum.tst",t);
     1723  t = t+ "number @@Nn = " + s + ";"+"$";
     1724  write(":w tstnum.tst",t);
     1725  string runsing = system("Singular");
     1726  int k;
     1727  t = runsing+ " -teq <tstnum.tst >tstnum.out";
     1728  k = system("sh",t);
     1729  if (k!=0)
     1730  {
     1731    ERROR("Problems running Singular");
     1732  }
     1733  int i = system("sh", "grep error tstnum.out > /dev/NULL");
     1734  if (i!=0)
     1735  {
     1736    // no error: s is a number
     1737    i = 1;
     1738  }
     1739  k = system("sh","rm tstnum.tst tstnum.out > /dev/NULL");
     1740  return(i);
     1741}
     1742example
     1743{
     1744  "EXAMPLE:"; echo = 2;
     1745  ring r = (0,a),x,dp;
     1746  string s = "a^2+7*a-2";
     1747  testnumber(s); 
     1748  s = "b+a";
     1749  testnumber(s); 
     1750}
     1751
     1752proc str2lplace(string s)
     1753{
     1754  // converts a word (monomial) with coeff into letter-place
     1755  // string: coef*var1^exp1*var2^exp2*...varN^expN
     1756  s = strpower2rep(s); // expand powers
     1757  if (size(s)==0) { return(0); }
     1758  int i,j,k,insC;
     1759  string a,b,c,d,t;
     1760  // 1. get coeff
     1761  i = find(s,"*");
     1762  if (i==0) { return(s); }
     1763  list VN;
     1764  c = s[1..i-1]; // incl. the case like (-a^2+1)
     1765  int tn = testnumber(c);
     1766  if (tn == 0)
     1767  {
     1768    // failed test
     1769    if (c[1]=="-")
     1770    {
     1771      // two situations: either there's a negative number
     1772      t = c[2..size(c)];
     1773      if (testnumber(t))
     1774      {
     1775         //a negative number       
     1776        // nop here
     1777      }
     1778      else
     1779      {
     1780         // a variable times -1
     1781          c = "-1";
     1782          j++; VN[j] = t; //string(c[2..size(c)]);
     1783          insC = 1;
     1784      }
     1785    }
     1786    else
     1787    {
     1788      // just a variable with coeff 1
     1789          j++; VN[j] = string(c);
     1790          c = "1";
     1791          insC = 1;
     1792    }
     1793  }
     1794 // get vars
     1795  t = s;
     1796  //  t = s[i+1..size(s)];
     1797  k = size(t); //j = 0;
     1798  while (k>0)
     1799  {
     1800    t = t[i+1..size(t)]; //next part
     1801    i = find(t,"*"); // next *
     1802    if (i==0)
     1803    {
     1804      // last monomial
     1805      j++;
     1806      VN[j] = t;
     1807      k = size(t);
     1808      break;
     1809    }
     1810    b = t[1..i-1];
     1811    //    print(b);
     1812    j++;
     1813    VN[j] = b;
     1814    k = size(t);
     1815  }
     1816  VN = addplaces(VN);
     1817  VN[size(VN)+1] = string(c);
     1818  return(VN);
     1819}
     1820example
     1821{
     1822  "EXAMPLE:"; echo = 2;
     1823  ring r = (0,a),(f2,f1),dp;
     1824  str2lplace("-2*f2^2*f1^2*f2"); 
     1825  str2lplace("-f1*f2");
     1826  str2lplace("(-a^2+7a)*f1*f2");
     1827}
     1828
     1829proc strpower2rep(string s)
     1830{
     1831  // makes x*x*x*x out of x^4 ., rep statys for repetitions
     1832  // looks for "-" problem
     1833  // exception: "-" as coeff
     1834  string ex,t;
     1835  int i,j,k;
     1836
     1837  i = find(s,"^"); // first ^
     1838  if (i==0) { return(s); } // no ^ signs
     1839
     1840  if (s[1] == "-")
     1841  {
     1842    // either -coef or -1
     1843    // got the coeff:
     1844    i = find(s,"*");
     1845    if (i==0)
     1846    {
     1847      // no *'s   => coef == -1 or s == -23
     1848      i = size(s)+1;
     1849    }
     1850    t = string(s[2..i-1]); // without "-"
     1851    if ( testnumber(t) )
     1852    {
     1853      // a good number
     1854      t = strpower2rep(string(s[2..size(s)]));
     1855      t = "-"+t;
     1856      return(t);
     1857    }
     1858    else
     1859    {
     1860      // a variable
     1861      t = strpower2rep(string(s[2..size(s)]));
     1862      t = "-1*"+ t;
     1863      return(t);
     1864    }
     1865  }
     1866  // the case when leadcoef is a number in ()
     1867  if (s[1] == "(")
     1868  {
     1869    i = find(s,")",2);    // must be nonzero
     1870    t = s[2..i-1];
     1871    if ( testnumber(t) )
     1872    {
     1873      // a good number
     1874    }
     1875    else {"strpower2rep: bad number as coef";}
     1876    ex = string(s[i+2..size(s)]); // 2 because of *
     1877    ex =  strpower2rep(ex);
     1878    t = "("+t+")*"+ex;
     1879    return(t);
     1880  }
     1881
     1882  i = find(s,"^"); // first ^
     1883  j = find(s,"*",i+1); // next * == end of ^
     1884  if (j==0)
     1885  {
     1886    ex = s[i+1..size(s)];
     1887  }
     1888  else
     1889  {
     1890    ex = s[i+1..j-1];
     1891  }
     1892  execute("int @exp = " + ex + ";"); //@exp = exponent
     1893  // got varname
     1894  for (k=i-1; k>0; k--)
     1895  {
     1896    if (s[k] == "*") break;
     1897  }
     1898  string varn = s[k+1..i-1];
     1899  //  "varn:";  varn;
     1900  string pref;
     1901  if (k>0)
     1902  {
     1903    pref = s[1..k]; // with * on the k-th place 
     1904  }
     1905  //  "pref:";  pref;
     1906  string suf;
     1907  if ( (j>0) && (j+1 <= size(s)) )
     1908  {
     1909    suf = s[j+1..size(s)]; // without * on the 1st place
     1910  }
     1911  //  "suf:"; suf;
     1912  string toins;
     1913  for (k=1; k<=@exp; k++)
     1914  {
     1915    toins = toins + varn+"*";
     1916  }
     1917  //  "toins: ";  toins;
     1918  if (size(suf) == 0)
     1919  {
     1920    toins = toins[1..size(toins)-1]; // get rid of trailing *
     1921  }
     1922  else
     1923  {
     1924    suf = strpower2rep(suf);
     1925  }
     1926  ex = pref + toins + suf;
     1927  return(ex);
     1928  //  return(strpower2rep(ex));
     1929}
     1930example
     1931{
     1932  "EXAMPLE:"; echo = 2;
     1933  ring r = (0,a),(x,y,z,t),dp;
     1934  strpower2rep("-x^4"); 
     1935  strpower2rep("-2*x^4*y^3*z*t^2"); 
     1936  strpower2rep("-a^2*x^4"); 
     1937}
     1938
     1939proc Liebr(poly a, poly b)
     1940{
     1941  // alias ppLiebr
     1942  poly q;
     1943  while (b!=0)
     1944  {
     1945    q = q + pmLiebr(a,lead(b));
     1946    b = b - lead(b);
     1947  }
     1948  return(q);
     1949}
     1950example
     1951{
     1952  "EXAMPLE:"; echo = 2;
     1953  ring r = 0,(x(1),x(2),x(3),y(1),y(2),y(3)),dp;
     1954  poly a = x(1)*y(2); poly b = y(1);
     1955  int uptodeg=3; int lV=2;
     1956  export uptodeg; export lV;
     1957  Liebr(a,b);
     1958}
     1959
     1960proc pmLiebr(poly a, poly b)
     1961{
     1962  //  a poly, b mono
     1963  poly s;
     1964  while (a!=0)
     1965  {
     1966    s = s + mmLiebr(lead(a),lead(b));
     1967    a = a - lead(a);
     1968  }
     1969  return(s);
     1970}
     1971
     1972//proc pshift(poly a, int i, int uptodeg, int lV)
     1973proc pshift(poly a, int i)
     1974{
     1975  // shifts a monomial a by i
     1976  // calls pLPshift(p,sh,uptodeg,lVblock);
     1977  return(system("stest",a,i,uptodeg,lV));
     1978}
     1979
     1980proc mmLiebr(poly a, poly b)
     1981{
     1982  // a,b, monomials
     1983  a = lead(a);
     1984  b = lead(b);
     1985  int sa = deg(a); 
     1986  int sb = deg(b); 
     1987  poly v = a*pshift(b,sa) - b*pshift(a,sb);
     1988  return(v);
     1989}
     1990
     1991static proc test_shift()
     1992{
     1993  LIB "freegb.lib";
     1994  ring r = 0,(a,b),dp;
     1995  int d =5;
     1996  def R = freegbRing(d);
     1997  setring R;
     1998  int uptodeg = d; export uptodeg;
     1999  int lV = 2; export lV;
     2000  poly p = mmLiebr(a(1),b(1));
     2001  poly p = Liebr(a(1),b(1));
     2002}
     2003
     2004proc Serre(intmat A, int zu)
     2005{
     2006  // zu = 1 -> with commutators [f_i,f_j]; zu == 0 without them
     2007  // suppose that A is cartan matrix
     2008  // then Serre's relations are
     2009  // (ad f_j)^{1-A_{ij}} ( f_i)
     2010  int ppl = printlevel-voice+2;
     2011  int n = ncols(A); // hence n variables
     2012  int i,j,k,l;
     2013  poly p,q;
     2014  ideal I;
     2015  for (i=1; i<=n; i++)
     2016  {
     2017    for (j=1; j<=n; j++)
     2018    {
     2019      l = 1 - A[i,j];
     2020      //     printf("i:%s, j: %s, l: %s",i,j,l);
     2021      dbprint(ppl,"i, j, l: ",i,j,l);
     2022      //      if ((i!=j) && (l >0))
     2023      //      if ( (i!=j) &&  ( ((zu ==0) &&  (l >=2)) || ((zu ==1) &&  (l >=1)) ) )
     2024      if ((i!=j) && (l >0))
     2025      {
     2026        q = Liebr(var(j),var(i));
     2027        //        printf("first bracket: %s",q);
     2028        dbprint(ppl,"first bracket: ",q);
     2029        //        if (l >=2)
     2030        //        {
     2031          for (k=1; k<=l-1; k++)
     2032          {
     2033            q = Liebr(var(j),q);
     2034            //            printf("further bracket: %s",q);
     2035            dbprint(ppl,"further bracket:",q);
     2036          }
     2037          //        }
     2038      }
     2039      if (q!=0) { I = I,q; q=0;}
     2040    }
     2041  }
     2042  I = simplify(I,2);
     2043  return(I);
     2044}
     2045example
     2046{
     2047  "EXAMPLE:"; echo = 2;
     2048  intmat A[2][2] = 2, -1, -1, 2; // sl_3 == A_2
     2049  ring r = 0,(f1,f2),dp;
     2050  int uptodeg = 3; int lV = 2;
     2051  export uptodeg; export lV;
     2052  def R = freegbRing(uptodeg);
     2053  setring R;
     2054  ideal I = Serre(A,1);
     2055  I;
     2056  Serre(A,0);
     2057}
     2058
     2059proc lp2lstr(ideal K, def save)
     2060"USAGE:  lp2lstr(K,save); K an ideal, save a ring
     2061RETURN:  nothing (exports object LN into save)
     2062PURPOSE: converts letter-place ideal to list of modules
     2063EXAMPLE: example lp2lstr; shows examples
     2064"
     2065{
     2066  def @R = basering;
     2067  string err;
     2068  int s = nvars(save);
     2069  int i,j,k;
     2070    // K contains vars x(1),...z(1) = images of originals
     2071  // 5. go back to orig vars, produce strings/modules
     2072  int sk = size(K);
     2073  int sp, sx, a, b;
     2074  intvec x;
     2075  poly p,q;
     2076  poly pn;
     2077  // vars in 'save'
     2078  setring save;
     2079  module N;
     2080  list LN;
     2081  vector V;
     2082  poly pn;
     2083  // test and skip exponents >=2
     2084  setring @R;
     2085  for(i=1; i<=sk; i++)
     2086  {
     2087    p  = K[i];
     2088    while (p!=0)
     2089    {
     2090      q  = lead(p);
     2091      //      "processing q:";q;
     2092      x  = leadexp(q);
     2093      sx = size(x);
     2094      for(k=1; k<=sx; k++)
     2095      {
     2096        if ( x[k] >= 2 )
     2097        {
     2098          err = "skip: the value x[k] is " + string(x[k]);
     2099          dbprint(ppl,err);
     2100          //        return(0);
     2101          K[i] = 0;
     2102          p    = 0;
     2103          q    = 0;
     2104          break;
     2105        }
     2106      }
     2107      p  = p - q;
     2108    }
     2109  }
     2110  K  = simplify(K,2);
     2111  sk = size(K);
     2112  for(i=1; i<=sk; i++)
     2113  {
     2114    //    setring save;
     2115    //    V  = 0;
     2116    setring @R;
     2117    p  = K[i];
     2118    while (p!=0)
     2119    {
     2120      q  = lead(p);
     2121      err =  "processing q:" + string(q);
     2122      dbprint(ppl,err);
     2123      x  = leadexp(q);
     2124      sx = size(x);
     2125      pn = leadcoef(q);
     2126      setring save;
     2127      pn = imap(@R,pn);
     2128      V  = V + leadcoef(pn)*gen(1);
     2129      for(k=1; k<=sx; k++)
     2130      {
     2131        if (x[k] ==1)
     2132        {
     2133          a = k / s; // block number=a+1, a!=0
     2134          b = k % s; // remainder
     2135          //      printf("a: %s, b: %s",a,b);
     2136          if (b == 0)
     2137          {
     2138            // that is it's the last var in the block
     2139            b = s;
     2140            a = a-1;
     2141          }
     2142          V = V + var(b)*gen(a+2);
     2143        }
     2144      }
     2145      err = "V: " + string(V);
     2146      dbprint(ppl,err);
     2147      //      printf("V: %s", string(V));
     2148      N = N,V;
     2149      V  = 0;
     2150      setring @R;
     2151      p  = p - q;
     2152      pn = 0;
     2153    }
     2154    setring save;
     2155    LN[i] = simplify(N,2);
     2156    N     = 0;
     2157  }
     2158  setring save;
     2159  export LN;
     2160  //  return(LN);
     2161}
     2162example
     2163{
     2164  "EXAMPLE:"; echo = 2;
     2165  intmat A[2][2] = 2, -1, -1, 2; // sl_3 == A_2
     2166  ring r = 0,(f1,f2),dp;
     2167  int uptodeg = 3; int lV = 2;
     2168  export uptodeg; export lV;
     2169  def R = freegbRing(uptodeg);
     2170  setring R;
     2171  ideal I = Serre(A);
     2172  lp2lstr(I,r);
     2173  setring r;
     2174  lst2str(LN,1);
     2175  kill uptodeg; kill lV;
     2176}
     2177
     2178proc strList2poly(list L)
     2179{
     2180  //  list L comes from sent2lplace (which takes a poly on the input)
     2181  // each entry of L is a sublist with the coef on the last place
     2182  int s = size(L); int t;
     2183  int i,j;
     2184  list M;
     2185  poly p,q;
     2186  string Q;
     2187  for(i=1; i<=s; i++)
     2188  {
     2189    M = L[i];
     2190    t = size(M);
     2191    //    q = M[t]; // a constant
     2192    Q = string(M[t]);
     2193    for(j=1; j<t; j++)
     2194    {
     2195      //      q = q*M[j];
     2196      Q = Q+"*"+string(M[j]);
     2197    }
     2198    execute("q="+Q+";");
     2199    //    q;
     2200    p = p + q;
     2201  }
     2202  kill Q;
     2203  return(p);
     2204}
     2205example
     2206{
     2207  "EXAMPLE:"; echo = 2;
     2208  ring r =0,(x,y,z,t),Dp;
     2209  def A = freegbRing(4);
     2210  setring A;
     2211  string t = "-2*y*z*y*z + y*t*z*z - z*x*x*y  + 2*z*y*z*y";
     2212  list L = sent2lplace(t);
     2213  L;
     2214  poly p = strList2poly(L);
     2215  p;
     2216}
     2217
     2218proc file2lplace(string fname)
     2219{
     2220  string s = read(fname);
     2221  // assume: file is a comma-sep list of polys
     2222  // the vars are declared before
     2223  // ends with ";"
     2224  string t; int i;
     2225  ideal I;
     2226  list tst;
     2227  while (s!="")
     2228  {
     2229    i = find(s,",");
     2230    "i"; i;
     2231    if (i==0)
     2232    {
     2233      i = find(s,";");
     2234      if (i==0)
     2235      {
     2236        // no ; ??
     2237         "no colon or semicolon found anymore";
     2238         return(I);
     2239      }
     2240      // no "," but ";" on the i-th place
     2241      t = s[1..i-1];
     2242      s = "";
     2243      "processing: "; t;
     2244      tst = sent2lplace(t);
     2245      tst;
     2246      I = I, strList2poly(tst);
     2247      return(I);
     2248    }
     2249    // here i !=0
     2250    t = s[1..i-1];
     2251    s = s[i+1..size(s)];
     2252    "processing: "; t;
     2253    tst = sent2lplace(t);
     2254    tst;
     2255    I = I, strList2poly(tst);
     2256  }
     2257  return(I);
     2258}
     2259example
     2260{
     2261  "EXAMPLE:"; echo = 2;
     2262  ring r =0,(x,y,z,t),dp;
     2263  def A = freegbRing(4);
     2264  setring A;
     2265  string fn = "myfile";
     2266  string s1 = "z*y*y*y - 3*y*z*x*y  + 3*y*y*z*y - y*x*y*z,";
     2267  string s2 = "-2*y*x*y*z + y*y*z*z - z*z*y*y + 2*z*y*z*y,";
     2268  string s3 = "z*y*x*t - 2*y*z*y*t + y*y*z*t - t*z*y*y + 2*t*y*z*y - t*x*y*z;";
     2269  write(":w "+fn,s1);  write(":a "+fn,s2);   write(":a "+fn,s3);
     2270  read(fn);
     2271  ideal I = file2lplace(fn);
     2272  I;
     2273}
     2274
     2275static proc get_ls3nilp()
     2276{
     2277//first app of file2lplace
     2278  ring r =0,(x,y,z,t),dp;
     2279  int d = 10;
     2280  def A = freegbRing(d);
     2281  setring A;
     2282  ideal I = file2lplace("./ls3nilp.bg");
     2283  // and now test the correctness: go back from lplace to strings
     2284  lp2lstr(I,r);
     2285  setring r;
     2286  lst2str(LN,1); // agree!
     2287}
Note: See TracChangeset for help on using the changeset viewer.