Poor Man’s map#

class sage.categories.poor_man_map.PoorManMap(function, domain=None, codomain=None, name=None)[source]#

Bases: SageObject

A class for maps between sets which are not (yet) modeled by parents

Could possibly disappear when all combinatorial classes / enumerated sets will be parents

INPUT:

  • function – a callable or an iterable of callables. This represents the underlying function used to implement this map. If it is an iterable, then the callables will be composed to implement this map.

  • domain – the domain of this map or None if the domain is not known or should remain unspecified

  • codomain – the codomain of this map or None if the codomain is not known or should remain unspecified

  • name – a name for this map or None if this map has no particular name

EXAMPLES:

sage: from sage.categories.poor_man_map import PoorManMap
sage: f = PoorManMap(factorial, domain=(1, 2, 3), codomain=(1, 2, 6))
sage: f
A map from (1, 2, 3) to (1, 2, 6)
sage: f(3)
6
>>> from sage.all import *
>>> from sage.categories.poor_man_map import PoorManMap
>>> f = PoorManMap(factorial, domain=(Integer(1), Integer(2), Integer(3)), codomain=(Integer(1), Integer(2), Integer(6)))
>>> f
A map from (1, 2, 3) to (1, 2, 6)
>>> f(Integer(3))
6

The composition of several functions can be created by passing in a tuple of functions:

sage: i = PoorManMap((factorial, sqrt), domain=(1, 4, 9), codomain=(1, 2, 6))
>>> from sage.all import *
>>> i = PoorManMap((factorial, sqrt), domain=(Integer(1), Integer(4), Integer(9)), codomain=(Integer(1), Integer(2), Integer(6)))

However, the same effect can also be achieved by just composing maps:

sage: g = PoorManMap(factorial, domain=(1, 2, 3), codomain=(1, 2, 6))
sage: h = PoorManMap(sqrt, domain=(1, 4, 9), codomain=(1, 2, 3))
sage: i == g*h
True
>>> from sage.all import *
>>> g = PoorManMap(factorial, domain=(Integer(1), Integer(2), Integer(3)), codomain=(Integer(1), Integer(2), Integer(6)))
>>> h = PoorManMap(sqrt, domain=(Integer(1), Integer(4), Integer(9)), codomain=(Integer(1), Integer(2), Integer(3)))
>>> i == g*h
True
codomain()[source]#

Returns the codomain of self

EXAMPLES:

sage: from sage.categories.poor_man_map import PoorManMap
sage: PoorManMap(lambda x: x+1, domain=(1,2,3), codomain=(2,3,4)).codomain()
(2, 3, 4)
>>> from sage.all import *
>>> from sage.categories.poor_man_map import PoorManMap
>>> PoorManMap(lambda x: x+Integer(1), domain=(Integer(1),Integer(2),Integer(3)), codomain=(Integer(2),Integer(3),Integer(4))).codomain()
(2, 3, 4)
domain()[source]#

Returns the domain of self

EXAMPLES:

sage: from sage.categories.poor_man_map import PoorManMap
sage: PoorManMap(lambda x: x+1, domain=(1,2,3), codomain=(2,3,4)).domain()
(1, 2, 3)
>>> from sage.all import *
>>> from sage.categories.poor_man_map import PoorManMap
>>> PoorManMap(lambda x: x+Integer(1), domain=(Integer(1),Integer(2),Integer(3)), codomain=(Integer(2),Integer(3),Integer(4))).domain()
(1, 2, 3)