Changeset 30b8381 in git for kernel/syz1.cc


Ignore:
Timestamp:
Jul 16, 2004, 10:43:01 AM (20 years ago)
Author:
Hans Schönemann <hannes@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
eb333f15264ff5eda5006038b3f9ee7fbfe87c41
Parents:
654b44a579d2278ad9f452357b30484f749a343f
Message:
*hannes: betti and weights (from 2-0-5)


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

Legend:

Unmodified
Added
Removed
  • kernel/syz1.cc

    r654b44 r30b8381  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: syz1.cc,v 1.8 2004-06-02 17:05:07 Singular Exp $ */
     4/* $Id: syz1.cc,v 1.9 2004-07-16 08:43:01 Singular Exp $ */
    55/*
    66* ABSTRACT: resolutions
     
    17281728}
    17291729
    1730 /*3
    1731 * read out the Betti numbers from resolution
    1732 * (if not LaScala calls the traditional Betti procedure)
    1733 */
    1734 intvec * syBettiOfComputation(syStrategy syzstr, BOOLEAN minim,int * row_shift)
    1735 {
    1736   int dummy;
    1737   if (syzstr->betti!=NULL)
    1738   {
    1739     if (minim || (syzstr->resPairs!=NULL))
    1740       return ivCopy(syzstr->betti);
    1741   }
    1742   intvec *result;
    1743   if (syzstr->resPairs!=NULL)
    1744   {
    1745     int i,j=-1,jj=-1,l,sh=0;
    1746     SRes rP=syzstr->resPairs;
    1747 
    1748     if (syzstr->hilb_coeffs!=NULL) sh = 1;
    1749     l = syzstr->length;
    1750     while ((l>0) && (rP[l-1]==NULL)) l--;
    1751     if (l==0) return NULL;
    1752     l--;
    1753     while (l>=sh)
    1754     {
    1755       i = 0;
    1756       while ((i<(*syzstr->Tl)[l]) &&
    1757         ((rP[l][i].lcm!=NULL) || (rP[l][i].syz!=NULL)))
    1758       {
    1759         if (rP[l][i].isNotMinimal==NULL)
    1760         {
    1761           if (j<rP[l][i].order-l)
    1762             j = rP[l][i].order-l;
    1763           if (jj<l)
    1764             jj = l;
    1765         }
    1766         i++;
    1767       }
    1768       l--;
    1769     }
    1770     j = j+sh;
    1771     jj = jj+2;
    1772     result=new intvec(j,jj-sh,0);
    1773     IMATELEM(*result,1,1)
    1774       = si_max(1,(int)idRankFreeModule(syzstr->res[1],
    1775                                (syzstr->syRing!=NULL?syzstr->syRing:currRing)));
    1776     for (i=sh;i<jj;i++)
    1777     {
    1778       j = 0;
    1779       while (j<(*syzstr->Tl)[i])
    1780       {
    1781         if ((rP[i][j].isNotMinimal==NULL)&&
    1782            ((rP[i][j].lcm!=NULL) || (rP[i][j].syz!=NULL)))
    1783           IMATELEM(*result,rP[i][j].order-i+sh,i+2-sh)++;
    1784         j++;
    1785       }
    1786     }
    1787   }
    1788   else if (syzstr->fullres!=NULL)
    1789     result = syBetti(syzstr->fullres,syzstr->length,&dummy,NULL,minim,row_shift);
    1790   else
    1791     result = syBetti(syzstr->minres,syzstr->length,&dummy,NULL,minim,row_shift);
    1792   if ((result!=NULL) && ((minim) || (syzstr->resPairs!=NULL)))
    1793     syzstr->betti = ivCopy(result);
    1794   return result;
    1795 }
    1796 
    1797 /*3
    1798 * computes the allocated length of the resolution
    1799 */
    1800 int syLength(syStrategy syzstr)
    1801 {
    1802   return syzstr->length;
    1803 }
    1804 
    1805 /*3
    1806 * computes the real length of the resolution
    1807 */
    1808 int sySize(syStrategy syzstr)
    1809 {
    1810   resolvente r=syzstr->res;
    1811   if (r==NULL)
    1812     r = syzstr->fullres;
    1813   if (r==NULL)
    1814     r = syzstr->minres;
    1815   if (r==NULL)
    1816   {
    1817     WerrorS("No resolution found");
    1818     return 0;
    1819   }
    1820   int i=syzstr->length;
    1821   while ((i>0) && (r[i-1]==NULL)) i--;
    1822   return i;
    1823 }
    1824 
    1825 /*3
    1826 * computes the cohomological dimension of res[1]
    1827 */
    1828 int syDim(syStrategy syzstr)
    1829 {
    1830   int i,j=-1,l;
    1831   if (syzstr->resPairs!=NULL)
    1832   {
    1833     SRes rP=syzstr->resPairs;
    1834 
    1835     l = syzstr->length;
    1836     while ((l>0) && (rP[l-1]==NULL)) l--;
    1837     if (l==0) return -1;
    1838     l--;
    1839     while (l>=0)
    1840     {
    1841       i = 0;
    1842       while ((i<(*syzstr->Tl)[l]) &&
    1843         ((rP[l][i].lcm!=NULL) || (rP[l][i].syz!=NULL)) &&
    1844         (rP[l][i].isNotMinimal!=NULL))
    1845       {
    1846         i++;
    1847       }
    1848       if ((i<(*syzstr->Tl)[l]) &&
    1849         ((rP[l][i].lcm!=NULL) || (rP[l][i].syz!=NULL)) &&
    1850         (rP[l][i].isNotMinimal==NULL))
    1851         return l;
    1852       l--;
    1853     }
    1854     return l;
    1855   }
    1856   else
    1857     return sySize(syzstr);
    1858 }
    1859 
    1860 /*3
    1861 * copies the resolution (by increment the reference counter)
    1862 */
    1863 syStrategy syCopy(syStrategy syzstr)
    1864 {
    1865   syStrategy result=syzstr;
    1866   (result->references)++;
    1867   return result;
    1868 }
    1869 
    1870 /*2
    1871 * local print procedure used in syPrint
    1872 */
    1873 static void syPrintEmptySpaces(int i)
    1874 {
    1875   if (i!=0)
    1876   {
    1877     PrintS(" ");
    1878     syPrintEmptySpaces(i/10);
    1879   }
    1880 }
    1881 
    1882 /*2
    1883 * local print procedure used in syPrint
    1884 */
    1885 static void syPrintEmptySpaces1(int i)
    1886 {
    1887   if (i!=0)
    1888   {
    1889     PrintS(" ");
    1890     syPrintEmptySpaces1(i-1);
    1891   }
    1892 }
    1893 
    1894 /*2
    1895 * local print procedure used in syPrint
    1896 */
    1897 static int syLengthInt(int i)
    1898 {
    1899   int j=0;
    1900 
    1901   if (i==0) return 1;
    1902   while (i!=0)
    1903   {
    1904     j++;
    1905     i = i/10;
    1906   }
    1907   return j;
    1908 }
    1909 
    1910 /*3
    1911 * prints the resolution as sequence of free modules
    1912 */
    1913 void syPrint(syStrategy syzstr)
    1914 {
    1915   if ((syzstr->resPairs==NULL) && (syzstr->fullres==NULL)
    1916      && (syzstr->minres==NULL))
    1917   {
    1918     PrintS("No resolution defined\n");
    1919     return;
    1920   }
    1921   int l=0;
    1922   if (syzstr->resolution==NULL)
    1923   {
    1924     int j;
    1925     if (syzstr->resPairs!=NULL)
    1926     {
    1927       syzstr->resolution = new intvec(syzstr->length+1);
    1928       SRes rP=syzstr->resPairs;
    1929       (*syzstr->resolution)[0]
    1930         = si_max(1,(int)idRankFreeModule(syzstr->res[1],
    1931                                  (syzstr->syRing != NULL ? syzstr->syRing : currRing)));
    1932       while ((l<syzstr->length) && (rP[l]!=NULL))
    1933       {
    1934         j=0;
    1935         while ((j<(*syzstr->Tl)[l]) &&
    1936           ((rP[l][j].lcm!=NULL) || (rP[l][j].syz!=NULL)))
    1937         {
    1938           if (rP[l][j].isNotMinimal==NULL)
    1939             ((*syzstr->resolution)[l+1])++;
    1940           j++;
    1941         }
    1942         l++;
    1943       }
    1944     }
    1945     else
    1946     {
    1947       resolvente rr;
    1948       syzstr->resolution = new intvec(syzstr->length+2);
    1949       if (syzstr->minres!=NULL)
    1950         rr = syzstr->minres;
    1951       else
    1952         rr = syzstr->fullres;
    1953       (*syzstr->resolution)[0]
    1954         = si_max(1,(int)idRankFreeModule(rr[0],
    1955                                  (syzstr->syRing != NULL ? syzstr->syRing : currRing)));
    1956       while ((l<syzstr->length) && (rr[l]!=NULL))
    1957       {
    1958         j = IDELEMS(rr[l]);
    1959         while ((j>0) && (rr[l]->m[j-1]==NULL)) j--;
    1960         ((*syzstr->resolution)[l+1]) = j;
    1961         l++;
    1962       }
    1963     }
    1964   }
    1965   char *sn=currRingHdl->id;
    1966   int sl=strlen(sn);
    1967   syPrintEmptySpaces1(sl);
    1968   l = 0;
    1969   loop
    1970   {
    1971     if ((l>=syzstr->resolution->length()) || ((*syzstr->resolution)[l]==0))
    1972       break;
    1973     Print("%d",(*syzstr->resolution)[l]);
    1974     syPrintEmptySpaces1(sl+5);
    1975     l++;
    1976   }
    1977   PrintLn();
    1978   l = 0;
    1979   loop
    1980   {
    1981     if ((l>=syzstr->resolution->length()) || ((*syzstr->resolution)[l]==0))
    1982       break;
    1983     PrintS(sn);
    1984     if (((l+1)>=syzstr->resolution->length()) || ((*syzstr->resolution)[(l+1)]==0))
    1985       break;
    1986     PrintS(" <-- ");
    1987     syPrintEmptySpaces((*syzstr->resolution)[l]);
    1988     l++;
    1989   }
    1990   PrintLn();
    1991   PrintLn();
    1992   l = 0;
    1993   loop
    1994   {
    1995     if ((l>=syzstr->resolution->length()) || ((*syzstr->resolution)[l]==0))
    1996       break;
    1997     Print("%d",l);
    1998     syPrintEmptySpaces1(sl+5+syLengthInt((*syzstr->resolution)[l])-
    1999                          syLengthInt(l));
    2000     l++;
    2001   }
    2002   PrintLn();
    2003   if (syzstr->minres==NULL)
    2004   {
    2005     PrintS("resolution not minimized yet");
    2006     PrintLn();
    2007   }
    2008 }
    2009 
    20101730/*2
    20111731* divides out the weight monomials (given by the Schreyer-ordering)
     
    21221842}
    21231843
     1844/*3
     1845* read out the Betti numbers from resolution
     1846* (if not LaScala calls the traditional Betti procedure)
     1847*/
     1848intvec * syBettiOfComputation(syStrategy syzstr, BOOLEAN minim,int * row_shift,
     1849                              intvec* weights)
     1850{
     1851  int dummy;
     1852  BOOLEAN std_weights=TRUE;
     1853  if ((weights!=NULL)
     1854  && (syzstr->betti!=NULL)
     1855  && (syzstr->weights!=NULL) && (syzstr->weights[0]!=NULL))
     1856  {
     1857    int i;
     1858    for(i=weights->length()-1; i>=0; i--)
     1859    {
     1860      //Print("test %d: %d - %d\n",i,(*weights)[i], (*(syzstr->weights[0]))[i]);
     1861      if ((*weights)[i]!=(*(syzstr->weights[0]))[i])
     1862      {
     1863        std_weights=FALSE;
     1864        break;
     1865      }
     1866    }
     1867  }
     1868  if ((syzstr->betti!=NULL)
     1869  && (std_weights))
     1870  {
     1871    if (minim || (syzstr->resPairs!=NULL))
     1872      return ivCopy(syzstr->betti);
     1873  }
     1874  if ((syzstr->fullres==NULL) && (syzstr->minres==NULL))
     1875  {
     1876     if (syzstr->hilb_coeffs==NULL)
     1877     {
     1878        syzstr->fullres = syReorder(syzstr->res,syzstr->length,syzstr);
     1879     }
     1880     else
     1881     {
     1882        syzstr->minres = syReorder(syzstr->orderedRes,syzstr->length,syzstr);
     1883        syKillEmptyEntres(syzstr->minres,syzstr->length);
     1884     }
     1885   }
     1886  intvec *result=NULL;
     1887  if (syzstr->fullres!=NULL)
     1888    result = syBetti(syzstr->fullres,syzstr->length,&dummy,weights,minim,row_shift);
     1889  else
     1890    result = syBetti(syzstr->minres,syzstr->length,&dummy,weights,minim,row_shift);
     1891  if ((result!=NULL)
     1892  && ((minim) || (syzstr->resPairs!=NULL))
     1893  && std_weights)
     1894  {
     1895    syzstr->betti = ivCopy(result);
     1896  }
     1897  return result;
     1898}
     1899
     1900/*3
     1901* computes the allocated length of the resolution
     1902*/
     1903int syLength(syStrategy syzstr)
     1904{
     1905  return syzstr->length;
     1906}
     1907
     1908/*3
     1909* computes the real length of the resolution
     1910*/
     1911int sySize(syStrategy syzstr)
     1912{
     1913  resolvente r=syzstr->res;
     1914  if (r==NULL)
     1915    r = syzstr->fullres;
     1916  if (r==NULL)
     1917    r = syzstr->minres;
     1918  if (r==NULL)
     1919  {
     1920    WerrorS("No resolution found");
     1921    return 0;
     1922  }
     1923  int i=syzstr->length;
     1924  while ((i>0) && (r[i-1]==NULL)) i--;
     1925  return i;
     1926}
     1927
     1928/*3
     1929* computes the cohomological dimension of res[1]
     1930*/
     1931int syDim(syStrategy syzstr)
     1932{
     1933  int i,j=-1,l;
     1934  if (syzstr->resPairs!=NULL)
     1935  {
     1936    SRes rP=syzstr->resPairs;
     1937
     1938    l = syzstr->length;
     1939    while ((l>0) && (rP[l-1]==NULL)) l--;
     1940    if (l==0) return -1;
     1941    l--;
     1942    while (l>=0)
     1943    {
     1944      i = 0;
     1945      while ((i<(*syzstr->Tl)[l]) &&
     1946        ((rP[l][i].lcm!=NULL) || (rP[l][i].syz!=NULL)) &&
     1947        (rP[l][i].isNotMinimal!=NULL))
     1948      {
     1949        i++;
     1950      }
     1951      if ((i<(*syzstr->Tl)[l]) &&
     1952        ((rP[l][i].lcm!=NULL) || (rP[l][i].syz!=NULL)) &&
     1953        (rP[l][i].isNotMinimal==NULL))
     1954        return l;
     1955      l--;
     1956    }
     1957    return l;
     1958  }
     1959  else
     1960    return sySize(syzstr);
     1961}
     1962
     1963/*3
     1964* copies the resolution (by increment the reference counter)
     1965*/
     1966syStrategy syCopy(syStrategy syzstr)
     1967{
     1968  syStrategy result=syzstr;
     1969  (result->references)++;
     1970  return result;
     1971}
     1972
     1973/*2
     1974* local print procedure used in syPrint
     1975*/
     1976static void syPrintEmptySpaces(int i)
     1977{
     1978  if (i!=0)
     1979  {
     1980    PrintS(" ");
     1981    syPrintEmptySpaces(i/10);
     1982  }
     1983}
     1984
     1985/*2
     1986* local print procedure used in syPrint
     1987*/
     1988static void syPrintEmptySpaces1(int i)
     1989{
     1990  if (i!=0)
     1991  {
     1992    PrintS(" ");
     1993    syPrintEmptySpaces1(i-1);
     1994  }
     1995}
     1996
     1997/*2
     1998* local print procedure used in syPrint
     1999*/
     2000static int syLengthInt(int i)
     2001{
     2002  int j=0;
     2003
     2004  if (i==0) return 1;
     2005  while (i!=0)
     2006  {
     2007    j++;
     2008    i = i/10;
     2009  }
     2010  return j;
     2011}
     2012
     2013/*3
     2014* prints the resolution as sequence of free modules
     2015*/
     2016void syPrint(syStrategy syzstr)
     2017{
     2018  if ((syzstr->resPairs==NULL) && (syzstr->fullres==NULL)
     2019     && (syzstr->minres==NULL))
     2020  {
     2021    PrintS("No resolution defined\n");
     2022    return;
     2023  }
     2024  int l=0;
     2025  if (syzstr->resolution==NULL)
     2026  {
     2027    int j;
     2028    if (syzstr->resPairs!=NULL)
     2029    {
     2030      syzstr->resolution = new intvec(syzstr->length+1);
     2031      SRes rP=syzstr->resPairs;
     2032      (*syzstr->resolution)[0]
     2033        = si_max(1,(int)idRankFreeModule(syzstr->res[1],
     2034                                 (syzstr->syRing != NULL ? syzstr->syRing : currRing)));
     2035      while ((l<syzstr->length) && (rP[l]!=NULL))
     2036      {
     2037        j=0;
     2038        while ((j<(*syzstr->Tl)[l]) &&
     2039          ((rP[l][j].lcm!=NULL) || (rP[l][j].syz!=NULL)))
     2040        {
     2041          if (rP[l][j].isNotMinimal==NULL)
     2042            ((*syzstr->resolution)[l+1])++;
     2043          j++;
     2044        }
     2045        l++;
     2046      }
     2047    }
     2048    else
     2049    {
     2050      resolvente rr;
     2051      syzstr->resolution = new intvec(syzstr->length+2);
     2052      if (syzstr->minres!=NULL)
     2053        rr = syzstr->minres;
     2054      else
     2055        rr = syzstr->fullres;
     2056      (*syzstr->resolution)[0]
     2057        = si_max(1,(int)idRankFreeModule(rr[0],
     2058                                 (syzstr->syRing != NULL ? syzstr->syRing : currRing)));
     2059      while ((l<syzstr->length) && (rr[l]!=NULL))
     2060      {
     2061        j = IDELEMS(rr[l]);
     2062        while ((j>0) && (rr[l]->m[j-1]==NULL)) j--;
     2063        ((*syzstr->resolution)[l+1]) = j;
     2064        l++;
     2065      }
     2066    }
     2067  }
     2068  char *sn=currRingHdl->id;
     2069  int sl=strlen(sn);
     2070  syPrintEmptySpaces1(sl);
     2071  l = 0;
     2072  loop
     2073  {
     2074    if ((l>=syzstr->resolution->length()) || ((*syzstr->resolution)[l]==0))
     2075      break;
     2076    Print("%d",(*syzstr->resolution)[l]);
     2077    syPrintEmptySpaces1(sl+5);
     2078    l++;
     2079  }
     2080  PrintLn();
     2081  l = 0;
     2082  loop
     2083  {
     2084    if ((l>=syzstr->resolution->length()) || ((*syzstr->resolution)[l]==0))
     2085      break;
     2086    PrintS(sn);
     2087    if (((l+1)>=syzstr->resolution->length()) || ((*syzstr->resolution)[(l+1)]==0))
     2088      break;
     2089    PrintS(" <-- ");
     2090    syPrintEmptySpaces((*syzstr->resolution)[l]);
     2091    l++;
     2092  }
     2093  PrintLn();
     2094  PrintLn();
     2095  l = 0;
     2096  loop
     2097  {
     2098    if ((l>=syzstr->resolution->length()) || ((*syzstr->resolution)[l]==0))
     2099      break;
     2100    Print("%d",l);
     2101    syPrintEmptySpaces1(sl+5+syLengthInt((*syzstr->resolution)[l])-
     2102                         syLengthInt(l));
     2103    l++;
     2104  }
     2105  PrintLn();
     2106  if (syzstr->minres==NULL)
     2107  {
     2108    PrintS("resolution not minimized yet");
     2109    PrintLn();
     2110  }
     2111}
     2112
    21242113/*2
    21252114* deleting all monomials the component of which correspond
Note: See TracChangeset for help on using the changeset viewer.