Ticket #10683: trac_10683-hermitian_inner_product-v2.patch

File trac_10683-hermitian_inner_product-v2.patch, 4.2 KB (added by rbeezer, 10 years ago)

Apply first

  • sage/modules/free_module_element.pyx

    # HG changeset patch
    # User Rob Beezer <beezer@ups.edu>
    # Date 1295909255 28800
    # Node ID f3faa10b1a2e873d62c661f5c2ec2459df98c8ab
    # Parent  ace57cd55d39d7358cc3c699f7b6febb5131d5da
    10683: Hermitian inner product of vectors
    
    diff -r ace57cd55d39 -r f3faa10b1a2e sage/modules/free_module_element.pyx
    a b  
    21272127            v = M.coordinate_vector(self)
    21282128            w = M.coordinate_vector(right)
    21292129            return A.linear_combination_of_rows(v).dot_product(w)
    2130        
     2130
     2131    def hermitian_inner_product(self, right):
     2132        r"""
     2133        Returns the dot product, but with the entries of the first vector
     2134        conjugated beforehand.
     2135
     2136        INPUT:
     2137
     2138        - ``right`` - a vector of the same degree as ``self``
     2139
     2140        OUTPUT:
     2141
     2142        If ``self`` and ``right`` are the vectors `\vec{x}` and
     2143        `\vec{y}` of degree `n` then this routine computes
     2144
     2145        .. math::
     2146
     2147            \sum_{i=1}^{n}\overline{x}_i{y}_i
     2148
     2149        where the bar indicates complex conjugation.
     2150
     2151        ..note::
     2152
     2153            If your vectors do not contain complex entries, then
     2154            :meth:`dot_product` will return the same result without
     2155            the overhead of conjugating elements of ``self``.
     2156
     2157            If you are not computing a weighted inner product, and
     2158            your vectors do not have complex entries, then the
     2159            :meth:`dot_product` should return the same result.
     2160
     2161        EXAMPLES::
     2162
     2163            sage: v = vector(CDF, [2+3*I, 5-4*I])
     2164            sage: w = vector(CDF, [6-4*I, 2+3*I])
     2165            sage: v.hermitian_inner_product(w)
     2166            -2.0 - 3.0*I
     2167
     2168        Sage implements a few specialized fields over the complex numbers,
     2169        such as cyclotomic fields and quadratic number fields.  So long as
     2170        the base rings have a conjugate method, then the Hermitian inner
     2171        product will be available. ::
     2172
     2173            sage: Q.<a> = QuadraticField(-7)
     2174            sage: a^2
     2175            -7
     2176            sage: v = vector(Q, [3+a, 5-2*a])
     2177            sage: w = vector(Q, [6, 4+3*a])
     2178            sage: v.hermitian_inner_product(w)
     2179            17*a - 4
     2180
     2181        The Hermitian inner product should be additive in
     2182        each argument (we only need to test one), linear
     2183        in each argument (with conjugation on the first scalar),
     2184        and anti-commutative. ::
     2185
     2186            sage: alpha = CDF(5.0 + 3.0*I)
     2187            sage: u = vector(CDF, [2+4*I, -3+5*I, 2-7*I])
     2188            sage: v = vector(CDF, [-1+3*I, 5+4*I, 9-2*I])
     2189            sage: w = vector(CDF, [8+3*I, -4+7*I, 3-6*I])
     2190            sage: (u+v).hermitian_inner_product(w) == u.hermitian_inner_product(w) + v.hermitian_inner_product(w)
     2191            True
     2192            sage: (alpha*u).hermitian_inner_product(w) == alpha.conjugate()*u.hermitian_inner_product(w)
     2193            True
     2194            sage: u.hermitian_inner_product(alpha*w) == alpha*u.hermitian_inner_product(w)
     2195            True
     2196            sage: u.hermitian_inner_product(v) == v.hermitian_inner_product(u).conjugate()
     2197            True
     2198
     2199        For vectors with complex entries, the Hermitian inner product
     2200        has a more natural relationship with the 2-norm (which is the
     2201        default for the :meth:`norm` method). The norm squared equals
     2202        the Hermitian inner product of the vector with itself.  ::
     2203
     2204            sage: v = vector(CDF, [-0.66+0.47*I, -0.60+0.91*I, -0.62-0.87*I, 0.53+0.32*I])
     2205            sage: abs(v.norm()^2 - v.hermitian_inner_product(v)) < 1.0e-10
     2206            True
     2207
     2208        TESTS:
     2209
     2210        This method is built on the :meth:`dot_product` method,
     2211        which allows for a wide variety of inputs.  Any error
     2212        handling happens there. ::
     2213
     2214            sage: v = vector(CDF, [2+3*I])
     2215            sage: w = vector(CDF, [5+2*I, 3+9*I])
     2216            sage: v.hermitian_inner_product(w)
     2217            Traceback (most recent call last):
     2218            ...
     2219            ArithmeticError: degrees (1 and 2) must be the same
     2220        """
     2221        return (self.conjugate()).dot_product(right)
     2222
    21312223    def is_dense(self):
    21322224        """
    21332225        Return True if this is a dense vector, which is just a