Message Boards Message Boards

0
|
4290 Views
|
1 Reply
|
1 Total Likes
View groups...
Share
Share this post:

Understand the following function formula format?

I came across an old post and notice an syntax different from what I am costume in WM. The original post is here

(*definition of the modified spherical Bessel function of the first \
kind from https://mathematica.stackexchange.com/questions/10767/fast-spherical-\
harmonics-radiative-transfer*)
SphericalBesselI[0, 0] := SphericalBesselI[0, 0] = 1;
SphericalBesselI[l_, z_] := Sqrt[\[Pi]/(2 z)] BesselI[l + 1/2, z];
(*expansion coefficients for the Henyey-Greenstein phase function*)
\[Sigma][l_][g_] := g^l
(*diagonal matrix elements*)
h[l_][g_, \[Omega]_] := 
  h[l][g, \[Omega]] = (2 l + 1) (1 - \[Omega] \[Sigma][l][g]);
(*low-order determinants*)

Look at line 7 and 9. It has a double brackets. Not sure but will [Sigma][l][g] := g^l be same as [Sigma][l,g] := g^l?

POSTED BY: Jose Calderon
Posted 5 years ago

In general, no, f[x][y] is not the same as f[x, y]. However, several built-in functions have a similar behavior. For example, myList[[1]][[3]] is the same as myList[[1, 3]], and SortBy[f] is an "operator form" of SortBy[exp, f] that can be used as SoryBy[f][myList].

The technical term for f[x]=exp is DownValue, and the technical term for f[x][y]=exp is SubValue. Here is a simple example to show they are different in general:

In[1]:= f[1]="This is a DownValue";
In[2]:= f[2][3]="This is a SubValue.";
In[3]:= f[4][5][6]="Also a SubValue.";
In[4]:= {DownValues[f], SubValues[f]}                                           
Out[4]= {{HoldPattern[f[1]] :> This is a DownValue}, 
                {HoldPattern[f[2][3]] :> This is a SubValue., 
                HoldPattern[f[4][5][6]] :> Also a SubValue.}}

You can transform a function of n arguments f[a, b, c, d, ...] into a function that can be applied to each argument one at a time as g[a][b][c][d]... by using Curry. As an example, you could use Curry to compute Fourier coefficients like this:

In[1]:= a[f_,n_, min_, max_]:= 1/\[Pi] Integrate[f[x]*Cos[ n*x], {x, min, max}] 
In[2]:= coeff = Curry[a, {4, 3, 1, 2}][-\[Pi]][\[Pi]]; (* Some textbooks use 0 to  2Pi, but we use -Pi to Pi. *)
In[3]:= coeff[1, Exp] //InputForm
Out[3]//InputForm= -(Sinh[Pi]/Pi)
In[4]:= 2 Re[FourierCoefficient[Exp[t], t, 1]] // InputForm (* Check our work with Mathematica. *)
Out[4]//InputForm= -(Sinh[Pi]/Pi)

Notice that I have adjusted the order in which the arguments need to be supplied by giving Curry the argument order as a list {4, 3, 1, 2}.

POSTED BY: Updating Name
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract