From a4dfb20b21613dccd7cbab94e3c1f9c14696879e Mon Sep 17 00:00:00 2001 From: Jerry James Date: Fri, 6 Jun 2025 12:21:55 -0600 Subject: [PATCH] Support bigint, bigintvec, and bigintmat --- gap/singular.g | 98 +++++++++++++++++++++++++++++++++++++++---------- tst/testall.tst | 21 +++++++---- 2 files changed, 92 insertions(+), 27 deletions(-) diff --git a/gap/singular.g b/gap/singular.g index bfeadfe..59f849b 100644 --- a/gap/singular.g +++ b/gap/singular.g @@ -1144,6 +1144,32 @@ end ); +BindGlobal( "ParseGapIntmatToSingBigintmat", function ( mat ) + local str, dim, i, j; + dim := DimensionsMat( mat ); + str := "(x->{bigintmat m["; + Append( str, String( dim[1] ) ); + Append( str, "]["); + Append( str, String( dim[2] ) ); + Append( str, "] = " ); + for i in [ 1 .. dim[1] ] do + Append( str, "\n" ); + for j in [ 1 .. dim[2] ] do + Append( str, String( mat[i][j] ) ); + if not (i = dim[1] and j = dim[2]) then + Append( str, "," ); + fi; + if j mod 50 = 0 then + Append( str, "\n" ); + fi; + od; + od; + Append( str, "; m})(0)" ); + return str; +end ); + + + BindGlobal( "ParseGapIntvecToSingIntvec", function ( vec ) local str, dim, i; dim := Length( vec ); @@ -1163,6 +1189,24 @@ end ); +BindGlobal( "ParseGapIntvecToSingBigintvec", function ( vec ) + local str, dim, i; + dim := Length( vec ); + str := "bigintvec("; + for i in [ 1 .. dim ] do + Append( str, String( vec[i] ) ); + if not i = dim then + Append( str, "," ); + fi; + if i mod 50 = 0 then + Append( str, "\n" ); + fi; + od; + Append( str, ")" ); + return str; +end ); + + BindGlobal( "ParseGapModuleToSingModule", function ( M ) @@ -1851,10 +1895,37 @@ are, therefore, limited in their range (e.g., the range is between \ intvec := [ "Variables of type intvec are lists of integers.", obj -> IsRowVector( obj ) and ForAll( obj, IsSingularInt ), ParseGapIntvecToSingIntvec, - obj -> List( SplitString( obj, ',' ), Int ), + obj -> List( SplitString( obj, ',', ' ' ), Int ), ], + bigint := [ "Variables of type bigint represent arbitrarily long integers.", + obj -> IsInt( obj ) and ( SingularVersion >= 4000 or + # because it may be still unknown + SingularVersion = 0 ), + String, + Int + ], + + + bigintmat := [ "Variables of type bigintmat are matrices with arbitrarily \ +long integer entries.", + obj -> IsMatrix( obj ) and + ForAll( obj, x -> ForAll( x, IsInt ) ) and + ( SingularVersion >= 4000 or SingularVersion = 0 ), + ParseGapIntmatToSingBigintmat, + ], + + + bigintvec := [ "Variables of type bigintvec are lists of arbitrarily long \ +integers.", + obj -> IsRowVector( obj ) and ForAll( obj, IsInt ) and + ( SingularVersion >= 4400 or SingularVersion = 0 ), + ParseGapIntvecToSingBigintvec, + obj -> List( SplitString( obj, ',', ' ' ), Int ), + ], + + link := [ "Links are the communication channels of SINGULAR, i.e., \ something SINGULAR can write to and/or read from.", ReturnFalse, # not implemented @@ -2004,19 +2075,6 @@ have a return type 'none', see \"3.5.1 General command syntax\".", ], - bigint := [ "Variables of type bigint represent the arbitrary long \ -integers. They can only be constructed from other types (int, number).", -# obj -> IsInt( obj ) and ( SingularVersion >= 3002 or -# # because it may be still unknown -# SingularVersion = 0 ), -# obj -> Concatenation( "bigint(", String( obj ), ")" ), -ReturnFalse, -, - Int - ], - - - package := [ "The data type package is used to group identifiers into \ collections. Introduced in Singular 3.0.0.", ReturnFalse, # makes no sense in Gap @@ -2030,10 +2088,10 @@ collections. Introduced in Singular 3.0.0.", # the record entries in the order that we have given them (a change introduced # in GAP 4.5). So we here list the order in which they should be tested -SingularDataTypeTestOrder := [ "def", "ideal", "int", "intmat", "intvec", "link", - "map", "matrix", "module", "number", "poly", "proc", "qring", "resolution", - "ring", "string", "vector", "list", "?unknown type?", "none", "bigint", - "package" ]; +SingularDataTypeTestOrder := [ "def", "ideal", "int", "intmat", "intvec", + "bigint", "bigintvec", "bigintmat", "link", "map", "matrix", "module", + "number", "poly", "proc", "qring", "resolution", "ring", "string", "vector", + "list", "?unknown type?", "none", "package" ]; # And check for sanity that this set is same as the names in the record if Set(SingularDataTypeTestOrder) <> Set(RecNames(SingularDataTypes)) then @@ -2160,8 +2218,8 @@ ConvertSingObjToGapObj := function ( obj, type_output, singname ) return ideal; - # intmat - elif type_output = "intmat" then + # intmat / bigintmat + elif type_output = "intmat" or type_output = "bigintmat" then list:= List( SplitString( obj, ',' ,' '), Int ); command := Concatenation( "nrows( ", singname, " );" ); nrows := Int( SingCommandInStreamOutStream( "", command ) ); diff --git a/tst/testall.tst b/tst/testall.tst index 04308b1..0e6373e 100644 --- a/tst/testall.tst +++ b/tst/testall.tst @@ -538,6 +538,10 @@ gap> intmat:=[[12,34],[56,78]]; [ [ 12, 34 ], [ 56, 78 ] ] gap> intvec:=[98765,4321]; [ 98765, 4321 ] +gap> bigint:=18446744073709551616; +18446744073709551616 +gap> bigintmat:=[[18446744073709551616,34],[56,432109876543210]]; +[ [ 18446744073709551616, 34 ], [ 56, 432109876543210 ] ] gap> map:=AlgebraGeneralMappingByImages(ring,ring,[x,y],[x+y,x-y]); [ x, y ] -> [ x+y, x-y ] gap> matrix:=[[x+y, x*y],[x+y+x*y,x^2+y^2]]; @@ -557,27 +561,29 @@ gap> vector:=[x^3+y^3,+(5)^3*x^2+Z(5)^3,x*y+y^2+Z(5)^3*y]; # gap> list1 := [ ideal, int, intmat, intvec, map, matrix, module, number, -> poly, proc, ring, string, vector]; +> poly, proc, ring, string, vector, bigint, bigintmat ]; [ , 123456, [ [ 12, 34 ], [ 56, 78 ] ], [ 98765, 4321 ], [ x, y ] -> [ x+y, x-y ], [ [ x+y, x*y ], [ x*y+x+y, x^2+y^2 ] ], , Z(5)^3, x^3+y^3+Z(5)^3*x^2+Z(5)^3*x*y+y^2+Z(5)^3*y, function( ) ... end, GF(5)[x,y], "ciao", - [ x^3+y^3, Z(5)^3, x*y+y^2+Z(5)^3*y ] ] + [ x^3+y^3, Z(5)^3, x*y+y^2+Z(5)^3*y ], 18446744073709551616, + [ [ 18446744073709551616, 34 ], [ 56, 432109876543210 ] ] ] gap> List( list1, SingularType); [ "ideal", "int", "intmat", "intvec", "map", "matrix", "module", "number", - "poly", "proc", "ring", "string", "vector" ] + "poly", "proc", "ring", "string", "vector", "bigint", "bigintmat" ] # gap> list2 := [ ideal, int, intmat, intvec, matrix, module, number, -> poly, string, vector]; +> poly, string, vector, bigint, bigintmat ]; [ , 123456, [ [ 12, 34 ], [ 56, 78 ] ], [ 98765, 4321 ], [ [ x+y, x*y ], [ x*y+x+y, x^2+y^2 ] ], , Z(5)^3, x^3+y^3+Z(5)^3*x^2+Z(5)^3*x*y+y^2+Z(5)^3*y, - "ciao", [ x^3+y^3, Z(5)^3, x*y+y^2+Z(5)^3*y ] ] + "ciao", [ x^3+y^3, Z(5)^3, x*y+y^2+Z(5)^3*y ], 18446744073709551616, + [ [ 18446744073709551616, 34 ], [ 56, 432109876543210 ] ] ] gap> list3 := SingularInterface( "id_func", [list2], "def" ); #I running SingularInterface( "id_func", [ "list" ], "def" )... #I done SingularInterface. @@ -591,7 +597,8 @@ gap> list3 := SingularInterface( "id_func", [list2], "def" ); [ [ x+y, x*y ], [ x*y+x+y, x^2+y^2 ] ], , Z(5)^3, x^3+y^3+Z(5)^3*x^2+Z(5)^3*x*y+y^2+Z(5)^3*y, - "ciao", [ x^3+y^3, Z(5)^3, x*y+y^2+Z(5)^3*y ] ] + "ciao", [ x^3+y^3, Z(5)^3, x*y+y^2+Z(5)^3*y ], 18446744073709551616, + [ [ 18446744073709551616, 34 ], [ 56, 432109876543210 ] ] ] # gap> for i in [2,3,4,5,7,8,9,10] do @@ -619,7 +626,7 @@ gap> SingularCommand("","transpose(mm2)==mm"); # this should be at the end of the test file: # gap> [ SingularNr.Process, SingularNr.Input, SingularNr.Output ]; -[ 0, 1136, 1136 ] +[ 0, 1156, 1156 ] gap> SingularBaseRing; GF(5)[x,y] gap> CoefficientsRing( SingularBaseRing );