Coerce maps¶
- class sage.structure.coerce_maps.CallableConvertMap[source]¶
Bases:
Map
This lets one easily create maps from any callable object.
This is especially useful to create maps from bound methods.
EXAMPLES:
sage: from sage.structure.coerce_maps import CallableConvertMap sage: def foo(P, x): return x/2 sage: f = CallableConvertMap(ZZ, QQ, foo) sage: f(3) 3/2 sage: f Conversion via foo map: From: Integer Ring To: Rational Field
>>> from sage.all import * >>> from sage.structure.coerce_maps import CallableConvertMap >>> def foo(P, x): return x/Integer(2) >>> f = CallableConvertMap(ZZ, QQ, foo) >>> f(Integer(3)) 3/2 >>> f Conversion via foo map: From: Integer Ring To: Rational Field
from sage.structure.coerce_maps import CallableConvertMap def foo(P, x): return x/2 f = CallableConvertMap(ZZ, QQ, foo) f(3) f
Create a homomorphism from \(\RR\) to \(\RR^+\) viewed as additive groups.
sage: # needs sage.symbolic sage: f = CallableConvertMap(RR, RR, exp, parent_as_first_arg=False) sage: f(0) 1.00000000000000 sage: f(1) 2.71828182845905 sage: f(-3) 0.0497870683678639
>>> from sage.all import * >>> # needs sage.symbolic >>> f = CallableConvertMap(RR, RR, exp, parent_as_first_arg=False) >>> f(Integer(0)) 1.00000000000000 >>> f(Integer(1)) 2.71828182845905 >>> f(-Integer(3)) 0.0497870683678639
# needs sage.symbolic f = CallableConvertMap(RR, RR, exp, parent_as_first_arg=False) f(0) f(1) f(-3)
- class sage.structure.coerce_maps.DefaultConvertMap[source]¶
Bases:
Map
This morphism simply calls the codomain’s element_constructor method, passing in the codomain as the first argument.
EXAMPLES:
sage: QQ[['x']].coerce_map_from(QQ) Coercion map: From: Rational Field To: Power Series Ring in x over Rational Field
>>> from sage.all import * >>> QQ[['x']].coerce_map_from(QQ) Coercion map: From: Rational Field To: Power Series Ring in x over Rational Field
QQ[['x']].coerce_map_from(QQ)
- class sage.structure.coerce_maps.DefaultConvertMap_unique[source]¶
Bases:
DefaultConvertMap
This morphism simply defers action to the codomain’s element_constructor method, WITHOUT passing in the codomain as the first argument.
This is used for creating elements that don’t take a parent as the first argument to their __init__ method, for example, Integers, Rationals, Algebraic Reals… all have a unique parent. It is also used when the element_constructor is a bound method (whose self argument is assumed to be bound to the codomain).