Let's shift our perspective to looking at a "time independent r
" as "r[t]
is constant for all t
". This naturally extends to a time dependent case where "r[t]
is not constant for all t
". With this in mind, we can change r
to r[t]
and not lose any generality.
Then we can rewrite your expression as
y[r_] := D[otherfunction[r[t]], t] + D[r[t], t]
where r
now needs to be given as a Function
. For example
y[Function[{t}, t^2]]
2 t + 2 t otherfunction'[t^2]
There are also the "syntactic" reasons why your implementation isn't doing what you want it to (as in @Daniel Huber's excellent answer), but this is another way of thinking about "what the code means".
Alternatively, you can also use the total derivative Dt
which has the documentation
All quantities not explicitly specified as constants are assumed to depend on the [arguments]
So for your example
Dt[otherfunction[r], t] + Dt[r, t]
Dt[r, t] + Dt[r, t] otherfunction'[r]
otherfunction
andt
are global. They should be instead be passed to the function via its arguments. So your function should have beeny[r_,t_,f_]
wheref
is the other function. This is the right way to do things. $\endgroup$