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
""" Benchmarks for matrices
This file has many functions for computing timing benchmarks of various methods for random matrices with given bounds for the entries. The systems supported are Sage and Magma.
The basic command syntax is as follows::
sage: import sage.matrix.benchmark as b sage: print("starting"); import sys; sys.stdout.flush(); b.report([b.det_ZZ], 'Test', systems=['sage']) starting... ====================================================================== Test ====================================================================== ... ====================================================================== """
""" Run benchmarks with default arguments for each function in the list F.
INPUT:
- ``F`` - a list of callables used for benchmarking - ``title`` - a string describing this report - ``systems`` - a list of systems (supported entries are 'sage' and 'magma') - ``**kwds`` - keyword arguments passed to all functions in ``F``
EXAMPLES::
sage: import sage.matrix.benchmark as b sage: print("starting"); import sys; sys.stdout.flush(); b.report([b.det_ZZ], 'Test', systems=['sage']) starting... ====================================================================== Test ====================================================================== ... ====================================================================== """ raise NotImplementedError("at most two systems ('sage' or 'magma')") except AlarmInterrupt: t = -timeout if w[1] == 0: w.append(0.0) else: w.append(w[0]/w[1])
####################################################################### # Dense Benchmarks over ZZ #######################################################################
""" Reports all the benchmarks for integer matrices and few rational matrices.
INPUT:
- ``**kwds`` - passed through to :func:`report`
EXAMPLES::
sage: import sage.matrix.benchmark as b sage: print("starting"); import sys; sys.stdout.flush(); b.report_ZZ(systems=['sage']) # long time (15s on sage.math, 2012) starting... ====================================================================== Dense benchmarks over ZZ ====================================================================== ... ====================================================================== """ F = [vecmat_ZZ, rank_ZZ, rank2_ZZ, charpoly_ZZ, smithform_ZZ, det_ZZ, det_QQ, matrix_multiply_ZZ, matrix_add_ZZ, matrix_add_ZZ_2, nullspace_ZZ]
title = 'Dense benchmarks over ZZ' report(F, title, **kwds)
# Integer Nullspace
""" Nullspace over ZZ: Given a n+1 x n matrix over ZZ with random entries between min and max, compute the nullspace.
INPUT:
- ``n`` - matrix dimension (default: ``200``) - ``min`` - minimal value for entries of matrix (default: ``0``) - ``max`` - maximal value for entries of matrix (default: ``2**32``) - ``system`` - either 'sage' or 'magma' (default: 'sage')
EXAMPLES::
sage: import sage.matrix.benchmark as b sage: ts = b.nullspace_ZZ(200) sage: tm = b.nullspace_ZZ(200, system='magma') # optional - magma """ elif system == 'magma': code = """ n := %s; A := RMatrixSpace(RationalField(), n+1,n)![Random(%s,%s) : i in [1..n*(n+1)]]; t := Cputime(); K := Kernel(A); s := Cputime(t); """%(n,min,max) if verbose: print(code) magma.eval(code) return float(magma.eval('s')) else: raise ValueError('unknown system "%s"'%system)
""" Characteristic polynomial over ZZ: Given a n x n matrix over ZZ with random entries between min and max, compute the charpoly.
INPUT:
- ``n`` - matrix dimension (default: ``100``) - ``min`` - minimal value for entries of matrix (default: ``0``) - ``max`` - maximal value for entries of matrix (default: ``9``) - ``system`` - either 'sage' or 'magma' (default: 'sage')
EXAMPLES::
sage: import sage.matrix.benchmark as b sage: ts = b.charpoly_ZZ(100) sage: tm = b.charpoly_ZZ(100, system='magma') # optional - magma """ elif system == 'magma': code = """ n := %s; A := MatrixAlgebra(IntegerRing(), n)![Random(%s,%s) : i in [1..n^2]]; t := Cputime(); K := CharacteristicPolynomial(A); s := Cputime(t); """%(n,min,max) if verbose: print(code) magma.eval(code) return float(magma.eval('s')) else: raise ValueError('unknown system "%s"'%system)
""" Rank over ZZ: Given a n x (n+10) matrix over ZZ with random entries between min and max, compute the rank.
INPUT:
- ``n`` - matrix dimension (default: ``700``) - ``min`` - minimal value for entries of matrix (default: ``0``) - ``max`` - maximal value for entries of matrix (default: ``9``) - ``system`` - either 'sage' or 'magma' (default: 'sage')
EXAMPLES::
sage: import sage.matrix.benchmark as b sage: ts = b.rank_ZZ(300) sage: tm = b.rank_ZZ(300, system='magma') # optional - magma """ elif system == 'magma': code = """ n := %s; A := RMatrixSpace(IntegerRing(), n, n+10)![Random(%s,%s) : i in [1..n*(n+10)]]; t := Cputime(); K := Rank(A); s := Cputime(t); """%(n,min,max) if verbose: print(code) magma.eval(code) return float(magma.eval('s')) else: raise ValueError('unknown system "%s"'%system)
""" Rank 2 over ZZ: Given a (n + 10) x n matrix over ZZ with random entries between min and max, compute the rank.
INPUT:
- ``n`` - matrix dimension (default: ``400``) - ``min`` - minimal value for entries of matrix (default: ``0``) - ``max`` - maximal value for entries of matrix (default: ``2**64``) - ``system`` - either 'sage' or 'magma' (default: 'sage')
EXAMPLES::
sage: import sage.matrix.benchmark as b sage: ts = b.rank2_ZZ(300) sage: tm = b.rank2_ZZ(300, system='magma') # optional - magma """ elif system == 'magma': code = """ n := %s; A := RMatrixSpace(IntegerRing(), n+10, n)![Random(%s,%s) : i in [1..n*(n+10)]]; t := Cputime(); K := Rank(A); s := Cputime(t); """%(n,min,max) if verbose: print(code) magma.eval(code) return float(magma.eval('s')) else: raise ValueError('unknown system "%s"'%system)
# Smith Form
""" Smith Form over ZZ: Given a n x n matrix over ZZ with random entries between min and max, compute the Smith normal form.
INPUT:
- ``n`` - matrix dimension (default: ``128``) - ``min`` - minimal value for entries of matrix (default: ``0``) - ``max`` - maximal value for entries of matrix (default: ``9``) - ``system`` - either 'sage' or 'magma' (default: 'sage')
EXAMPLES::
sage: import sage.matrix.benchmark as b sage: ts = b.smithform_ZZ(100) sage: tm = b.smithform_ZZ(100, system='magma') # optional - magma """ elif system == 'magma': code = """ n := %s; A := MatrixAlgebra(IntegerRing(), n)![Random(%s,%s) : i in [1..n^2]]; t := Cputime(); K := ElementaryDivisors(A); s := Cputime(t); """%(n,min,max) if verbose: print(code) magma.eval(code) return float(magma.eval('s')) else: raise ValueError('unknown system "%s"'%system)
""" Matrix multiplication over ZZ Given an n x n matrix A over ZZ with random entries between min and max, inclusive, compute A * (A+1).
INPUT:
- ``n`` - matrix dimension (default: ``300``) - ``min`` - minimal value for entries of matrix (default: ``-9``) - ``max`` - maximal value for entries of matrix (default: ``9``) - ``system`` - either 'sage' or 'magma' (default: 'sage') - ``times`` - number of experiments (default: ``1``)
EXAMPLES::
sage: import sage.matrix.benchmark as b sage: ts = b.matrix_multiply_ZZ(200) sage: tm = b.matrix_multiply_ZZ(200, system='magma') # optional - magma """ elif system == 'magma': code = """ n := %s; A := MatrixAlgebra(IntegerRing(), n)![Random(%s,%s) : i in [1..n^2]]; B := A + 1; t := Cputime(); for z in [1..%s] do K := A * B; end for; s := Cputime(t); """%(n,min,max,times) if verbose: print(code) magma.eval(code) return float(magma.eval('s'))/times else: raise ValueError('unknown system "%s"'%system)
""" Matrix addition over ZZ Given an n x n matrix A and B over ZZ with random entries between ``min`` and ``max``, inclusive, compute A + B ``times`` times.
INPUT:
- ``n`` - matrix dimension (default: ``200``) - ``min`` - minimal value for entries of matrix (default: ``-9``) - ``max`` - maximal value for entries of matrix (default: ``9``) - ``system`` - either 'sage' or 'magma' (default: 'sage') - ``times`` - number of experiments (default: ``50``)
EXAMPLES::
sage: import sage.matrix.benchmark as b sage: ts = b.matrix_add_ZZ(200) sage: tm = b.matrix_add_ZZ(200, system='magma') # optional - magma """ elif system == 'magma': code = """ n := %s; min := %s; max := %s; A := MatrixAlgebra(IntegerRing(), n)![Random(min,max) : i in [1..n^2]]; B := MatrixAlgebra(IntegerRing(), n)![Random(min,max) : i in [1..n^2]]; t := Cputime(); for z in [1..%s] do K := A + B; end for; s := Cputime(t); """%(n,min,max,times) if verbose: print(code) magma.eval(code) return float(magma.eval('s'))/times else: raise ValueError('unknown system "%s"'%system)
""" Matrix addition over ZZ. Given an n x n matrix A and B over ZZ with random ``bits``-bit entries, compute A + B.
INPUT:
- ``n`` - matrix dimension (default: ``200``) - ``bits`` - bitsize of entries - ``system`` - either 'sage' or 'magma' (default: 'sage') - ``times`` - number of experiments (default: ``50``)
EXAMPLES::
sage: import sage.matrix.benchmark as b sage: ts = b.matrix_add_ZZ_2(200) sage: tm = b.matrix_add_ZZ_2(200, system='magma') # optional - magma """
""" Dense integer determinant over ZZ. Given an n x n matrix A over ZZ with random entries between min and max, inclusive, compute det(A).
INPUT:
- ``n`` - matrix dimension (default: ``200``) - ``min`` - minimal value for entries of matrix (default: ``1``) - ``max`` - maximal value for entries of matrix (default: ``100``) - ``system`` - either 'sage' or 'magma' (default: 'sage')
EXAMPLES::
sage: import sage.matrix.benchmark as b sage: ts = b.det_ZZ(200) sage: tm = b.det_ZZ(200, system='magma') # optional - magma """ elif system == 'magma': code = """ n := %s; A := MatrixAlgebra(IntegerRing(), n)![Random(%s,%s) : i in [1..n^2]]; t := Cputime(); d := Determinant(A); s := Cputime(t); """%(n,min,max) if verbose: print(code) magma.eval(code) return float(magma.eval('s')) else: raise ValueError('unknown system "%s"'%system)
""" Dense rational determinant over QQ. Given an n x n matrix A over QQ with random entries with numerator bound and denominator bound, compute det(A).
INPUT:
- ``n`` - matrix dimension (default: ``200``) - ``num_bound`` - numerator bound, inclusive (default: ``10``) - ``den_bound`` - denominator bound, inclusive (default: ``10``) - ``system`` - either 'sage' or 'magma' (default: 'sage')
EXAMPLES::
sage: import sage.matrix.benchmark as b sage: ts = b.det_QQ(200) sage: ts = b.det_QQ(10, num_bound=100000, den_bound=10000) sage: tm = b.det_QQ(200, system='magma') # optional - magma """ elif system == 'magma': code = """ n := %s; A := MatrixAlgebra(RationalField(), n)![Random(%s,%s)/Random(1,%s) : i in [1..n^2]]; t := Cputime(); d := Determinant(A); s := Cputime(t); """%(n,-num_bound, num_bound, den_bound) if verbose: print(code) magma.eval(code) return float(magma.eval('s')) else: raise ValueError('unknown system "%s"'%system)
""" Vector matrix multiplication over ZZ.
Given an n x n matrix A over ZZ with random entries between min and max, inclusive, and v the first row of A, compute the product v * A.
INPUT:
- ``n`` - matrix dimension (default: ``300``) - ``min`` - minimal value for entries of matrix (default: ``-9``) - ``max`` - maximal value for entries of matrix (default: ``9``) - ``system`` - either 'sage' or 'magma' (default: 'sage') - ``times`` - number of runs (default: ``200``)
EXAMPLES::
sage: import sage.matrix.benchmark as b sage: ts = b.vecmat_ZZ(300) # long time sage: tm = b.vecmat_ZZ(300, system='magma') # optional - magma """ if system == 'sage': A = random_matrix(ZZ, n, n, x=min, y=max+1) v = A.row(0) t = cputime() for z in range(times): w = v * A return cputime(t)/times elif system == 'magma': code = """ n := %s; A := MatrixAlgebra(IntegerRing(), n)![Random(%s,%s) : i in [1..n^2]]; v := A[1]; t := Cputime(); for z in [1..%s] do K := v * A; end for; s := Cputime(t); """%(n,min,max,times) if verbose: print(code) magma.eval(code) return float(magma.eval('s'))/times else: raise ValueError('unknown system "%s"'%system)
####################################################################### # Dense Benchmarks over GF(p), for small p. #######################################################################
""" Runs all the reports for finite field matrix operations, for prime p=16411.
INPUT:
- ``p`` - ignored - ``**kwds`` - passed through to :func:`report`
.. note::
right now, even though p is an input, it is being ignored! If you need to check the performance for other primes, you can call individual benchmark functions.
EXAMPLES::
sage: import sage.matrix.benchmark as b sage: print("starting"); import sys; sys.stdout.flush(); b.report_GF(systems=['sage']) starting... ====================================================================== Dense benchmarks over GF with prime 16411 ====================================================================== ... ====================================================================== """ matrix_multiply_GF, det_GF]
# Nullspace over GF
""" Given a n+1 x n matrix over GF(p) with random entries, compute the nullspace.
INPUT:
- ``n`` - matrix dimension (default: 300) - ``p`` - prime number (default: ``16411``) - ``system`` - either 'magma' or 'sage' (default: 'sage')
EXAMPLES::
sage: import sage.matrix.benchmark as b sage: ts = b.nullspace_GF(300) sage: tm = b.nullspace_GF(300, system='magma') # optional - magma """ elif system == 'magma': code = """ n := %s; A := Random(RMatrixSpace(GF(%s), n, n+1)); t := Cputime(); K := Kernel(A); s := Cputime(t); """%(n,p) if verbose: print(code) magma.eval(code) return magma.eval('s') else: raise ValueError('unknown system "%s"'%system)
# Characteristic Polynomial over GF
""" Given a n x n matrix over GF with random entries, compute the charpoly.
INPUT:
- ``n`` - matrix dimension (default: 100) - ``p`` - prime number (default: ``16411``) - ``system`` - either 'magma' or 'sage' (default: 'sage')
EXAMPLES::
sage: import sage.matrix.benchmark as b sage: ts = b.charpoly_GF(100) sage: tm = b.charpoly_GF(100, system='magma') # optional - magma """ elif system == 'magma': code = """ n := %s; A := Random(MatrixAlgebra(GF(%s), n)); t := Cputime(); K := CharacteristicPolynomial(A); s := Cputime(t); """%(n,p) if verbose: print(code) magma.eval(code) return magma.eval('s') else: raise ValueError('unknown system "%s"'%system)
""" Given two n x n matrix over GF(p) with random entries, add them.
INPUT:
- ``n`` - matrix dimension (default: 300) - ``p`` - prime number (default: ``16411``) - ``system`` - either 'magma' or 'sage' (default: 'sage') - ``times`` - number of experiments (default: ``100``)
EXAMPLES::
sage: import sage.matrix.benchmark as b sage: ts = b.matrix_add_GF(500, p=19) sage: tm = b.matrix_add_GF(500, p=19, system='magma') # optional - magma """ elif system == 'magma': code = """ n := %s; A := Random(MatrixAlgebra(GF(%s), n)); B := Random(MatrixAlgebra(GF(%s), n)); t := Cputime(); for z in [1..%s] do K := A + B; end for; s := Cputime(t); """%(n,p,p,times) if verbose: print(code) magma.eval(code) return magma.eval('s') else: raise ValueError('unknown system "%s"'%system)
# Matrix multiplication over GF(p)
""" Given an n x n matrix A over GF(p) with random entries, compute A * (A+1).
INPUT:
- ``n`` - matrix dimension (default: 100) - ``p`` - prime number (default: ``16411``) - ``system`` - either 'magma' or 'sage' (default: 'sage') - ``times`` - number of experiments (default: ``3``)
EXAMPLES::
sage: import sage.matrix.benchmark as b sage: ts = b.matrix_multiply_GF(100, p=19) sage: tm = b.matrix_multiply_GF(100, p=19, system='magma') # optional - magma """ elif system == 'magma': code = """ n := %s; A := Random(MatrixAlgebra(GF(%s), n)); B := A + 1; t := Cputime(); for z in [1..%s] do K := A * B; end for; s := Cputime(t); """%(n,p,times) if verbose: print(code) magma.eval(code) return float(magma.eval('s'))/times else: raise ValueError('unknown system "%s"'%system)
""" Rank over GF(p): Given a n x (n+10) matrix over GF(p) with random entries, compute the rank.
INPUT:
- ``n`` - matrix dimension (default: 300) - ``p`` - prime number (default: ``16411``) - ``system`` - either 'magma' or 'sage' (default: 'sage')
EXAMPLES::
sage: import sage.matrix.benchmark as b sage: ts = b.rank_GF(1000) sage: tm = b.rank_GF(1000, system='magma') # optional - magma """ elif system == 'magma': code = """ n := %s; A := Random(MatrixAlgebra(GF(%s), n)); t := Cputime(); K := Rank(A); s := Cputime(t); """%(n,p) if verbose: print(code) magma.eval(code) return float(magma.eval('s')) else: raise ValueError('unknown system "%s"'%system)
""" Rank over GF(p): Given a (n + 10) x n matrix over GF(p) with random entries, compute the rank.
INPUT:
- ``n`` - matrix dimension (default: 300) - ``p`` - prime number (default: ``16411``) - ``system`` - either 'magma' or 'sage' (default: 'sage')
EXAMPLES::
sage: import sage.matrix.benchmark as b sage: ts = b.rank2_GF(500) sage: tm = b.rank2_GF(500, system='magma') # optional - magma """ elif system == 'magma': code = """ n := %s; A := Random(MatrixAlgebra(GF(%s), n)); t := Cputime(); K := Rank(A); s := Cputime(t); """%(n,p) if verbose: print(code) magma.eval(code) return float(magma.eval('s')) else: raise ValueError('unknown system "%s"'%system)
""" Dense determinant over GF(p). Given an n x n matrix A over GF with random entries compute det(A).
INPUT:
- ``n`` - matrix dimension (default: 300) - ``p`` - prime number (default: ``16411``) - ``system`` - either 'magma' or 'sage' (default: 'sage')
EXAMPLES::
sage: import sage.matrix.benchmark as b sage: ts = b.det_GF(1000) sage: tm = b.det_GF(1000, system='magma') # optional - magma """ elif system == 'magma': code = """ n := %s; A := Random(MatrixAlgebra(GF(%s), n)); t := Cputime(); d := Determinant(A); s := Cputime(t); """%(n,p) if verbose: print(code) magma.eval(code) return float(magma.eval('s')) else: raise ValueError('unknown system "%s"'%system)
####################################################################### # Dense Benchmarks over QQ #######################################################################
""" Returns the Hilbert matrix of size n over rationals.
EXAMPLES::
sage: import sage.matrix.benchmark as b sage: b.hilbert_matrix(3) [ 1 1/2 1/3] [1/2 1/3 1/4] [1/3 1/4 1/5] """
# Reduced row echelon form over QQ
""" Given a n x (2*n) matrix over QQ with random integer entries between min and max, compute the reduced row echelon form.
INPUT:
- ``n`` - matrix dimension (default: ``300``) - ``min`` - minimal value for entries of matrix (default: ``-9``) - ``max`` - maximal value for entries of matrix (default: ``9``) - ``system`` - either 'sage' or 'magma' (default: 'sage')
EXAMPLES::
sage: import sage.matrix.benchmark as b sage: ts = b.echelon_QQ(100) sage: tm = b.echelon_QQ(100, system='magma') # optional - magma """ elif system == 'magma': code = """ n := %s; A := RMatrixSpace(RationalField(), n, 2*n)![Random(%s,%s) : i in [1..n*2*n]]; t := Cputime(); K := EchelonForm(A); s := Cputime(t); """%(n,min,max) if verbose: print(code) magma.eval(code) return float(magma.eval('s')) else: raise ValueError('unknown system "%s"'%system)
# Invert a matrix over QQ.
""" Given a n x n matrix over QQ with random integer entries between min and max, compute the reduced row echelon form.
INPUT:
- ``n`` - matrix dimension (default: ``300``) - ``min`` - minimal value for entries of matrix (default: ``-9``) - ``max`` - maximal value for entries of matrix (default: ``9``) - ``system`` - either 'sage' or 'magma' (default: 'sage')
EXAMPLES::
sage: import sage.matrix.benchmark as b sage: ts = b.inverse_QQ(100) sage: tm = b.inverse_QQ(100, system='magma') # optional - magma """ elif system == 'magma': code = """ n := %s; A := MatrixAlgebra(RationalField(), n)![Random(%s,%s) : i in [1..n*n]]; t := Cputime(); K := A^(-1); s := Cputime(t); """%(n,min,max) if verbose: print(code) magma.eval(code) return float(magma.eval('s')) else: raise ValueError('unknown system "%s"'%system)
# Matrix multiplication over QQ """ Given an n x n matrix A over QQ with random entries whose numerators and denominators are bounded by bnd, compute A * (A+1).
INPUT:
- ``n`` - matrix dimension (default: ``300``) - ``bnd`` - numerator and denominator bound (default: ``bnd``) - ``system`` - either 'sage' or 'magma' (default: 'sage') - ``times`` - number of experiments (default: ``1``)
EXAMPLES::
sage: import sage.matrix.benchmark as b sage: ts = b.matrix_multiply_QQ(100) sage: tm = b.matrix_multiply_QQ(100, system='magma') # optional - magma """ elif system == 'magma': A = magma(random_matrix(QQ, n, n, num_bound=bnd, den_bound=bnd)) code = """ n := %s; A := %s; B := A + 1; t := Cputime(); for z in [1..%s] do K := A * B; end for; s := Cputime(t); """%(n, A.name(), times) if verbose: print(code) magma.eval(code) return float(magma.eval('s'))/times else: raise ValueError('unknown system "%s"'%system)
# Determinant of Hilbert matrix """ Runs the benchmark for calculating the determinant of the hilbert matrix over rationals of dimension n.
INPUT:
- ``n`` - matrix dimension (default: ``300``) - ``system`` - either 'sage' or 'magma' (default: 'sage')
EXAMPLES::
sage: import sage.matrix.benchmark as b sage: ts = b.det_hilbert_QQ(50) sage: tm = b.det_hilbert_QQ(50, system='magma') # optional - magma """ elif system == 'magma': code = """ h := HilbertMatrix(%s); tinit := Cputime(); d := Determinant(h); s := Cputime(tinit); delete h; """%n if verbose: print(code) magma.eval(code) return float(magma.eval('s'))
# inverse of Hilbert matrix """ Runs the benchmark for calculating the inverse of the hilbert matrix over rationals of dimension n.
INPUT:
- ``n`` - matrix dimension (default: ``300``) - ``system`` - either 'sage' or 'magma' (default: 'sage')
EXAMPLES::
sage: import sage.matrix.benchmark as b sage: ts = b.invert_hilbert_QQ(30) sage: tm = b.invert_hilbert_QQ(30, system='magma') # optional - magma """ elif system == 'magma': code = """ h := HilbertMatrix(%s); tinit := Cputime(); d := h^(-1); s := Cputime(tinit); delete h; """%n if verbose: print(code) magma.eval(code) return float(magma.eval('s'))
""" Compute product of square ``n`` matrix by random vector with num and denom bounded by ``h`` the given number of ``times``.
INPUT:
- ``n`` - matrix dimension (default: ``300``) - ``h`` - numerator and denominator bound (default: ``bnd``) - ``system`` - either 'sage' or 'magma' (default: 'sage') - ``times`` - number of experiments (default: ``1``)
EXAMPLES::
sage: import sage.matrix.benchmark as b sage: ts = b.MatrixVector_QQ(500) sage: tm = b.MatrixVector_QQ(500, system='magma') # optional - magma """ elif system == 'magma': code = """ n:=%s; h:=%s; times:=%s; v:=VectorSpace(RationalField(),n)![Random(h)/(Random(h)+1) : i in [1..n]]; M:=MatrixAlgebra(RationalField(),n)![Random(h)/(Random(h)+1) : i in [1..n^2]]; t := Cputime(); for z in [1..times] do W:=v*M; end for; s := Cputime(t); """%(n,h,times) if verbose: print(code) magma.eval(code) return float(magma.eval('s')) else: raise ValueError('unknown system "%s"'%system)
####################################################################### # Dense Benchmarks over machine reals # Note that the precision in reals for MAGMA is base 10, while in # sage it is in base 2 #######################################################################
# Real Nullspace
""" Nullspace over RR: Given a n+1 x n matrix over RR with random entries between min and max, compute the nullspace.
INPUT:
- ``n`` - matrix dimension (default: ``300``) - ``min`` - minimal value for entries of matrix (default: ``0``) - ``max`` - maximal value for entries of matrix (default: ``10``) - ``system`` - either 'sage' or 'magma' (default: 'sage')
EXAMPLES::
sage: import sage.matrix.benchmark as b sage: ts = b.nullspace_RR(100) sage: tm = b.nullspace_RR(100, system='magma') # optional - magma """ elif system == 'magma': code = """ n := %s; A := RMatrixSpace(RealField(16), n+1,n)![Random(%s,%s) : i in [1..n*(n+1)]]; t := Cputime(); K := Kernel(A); s := Cputime(t); """%(n,min,max) if verbose: print(code) magma.eval(code) return float(magma.eval('s')) else: raise ValueError('unknown system "%s"'%system)
""" Nullspace over RDF: Given a n+1 x n matrix over RDF with random entries between min and max, compute the nullspace.
INPUT:
- ``n`` - matrix dimension (default: ``300``) - ``min`` - minimal value for entries of matrix (default: ``0``) - ``max`` - maximal value for entries of matrix (default: `10``) - ``system`` - either 'sage' or 'magma' (default: 'sage')
EXAMPLES::
sage: import sage.matrix.benchmark as b sage: ts = b.nullspace_RDF(100) # long time sage: tm = b.nullspace_RDF(100, system='magma') # optional - magma """ if system == 'sage': from sage.rings.real_double import RDF A = random_matrix(ZZ, n+1, n, x=min, y=max+1).change_ring(RDF) t = cputime() v = A.kernel() return cputime(t) elif system == 'magma': code = """ n := %s; A := RMatrixSpace(RealField(16), n+1,n)![Random(%s,%s) : i in [1..n*(n+1)]]; t := Cputime(); K := Kernel(A); s := Cputime(t); """%(n,min,max) if verbose: print(code) magma.eval(code) return float(magma.eval('s')) else: raise ValueError('unknown system "%s"'%system)
|