Hi Jose,

On Sun, Apr 4, 2010 at 8:50 PM, Jose Guzman <[email protected]> wrote:

<SNIP>

> For example, if I do:
>
> $    ./sage -ipython -nobanner
>>>> from sage.all import *
>>>> f(x) = x**2
>
> I found the following error:

That's because when you define a function on the Sage command line,
the function definition is first preparsed using the Sage preparser.

[mv...@sage ~]$ sage -ipython -nobanner

In [1]: from sage.all import *

In [2]: preparse("f(x) = x**2")
Out[2]: '__tmp__=var("x"); f = symbolic_expression(x**Integer(2)).function(x)'

In [3]: x = var("x")

In [4]: f  = symbolic_expression(x**Integer(2)).function(x)

In [5]: f(3)
Out[5]: 9


> By the way, I did not find much documentation regarding the use of the Sage
> in command-line mode, or about how to call Sage as a Python library. If this
> is not already present, I will try to add this (after reading the developers
> guide) to the standard Sage documentation.

See a blog post [1] about this topic. If you would like to add such
information to the Sage standard documentation, maybe we could
collaborate on writing such a document.

When you are using Sage as a Python library, be careful not to do
anything that relies on the Sage preparser. Try to expect Python
behaviour. For example, on the Sage command line, the caret notation
"^" for exponentiation is preparsed to the double asterisks notation
"**", before carrying out any simplification. So you should use "**"
in Python scripts that uses the Sage library, and avoid using "^".

[1] http://mvngu.wordpress.com/2009/10/08/how-to-use-sage-as-a-python-library/

-- 
Regards
Minh Van Nguyen

-- 
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

To unsubscribe, reply using "remove me" as the subject.

Reply via email to