Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" Saturation over ZZ """
""" INPUT:
- A -- a matrix over ZZ - p -- a prime - proof -- bool (default: True)
OUTPUT:
The p-saturation of the matrix A, i.e., a new matrix in Hermite form whose row span a ZZ-module that is p-saturated.
EXAMPLES::
sage: from sage.matrix.matrix_integer_dense_saturation import p_saturation sage: A = matrix(ZZ, 2, 2, [3,2,3,4]); B = matrix(ZZ, 2,3,[1,2,3,4,5,6]) sage: A.det() 6 sage: C = A*B; C [11 16 21] [19 26 33] sage: C2 = p_saturation(C, 2); C2 [ 1 8 15] [ 0 9 18] sage: C2.index_in_saturation() 9 sage: C3 = p_saturation(C, 3); C3 [ 1 0 -1] [ 0 2 4] sage: C3.index_in_saturation() 2 """ else: # Faster than change_ring except OverflowError: # fall back to generic GF(p) matrices A = H.change_ring(GF(p)) verbose("done saturating", tm)
""" INPUT:
- k -- an integer - n -- an integer
OUTPUT:
a randomly chosen sublist of range(k) of size n.
EXAMPLES::
sage: import sage.matrix.matrix_integer_dense_saturation as s sage: s.random_sublist_of_size(10,3) [0, 1, 5] sage: s.random_sublist_of_size(10,7) [0, 1, 3, 4, 5, 7, 8] """ raise ValueError("n must be <= len(v)") # use complement
""" Solve the matrix equation B*Z = A when the last row of $B$ contains huge entries.
INPUT:
- B -- a square n x n nonsingular matrix with painful big bottom row. - A -- an n x k matrix.
OUTPUT:
the unique solution to B*Z = A.
EXAMPLES::
sage: from sage.matrix.matrix_integer_dense_saturation import solve_system_with_difficult_last_row sage: B = matrix(ZZ, 3, [1,2,3, 3,-1,2,939239082,39202803080,2939028038402834]); A = matrix(ZZ,3,2,[1,2,4,3,-1,0]) sage: X = solve_system_with_difficult_last_row(B, A); X [ 290668794698843/226075992027744 468068726971/409557956572] [-226078357385539/1582531944194208 1228691305937/2866905696004] [ 2365357795/1582531944194208 -17436221/2866905696004] sage: B*X == A True """ # See the comments in the function of the same name in matrix_integer_dense_hnf.py. # This function is just a generalization of that one to A a matrix. else: verbose("Difficult solve quickly failed. Using direct approach.") return B.solve_right(A)
# The sought for solution Z to B*Z = A is some linear combination # Z = X + alpha*k # Let w be the last row of B; then Z satisfies # w * Z = A' # where A' is the last row of A. Thus # w * (X + alpha*k) = A' # so w * X + alpha*w*k = A' # so alpha*w*k = A' - w*X.
verbose("Difficult solve quickly failed. Using direct approach.") return B.solve_right(A)
""" Compute a saturation matrix of A.
INPUT:
- A -- a matrix over ZZ - proof -- bool (default: True) - p -- int (default: 0); if not 0 only guarantees that output is p-saturated - max_dets -- int (default: 4) max number of dets of submatrices to compute.
OUTPUT:
matrix -- saturation of the matrix A.
EXAMPLES::
sage: from sage.matrix.matrix_integer_dense_saturation import saturation sage: A = matrix(ZZ, 2, 2, [3,2,3,4]); B = matrix(ZZ, 2,3,[1,2,3,4,5,6]); C = A*B sage: C [11 16 21] [19 26 33] sage: C.index_in_saturation() 18 sage: S = saturation(C); S [11 16 21] [-2 -3 -4] sage: S.index_in_saturation() 1 sage: saturation(C, proof=False) [11 16 21] [-2 -3 -4] sage: saturation(C, p=2) [11 16 21] [-2 -3 -4] sage: saturation(C, p=2, max_dets=1) [11 16 21] [-2 -3 -4] """ # Find a submatrix of full rank and instead saturate that matrix.
# Factor out all common factors from all rows, just in case.
# Take the GCD of at most num_dets randomly chosen determinants.
# already p-saturated return A._insert_zero_columns(zero_cols)
# Factor and p-saturate at each p. # This is not a good algorithm, because all the HNF's in it are really slow! # #tm = verbose('factoring gcd %s of determinants'%d) #limit = 2**31-1 #F = d.factor(limit = limit) #D = [p for p, e in F if p <= limit] #B = [n for n, e in F if n > limit] # all big factors -- there will only be at most one #assert len(B) <= 1 #C = B[0] #for p in D: # A = p_saturation(A, p=p, proof=proof)
# This is a really simple but powerful algorithm. # FACT: If A is a matrix of full rank, then hnf(transpose(A))^(-1)*A is a saturation of A. # To make this practical we use solve_system_with_difficult_last_row, since the # last column of HNF's are typically the only really big ones.
# Now compute B^(-1) * A
r""" The index of A in its saturation.
INPUT:
- ``A`` -- matrix over `\ZZ`
- ``proof`` -- boolean (``True`` or ``False``)
OUTPUT:
An integer
EXAMPLES::
sage: from sage.matrix.matrix_integer_dense_saturation import index_in_saturation sage: A = matrix(ZZ, 2, 2, [3,2,3,4]); B = matrix(ZZ, 2,3,[1,2,3,4,5,6]); C = A*B; C [11 16 21] [19 26 33] sage: index_in_saturation(C) 18 sage: W = C.row_space() sage: S = W.saturation() sage: W.index_in(S) 18
For any zero matrix the index in its saturation is 1 (see :trac:`13034`)::
sage: m = matrix(ZZ, 3) sage: m [0 0 0] [0 0 0] [0 0 0] sage: m.index_in_saturation() 1 sage: m = matrix(ZZ, 2, 3) sage: m [0 0 0] [0 0 0] sage: m.index_in_saturation() 1
TESTS::
sage: zero = matrix(ZZ, [[]]) sage: zero.index_in_saturation() 1 """
|