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 Regards, JM --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---