What does # mean in Mathematica?

user376089 picture user376089 · Nov 24, 2010 · Viewed 21.8k times · Source

Does anyone know What # in for example Root[-1 - 2 #1 - #1^2 + 2 #1^3 + #1^4 &, 1] means in Mathematica?

Then what does Root[-1 - 2 #1 - #1^2 + 2 #1^3 + #1^4 &, 1] exactly mean?

Thanks.

Answer

Dr. belisarius picture Dr. belisarius · Nov 24, 2010

It's a placeholder for a variable.

If you want to define a y(x)=x^2 function, you just could do:

  f = #^2 & 

The & "pumps in" the variable into the # sign. That is important for pairing & and # when you have nested functions.

  In: f[2]  
  Out: 4   

If you have a function operating on two vars, you could do:

 f = #1 + #2 &

So

  In: f[3,4]  
  Out: 7  

Or you may have a function operating in a list, so:

 f = #[[1]] + #[[2]] &

So:

  In: f[{3,4}]
  Out: 7

About Root[]

According to Mathematica help:

Root[f,k] represents the exact kth root of the polynomial equation f[x]==0  .

So, if your poly is x^2 - 1, using what we saw above:

        f = #^2 - 1 &

In[4]:= Root[f, 1]  

Out[4]= -1  (* as we expected ! *)

And

In[5]:= Root[f, 2]  

Out[5]= 1  (* Thanks God ! *)

But if we try with a higher order polynomial:

         f = -1 - 2 #1 - #1^2 + 2 #1^3 + #1^4 &  

In[6]:= Root[f, 1]

Out[6]= Root[-1 - 2 #1 - #1^2 + 2 #1^3 + #1^4 &, 1]

That means Mathematica doesn't know how to caculate a symbolic result. It's just the first root of the polynomial. But it does know what is its numerical value:

In[7]:= N@Root[-1 - 2 #1 - #1^2 + 2 #1^3 + #1^4 &, 1]

Out[7]= -2.13224

So, Root[f,k] is a kind of stenographic writing for roots of polynomials with order > 3. I save you from an explanation about radicals and finding polynomial roots ... for the better, I think