MathGroup Archive 2012

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

Search the Archive

Re: Sum of Products

  • To: mathgroup at smc.vnet.net
  • Subject: [mg126743] Re: Sum of Products
  • From: Dana DeLouis <dana01 at me.com>
  • Date: Sun, 3 Jun 2012 05:02:09 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com

>    Total[Times @@@ Subsets[{a, b, c}, {2}]]

Hi.  Just out of educational curiosity..
This appears to be a closed form if your data is a range of integers:

fx[a_Integer?Positive,b_Integer?Positive]/;a<b  :=  
          1/24 (b-a) (b+1-a) (3 a^2+6 a b+a+(3 b-1) b-2)

// Your equation took 13.3 seconds

Total[Times@@@Subsets[Range[1234,6789],{2}]] //Timing
{13.3337,  248323259329475}

// (Bob's excellent faster solution)

SymmetricPolynomial[2, Range[1234,6789]] //Timing
{8.89592,  248323259329475}

// Closed Form:

fx[1234, 6789] //Timing
{0.000072,  248323259329475}


= = = = = = = = = = = = =
Again, only if it's an interval.
HTH :>)
Dana DeLouis
Mac & Math 8
= = = = = = = = = = = = =



On May 29, 5:51 am, "Harvey P. Dale" <h... at nyu.edu> wrote:
>         If I have a list and want to sum the products of each possible
> grouping of two elements in the list, this program will do that:
> 
>                 Total[Times @@@ Subsets[{a, b, c}, {2}]]
> 
> Is there any other, shorter, built-in Mathematica object that will
> produce the same result?
> 
>         Thanks.
> 
>         Harvey





  • Prev by Date: Re: Nesting NMaximize
  • Next by Date: Re: new functional operator
  • Previous by thread: Conditionals for lookup table
  • Next by thread: Histogram ignores 'bspec' (bin spec) ??