What is the identity for Tuples?Duplicate TuplesSelecting from a list returned by TuplesSelect elements in a list of tuples of quaternions that satisfy a conditionTuples of elements from list excluding anything with repeated valuesDelete duplicates in tuples
I have just 4 hours a month to security check a cloud based application - How to use my time?
Undefined control sequence error after TeX Live update
Change date format with sed or awk in file
How to get a large amount of cash abroad if a debit card stops working?
JPEG with transparent background
After upgrading Xcode 11.2 from Xcode 11.1, app crashes due to _UITextLayoutView
Replacing 2-prong outlets in basement - existing wiring has two hot wires, one neutral?
At The Square Brackets
Pigeon Hole Principle (most probably)
Is it possible to be admitted to CS PhD programs (in US) with scholarship at age 18?
What is the difference between money and currency?
Are there any galaxies visible in the night sky around the Orion constellation?
Is there a heuristic approach to the MILP problem?
I have been accused of copying two lab reports from the previous year even though I had done everything by myself
What does it mean by "commercial support available" for an open-source platform?
Isn't LaTeX a complete software for producing books?
Why is weak Kőnig's lemma weaker than Kőnig's lemma?
Is there any 24/7 store in Turku?
Mechanics to keep mobs and environment alive without using tons of memory?
Why is it possible to teach real numbers before even rigorously defining them?
How to enable Double-Tap to Drag in Mac OS X Catalina?
Did Catherine the Great really call for the abolition of serfdom?
How should a leader behave when they miss deadlines themselves?
1 kHz clock over long wire
What is the identity for Tuples?
Duplicate TuplesSelecting from a list returned by TuplesSelect elements in a list of tuples of quaternions that satisfy a conditionTuples of elements from list excluding anything with repeated valuesDelete duplicates in tuples
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;
.everyonelovesstackoverflowposition:absolute;height:1px;width:1px;opacity:0;top:0;left:0;pointer-events:none;
$begingroup$
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.
tuples
$endgroup$
add a comment
|
$begingroup$
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.
tuples
$endgroup$
1
$begingroup$
How do you want youraltTuples[]to behave when the length of $p$ is not zero? For examplealtTuples[a, b, c, d, e, f]returnsTuples[a, b, c, d, e, f], probably not what you want.
$endgroup$
– mjw
Jul 8 at 1:19
$begingroup$
I corrected altTuples. Actually I want it to return Tuples[a, b, c, d, e, f]. I think Nothing is what I was looking for.
$endgroup$
– JAS
Jul 8 at 23:27
$begingroup$
What you have above is almost correct (up to a typo). Anyway seems to produce what you want. 'AltTuples[p,q]` gives the same output as Tuples[p,q] when the first argument is a list with non-zero length.
$endgroup$
– mjw
Jul 8 at 23:36
add a comment
|
$begingroup$
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.
tuples
$endgroup$
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.
tuples
tuples
edited Jul 8 at 23:25
JAS
asked Jul 7 at 22:18
JASJAS
263 bronze badges
263 bronze badges
1
$begingroup$
How do you want youraltTuples[]to behave when the length of $p$ is not zero? For examplealtTuples[a, b, c, d, e, f]returnsTuples[a, b, c, d, e, f], probably not what you want.
$endgroup$
– mjw
Jul 8 at 1:19
$begingroup$
I corrected altTuples. Actually I want it to return Tuples[a, b, c, d, e, f]. I think Nothing is what I was looking for.
$endgroup$
– JAS
Jul 8 at 23:27
$begingroup$
What you have above is almost correct (up to a typo). Anyway seems to produce what you want. 'AltTuples[p,q]` gives the same output as Tuples[p,q] when the first argument is a list with non-zero length.
$endgroup$
– mjw
Jul 8 at 23:36
add a comment
|
1
$begingroup$
How do you want youraltTuples[]to behave when the length of $p$ is not zero? For examplealtTuples[a, b, c, d, e, f]returnsTuples[a, b, c, d, e, f], probably not what you want.
$endgroup$
– mjw
Jul 8 at 1:19
$begingroup$
I corrected altTuples. Actually I want it to return Tuples[a, b, c, d, e, f]. I think Nothing is what I was looking for.
$endgroup$
– JAS
Jul 8 at 23:27
$begingroup$
What you have above is almost correct (up to a typo). Anyway seems to produce what you want. 'AltTuples[p,q]` gives the same output as Tuples[p,q] when the first argument is a list with non-zero length.
$endgroup$
– mjw
Jul 8 at 23:36
1
1
$begingroup$
How do you want your
altTuples[] to behave when the length of $p$ is not zero? For example altTuples[a, b, c, d, e, f] returns Tuples[a, b, c, d, e, f], probably not what you want.$endgroup$
– mjw
Jul 8 at 1:19
$begingroup$
How do you want your
altTuples[] to behave when the length of $p$ is not zero? For example altTuples[a, b, c, d, e, f] returns Tuples[a, b, c, d, e, f], probably not what you want.$endgroup$
– mjw
Jul 8 at 1:19
$begingroup$
I corrected altTuples. Actually I want it to return Tuples[a, b, c, d, e, f]. I think Nothing is what I was looking for.
$endgroup$
– JAS
Jul 8 at 23:27
$begingroup$
I corrected altTuples. Actually I want it to return Tuples[a, b, c, d, e, f]. I think Nothing is what I was looking for.
$endgroup$
– JAS
Jul 8 at 23:27
$begingroup$
What you have above is almost correct (up to a typo). Anyway seems to produce what you want. 'AltTuples[p,q]` gives the same output as Tuples[p,q] when the first argument is a list with non-zero length.
$endgroup$
– mjw
Jul 8 at 23:36
$begingroup$
What you have above is almost correct (up to a typo). Anyway seems to produce what you want. 'AltTuples[p,q]` gives the same output as Tuples[p,q] when the first argument is a list with non-zero length.
$endgroup$
– mjw
Jul 8 at 23:36
add a comment
|
4 Answers
4
active
oldest
votes
$begingroup$
If 1,2,3 is fine, you can use Nothing:
Tuples[Nothing, 1, 2, 3]
(* 1, 2, 3 *)
If you want 1,2,3, you can Flatten the result, of course.
$endgroup$
1
$begingroup$
Thank you, this does exactly what I need.
$endgroup$
– JAS
Jul 8 at 23:20
add a comment
|
$begingroup$
You can use Inactive[Sequence][] as identity like this:
Tuples[Inactive[Sequence][],q]//Activate
q
$endgroup$
add a comment
|
$begingroup$
Use TagSetDelayed to define a function that behaves as desired:
ClearAll[iDentity]
iDentity /: iDentity[___], a : __ := iDentity[a]
iDentity /: Tuples[iDentity[a_]] := a
Tuples[iDentity[], q]
q
Tuples[iDentity[blah], 1, 2, 3]
1, 2, 3
Alternatively, define your function altTuples with two signatures:
ClearAll[altTuples]
altTuples[tuplesIdentity ] := a
altTuples[x_] := Tuples[x]
altTuples[x, y, 1, 2]
x, 1, x, 2, y, 1, y, 2
altTuples[tuplesIdentity, 1, 2]
1, 2
altTuples[, 1, 2]
1, 2
$endgroup$
add a comment
|
$begingroup$
I think this is what you want:
altTuples[p_List, q_List] := If[Length[p] == 0, q, Tuples[p, q]]
The statement
altTuples[, d, e, f]
returns
d, e, f
and
altTuples[a, b, c, d, e, f]
returns
a, d, a, e, a, f, b, d, b, e, b, f, c, d, c, e, c, f
$endgroup$
add a comment
|
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "387"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f201715%2fwhat-is-the-identity-for-tuples%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
If 1,2,3 is fine, you can use Nothing:
Tuples[Nothing, 1, 2, 3]
(* 1, 2, 3 *)
If you want 1,2,3, you can Flatten the result, of course.
$endgroup$
1
$begingroup$
Thank you, this does exactly what I need.
$endgroup$
– JAS
Jul 8 at 23:20
add a comment
|
$begingroup$
If 1,2,3 is fine, you can use Nothing:
Tuples[Nothing, 1, 2, 3]
(* 1, 2, 3 *)
If you want 1,2,3, you can Flatten the result, of course.
$endgroup$
1
$begingroup$
Thank you, this does exactly what I need.
$endgroup$
– JAS
Jul 8 at 23:20
add a comment
|
$begingroup$
If 1,2,3 is fine, you can use Nothing:
Tuples[Nothing, 1, 2, 3]
(* 1, 2, 3 *)
If you want 1,2,3, you can Flatten the result, of course.
$endgroup$
If 1,2,3 is fine, you can use Nothing:
Tuples[Nothing, 1, 2, 3]
(* 1, 2, 3 *)
If you want 1,2,3, you can Flatten the result, of course.
answered Jul 7 at 22:45
AccidentalFourierTransformAccidentalFourierTransform
7,0781 gold badge14 silver badges45 bronze badges
7,0781 gold badge14 silver badges45 bronze badges
1
$begingroup$
Thank you, this does exactly what I need.
$endgroup$
– JAS
Jul 8 at 23:20
add a comment
|
1
$begingroup$
Thank you, this does exactly what I need.
$endgroup$
– JAS
Jul 8 at 23:20
1
1
$begingroup$
Thank you, this does exactly what I need.
$endgroup$
– JAS
Jul 8 at 23:20
$begingroup$
Thank you, this does exactly what I need.
$endgroup$
– JAS
Jul 8 at 23:20
add a comment
|
$begingroup$
You can use Inactive[Sequence][] as identity like this:
Tuples[Inactive[Sequence][],q]//Activate
q
$endgroup$
add a comment
|
$begingroup$
You can use Inactive[Sequence][] as identity like this:
Tuples[Inactive[Sequence][],q]//Activate
q
$endgroup$
add a comment
|
$begingroup$
You can use Inactive[Sequence][] as identity like this:
Tuples[Inactive[Sequence][],q]//Activate
q
$endgroup$
You can use Inactive[Sequence][] as identity like this:
Tuples[Inactive[Sequence][],q]//Activate
q
answered Jul 7 at 22:36
Thies HeideckeThies Heidecke
7,90426 silver badges40 bronze badges
7,90426 silver badges40 bronze badges
add a comment
|
add a comment
|
$begingroup$
Use TagSetDelayed to define a function that behaves as desired:
ClearAll[iDentity]
iDentity /: iDentity[___], a : __ := iDentity[a]
iDentity /: Tuples[iDentity[a_]] := a
Tuples[iDentity[], q]
q
Tuples[iDentity[blah], 1, 2, 3]
1, 2, 3
Alternatively, define your function altTuples with two signatures:
ClearAll[altTuples]
altTuples[tuplesIdentity ] := a
altTuples[x_] := Tuples[x]
altTuples[x, y, 1, 2]
x, 1, x, 2, y, 1, y, 2
altTuples[tuplesIdentity, 1, 2]
1, 2
altTuples[, 1, 2]
1, 2
$endgroup$
add a comment
|
$begingroup$
Use TagSetDelayed to define a function that behaves as desired:
ClearAll[iDentity]
iDentity /: iDentity[___], a : __ := iDentity[a]
iDentity /: Tuples[iDentity[a_]] := a
Tuples[iDentity[], q]
q
Tuples[iDentity[blah], 1, 2, 3]
1, 2, 3
Alternatively, define your function altTuples with two signatures:
ClearAll[altTuples]
altTuples[tuplesIdentity ] := a
altTuples[x_] := Tuples[x]
altTuples[x, y, 1, 2]
x, 1, x, 2, y, 1, y, 2
altTuples[tuplesIdentity, 1, 2]
1, 2
altTuples[, 1, 2]
1, 2
$endgroup$
add a comment
|
$begingroup$
Use TagSetDelayed to define a function that behaves as desired:
ClearAll[iDentity]
iDentity /: iDentity[___], a : __ := iDentity[a]
iDentity /: Tuples[iDentity[a_]] := a
Tuples[iDentity[], q]
q
Tuples[iDentity[blah], 1, 2, 3]
1, 2, 3
Alternatively, define your function altTuples with two signatures:
ClearAll[altTuples]
altTuples[tuplesIdentity ] := a
altTuples[x_] := Tuples[x]
altTuples[x, y, 1, 2]
x, 1, x, 2, y, 1, y, 2
altTuples[tuplesIdentity, 1, 2]
1, 2
altTuples[, 1, 2]
1, 2
$endgroup$
Use TagSetDelayed to define a function that behaves as desired:
ClearAll[iDentity]
iDentity /: iDentity[___], a : __ := iDentity[a]
iDentity /: Tuples[iDentity[a_]] := a
Tuples[iDentity[], q]
q
Tuples[iDentity[blah], 1, 2, 3]
1, 2, 3
Alternatively, define your function altTuples with two signatures:
ClearAll[altTuples]
altTuples[tuplesIdentity ] := a
altTuples[x_] := Tuples[x]
altTuples[x, y, 1, 2]
x, 1, x, 2, y, 1, y, 2
altTuples[tuplesIdentity, 1, 2]
1, 2
altTuples[, 1, 2]
1, 2
edited Jul 8 at 1:48
answered Jul 7 at 23:21
kglrkglr
224k10 gold badges254 silver badges511 bronze badges
224k10 gold badges254 silver badges511 bronze badges
add a comment
|
add a comment
|
$begingroup$
I think this is what you want:
altTuples[p_List, q_List] := If[Length[p] == 0, q, Tuples[p, q]]
The statement
altTuples[, d, e, f]
returns
d, e, f
and
altTuples[a, b, c, d, e, f]
returns
a, d, a, e, a, f, b, d, b, e, b, f, c, d, c, e, c, f
$endgroup$
add a comment
|
$begingroup$
I think this is what you want:
altTuples[p_List, q_List] := If[Length[p] == 0, q, Tuples[p, q]]
The statement
altTuples[, d, e, f]
returns
d, e, f
and
altTuples[a, b, c, d, e, f]
returns
a, d, a, e, a, f, b, d, b, e, b, f, c, d, c, e, c, f
$endgroup$
add a comment
|
$begingroup$
I think this is what you want:
altTuples[p_List, q_List] := If[Length[p] == 0, q, Tuples[p, q]]
The statement
altTuples[, d, e, f]
returns
d, e, f
and
altTuples[a, b, c, d, e, f]
returns
a, d, a, e, a, f, b, d, b, e, b, f, c, d, c, e, c, f
$endgroup$
I think this is what you want:
altTuples[p_List, q_List] := If[Length[p] == 0, q, Tuples[p, q]]
The statement
altTuples[, d, e, f]
returns
d, e, f
and
altTuples[a, b, c, d, e, f]
returns
a, d, a, e, a, f, b, d, b, e, b, f, c, d, c, e, c, f
answered Jul 8 at 23:34
mjwmjw
1,60513 bronze badges
1,60513 bronze badges
add a comment
|
add a comment
|
Thanks for contributing an answer to Mathematica Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f201715%2fwhat-is-the-identity-for-tuples%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
$begingroup$
How do you want your
altTuples[]to behave when the length of $p$ is not zero? For examplealtTuples[a, b, c, d, e, f]returnsTuples[a, b, c, d, e, f], probably not what you want.$endgroup$
– mjw
Jul 8 at 1:19
$begingroup$
I corrected altTuples. Actually I want it to return Tuples[a, b, c, d, e, f]. I think Nothing is what I was looking for.
$endgroup$
– JAS
Jul 8 at 23:27
$begingroup$
What you have above is almost correct (up to a typo). Anyway seems to produce what you want. 'AltTuples[p,q]` gives the same output as Tuples[p,q] when the first argument is a list with non-zero length.
$endgroup$
– mjw
Jul 8 at 23:36