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

MathGroup Archive 2008

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

Search the Archive

Re: Re: Eliminating intermediate results

  • To: mathgroup at smc.vnet.net
  • Subject: [mg91634] Re: [mg91560] Re: Eliminating intermediate results
  • From: Ray Koopman <koopman at sfu.ca>
  • Date: Sat, 30 Aug 2008 01:51:21 -0400 (EDT)
  • Reply-to: Ray Koopman <koopman at sfu.ca>

On Fri, 29 Aug 2008 12:18:19 -0500 danl at wolfram.com wrote:
> 
> In version 6, one could also use built-in IntegerPartitions
> for this sort of thing. For the poster's example:
> 
> Total[6! / Apply[Times,Map[Factorial[Length[#]]&,Map[Split,
>    Map[PadLeft[#,6]&,IntegerPartitions[24,6][[1;;20]]]],{2}],{1}]]
> 
> If desired, one might generate them using Permutations
> instead of just counting via factorial.
> 
> Daniel
> 

Yes, in my haste I forgot that the permutations can be counted 
without actually generating them. This makes it faster 
and reduces the dependence on k:

try[n_,k_] := {Timing@Do[Null,{1*^7}];
 Timing@Tr[Length@Permutations@#&/@P[n-k,k]],
 Timing@Tr[Multinomial@@Length/@Split@#&/@P[n-k,k]],
 Timing@Tr[k!/Times@@Factorial[Length/@Split@#]&/@P[n-k,k]],
 Timing[k!*Tr[1/Times@@Factorial[Length/@Split@#]&/@P[n-k,k]]]}

(On my system, the timed dummy loop is necessary to keep the first 
real time honest. See <http://groups.google.ca/group/comp.soft-sys.math.mathematica/msg/1125a9dbeae0d5db>.)

try[30,6]
{{0.05 Second,118755},
 {0.02 Second,118755},
 {0.02 Second,118755},
 {0.03 Second,118755}}

try[30,8]
{{0.87 Second,1560780},
 {0.01 Second,1560780},
 {0.03 Second,1560780},
 {0.02 Second,1560780}}

try[30,10]
{{6.64 Second,10015005},
 {0.01 Second,10015005},
 {0.03 Second,10015005},
 {0.02 Second,10015005}}


  • Prev by Date: Re: Re: Mathematica and F#
  • Next by Date: Re: light-weight PC to run Mathematica?
  • Previous by thread: Re: Eliminating intermediate results
  • Next by thread: NonlinearRegress of user functions