Ticket #11863: trac_11863_bilinear_form_v3.patch

File trac_11863_bilinear_form_v3.patch, 2.8 KB (added by Frédéric Chapoton, 10 years ago)
  • sage/quadratic_forms/quadratic_form.py

    # HG changeset patch
    # User Anna Haensch <annahaensch@gmail.com>
    # Date 1317152380 14400
    # Node ID 639a44854297aa4739208933bfc6830b7956576c
    # Parent  4da76c3bf3a5c0cb5430ad2b25426fb7c5014210
    trac #11863 bilinear form of a quadratic form
    
    diff --git a/sage/quadratic_forms/quadratic_form.py b/sage/quadratic_forms/quadratic_form.py
    a b class QuadraticForm(): 
    14771477   
    14781478        return ideal(self.base_ring()(self.level()))
    14791479
     1480    def bilinear_map(self,v,w):
     1481        r"""
     1482        Returns the value of the associated bilinear map on two vectors
     1483
     1484        Given a quadratic form `Q` over some base ring `R` with
     1485        characteristic not equal to 2, this gives the image of two
     1486        vectors with coefficients in `R` under the associated bilinear
     1487        map `B`, given by the relation `2 B(v,w) = Q(v) + Q(w) - Q(v+w)`.
     1488
     1489        INPUT:
     1490
     1491        `v, w` -- two vectors
     1492
     1493        OUTPUT:
     1494
     1495        an element of the base ring `R`.
     1496
     1497        EXAMPLES:
     1498
     1499        First, an example over `\ZZ`::
     1500
     1501            sage: Q = QuadraticForm(ZZ,3,[1,4,0,1,4,1])
     1502            sage: v = vector(ZZ,(1,2,0))
     1503            sage: w = vector(ZZ,(0,1,1))
     1504            sage: Q.bilinear_map(v,w)
     1505            8
     1506
     1507        This also works over `\QQ`::
     1508
     1509            sage: Q = QuadraticForm(QQ,2,[1/2,2,1])
     1510            sage: v = vector(QQ,(1,1))
     1511            sage: w = vector(QQ,(1/2,2))
     1512            sage: Q.bilinear_map(v,w)
     1513            19/4
     1514
     1515        The vectors must have the correct length::
     1516
     1517            sage: Q = DiagonalQuadraticForm(ZZ,[1,7,7])
     1518            sage: v = vector((1,2))
     1519            sage: w = vector((1,1,1))
     1520            sage: Q.bilinear_map(v,w)
     1521            Traceback (most recent call last):
     1522            ...
     1523            TypeError: vectors must have length 3
     1524
     1525        This does not work if the characteristic is 2::
     1526
     1527            sage: Q = DiagonalQuadraticForm(GF(2),[1,1,1])
     1528            sage: v = vector((1,1,1))
     1529            sage: w = vector((1,1,1))
     1530            sage: Q.bilinear_map(v,w)
     1531            Traceback (most recent call last):
     1532            ...
     1533            TypeError: not defined for rings of characteristic 2
     1534        """
     1535        if len(v) != self.dim() or len(w) != self.dim():
     1536            raise TypeError("vectors must have length " + str(self.dim()))
     1537        if self.base_ring().characteristic() == 2:
     1538            raise TypeError("not defined for rings of characteristic 2")
     1539        return (self(v+w) - self(v) - self(w))/2
    14801540
    14811541
    14821542## =====================================================================================================
    def DiagonalQuadraticForm(R, diag): 
    15031563        [ * 3 0 0 ]
    15041564        [ * * 5 0 ]
    15051565        [ * * * 7 ]
    1506 
    15071566    """
    15081567    Q = QuadraticForm(R, len(diag))
    15091568    for i in range(len(diag)):