#17445: Missing documentation of derivative operator/notation
-------------------------------+------------------------
       Reporter:  schymans     |        Owner:
           Type:  enhancement  |       Status:  new
       Priority:  major        |    Milestone:  sage-6.5
      Component:  symbolics    |   Resolution:
       Keywords:               |    Merged in:
        Authors:  schymans     |    Reviewers:
Report Upstream:  N/A          |  Work issues:
         Branch:               |       Commit:
   Dependencies:               |     Stopgaps:
-------------------------------+------------------------

Comment (by nbruin):

 Replying to [comment:20 schymans]:
 > {{{
 > sage: function('p',t)
 > sage: function('n', t)
 > sage: function('T', t)
 > sage: function('V', t)
 > sage: diff(eq_p,t)
 > p == R*T*n/V
 > 0 == 0
 > }}}
 Just by rebinding the names in the global scope, you do not change the
 identity of the consituents in `eq_p`. Those are still variables.
 Pointwise operations aren't supported for functions:
 {{{
 sage: function('f')
 f
 sage: function('g')
 g
 sage: f*g
 TypeError: unsupported operand type(s) for *: 'NewSymbolicFunction' and
 'NewSymbolicFunction'
 }}}

 > Alright, I thought, what about a system with constant volume?
 >
 > {{{
 > sage: eq_p = p(t) == n(t)*R*T(t)/V
 > }}}
 This already fails for me, because `V` at this point is a function and
 dividing a symbolic expression by a function isn't supported.

 > Pity, would have been too easy. Interestingly, this works instead:
 >
 > {{{
 > sage: eq_p = p(t) == n(t)*R*T(t)/V(x)
 > sage: diff(eq_p,t)
 > D[0](p)(t) == R*n(t)*D[0](T)(t)/V(x) + R*T(t)*D[0](n)(t)/V(x)
 > }}}
 >
 > I'm still confused. What I want to express by function('V', t) is that V
 is a function of t and hence needs to be treated as such when taking the
 derivative with respect to t.
 I don't think you can, because in sage, symbolic functions have variable
 *positions*, not *names*.


 > By writing V(t) above, I turn the function into an expression again,
 which does lead to the desired functionality, but you mentioned earlier
 that V(t) means "Function V evaluated at t", which to me means something
 different. I don't see the utility of defining function('V', t) in the
 above at all. I could have equally defined function('V', x), right?

 Or as `function('V')` for that matter. It seems misguided to me that
 `function` admits an argument list. It has no meaning other than that
 `function('V',x) == function('V')(x)`. I think the RHS syntax is much
 clearer.

 > What would be the correct way to do the above consistently?

 A "symbolic function" in sage is simply something that can occur in the
 "operator" slot of a symbolic expression. I don't think there is much
 support for algebra on such objects. Hence the need to talk about `V(t)`
 and `V(x)` (but better not in the same expression! Then you should use
 `V(x,t)` and be consistent about the order in which `x,t` occur). If you
 absolutely need to make the thing into a "function" again, you could turn
 it into a "callable symbolic expression":
 {{{
 sage: A = n(t)*R*T(t)/V(x)
 sage: p=diff(A,t).function(t)
 sage: p
 t |--> R*n(t)*D[0](T)(t)/V(x) + R*T(t)*D[0](n)(t)/V(x)
 sage: parent(p)
 Callable function ring with arguments (t,)
 }}}
 You do have to decide beforehand if `V` is going to be a function of `x`
 or of `t` or of both. Also, the expression above should probably be
 {{{
 sage: p=diff(A,t).function(x,t)
 sage: p
 (x, t) |--> R*n(t)*D[0](T)(t)/V(x) + R*T(t)*D[0](n)(t)/V(x)
 sage: parent(p)
 Callable function ring with arguments (x, t)
 }}}

 The root cause of this is the following: `sin` is a function, right? You
 know the meaning of `sin(x)` and of `sin(y)`, right? So is `sin` a
 function of `x` or of `y`? What should `diff(sin,x)` and `diff(sin,y)` be?

 The answer is of course that `sin` by itself isn't a function of `x` or
 `y`. It simply is a function. It depends on the context what you put into
 it. In any case `D[0](sin)` is its derivative,

 You may wish that sage would treat V differently, but it doesn't.
 Otherwise, if you do `function('V',t)`, what should it do if you call
 `V(x)`? raise an error? What about `V(t+1)`? It really has no choice other
 than to ignore the name of the parameter and only look at its position in
 the argument list. Indeed, going back to the topic of the ticket, I
 recommend that the whole `function('f',x)` syntax gets deprecated or at
 least gets advised against in the documentation. It pretends that sage can
 do something with it that it can't.

--
Ticket URL: <http://trac.sagemath.org/ticket/17445#comment:21>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to