80 views

Skip to first unread message

Nov 27, 2012, 5:23:01 AM11/27/12

to sage-s...@googlegroups.com

Hi,

I'm pretty sure this question has been answered over and over but

despite intensive googling I could not find these answers.

I have expressions (say, f = exp(x)) that want to export to another

computing system.

str(f) is 'e^x' but the target system does not understand it.

Is there a way to have a string version of f with the exp() notation

preserved?

Thanks in advance and sorry for being so dumb.

--

Regards,

Serge Torres

I'm pretty sure this question has been answered over and over but

despite intensive googling I could not find these answers.

I have expressions (say, f = exp(x)) that want to export to another

computing system.

str(f) is 'e^x' but the target system does not understand it.

Is there a way to have a string version of f with the exp() notation

preserved?

Thanks in advance and sorry for being so dumb.

--

Regards,

Serge Torres

Nov 27, 2012, 6:16:20 AM11/27/12

to sage-s...@googlegroups.com

On Tue, 27 Nov 2012 11:23:01 +0100

Serge Torres <Serge....@laposte.net> wrote:

> I'm pretty sure this question has been answered over and over but

> despite intensive googling I could not find these answers.

>

> I have expressions (say, f = exp(x)) that want to export to another

> computing system.

>

> str(f) is 'e^x' but the target system does not understand it.

>

> Is there a way to have a string version of f with the exp() notation

> preserved?

This is #11428 on trac.
Serge Torres <Serge....@laposte.net> wrote:

> I'm pretty sure this question has been answered over and over but

> despite intensive googling I could not find these answers.

>

> I have expressions (say, f = exp(x)) that want to export to another

> computing system.

>

> str(f) is 'e^x' but the target system does not understand it.

>

> Is there a way to have a string version of f with the exp() notation

> preserved?

http://trac.sagemath.org/sage_trac/ticket/11428

The patch on the ticket does not work. It needs to go through the

registry of functions stored in Pynac and update the name or the

printing functions there. Unfortunately I don't have time to implement

that right now.

As a workaround in your case, you can modify the definition of

Function_exp in sage/functions/log.py to set a latex_name in the

initializer, or if that doesn't work, define a _print_latex_ method.

Cheers,

Burcin

Nov 27, 2012, 11:15:44 AM11/27/12

to sage-s...@googlegroups.com

Create a symbolic function fn that prints as '\exp', replace e^x in your

expression with fn, translate the new expression to latex:

# the top level function method injects the name of the function into

# the name space. I don't want to overwrite the exp method in the top

# level. Hence the import

sage: from sage.symbolic.function_factory import function

sage: fn = function('exp', latex_name='\exp')

sage: fn

exp

sage: type(exp)

<class 'sage.functions.log.Function_exp'>

sage: latex(fn(x))

\exp\left(x\right)

sage: t = exp(x^2) + (x+1)*exp(a^2+b)

sage: latex(t)

{\left(x + 1\right)} e^{\left(a^{2} + b\right)} + e^{\left(x^{2}\right)}

sage: latex(t.substitute_function(exp, myfn))

{\left(x + 1\right)} \exp\left(a^{2} + b\right) + \exp\left(x^{2}\right)

Cheers,

Burcin

Reply all

Reply to author

Forward

0 new messages

Search

Clear search

Close search

Google apps

Main menu