Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Lattices in Sage

I have the following Magma code, and I want to rewrite it in Sage.

L:=Lattice(Matrix(Rationals(),2,2,[N2t,0,tau,1]), Matrix(Rationals(),2,2,[1,0,0,1]));
short:=LLLBasisMatrix(L);

In Sage I did something like this:

L = LatticePoset([Matrix(QQ, 2, 2, [N2t, 0, tau, 1]), Matrix(QQ, 2, 2, [1, 0, 0, 1])])
short = L.LLL()

But, I get an error when calling the LatticePoset function. The error is "TypeError: 'sage.rings.rational.Rational' object is not callable". Any ideas how to correct it? Also is LLL the correct function to call here? While Magma has both LLL and LLLBasisMatrix functions.

Lattices in Sage

I have the following Magma code, and I want to rewrite it in Sage.

N2t:=25516019074809772890907399206668148197126676353207284389908944819944616771\
7167960744601102972601602922181202360582451390444069288993036758893159458257631\
7922888063924275113129597015529978633082726499411680508212361255101456369567267\
7657841421497110048164497754387005155761445652482244828120107002989662877156928\
5982163522457460577547615506364312525396285709733305329300010560421731105246057\
7190682760508480341511798184712712266779613412559513108135433867573738098144531\
25;

tau:=2188907639255876032767765925993460963846331337980258290144028319336683129116481\
9780840018602360527472447127247594678967295892871925139132561808422151579794094\
3854129747468385480466969438715015392830449452561079675587048470808895105602287\
5584202193081906035689682116914576488671041449431850143696923648303395871752428\
6008339273426400925089525356222254452347532030101233967584203566313861768653268\
558884527430972086051680415120281152591994818818861033582581858059564186563;

L:=Lattice(Matrix(Rationals(),2,2,[N2t,0,tau,1]), Matrix(Rationals(),2,2,[1,0,0,1]));
short:=LLLBasisMatrix(L);
"Lattice:\n",L;
"\nBasis matrix:\n",LLLBasisMatrix(L);

It produces an output as this:

Lattice:

Lattice of rank 2 and degree 2
Basis:
(102023170379847390036419158203055907729904658255806477141677305742879698289468\
    935970994110302270574525787108905003995971786987184762986658432845804995482\
    389503404930748846967519469979815719436719450952523599262146032904382052609\
    90700057 825694748623677772412237836275094480725776114625437569303747287772\
    934779898240599707874718276414616705404304473956339523041757026013068408812\
    507303811564790837600752813434147793995359168965340146717755845579784490778\
    2953853188523035739)
(102465661838402598784985533725011269841412691852687895702637347218011036503315\
    002899630973998723985375453433081665067141824770139747648141250254751339423\
    488963126438549010540191605764445865443657969637454905580812715097831565751\
    08200308 -16717264442859224619443675909830190129129150779488715809239373764\
    820994371166956340919825037680096505143023318907453241894223734762573909311\
    763546022785985897046967226468643453488866610744413079439965257117838418338\
    225876246621830585009)

Basis matrix:

[102023170379847390036419158203055907729904658255806477141677305742879698289468\
    935970994110302270574525787108905003995971786987184762986658432845804995482\
    389503404930748846967519469979815719436719450952523599262146032904382052609\
    90700057 825694748623677772412237836275094480725776114625437569303747287772\
    934779898240599707874718276414616705404304473956339523041757026013068408812\
    507303811564790837600752813434147793995359168965340146717755845579784490778\
    2953853188523035739]
[102465661838402598784985533725011269841412691852687895702637347218011036503315\
    002899630973998723985375453433081665067141824770139747648141250254751339423\
    488963126438549010540191605764445865443657969637454905580812715097831565751\
    08200308 -16717264442859224619443675909830190129129150779488715809239373764\
    820994371166956340919825037680096505143023318907453241894223734762573909311\
    763546022785985897046967226468643453488866610744413079439965257117838418338\
    225876246621830585009]

[1 0]
[0 1]

[1 0]
[0 1]

In Sage I did have something like this:

L N2t = LatticePoset([Matrix(QQ, 2, 2, [N2t, 0, tau, 1]), 255160190748097728909073992066681481971266763532072843899089448199446167717167960744601102972601602922181202360582451390444069288993036758893159458257631792288806392427511312959701552997863308272649941168050821236125510145636956726776578414214971100481644977543870051557614456524822448281201070029896628771569285982163522457460577547615506364312525396285709733305329300010560421731105246057719068276050848034151179818471271226677961341255951310813543386757373809814453125
tau = 21889076392558760327677659259934609638463313379802582901440283193366831291164819780840018602360527472447127247594678967295892871925139132561808422151579794094385412974746838548046696943871501539283044945256107967558704847080889510560228755842021930819060356896821169145764886710414494318501436969236483033958717524286008339273426400925089525356222254452347532030101233967584203566313861768653268558884527430972086051680415120281152591994818818861033582581858059564186563
M = Matrix(QQ, 2, 2, [1, 0, 0, 1])])
short = L.LLL()
[(N2t,0,tau,1), (1,0,0,1)])
M.LLL()

But, I get Which produces an error when calling the output of:

LatticePoset[                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       1                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        1]
[ 127580095374048864454536996033340740985633381766036421949544724099723083858583980372300551486300801461090601180291225695222034644496518379446579729128815896144403196213755656479850776498931654136324970584025410618062755072818478363388289207107485550240822488771935025778807228262411224140600535014948314385784642991081761228730288773807753182156262698142854866652664650005280210865552623028859534138025424017075589909235635613338980670627975655406771693378686904907226562                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        0   21889076392558760327677659259934609638463313379802582901440283193366831291164819780840018602360527472447127247594678967295892871925139132561808422151579794094385412974746838548046696943871501539283044945256107967558704847080889510560228755842021930819060356896821169145764886710414494318501436969236483033958717524286008339273426400925089525356222254452347532030101233967584203566313861768653268558884527430972086051680415120281152591994818818861033582581858059564186563 -127580095374048864454536996033340740985633381766036421949544724099723083858583980372300551486300801461090601180291225695222034644496518379446579729128815896144403196213755656479850776498931654136324970584025410618062755072818478363388289207107485550240822488771935025778807228262411224140600535014948314385784642991081761228730288773807753182156262698142854866652664650005280210865552623028859534138025424017075589909235635613338980670627975655406771693378686904907226562]
 function. The error is "TypeError: 'sage.rings.rational.Rational' object 

Which is not callable". exactly the same result. Any ideas idea how to correct it? Also is LLL convert the correct function above Magma code to call here? While Magma has both LLL and LLLBasisMatrix functions.a proper Sage code?

Lattices in Sage

I have the following Magma code, and I want to rewrite it in Sage.

N2t:=25516019074809772890907399206668148197126676353207284389908944819944616771\
7167960744601102972601602922181202360582451390444069288993036758893159458257631\
7922888063924275113129597015529978633082726499411680508212361255101456369567267\
7657841421497110048164497754387005155761445652482244828120107002989662877156928\
5982163522457460577547615506364312525396285709733305329300010560421731105246057\
7190682760508480341511798184712712266779613412559513108135433867573738098144531\
25;

tau:=2188907639255876032767765925993460963846331337980258290144028319336683129116481\
9780840018602360527472447127247594678967295892871925139132561808422151579794094\
3854129747468385480466969438715015392830449452561079675587048470808895105602287\
5584202193081906035689682116914576488671041449431850143696923648303395871752428\
6008339273426400925089525356222254452347532030101233967584203566313861768653268\
558884527430972086051680415120281152591994818818861033582581858059564186563;

L:=Lattice(Matrix(Rationals(),2,2,[N2t,0,tau,1]), Matrix(Rationals(),2,2,[1,0,0,1]));
"Lattice:\n",L;
"\nBasis matrix:\n",LLLBasisMatrix(L);

It produces an output as this:

Lattice:

Lattice of rank 2 and degree 2
Basis:
(102023170379847390036419158203055907729904658255806477141677305742879698289468\
    935970994110302270574525787108905003995971786987184762986658432845804995482\
    389503404930748846967519469979815719436719450952523599262146032904382052609\
    90700057 825694748623677772412237836275094480725776114625437569303747287772\
    934779898240599707874718276414616705404304473956339523041757026013068408812\
    507303811564790837600752813434147793995359168965340146717755845579784490778\
    2953853188523035739)
(102465661838402598784985533725011269841412691852687895702637347218011036503315\
    002899630973998723985375453433081665067141824770139747648141250254751339423\
    488963126438549010540191605764445865443657969637454905580812715097831565751\
    08200308 -16717264442859224619443675909830190129129150779488715809239373764\
    820994371166956340919825037680096505143023318907453241894223734762573909311\
    763546022785985897046967226468643453488866610744413079439965257117838418338\
    225876246621830585009)

Basis matrix:

[102023170379847390036419158203055907729904658255806477141677305742879698289468\
    935970994110302270574525787108905003995971786987184762986658432845804995482\
    389503404930748846967519469979815719436719450952523599262146032904382052609\
    90700057 825694748623677772412237836275094480725776114625437569303747287772\
    934779898240599707874718276414616705404304473956339523041757026013068408812\
    507303811564790837600752813434147793995359168965340146717755845579784490778\
    2953853188523035739]
[102465661838402598784985533725011269841412691852687895702637347218011036503315\
    002899630973998723985375453433081665067141824770139747648141250254751339423\
    488963126438549010540191605764445865443657969637454905580812715097831565751\
    08200308 -16717264442859224619443675909830190129129150779488715809239373764\
    820994371166956340919825037680096505143023318907453241894223734762573909311\
    763546022785985897046967226468643453488866610744413079439965257117838418338\
    225876246621830585009]

[1 0]
[0 1]

[1 0]
[0 1]

In Sage I have something like this:

N2t = 255160190748097728909073992066681481971266763532072843899089448199446167717167960744601102972601602922181202360582451390444069288993036758893159458257631792288806392427511312959701552997863308272649941168050821236125510145636956726776578414214971100481644977543870051557614456524822448281201070029896628771569285982163522457460577547615506364312525396285709733305329300010560421731105246057719068276050848034151179818471271226677961341255951310813543386757373809814453125
tau = 21889076392558760327677659259934609638463313379802582901440283193366831291164819780840018602360527472447127247594678967295892871925139132561808422151579794094385412974746838548046696943871501539283044945256107967558704847080889510560228755842021930819060356896821169145764886710414494318501436969236483033958717524286008339273426400925089525356222254452347532030101233967584203566313861768653268558884527430972086051680415120281152591994818818861033582581858059564186563
M = Matrix(QQ, [(N2t,0,tau,1), (1,0,0,1)])
M.LLL()

Which produces an Whose output of:

[                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       1                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        1]
[ 127580095374048864454536996033340740985633381766036421949544724099723083858583980372300551486300801461090601180291225695222034644496518379446579729128815896144403196213755656479850776498931654136324970584025410618062755072818478363388289207107485550240822488771935025778807228262411224140600535014948314385784642991081761228730288773807753182156262698142854866652664650005280210865552623028859534138025424017075589909235635613338980670627975655406771693378686904907226562                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        0   21889076392558760327677659259934609638463313379802582901440283193366831291164819780840018602360527472447127247594678967295892871925139132561808422151579794094385412974746838548046696943871501539283044945256107967558704847080889510560228755842021930819060356896821169145764886710414494318501436969236483033958717524286008339273426400925089525356222254452347532030101233967584203566313861768653268558884527430972086051680415120281152591994818818861033582581858059564186563 -127580095374048864454536996033340740985633381766036421949544724099723083858583980372300551486300801461090601180291225695222034644496518379446579729128815896144403196213755656479850776498931654136324970584025410618062755072818478363388289207107485550240822488771935025778807228262411224140600535014948314385784642991081761228730288773807753182156262698142854866652664650005280210865552623028859534138025424017075589909235635613338980670627975655406771693378686904907226562]

Which is not exactly the same result. Any idea how to convert thing produced by the above Magma code to a proper code. I think the main problem is that I use a matrix and just apply the LLL algorithm to it in the Sage code?part. Whereas, in Magma there a lattice created, and then the LLLBasisMatrix function (https://magma.maths.usyd.edu.au/magma/handbook/text/312#2964) called. Roughly speaking that function does this:

Given a lattice L with basis matrix B, return the LLL basis matrix B' of L, together with the transformation matrix T such that B'=TB. The LLL basis matrix B' is simply defined to be a LLL-reduced form of B; it is stored in L when computed and subsequently used internally by many lattice functions. The LLL basis matrix will be created automatically internally as needed with δ=0.999 by default (note that this is different from the usual default of 0.75); by the use of parameters to this function one can ensure that the LLL basis matrix is created in a way which is different to the default.

How does one create a lattice in Sage? And does Sage have a function similar to LLLBasisMatrix above? If not, how can I achieve the same functionality in Sage?

Lattices in Sage

I have the following Magma code, and I want to rewrite it in Sage.

L:=Lattice(Matrix(Rationals(),2,2,[N2t,0,tau,1]), Matrix(Rationals(),2,2,[1,0,0,1]));
"Lattice:\n",L;
"\nBasis matrix:\n",LLLBasisMatrix(L);

In Sage I have something like this:

M = Matrix(QQ, [(N2t,0,tau,1), (1,0,0,1)])
M.LLL()

Whose output is not exactly the same thing produced by the above Magma code. I think the main problem is that I use a matrix and just apply the LLL algorithm to it in the Sage part. Whereas, in Magma there a lattice created, and then the LLLBasisMatrix function (https://magma.maths.usyd.edu.au/magma/handbook/text/312#2964) called. Roughly speaking that function does this:

Given a lattice L with basis matrix B, return the LLL basis matrix B' of L, together with the transformation matrix T such that B'=TB. The LLL basis matrix B' is simply defined to be a LLL-reduced form of B; it is stored in L when computed and subsequently used internally by many lattice functions. The LLL basis matrix will be created automatically internally as needed with δ=0.999 by default (note that this is different from the usual default of 0.75); by the use of parameters to this function one can ensure that the LLL basis matrix is created in a way which is different to the default.

How does one create a lattice in Sage? And does Sage have a function similar to LLLBasisMatrix above? If not, how can I achieve the same functionality in Sage?

As for numeric example, I have the following values:

N2t = 1136868377216160297393798828125
D = 53364935730486508893809772233249725927747397616650814998641
tau = 954690521650617175389887577728

and if I call the above Magma code with these values, I get the following result for the basis matrix:

[-182177855565543122003911250397                               1]
[ 772512666085074053385976327331                               2]

whereas if I call the above Sage code with the above values, I get the following result:

[1136868377216160297393798828125                                                           0                              954690521650617175389887577728                                                           1]
[1                                                           0                                                           0 53364935730486508893809772233249725927747397616650814998641]

Lattices in Sage

I have the following Magma code, and I want to rewrite it in Sage.

L:=Lattice(Matrix(Rationals(),2,2,[N2t,0,tau,1]), Matrix(Rationals(),2,2,[1,0,0,1]));
Matrix(Rationals(),2,2,[1,0,0,D]));
"Lattice:\n",L;
"\nBasis matrix:\n",LLLBasisMatrix(L);

In Sage I have something like this:

M = Matrix(QQ, [(N2t,0,tau,1), (1,0,0,1)])
M.LLL()

Whose output is not exactly the same thing produced by the above Magma code. I think the main problem is that I use a matrix and just apply the LLL algorithm to it in the Sage part. Whereas, in Magma there a lattice created, and then the LLLBasisMatrix function (https://magma.maths.usyd.edu.au/magma/handbook/text/312#2964) called. Roughly speaking that function does this:

Given a lattice L with basis matrix B, return the LLL basis matrix B' of L, together with the transformation matrix T such that B'=TB. The LLL basis matrix B' is simply defined to be a LLL-reduced form of B; it is stored in L when computed and subsequently used internally by many lattice functions. The LLL basis matrix will be created automatically internally as needed with δ=0.999 by default (note that this is different from the usual default of 0.75); by the use of parameters to this function one can ensure that the LLL basis matrix is created in a way which is different to the default.

How does one create a lattice in Sage? And does Sage have a function similar to LLLBasisMatrix above? If not, how can I achieve the same functionality in Sage?

As for numeric example, I have the following values:

N2t = 1136868377216160297393798828125
D = 53364935730486508893809772233249725927747397616650814998641
tau = 954690521650617175389887577728

and if I call the above Magma code with these values, I get the following result for the basis matrix:

[-182177855565543122003911250397                               1]
[ 772512666085074053385976327331                               2]

whereas if I call the above Sage code with the above values, I get the following result:

[1136868377216160297393798828125                                                           0                              954690521650617175389887577728                                                           1]
[1                                                           0                                                           0 53364935730486508893809772233249725927747397616650814998641]

Lattices in Sage

I have the following Magma code, and I want to rewrite it in Sage.

L:=Lattice(Matrix(Rationals(),2,2,[N2t,0,tau,1]), Matrix(Rationals(),2,2,[1,0,0,D]));
"Lattice:\n",L;
"\nBasis matrix:\n",LLLBasisMatrix(L);

In Sage I have something like this:

M = Matrix(QQ, [(N2t,0,tau,1), (1,0,0,1)])
(1,0,0,D)])
M.LLL()

Whose output is not exactly the same thing produced by the above Magma code. I think the main problem is that I use a matrix and just apply the LLL algorithm to it in the Sage part. Whereas, in Magma there a lattice created, and then the LLLBasisMatrix function (https://magma.maths.usyd.edu.au/magma/handbook/text/312#2964) called. Roughly speaking that function does this:

Given a lattice L with basis matrix B, return the LLL basis matrix B' of L, together with the transformation matrix T such that B'=TB. The LLL basis matrix B' is simply defined to be a LLL-reduced form of B; it is stored in L when computed and subsequently used internally by many lattice functions. The LLL basis matrix will be created automatically internally as needed with δ=0.999 by default (note that this is different from the usual default of 0.75); by the use of parameters to this function one can ensure that the LLL basis matrix is created in a way which is different to the default.

How does one create a lattice in Sage? And does Sage have a function similar to LLLBasisMatrix above? If not, how can I achieve the same functionality in Sage?

As for numeric example, I have the following values:

N2t = 1136868377216160297393798828125
D = 53364935730486508893809772233249725927747397616650814998641
tau = 954690521650617175389887577728

and if I call the above Magma code with these values, I get the following result for the basis matrix:

[-182177855565543122003911250397                               1]
[ 772512666085074053385976327331                               2]

whereas if I call the above Sage code with the above values, I get the following result:

[1136868377216160297393798828125                                                           0                              954690521650617175389887577728                                                           1]
[1                                                           0                                                           0 53364935730486508893809772233249725927747397616650814998641]
click to hide/show revision 7
retagged

Lattices in Sage

I have the following Magma code, and I want to rewrite it in Sage.

L:=Lattice(Matrix(Rationals(),2,2,[N2t,0,tau,1]), Matrix(Rationals(),2,2,[1,0,0,D]));
"Lattice:\n",L;
"\nBasis matrix:\n",LLLBasisMatrix(L);

In Sage I have something like this:

M = Matrix(QQ, [(N2t,0,tau,1), (1,0,0,D)])
M.LLL()

Whose output is not exactly the same thing produced by the above Magma code. I think the main problem is that I use a matrix and just apply the LLL algorithm to it in the Sage part. Whereas, in Magma there a lattice created, and then the LLLBasisMatrix function (https://magma.maths.usyd.edu.au/magma/handbook/text/312#2964) called. Roughly speaking that function does this:

Given a lattice L with basis matrix B, return the LLL basis matrix B' of L, together with the transformation matrix T such that B'=TB. The LLL basis matrix B' is simply defined to be a LLL-reduced form of B; it is stored in L when computed and subsequently used internally by many lattice functions. The LLL basis matrix will be created automatically internally as needed with δ=0.999 by default (note that this is different from the usual default of 0.75); by the use of parameters to this function one can ensure that the LLL basis matrix is created in a way which is different to the default.

How does one create a lattice in Sage? And does Sage have a function similar to LLLBasisMatrix above? If not, how can I achieve the same functionality in Sage?

As for numeric example, I have the following values:

N2t = 1136868377216160297393798828125
D = 53364935730486508893809772233249725927747397616650814998641
tau = 954690521650617175389887577728

and if I call the above Magma code with these values, I get the following result for the basis matrix:

[-182177855565543122003911250397                               1]
[ 772512666085074053385976327331                               2]

whereas if I call the above Sage code with the above values, I get the following result:

[1136868377216160297393798828125                                                           0                              954690521650617175389887577728                                                           1]
[1                                                           0                                                           0 53364935730486508893809772233249725927747397616650814998641]