From 48b20f6275c87f9afa5a9cdb848465a78e65e0e7 Mon Sep 17 00:00:00 2001 From: ThomasBreuer Date: Tue, 29 Jan 2019 12:48:09 +0100 Subject: [PATCH] `CloseMutableBasis` now returns something Up to now, `CloseMutableBasis` had no return value. Now it returns `true` if the basis was extended and `false` otherwise. This saves work in situations where one builds a basis by adding vectors, and where one wants to know which ones really extended the current basis. --- lib/algrep.gi | 3 +-- lib/basismut.gd | 15 ++++++++++++--- lib/basismut.gi | 7 ++++++- lib/vspcmat.gi | 5 ++++- lib/vspcrow.gi | 7 ++++++- tst/testinstall/vspchom.tst | 3 +++ tst/testinstall/vspcmali.tst | 7 +++++++ tst/testinstall/vspcmat.tst | 22 ++++++++++++++++++++++ tst/testinstall/vspcrow.tst | 22 ++++++++++++++++++++-- 9 files changed, 81 insertions(+), 10 deletions(-) diff --git a/lib/algrep.gi b/lib/algrep.gi index 8354b430c8..c9e3b2a869 100644 --- a/lib/algrep.gi +++ b/lib/algrep.gi @@ -568,8 +568,7 @@ InstallMethod( CloseMutableBasis, [ IsMutableBasis and IsMutable and IsMutableBasisViaUnderlyingMutableBasisRep, IsVector ], 0, function( MB, v ) - - CloseMutableBasis( MB!.underlyingMutableBasis, ExtRepOfObj( v ) ); + return CloseMutableBasis( MB!.underlyingMutableBasis, ExtRepOfObj( v ) ); end ); diff --git a/lib/basismut.gd b/lib/basismut.gd index f00067960c..05223ac3ca 100644 --- a/lib/basismut.gd +++ b/lib/basismut.gd @@ -218,24 +218,33 @@ DeclareOperation( "ImmutableBasis", [ IsMutableBasis, IsFreeLeftModule ] ); ## ## ## For a mutable basis MB over the coefficient ring R, say, -## and a vector v, CloseMutableBasis changes MB such that afterwards -## it describes the R-span of the former basis vectors together with v. +## and a vector v, changes MB +## such that afterwards it describes the R-span of the former +## basis vectors together with v. ##

## Note that if v enlarges the dimension then this does in general not ## mean that v is simply added to the basis vectors of MB. ## Usually a linear combination of v and the other basis vectors is added, ## and also the old basis vectors may be modified, for example in order to -## keep the list of basis vectors echelonized (see ). +## keep the list of basis vectors echelonized +## (see ). +##

+## returns false if v was +## already in the R-span described by MB, +## and true if MB got extended. ## MB:= MutableBasis( Rationals, [ [ 1, 1, 3 ], [ 2, 2, 1 ] ] ); ## ## gap> IsContainedInSpan( MB, [ 1, 0, 0 ] ); ## false ## gap> CloseMutableBasis( MB, [ 1, 0, 0 ] ); +## true ## gap> MB; ## ## gap> IsContainedInSpan( MB, [ 1, 0, 0 ] ); ## true +## gap> CloseMutableBasis( MB, [ 1, 0, 0 ] ); +## false ## ]]> ## ## diff --git a/lib/basismut.gi b/lib/basismut.gi index 89c65c260d..f089c6abc8 100644 --- a/lib/basismut.gi +++ b/lib/basismut.gi @@ -206,6 +206,10 @@ InstallMethod( CloseMutableBasis, V:= LeftModuleByGenerators( LeftActingDomain( V ), vectors ); UseBasis( V, vectors ); MB!.immutableBasis := Basis( V ); + return true; + else + # The basis was not extended. + return false; fi; end ); @@ -406,7 +410,7 @@ InstallMethod( CloseMutableBasis, function( MB, v ) local R, M; if IsBound( MB!.niceMutableBasis ) then - CloseMutableBasis( MB!.niceMutableBasis, + return CloseMutableBasis( MB!.niceMutableBasis, NiceVector( MB!.leftModule, v ) ); elif v <> MB!.zero then @@ -419,6 +423,7 @@ InstallMethod( CloseMutableBasis, MB!.leftModule:= M; MB!.niceMutableBasis:= MutableBasis( R, [ NiceVector( M, v ) ] ); + return true; fi; end ); diff --git a/lib/vspcmat.gi b/lib/vspcmat.gi index 454d63ace6..0740ec2a16 100644 --- a/lib/vspcmat.gi +++ b/lib/vspcmat.gi @@ -1045,6 +1045,7 @@ InstallMethod( CloseMutableBasis, ResetFilterObj( MB, IsMutableBasisOfGaussianMatrixSpaceRep ); MB!.immutableBasis:= Basis( V ); + return true; else @@ -1077,10 +1078,12 @@ InstallMethod( CloseMutableBasis, od; Add( basisvectors, v ); heads[i][j]:= Length( basisvectors ); - break; + return true; fi; od; + # The basis was not extended. + return false; fi; end ); diff --git a/lib/vspcrow.gi b/lib/vspcrow.gi index 69db340109..16d3d462f8 100644 --- a/lib/vspcrow.gi +++ b/lib/vspcrow.gi @@ -1560,6 +1560,7 @@ InstallMethod( CloseMutableBasis, ResetFilterObj( MB, IsMutableBasisOfGaussianRowSpaceRep ); MB!.immutableBasis:= Basis( V ); + return true; else @@ -1568,7 +1569,7 @@ InstallMethod( CloseMutableBasis, ncols:= Length( v ); heads:= MB!.heads; - if ncols <> Length( MB!.heads ) then + if ncols <> Length( heads ) then Error( " must have same length as `MB!.heads'" ); fi; @@ -1588,6 +1589,10 @@ InstallMethod( CloseMutableBasis, MultVector( v, Inverse( v[j] ) ); Add( basisvectors, v ); heads[j]:= Length( basisvectors ); + return true; + else + # The basis was not extended. + return false; fi; fi; diff --git a/tst/testinstall/vspchom.tst b/tst/testinstall/vspchom.tst index e4e907fa9d..e9e8c9902d 100644 --- a/tst/testinstall/vspchom.tst +++ b/tst/testinstall/vspchom.tst @@ -404,7 +404,10 @@ gap> IsSubset( hom, triv ); true gap> mb:= MutableBasis( f, [], zero ); +gap> CloseMutableBasis( mb, zero ); +false gap> CloseMutableBasis( mb, map6 ); +true gap> ImmutableBasis( mb ); Basis( , ... ) diff --git a/tst/testinstall/vspcmali.tst b/tst/testinstall/vspcmali.tst index 06a3ae1288..6ec96bad90 100644 --- a/tst/testinstall/vspcmali.tst +++ b/tst/testinstall/vspcmali.tst @@ -365,6 +365,7 @@ gap> mb:= MutableBasis( Rationals, gap> IsMutableBasisOfGaussianMatrixSpaceRep( mb ); true gap> CloseMutableBasis( mb, LieObject( [ [ E(4), 0 ], [ 0, 0 ] ] ) ); +true gap> IsMutableBasisOfGaussianMatrixSpaceRep( mb ); false gap> Print( BasisVectors( mb ), "\n" ); @@ -376,8 +377,11 @@ gap> mb:= MutableBasis( Rationals, > LieObject( [ [ 1, 1 ], [ 1, 1 ] ] ) ] ); gap> CloseMutableBasis( mb, LieObject( [ [ 1, 2 ], [ 3, 4 ] ] ) ); +true gap> CloseMutableBasis( mb, LieObject( [ [ 1, 2 ], [ 3, 5 ] ] ) ); +true gap> CloseMutableBasis( mb, LieObject( [ [ 0, 0 ], [ 0, 7 ] ] ) ); +false gap> IsMutableBasisOfGaussianMatrixSpaceRep( mb ); true gap> bv:= BasisVectors( mb );; @@ -392,8 +396,11 @@ gap> mb:= MutableBasis( Rationals, [], > LieObject( [ [ 0, 0 ], [ 0, 0 ] ] ) ); gap> CloseMutableBasis( mb, LieObject( [ [ 1, 2 ], [ 3, 4 ] ] ) ); +true gap> CloseMutableBasis( mb, LieObject( [ [ 1, 2 ], [ 3, 5 ] ] ) ); +true gap> CloseMutableBasis( mb, LieObject( [ [ 0, 0 ], [ 0, 7 ] ] ) ); +false gap> IsMutableBasisOfGaussianMatrixSpaceRep( mb ); true gap> BasisVectors( mb ); diff --git a/tst/testinstall/vspcmat.tst b/tst/testinstall/vspcmat.tst index 2558e076be..733a2b565a 100644 --- a/tst/testinstall/vspcmat.tst +++ b/tst/testinstall/vspcmat.tst @@ -322,6 +322,7 @@ gap> mb:= MutableBasis( Rationals, gap> IsMutableBasisOfGaussianMatrixSpaceRep( mb ); true gap> CloseMutableBasis( mb, [ [ E(4), 0 ], [ 0, 0 ] ] ); +true gap> IsMutableBasisOfGaussianMatrixSpaceRep( mb ); false gap> BasisVectors( mb ); @@ -332,8 +333,11 @@ gap> mb:= MutableBasis( Rationals, > [ [ 1, 1 ], [ 1, 1 ] ] ] ); gap> CloseMutableBasis( mb, [ [ 1, 2 ], [ 3, 4 ] ] ); +true gap> CloseMutableBasis( mb, [ [ 1, 2 ], [ 3, 5 ] ] ); +true gap> CloseMutableBasis( mb, [ [ 0, 0 ], [ 0, 7 ] ] ); +false gap> IsMutableBasisOfGaussianMatrixSpaceRep( mb ); true gap> bv:= BasisVectors( mb );; @@ -347,8 +351,11 @@ SemiEchelonBasis( , gap> mb:= MutableBasis( Rationals, [], [ [ 0, 0 ], [ 0, 0 ] ] ); gap> CloseMutableBasis( mb, [ [ 1, 2 ], [ 3, 4 ] ] ); +true gap> CloseMutableBasis( mb, [ [ 1, 2 ], [ 3, 5 ] ] ); +true gap> CloseMutableBasis( mb, [ [ 0, 0 ], [ 0, 7 ] ] ); +false gap> IsMutableBasisOfGaussianMatrixSpaceRep( mb ); true gap> BasisVectors( mb ); @@ -359,7 +366,22 @@ SemiEchelonBasis( , gap> mb:= MutableBasis( Rationals, [], [ [ 0, 0 ], [ 0, 0 ] ] ); gap> CloseMutableBasis( mb, [ [ 1, 0 ], [ 0, 1 ] ] ); +true gap> CloseMutableBasis( mb, [ [ 0, 1 ], [ 1, 0 ] ] ); +true gap> IsContainedInSpan( mb, [ [ 1, 1 ], [ 1, 1 ] ] ); true + +############################################################################# +## +## 8. Methods for mutable bases of non-Gaussian matrix spaces +## +gap> mb:= MutableBasis( Rationals, [ [ [ E(4) ] ] ] ); + +gap> CloseMutableBasis( mb, [ [ E(3) ] ] ); +true +gap> CloseMutableBasis( mb, [ [ E(3)+E(4) ] ] ); +false + +## gap> STOP_TEST( "vspcmat.tst", 1); diff --git a/tst/testinstall/vspcrow.tst b/tst/testinstall/vspcrow.tst index 6f87d2ae04..d672b9f275 100644 --- a/tst/testinstall/vspcrow.tst +++ b/tst/testinstall/vspcrow.tst @@ -290,6 +290,7 @@ gap> mb:= MutableBasis( Rationals, gap> IsMutableBasisOfGaussianRowSpaceRep( mb ); true gap> CloseMutableBasis( mb, [ E(4), 0, 0, 0 ] ); +true gap> IsMutableBasisOfGaussianRowSpaceRep( mb ); false gap> BasisVectors( mb ); @@ -298,8 +299,11 @@ gap> mb:= MutableBasis( Rationals, > [ [ 1, 1, 1, 1 ], [ 0, 1, 1, 1 ], [ 1, 1, 1, 1 ] ] ); gap> CloseMutableBasis( mb, [ 1, 2, 3, 4 ] ); +true gap> CloseMutableBasis( mb, [ 1, 2, 3, 5 ] ); +true gap> CloseMutableBasis( mb, [ 0, 0, 0, 7 ] ); +false gap> IsMutableBasisOfGaussianRowSpaceRep( mb ); true gap> BasisVectors( mb ); @@ -310,8 +314,11 @@ SemiEchelonBasis( , gap> mb:= MutableBasis( Rationals, [], [ 0, 0, 0, 0 ] ); gap> CloseMutableBasis( mb, [ 1, 2, 3, 4 ] ); +true gap> CloseMutableBasis( mb, [ 1, 2, 3, 5 ] ); +true gap> CloseMutableBasis( mb, [ 0, 0, 0, 7 ] ); +false gap> IsMutableBasisOfGaussianRowSpaceRep( mb ); true gap> BasisVectors( mb ); @@ -320,9 +327,20 @@ gap> ImmutableBasis( mb ); SemiEchelonBasis( , [ [ 1, 2, 3, 4 ], [ 0, 0, 0, 1 ] ] ) +############################################################################ +## +## 8. Methods for mutable bases of non-Gaussian row spaces +## +gap> mb:= MutableBasis( Rationals, [ [ E(4) ] ] ); + +gap> CloseMutableBasis( mb, [ E(3) ] ); +true +gap> CloseMutableBasis( mb, [ E(3)+E(4) ] ); +false + ############################################################################# ## -## 8. Enumerations +## 9. Enumerations ## gap> erg:= [];; i:= 0;; gap> dims:= [ 1,4,27,28,29,31,32,33,63,64,65,92,127,128,129,384 ];; @@ -338,7 +356,7 @@ gap> erg; ############################################################################# ## -## 9. Arithmetic +## 10. Arithmetic ## gap> A := [ [ Z(2^2)^2, 0*Z(2), Z(2^2), 0*Z(2), 0*Z(2), 0*Z(2) ], > [ Z(2^2)^2, 0*Z(2), Z(2^2)^2, Z(2)^0, Z(2^2)^2, Z(2)^0 ],