# Weird behavior of two Prime symbols in package

I discovered some very strange behavior, which leads to strange errors. Hope you can explain it for me. It might be a bug.

So, i created a package, where i prepare set of equations to use in NDSolve. Let it be very simple one as an example:

BeginPackage["ErrorPrime2Package"];
getEqtn::usage = "Get the equation";
Begin["Private"];
eq = {
(y^\[Prime]\[Prime])[x] == y[x],
y[0] == 0,
Derivative[1][y][0] == 0
};
funcs = {y};
getEqtn = {eq, funcs, x};
End[];
EndPackage[];

Then in a separate file i load this package and use getEqtn from it:

Needs["ErrorPrime2Package"];
{eqns, funs, varx} = getEqtn;
NDSolve[eqns, funs, {varx, 0, 1}]

But when i run NDSolve, it gives me error "The function ErrorPrime2PackagePrivatey appears with no arguments."

It is very confusing, because as you may see, any y has an [x] argument. So, where is the problem?

If you look at eqns variable:

{(ErrorPrime2PackagePrivatey^
ErrorPrime2PackagePrivate\[Prime]\[Prime])[
ErrorPrime2PackagePrivatex] ==
ErrorPrime2PackagePrivatey[ErrorPrime2PackagePrivatex],
ErrorPrime2PackagePrivatey[0] == 0,
Derivative[1][ErrorPrime2PackagePrivatey][0] == 0}

As you can see, for some reason i can't understand there is ErrorPrime2PackagePrivate part appear before the first \Prime. Why is it there?

You can avoid this error if use '' or \DoublePrime instead, with them everything works fine.

Feel free to ask me clarifying questions if something is not clear in my description.

• It should be y''[x] not (y^\[Prime]\[Prime])[x]
– Kuba
May 14 '18 at 15:36
• If you type y'', evaluate it, copy the contents of the output cell, then paste it into a plain text editor, you get y^\[Prime]\[Prime]. However, this is not correct in the sense that it is not equivalent to the original input (in fact it's nonsense). I would call this copying behaviour a bug. May 14 '18 at 15:49
• Do you simply write the 1D form of y^\[Prime]\[Prime] in the package or the 2D form of it (I mean something that you obtained by pressing Ctrl+Shift+N)? If the former, it's invalid anywhere, not only in the package. May 14 '18 at 15:51
• I write y, then press Ctrl+^ then Esc, ', Esc and again Esc, ', Esc. May 14 '18 at 15:53
• @Szabolcs Not completely nonsense. By transforming the code to StandardForm (Ctrl+Shift+N etc.) it becomes meaningful again, but this design is indeed a bit annoying. May 14 '18 at 15:54

In short, the syntax y^\[Prime]\[Prime] is invalid. (Technically, it's valid, but it doesn't mean what it looks like. ^ is the infix form of Power and \[Prime]\[Prime] is treated as a symbol name.)

You probably obtained this expression by typing either

y''

or

Derivative[2][y]

then evaluating it, then copying the contents of the output cell.

If we now paste this into a plain text editor, we get

y^\[Prime]\[Prime]

This is nonsense that does not have the same FullForm as the copied expression, at least according to the kernel. (As @xzczd points out in a comment, according to the FE it is equivalent: Command-Shift-N converts it back. But there should not be such an inconsistency between the FE and the Kernel. Nor should ^ mean anything else than Power.)

I would call this a bug in how the Front End copies the expression. Note that it copies it this way even if we use Copy As -> Input Text. Also note that y' does not suffer from the problem. y''' also doesn't suffer from the problem: the copied expression is ugly and complicated, but pasting it back into Mathematica does yield an expression equivalent to what was copied.

What should you do? Don't use \[Prime]. Type derivatives using ', i.e. as y''.

• Thank you, i think i'll stick with '. May 14 '18 at 20:52