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

MathGroup Archive 2008

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

Search the Archive

RE: Product

  • To: mathgroup at smc.vnet.net
  • Subject: [mg88034] RE: [mg87457] Product
  • From: "Jose Luis Gomez" <jose.luis.gomez at itesm.mx>
  • Date: Tue, 22 Apr 2008 06:29:26 -0400 (EDT)
  • References: <200804110542.BAA04653@smc.vnet.net>

In the following link of Wolfram Blog, Mark Sofroniou makes some comments
about the efficient algorithms for multiplications included in Mathematica.

http://blog.wolfram.com/2007/09/25/arithmetic-is-hard-to-get-right/

Best Regards!

Jose
Mexico


-----Mensaje original-----
De: Jose Luis Gomez [mailto:jose.luis.gomez at itesm.mx] 
Enviado el: Viernes, 11 de Abril de 2008 11:24 a.m.
Para: 'Steven'; 'mathgroup at smc.vnet.net'
Asunto: RE: [mg87457] Product

(* Steven *)
(* I think it is an interesting question *)
(* See what happens when we compare total with other ways to add many small
integers *)

(* First a test list:*)

In[1]:= mytestlist = Table[RandomInteger[{1, 9}], {1000000}];

(* add all the numbers in the list, and also report the computer time used
to calculate:*)

In[2]:= Timing[Plus @@ mytestlist]

Out[2]= {0.266, 5003966}

(* AGAIN add all the numbers in the list, BUT THIS TIME USING TOTAL and also
report the computer time used to calculate:*)

In[3]:= Timing[Total[mytestlist]]

Out[3]= {0.031, 5003966}

(* As you can see, for small integers, Total has a special algorithm that
that adds ten times faster than just add all the numbers in order*)
(* Therefore your question is equivalent to ask if there is an improved
algorithm to multiply numbers, and if that algorithm is implemented in a
special command in Mathematica, equivalent to Total*)

(* I do not know the answer, while someone else answers this, you can
multiply the following way:*)

In[4]:= Times @@ mytestlist

(* large result deleted *)

(* The following link might be interesting for you:*)
(* http://homepage.cem.itesm.mx/lgomez/matecmatica/fp/fp.html *)
(* http://homepage.cem.itesm.mx/lgomez/matecmatica/funcionalprog.nb *)

(* Hope that helps *)
(* Jose *)
(* Mexico *)

-----Mensaje original-----
De: Steven [mailto:steven_504 at telenet.be] 
Enviado el: Viernes, 11 de Abril de 2008 12:43 a.m.
Para: mathgroup at smc.vnet.net
Asunto: [mg87457] Product

Silly beginner's question: is there a function to multiply all elements of a
list, like Total does for addition?
'fraid I can't find it.
TIA





  • References:
    • Product
      • From: "Steven" <steven_504@telenet.be>
  • Prev by Date: Re: Re: Timing
  • Next by Date: Re: need help with Plot
  • Previous by thread: Re: Re: Product
  • Next by thread: Re: Product