Path: blob/master/sage/libs/ntl/notes/2006-01-16-pari_ntl_benchmark.txt
4156 views
THIS IS PARI/NTL Linear algebra benchmark:12Looking at what PARI now does for matrices, it seems like3it does a lot. It computes kernels and images pretty4efficiently. It might be easy to get from the PARI kernel5to the echelon form, depending on the format of the PARI kernel.67Here are some examples of using the SAGE/PARI-C interface to8make matrices over finite fields in PARI and computer their kernel.910First a small example so what is going on is clearer:1112sage: k,a = GF(2^8).objgen()13sage: A = MatrixSpace(k,3,5)([k.random_element() for _ in range(3*5)])14sage: A15[ a^5 + a^3 + a^2 a^7 + a^6 + a^2 + 1 a^7 + a^6 + a^4 + a^2 a^3 + a^2 + a a^6 + 1]16[ a^5 + a^3 a^5 + a^4 + a^2 + 1 a^6 + a^2 a^7 + a^6 + a^3 + 1 a^5 + 1]17[ a^7 + a^4 + a^3 + a + 1 a^7 + a^5 + a^4 + a^3 + a^2 + 1 a^7 + a^4 + a^3 + a^2 + a + 1 a^7 + a^4 + a^2 + 1 a^6 + a^5 + a^4 + a^3 + a^2 + a]18sage: B = pari(A)19sage: B20[Mod(Mod(1, 2)*a^5 + Mod(1, 2)*a^3 + Mod(1, 2)*a^2, ...21(a *huge* matrix to look at!)22sage: B.matker()23[Mod(Mod(1, 2)*a^6 + Mod(1, 2)*a^5 + Mod(1, 2)*a^2 + Mod(1, 2)*a + Mod(1, 2),24... again *huge*25This looks beter:26sage: B.matker().lift().lift()27[a^6 + a^5 + a^2 + a + 1, a^6 + a^3;28a^6 + a^4 + a^3 + a^2, a^7 + a^5 + a^4 + a^3 + a^2 + a + 1;29a^4 + a^2 + 1, a^6 + a^5 + a^4 + a^3; 1, 0; 0, 1]3031Note: matrices act from the right in SAGE, so32sage: A.transpose().kernel()33Vector space of degree 5 and dimension 2 over Finite field in a of size 2^834Basis matrix:35[ 1 0 a^4 + a a^7 + a^6 + a^5 + a^4 + a^2 a^3 + a^2 + a]36[ 0 1 a^7 + a^4 + a^2 a^5 + a^4 + a^2 + 1 a^7 + a^5 + a^3 + a + 1]3738-----3940OK, now here's an example to get a sense of speed:4142sage: k,a = GF(2^8).objgen()43sage: A = MatrixSpace(k,50,50)([k.random_element() for _ in range(50*50)])44sage: B = pari(A)45sage: time v= B.matker()46Time: CPU 0.69 s, Wall: 0.79 s4748With your NTL interface code it did a 100x100 matrix in 0.08 seconds.49So NTL appears to currently be *vastly* faster than PARI50(even in C library mode) for51working over finite field extensions. This is good information52to have.5354--------------5556From Martin Albrecht:57I've implemented the NTL GF2E matrices and did some initial benchmarks:5859NTL:6061sage: ntl.set_GF2E_modulus(ntl.GF2X([1,1,0,1,1,0,0,0,1]))62sage: m=ntl.mat_GF2E(100,100,[ ntl.GF2E_random() for i in xrange(100*100) ])63sage: time m.echelon_form()64_10 = 10065Time: CPU 0.08 s, Wall: 0.09 s66676869