Skip to main content
Tweeted twitter.com/StackMma/status/1148471963180044290
corrected the function altTuples
Source Link
JAS
  • 71
  • 4

My question is, what list p in the following statement returns the list q?

Tuples[{{p},{q}}]

If we think of Tuples as a binary operator then p would be the identity for Tuples.

I thought an empty list would work, but evaluating the following

Tuples[{{},{1,2,3}}]

gives {} instead of {1,2,3} or {{1},{2},{3}} as I had hoped.

The following doesn't work either:

Tuples[{{\[EmptySet]},{1,2,3}}]

Certainly, I could write a function like the following

altTuples[p_List,q_List]:= If[Length[p]==0,q,Tuples[pTuples[{p,q]]q}]

That does exactly what I want, but I want to know if I'm missing something. Is there in fact an identity for Tuples? Is there a way to do what I want with Outer? I've tried the obvious solutions with no luck.

My question is, what list p in the following statement returns the list q?

Tuples[{{p},{q}}]

If we think of Tuples as a binary operator then p would be the identity for Tuples.

I thought an empty list would work, but evaluating the following

Tuples[{{},{1,2,3}}]

gives {} instead of {1,2,3} or {{1},{2},{3}} as I had hoped.

The following doesn't work either:

Tuples[{{\[EmptySet]},{1,2,3}}]

Certainly, I could write a function like the following

altTuples[p_List,q_List]:= If[Length[p]==0,q,Tuples[p,q]]

That does exactly what I want, but I want to know if I'm missing something. Is there in fact an identity for Tuples? Is there a way to do what I want with Outer? I've tried the obvious solutions with no luck.

My question is, what list p in the following statement returns the list q?

Tuples[{{p},{q}}]

If we think of Tuples as a binary operator then p would be the identity for Tuples.

I thought an empty list would work, but evaluating the following

Tuples[{{},{1,2,3}}]

gives {} instead of {1,2,3} or {{1},{2},{3}} as I had hoped.

The following doesn't work either:

Tuples[{{\[EmptySet]},{1,2,3}}]

Certainly, I could write a function like the following

altTuples[p_List,q_List]:= If[Length[p]==0,q,Tuples[{p,q}]

That does exactly what I want, but I want to know if I'm missing something. Is there in fact an identity for Tuples? Is there a way to do what I want with Outer? I've tried the obvious solutions with no luck.

Became Hot Network Question
Source Link
JAS
  • 71
  • 4

What is the identity for Tuples?

My question is, what list p in the following statement returns the list q?

Tuples[{{p},{q}}]

If we think of Tuples as a binary operator then p would be the identity for Tuples.

I thought an empty list would work, but evaluating the following

Tuples[{{},{1,2,3}}]

gives {} instead of {1,2,3} or {{1},{2},{3}} as I had hoped.

The following doesn't work either:

Tuples[{{\[EmptySet]},{1,2,3}}]

Certainly, I could write a function like the following

altTuples[p_List,q_List]:= If[Length[p]==0,q,Tuples[p,q]]

That does exactly what I want, but I want to know if I'm missing something. Is there in fact an identity for Tuples? Is there a way to do what I want with Outer? I've tried the obvious solutions with no luck.