# What does # mean in Mathematica?

I asked Mathematica to compute the following

Solve[c (1-x)^2-x^(1/4) == 0, x]


and it returned this:

x = Root[#1^8 c^4 - 8 #1^7 c^4 + 28 #1^6 c^4 - 56 #1^5 c^4 + 70 #1^4 c^4 - 56 #1^3 c^4 + 28 #1^2 c^4 + #1 (-8 c^4-1) + c^4&, 1]

What does this mean? In particular, what's with all the #s?

-
the coefficient c is a fixed, but arbitrary. –  ronanymous Feb 5 '13 at 1:57
You may find the Mathematica Documentation Center helpful for questions like this (you can just type # in the search field at the top and it will direct you to an explanation). In any case, here's a web version of the documentation: reference.wolfram.com/mathematica/ref/Slot.html –  David Skulsky Feb 5 '13 at 2:03
MathGroup version of the same –  Szabolcs Feb 5 '13 at 2:10
For future reference, click or select a symbol in Mathematica and hit F1 to search for that symbol in the help system. –  amr Feb 5 '13 at 2:29

# is a placeholder for an expression.

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

f = #^2 &


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

f[2]
(* 4 *)


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

f = #1 + #2 &


So

f[3,4]
(* 7 *)


Or you may have a function operating on a list, like:

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


So:

f[{3,4}]
(* 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 polynomial is $x^2 - 1$, using what we saw above:

f = #^2 - 1 &
Root[f, 1]

(*
- 1  (* as we expected ! *)
*)


And

Root[f, 2]
(*
1  (* Thanks God ! *)
*)


But if we try with a higher order polynomial:

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

(*
Root[-1 - 2 #1 - #1^2 + 2 #1^3 + #1^4 &, 1]
*)


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

 N@Root[-1 - 2 #1 - #1^2 + 2 #1^3 + #1^4 &, 1]
(* -2.13224 *)


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

-
Original. Also, more on working with Root objects –  rm -rf Feb 5 '13 at 3:12
@rm-rf It's called migration by self-defense :) –  belisarius Feb 5 '13 at 3:38
It's good that it's here now. I remember this came up a long time ago here and I think the migration was either denied or no one cared... –  rm -rf Feb 5 '13 at 4:00

While the tutorial will undoubtedly explain better that I could the entire topic of pure functions, which is what Slot, or # has to do with, I'll answer the specific question at hand.

The Slot is treated as the argument in an anonymous function. Specifically, the code

#^2 & // FullForm


Reveals that what is actually going on is Function[Power[Slot[1],2]]. In other words, the Slot[1] indicates the parameter of my unnamed - "pure" - squaring function. The ampersand denotes the end of the pure function (so that in more complicated expressions one could use several pure functions and limit what they do).

Thus, something like #^2 & [3] evaluates to 9 (more examples in the linked tutorial).

Now, to address the role of Root. For some expressions, such as yours, which can be rewritten as a degree-8 polynomial, there exist no exact algebraic solutions. Thus, MMA does the best it can, showing that the root of a polynomial which takes in an argument #1 (equivalent to #) and transforms it into #1^8 c^4... would be the exact solution to your equation.

In this case, your best bet is to quantify all but one parameter and use numerical solving.

-
+1 for one of the most concise and clearest descriptions of # and & and pure functions I've read. –  Jagra Feb 5 '13 at 12:28