William Stein wrote: > On Wed, Sep 17, 2008 at 8:02 AM, Jason Merrill <[EMAIL PROTECTED]> wrote: >> On Sep 17, 2:20 am, Jason Merrill <[EMAIL PROTECTED]> wrote: >>> Here's a monkeypatch that makes this work(ish) >>> >>> from sage.calculus.calculus import SymbolicExpression >>> class FormalSymbolicExpression(SymbolicExpression): >>> def __init__(self,expr): >>> self.expr = expr >>> # just delegate everything to the input expression >>> for m in dir(expr): >>> self.m = m >>> def _repr_(self,simplify=False): >>> return self.expr._repr_(simplify=False) >>> # implement a _latex_ method >>> >>> SymbolicExpression.formal = lambda self: >>> FormalSymbolicExpression(self) >>> >>> def formal(expr): >>> try: >>> return expr.formal() >>> except AttributeError: >>> return expr >> Right... so that delegation bit doesn't actually do anything. This >> was leading to >> >> sage: simplify(formal(exp(I*pi))) >> e^(pi*I) >> >> and presumably horrendous amounts of other strangeness. Here's >> another try. It doesn't actually inherit from SymbolicExpression >> anymore, which will probably cause some difficulty with isinstance >> calls, but it's maybe a little closer >> >> from sage.calculus.calculus import SymbolicExpression >> class FormalSymbolicExpression(): >> def __init__(self,expr): >> self.expr = expr >> >> def __getattr__(self,attrib): >> return getattr(self.expr,attrib) >> >> def __repr__(self,simplify=False): >> return self.expr._repr_(simplify=False) >> >> SymbolicExpression.formal = \ >> lambda self: FormalSymbolicExpression(self) >> >> def formal(expr): >> try: >> return expr.formal() >> except AttributeError: >> return expr >> >> And now >> >> sage: simplify(formal(exp(I*pi))) >> -1 > > Jason, > > Just a heads up -- your code above is going to become pointless when we switch > to using Ginac as a backend for symbolic manipulation, since Sage will no > longer > keep its own expression tree.
I looked at your ginac/pynac symbolic stuff last night. It appears that you just call a Gex_to_str function (or something like that) to print out the expression, which presumably is a ginac thing. Calling latex() on any expression just returns \text{printed representation}. If Sage will not maintain the expression tree, will it be able to access it to print out a latex form? Does Ginac output latex versions of expressions? Thanks, Jason --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---