On Jul 25, 2019, at 14:57, Chris Angelico <ros...@gmail.com> wrote:
> 
>> On Fri, Jul 26, 2019 at 7:47 AM Greg Ewing <greg.ew...@canterbury.ac.nz> 
>> wrote:
>> 
>> Also, this would really only work sensibly for Cartesian products of
>> two sets, not three or more. Writing s1 * s2 * s3 wouldn't give you
>> a set of 3-tuples (a, b, c), but a set of 2-tuples ((a, b), c).
>> Mathematicians usually gloss over this distinction, but in programming
>> it becomes important.

The usual set-theoretic definition of tuples is just recursively as ordered 
pairs: () is 0, (a) is a, (a, b) is <a, b>, (a, b, c) is <<a, b>, c>, etc.  So, 
you don’t have to gloss over anything; s1 * s2 * s3 gives you elements ((a, b), 
c), but those are identical to elements (a, b, c).

The reason it’s important in Python is that Python tuples aren’t mathematical 
tuples (except maybe for len==2). But then Python sets aren’t infinite, don’t 
contain other sets, etc., so…

> Both could be solved if the product of a set and a set was a
> "Cartesian product" object that just retains an iterator on each.

But then, when you actually want the nested product, would you have to write 
something like set(a*b)*c?

More realistically, you’d probably be producting two things that you thought 
were independent objects, when it turns out that one is actually a product 
object wrapping two sets and you unexpectedly got a flattened product, and now 
have to debug why each game[1] is a player rather than a game number because 
each game is a (player, player, number) rather than a (dontcare, number)…

Even more realistically, both desired possibilities would probably would come 
up so rarely that nobody would have a good intuition for what to expect, so a 
magic collapsing product object is probably a waste of effort.

Because really, when you need N-way products, you almost always need either 
iterators or numpy in the first place.

But if the OP has some good examples, maybe we can extrapolate from those 
instead of guessing what might be useful if examples existed. :)
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/SK5NN6VFW62JSK6KYXWZDOBGUBMYB3ZL/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to