I don't think the __init__ function in Expression is usable as it is.
Here is the code:
def __init__(self, SR, x=0):
cdef GEx exp
GEx_construct_pyobject(exp, x)
GEx_construct_ex(&self._gobj, exp)
self._parent = SR
The line with GEx_construct_pyobject() coerces the symbolic expression
you give it to a constant numeric object. Then, in your construction, b
becomes a constant.
sage: b.operator() # this returns None since it's a constant
sage: t.operator()
f
After applying the patch below, the following works:
----------------------------------------------------------------------
| Sage Version 4.0.1, Release Date: 2009-06-06 |
| Type notebook() for the GUI, and license() for information. |
----------------------------------------------------------------------
Loading Sage library. Current Mercurial branch is: la
sage: from sage.symbolic.expression import Expression
sage: class esub(Expression):
....: def __init__(self, parent, val):
....: Expression.__init__(self, parent, val)
....:
sage: f = function('f')
sage: g = function('g')
sage: t = f(x)
sage: b = esub(SR, t)
sage: b.substitute_function(f, g)
g(x)
This still doesn't solve your problem though, most methods of
Expression will return Expression objects.
sage: type(b.substitute_function(f, g))
<type 'sage.symbolic.expression.Expression'>
Can you explain your application a little?
Cheers,
Burcin
diff --git a/sage/symbolic/expression.pyx b/sage/symbolic/expression.pyx
--- a/sage/symbolic/expression.pyx
+++ b/sage/symbolic/expression.pyx
@@ -212,9 +212,8 @@
sage: sage.symbolic.expression.Expression(SR, 5)
5
"""
- cdef GEx exp
- GEx_construct_pyobject(exp, x)
- GEx_construct_ex(&self._gobj, exp)
+ cdef Expression exp = self.coerce_in(x)
+ GEx_construct_ex(&self._gobj, exp._gobj)
self._parent = SR
def __dealloc__(self):
On Fri, Jun 12, 2009 at 2:09 AM, Nicolas<nicolas.f...@gmail.com> wrote:
>
> Dear Burcin,
>
> Just one quick question about patches, I have just changed the
> expression.pyx file and ran another make (which took not so much
> time).
After you make the change to the file, just run "sage -br" (for build
and run) to compile your changes and make them active.
--Mike
On Fri, 12 Jun 2009 02:09:08 -0700 (PDT)
Nicolas <nicolas.f...@gmail.com> wrote:
> Just one quick question about patches, I have just changed the
> expression.pyx file and ran another make (which took not so much
> time). But it does not seem to work. Is this simple way of applying
> patch enough or do I have to go through the mercurial system ?
You need to do
./sage -br
From your other message:
> I will try out your patch. Why do you say that does not solve my
> problem ?
You'll see that whenever you perform arithmetic on the new objects,
you'll end up with Expression's again.
< assuming the class esub was defined as in my previous message >
sage: var('x,y,z')
(x, y, z)
sage: t = x * y^z
sage: u = esub(SR, t)
sage: u
y^z*x
sage: type(u)
<class '__main__.esub'>
sage: type(u*u)
<type 'sage.symbolic.expression.Expression'>
Let's see how far you get with the patch. I'll try to see if there is
a simple fix to make Expression behave well w.r.t. object oriented
design.
Cheers,
Burcin