I was musing about formal symbolic expressions on sage support:

http://groups.google.com/group/sage-support/browse_thread/thread/78dc8d2d476acc46

but thought it was time to move it over to devel.  The motivation is
to have a nice notation for formal integrals and derivatives:

sage: integral(sin(x),x).formal()
integral(sin(x),x)

If this is a good idea, then maybe it's a good idea to have a formal
method for all symbolic expressions.

sage: (x - x).formal()
x - x

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

Let's see it in action

sage: x - x
0
sage: (x - x).formal()
x - x
sage: formal(x - x)
x - x
sage: simplify(formal(x - x))
0

sage: exp(i*pi)
-1
sage: formal(exp(i*pi))
exp(I*pi)

This won't work on integral or derivative yet because they aren't lazy
enough.  But it seems like they could be made to behave like the
Function_* classes, for instance Function_exp above.

Cheers,

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
-~----------~----~----~----~------~----~------~--~---

Reply via email to