[SCM] an open source computer algebra system branch, cleanedupstream, updated. 6125e540ca6d66c307958938a9d53b245507c323

Bernhard R. Link brlink at debian.org
Tue Apr 24 15:55:41 UTC 2012


The following commit has been merged in the cleanedupstream branch:
commit bab5749445d9f3f639baa0265f8732d9119745f9
Author: Hans Schoenemann <hannes at mathematik.uni-kl.de>
Date:   Thu Apr 19 21:22:43 2012 +0200

    chg: bigintmat ops: print, String etc.

diff --git a/Singular/iparith.cc b/Singular/iparith.cc
index 1de832b..d6c7927 100644
--- a/Singular/iparith.cc
+++ b/Singular/iparith.cc
@@ -4921,6 +4921,7 @@ static BOOLEAN jjTYPEOF(leftv res, leftv v)
     case RING_CMD:       res->data=omStrDup("ring"); break;
     case QRING_CMD:      res->data=omStrDup("qring"); break;
     case INTMAT_CMD:     res->data=omStrDup("intmat"); break;
+    case BIGINTMAT_CMD:  res->data=omStrDup("bigintmat"); break;
     case NUMBER_CMD:     res->data=omStrDup("number"); break;
     case BIGINT_CMD:     res->data=omStrDup("bigint"); break;
     case LIST_CMD:       res->data=omStrDup("list"); break;
diff --git a/Singular/ipassign.cc b/Singular/ipassign.cc
index 14722c4..487ad76 100644
--- a/Singular/ipassign.cc
+++ b/Singular/ipassign.cc
@@ -495,17 +495,8 @@ static BOOLEAN jiA_INTVEC(leftv res, leftv a, Subexpr e)
   //if ((res->data==NULL) || (res->Typ()==a->Typ()))
   {
     if (res->data!=NULL) delete ((intvec *)res->data);
-    switch (a->Typ())
-    {
-      case INTMAT_CMD:
-      case INTVEC_CMD:
-        res->data=(void *)a->CopyD(INTVEC_CMD);
-        jiAssignAttr(res,a);
-        break;
-      case BIGINTMAT_CMD:
-        res->data=(void *)bim2iv((bigintmat *)a->Data());
-        break;
-    }
+    res->data=(void *)a->CopyD(INTVEC_CMD);
+    jiAssignAttr(res,a);
     return FALSE;
   }
 #if 0
@@ -525,16 +516,8 @@ static BOOLEAN jiA_INTVEC(leftv res, leftv a, Subexpr e)
 static BOOLEAN jiA_BIGINTMAT(leftv res, leftv a, Subexpr e)
 {
   if (res->data!=NULL) delete ((bigintmat *)res->data);
-  switch (a->Typ())
-  {
-    case BIGINTMAT_CMD:
-      res->data=(void *)a->CopyD(BIGINTMAT_CMD);
-      jiAssignAttr(res,a);
-      break;
-    case INTMAT_CMD:
-      res->data=(void *)iv2bim((intvec *)a->Data());
-      break;
-  }
+  res->data=(void *)a->CopyD(BIGINTMAT_CMD);
+  jiAssignAttr(res,a);
   return FALSE;
 }
 static BOOLEAN jiA_IDEAL(leftv res, leftv a, Subexpr e)
diff --git a/Singular/ipconv.cc b/Singular/ipconv.cc
index 5b92f58..bfa8125 100644
--- a/Singular/ipconv.cc
+++ b/Singular/ipconv.cc
@@ -8,6 +8,7 @@
 #include <kernel/mod2.h>
 #include <Singular/tok.h>
 #include <Singular/ipid.h>
+#include <kernel/bigintmat.h>
 #include <kernel/intvec.h>
 #include <kernel/options.h>
 #include <omalloc/omalloc.h>
@@ -183,6 +184,16 @@ static void * iiIm2Ma(void *data)
   return (void *)m;
 }
 
+static void * iiIm2Bim(void *data)
+{
+  return (void *)iv2bim((intvec*)data);
+}
+
+static void * iiBim2Im(void *data)
+{
+  return (void *)bim2iv((bigintmat*)data);
+}
+
 static void * iiN2P(void *data)
 {
   poly p=NULL;
diff --git a/Singular/ipshell.cc b/Singular/ipshell.cc
index d4d43da..186635f 100644
--- a/Singular/ipshell.cc
+++ b/Singular/ipshell.cc
@@ -231,6 +231,8 @@ void type_cmd(leftv v)
     case MAP_CMD:Print(" from %s\n",((map)(v->Data()))->preimage); break;
     case INTMAT_CMD: Print(" %d x %d\n",((intvec*)(v->Data()))->rows(),
                                       ((intvec*)(v->Data()))->cols()); break;
+    case BIGINTMAT_CMD: Print(" %d x %d\n",((bigintmat*)(v->Data()))->rows(),
+                                      ((bigintmat*)(v->Data()))->cols()); break;
     case MATRIX_CMD:Print(" %u x %u\n" ,
        MATROWS((matrix)(v->Data())),
        MATCOLS((matrix)(v->Data())));break;
diff --git a/Singular/subexpr.cc b/Singular/subexpr.cc
index dce9630..0a5c03e 100644
--- a/Singular/subexpr.cc
+++ b/Singular/subexpr.cc
@@ -116,8 +116,7 @@ void sleftv::Print(leftv store, int spaces)
           ((intvec *)d)->show(t,spaces);
           break;
         case BIGINTMAT_CMD:
-          ((bigintmat *)d)->print();
-         // PrintS(((bigintmat *)d)->prettyprint(spaces));
+          ((bigintmat *)d)->pprint(80);
           break;
         case RING_CMD:
         case QRING_CMD:
@@ -814,7 +813,20 @@ char *  sleftv::String(void *d, BOOLEAN typed, int dim)
           else
             return s;
         }
-
+        case BIGINTMAT_CMD:
+        {
+          bigintmat *bim=(bigintmat*)d;
+          s = bim->String();
+          if (typed)
+          {
+            char* ns = (char*) omAlloc0(strlen(s) + 40);
+            sprintf(ns, "bigintmat(bigintvec(%s),%d,%d)", s, bim->rows(), bim->cols());
+            omCheckAddr(ns);
+            return ns;
+          }
+          else
+            return omStrDup(s);
+        } 
         case RING_CMD:
         case QRING_CMD:
           s  = rString((ring)d);
diff --git a/Singular/table.h b/Singular/table.h
index aad00ce..b495f42 100644
--- a/Singular/table.h
+++ b/Singular/table.h
@@ -1120,6 +1120,10 @@ struct sConvertTypes dConvertTypes[] =
    { INTVEC_CMD,      INTMAT_CMD,     D(iiDummy), NULL },
 //  intvec -> matrix
    { INTVEC_CMD,      MATRIX_CMD,     D(iiIm2Ma) , NULL },
+//  intmat -> bigintmat
+   { INTMAT_CMD,      BIGINTMAT_CMD,  D(iiIm2Bim) , NULL },
+//  bigintmat -> intmat
+   { BIGINTMAT_CMD,   INTMAT_CMD,     D(iiBim2Im) , NULL },
 //  intmat -> matrix
    { INTMAT_CMD,      MATRIX_CMD,     D(iiIm2Ma) , NULL },
 //  number -> poly
@@ -1186,9 +1190,7 @@ struct sValAssign dAssign[]=
 ,{D(jiA_INTVEC),   INTVEC_CMD,     INTVEC_CMD }
 ,{D(jiA_INTVEC),   INTMAT_CMD,     INTMAT_CMD }
 //,{D(jiA_INTVEC),   INTMAT_CMD,     INTVEC_CMD }
-,{D(jiA_INTVEC),   INTMAT_CMD,     BIGINTMAT_CMD}
 ,{D(jiA_BIGINTMAT),BIGINTMAT_CMD,  BIGINTMAT_CMD}
-,{D(jiA_BIGINTMAT),BIGINTMAT_CMD,  INTMAT_CMD }
 ,{D(jiA_NUMBER),   NUMBER_CMD,     NUMBER_CMD }
 ,{D(jiA_BIGINT),   BIGINT_CMD,     BIGINT_CMD }
 ,{D(jiA_LIST_RES), LIST_CMD,       RESOLUTION_CMD }
diff --git a/kernel/bigintmat.cc b/kernel/bigintmat.cc
index 11ab3b1..38a9fe5 100644
--- a/kernel/bigintmat.cc
+++ b/kernel/bigintmat.cc
@@ -1,33 +1,18 @@
-/* Probleme:
-3) Ausgabe als String fehlt noch
-5) Welche der eingebundenen Dateien werden wirklich benötigt?
-
-in Makefile.in
-Dateien eintragen, in /SIngular/ config.status ausführen
-
-table.h in /Singular/
-
-
-//spielwiese
-autogen.sh
-
-/libpoly/misc/Makefile.am
-*/
 /*****************************************
 *  Computer Algebra System SINGULAR      *
 *****************************************/
 /*
 * ABSTRACT: class bigintmat: matrizes of big integers
 */
-#include <kernel/mod2.h>                     
-#include <kernel/febase.h>                     
-#include <kernel/options.h>                        
+#include <kernel/mod2.h>
+#include <kernel/febase.h>
+#include <kernel/options.h>
 #include <kernel/bigintmat.h>
-#include <omalloc/omalloc.h>                    
-#include <kernel/longrat.h>                   
-#include <kernel/intvec.h>  
-#include <math.h>        
-#include <string.h>        
+#include <omalloc/omalloc.h>
+#include <kernel/longrat.h>
+#include <kernel/intvec.h>
+#include <math.h>
+#include <string.h>
 
 #define BIGIMATELEM(M,I,J) (M)[(I-1)*(M).cols()+J-1]
 
@@ -79,11 +64,11 @@ void bigintmat::operator*=(int intop)
 {
   for (int i=0; i<row*col; i++)
   {
-  	number iop = nlInit(intop, NULL);
-  	number prod = nlMult(v[i], iop);
-  	nlDelete(&(v[i]), NULL);
-  	nlDelete(&iop, NULL);
-  	v[i] = prod;
+          number iop = nlInit(intop, NULL);
+          number prod = nlMult(v[i], iop);
+          nlDelete(&(v[i]), NULL);
+          nlDelete(&iop, NULL);
+          v[i] = prod;
   }
 }
 
@@ -91,9 +76,9 @@ void bigintmat::operator*=(number bintop)
 {
   for (int i=0; i<row*col; i++)
   {
-  	number prod = nlMult(v[i], bintop);
-  	nlDelete(&(v[i]), NULL);
-  	v[i] = prod;
+          number prod = nlMult(v[i], bintop);
+          nlDelete(&(v[i]), NULL);
+          v[i] = prod;
   }
 }
 
@@ -108,7 +93,7 @@ bool operator==(bigintmat & lhr, bigintmat & rhr)
   if (lhr.rows() != rhr.rows()) { return false; }
   for (int i=0; i<(lhr.rows())*(lhr.cols()); i++)
   {
-    if (!nlEqual(lhr[i], rhr[i])) { return false; }  
+    if (!nlEqual(lhr[i], rhr[i])) { return false; }
   }
   return true;
 }
@@ -139,7 +124,7 @@ bigintmat * bimAdd(bigintmat * a, bigintmat * b)
     {
       if (ma == a->rows())
       {
-        for(i=mn; i<ma; i++) 
+        for(i=mn; i<ma; i++)
         {
           bim->set(i, (*a)[i]);
         }
@@ -160,7 +145,7 @@ bigintmat * bimAdd(bigintmat * a, bigintmat * b)
   {
     number n = nlAdd((*a)[i], (*b)[i]);
     bim->set(i, n);
-    nlDelete(&n, NULL); 
+    nlDelete(&n, NULL);
   }
   return bim;
 }
@@ -185,7 +170,7 @@ bigintmat * bimSub(bigintmat * a, bigintmat * b)
     {
       if (ma == a->rows())
       {
-        for(i=mn; i<ma; i++) 
+        for(i=mn; i<ma; i++)
         {
           bim->set(i, (*a)[i]);
         }
@@ -312,64 +297,202 @@ bigintmat * bimCopy(const bigintmat * b)
   return a;
 }
 
-void bigintmat::print()
+char* bigintmat::String()
 {
   StringSetS("");
-  for (int i=0; i<col*row; i++)
+  int i;
+  for (i=0; i<col*row-1; i++)
   {
-    //int n = nlInt(v[i], NULL);
-    //char tmp[10];
-    //sprintf(tmp, "%d", n);
     nlWrite(v[i], NULL);
-    //PrintS(tmp); //
-    if (i != col*row-1)
+    StringAppendS(",");
+  }
+  nlWrite(v[i], NULL);
+   /* if (i != col*row-1)
     {
-      StringAppend(",");
+      StringAppendS(",");
       if ((i+1)%col == 0)
-        StringAppend("\n");
-    }    
-  }
-  PrintS(StringAppend(""));
+        StringAppendS("\n");
+    }   */
+  return StringAppendS("");
 }
 
-void bigintmat::prettyprint(int swid)
+int bigintmat::getwid(int maxwid)
 {
- // if (col*row == 0) return "";
-  int colwid = floor((swid-2*(col-1))/col); // Berechnung der Spaltenbreite (im Zweifel abrunden)
-  char * ps;
-  ps = (char*) omAlloc(sizeof(char)*(colwid*col+2*(col-1)+row-1));  //Reale Länge des Strings
-  int pos = 0;
+  int wid=0;
+  int colwid = floor((maxwid-2*(col-1))/col);
   for (int i=0; i<col*row; i++)
   {
-    SPrintStart();
+    StringSetS("");
     nlWrite(v[i], NULL);
-    char * ts = SPrintEnd();
-    int nl = strlen(ts); 
-    if (nl > colwid)  // Zu lange Zahl wird durch ### dargestellt
+    char * tmp = StringAppendS("");
+    char * ts = omStrDup(tmp);
+    int nl = strlen(ts);
+    if (nl > wid)
     {
-      for (int j=0; j<colwid; j++)
-        ps[pos+j] = '#';
+      if (nl > colwid)
+      {
+        int phwid = floor(log10(row))+floor(log10(col))+5;
+        if ((colwid > phwid) && (wid < phwid))
+          wid = phwid;
+      }
+      else
+        wid = nl;
     }
-    else  // Mit Leerzeichen auffüllen und zahl reinschreiben
+  }
+  return wid;
+}
+
+void bigintmat::pprint(int maxwid)
+{
+  if ((col==0) || (row==0))
+    PrintS("");
+  else
+  {
+    int colwid = getwid(maxwid);
+    if (colwid*col+2*(col-1) > maxwid)
+      colwid = floor((maxwid-2*(col-1))/col);
+    char * ps;
+    ps = (char*) omAlloc0(sizeof(char)*(colwid*col*row+2*(col-1)*row+row));
+    int pos = 0;
+    for (int i=0; i<col*row; i++)
     {
-      for (int j=0; j<colwid-nl; j++)
-        ps[pos+j] = ' ';
-      for (int j=0; j<nl; j++)
-        ps[pos+colwid-nl+j] = ts[j];
+      StringSetS("");
+      nlWrite(v[i], NULL);
+      char * temp = StringAppendS("");
+      char * ts = omStrDup(temp);
+      int nl = strlen(ts);
+      if (nl > colwid)
+      {
+        StringSetS("");
+        int cj = i%col;
+        int ci = floor(i/col);
+        StringAppend("[%d,%d]", ci+1, cj+1);
+        char *tmp = StringAppendS("");
+        char * ph = omStrDup(tmp);
+        int phl = strlen(ph);
+        if (phl > colwid)
+        {
+          for (int j=0; j<colwid; j++)
+            ps[pos+j] = '*';
+        }
+        else
+        {
+          for (int j=0; j<colwid-phl; j++)
+            ps[pos+j] = ' ';
+          for (int j=0; j<phl; j++)
+            ps[pos+colwid-phl+j] = ph[j];
+        }
+        omFree(ph);
+      }
+      else  // Mit Leerzeichen auffüllen und zahl reinschreiben
+      {
+        for (int j=0; j<colwid-nl; j++)
+          ps[pos+j] = ' ';
+        for (int j=0; j<nl; j++)
+          ps[pos+colwid-nl+j] = ts[j];
+      }
+      // ", " oder "\n" einfügen
+      if ((i+1)%col == 0)
+      {
+        if (i != col*row-1)
+        {
+          ps[pos+colwid] = '\n';
+          pos += colwid+1;
+        }
+      }
+      else
+      {
+        ps[pos+colwid] = ',';
+        ps[pos+colwid+1] = ' ';
+        pos += colwid+2;
+      }
+    // Hier ts zerstören
     }
-    
-    // ", " oder "\n" einfügen
-    if (((i+1)%col == 0) && (i != col*row))
+    PrintS(ps);
+    omFree(ps);
+  }
+}
+
+// Ungetestet
+static void bimRowContent(bigintmat *bimat, int rowpos, int colpos)
+{
+  number tgcd, m;
+  int i=bimat->cols();
+
+  loop
+  {
+    tgcd = nlCopy(BIMATELEM(*bimat,rowpos,i--));
+    if (!nlIsZero(tgcd)) break;
+    if (i<colpos) return;
+  }
+  if ((!nlGreaterZero(tgcd)) && (!nlIsZero(tgcd))) tgcd = nlNeg(tgcd);
+  if (nlIsOne(tgcd)) return;
+  loop
+  {
+    m = nlCopy(BIMATELEM(*bimat,rowpos,i--));
+    if (!nlIsZero(m))
     {
-      ps[colwid] = '\n';
-      pos += colwid+1;
+      number tp1 = nlGcd(tgcd, m, NULL);
+      nlDelete(&tgcd, NULL);
+      tgcd = tp1;
     }
-    else
+    if (nlIsOne(tgcd)) return;
+    if (i<colpos) break;
+  }
+  for (i=bimat->cols();i>=colpos;i--)
+  {
+    number tp2 = nlDiv(BIMATELEM(*bimat,rowpos,i), tgcd);
+    nlDelete(&BIMATELEM(*bimat,rowpos,i), NULL);
+    BIMATELEM(*bimat,rowpos,i) = tp2;
+  }
+  nlDelete(&tgcd, NULL);
+  nlDelete(&m, NULL);
+}
+
+static void bimReduce(bigintmat *bimat, int rpiv, int colpos,
+                     int ready, int all)
+{
+  number tgcd, ce, m1, m2;
+  int j, i;
+  number piv = BIMATELEM(*bimat,rpiv,colpos);
+
+  for (j=all;j>ready;j--)
+  {
+    ce = nlCopy(BIMATELEM(*bimat,j,colpos));
+    if (!nlIsZero(ce))
     {
-      ps[colwid] = ',';
-      ps[colwid+1] = ' ';
-      pos += colwid+2;
+      nlDelete(&BIMATELEM(*bimat,j,colpos), NULL);
+      BIMATELEM(*bimat,j,colpos) = nlInit(0, NULL);
+      m1 = nlCopy(piv);
+      m2 = nlCopy(ce);
+      tgcd = nlGcd(m1, m2, NULL);
+      if (!nlIsOne(tgcd))
+      {
+        number tp1 = nlDiv(m1, tgcd);
+        number tp2 = nlDiv(m2, tgcd);
+        nlDelete(&m1, NULL);
+        nlDelete(&m2, NULL);
+        m1 = tp1;
+        m2 = tp2;
+      }
+      for (i=bimat->cols();i>colpos;i--)
+      {
+        nlDelete(&BIMATELEM(*bimat,j,i), NULL);
+        number tp1 = nlMult(BIMATELEM(*bimat,j,i), m1);
+        number tp2 = nlMult(BIMATELEM(*bimat,rpiv,i), m2);
+        BIMATELEM(*bimat,j,i) = nlSub(tp1, tp2);
+        nlDelete(&tp1, NULL);
+        nlDelete(&tp2, NULL);
+      }
+      bimRowContent(bimat, j, colpos+1);
+      nlDelete(&m1, NULL);
+      nlDelete(&m2, NULL);
     }
-  // Hier ts zerstören
+    nlDelete(&ce, NULL);
   }
 }
+
+
+
+
+
diff --git a/kernel/bigintmat.h b/kernel/bigintmat.h
index d4b4f40..fba30bc 100644
--- a/kernel/bigintmat.h
+++ b/kernel/bigintmat.h
@@ -7,10 +7,10 @@
 * ABSTRACT: class bigintmat: matrizes of big integers
 */
 #include <string.h>
-#include <omalloc/omalloc.h>  
-#include <kernel/febase.h>    
-#include <kernel/longrat.h>   
-#include <kernel/intvec.h>    
+#include <omalloc/omalloc.h>
+#include <kernel/febase.h>
+#include <kernel/longrat.h>
+#include <kernel/intvec.h>
 
 
 class bigintmat
@@ -42,8 +42,8 @@ public:
       }
     }
   }
-  
-  
+
+
   inline number& operator[](int i)
     {
 #ifndef NDEBUG
@@ -64,7 +64,7 @@ public:
 #endif
       return v[i];
     }
-    
+
 #define BIMATELEM(M,I,J) (M)[(I-1)*(M).cols()+J-1]
   void operator*=(int intop);
   void operator*=(number bintop);
@@ -83,9 +83,10 @@ public:
   number get(int i);
   void set(int i, int j, number n);
   void set(int i, number n);
-  void print();
-  void prettyprint(int swid);
+  char * String();
+  void pprint(int maxwid);
   int compare(const bigintmat* op) const;
+  int getwid(int maxwid);
 };
 bool operator==(bigintmat & lhr, bigintmat & rhr);
 bool operator!=(bigintmat & lhr, bigintmat & rhr);
@@ -94,6 +95,9 @@ bigintmat * bimSub(bigintmat * a, bigintmat * b);
 bigintmat * bimMult(bigintmat * a, bigintmat * b);
 intvec * bim2iv(bigintmat * b);
 bigintmat * bimCopy(const bigintmat * b);
+static void bimRowContent(bigintmat *bimat, int rowpos, int colpos);
+static void bimReduce(bigintmat *bimat, int rpiv, int colpos,
+                     int ready, int all);
 
 bigintmat * iv2bim(intvec * b);
 #endif

-- 
an open source computer algebra system



More information about the debian-science-commits mailing list