# How make D[f,x] treat OverBar[x] as a constant

I have an expression of the form f = a*x +OverBar[x], where OverBar[x] is just a name, it has not much to do with the variable x. I want D[f,x] = a but Mathematica shows D[f,x] = a +OverBar'[x].

Is there a way to let Mathematica know that OverBar[x] is just a name and it's derivative wrt to x is zero? D[] doesn't take Assumptions as an option afaik.

Also it does not matter whether I take something else say OverHat or UnderBar the issues is still the same D[OverHat[x],x] = OverHat'[x] according to Mathematica.

If nothing helps, is there any notation resembling OverBar that does not become a function of its argument? i.e. that it is just a symbol/name.

• Take a look at this, you just have OverBar instead of Subscript – swish Feb 17 '17 at 14:56
• Related: (91356) – Mr.Wizard Feb 17 '17 at 15:16
• Could use Dt: In[78]:= Dt[a*x + OverBar[x], x, Constants -> {a, OverBar}] Out[78]= a – Daniel Lichtblau Feb 17 '17 at 16:30

If you prefer not to have to make the replacement each time:

OverBar'[x] = 0;

f = a*x + OverBar[x]

D[f, x]

a*x + OverBar[x]

a


Just put OverBar'[p] or whatever variable to zero after differentiation. Nothing fancy but should do the job. Something like

D[f,x]//ReplaceAll[#, OverBar'[x] -> 0] &


Or make a list and set all the OverBar'[par] in the world to zero, where par is any of your (my) parameters.

• No need to do it after differentiation; you can set OverBar'[x] = 0 at the beginning and it should work too. – Mr.Wizard Feb 17 '17 at 12:35
• Yup that's right, in some cases that's better. – Your Majesty Feb 17 '17 at 12:36
• Incidentally D[f,x] /. OverBar'[x] -> 0 – Mr.Wizard Feb 17 '17 at 12:40

I wouldn't use OverBar[x] and x together. For example:

Solve[a x + OverBar[x] == 2, x] //InputForm


DynamicSolve::nsmet: This system cannot be solved with the methods available to Solve.

Solve[a*x + OverBar[x] == 2, x]

However, it is possible to get an object that looks like OverBar[x], but doesn't actually include x. If you entered OverBar[x] explicitly as OverBar[x] in your code, you could instead use:

OverBar[RawBoxes@"x"]


(I replaced the above output with an image of what one would see in a notebook).

The box structure is identical:

ToBoxes[OverBar[x]]
ToBoxes[OverBar[RawBoxes@"x"]]


OverscriptBox["x", "_"]

OverscriptBox["x", "_"]

This construct is completely independent of x, so now Solve and D will work as expected:

Solve[a x + OverBar[RawBoxes@"x"] == 2, x]


(Again, the above is an image)

D[a x + OverBar[RawBoxes@"x"], x]


a

Now, it might be that you like to use keyboard shortcuts to create the OverBar object, and the above approach won't work for you. In that case you can add a MakeExpression rule as follows:

MakeExpression[OverscriptBox["x", "_"], StandardForm] := HoldComplete[OverBar[RawBoxes@"x"]]


Now, the object created by the key strokes:

x, control + 7, _

will be interpreted as the OverBar[RawBoxes@"x"] expression I give above.