Did I find the right examples for you? yes no

All Samples(39)  |  Call(34)  |  Derive(0)  |  Import(5)
Create a homomorphism object.

This function tries to build a homomorphism from ``domain`` to ``codomain``
via the matrix ``matrix``.

Examples
========

>>> from sympy import QQ
>>> from sympy.abc import x(more...)

        def homomorphism(domain, codomain, matrix):
    r"""
    Create a homomorphism object.

    This function tries to build a homomorphism from ``domain`` to ``codomain``
    via the matrix ``matrix``.

    Examples
    ========

    >>> from sympy import QQ
    >>> from sympy.abc import x
    >>> from sympy.polys.agca import homomorphism

    >>> R = QQ.old_poly_ring(x)
    >>> T = R.free_module(2)

    If ``domain`` is a free module generated by `e_1, \dots, e_n`, then
    ``matrix`` should be an n-element iterable `(b_1, \dots, b_n)` where
    the `b_i` are elements of ``codomain``. The constructed homomorphism is the
    unique homomorphism sending `e_i` to `b_i`.

    >>> F = R.free_module(2)
    >>> h = homomorphism(F, T, [[1, x], [x**2, 0]])
    >>> h
    Matrix([
    [1, x**2], : QQ[x]**2 -> QQ[x]**2
    [x,    0]])
    >>> h([1, 0])
    [1, x]
    >>> h([0, 1])
    [x**2, 0]
    >>> h([1, 1])
    [x**2 + 1, x]

    If ``domain`` is a submodule of a free module, them ``matrix`` determines
    a homomoprhism from the containing free module to ``codomain``, and the
    homomorphism returned is obtained by restriction to ``domain``.

    >>> S = F.submodule([1, 0], [0, x])
    >>> homomorphism(S, T, [[1, x], [x**2, 0]])
    Matrix([
    [1, x**2], : <[1, 0], [0, x]> -> QQ[x]**2
    [x,    0]])

    If ``domain`` is a (sub)quotient `N/K`, then ``matrix`` determines a
    homomorphism from `N` to ``codomain``. If the kernel contains `K`, this
    homomorphism descends to ``domain`` and is returned; otherwise an exception
    is raised.

    >>> homomorphism(S/[(1, 0)], T, [0, [x**2, 0]])
    Matrix([
    [0, x**2], : <[1, 0] + <[1, 0]>, [0, x] + <[1, 0]>, [1, 0] + <[1, 0]>> -> QQ[x]**2
    [0,    0]])
    >>> homomorphism(S/[(0, x)], T, [0, [x**2, 0]])
    Traceback (most recent call last):
    ...
    ValueError: kernel <[1, 0], [0, 0]> must contain sm, got <[0,x]>

    """
    def freepres(module):
        """
        Return a tuple ``(F, S, Q, c)`` where ``F`` is a free module, ``S`` is a
        submodule of ``F``, and ``Q`` a submodule of ``S``, such that
        ``module = S/Q``, and ``c`` is a conversion function.
        """
        if isinstance(module, FreeModule):
            return module, module, module.submodule(), lambda x: module.convert(x)
        if isinstance(module, QuotientModule):
            return (module.base, module.base, module.killed_module,
                    lambda x: module.convert(x).data)
        if isinstance(module, SubQuotientModule):
            return (module.base.container, module.base, module.killed_module,
                    lambda x: module.container.convert(x).data)
        # an ordinary submodule
        return (module.container, module, module.submodule(),
                lambda x: module.container.convert(x))

    SF, SS, SQ, _ = freepres(domain)
    TF, TS, TQ, c = freepres(codomain)
    # NOTE this is probably a bit inefficient (redundant checks)
    return FreeModuleHomomorphism(SF, TF, [c(x) for x in matrix]
         ).restrict_domain(SS).restrict_codomain(TS
         ).quotient_codomain(TQ).quotient_domain(SQ)
        


src/s/y/sympy-HEAD/sympy/polys/agca/tests/test_homomorphisms.py   sympy(Download)
"""Tests for homomorphisms."""
 
from sympy import QQ, S
from sympy.abc import x, y
from sympy.polys.agca import homomorphism
def test_printing():
    R = QQ.old_poly_ring(x)
 
    assert str(homomorphism(R.free_module(1), R.free_module(1), [0])) == \
        'Matrix([[0]]) : QQ[x]**1 -> QQ[x]**1'
    assert str(homomorphism(R.free_module(2), R.free_module(2), [0, 0])) == \
        'Matrix([                       \n[0, 0], : QQ[x]**2 -> QQ[x]**2\n[0, 0]])                       '
    assert str(homomorphism(R.free_module(1), R.free_module(1) / [[x]], [0])) == \
def test_operations():
    F = QQ.old_poly_ring(x).free_module(2)
    G = QQ.old_poly_ring(x).free_module(3)
    f = F.identity_hom()
    g = homomorphism(F, F, [0, [1, x]])

src/s/y/sympy-HEAD/sympy/printing/pretty/tests/test_pretty.py   sympy(Download)
def test_Homomorphism():
    from sympy.polys.agca import homomorphism
 
    R = QQ.old_poly_ring(x)
 
    expr = homomorphism(R.free_module(1), R.free_module(1), [0])
    assert pretty(expr) == ascii_str
 
    expr = homomorphism(R.free_module(2), R.free_module(2), [0, 0])
 
    ucode_str = \
    assert pretty(expr) == ascii_str
 
    expr = homomorphism(R.free_module(1), R.free_module(1) / [[x]], [0])
 
    ucode_str = \

src/s/y/sympy-0.7.5/sympy/printing/pretty/tests/test_pretty.py   sympy(Download)
def test_Homomorphism():
    from sympy.polys.agca import homomorphism
 
    R = QQ.old_poly_ring(x)
 
    expr = homomorphism(R.free_module(1), R.free_module(1), [0])
    assert pretty(expr) == ascii_str
 
    expr = homomorphism(R.free_module(2), R.free_module(2), [0, 0])
 
    ucode_str = \
    assert pretty(expr) == ascii_str
 
    expr = homomorphism(R.free_module(1), R.free_module(1) / [[x]], [0])
 
    ucode_str = \

src/s/y/sympy-HEAD/sympy/printing/tests/test_latex.py   sympy(Download)
def test_Modules():
    from sympy.polys.domains import QQ
    from sympy.polys.agca import homomorphism
 
    R = QQ.old_poly_ring(x, y)
        r"\left< {{\left[ {1},{\frac{x^{3}}{2}} \right]} + {\left< {\left[ {x},{y} \right]},{\left[ {1},{x^{2}} \right]} \right>}},{{\left[ {2},{y} \right]} + {\left< {\left[ {x},{y} \right]},{\left[ {1},{x^{2}} \right]} \right>}} \right>"
 
    h = homomorphism(QQ.old_poly_ring(x).free_module(2), QQ.old_poly_ring(x).free_module(2), [0, 0])
 
    assert latex(h) == r"{\left[\begin{matrix}0 & 0\\0 & 0\end{matrix}\right]} : {{\mathbb{Q}\left[x\right]}^{2}} \to {{\mathbb{Q}\left[x\right]}^{2}}"

src/s/y/sympy-0.7.5/sympy/printing/tests/test_latex.py   sympy(Download)
def test_Modules():
    from sympy.polys.domains import QQ
    from sympy.polys.agca import homomorphism
 
    R = QQ.old_poly_ring(x, y)
        r"\left< {{\left[ {1},{\frac{x^{3}}{2}} \right]} + {\left< {\left[ {x},{y} \right]},{\left[ {1},{x^{2}} \right]} \right>}},{{\left[ {2},{y} \right]} + {\left< {\left[ {x},{y} \right]},{\left[ {1},{x^{2}} \right]} \right>}} \right>"
 
    h = homomorphism(QQ.old_poly_ring(x).free_module(2), QQ.old_poly_ring(x).free_module(2), [0, 0])
 
    assert latex(h) == r"{\left[\begin{matrix}0 & 0\\0 & 0\end{matrix}\right]} : {{\mathbb{Q}\left[x\right]}^{2}} \to {{\mathbb{Q}\left[x\right]}^{2}}"