Thanks, FiniteSetMaps might be what I want, but I'll keep both approaches in mind.
John On Monday, April 18, 2016 at 3:51:27 PM UTC-7, vdelecroix wrote: > > I read the end of your mail too late. The following works with lambda > functions. > > sage: S = FiniteEnumeratedSet([1,2,3]) > sage: T = FiniteEnumeratedSet([4,5,6,7]) > sage: d = {1:5, 2:7, 3:5} > sage: f = S.hom(lambda x: d[x], T) > sage: f(1) > 5 > sage: f(2) > 7 > sage: f(3) > 5 > > Otherwise you should have a look at FiniteSetMaps. > > On 18/04/16 19:48, Vincent Delecroix wrote: > > It should... but Sage does not recognize that 2 belongs to S. Note that > > the following works > > > > sage: S = FiniteEnumeratedSet([1,2,3]) > > sage: T = FiniteEnumeratedSet([4,5,6,7]) > > sage: f = S.hom(lambda x: 3+x, T) > > sage: f(1) > > 4 > > > > Vincent > > > > On 18/04/16 15:02, John H Palmieri wrote: > >> How do I define a function between finite sets within the category > >> framework? Should the following work? > >> > >> sage: S = Set([1,2,3]) > >> sage: T = Set([4,5,6,7]) > >> sage: f = S.hom(lambda x: 3+x, T) > >> sage: f > >> Generic morphism: > >> From: {1, 2, 3} > >> To: {4, 5, 6, 7} > >> sage: f(2) > >> > >> > --------------------------------------------------------------------------- > >> > >> TypeError Traceback (most recent > >> call > >> last) > >> .... > >> TypeError: 2 fails to convert into the map's domain {1, 2, 3}, but > a > >> `pushforward` method is not properly implemented > >> > >> I see that it works if I define S and T using FiniteEnumeratedSet > >> instead. > >> Is that the best solution? > >> > >> Or suppose I want to define a map sending 1 to 5, 2 to 7, 3 to 5. I > can't > >> see how to use the dictionary {1:5, 2:7, 3:5} (for example) to define a > >> function. > >> > >> In general, I would like fully functional, callable, composable > morphisms > >> of sets, and finite sets are good enough for now. Any advice? Also of > >> other > >> categories, in particular finite abelian groups, but maybe those work > >> better already? > >> > -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at https://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.