On Apr 23, 2010, at 1:37 AM, bb wrote:
Mike Hansen schrieb:
On Mon, Apr 19, 2010 at 11:52 AM, bb <bblo...@arcor.de> wrote:
I get a runtime error, but just would expect infinity! Is there
something
wrong or any explanation?
This is because when you do 2^3^4^5 you are computing that number
exactly as an integer, and that number is definitely not infinity.
If
you wanted to use floating point arithmetic, then you should start
with something like 2.0:
sage: 2.0^3^4^5
+infinity
Doing something like float(2^3^4^5) computes 2^3^4^5 as an integer
and
then tries to convert that to a float.
Also, note that when you type in such an expression, the operations
are done in the following manner:
var(sage: var('x, y, z')
(x, y, z)
sage: x^y^z
x^(y^z)
which is different than
sage: (x^y)^z
(x^y)^z
Since exponentiation is non-associative, you need to be careful with
such differences.
--Mike
Thank you for your answer! I think there is a fundamental question
left apart from the question of assoziativity/non-assoziativity.
There Sage (I think coming from python) does not follow the common
rule to evaluate an expression with operators of the same precedence
from left tor right.
The exponentiation operator is a common exception to the left-to-right
rule. This is probably because a^(b^c) is more useful than (a^b)^c =
a^(b*c). Magma, Mathematica, and even bc follow the right-to-left rule
for exponentiation. (Maple actually raises an error if you don't have
the parenthesis.)
Since Georg Cantor there is a difference between countable infinity
(in the actual example) and noncountable infinity ( in the example
calculated with a float). I would not say, that infinity is wrong in
this case, only just because there is existing an infinite set of
integers so that infinity never might be reached.
The infinity given here has nothing to do with set cardinalities, it
is better understood as the compactification of the real line.
(I think that is the line of argument of your explanation?) The
essential point is, one has to map the unlimited ideas of math to
the restricted possibilities of a computer.
From a mathamatical point of view one can call the result of the
calculation
sage: 2^(3^(4^5))
---------------------------------------------------------------------------
RuntimeError Traceback (most recent
call last)
/home/bb/sage-4.3.5/<ipython console> in <module>()
/home/bb/sage-4.3.5/local/lib/python2.6/site-packages/sage/rings/
integer.so in sage.rings.integer.Integer.__pow__ (sage/rings/
integer.c:12114)()
RuntimeError: exponent must be at most 9223372036854775807
sage:
just a bug! Infinity is infinity, if countable or not countable. The
correct math-answer only could be countable infinity! But I think
infinity would in any case be better than "RuntimeError" as an answer!
I strongly disagree--infinity is an approximation to very large
numbers, not an exact answer. This is fine for floating point numbers
where one is only working with approximations to real numbers anyways,
but integer arithmetic is supposed to be exact. The error above is
desirable, as it tells you it can't to the computation because it
can't represent the result in memory (in particular, no one I know has
a place to store all 9223372036854775807 x 8 bytes of the answer).
- Robert
--
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org