Ticket #10683: trac_10683-hermitian_inner_product-v3.patch

File trac_10683-hermitian_inner_product-v3.patch, 4.2 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 3b0bda687254cb207ffba8d1382bbd1a2e6abf35
    # Parent  461868191947707e8c6a764078c3bec7274088a6
    10683: Hermitian inner product of vectors
    
    diff -r 461868191947 -r 3b0bda687254 sage/modules/free_module_element.pyx
    a b  
    24312431    # tensor product is an alias in the special case of two vectors
    24322432    tensor_product = outer_product
    24332433
     2434    def hermitian_inner_product(self, right):
     2435        r"""
     2436        Returns the dot product, but with the entries of the first vector
     2437        conjugated beforehand.
     2438
     2439        INPUT:
     2440
     2441        - ``right`` - a vector of the same degree as ``self``
     2442
     2443        OUTPUT:
     2444
     2445        If ``self`` and ``right`` are the vectors `\vec{x}` and
     2446        `\vec{y}` of degree `n` then this routine computes
     2447
     2448        .. math::
     2449
     2450            \sum_{i=1}^{n}\overline{x}_i{y}_i
     2451
     2452        where the bar indicates complex conjugation.
     2453
     2454        ..note::
     2455
     2456            If your vectors do not contain complex entries, then
     2457            :meth:`dot_product` will return the same result without
     2458            the overhead of conjugating elements of ``self``.
     2459
     2460            If you are not computing a weighted inner product, and
     2461            your vectors do not have complex entries, then the
     2462            :meth:`dot_product` should return the same result.
     2463
     2464        EXAMPLES::
     2465
     2466            sage: v = vector(CDF, [2+3*I, 5-4*I])
     2467            sage: w = vector(CDF, [6-4*I, 2+3*I])
     2468            sage: v.hermitian_inner_product(w)
     2469            -2.0 - 3.0*I
     2470
     2471        Sage implements a few specialized fields over the complex numbers,
     2472        such as cyclotomic fields and quadratic number fields.  So long as
     2473        the base rings have a conjugate method, then the Hermitian inner
     2474        product will be available. ::
     2475
     2476            sage: Q.<a> = QuadraticField(-7)
     2477            sage: a^2
     2478            -7
     2479            sage: v = vector(Q, [3+a, 5-2*a])
     2480            sage: w = vector(Q, [6, 4+3*a])
     2481            sage: v.hermitian_inner_product(w)
     2482            17*a - 4
     2483
     2484        The Hermitian inner product should be additive in
     2485        each argument (we only need to test one), linear
     2486        in each argument (with conjugation on the first scalar),
     2487        and anti-commutative. ::
     2488
     2489            sage: alpha = CDF(5.0 + 3.0*I)
     2490            sage: u = vector(CDF, [2+4*I, -3+5*I, 2-7*I])
     2491            sage: v = vector(CDF, [-1+3*I, 5+4*I, 9-2*I])
     2492            sage: w = vector(CDF, [8+3*I, -4+7*I, 3-6*I])
     2493            sage: (u+v).hermitian_inner_product(w) == u.hermitian_inner_product(w) + v.hermitian_inner_product(w)
     2494            True
     2495            sage: (alpha*u).hermitian_inner_product(w) == alpha.conjugate()*u.hermitian_inner_product(w)
     2496            True
     2497            sage: u.hermitian_inner_product(alpha*w) == alpha*u.hermitian_inner_product(w)
     2498            True
     2499            sage: u.hermitian_inner_product(v) == v.hermitian_inner_product(u).conjugate()
     2500            True
     2501
     2502        For vectors with complex entries, the Hermitian inner product
     2503        has a more natural relationship with the 2-norm (which is the
     2504        default for the :meth:`norm` method). The norm squared equals
     2505        the Hermitian inner product of the vector with itself.  ::
     2506
     2507            sage: v = vector(CDF, [-0.66+0.47*I, -0.60+0.91*I, -0.62-0.87*I, 0.53+0.32*I])
     2508            sage: abs(v.norm()^2 - v.hermitian_inner_product(v)) < 1.0e-10
     2509            True
     2510
     2511        TESTS:
     2512
     2513        This method is built on the :meth:`dot_product` method,
     2514        which allows for a wide variety of inputs.  Any error
     2515        handling happens there. ::
     2516
     2517            sage: v = vector(CDF, [2+3*I])
     2518            sage: w = vector(CDF, [5+2*I, 3+9*I])
     2519            sage: v.hermitian_inner_product(w)
     2520            Traceback (most recent call last):
     2521            ...
     2522            ArithmeticError: degrees (1 and 2) must be the same
     2523        """
     2524        return (self.conjugate()).dot_product(right)
     2525
    24342526    def is_dense(self):
    24352527        """
    24362528        Return True if this is a dense vector, which is just a