Ticket #10683: trac_10683-hermitian_inner_product.patch

File trac_10683-hermitian_inner_product.patch, 5.1 KB (added by rbeezer, 10 years ago)
  • sage/modules/free_module_element.pyx

    # HG changeset patch
    # User Rob Beezer <beezer@ups.edu>
    # Date 1295909255 28800
    # Node ID a60bce544850023e286643836f12ea9b8a74a2d0
    # Parent  5cbb00e51ca2580f087684cffe47745bb9f28a47
    10683: Hermitian inner product of vectors
    
    diff -r 5cbb00e51ca2 -r a60bce544850 sage/modules/free_module_element.pyx
    a b  
    21182118            v = M.coordinate_vector(self)
    21192119            w = M.coordinate_vector(right)
    21202120            return A.linear_combination_of_rows(v).dot_product(w)
     2121
     2122    def hermitian_inner_product(self, right):
     2123        r"""
     2124        Returns the inner product, with the entries of the first vector conjugated beforehand.
     2125
     2126        INPUT:
     2127
     2128        - ``right`` - a vector of the same degree as ``self``
     2129
     2130        OUTPUT:
     2131
     2132        If ``self`` and ``right`` are the vectors `\vec{x}` and
     2133        `\vec{y}` of degree `n` then this routine computes
     2134
     2135        .. math::
     2136
     2137            \sum_{i=1}^{n}\overline{x}_i{y}_i
     2138
     2139        where the bar indicates complex conjugation.
     2140
     2141        ..note::
     2142
     2143            If your vectors do not contain complex entries, then
     2144            :meth:`inner_product` will return the same result without
     2145            the overhead of conjugating ``self``.
     2146
     2147            If you are not computing a weighted inner product, and
     2148            your vectors do not have complex entries, then the
     2149            :meth:`dot_product` should return the same result.
     2150
     2151        EXAMPLES::
     2152
     2153            sage: v = vector(CDF, [2+3*I, 5-4*I])
     2154            sage: w = vector(CDF, [6-4*I, 2+3*I])
     2155            sage: v.hermitian_inner_product(w)
     2156            -2.0 - 3.0*I
     2157
     2158        Sage implements a few specialized fields over the complex numbers,
     2159        such as cyclotomic fields and quadratic number fields.  So long as
     2160        the base rings have a conjugate method, then the Hermitian inner
     2161        product will be available. ::
     2162
     2163            sage: Q.<a> = QuadraticField(-7)
     2164            sage: a^2
     2165            -7
     2166            sage: v = vector(Q, [3+a, 5-2*a])
     2167            sage: w = vector(Q, [6, 4+3*a])
     2168            sage: v.hermitian_inner_product(w)
     2169            17*a - 4
     2170
     2171        The Hermitian inner product should be additive in
     2172        each argument (we only need to test one), linear
     2173        in each argument (with conjugation on the first scalar),
     2174        and anti-commutative. ::
     2175
     2176            sage: alpha = CDF(5.0 + 3.0*I)
     2177            sage: u = vector(CDF, [2+4*I, -3+5*I, 2-7*I])
     2178            sage: v = vector(CDF, [-1+3*I, 5+4*I, 9-2*I])
     2179            sage: w = vector(CDF, [8+3*I, -4+7*I, 3-6*I])
     2180            sage: (u+v).hermitian_inner_product(w) == u.hermitian_inner_product(w) + v.hermitian_inner_product(w)
     2181            True
     2182            sage: (alpha*u).hermitian_inner_product(w) == alpha.conjugate()*u.hermitian_inner_product(w)
     2183            True
     2184            sage: u.hermitian_inner_product(alpha*w) == alpha*u.hermitian_inner_product(w)
     2185            True
     2186            sage: u.hermitian_inner_product(v) == v.hermitian_inner_product(u).conjugate()
     2187            True
     2188
     2189        For vectors with complex entries, the Hermitian inner product
     2190        has a more natural relationship with the 2-norm (which is the
     2191        default for the :meth:`norm` method). The norm squared equals
     2192        the Hermitian inner product of the vector with itself.  ::
     2193
     2194            sage: v = vector(CDF, [-0.66+0.47*I, -0.60+0.91*I, -0.62-0.87*I, 0.53+0.32*I])
     2195            sage: abs(v.norm()^2 - v.hermitian_inner_product(v)) < 1.0e-10
     2196            True
     2197
     2198        The parent vector space can be endowed with an inner product
     2199        matrix to effectively weight the inner product along orthogonal
     2200        axes.  ::
     2201
     2202            sage: ipm = matrix(CDF, [[2, 2-I],[2+I, 4]])
     2203            sage: V = VectorSpace(CDF, 2, inner_product_matrix = ipm)
     2204            sage: v = V([3 + 2*I, 1 - 6*I])
     2205            sage: w = V([-1 + 2*I, 2 + I])
     2206            sage: ip = v.hermitian_inner_product(w); ip
     2207            -21.0 + 37.0*I
     2208            sage: ip == v.row().conjugate()*ipm*w.column()
     2209            True
     2210            sage: vv_ip = v.hermitian_inner_product(v); vv_ip
     2211            98.0
     2212            sage: vv_ip in RDF
     2213            True
     2214
     2215        .. note::
     2216
     2217            The use of an inner product matrix makes no restrictions on
     2218            the nature of the matrix.  In particular, in this context it
     2219            need not be Hermitian and positive-definite (as in the
     2220            example above).
     2221
     2222        TESTS:
     2223
     2224        This method is built on the :meth:`inner_product` method,
     2225        which allows for a wide variety of inputs.  Any error
     2226        handling happens there. ::
     2227
     2228            sage: v = vector(CDF, [2+3*I])
     2229            sage: w = vector(CDF, [5+2*I, 3+9*I])
     2230            sage: v.hermitian_inner_product(w)
     2231            Traceback (most recent call last):
     2232            ...
     2233            ArithmeticError: degrees (1 and 2) must be the same
     2234        """
     2235        return (self.conjugate()).inner_product(right)
    21212236       
    21222237    def is_dense(self):
    21232238        """