Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2007

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

Search the Archive

Re: sum over i+j+k==n

  • To: mathgroup at smc.vnet.net
  • Subject: [mg84432] Re: [mg84423] sum over i+j+k==n
  • From: DrMajorBob <drmajorbob at bigfoot.com>
  • Date: Mon, 24 Dec 2007 04:44:13 -0500 (EST)
  • References: <5316732.1198403595310.JavaMail.root@isp02>
  • Reply-to: drmajorbob at bigfoot.com

Here are a couple of possibilities with Table:

n = 10;
tbl0 = Flatten[Table[{i, j, n - i - j}, {i, 0, n}, {j, 0, n - i}], 1]

{{0, 0, 10}, {0, 1, 9}, {0, 2, 8}, {0, 3, 7}, {0, 4, 6}, {0, 5,
   5}, {0, 6, 4}, {0, 7, 3}, {0, 8, 2}, {0, 9, 1}, {0, 10, 0}, {1, 0,
   9}, {1, 1, 8}, {1, 2, 7}, {1, 3, 6}, {1, 4, 5}, {1, 5, 4}, {1, 6,
   3}, {1, 7, 2}, {1, 8, 1}, {1, 9, 0}, {2, 0, 8}, {2, 1, 7}, {2, 2,
   6}, {2, 3, 5}, {2, 4, 4}, {2, 5, 3}, {2, 6, 2}, {2, 7, 1}, {2, 8,
   0}, {3, 0, 7}, {3, 1, 6}, {3, 2, 5}, {3, 3, 4}, {3, 4, 3}, {3, 5,
   2}, {3, 6, 1}, {3, 7, 0}, {4, 0, 6}, {4, 1, 5}, {4, 2, 4}, {4, 3,
   3}, {4, 4, 2}, {4, 5, 1}, {4, 6, 0}, {5, 0, 5}, {5, 1, 4}, {5, 2,
   3}, {5, 3, 2}, {5, 4, 1}, {5, 5, 0}, {6, 0, 4}, {6, 1, 3}, {6, 2,
   2}, {6, 3, 1}, {6, 4, 0}, {7, 0, 3}, {7, 1, 2}, {7, 2, 1}, {7, 3,
   0}, {8, 0, 2}, {8, 1, 1}, {8, 2, 0}, {9, 0, 1}, {9, 1, 0}, {10, 0,
   0}}

tbl1 = Flatten[
   Table[{i, j, n - i - j}, {i, 1, n - 3}, {j, 1, n - i - 1}], 1]

{{1, 1, 8}, {1, 2, 7}, {1, 3, 6}, {1, 4, 5}, {1, 5, 4}, {1, 6, 3}, {1,
    7, 2}, {1, 8, 1}, {2, 1, 7}, {2, 2, 6}, {2, 3, 5}, {2, 4, 4}, {2,
   5, 3}, {2, 6, 2}, {2, 7, 1}, {3, 1, 6}, {3, 2, 5}, {3, 3, 4}, {3, 4,
    3}, {3, 5, 2}, {3, 6, 1}, {4, 1, 5}, {4, 2, 4}, {4, 3, 3}, {4, 4,
   2}, {4, 5, 1}, {5, 1, 4}, {5, 2, 3}, {5, 3, 2}, {5, 4, 1}, {6, 1,
   3}, {6, 2, 2}, {6, 3, 1}, {7, 1, 2}, {7, 2, 1}}

You can get sums by changing Table to Sum and {i, j, n - i - j} to  =

f[i,j,n-i-j], or:

Total[f @@@ tbl0]

f[0, 0, 10] + f[0, 1, 9] + f[0, 2, 8] + f[0, 3, 7] + f[0, 4, 6] +
  f[0, 5, 5] + f[0, 6, 4] + f[0, 7, 3] + f[0, 8, 2] + f[0, 9, 1] +
  f[0, 10, 0] + f[1, 0, 9] + f[1, 1, 8] + f[1, 2, 7] + f[1, 3, 6] +
  f[1, 4, 5] + f[1, 5, 4] + f[1, 6, 3] + f[1, 7, 2] + f[1, 8, 1] +
  f[1, 9, 0] + f[2, 0, 8] + f[2, 1, 7] + f[2, 2, 6] + f[2, 3, 5] +
  f[2, 4, 4] + f[2, 5, 3] + f[2, 6, 2] + f[2, 7, 1] + f[2, 8, 0] +
  f[3, 0, 7] + f[3, 1, 6] + f[3, 2, 5] + f[3, 3, 4] + f[3, 4, 3] +
  f[3, 5, 2] + f[3, 6, 1] + f[3, 7, 0] + f[4, 0, 6] + f[4, 1, 5] +
  f[4, 2, 4] + f[4, 3, 3] + f[4, 4, 2] + f[4, 5, 1] + f[4, 6, 0] +
  f[5, 0, 5] + f[5, 1, 4] + f[5, 2, 3] + f[5, 3, 2] + f[5, 4, 1] +
  f[5, 5, 0] + f[6, 0, 4] + f[6, 1, 3] + f[6, 2, 2] + f[6, 3, 1] +
  f[6, 4, 0] + f[7, 0, 3] + f[7, 1, 2] + f[7, 2, 1] + f[7, 3, 0] +
  f[8, 0, 2] + f[8, 1, 1] + f[8, 2, 0] + f[9, 0, 1] + f[9, 1, 0] +
  f[10, 0, 0]

Total[f @@@ tbl1]

f[1, 1, 8] + f[1, 2, 7] + f[1, 3, 6] + f[1, 4, 5] + f[1, 5, 4] +
  f[1, 6, 3] + f[1, 7, 2] + f[1, 8, 1] + f[2, 1, 7] + f[2, 2, 6] +
  f[2, 3, 5] + f[2, 4, 4] + f[2, 5, 3] + f[2, 6, 2] + f[2, 7, 1] +
  f[3, 1, 6] + f[3, 2, 5] + f[3, 3, 4] + f[3, 4, 3] + f[3, 5, 2] +
  f[3, 6, 1] + f[4, 1, 5] + f[4, 2, 4] + f[4, 3, 3] + f[4, 4, 2] +
  f[4, 5, 1] + f[5, 1, 4] + f[5, 2, 3] + f[5, 3, 2] + f[5, 4, 1] +
  f[6, 1, 3] + f[6, 2, 2] + f[6, 3, 1] + f[7, 1, 2] + f[7, 2, 1]

Bobby

On Sun, 23 Dec 2007 03:36:05 -0600, Jack Kennedy <jack at realmode.com> wro=
te:

> Hi All,
> I often find myself needing to sum over triples
> (or other tuples) like i,j,k where i+j+k=n. Is there
> a convenient way to write this in Mathematica?
> Thanks,
> Jack
>
> (version 5.1)
>
>



-- =

DrMajorBob at bigfoot.com


  • Prev by Date: Re: how fill PolarPlot?
  • Next by Date: Re: how fill PolarPlot?
  • Previous by thread: Re: sum over i+j+k==n
  • Next by thread: how fill PolarPlot?