# Replace function and its derivatives by zero

If I try to replace the function u0 and its derivatives by zero in the following examplary expression

expr = t HeavisideTheta[0.174 +φ] - 1651.2 u0[t, φ] + 3293.841 t Derivative[0, 1][u0][t, φ];
expr/.u0->(0&)
(*0. + t HeavisideTheta[0.174 + φ]*)


Mathematica gives an output 0.+....

My question: How can I avoid this zero part 0.+ in the output(without using Chop) ? Thanks!

Could you just add another replacement rule?

expr /. u0 -> (0&) /. 0. -> 0


t HeavisideTheta[0.174 + φ]

• Thanks, unbelievable simple trick /.0. -> 0, but it works. – Ulrich Neumann Oct 29 '19 at 15:48

Try also this:

Map[Rationalize, expr, Infinity] /. u0 -> (0 &) // N

(* t HeavisideTheta[0.174 + φ]  *)

• Thanks! expr /. u0 -> (0 &) // Rationalize works too! – Ulrich Neumann Oct 30 '19 at 7:50
• @Ulrich Neumann Yes, this your version is even better. – Alexei Boulbitch Oct 30 '19 at 12:57

Not sure if this will cause other problem, but the following does work for your example:

Clear@u0
u0 /: u0[__] number_Real := 0
Derivative[__][u0] ^:= u0
expr
(* t HeavisideTheta[0.174 + φ] *)

• @xzcd Thanks, your first solution (comment SetPrecision[expr, Infinity] /. u0 -> (0 &) ) seems to be more reliable because it also solves the case expr=t HeavisideTheta[a + \[CurlyPhi]] - b u0[t, \[CurlyPhi]] + c t Derivative[0, 1][u0][t, \[CurlyPhi]] – Ulrich Neumann Oct 29 '19 at 13:02
• @UlrichNeumann I removed that one because I think that method is somewhat similar to the Chop method. (It changes the numbers inside expr, too. ) To handle the new added example, you can again add a /. u0 -> (0 &) at the end of expr. – xzczd Oct 29 '19 at 13:08