I'm not sure I follow.  If I create a test _eval_derivative method to
Symbol, like

diff --git a/sympy/core/symbol.py b/sympy/core/symbol.py
index 635c2c5..e1d36b1 100644
--- a/sympy/core/symbol.py
+++ b/sympy/core/symbol.py
@@ -24,6 +24,11 @@ class Symbol(AtomicExpr, Boolean):

     """

+    def _eval_derivative(self, s):
+        from sympy.core.function import Derivative
+        print 'test'
+        return Derivative(self, s)
+
     is_comparable = False

     __slots__ = ['is_commutative', 'name']

Then I get

In [1]: diff(x, x)
test
Out[1]:
d
──(x)
dx

So it's definitely being called.  It should be the same for any
subclass of Symbol.

The idea, for what you want to do, would be to make x.diff(t) return
some kind of object instead of 0 (i.e., make x kind of like x(t), but
the object returned would be a Symbol subclass, so that it can be
passed to diff()).

Aaron Meurer

On Fri, Jun 3, 2011 at 8:16 PM, Gilbert gede <[email protected]> wrote:
> You're talking about Symbol._eval_derivative?  I tried that within my
> extended Symbol class.  It returns 0 or 1 testing self == symbol.  I
> tried making some changes to it, but I don't think I can use it.  I
> think it doesn't even get called unless you do something like:
> t = timevaryingsymbols('t')
> Derivative(2+3*t,t)
> I think only when t is both part of (expr, symbols, ...) within
> Derivative's __new__ definition does t's _eval_derivative() method get
> called.
>
> -Gilbert
>
>
>
> On Jun 3, 6:53 pm, Aaron Meurer <[email protected]> wrote:
>> Can you just get what you want by overriding _eval_derivative()?
>>
>> Aaron Meurer
>>
>>
>>
>>
>>
>>
>>
>> On Fri, Jun 3, 2011 at 7:48 PM, Gilbert gede <[email protected]> wrote:
>> > I guess I should have asked this as well; is it considered bad to
>> > write diff() and replace the current Sympy diff() within my code? Or
>> > is that OK?
>>
>> > -Gilbert
>>
>> > On Jun 3, 6:38 pm, Gilbert gede <[email protected]> wrote:
>> >> Yeah, I had read some of them.  I had already thought of writing my
>> >> own Diff method or something and do substitution with it, but was
>> >> hoping to have the functionality I want work like standard SymPy
>> >> operations.  That's what I've been trying to do with my PyDy classes;
>> >> make them work more like you would expect other SymPy objects to.
>> >> I have read through Derivative() and diff(), and couldn't really find
>> >> a way to make them do what I want (like I said about my symbol
>> >> extension no longer having its methods called once it is inside a
>> >> SymPy add or mul).  I guess what I was hoping for was input on whether
>> >> I could make Derivative do what I want with my extended Symbol, as I
>> >> couldn't really see how.  But if writing my own Diff method is the
>> >> only option, there's not much I can do then.
>>
>> >> Thanks,
>> >> -Gilbert
>>
>> >> On Jun 3, 5:53 pm, "Aaron S. Meurer" <[email protected]> wrote:
>>
>> >> > This has actually been discussed quite a bit before (a lot of people 
>> >> > want to use Lagrangians).  You can search the mailing list.  From what 
>> >> > I've seen, you will either have to write your own custom diff routine 
>> >> > or do clever substitution of functions and derivatives with symbols.  I 
>> >> > don't think I've ever seen anyone suggest extending Symbol to hold a 
>> >> > time derivative, which is essentially just a more formal way of doing 
>> >> > the substation method.  It might work.
>>
>> >> > Aaron Meurer
>>
>> >> > On Jun 3, 2011, at 6:05 PM, Gilbert Gede wrote:
>>
>> >> > > Hi,
>> >> > > I was trying to implement some functionality for PyDy for this year's 
>> >> > > GSoC, and was looking for some advice.
>> >> > > In dynamics problems, you usually have time-varying quantities, like 
>> >> > > generalized coordinates, speeds, and accelerations.  Often, you want 
>> >> > > to take the partial derivative of an expression with respect to the 
>> >> > > time derivative of one of these quantities.  This come up when using 
>> >> > > Lagrange's Method (or Kane's Method).  It's described to some degree 
>> >> > > here:
>> >> > >http://en.wikipedia.org/wiki/Lagrangian_mechanics
>> >> > >https://gist.github.com/1005937
>> >> > > In Lagrange's Method, you end up taking the partial derivative of the 
>> >> > > energy with respect to the time derivative of a generalized 
>> >> > > coordinate.  I'm trying to figure out a way to make this work in 
>> >> > > PyDy/SymPy. Derivative won't take in anything but a Symbol.
>> >> > > The only idea I have come up with is to extend Symbol and write my 
>> >> > > own .diff() method for it which returns a new symbol representing the 
>> >> > > time differentiation of the original extended Symbol.  Once my new 
>> >> > > object is inside a Mul or Add sympy object, then my .diff() method is 
>> >> > > no longer called.
>> >> > > Can anyone give some insight into how I could get this desired 
>> >> > > behavior, taking the derivative of an expression wrt a 
>> >> > > time-differentiated symbol, to work in a way consistent with existing 
>> >> > > SymPy behavior?  Thanks.
>>
>> >> > > -Gilbert
>>
>> >> > > --
>> >> > > You received this message because you are subscribed to the Google 
>> >> > > Groups "sympy" group.
>> >> > > To post to this group, send email to [email protected].
>> >> > > To unsubscribe from this group, send email to 
>> >> > > [email protected].
>> >> > > For more options, visit this group 
>> >> > > athttp://groups.google.com/group/sympy?hl=en.
>>
>> > --
>> > You received this message because you are subscribed to the Google Groups 
>> > "sympy" group.
>> > To post to this group, send email to [email protected].
>> > To unsubscribe from this group, send email to 
>> > [email protected].
>> > For more options, visit this group 
>> > athttp://groups.google.com/group/sympy?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "sympy" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/sympy?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to