sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.31k stars 451 forks source link

how to use SetMorphism? #17000

Open 3f8450e1-87bf-41c6-ab53-29a0552debb3 opened 9 years ago

3f8450e1-87bf-41c6-ab53-29a0552debb3 commented 9 years ago

Hello every one,

I want create set bijections in sage...

sage: U = Set({'a', 'b', 'c', 'd'})
sage: V = Set({1,2,3,4})
sage: from sage.categories.morphism import SetMorphism
sage: bij = SetMorphism(
....:   Hom(U, V, Sets()),
....:   lambda l: {'a':1, 'b':2, 'c':3, 'd':4}[l]
....: )
sage: bij('a')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-c2a304e84b3a> in <module>()
----> 1 bij('a')

/Users/elix/sage/newinst/cha/local/lib/python2.7/site-packages/sage/categories/map.so in sage.categories.map.Map.__call__ (sage/categories/map.c:5346)()

TypeError: a fails to convert into the map's domain {'a', 'c', 'b', 'd'}, but a `pushforward` method is not properly implemented

How to do this.?

CC: @nthiery

Component: categories

Keywords: morphism

Author: Jean-Baptiste Priez

Issue created by migration from https://trac.sagemath.org/ticket/17000

nthiery commented 9 years ago
comment:1

This is a known limitation which has been annoying for a while: at the end of Map.call, it's systematically checked that the parent of the result is the codomain of the map. In particular, the result should be an Element.

In other words, Map does not play well with facade parents, especially if the elements are plain Python objects.

I think there is a ticket about this, but I don't remember which from the top of my head.

Nice ticket number by the way :-)