Skip to main content
added 319 characters in body
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

Some optionsHere is another option:

l = {(#1 - 1) &, (#1^2 + #1) &, (#1^3 - 1) &};

Thread[Times @@ l, Function]
(#1 - 1) (#1^3 - 1) (#1^2 + #1) &

This has the benefit of not evaluating the body of the functions. For example:

Evaluate[Timesl @@= l[[All{(#1 - 1) &, 1]]](#1^2 + #1) &, (Print["!"]; #1^3 - 1) &};

Thread[Times @@ l, Function]
(#1 - 1) (Print["!"]; #1^3 - 1) (#1^2 + #1) &

Note that the Print statement remains. Compare with:

Function @@ {Times @@ First /@ l}

(-1 + #1) (#1 + #1^2) (-1 + #1^3) &

Some options:

l = {(#1 - 1) &, (#1^2 + #1) &, (#1^3 - 1) &};

Thread[Times @@ l, Function]
(#1 - 1) (#1^3 - 1) (#1^2 + #1) &
Evaluate[Times @@ l[[All, 1]]] &
(-1 + #1) (#1 + #1^2) (-1 + #1^3) &

Here is another option:

l = {(#1 - 1) &, (#1^2 + #1) &, (#1^3 - 1) &};

Thread[Times @@ l, Function]
(#1 - 1) (#1^3 - 1) (#1^2 + #1) &

This has the benefit of not evaluating the body of the functions. For example:

l = {(#1 - 1) &, (#1^2 + #1) &, (Print["!"]; #1^3 - 1) &};

Thread[Times @@ l, Function]
(#1 - 1) (Print["!"]; #1^3 - 1) (#1^2 + #1) &

Note that the Print statement remains. Compare with:

Function @@ {Times @@ First /@ l}

(-1 + #1) (#1 + #1^2) (-1 + #1^3) &
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

Some options:

l = {(#1 - 1) &, (#1^2 + #1) &, (#1^3 - 1) &};

Thread[Times @@ l, Function]
(#1 - 1) (#1^3 - 1) (#1^2 + #1) &
Evaluate[Times @@ l[[All, 1]]] &
(-1 + #1) (#1 + #1^2) (-1 + #1^3) &