Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meaning of "tmp$xxxx" in Mathematica output

As it is problematic to google strings which contain $ (dollar sign) I couldn't find any explanation to the following output:

{Cos[tmp$132923 + \[Phi]], 
 Sin[tmp$132926 + \[Phi]], 
\[Phi]
}

The question:

What does tmp$xxxx means?

Some background

In `book2.nb' I defined the following function:

g[i_, j_] := {
  f1[i, t, f2[b, j], p][[1]],
  f1[i, t, f2[b, j], p][[2]],
  f3[i, t, p]
  }

Where f1,f2,f3 are all defined in another notebook book1.nb, which was initialized and working fine. Furthermore, f1 returns a list and b is a list defined and active.

Now, when I invoke g[1,1] I get an output similar to the one cited above - with this tmp$. Nevertheless, if I try to plot g it works perfectly (using ParametricPlot3D[g[1, 1], {t, 0, 1}, {p, 0, 2 Pi}]). However, if I try to define a variable

V= {
      f1[1, t, f2[b, 1], p][[1]],
      f1[1, t, f2[b, 1], p][[2]],
      f3[1, t, p]
      }

where I replace i,j with fixed values. Then V is once again with a tmp$ element, but this time it DOESN'T plot...

like image 1000
Dror Avatar asked Nov 10 '11 09:11

Dror


2 Answers

You are most likely seeing localized symbols that result through scoping such as Module.

Here is one example. Since the localized symbol x is used to define the global symbol y the temporary symbol x$152 escapes Module.

In[1]:= Module[{x}, y = x]; y

Out[2]= x$152

There are other variations of this process. Suppose you set a unique context for the cell (Evaluation > Notebook's Default Context > Unique to Each Cell Group) and then make an assignment to an explicitly Global symbol:

Global`b = a

Now in another notebook:

In[1]:= b

Out[1]= Notebook$$33`a
like image 147
Mr.Wizard Avatar answered Oct 21 '22 08:10

Mr.Wizard


Your code probably has a variation of this problem:

f[x_] := Module[{t}, Cos[t]+Cos[x] ]

at which point evaluating this:

f[y]

gives this:

Cos[t$685] + Cos[y]

Often, this means there is a problem with the code.

Either 't' was meant to be passed in as a parameter of 'f':

f[x_,t_] := Module[{}, Cos[t]+Cos[x] ]

or 't' needed to be initialized in some fashion:

f[x_] := Module[{t}, t=2x; Cos[t]+Cos[x] ]

It's perfectly ok to use these unique variables in your code, if you intend to do so. For example, this is one way to write an expression with with many unique variables:

Plus @@ Table[Unique[x]^i, {i, 100}]
like image 7
Arnoud Buzing Avatar answered Oct 21 '22 07:10

Arnoud Buzing