From bf1c1cf2d7b18ccee5a3930930b7bda217fe68a9 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 29 Jan 2018 16:16:17 +0100 Subject: [PATCH] Given a vector space V with DimensionOfVectors(V) = 0, e.g. V:=GF(5)^0, we currently have Zero(V) = []. This commit makes the following snippets work: * Coefficients(Basis(V), []) * Position(Enumerator(V), []) * [] in V --- hpcgap/lib/basis.gi | 11 +++++++++++ lib/basis.gi | 11 +++++++++++ lib/modulrow.gi | 12 +++++++++++- .../2018-01-29-empty-list-in-vecspace.tst | 17 +++++++++++++++++ 4 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 tst/testbugfix/2018-01-29-empty-list-in-vecspace.tst diff --git a/hpcgap/lib/basis.gi b/hpcgap/lib/basis.gi index 7364cc3e10..9fac2a847c 100644 --- a/hpcgap/lib/basis.gi +++ b/hpcgap/lib/basis.gi @@ -1403,6 +1403,17 @@ InstallMethod( Coefficients, fi; end ); +InstallOtherMethod( Coefficients, + "for empty basis and empty list", + [ IsBasis and IsEmpty, IsEmpty and IsList ], SUM_FLAGS, + function( B, v ) + if v = Zero( UnderlyingLeftModule( B ) ) then + return []; + else + return fail; + fi; + end ); + InstallMethod( LinearCombination, "for empty basis and empty list", [ IsBasis and IsEmpty, IsList and IsEmpty ], SUM_FLAGS, diff --git a/lib/basis.gi b/lib/basis.gi index 4fc3f53610..d4958c81b2 100644 --- a/lib/basis.gi +++ b/lib/basis.gi @@ -1398,6 +1398,17 @@ InstallMethod( Coefficients, fi; end ); +InstallOtherMethod( Coefficients, + "for empty basis and empty list", + [ IsBasis and IsEmpty, IsEmpty and IsList ], SUM_FLAGS, + function( B, v ) + if v = Zero( UnderlyingLeftModule( B ) ) then + return []; + else + return fail; + fi; + end ); + InstallMethod( LinearCombination, "for empty basis and empty list", [ IsBasis and IsEmpty, IsList and IsEmpty ], SUM_FLAGS, diff --git a/lib/modulrow.gi b/lib/modulrow.gi index ca49f72209..964ed8e546 100644 --- a/lib/modulrow.gi +++ b/lib/modulrow.gi @@ -209,6 +209,15 @@ InstallMethod( \in, and IsSubset( LeftActingDomain( M ), v ); end ); +# TODO: HACK: properly document this +InstallMethod( \in, + "for empty list and vector space with length 0 vector", + [ IsEmpty and IsList, IsFreeLeftModule and IsFullRowModule ], + SUM_FLAGS, # can't do better + function( v, M ) + return DimensionOfVectors(M) = 0; + end ); + ############################################################################# ## @@ -535,7 +544,8 @@ InstallMethod( EnumeratorByBasis, zerovector := Zero( V ), dimension := Dimension( V ) ) ); - if IsField( F ) and Size( F ) < 256 and IsInternalRep( One( F ) ) then + if IsField( F ) and Size( F ) < 256 and Dimension( V ) > 0 and + IsInternalRep( One( F ) ) then # Use a more efficient method for `Position'. enum!.NumberElement:= PosVecEnumFF; SetFilterObj( enum, IsQuickPositionList ); diff --git a/tst/testbugfix/2018-01-29-empty-list-in-vecspace.tst b/tst/testbugfix/2018-01-29-empty-list-in-vecspace.tst new file mode 100644 index 0000000000..7fa957d3e6 --- /dev/null +++ b/tst/testbugfix/2018-01-29-empty-list-in-vecspace.tst @@ -0,0 +1,17 @@ +# +# See +# +gap> V := GF(5)^0;; +gap> e := Enumerator(V);; +gap> Position(e, Zero(V)); +1 +gap> Coefficients(Basis(V), Zero(V)); +[ ] + +# +gap> V := GF(257)^0;; +gap> e := Enumerator(V);; +gap> Position(e, Zero(V)); +1 +gap> Coefficients(Basis(V), Zero(V)); +[ ]