3

I found a nice bug in Mathematica 9.0.1.0. Could anyone check to reproduce it?

Create a file temp.txt with one line:

Attributes[s$] = {Temporary}

Load it into Mathematica with <<.

Now calculate:

Sum[x^(-n)*y^n, {n, 0, Infinity}]

Mathematica stops responding and the only option is to quit the kernel. You can't interrupt or abort.

Now change s to a or b in the file and repeat the above. It works!

Next put the line

Attributes[s$] = {Temporary}

directly into the notebook and calculate the sum. It works!

What is so special about temporary variable s$ loaded from the file?

I used a temporary variable s$ in one of my functions and then saved the function to the file. Mathematica added the above line to the file. Everything stopped working.

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
Vlad
  • 39
  • 1
  • Probably unrelated, but I've actually had weird situations where the choice of dummy variable in the integration changed the result of the symbolic integral, with certain choices giving the correct answer and other choices causing the kernel to time out. – DumpsterDoofus Feb 07 '14 at 00:31
  • 2
    Mathematica uses renaming to localize variables. In certain situations s will be renamed to s$ to avoid name collisions (though not in Module). You should never use such names in your code or you're risking to break things. – Szabolcs Feb 07 '14 at 00:31
  • I always use Module for functions. Why it works in the notebook and not from the file ? What a difference between "s" and "a" ? If I can use "a" and not "s", it should be documented and this is unacceptable. It works fine in Mathematica 7, by the way. – Vlad Feb 07 '14 at 00:38
  • @Vlad As I said you should never use the name s$, as this is reserved for internal operations. If you do, you are just asking for trouble. Did you explicitly use this symbol (s$) in your code? – Szabolcs Feb 07 '14 at 00:39
  • Ok, I started checking all letters. It works for "a" and "b", but does not work for "c" and "d". Shall we divide the alphabet into allowed and forbidden temporary variables ? And the variable "s" is never used in the above example. – Vlad Feb 07 '14 at 00:44
  • 1
    @Vlad This is not a Q/A site, not a place to rant. Please make sure that you ask a clear and answerable question. If your question was, "is this a bug and how do I work around it?", then you got the answer: if you used s$ then it's not a bug, it's user error. If you didn't then maybe. Yet you fail to tell us if you did or didn;t. – Szabolcs Feb 07 '14 at 00:59
  • @Szabolcs Does your emphatic never include e.g. this use? I've done that more than a few times without apparent problem, but maybe I haven't thought this through. – Mr.Wizard Feb 07 '14 at 01:04
  • @Szabolcs I clearly said that the variable "s" is not used in the code I showed. I define "s" as a temporary variable and only use variables "x", "y" and "n". It stops working. – Vlad Feb 07 '14 at 01:41
  • 1
    @Mr.Wizard I think that, if your use stopped working or happened to eventually break something, it wouldn't be a MMA bug, but a risk you were willing to take – Rojo Feb 07 '14 at 01:41
  • 1
    @Vlad, as to the difference, I think at least in the notebook the line where you set the attributes shouldn't do anything. Because since it is Temporary the symbol should get removed instantly. Perhaps that's not the case if it was defined in the file? I haven't tried – Rojo Feb 07 '14 at 01:46
  • ...but it doesn't remove it, so I guess I'm confused and wrong about something – Rojo Feb 07 '14 at 01:48
  • @Vlad Simply mentioning it to Mathematica counts as using it. However, what I asked you was: did you use s or s$? The two are two different things. In the example you posted you are using s$, which as I said is a mistake and there's no surprise that it breaks Sum's or Get's internals. – Szabolcs Feb 07 '14 at 06:00
  • @Mr.Wizard I'd say that's a hack which I might also use for a one time quick and dirty solution ... It's also true that Mathematica has problems because of how it handles name collisions and localizations. However I wouldn't do that in a project where there's any expectation of reliability, such as MATLink ... or even code I regularly use for my research. – Szabolcs Feb 07 '14 at 06:03
  • @Rojo It does remove it during notebook session if you set $HistoryLength = 0; and removes even without this when the line Attributes[s$] = {Temporary} is imported from a file using Get. – Alexey Popkov Feb 07 '14 at 10:53
  • 2
    I filed a bug report for this. Best advice remains: Don't use variables that end with $. Too much chance of confusing the scoping mechanism. – Daniel Lichtblau Feb 07 '14 at 16:03

0 Answers0