On Wed, Jul 22, 2009 at 8:52 PM, Golam Mortuza Hossain wrote:
>
> Hi,
>
> On Wed, Jul 22, 2009 at 11:49 PM, Bill Page wrote:
>
>>> ---------
>>> h = f(x^2).diff(x)*(x+1/x)
>>>
>>> sage: h.subs(f(x^2)==1)
>>> 2*(x + 1/x)*x*D[0](f)(x^2)
>>>
>>> sage: h.subs(f(x^2).diff(x)==0)
>>> 2*(x + 1/x)*x*D[0](f)(x^2)
>>> ---------
>>
>> It does not make sense to ask to "substitute" 'f(x^2)=1' into 'h'
>> because 'f(x^2)' is an expression - not a function.
>
> May be I didn't understand you properly. Are you saying substituting
> an expression (f(x^2)) within an expression (h) by a constant is
> invalid?
>

No. I am saying two things: First, 'f(x^2)' does not occur in the
value of 'h'. '.diff(x)' has already been evaluated as
'2*D[0](f)(x^2)'. Second the 'f' that does occur in the value of 'h'
represents a function - not an expression.

> If so, then isn't: "(x+x^2).subs(x==1)" invalid as well?
>

No. The expression 'x' does occur in '(x+x^2)'. This substitution is valid.

> Anyway, it does not help whether you substitute by
> a constant or by an expression, the problem remains.
> Within sage the only way I  know, to do above substitution is
> to do
> -------
> sage: h.subs(f(x^2).diff(x)/(2*x)==0)
> 0
> -------

What you need to do is to substitute a *function* for 'f' in
'...D[0](f)...' For example:

   q(x)=1
   h.subs({f:q}})

This used to work in previous releases of Sage. E.g.

wsp...@debian:~/sage-3.4$ ./sage
----------------------------------------------------------------------
| Sage Version 3.4, Release Date: 2009-03-11                         |
| Type notebook() for the GUI, and license() for information.        |
----------------------------------------------------------------------
sage: function('f')
f
sage: a=f(x)
sage: q(x)=1
sage: a.subs({f:q})
1

--

but it seems to have been broken recently (perhaps by the new coercion system?)

p...@boxen:~$ sage
----------------------------------------------------------------------
| Sage Version 4.1, Release Date: 2009-07-09                         |
| Type notebook() for the GUI, and license() for information.        |
----------------------------------------------------------------------
sage: function('f')
f
sage: a=f(x)
sage: q(x)=1
sage: a.subs({f:q})
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

/home/page/<ipython console> in <module>()

/usr/local/sage/local/lib/python2.6/site-packages/sage/symbolic/expression.so
in sage.symbolic.expression.Expression.substitute
(sage/symbolic/expression.cpp:13494)()

/usr/local/sage/local/lib/python2.6/site-packages/sage/symbolic/expression.so
in sage.symbolic.expression.Expression.coerce_in
(sage/symbolic/expression.cpp:9538)()

/usr/local/sage/local/lib/python2.6/site-packages/sage/structure/parent_old.so
in sage.structure.parent_old.Parent._coerce_
(sage/structure/parent_old.c:4632)()

/usr/local/sage/local/lib/python2.6/site-packages/sage/structure/parent.so
in sage.structure.parent.Parent.coerce
(sage/structure/parent.c:4765)()

TypeError: no canonical coercion from <type
'sage.symbolic.function.SFunction'> to Symbolic Ring

> However, even using such ugly tricks, I have encountered issues in
> substituting expression that contains new derivative.
>

I don't doubt it. I think these issues should be documented so
(eventually) they can be fixed.

Regards,
Bill Page.

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to 
sage-devel-unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to