2
$\begingroup$
Thread[f[{a, b, c}, 0]]

(*
    {f[a,0],f[b,0],f[c,0]}
*)

Thread[f[{a, b, c}, pp[0]]]

(*
    {f[a,pp[0]],f[b,pp[0]],f[c,pp[0]]}
*)

Howerver, the head of pp can't be List

Thread[f[{a, b, c}, pp[0]]]

Thread[f[{a, b, c}, List[0]]]

Thread::tdlen: Objects of unequal length in f[{a,b,c},{0}] cannot be combined. >>

(*
    f[{a,b,c},{0}]
*)

Thread[f[{a, b, c}, Defer[List][0]]]

(*
    {f[a,List[0]],f[b,List[0]],f[c,List[0]]}
*)

How can I obtain the result above directly? Or this may better be put in Help Page?

Update


how about the reverse case of args.

Reverse /@ Thread[Reverse@f[{75}, {95, 64}], List, 1]

(*
    {f[{75},95],f[{75},64]}
*)

Distribute[f[{75}, {95, 64}], List]

(*
    {f[75,95],f[75,64]}
*)

Distribute[f[{{75}}, {95, 64}], List]

This is expected, is it possible done by Thread or without arg is {75} not {{75}}

$\endgroup$
2
$\begingroup$

Use the three-argument form of Thread:

enter image description here

Thread[f[{a, b, c}, {0}], List, 1]
(* {f[a, {0}], f[b, {0}], f[c, {0}]} *)

See also Thread >> Details

enter image description here

Examples:

Thread[h[{0}, {a, b, c}], List, {2}]
(* {h[{0}, a], h[{0}, b], h[{0}, c]} *)

Thread[h[{0}, {a, b}, {u, r}], List, {2, 3}]
(* {h[{0}, a, u], h[{0}, b, r]} *)

Thread[h[{a, b}, {0}, {u, r}], List, {1, 3, 2}]
(* {h[a, {0}, u], h[b, {0}, r]} *)
|improve this answer|||||
$\endgroup$
  • $\begingroup$ sad, I've tried List, however without args Setting. :) $\endgroup$ – HyperGroups Mar 5 '15 at 9:27
  • $\begingroup$ Hi, how about the reverse case of args. Reverse /@ Thread[Reverse@f[{75}, {95, 64}], List, 1] ? I found Distribute can do but should add a List in first arg. Distribute[f[{75}, {95, 64}], List] or Distribute[f[{{75}}, {95, 64}], List] $\endgroup$ – HyperGroups Mar 5 '15 at 9:47
  • $\begingroup$ @HyperGroups, for the first example i would use Thread[f[{75}, {95, 64}], List, {2}]. Yes, Distribute also works. You can also use f[{75},#]&/@{95,64}], or Tuples[f[{{75}}, {95, 64}]]. $\endgroup$ – kglr Mar 5 '15 at 10:08
  • $\begingroup$ Thanks, I think you can add the Usage of {2} of Thread into the answer. $\endgroup$ – HyperGroups Mar 5 '15 at 10:14
  • $\begingroup$ @kglr Hi, kglr. What if I want to thread {a,b}, {u,r}, {x,y} in h[{a, b}, {0}, {u, r}, {x, y}] $\endgroup$ – matheorem Nov 11 '15 at 1:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.