TL;DR: the maths does not matter. Programming language (design)/computer science/data structures should lead this discussion! Also, -1 on this proposal, -1000 on having it apply to strings.
Feel free to read on if you want to hear some ramblings of somebody who does not get to use their academic knowledge of maths enough seeing an opportunity... On Wed, 6 May 2020 at 07:18, Steven D'Aprano <st...@pearwood.info> wrote: > On Wed, May 06, 2020 at 02:58:01AM +0100, Henk-Jaap Wagenaar wrote: > > > I don't think that is accurate to represent as a representation of "a > > mathematician". The top voted answer here disagrees: > > > https://math.stackexchange.com/questions/122595/whats-the-difference-between-tuples-and-sequences > > > > "A sequence requires each element to be of the same type. > > A tuple can have elements with different types." > > Are you saying that you can't have a sequence that alternates between > ints and rationals, say, or ints and surds (reals)? > > The sequence A_n = sqrt(n) from n=0 starts off int, int, real, ... so > there is that. > That's a sequence in the reals (or algebraics or some other set that contains square roots), of which a subsequence also happens to live in the integers. A square is still a rectangle. > For what its worth, Wolfram Mathworld disagrees with both Greg's comment > and the stackexchange answer, stating that a tuple is just a synonym for > a list, and that both lists and sequences are ordered sets: > > https://mathworld.wolfram.com/n-Tuple.html > > https://mathworld.wolfram.com/List.html These two above pertain to data structures in computer science, not mathematics. An "ordered set" is not a mathematical term I have every come across, but if it is, it means exactly as how they define a sequence (though you would have to extend it to infinite sequences to allow infinite ordered sets): > > https://mathworld.wolfram.com/Sequence.html > > > The notation ([image: a_1], [image: a_2], ..., [image: a_n]) is the same as saying it is a sequence in some set X^n (if not given an X, setting X = {a_1, ..., a_n} works, is that cheating? Yes. Is that a problem in set-theoretic mathematics? Not in this case anyway) > > The common usage for both is: you have a tuple of (Z, +) representing the > > Abelian group of addition (+) on the integers (Z), whereas you have the > > sequence {1/n}_{n \in N} converging to 0 in the space Q^N (rational > > infinite sequences) for example. > > One can come up with many other usages. I think a far more common use > for tuples are the ordered pairs used for coordinates: > > (1, 2) > I would call that an ordered pair, or, a sequence of length 2. > > So although tuples are ordered sets, and sequences are ordered sets, the > way they are used is very different. One would not call the coordinate > (1, 2) a sequence 1 followed by 2, and one would not normally consider a > sequence such as [0, 2, 4, 6, 8, ...] to be a tuple. > I would not use the word "tuple", in my experience, tuple in mathematics (not computer science!) is only used in the way I described it: to gather up the information about a structure into one object, so that we can say it exists: because existing means some kind of set exists, and so we need to somehow codify for e.g. addition on the integers both the addition and the integers, i.e. combining two wholly different things into one 2-sequence: (Z, +). Note that such structures might require infinite tuples, e.g. if they support infinitely many operators. Anyway, this is where the StackOverflow answer comes from: tuples are used in parlance for sequences are in the same "space" for their coordinates, sequences for things that have all coordinates in the same "space". > In normal use, a tuple is considered to be an atomic[1] object (e.g. a > point in space), while a sequence is, in a sense, a kind of iterative > process that has been reified. > > You can construct a sequence (or tuple) iteratively, but whether you do or not has no bearing on the end result. Also, tuples are very much not atomic in the mathematical sense. I would also like to note when you say "a tuple is considered to be an atomic[1] object (e.g. a point in space)", then to a mathematician, A_n = 1/sqrt(n) for n = 0, 1, ... is simply a point in space too: just the space of sequences over the reals. Mathematicians (generally, in the field of foundational logic it is a tad different) don't tend to be concerned with differences such as how you define an object (just need to make sure it exists), whether things are finite or infinite, specified or unspecified. Unfortunately, in real life, in a programming language, we do have to care about these things. > > > I'd say the difference is just one of semantics > > The difference between any two things is always one of semantics. > > > > and as a mathematician I > > would consider tuples and sequences as "isomorphic", in fact, the > > set-theoretical construction of tuples as functions is *identical* to the > > usual definition of sequences: i.e. they are just two interpretations of > > the the same object depending on your point of view. > > Many things are isomorphic. "Prime numbers greater than a googolplex" > are isomorphic to the partial sums of the sequence > > 1/2 − 1/4 + 1/8 − 1/16 + ⋯ = 1/3 > > but that doesn't mean you could use 1/2 * 1/4 as your RSA public key :-) > > > But in this case, it does mean, that claiming that the mathematical point of view is that tuples and lists are different due to them being based on tuples and sequences in mathematics is flawed. An alpha-tuple is the same as an alpha-sequence in mathematics and is an element of X^alpha for some X. That's not a random isomorphism, that's a canonical one, which is a big difference with your isomorphism. I strongly oppose any idea that mathematics supports distinction between tuples and lists, however my main point is that it does not even matter. Python should not be led by mathematical conventions/structures in this decision or in others, and it has not in the past: I can have a set {0} in Python and another {0} and they will be different, in mathematics that makes no sense: those two sets are the same, similarly, Programming languages are not mathematics and mathematics is not a programming language and when it comes to comparing things as equal, using it as an example is a losing battle. It should instead look towards computer science, other programming languages and actual use cases to determine what is best. On a personal note, I prefer the current behaviour: e.g. tuples will not successively compare with a list ever not because it is consistent with any mathematical property, but because I think it is a good design for Python/a programming language. On Wed, 6 May 2020 at 08:05, Greg Ewing <greg.ew...@canterbury.ac.nz> wrote: > On 6/05/20 1:58 pm, Henk-Jaap Wagenaar wrote: > > I'd say the difference is just one of semantics and as a mathematician I > > would consider tuples and sequences as "isomorphic", in fact, the > > set-theoretical construction of tuples as functions is *identical* to > > the usual definition of sequences: i.e. they are just two > > interpretations of the the same object depending on your point of view. > > Maybe the small subset of mathematicians that concern themselves > with trying to define everything in terms of sets, but I don't > think the majority of mathematicians think like that in their > everyday work. It's certainly at odds with the way I see tuples > and sequences being used in mathematics. I would genuinely be interested to be linked some examples of tuples being used in a different way in mathematics, not computer science (e.g. the links by Stephen were in computer science data structures) > As well as the same type vs. different types thing, here are > some other salient differences: > > - Infinite sequences make sense, infinite tuples not so much. > So... say you are solving a problem in 1d, you do that on a real number x, right? Now you solve it in 2d, so you do your work on a pair (x, y), then you might solve it in 3d and do your work on a triplet (x, y, z). A few days later you generalize it to n-dimensions and you get a *sequence* (I would not use the word tuple here, nor have I ever seen it used, though I do not dispute some might) (x_1, ..., x_n) that you work on. Then, a few days later you generalize it to infinite sequences (x_1, x_2, ...). Surely we are done now? No way, we can do that again, so we can make it instead a doubly infinite sequence (x_1, x_2, ..., x_omega, x_(omega + 1), ..., x_(2 * omega)) and so on (we are now inducting over the ordinals slowly but surely, see https://en.wikipedia.org/wiki/Ordinal_number#Transfinite_sequence) Anyway, my point is, to me, all those objects, from x, to (x, y, z), all the way to (x_1, x_2, ..., x_omega, x_(omega + 1), ..., x_(2 * omega)) look the same to me: they are all {x_n}_{n in I} for different index sets I and all with coordinates in X = R, the real numbers. To a programming language/programmer/computer science these are all quite different, require different implementations, restrictions and idea Make no difference to a mathematician how long it is, or even whether "long" makes sense (e.g. you can interpret a function f: R -> R as a sequence {f(x)}_{x in R} instead, which, sometimes might be more insightful than the other interpretation). > - Sequences are fundamentally ordered, whereas tuples are not > ordered in the same sense. Any apparent ordering in a tuple is > an artifact of the way we conventionally write them. If we were > in the habit of labelling the elements of a tuple and writing > things like (x:1, y:2, z:3) then we wouldn't have to write them > in any particular order -- (y:2, x:1, z:3) would be the same > tuple. > Labelling the elements of a tuple? Again, in my view programming/computer science speak coming in again: that does not really make sense when it comes to mathematics. Once again, my point is that mathematics does not matter: the data structure that is a tuple in Python does not correspond to a tuple in mathematics, and that does not even make sense, because mathematics does not deal with data structures. I think also, in the case/example you are describing, you really want a namedtuple (as I would want to describe structures in mathematics too), not a plain tuple, if the order is not what is important.
_______________________________________________ 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/V7CGZDXUYGZXVPEL6BE6AS2EFT7B7JEB/ Code of Conduct: http://python.org/psf/codeofconduct/