Ask Your Question
1

Syntax error on limit

asked 2014-07-16 15:35:44 +0100

Caterpillar gravatar image

updated 2014-07-16 16:06:33 +0100

I would like to execute

limit(((n^(2n)-2n!+n*log(n,10))^((n^(2n))/(n!)))/(n^(((2n)^(2n))/((n-1)!))),n=infinity)

but I obtain the well-known big huge error message with painful infos inside. I cannot manage to fix the error, since I do not understand what is.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_19.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("bGltaXQoKChuXigybiktMm4hK24qbG9nKG4sMTApKV4oKG5eKDJuKSkvKG4hKSkpLyhuXigoKDJuKV4oMm4pKS8oKG4tMSkhKSkpLG49aW5maW5pdHkp"),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>

  File "/tmp/tmpe9jdup/___code___.py", line 3
    limit(((n**(2n)-2n!+n*log(n,_sage_const_10 ))**((n**(2n))/(n!)))/(n**(((2n)**(2n))/((n-_sage_const_1 )!))),n=infinity)
                 ^
SyntaxError: invalid syntax

'Sage Version 6.1.1, Release Date: 2014-02-04'

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2014-07-16 16:01:06 +0100

slelievre gravatar image

updated 2014-07-16 16:15:02 +0100

For reference, I am using Sage 6.3.beta5, in the command-line, on my computer, so the error messages might look slightly different than those you see, but presumably they occur in the same places.

sage: version()
'Sage Version 6.3.beta5, Release Date: 2014-07-01'

When you are tracking an error, it helps to simplify the expression.

sage: limit(n*2n,n=infinity)
sage: limit(n*2n,n=infinity)
  File "<ipython-input-1-82ece3d42612>", line 1
    limit(n*2n,n=infinity)
             ^
SyntaxError: invalid syntax

The arrow is pointing to the error. In this case, the syntax error is in 2n, which you should type as 2*n.

Going further,

sage: limit(n!,n=infinity)
  File "<ipython-input-3-b3d491dc965e>", line 1
    limit(n!,n=infinity)
           ^
SyntaxError: invalid syntax

shows you that n! is not recognised. Use factorial(n).

Also, if you do:

sage: limit(n,n=oo)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-5-ed612516482f> in <module>()
----> 1 limit(n,n=oo)

/Applications/sage-6.3.beta5/local/lib/python2.7/site-packages/sage/calculus/calculus.pyc in limit(ex, dir, taylor, algorithm, **argv)
   1224     """
   1225     if not isinstance(ex, Expression):
-> 1226         ex = SR(ex)
   1227 
   1228     if len(argv) != 1:

/Applications/sage-6.3.beta5/local/lib/python2.7/site-packages/sage/structure/parent.so in sage.structure.parent.Parent.__call__ (build/cythonized/sage/structure/parent.c:8902)()

/Applications/sage-6.3.beta5/local/lib/python2.7/site-packages/sage/structure/coerce_maps.so in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (build/cythonized/sage/structure/coerce_maps.c:4203)()

/Applications/sage-6.3.beta5/local/lib/python2.7/site-packages/sage/structure/coerce_maps.so in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (build/cythonized/sage/structure/coerce_maps.c:4110)()

/Applications/sage-6.3.beta5/local/lib/python2.7/site-packages/sage/symbolic/ring.so in sage.symbolic.ring.SymbolicRing._element_constructor_ (build/cythonized/sage/symbolic/ring.cpp:5229)()

TypeError:

and that's because in Sage, n is a shortcut for the numerical_approximation function.

By contrast:

sage: limit(x,x=infinity)
+Infinity

Note that there is a convenient shortcut for infinity, which is oo, so you can type:

sage: limit(x,x=oo)
+Infinity

It's true that the error message for n is not very informative!

It gets more informative if you try:

sage: limit(2*n,n=infinity)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-9-fdebc251e72d> in <module>()
----> 1 limit(Integer(2)*n,n=infinity)

/Applications/sage-6.3.beta5/local/lib/python2.7/site-packages/sage/structure/element.so in sage.structure.element.RingElement.__mul__ (build/cythonized/sage/structure/element.c:15353)()

/Applications/sage-6.3.beta5/local/lib/python2.7/site-packages/sage/structure/coerce.so in sage.structure.coerce.CoercionModel_cache_maps.bin_op (build/cythonized/sage/structure/coerce.c:8323)()

TypeError: unsupported operand parent(s) for '*': 'Integer Ring' and '<type 'function'>'

There, Sage is telling you that it can't multiply an integer (here, 2) with a function (here, n).

To use n as a summation variable, first declare it as a symbolic variable:

sage: var('n')
n

Then things start to work.

sage: limit(n,n=oo)
+Infinity

And you can input the limit ... (more)

edit flag offensive delete link more

Comments

Hi, thank you for the exhaustive answer. Concerning `2n!` I don't know, I simply saw it as is, in the pdf of the professor. Concerning SageMath version, I edited my post. The command was executed on my Sagemath's server web interface.

Caterpillar gravatar imageCaterpillar ( 2014-07-16 16:15:31 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-07-16 15:35:44 +0100

Seen: 821 times

Last updated: Jul 16 '14