Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/libs/ntl/notes/2006-01-16-pari_ntl_benchmark.txt
4156 views
1
THIS IS PARI/NTL Linear algebra benchmark:
2
3
Looking at what PARI now does for matrices, it seems like
4
it does a lot. It computes kernels and images pretty
5
efficiently. It might be easy to get from the PARI kernel
6
to the echelon form, depending on the format of the PARI kernel.
7
8
Here are some examples of using the SAGE/PARI-C interface to
9
make matrices over finite fields in PARI and computer their kernel.
10
11
First a small example so what is going on is clearer:
12
13
sage: k,a = GF(2^8).objgen()
14
sage: A = MatrixSpace(k,3,5)([k.random_element() for _ in range(3*5)])
15
sage: A
16
[ 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]
17
[ 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]
18
[ 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]
19
sage: B = pari(A)
20
sage: B
21
[Mod(Mod(1, 2)*a^5 + Mod(1, 2)*a^3 + Mod(1, 2)*a^2, ...
22
(a *huge* matrix to look at!)
23
sage: B.matker()
24
[Mod(Mod(1, 2)*a^6 + Mod(1, 2)*a^5 + Mod(1, 2)*a^2 + Mod(1, 2)*a + Mod(1, 2),
25
... again *huge*
26
This looks beter:
27
sage: B.matker().lift().lift()
28
[a^6 + a^5 + a^2 + a + 1, a^6 + a^3;
29
a^6 + a^4 + a^3 + a^2, a^7 + a^5 + a^4 + a^3 + a^2 + a + 1;
30
a^4 + a^2 + 1, a^6 + a^5 + a^4 + a^3; 1, 0; 0, 1]
31
32
Note: matrices act from the right in SAGE, so
33
sage: A.transpose().kernel()
34
Vector space of degree 5 and dimension 2 over Finite field in a of size 2^8
35
Basis matrix:
36
[ 1 0 a^4 + a a^7 + a^6 + a^5 + a^4 + a^2 a^3 + a^2 + a]
37
[ 0 1 a^7 + a^4 + a^2 a^5 + a^4 + a^2 + 1 a^7 + a^5 + a^3 + a + 1]
38
39
-----
40
41
OK, now here's an example to get a sense of speed:
42
43
sage: k,a = GF(2^8).objgen()
44
sage: A = MatrixSpace(k,50,50)([k.random_element() for _ in range(50*50)])
45
sage: B = pari(A)
46
sage: time v= B.matker()
47
Time: CPU 0.69 s, Wall: 0.79 s
48
49
With your NTL interface code it did a 100x100 matrix in 0.08 seconds.
50
So NTL appears to currently be *vastly* faster than PARI
51
(even in C library mode) for
52
working over finite field extensions. This is good information
53
to have.
54
55
--------------
56
57
From Martin Albrecht:
58
I've implemented the NTL GF2E matrices and did some initial benchmarks:
59
60
NTL:
61
62
sage: ntl.set_GF2E_modulus(ntl.GF2X([1,1,0,1,1,0,0,0,1]))
63
sage: m=ntl.mat_GF2E(100,100,[ ntl.GF2E_random() for i in xrange(100*100) ])
64
sage: time m.echelon_form()
65
_10 = 100
66
Time: CPU 0.08 s, Wall: 0.09 s
67
68
69