MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: a strange line of code

  • To: mathgroup at
  • Subject: [mg52723] Re: a strange line of code
  • From: D Herring <dherring at>
  • Date: Sat, 11 Dec 2004 05:21:16 -0500 (EST)
  • References: <cpb00k$j28$>
  • Sender: owner-wri-mathgroup at

> in a notebook, I found and function to calculate the Feigenbaum 
> bifurcation Diagram.
> I principial understand the Feigenbaum, and I think I'm also able to 
> write such an funcion by myself, but not in this compact way.
> Can someone please explain me the meaning of the Symbols #, @ and &
> Here is the Code:
> Feigenbaum = Compile[{{
>      ?, _Real}}, ({?, #} &) /@ Union[Drop[NestList[
>        ? # (1 - #) &, 0.2, 300], 100]]];

In a nutshell,
# - argument for an unnamed function
& - completes the definition of an unnamed function; it takes the 
previous token (raw term or bracketed expression) and treats it as a 
function which takes an input.
/@ - Map command, infix notation

For a brief intro to the function notation, see section 2.2.4 in the 
Mathematical Book, or look up & in the Master Index.

Basically, "f[x_]:=x^2" can be written in a ``pure'' form as "(#^2)&".
"y=f[3]" is then equivalent to "y=(#^2)& /@ 3".

"y=Map[f,x]" is equivalent to "y=f /@ x".  If x was a list, the result 
will be of the form y={f[x[[1]]], f[x[[2]]], ...}.

Your example was carefully crafted line of code; it highlights the 
expressive power of functional programming, but also shows the potential 
for obfuscation.


  • Prev by Date: Re: Re: finite domains
  • Next by Date: Re: a strange line of code
  • Previous by thread: Re: a strange line of code
  • Next by thread: Re: a strange line of code