8

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!

jlperla
  • 967
  • 6
  • 18

1 Answers1

4

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.

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
  • 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? – jlperla Jul 22 '14 at 19:21
  • @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. – Mr.Wizard Jul 22 '14 at 19:26
  • @jlperla Oh, and thanks for the Bounty! – Mr.Wizard Jul 22 '14 at 19:27
  • Sent to them. Thank you so much for looking at this and finding a workaround. – jlperla Jul 22 '14 at 20:56
  • @jlperla By the way is there a reason you are using ! MemberQ[$scriptedfunctionsvars, HoldPattern @ z, Infinity]; rather than FreeQ[$scriptedfunctionsvars, HoldPattern @ z]? – Mr.Wizard Jul 25 '14 at 07:00
  • For whatever reason, it didn't pass my test cases (which was my stopping criteria on the code). I couldn't figure out why. – jlperla Jul 25 '14 at 18:46
  • @jlperla If you're able to give me an example I think I'll learn something. Please, if you have time. – Mr.Wizard Jul 25 '14 at 20:23
  • Take a look at http://mathematica.stackexchange.com/questions/30884/displaying-index-as-subscript-on-output-e-g-ci-c-i-with-notation-or (which was originally based on the code you gave me). I wrote down the final code I used as an answer at the bottom. (the only thing I added was a OverDotcase) There is also a complete listing of the test cases in that post. – jlperla Jul 25 '14 at 20:39
  • If you wish to refactor this, especially if it is as a module DisplayScripted or something like that, I am sure it would be appreciated by all. – jlperla Jul 25 '14 at 20:39