4

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.

Physics_maths
  • 1,329
  • 1
  • 10
  • 26

3 Answers3

2

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.

Physics_maths
  • 1,329
  • 1
  • 10
  • 26
2

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

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
2

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"]

enter image description here

(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]

enter image description here

(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.

Carl Woll
  • 130,679
  • 6
  • 243
  • 355