Suggestion: make sequence and map interfaces more similar

Antoon Pardon antoon.pardon at rece.vub.ac.be
Wed Mar 30 09:12:29 EDT 2016


Op 30-03-16 om 14:22 schreef Steven D'Aprano:
> On Wed, 30 Mar 2016 09:28 pm, Jussi Piitulainen wrote:
>
>> Steven D'Aprano writes:
>>
>>> On Wed, 30 Mar 2016 06:12 pm, Jussi Piitulainen wrote:
>>>
>>>> Steven D'Aprano writes:
>>>>
>>>>> Given a surjection (many-to-one mapping)
>>>> No. And I doubt that Wikipedia says that.
>>> No to what? What are you disagreeing with?
>> Surjection does not mean many-to-one mapping. It means something else.
>
> Oh, if only I had linked to the Wikipedia page earlier... oh wait, I did.
> Here it is again:
>
> https://en.wikipedia.org/wiki/Bijection,_injection_and_surjection
>
>
> The relevant definition is:
>
>
>     The function is surjective (onto) if every element of the codomain is
> mapped to by at least one element of the domain. (That is, the image and
> the codomain of the function are equal.) A surjective function is a
> surjection. Notationally:
>
>     \forall y \in B, \exists x \in A \text{ such that } y = f(x).\ 
>
>
>
> and the relevant diagram is the image labelled "Non-injective and
> surjective", also seen here:
>
> https://en.wikipedia.org/wiki/File:Surjection.svg
>
>
> Why is a mapping (such as a dict) best described as a surjection? Consider:
>
> d = {1: None, 2: 'a', 3: 'b', 4: None}
>
>
> Every key has exactly one value. There are no values without a key, and
> every value has *at least* one key.

That second remark depends on what you consider the codomain. You could
of course define the codomain as the set of actual values in the mapping,
but that seems to be very artificial since it means that the codomain can
changes any time a value is changed, added or removed.

A more intuitive view would be that the codomain is the set of things
that potentially can be a value in your mapping (in this application).
So looking at your example 'c' seems to be such a potential value which
for the moment doesn't have a key. So your mapping is no surjection.
 

> To be an injection or a bijection, it must be one-to-one. Since multiple
> keys can map to the same value, it's not an injection or a bijection.
>
> Every value must have a key: there are no values in the dict without a key.
> Hence, it's a surjection.

Only if you use the special python meaning of (dictionary) values in this context.
If you use the ordinary (mathematical) meaning, there are lots of values that
don't have a key, like every two characters string.

-- 
Antoon.




More information about the Python-list mailing list