Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #10338

Re: Sum of Products

From Dana DeLouis <dana01@me.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Sum of Products
Date 2012-06-03 09:03 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jqf99m$a6e$1@smc.vnet.net> (permalink)

Show all headers | View raw


>    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...@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


Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: Sum of Products Dana DeLouis <dana01@me.com> - 2012-06-03 09:03 +0000

csiph-web