]> www.ginac.de Git - ginac.git/commitdiff
- Cleanup and clarifications.
authorRichard Kreckel <Richard.Kreckel@uni-mainz.de>
Tue, 14 Mar 2000 19:39:00 +0000 (19:39 +0000)
committerRichard Kreckel <Richard.Kreckel@uni-mainz.de>
Tue, 14 Mar 2000 19:39:00 +0000 (19:39 +0000)
- Addition of sparse expression trees (to be used at a later stage).

check/exam_lsolve.cpp
check/genex.cpp
check/time_toeplitz.cpp
check/time_vandermonde.cpp

index dfa71da22d9439d5786e0e0c639f61a39b842330..bcbc25fee3959e1ff951c5fb78f313b86a832c87 100644 (file)
@@ -98,7 +98,7 @@ static unsigned exam_lsolve2b(void)
 
 static unsigned exam_lsolve2c(void)
 {
-    // An example from the Maple online help.
+    // A more interesting example from the Maple online help.
     unsigned result = 0;
     symbol x("x"), y("y");
     lst eqns, vars;
index 77ea18fdb0d89da8afa3f0062f129c7f9476b0d7..eabfa122598d639e3e2caea10e685fe6d11a41f2 100644 (file)
@@ -1,7 +1,7 @@
 /** @file genex.cpp
  *
- *  Provides some routines for generating expressions that are later used as input
- *  in the consistency checks. */
+ *  Provides some routines for generating expressions that are later used as 
+ *  input in the consistency checks. */
 
 /*
  *  GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany
@@ -44,7 +44,8 @@ dense_univariate_poly(const symbol & x, unsigned degree)
 }
 
 /* Create a dense bivariate random polynomial in x1 and x2.
- * (of the form 9 + 52*x1 - 27*x1^2 + 84*x2 + 7*x2^2 - 12*x1*x2 if degree ==2) */
+ * (of the form 9 + 52*x1 - 27*x1^2 + 84*x2 + 7*x2^2 - 12*x1*x2 if degree==2)
+ */
 const ex
 dense_bivariate_poly(const symbol & x1, const symbol & x2, unsigned degree)
 {
@@ -56,3 +57,75 @@ dense_bivariate_poly(const symbol & x1, const symbol & x2, unsigned degree)
     
     return bipoly;
 }
+
+const ex
+random_symbol(const symbol & x,
+              const symbol & y,
+              const symbol & z,
+              bool rational = true)
+{
+    ex e;
+    switch (abs(rand()) % 4) {
+        case 0:
+            e = x;
+            break;
+        case 1:
+            e = y;
+            break;
+        case 2:
+            e = z;
+            break;
+        case 3: {
+            int c1 = rand() % 20 - 10;
+            int c2 = rand() % 20 - 10;
+            if (c1 == 0) c1 = 1;
+            if (c2 == 0) c2 = 1;
+            if (!rational)
+                c2 = 1;
+            e = numeric(c1) / numeric(c2);
+            break;
+        }
+    }
+    return e;
+}
+
+/* Create a sparse random tree in three symbols. */
+const ex
+sparse_tree(const symbol & x,
+            const symbol & y,
+            const symbol & z,
+            int level,
+            bool trig = false,    // true includes trigonomatric functions
+            bool rational = true) // false includes coefficients in Q
+{
+    if (level == 0)
+        return random_symbol(x,y,z,rational);
+    switch (abs(rand()) % 7) {
+    case 0:
+    case 1:
+        return add(sparse_tree(x,y,z,level-1, trig, rational),
+                       sparse_tree(x,y,z,level-1, trig, rational));
+        case 2:
+        case 3:
+            return mul(sparse_tree(x,y,z,level-1, trig, rational),
+                       sparse_tree(x,y,z,level-1, trig, rational));
+        case 4:
+        case 5:
+            return power(sparse_tree(x,y,z,level-1, trig, rational),
+                         abs(rand() % 4));
+        case 6:
+            if (trig) {
+                switch (abs(rand()) % 4) {
+                    case 0:
+                        return sin(sparse_tree(x,y,z,level-1, trig, rational));
+                    case 1:
+                        return cos(sparse_tree(x,y,z,level-1, trig, rational));
+                    case 2:
+                        return exp(sparse_tree(x,y,z,level-1, trig, rational));
+                    case 3:
+                        return log(sparse_tree(x,y,z,level-1, trig, rational));
+                }
+            } else
+                return random_symbol(x,y,z,rational);
+    }
+}
index 6f138d3e50c94d6d1489acc5298e0b5723a0019f..8390ea267d2cb269bee0d29bfcb984a8eaded9f6 100644 (file)
@@ -41,11 +41,12 @@ static unsigned toeplitz_det(unsigned size)
     
     // construct Toeplitz matrix:
     matrix M(size,size);
-    for (unsigned ro=0; ro<size; ++ro)
+    for (unsigned ro=0; ro<size; ++ro) {
         for (unsigned nd=ro; nd<size; ++nd) {
             M.set(nd-ro,nd,p[ro]);
             M.set(nd,nd-ro,p[ro]);
         }
+    }
     
     // compute determinant:
     ex tdet = M.determinant();
index 364ca5a5ec8c340302494a53f261fa0304e26169..cfef6ea2be13b94777c095f2f19949db174f1a7f 100644 (file)
@@ -33,12 +33,14 @@ static unsigned vandermonde_det(unsigned size)
     
     // construct Vandermonde matrix:
     matrix M(size,size);
-    for (unsigned ro=0; ro<size; ++ro)
-        for (unsigned co=0; co<size; ++co)
+    for (unsigned ro=0; ro<size; ++ro) {
+        for (unsigned co=0; co<size; ++co) {
             if (ro%2)
                 M.set(ro,co,pow(-pow(a,1+ro/2),co));
             else
                 M.set(ro,co,pow(pow(a,1+ro/2),co));
+        }
+    }
     
     // compute determinant:
     ex vdet = M.determinant();