Ticket #11841: Trac_11841.patch

File Trac_11841.patch, 2.9 KB (added by annahaensch, 11 years ago)

put on top of bilinear_map.patch

  • sage/quadratic_forms/quadratic_form.py

    # HG changeset patch
    # User Anna Haensch <annahaensch@gmail.com>
    # Date 1317153891 14400
    # Node ID 448cea64a6e73d0588a9c0641c1d17cc8191ff7e
    # Parent  2f676f6063164ec77125ed3306f8437d310af1dc
    [mq]: Tuesdayb
    
    diff -r 2f676f606316 -r 448cea64a6e7 sage/quadratic_forms/quadratic_form.py
    a b  
    15221522            return (self(v+w)-self(v)-self(w))/2
    15231523
    15241524
    1525 
     1525    def new_lattice_on_space(self,L):
     1526        """
     1527        Determines the quadratic lattice spanned by the vectors in `L` with the same underlying
     1528        quadratic space as the lattice given.  If the given list of vectors doesn't span any
     1529        integral lattice, an error message will occur.  Warning: this allows for degenerate
     1530        lattices. 
     1531               
     1532        INPUT:
     1533           
     1534        - `self`--QuadraticForm
     1535        - `L`- list of vectors 
     1536               
     1537        EXAMPLES::
     1538               
     1539            sage: L=[((2,2)),((3,4))]
     1540            sage: Q=QuadraticForm(ZZ,2,[1,2,1])
     1541            sage: Q.new_lattice_on_space(L)
     1542            Quadratic form in 2 variables over Integer Ring with coefficients:
     1543            [ 16 56 ]
     1544            [ * 49 ]
     1545   
     1546        ::
     1547               
     1548            sage: L=[((1/7,2/7,1/7)),((0,1,0)),((0,0,1))]
     1549            sage: Q=DiagonalQuadraticForm(ZZ,[49,49,686])
     1550            sage: Q.new_lattice_on_space(L)
     1551            Quadratic form in 3 variables over Integer Ring with coefficients:
     1552            [ 19 28 196 ]
     1553            [ * 49 0 ]
     1554            [ * * 686 ]
     1555               
     1556        ::
     1557               
     1558            sage: L=[((2,2)),((1/2,1))]
     1559            sage: Q=QuadraticForm(ZZ,2,[1,2,1])
     1560            sage: Q.new_lattice_on_space(L)
     1561            (<type 'exceptions.TypeError'>, 'This basis cannot give an integral lattice.')
     1562   
     1563        """   
     1564        if len(L)!=self.dim():
     1565            return TypeError, "A basis must have n elements."
     1566        for i in range(len(L)):
     1567            if len(L[i])!=self.dim():
     1568                return TypeError, "vectors must have the same dimension as the underlying space."     
     1569        V=self.base_change_to(QQ)
     1570        mat_entries=[]           
     1571        for i in range(len(L)):
     1572            w_i=vector(QQ,L[i])
     1573            for j in range(i,len(L)):
     1574                w_j=vector(QQ,L[j])
     1575                if V.bilinear_map(w_i,w_j) not in ZZ:
     1576                    return TypeError, "This basis cannot give an integral lattice."
     1577                elif (i==j):
     1578                    mat_entries+=[V.bilinear_map(w_i,w_j)]
     1579                elif (i!=j):
     1580                    mat_entries+=[2*V.bilinear_map(w_i,w_j)]   
     1581        return QuadraticForm(ZZ,self.dim(),mat_entries)
    15261582
    15271583## =====================================================================================================
    15281584