| 888 | .. WARNING:: |
| 889 | |
| 890 | This allows for degenerate lattices. |
| 891 | |
| 892 | INPUT: |
| 893 | |
| 894 | `L` -- a list of vectors |
| 895 | |
| 896 | OUTPUT: |
| 897 | |
| 898 | a quadratic form |
| 899 | |
| 900 | EXAMPLES: |
| 901 | |
| 902 | First an example in dimension 2:: |
| 903 | |
| 904 | sage: L = [(2,2),(3,4)] |
| 905 | sage: Q = QuadraticForm(ZZ,2,[1,2,1]) |
| 906 | sage: Q.new_lattice_on_space(L) |
| 907 | Quadratic form in 2 variables over Integer Ring with coefficients: |
| 908 | [ 16 56 ] |
| 909 | [ * 49 ] |
| 910 | |
| 911 | Another example in dimension 3:: |
| 912 | |
| 913 | sage: L = [(1/7,2/7,1/7),(0,1,0),(0,0,1)] |
| 914 | sage: Q = DiagonalQuadraticForm(ZZ,[49,49,686]) |
| 915 | sage: Q.new_lattice_on_space(L) |
| 916 | Quadratic form in 3 variables over Integer Ring with coefficients: |
| 917 | [ 19 28 196 ] |
| 918 | [ * 49 0 ] |
| 919 | [ * * 686 ] |
| 920 | |
| 921 | :: |
| 922 | |
| 923 | sage: L = [(2,2),(1/2,1)] |
| 924 | sage: Q = QuadraticForm(ZZ,2,[1,2,1]) |
| 925 | sage: Q.new_lattice_on_space(L) |
| 926 | Traceback (most recent call last): |
| 927 | ... |
| 928 | TypeError: this basis cannot give an integral lattice |
| 929 | |
| 930 | sage: Q.new_lattice_on_space([(2,2)]) |
| 931 | Traceback (most recent call last): |
| 932 | ... |
| 933 | TypeError: a basis must have n elements |
| 934 | |
| 935 | sage: Q.new_lattice_on_space([(2,2),(1,2,1)]) |
| 936 | Traceback (most recent call last): |
| 937 | ... |
| 938 | TypeError: vectors must have the same dimension as the underlying space |
| 939 | """ |
| 940 | if len(L) != self.dim(): |
| 941 | raise TypeError("a basis must have n elements") |
| 942 | for i in range(len(L)): |
| 943 | if len(L[i]) != self.dim(): |
| 944 | raise TypeError("vectors must have the same dimension as the underlying space") |
| 945 | from sage.rings.rational_field import QQ |
| 946 | V = self.base_change_to(QQ) |
| 947 | mat_entries = [] |
| 948 | for i in range(len(L)): |
| 949 | w_i = vector(QQ,L[i]) |
| 950 | for j in range(i,len(L)): |
| 951 | w_j = vector(QQ,L[j]) |
| 952 | if V.bilinear_map(w_i,w_j) not in ZZ: |
| 953 | raise TypeError("this basis cannot give an integral lattice") |
| 954 | elif i == j: |
| 955 | mat_entries += [V.bilinear_map(w_i,w_j)] |
| 956 | elif i != j: |
| 957 | mat_entries += [2*V.bilinear_map(w_i,w_j)] |
| 958 | return QuadraticForm(ZZ,self.dim(),mat_entries) |