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.Thu, 03 Sep 2020 07:23:29 +0200How to handle very large numbershttps://ask.sagemath.org/question/53274/how-to-handle-very-large-numbers/I want to play around with factorials. I found that `factorial(10**9)` takes about 20 minutes (on my machine, which is a Mac mini with 8GB Memory). Then I tried `factorial(10**10)` and there I got this:
/Applications/...pathtoSageMath/sage/src/bin/sage-python: line 2: 975 Killed: 9 sage - python "$@"
Then I searched for a SageMath Stirling Formula, which I didn't find (only some related stuff), so I tried it myself:
sage: def s(n):
....: x=sqrt(2*pi*n)*((n/e)**n)
....: return x.numerical_approx()
....:
sage: s(5)
118.019167957590
sage: s(6)
710.078184642185
sage: s(10**10)
This gave me an error after some minutes:
RuntimeError
...
4047 relational_operator(self._gobj))
4048 else:
-> 4049 x = g_pow(self._gobj, nexp._gobj)
4050 return new_Expression_from_GEx(self._parent, x)
4051
RuntimeError: size of exponent exceeds signed long size
Then I tried s(10**9), there I got another error:
python3(755,0x10fbecdc0) malloc: can't allocate region
:*** mach_vm_map(size=18446744073151754240, flags: 100) failed (error code=3)
python3(755,0x10fbecdc0) malloc: *** set a breakpoint in malloc_error_break to debug
sig_error() without sig_on()
------------------------------------------------------------------------
(no backtrace available)
------------------------------------------------------------------------
Unhandled SIGABRT: An abort() occurred.
This probably occurred because a *compiled* module has a bug
in it and is not properly wrapped with sig_on(), sig_off().
Python will now terminate.
So what can I do? Is there a special library for very large reals or int or some special commands for getting an approximation of how many decimals a factorial will have? Could I use the `log` somehow or would this have the same runtime problems?
The reason why I'm asking is that I am rewriting a text which is 20 years old and there's a statement that `factorial(10**100)` could not be computed (ok, I believe that because of factorial being between `O(2**n)` and `O(2**(2**n))`) and `factorial(10**8)` would take many hours, which was not the case on my machine (see above).
And last but not least I would like to know if there is an upper bound for numbers that sage can handle. I thought not, but now I know otherwise ;-)
Also hints to good literature on these topics would be appreciated.
dantetanteThu, 03 Sep 2020 07:23:29 +0200https://ask.sagemath.org/question/53274/ContinuedFractions fail on large integers?https://ask.sagemath.org/question/38309/continuedfractions-fail-on-large-integers/ I've been doing some work with continued fractions, and when I get to a large enough number, I start hitting an error. For example, with the ContinuedFraction from [(18806263158919164762262694978536817267490601162205305175017345804331141023863425152608922362862834892943764814900901973487239748665085369033027389281788183,), [1, 1, 1, 1, 37612526317838329524525389957073634534981202324410610350034691608662282047726850305217844725725669785887529629801803946974479497330170738066054778563576366]]), I get the error below.
Specifically, I get it after I've created a ContinuedFraction with the arguments above, and then call .value() on it. I've tried to make sure all of those are sage Integer types, but it doesn't seem to help, and it looks like internally the CF code is overflowing somewhere. Is there any way around this, or is this a limitation I'll have to live with?
Thanks for any help!
Traceback (most recent call last):
File "/home/tc/Downloads/sagetemp/SageMath/local/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
self.run()
File "/home/tc/Downloads/sagetemp/SageMath/local/lib/python2.7/multiprocessing/process.py", line 114, in run
self._target(*self._args, **self._kwargs)
File "/home/tc/code/cfp/pi/piX/ones.py", line 16, in leeloo
v = ocf.value()
File "/home/tc/Downloads/sagetemp/SageMath/local/lib/python2.7/site-packages/sage/rings/continued_fraction.py", line 1423, in value
Q = QuadraticField(DD, 'sqrt%d' % DD)
File "/home/tc/Downloads/sagetemp/SageMath/local/lib/python2.7/site-packages/sage/rings/number_field/number_field.py", line 922, in QuadraticField
return NumberField(f, name, check=False, embedding=embedding, latex_name=latex_name, **args)
File "/home/tc/Downloads/sagetemp/SageMath/local/lib/python2.7/site-packages/sage/rings/number_field/number_field.py", line 524, in NumberField
return NumberField_version2(polynomial=polynomial, name=name, check=check, embedding=embedding, latex_name=latex_name, assume_disc_small=assume_disc_small, maximize_at_primes=maximize_at_primes, structure=structure)
File "sage/structure/factory.pyx", line 362, in sage.structure.factory.UniqueFactory.__call__ (/home/tc/Downloads/sagetemp/SageMath/src/build/cythonized/sage/structure/factory.c:1856)
File "/home/tc/Downloads/sagetemp/SageMath/local/lib/python2.7/site-packages/sage/rings/number_field/number_field.py", line 612, in create_key_and_extra_args
x = number_field_morphisms.root_from_approx(polynomial, embedding)
File "sage/rings/number_field/number_field_morphisms.pyx", line 490, in sage.rings.number_field.number_field_morphisms.root_from_approx (/home/tc/Downloads/sagetemp/SageMath/src/build/cythonized/sage/rings/number_field/number_field_morphisms.c:7640)
File "sage/rings/real_lazy.pyx", line 1584, in sage.rings.real_lazy.LazyAlgebraic.__init__ (/home/tc/Downloads/sagetemp/SageMath/src/build/cythonized/sage/rings/real_lazy.c:17914)
File "sage/rings/polynomial/polynomial_element.pyx", line 7247, in sage.rings.polynomial.polynomial_element.Polynomial.roots (/home/tc/Downloads/sagetemp/SageMath/src/build/cythonized/sage/rings/polynomial/polynomial_element.c:68115)
File "sage/rings/polynomial/polynomial_element.pyx", line 7143, in sage.rings.polynomial.polynomial_element.Polynomial.roots (/home/tc/Downloads/sagetemp/SageMath/src/build/cythonized/sage/rings/polynomial/polynomial_element.c:64632)
File "sage/rings/polynomial/polynomial_element.pyx", line 5786, in sage.rings.polynomial.polynomial_element.Polynomial._pari_ (/home/tc/Downloads/sagetemp/SageMath/src/build/cythonized/sage/rings/polynomial/polynomial_element.c:55229)
File "sage/rings/polynomial/polynomial_element.pyx", line 5839, in sage.rings.polynomial.polynomial_element.Polynomial._pari_with_name (/home/tc/Downloads/sagetemp/SageMath/src/build/cythonized/sage/rings/polynomial/polynomial_element.c:55757)
File "sage/rings/real_mpfr.pyx", line 3103, in sage.rings.real_mpfr.RealNumber._pari_ (/home/tc/Downloads/sagetemp/SageMath/src/build/cythonized/sage/rings/real_mpfr.c:22771)
ValueError: Cannot convert NaN or infinity to Pari floatcappalloTue, 18 Jul 2017 16:31:37 +0200https://ask.sagemath.org/question/38309/Does QuadraticField use any special algorithms for computing the class group of quadratic imaginary number fields?https://ask.sagemath.org/question/26922/does-quadraticfield-use-any-special-algorithms-for-computing-the-class-group-of-quadratic-imaginary-number-fields/ I need to compute the class group of a quadratic imaginary number field that has a fairly large discriminant (over 96 bits.) I was wondering what, if any, algorithms the QuadraticField class uses for computing the class group.
Dan ShumowFri, 22 May 2015 22:23:45 +0200https://ask.sagemath.org/question/26922/How do I deal with large, hex numbers in Sage?https://ask.sagemath.org/question/26061/how-do-i-deal-with-large-hex-numbers-in-sage/ How do I deal with large, hex numbers in Sage (say ones with 256 or 512 bytes)? How would I import them from a CSV file?
(cf. [this related answer](http://ask.sagemath.org/question/24708/how-to-enter-very-large-numbers/?answer=24710#post-id-24710))GeremiaSat, 07 Mar 2015 17:47:47 +0100https://ask.sagemath.org/question/26061/How to enter very large numbershttps://ask.sagemath.org/question/24708/how-to-enter-very-large-numbers/ Hi,
What is the best way to enter very large integers ( more than a thousand integers) on sage online? I tried to split the number into multiple lines using continuation symbols like \ and ... but nothing works. The horizontal scroll bar is not showing up when i enter the number on a single line. Thanks for your help.
anonmoziThu, 30 Oct 2014 15:42:42 +0100https://ask.sagemath.org/question/24708/