Skip to main content
added 310 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

You can use Tuples:

Tuples[f[{a, b, c}, {a, b, c}]]

{f[a, a], f[a, b], f[a, c], f[b, a], f[b, b], f[b, c], f[c, a], f[c, b], f[c, c]}

f @@@ Tuples[{a, b, c}, 2]

same result

Tuples[f[{a, b}, {r, s, t}, {x, y}]]

{f[a, r, x], f[a, r, y], f[a, s, x], f[a, s, y], f[a, t, x], f[a, t, y], f[b, r, x], f[b, r, y], f[b, s, x], f[b, s, y], f[b, t, x], f[b, t, y]}

f @@@ Tuples[{{a, b}, {r, s, t}, {x, y}}]

same result

p = {a, b};
p1 = {a, a, b, b};
Tuples[f[p, p1]]

{f[a, a], f[a, a], f[a, b], f[a, b], f[b, a], f[b, a], f[b, b], f[b, b]}

You can use Tuples:

Tuples[f[{a, b, c}, {a, b, c}]]

{f[a, a], f[a, b], f[a, c], f[b, a], f[b, b], f[b, c], f[c, a], f[c, b], f[c, c]}

p = {a, b};
p1 = {a, a, b, b};
Tuples[f[p, p1]]

{f[a, a], f[a, a], f[a, b], f[a, b], f[b, a], f[b, a], f[b, b], f[b, b]}

You can use Tuples:

Tuples[f[{a, b, c}, {a, b, c}]]

{f[a, a], f[a, b], f[a, c], f[b, a], f[b, b], f[b, c], f[c, a], f[c, b], f[c, c]}

f @@@ Tuples[{a, b, c}, 2]

same result

Tuples[f[{a, b}, {r, s, t}, {x, y}]]

{f[a, r, x], f[a, r, y], f[a, s, x], f[a, s, y], f[a, t, x], f[a, t, y], f[b, r, x], f[b, r, y], f[b, s, x], f[b, s, y], f[b, t, x], f[b, t, y]}

f @@@ Tuples[{{a, b}, {r, s, t}, {x, y}}]

same result

p = {a, b};
p1 = {a, a, b, b};
Tuples[f[p, p1]]

{f[a, a], f[a, a], f[a, b], f[a, b], f[b, a], f[b, a], f[b, b], f[b, b]}

Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

You can use Tuples:

Tuples[f[{a, b, c}, {a, b, c}]]

{f[a, a], f[a, b], f[a, c], f[b, a], f[b, b], f[b, c], f[c, a], f[c, b], f[c, c]}

p = {a, b};
p1 = {a, a, b, b};
Tuples[f[p, p1]]

{f[a, a], f[a, a], f[a, b], f[a, b], f[b, a], f[b, a], f[b, b], f[b, b]}