genius r665 - in trunk: . src



Author: jirka
Date: Sat Jun  7 18:02:47 2008
New Revision: 665
URL: http://svn.gnome.org/viewvc/genius?rev=665&view=rev

Log:

Sat Jun 07 13:02:21 2008  Jiri (George) Lebl <jirka 5z com>

	* src/matop.c, src/funclib.c, src/eval.c: Add a new flag to not do
	  backsubstitution in gauss if we are interested in nullspace and
	  the matrix is nonsingular
	
	* src/matop.c: fix the return value of gauss.  Singular means
	  nonempty nullspace, i.e. maximal row rank.  This also fixes
	  SolveLinearSystem which didn't work according to specs, i.e. it is
	  supposed to return null when solution is nonunique.

	* src/geniustests.txt: add more tests



Modified:
   trunk/ChangeLog
   trunk/NEWS
   trunk/src/eval.c
   trunk/src/funclib.c
   trunk/src/geniustests.txt
   trunk/src/matop.c
   trunk/src/matop.h

Modified: trunk/NEWS
==============================================================================
--- trunk/NEWS	(original)
+++ trunk/NEWS	Sat Jun  7 18:02:47 2008
@@ -5,18 +5,24 @@
 * Add "Save Console Output" menu item to save console contents
 * Add "Monitor a Variable" menu item to continuously monitor a single
   variable
+* Wrap nonmatrix output in "Show Full Answer"
 * Add IsMersennePrimeExponent, MersennePrimeExponents, IsDefined, undefine
-* QuadraticFormula built in and more numerically stable
+* CHANGE: zeros, ones, rand, randint, I, SetMatrixSize now accept 0 for size
+  and return null as an empty matrix.  wait, IndexComplement
+  accept 0 and act accordingly as well.
 * CHANGE: It's Fibonacci in correct spelling, short name is still fib
 * Calling internal functions is now slightly faster
+* QuadraticFormula built in and more numerically stable
 * Gaussian elimination is now faster, and more stable when nonrational
   matrices are involved
+* NullSpace slightly faster when the nullspace is empty
 * Other minor optimizations
+* Fix SolveLinearSystem (must return null on nonunique solutions)
 * Fix crash related to returning custom functions from functions
 * Fix some memory leaks
 * Documentation updates
-* Translations (Yannig Marchegay, Pawan Chitrakar, Jorge Gonzalez,
-  Jonh Wendell, moi)
+* Translations (L. Lommer, P. Kovar, Andre Klapper, Yannig Marchegay,
+  Pawan Chitrakar, Jorge Gonzalez, Jonh Wendell, et moi)
 
 Changes to 1.0.2
 

Modified: trunk/src/eval.c
==============================================================================
--- trunk/src/eval.c	(original)
+++ trunk/src/eval.c	Sat Jun  7 18:02:47 2008
@@ -2087,7 +2087,7 @@
 		/* FIXME: unfortunately the modulo logic of gauss is fucked */
 		old_modulo = ctx->modulo;
 		ctx->modulo = NULL;
-		if G_UNLIKELY (!gel_value_matrix_gauss(ctx,m,TRUE,FALSE,TRUE,NULL,mi)) {
+		if G_UNLIKELY (!gel_value_matrix_gauss(ctx,m,TRUE,FALSE,TRUE,FALSE,NULL,mi)) {
 			ctx->modulo = old_modulo;
 			gel_errorout (_("Matrix appears singular and can't be inverted"));
 			gel_matrixw_free(m);
@@ -2202,7 +2202,7 @@
 	/* FIXME: unfortunately the modulo logic of gauss is fucked */
 	old_modulo = ctx->modulo;
 	ctx->modulo = NULL;
-	if G_UNLIKELY (!gel_value_matrix_gauss(ctx,toinvert,TRUE,FALSE,TRUE,NULL,mi)) {
+	if G_UNLIKELY (!gel_value_matrix_gauss(ctx,toinvert,TRUE,FALSE,TRUE,FALSE,NULL,mi)) {
 		ctx->modulo = old_modulo;
 		gel_errorout (_("Matrix appears singular and can't be inverted"));
 		gel_matrixw_free(mi);
@@ -2268,7 +2268,7 @@
 	/* FIXME: unfortunately the modulo logic of gauss is fucked */
 	old_modulo = ctx->modulo;
 	ctx->modulo = NULL;
-	if G_UNLIKELY (!gel_value_matrix_gauss(ctx,m,TRUE,FALSE,TRUE,NULL,mi)) {
+	if G_UNLIKELY (!gel_value_matrix_gauss(ctx,m,TRUE,FALSE,TRUE,FALSE,NULL,mi)) {
 		ctx->modulo = old_modulo;
 		gel_errorout (_("Matrix appears singular and can't be inverted"));
 		gel_matrixw_free(mi);

Modified: trunk/src/funclib.c
==============================================================================
--- trunk/src/funclib.c	(original)
+++ trunk/src/funclib.c	Sat Jun  7 18:02:47 2008
@@ -3371,7 +3371,7 @@
 	GET_NEW_NODE(n);
 	n->type = MATRIX_NODE;
 	n->mat.matrix = gel_matrixw_copy(a[0]->mat.matrix);
-	gel_value_matrix_gauss (ctx, n->mat.matrix, FALSE, FALSE, FALSE, NULL, NULL);
+	gel_value_matrix_gauss (ctx, n->mat.matrix, FALSE, FALSE, FALSE, FALSE, NULL, NULL);
 	n->mat.quoted = FALSE;
 	return n;
 }
@@ -3386,7 +3386,7 @@
 	n->type = MATRIX_NODE;
 	n->mat.matrix = gel_matrixw_copy(a[0]->mat.matrix);
 	if ( ! n->mat.matrix->rref) {
-		gel_value_matrix_gauss (ctx, n->mat.matrix, TRUE, FALSE, FALSE, NULL, NULL);
+		gel_value_matrix_gauss (ctx, n->mat.matrix, TRUE, FALSE, FALSE, FALSE, NULL, NULL);
 	}
 	n->mat.quoted = FALSE;
 	return n;
@@ -3445,7 +3445,7 @@
 	if ( ! m->rref) {
 		m = gel_matrixw_copy (m);
 		/* only do ref, not rref for speed */
-		gel_value_matrix_gauss (ctx, m, FALSE, FALSE, FALSE, NULL, NULL);
+		gel_value_matrix_gauss (ctx, m, FALSE, FALSE, FALSE, FALSE, NULL, NULL);
 		copied_m = TRUE;
 	}
 
@@ -3526,7 +3526,16 @@
 	m = a[0]->mat.matrix;
 	if ( ! m->rref) {
 		m = gel_matrixw_copy (m);
-		gel_value_matrix_gauss (ctx, m, TRUE, FALSE, FALSE, NULL, NULL);
+		if (gel_value_matrix_gauss (ctx, m,
+					    TRUE /* reduce */,
+					    FALSE /* uppertriang */,
+					    FALSE /* stopsing */,
+					    TRUE /* stopnonsing */,
+					    NULL /* detop */,
+					    NULL /* simul */)) {
+			gel_matrixw_free (m);
+			return gel_makenum_null ();
+		}
 		copied_m = TRUE;
 	}
 
@@ -3670,7 +3679,7 @@
 	RM = gel_matrixw_copy(a[0]->mat.matrix);
 	RV = gel_matrixw_copy(a[1]->mat.matrix);
 
-	ret = gel_value_matrix_gauss (ctx, RM, TRUE, FALSE, FALSE, NULL, RV);
+	ret = gel_value_matrix_gauss (ctx, RM, TRUE, FALSE, FALSE, FALSE, NULL, RV);
 
 	if (retm != NULL) {
 		GET_NEW_NODE(n);

Modified: trunk/src/geniustests.txt
==============================================================================
--- trunk/src/geniustests.txt	(original)
+++ trunk/src/geniustests.txt	Sat Jun  7 18:02:47 2008
@@ -206,7 +206,7 @@
 IsFloat(3.1)							true
 IsFloat(3)							false
 I(4)								[1,0,0,0;0,1,0,0;0,0,1,0;0,0,0,1]
-I(0)								I(0)
+[I(0),99]							[99]
 lcm(4,6)							12
 function f(x)=(if(not IsInteger(x)) then bailout else 1);f(1.2)	f(1.2)
 function f(x)=(if(not IsInteger(x)) then bailout else 1);f(100)	1
@@ -899,5 +899,18 @@
 function f(x)=(ff=`()=(k+1);ff);ll=f(5)				(`()=(k+1))
 k=9;function f(x)=(ff=`()=(k+1);ff);ll=f(5)			(`()=(k+1))
 k=9;function f(x)=(ff=`()=(k+1);ff);ll=f(5);ll()		10
+IsNull(SolveLinearSystem ([1,4],[5]))				true
+SolveLinearSystem ([1],[5])					[5]
+SolveLinearSystem ([1;1],[5;5])					[5]
+SolveLinearSystem ([1,2;2,4;0,1],[1;2;3])			[-5;3]
+IsNull(SolveLinearSystem ([1,2;2,4;0,1],[1;3;3]))		true
+IsNull(zeros(5,0))						true
+IsNull(zeros(0,3))						true
+IsNull(ones(0,1))						true
+IsNull(ones(2,0))						true
+NullSpace([1,-1])						[-1;1]
+NullSpace([1,-1;0,0])						[-1;1]
+NullSpace([1,-1;2,-2])						[-1;1]
+NullSpace([1,-1;2,-2;-3,3])					[-1;1]
 load "nullspacetest.gel"					true
 load "longtest.gel"						true

Modified: trunk/src/matop.c
==============================================================================
--- trunk/src/matop.c	(original)
+++ trunk/src/matop.c	Sat Jun  7 18:02:47 2008
@@ -381,8 +381,13 @@
 /* return FALSE if singular */
 /* FIXME: if modular arithmetic is on, work over the modulo properly!!!! */
 gboolean
-gel_value_matrix_gauss (GelCtx *ctx, GelMatrixW *m, gboolean reduce, gboolean
-			uppertriang, gboolean stopsing, mpw_ptr detop,
+gel_value_matrix_gauss (GelCtx *ctx,
+			GelMatrixW *m,
+			gboolean reduce,
+			gboolean uppertriang,
+			gboolean stopsing,
+			gboolean stopnonsing,
+			mpw_ptr detop,
 			GelMatrixW *simul)
 {
 	int i, j, d, ii, w, h;
@@ -402,10 +407,10 @@
 
 	if (m->rref) {
 		/* test for singularity */
-		if (h > w) {
+		if (w > h) {
 			ret = FALSE;
 		} else {
-			GelETree *t = gel_matrixw_get_index(m,h-1,h-1);
+			GelETree *t = gel_matrixw_get_index(m,w-1,w-1);
 			if (t == NULL ||
 			    mpw_zero_p (t->val.value))
 				ret = FALSE;
@@ -458,7 +463,6 @@
 		}
 
 		if (j == h) {
-			ret = FALSE;
 			if(stopsing) {
 				mpw_clear(tmp);
 				return FALSE;
@@ -558,6 +562,14 @@
 		d++;
 	}
 
+	if (d < w)
+		ret = FALSE;
+
+	if (stopnonsing && d == w) {
+		mpw_clear(tmp);
+		return TRUE;
+	}
+
 	if(reduce) {
 		for(d = pivots_max; d >= 0; d--) {
 			i = pivots[d];
@@ -703,7 +715,13 @@
 	default:
 		mpw_init(tmp);
 		mm = gel_matrixw_copy(m);
-		gel_value_matrix_gauss(ctx,mm,FALSE,TRUE,FALSE,tmp,NULL);
+		gel_value_matrix_gauss(ctx,mm,
+				       FALSE /* reduce */,
+				       TRUE /* uppertriang */,
+				       FALSE /* stopsing */,
+				       FALSE /* stopnonsing */,
+				       tmp,
+				       NULL);
 		mpw_mul(rop,tmp,gel_matrixw_index(mm,0,0)->val.value);
 		mpw_clear(tmp);
 		for (i = 1; i < w; i++) {

Modified: trunk/src/matop.h
==============================================================================
--- trunk/src/matop.h	(original)
+++ trunk/src/matop.h	Sat Jun  7 18:02:47 2008
@@ -1,11 +1,13 @@
 /* GENIUS Calculator
- * Copyright (C) 1997-2003 George Lebl
+ * Copyright (C) 1997-2008 Jiri (George) Lebl
  *
- * Author: George Lebl
+ * Author: Jiri (George) Lebl
  *
- * This program is free software; you can redistribute it and/or modify
+ * This file is part of Genius.
+ *
+ * Genius is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation, either version 3 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
@@ -14,9 +16,7 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the  Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
- * USA.
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 #ifndef _MATOP_H_
@@ -39,6 +39,13 @@
 gboolean gel_value_matrix_det (GelCtx *ctx, mpw_t rop, GelMatrixW *m);
 /*NOTE: if simul is passed then we assume that it's the same size as m*/
 /* return FALSE if singular */
-gboolean gel_value_matrix_gauss (GelCtx *ctx, GelMatrixW *m, gboolean reduce, gboolean uppertriang, gboolean stopsing, mpw_ptr detop, GelMatrixW *simul);
+gboolean gel_value_matrix_gauss (GelCtx *ctx,
+				 GelMatrixW *m,
+				 gboolean reduce,
+				 gboolean uppertriang,
+				 gboolean stopsing,
+				 gboolean stopnonsing,
+				 mpw_ptr detop,
+				 GelMatrixW *simul);
 
 #endif



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]