# So far, so good
sage: n=var('n')
sage: f=e^(i*x*pi*n-i*2*pi*n)
sage: f.simplify_full()
e^(I*pi*n*x - 2*I*pi*n)
# Is there a way I can get this to simplify?
sage: latex(f)
e^{\left(I \, \pi n x + \left(-2 I\right) \, \pi n\right)}
# Why the "extra" parentheses around -2I ?
--Mike
Well, I hope to hear from one of these Maxima experts!
> Of course, you can do this ahead of time:
>
> sage: e^((n*pi-pi*2).factor())
> e^((n - 2)*pi)
>
> but this is probably not what you want.
Right. This crops up in the middle of a more complicated
expression. If I could figure out how to break the expression
up in the right way, then I guess I could search for parts
that are exponential functions, take the log of those, and
then simplify the logs. I know how to ultimately find all
the pieces of the function with .operands(), but I don't
then know any way to put them back together with the
proper operators. Maybe there's a way to access the parsed
tree of the expression? But of course that's crazy.
There must be a "normal" way to simplify it!
> > sage: latex(f)
> > e^{\left(I \, \pi n x + \left(-2 I\right) \, \pi n\right)}
> >
> > # Why the "extra" parentheses around -2I ?
>
> No idea. Pynac usually handles these sorts of things; I'm not sure
> whether I would call it a bug, though it does seem strange. Perhaps
> Pynac represents this as a complex internally and so this happens?
> Burcin will know :)
>
> - kcrisman
>
> --
> To post to this group, send email to sage-s...@googlegroups.com
> To unsubscribe from this group, send email to
> sage-support...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/sage-support
> URL: http://www.sagemath.org
>
>
>
>
>
>
This is all good information, thanks. It helps to at least know
that I'm not missing something obvious. It's the combination with
that latex issue that results in some really ugly output.
I've noticed too about how maxima continues to ask things that
(it would seem) you have already told it. I guess it would be
in my best interests to learn more about maxima.
Thanks again,
-Mike
Well ... I can see how one might work one's way
through the expression, using the operator() and operands()
functions. And, I suppose, I can see how one could then build
up the equivalent expression, having modified one of the
operands in a certain way. So, I don't suppose that there is
actually any need for a custom data structure to do this.
I guess it's really just a question of whether the way
these expressions sometimes display in latex bothers me
enough to do something about it, other than just complain.
Although ... I guess I'm still a bit confused as to why
this happens, even given the form of the exponential.
sage: f = e^(2*I*pi*n*x - 2*I*pi*n)
sage: latex(f)
e^{\left(\left(2 I\right) \, \pi n x + \left(-2 I\right) \, \pi
n\right)}
Still, I shouldn't really get +(−2i) right? I think you
mentioned something about Pynac (another program I know
nothing about). It seems like trying to fix this just
involves learning too much of a learning curve for me
to contemplate.
-Mike
See http://sagenb.org/home/pub/1760/ for an example of creating an
expression tree (in that worksheet, the expression tree is used to make
a mathematica expression...)
Thanks,
Jason
Hey, that's really cool. Thanks!
BTW, at this point, after the further Latex discussion, I realize
that my original problem was really more related to Ticket #9314
than to the expression itself (at least, that's what I'm currently
speculating). But, especially with that example,
it's pretty clear to me what to do if I need to parse an expression.
I believe that Ticket #9329 was generated in response to my original
post, before I understood that there was a Latex issue involved.
I believe that Ticket #9329 should be deleted (closed or whatever).
-Mike
OK, sure, that makes sense.
> I do hope the LaTeX issue gets resolved for you soon, though.
My current theory is that it will be resolved if Ticket #9314
gets fixed. But I don't really know that for sure :-)
> On 06/25/2010 06:07:02 AM, kcrisman wrote:
> > Dear Mike,
> >
> > Just to follow up:
> >
> > There is further discussion at
> > http://trac.sagemath.org/sage_trac/ticket/9329
> > if you are interested in saying exactly what sort of data structure
> > would enable you to perform the simplifications you would like to
> > without having to create a custom Maxima simplification routine.
> >
> > - kcrisman
>
> Well ... I can see how one might work one's way
> through the expression, using the operator() and operands()
> functions. And, I suppose, I can see how one could then build
> up the equivalent expression, having modified one of the
> operands in a certain way. So, I don't suppose that there is
> actually any need for a custom data structure to do this.
As far as I understand from your previous comments, a way to extract the
exponential functions from the expression is all you need. You don't
really need to walk through the tree. Here is one way to do this:
sage: t = exp(x+y)*(x-y)*(exp(y)+exp(z-y))
sage: t
(e^(-y + z) + e^y)*(x - y)*e^(x + y)
sage: w = SR.wild()
sage: t.find(exp(w))
[e^(-y + z), e^(x + y), e^y]
You can then change the expressions in the given array and substitute
new values for them:
sage: t.subs({res[1]: sin(res[1].operands()[0])})
(e^(-y + z) + e^y)*(x - y)*sin(x + y)
The .operands()[0] syntax is really cumbersome. We need a shortcut for
this. I thought .op(0) worked for pynac expressions before we switched
from the maxima backend.
> Although ... I guess I'm still a bit confused as to why
> this happens, even given the form of the exponential.
>
> sage: f = e^(2*I*pi*n*x - 2*I*pi*n)
> sage: latex(f)
> e^{\left(\left(2 I\right) \, \pi n x + \left(-2 I\right) \, \pi
> n\right)}
>
> Still, I shouldn't really get +(-2i) right?
This is a bug:
http://trac.sagemath.org/sage_trac/ticket/9394
I'll fix this when I have time to work on pynac again.
Cheers,
Burcin
Thanks. That's a good idea. I'll try that.
-Mike