For example, there is a list of prime factors.
{{2, 1}, {3, 2}, {43, 5}, {26684839, 1}}
How to combine them to the number 70612139395722186
using Mathematica?
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityFor example, there is a list of prime factors.
{{2, 1}, {3, 2}, {43, 5}, {26684839, 1}}
How to combine them to the number 70612139395722186
using Mathematica?
Times @@ Power @@@ {{2, 1}, {3, 2}, {43, 5}, {26684839, 1}}
Times @@ (#[[1]]^#[[2]] & /@ {{2, 1}, {3, 2}, {43, 5}, {26684839, 1}})
Here is another one
primefactors = {{2, 1}, {3, 2}, {43, 5}, {26684839, 1}};
Fold[Times[#1, Power @@ #2] &, 1, primefactors]
70612139395722186
If the list gets larger enough, you can use ParallelCombine
to MapReduce it,
ParallelCombine[Fold[Times[#1, Power @@ #2] &, 1, #]&, primefactors, Times]
For the list of current size, this actually only slows it down. And it can be used with any of the methods show here so far. If the method does it with as a function, f[#]& then:
ParallelCombine[f[#]&, primefactors, Times]
Also
pf = {{2, 1}, {3, 2}, {43, 5}, {26684839, 1}};
Inner[Power, ## & @@ (pf\[Transpose]), Times]
(* 70612139395722186 *)
Inner[Power, pf[[All, 1]], pf[[All, 2]], Times]
.
$\endgroup$
May 4, 2015 at 4:21