# Is there any functions to extract the combinations of sets [closed]

Suppose I have a function f which is depending on a,b,c (f[a_,b_,c_]). these a, b, c can take two value zero and infinity. How to have a combination of the function f when it takes zero and infinity values. how many such combinations are possible? Is there any built-in function to carry out this in Mathematica. Actually, the number of variables will increase so I am looking for any built of function exist to carry out this.

• Have a look at Tuples. – b.gates.you.know.what Nov 20 '18 at 15:19
• Since there are two choices for each of three parameters, there are 2^3 possible parameter settings. More generally, for n choices with m parameters, there are n^m possible parameter settings. – Bob Hanlon Nov 20 '18 at 15:38
• yes, you are correct. but my question was is there any built-in function in Mathematica for doing this. – acoustics Nov 20 '18 at 17:06

Tuples gives you the combination of elements, in your case Tuples[{0, ∞}, 3].

{{0, 0, 0}, {0, 0, ∞}, {0, ∞, 0}, {0, ∞, ∞}, {∞, 0, 0}, {∞, 0, ∞}, {∞, ∞, 0}, {∞, ∞, ∞}}

Since that returns a matrix, you can evaluate your function if you put the variables in brackets and use Map. A tractable example where instead of inf I use 1.

f[{a_, b_, c_}] := a + b + c
f /@ Tuples[{0, 1}, 3]


{0, 1, 1, 2, 1, 2, 2, 3}

• It solves my problem thanks. Tuples function is very helpful while handling combinations. – acoustics Nov 20 '18 at 17:14
• Or with the original form for f use Apply: f[a_, b_, c_] := a + b + c; f @@@ Tuples[{0, 1}, 3] – Bob Hanlon Nov 20 '18 at 18:40