MathGroup Archive 2010

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

Search the Archive

Re: Condensed syntax

  • To: mathgroup at smc.vnet.net
  • Subject: [mg113537] Re: Condensed syntax
  • From: Dana DeLouis <dana.del at gmail.com>
  • Date: Mon, 1 Nov 2010 05:02:39 -0500 (EST)

> I have a list of {i,j} values,
>
> ij = Tuples[config, 2]
>
> {{1, 1}, {1, 2}, {1, 3}, {1, 4}, {2, 1}, {2, 2}, {2, 3}, {2, 4}, {3,
>   1}, {3, 2}, {3, 3}, {3, 4}, {4, 1}, {4, 2}, {4, 3}, {4, 4}}
>
> and I want to create a list in which the {i,j} are passed as arguments
> to a function f[x,y], i.e., {f[1,1], f[1,2],..., f[4,4]}. I can do
> this using the two-step process:
>
> g[X_List] := Apply[f, X]
> Map[g, ij]
>
> {f[1, 1], f[1, 2], f[1, 3], f[1, 4], f[2, 1], f[2, 2], f[2, 3],
>  f[2, 4], f[3, 1], f[3, 2], f[3, 3], f[3, 4], f[4, 1], f[4, 2],
>  f[4, 3], f[4, 4]}
>
> Is there a way I can bypass the intermediate function g[x] and produce
> the final list in a single step?



Hi.  If we skip the Tuples Function, two additional possible solutions =
might be:

Your desired solution:

sol = {f[1, 1], f[1, 2], f[1, 3], f[1, 4], f[2, 1], f[2, 2], f[2, 3], =
f[2, 4],
    f[3, 1], f[3, 2], f[3, 3], f[3, 4], f[4, 1], f[4, 2], f[4, 3], f[4, =
4]};


r = Range@4;

me = Outer[f, r, r] // Flatten

{f[1, 1], f[1, 2], f[1, 3], f[1, 4], f[2, 1], f[2, 2], f[2, 3], f[2, 4],=

 f[3, 1], f[3, 2], f[3, 3], f[3, 4], f[4, 1], f[4, 2], f[4, 3], f[4, 4]}

me == sol
True

me = Distribute[f[r, r], List]

{f[1, 1], f[1, 2], f[1, 3], f[1, 4], f[2, 1], f[2, 2], f[2, 3], f[2, 4],=

 f[3, 1], f[3, 2], f[3, 3], f[3, 4], f[4, 1], f[4, 2], f[4, 3], f[4, 4]}

me == sol
True

= = = = = = = = = =
HTH  : >)
Dana DeLouis 
dana.del at gmail.com



  • Prev by Date: Re: Arrowhead Directive for FrameStyle?
  • Next by Date: Re: Assertions in Mathematica?
  • Previous by thread: Re: Arrowhead Directive for FrameStyle?
  • Next by thread: is there an 'issue' with putting Notation[] command inside a Module[]?