8
$\begingroup$

Bug introduced in 10.0.0 and fixed in 10.0.1


I had code to display with subscripts from Displaying index as subscript on output: e.g. C[i] -> C_i with Notation[...] or Interpretation[..]? which is now breaking an innocuous pure function substitution as in Looking for an elegant way to solve a (system of) ODEs/functional equations with undetermined coefficients The substitution itself has nothing to do with any actual display of subscripts.

I am having a little trouble creating a minimal example, but here goes. First, in Mma10 try the pre-side effect code:

ODE = F'[z] == g F[z]
Fguess = {F-> (Exp[a #]&)}
ODE /. Fguess //FullSimplify

=> e^(a z)(a - g)== 0, the proper output

Now, add in the following code, stripped down from that previous example. This isn't intended to actually have anything to do with the substitution, but is causing side effects.

NotScriptedVarQ[z_] := ! MemberQ[$scriptedfunctionsvars, z, Infinity];
makeDef[pat_, body_] := (MakeBoxes[a : pat, fmt_] := 
ToBoxes[Interpretation[body, a], fmt] /; 
 MemberQ[Union[$scriptedconstants, $scriptedfunctions], 
  Unevaluated@h];
  )
makeDef[h_Symbol[argssub__?NotScriptedVarQ], h[argssub]];
$scriptedconstants = {};
$scriptedfunctions = {};
$scriptedfunctionsvars = {};

Now, try the substitution and a few permutations:

(*The ODE and guess are*)
ODE = F'[z] == g F[z]
Fguess = {F -> (Exp[a #] &)}
(*Substituting NOW DOESN'T work*)
ODE /. Fguess // FullSimplify
(*But if the guess is NOT displayed before the substitution(i.e., no ;) WORKS!*)
Fguess = {F -> (Exp[a #] &)};
ODE /. Fguess // FullSimplify
(*And if the guess is substituted directly, IT WORKS!*)
F'[z] == g F[z] /. {F -> (Exp[a #] &)} // FullSimplify

As this used to work fine in Mma9, I imagine this is a bug. If so, any idea of a workaround?

One last thing I learned: If you change the definition so that NotScriptedVarQ[z_] := True, or change it to always be False, the bug is no longer there!

$\endgroup$
5
  • $\begingroup$ What are the Print expressions suppose to accomplish? Are they supposed to function as comments? Should that be the case, then use Mathematica's comment syntax, e.g., (* a comment *). $\endgroup$
    – m_goldberg
    Jul 16, 2014 at 4:21
  • $\begingroup$ Sorry, you are right, I just had them in there to keep track of the output. They don't effect the bug $\endgroup$
    – jlperla
    Jul 16, 2014 at 4:23
  • $\begingroup$ Prints converted to comments. Thanks. $\endgroup$
    – jlperla
    Jul 16, 2014 at 17:29
  • $\begingroup$ It seems this bug has been fixed in 10.0.1; I added a header accordingly. If you find this to not be true please remove that header (and let me know). $\endgroup$
    – Mr.Wizard
    Sep 17, 2014 at 16:04
  • $\begingroup$ Confirmed, fixed. $\endgroup$
    – jlperla
    Sep 19, 2014 at 17:17

1 Answer 1

4
+50
$\begingroup$

I can't yet explain the behavior but I can greatly reduce your minimum example:

MakeBoxes[a_ /; FreeQ["foo", a], fmt_] := "bar" /; False

ODE = F'[z] == g F[z];
Fguess = {F -> (Exp[a #] &)}

ODE /. {F -> (Exp[a #] &)}
ODE /. Fguess
{F -> (Exp[a #1] &)}

a E^(a z) == E^(a z) g

Derivative[1][F][z] == g F[z]

Critically:

  • If I suppress the output of Fguess = {F -> (Exp[a #] &)} by appending a ; the problem exhibited in the final line of code goes away.

  • If I replace FreeQ["foo", a] with FreeQ["foo", HoldPattern @ a] the problem goes away.
    (Kernel restart required.)

Apparently the evaluation of a within FreeQ (or MemberQ) when MakeBoxes is performed on the output of the line Fguess = {F -> (Exp[a #] &)} breaks something but at this point I have no idea what.

$\endgroup$
9
  • $\begingroup$ That did it! Changing to MemberQ[$scriptedfunctionsvars, HoldPattern@ z, Infinity] seems to have fixed everything. This sure looks like a bug to me, how does Wolfram like these things to be submitted? $\endgroup$
    – jlperla
    Jul 22, 2014 at 19:21
  • $\begingroup$ @jlperla Under the Help menu there should be a Give Feedback item you can use for that. I'm glad this solves your problem. I too believe it is a bug as I can't think of any other explanation for the behavior. I'll add that tag to the question. If later I am proven wrong so be it. $\endgroup$
    – Mr.Wizard
    Jul 22, 2014 at 19:26
  • $\begingroup$ @jlperla Oh, and thanks for the Bounty! $\endgroup$
    – Mr.Wizard
    Jul 22, 2014 at 19:27
  • $\begingroup$ Sent to them. Thank you so much for looking at this and finding a workaround. $\endgroup$
    – jlperla
    Jul 22, 2014 at 20:56
  • $\begingroup$ @jlperla By the way is there a reason you are using ! MemberQ[$scriptedfunctionsvars, HoldPattern @ z, Infinity]; rather than FreeQ[$scriptedfunctionsvars, HoldPattern @ z]? $\endgroup$
    – Mr.Wizard
    Jul 25, 2014 at 7:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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