[Python-ideas] Support multiplication for sets

Terry Reedy tjreedy at udel.edu
Sun Oct 9 07:20:22 CEST 2011


On 10/8/2011 3:42 AM, Georg Brandl wrote:
> Am 08.10.2011 02:57, schrieb Terry Reedy:
>> On 10/7/2011 7:20 AM, Paul Moore wrote:
>>> On 7 October 2011 11:37, Jakob Bowyer<jkbbwr at gmail.com>   wrote:
>>>> There is that but from a math point of view the syntax a * b does make
>>>> sence.
>>>> Its slightly clearer and makes more sense to people from outside of a
>>>> programming background.
>>
>> Math used a different symbol, an 'X' without serifs, for cross-products.
>> The result is a set of 'ordered pairs', which is different from a duple.
>
> While I understand the rest of your post, this made me wonder: what is the
> difference between an ordered pair and a 2-tuple?

I could just say that they are different but nearly synonymous words 
used in different fields. A more precise answer depends on the meaning 
chosen for 'ordered pair' and '2-tuple'.

If one takes 'ordered pair' as an undefined primitive (and generic) 
concept, then '2-tuple' is one specialization of the concept.
https://secure.wikimedia.org/wikipedia/en/wiki/Ordered_pair
says "Ordered pairs are also called 2-tuples, 2-dimensional vectors, or 
sequences of length 2." I take that as meaning that the latter three are 
specializations, as 'tuple' is definitely not the same as 'vector'.

If one takes 'ordered pair' as a specialized set, then they different 
for a different reason. Tuple is not a subclass of set, at least not in 
Python.

In practice, the two classes often have different interfaces. The two 
members of ordered pairs are the first and second. They are extracted by 
two different functions. Lisp cons cells with car (first) and cdr (rest) 
functions are an example. The two members of 2-tuples are also the 0-1 
or 1-2 members and are usually extracted by indexing, which is one 
function taking two parameters. Python duples with 0-1 indexing are an 
example.

-- 
Terry Jan Reedy




More information about the Python-ideas mailing list