# Replace in a Symbolic Derivative doesnt work with Pi/2

I was writing some small functions for GR applications, and I was defining a Function that gives me the Geodesic equations. When testing if those worked with the Schwarzschild Metric I came upon a problem when trying to replace the angle $$\theta$$ with $$\frac{\pi}{2}$$ this then didn't properly simplify it when there are derivatives of $$\theta$$.

I have made a simple example to showcase what my problem is:

Sum[D[xx[[i]][\[Tau]], \[Tau]], {i, 4}] /. t -> Pi/2


This produces the following output:

$$\left(\frac{\pi }{2}\right)'(\tau )+x'(\tau )+y'(\tau )+z'(\tau )$$

What can I do to either prevent this from happening or resolve this issue?

• Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. Jul 15 at 19:18

Define Pi/2 as a function, since Derivative expects functions.

Sum[D[xx[[i]][\[Tau]], \[Tau]], {i, 4}] /. t -> Function[\[Tau], Pi/2]

(*   Derivative[x][\[Tau]] +
Derivative[y][\[Tau]] +
Derivative[z][\[Tau]]   *)

• ok cool that works whats weird tho is that it works if you plug in just pi or like any number it works. Just if Pi is part of any kind of Fraction it doesnt work. Jul 15 at 20:09
• You can also use the short form with pure functions D[t[τ], τ] /. t -> (Pi/2 &)  Parentheses (...) are neccessary. Jul 17 at 18:05

This is more an extended comment than an answer. The core issue is that

D[t[τ], τ] /. t -> Pi/2
(* Derivative[Pi/2][τ] *)


does not evaluate to zero. But,

D[t[τ], τ] /. t -> 3/2
(* 0 *)


and even

D[t[τ], τ] /. t -> N[Pi]/2
(* 0 *)


do. Evidently, D does not recognize Pi as numeric upon substitution, even though Mathematica does in general.

NumericQ[Pi]
(* True *)


On the other hand,

D[Pi[τ], τ]
(* 0 *)


The same is true of E. I would characterize this as a bug.

Incidentally, I have experimented with Unevaluated, InActivate, and various forms of Hold as workarounds but without success.

• To @bbgodfrey, i think the point is, that Pi has Head Symbol, N[Pi]/2 has Head Real, 3/2 has Head Rational, which Derivative does analyse and work with, but Pi/2 has Head Times, or Pi+2 has Head Plus, where Derivative can not analyse it further and does not process it. Jul 17 at 15:07
• @Akku14 Good observation. However, it does process D[Pi[τ], τ], which seems inconsistent. Thanks. Jul 17 at 15:08
• this is very interesting insight on this i assumed it happens because Pi is in a way a special character that most often will just be taken symbolicaly. The Solution with N[Pi]/2 is an interesting one tho it leads to the problem of loosing the Exactness for my solution. One Thing i have tried is to just replace \. T[\tau] -> Pi/2 which works but only partly as it leaves any derivatives out. Jul 17 at 16:00
• Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. Jul 17 at 16:50
• @bbgodfrey , " However, it does process D[Pi[τ], τ], which seems inconsistent. " ------- May be it does repeated analysation ...//Head//Head. Pi[τ]//Head gives Pi, Pi//Head gives Symbol with Pi a known symbol, independent of τ, therefore derivative zero. In contrast any letter K, K[τ]//Head gives K and K//Head gives also Symbol, but unknown symbol and therefore not differentiated. Jul 17 at 18:00