Ticket #10536: trac_10536-vector-conjugation.patch

File trac_10536-vector-conjugation.patch, 2.4 KB (added by rbeezer, 9 years ago)
  • sage/modules/free_module_element.pyx

    # HG changeset patch
    # User Rob Beezer <beezer@ups.edu>
    # Date 1293771955 28800
    # Node ID a889d985aa506a026ea07a0994e3c740bc0915f1
    # Parent  5036b75a6d4138117da279304fd188fa936abc83
    10536: add vector conjugation
    
    diff -r 5036b75a6d41 -r a889d985aa50 sage/modules/free_module_element.pyx
    a b  
    17371737            if self[i] != 0:
    17381738                return (~self[i]) * self
    17391739        return self
     1740
     1741    def conjugate(self):
     1742        r"""
     1743        Returns a vector where every entry has been replaced by its complex conjugate.
     1744
     1745        OUTPUT:
     1746
     1747        A vector of the same length, over the same ring,
     1748        but with each entry replaced by the complex conjugate, as
     1749        implemented by the ``conjugate()`` method for elements of
     1750        the base ring, which is presently always complex conjugation.
     1751
     1752        EXAMPLES::
     1753
     1754            sage: v = vector(CDF, [2.3 - 5.4*I, -1.7 + 3.6*I])
     1755            sage: w = v.conjugate(); w
     1756            (2.3 + 5.4*I, -1.7 - 3.6*I)
     1757            sage: w.parent()
     1758            Vector space of dimension 2 over Complex Double Field
     1759
     1760        Even if conjugation seems nonsensical over a certain ring, this
     1761        method for vectors cooperates silently. ::
     1762
     1763            sage: u = vector(ZZ, range(6))
     1764            sage: u.conjugate()
     1765            (0, 1, 2, 3, 4, 5)
     1766
     1767        Sage implements a few specialized subfields of the complex numbers,
     1768        such as the cyclotomic fields.  This example uses such a field
     1769        containing a primitive 7-th root of unity named ``a``. ::
     1770
     1771            sage: F.<a> = CyclotomicField(7)
     1772            sage: v = vector(F, [a^i for i in range(7)])
     1773            sage: v
     1774            (1, a, a^2, a^3, a^4, a^5, -a^5 - a^4 - a^3 - a^2 - a - 1)
     1775            sage: v.conjugate()
     1776            (1, -a^5 - a^4 - a^3 - a^2 - a - 1, a^5, a^4, a^3, a^2, a)
     1777
     1778        TESTS::
     1779
     1780            sage: n = 15
     1781            sage: x = vector(CDF, [sin(i*pi/n)+cos(i*pi/n)*I for i in range(n)])
     1782            sage: x + x.conjugate() in RDF^n
     1783            True
     1784            sage: I*(x - x.conjugate()) in RDF^n
     1785            True
     1786        """
     1787        entries = [entry.conjugate() for entry in self]
     1788        return vector(entries)
     1789
    17401790       
    17411791    def inner_product(self, right):
    17421792        """