MathGroup Archive 2004

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

Search the Archive

Re: a strange line of code

  • To: mathgroup at
  • Subject: [mg52739] Re: a strange line of code
  • From: David Bailey <dave at>
  • Date: Sat, 11 Dec 2004 05:21:59 -0500 (EST)
  • References: <cpb00k$j28$>
  • Sender: owner-wri-mathgroup at

Stefan Schuster wrote:
> Hello,
> 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]]];
> thanks in advance
> Stefan

I think your function got a bit scrambled, but in answer to your 
question, the # and & characters together create a pure function. For 
example, (#^2+1)& is a pure function that squares its argument and adds 
one to it! Although '@' is a Mathematica operator, it does not feature 
here. The /@ operator is just another way of doing Map!

A good way to unpick code like this, is to choose a bit (in a notebook) 
with the mouse and click repeatedly to extend the selection. This 
process takes into account all the precedences of operators, etc. so 
that you can extract a sub-expression and paste it somewhere and test it 
on its own.

Some people love writing expressions like that - and, to be fair, the 
result is usually more efficient - but such code can be frighteningly 
opaque - particularly when you come to look at it in 3 months time!

David Bailey

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