3
$\begingroup$

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 ErrorPrime2Package`Private`y 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:

{(ErrorPrime2Package`Private`y^
   ErrorPrime2Package`Private`\[Prime]\[Prime])[
   ErrorPrime2Package`Private`x] == 
  ErrorPrime2Package`Private`y[ErrorPrime2Package`Private`x], 
 ErrorPrime2Package`Private`y[0] == 0, 
 Derivative[1][ErrorPrime2Package`Private`y][0] == 0}

As you can see, for some reason i can't understand there is ErrorPrime2Package`Private` 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.

$\endgroup$
  • 1
    $\begingroup$ It should be y''[x] not (y^\[Prime]\[Prime])[x] $\endgroup$ – Kuba May 14 '18 at 15:36
  • $\begingroup$ 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. $\endgroup$ – Szabolcs May 14 '18 at 15:49
  • $\begingroup$ 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. $\endgroup$ – xzczd May 14 '18 at 15:51
  • $\begingroup$ I write y, then press Ctrl+^ then Esc, ', Esc and again Esc, ', Esc. $\endgroup$ – Rainy Days May 14 '18 at 15:53
  • $\begingroup$ @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. $\endgroup$ – xzczd May 14 '18 at 15:54
5
$\begingroup$

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

$\endgroup$
  • $\begingroup$ Thank you, i think i'll stick with '. $\endgroup$ – Rainy Days May 14 '18 at 20:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.