ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 06 Jun 2012 08:02:20 +0200Converting string into number does not work properlyhttps://ask.sagemath.org/question/9034/converting-string-into-number-does-not-work-properly/Here is an example with huge integer number "n".
n=2^7000000;
Sage can convert huge integer number into string very quickly:
s=str(n);
But the other way, i.e. the same huge string converting back into integer number is very slow:
m=int(s);
It should be done in approximately same time as variables "m", "n", "s" are of the same length.
I also tried to use eval(s) and sage_eval(s) instead of int(s) and all are very slow.
Mathematica can do all the above operation much more quickly than Sage.
Do you know, where the problem is?
Is there some other function besides "int", "eval" and "sage_eval" that can do it faster?azerbajdzanWed, 06 Jun 2012 08:02:20 +0200https://ask.sagemath.org/question/9034/Cannot convert int to sage.rings.integer.Integerhttps://ask.sagemath.org/question/8099/cannot-convert-int-to-sageringsintegerinteger/I created a minimal example in the file bad.py
from sage.all import *
j = 0
m = matrix(3,3)
m.insert_row(j, [1,1,1])
Then from sage:
sage: load bad.py
TypeError: Cannot convert int to sage.rings.integer.Integer
I think I can see an easy workaround, I can wrap all the 1's in Integer() (or change the name of the file to .sage so the preparser does it), but why is that necessary? Is this a bug? Why would sage not be able to convert int to Integer? Isn't that a pretty obvious conversion?
paragonMon, 02 May 2011 14:23:12 +0200https://ask.sagemath.org/question/8099/