From d8a903f649d4f7b0792345baafa18fd8b15b137d Mon Sep 17 00:00:00 2001 From: Vincent Delecroix Date: Tue, 7 Apr 2020 21:55:37 +0200 Subject: [PATCH 1/2] implement methods for ZabM_ker and ZabM_indexrank --- cypari2/gen.pyx | 56 ++++++++++++++++++++++++++++++++++++++++++++ cypari2/paridecl.pxd | 11 +++++++++ 2 files changed, 67 insertions(+) diff --git a/cypari2/gen.pyx b/cypari2/gen.pyx index c37fc18..458eec1 100644 --- a/cypari2/gen.pyx +++ b/cypari2/gen.pyx @@ -3213,6 +3213,62 @@ cdef class Gen(Gen_base): raise ValueError("%s is not a square modulo %s" % (self, n)) return new_gen(s) + def ZabM_ker(self, Gen P, long n): + r""" + Return an integral primitive basis of the kernel of this matrix. + + INPUT: + + - ``P`` - cyclotomic polynomial + + - ``n`` - order of the cyclotomic polynomial + + Examples: + + >>> from cypari2 import Pari + >>> pari = Pari() + + >>> x = pari('x') + >>> M = pari([[2*x + 5, x - 4], [-2*x^2 - 5*x, -x^2 + 4*x]]) + >>> M.ZabM_ker(pari.polcyclo(5), 5) + [x; 1] + """ + cdef GEN s + sig_on() + s = ZabM_ker(self.g, P.g, n) + return new_gen(s) + + def ZabM_indexrank(self, Gen P, long n): + r""" + Return a vector with two t_VECSMALL components giving the rank profile of this + matrix. + + Inefficient (but correct) when the matrix does not have almost full column rank. + + INPUT: + + - ``P`` - cyclotomic polynomial + + - ``n`` - order of the cyclotomic polynomial + + Examples: + + >>> from cypari2 import Pari + >>> pari = Pari() + + >>> x = pari('x') + >>> M = pari([[2*x + 5, x - 4], [-2*x^2 - 5*x, -x^2 + 4*x]]) + >>> M.ZabM_indexrank(pari.polcyclo(5), 5) + [Vecsmall([1]), Vecsmall([1])] + >>> M = pari([[2*x + 5, x - 3], [-2*x^2 - 5*x, -x^2 + 4*x]]) + >>> M.ZabM_indexrank(pari.polcyclo(5), 5) + [Vecsmall([1, 2]), Vecsmall([1, 2])] + """ + cdef GEN s + sig_on() + s = ZabM_indexrank(self.g, P.g, n) + return new_gen(s) + def ellan(self, long n, python_ints=False): """ Return the first `n` Fourier coefficients of the modular diff --git a/cypari2/paridecl.pxd b/cypari2/paridecl.pxd index b996e89..6b8a8e3 100644 --- a/cypari2/paridecl.pxd +++ b/cypari2/paridecl.pxd @@ -771,16 +771,19 @@ cdef extern from *: # PARI headers already included by types.pxd GEN F2m_F2c_mul(GEN x, GEN y) GEN F2m_mul(GEN x, GEN y) GEN F2m_powu(GEN x, ulong n) + GEN Flc_Flv_mul(GEN x, GEN y, ulong p) GEN Flc_to_mod(GEN z, ulong pp) GEN Flm_Fl_add(GEN x, ulong y, ulong p) GEN Flm_Fl_mul(GEN y, ulong x, ulong p) void Flm_Fl_mul_inplace(GEN y, ulong x, ulong p) GEN Flm_Flc_mul(GEN x, GEN y, ulong p) GEN Flm_Flc_mul_pre(GEN x, GEN y, ulong p, ulong pi) + GEN Flm_Flc_mul_pre_Flx(GEN x, GEN y, ulong p, ulong pi, long sv) GEN Flm_add(GEN x, GEN y, ulong p) GEN Flm_center(GEN z, ulong p, ulong ps2) GEN Flm_mul(GEN x, GEN y, ulong p) GEN Flm_neg(GEN y, ulong p) + GEN Flm_powers(GEN x, ulong n, ulong p) GEN Flm_powu(GEN x, ulong n, ulong p) GEN Flm_sub(GEN x, GEN y, ulong p) GEN Flm_to_mod(GEN z, ulong pp) @@ -834,6 +837,11 @@ cdef extern from *: # PARI headers already included by types.pxd GEN FpV_to_mod(GEN z, GEN p) GEN FpVV_to_mod(GEN z, GEN p) GEN FpX_to_mod(GEN z, GEN p) + GEN ZabM_ker(GEN M, GEN P, long n) + GEN ZabM_indexrank(GEN M, GEN P, long n) + GEN ZabM_inv(GEN M, GEN P, long n, GEN *pden) + GEN ZabM_inv_ratlift(GEN M, GEN P, long n, GEN *pden) + GEN ZabM_pseudoinv(GEN M, GEN P, long n, GEN *pv, GEN *den) GEN ZV_zMs_mul(GEN B, GEN M) GEN ZpMs_ZpCs_solve(GEN M, GEN B, long nbrow, GEN p, long e) GEN gen_FpM_Wiedemann(void *E, GEN (*f)(void*, GEN), GEN B, GEN p) @@ -843,6 +851,9 @@ cdef extern from *: # PARI headers already included by types.pxd GEN matid_Flm(long n) GEN matid_F2xqM(long n, GEN T) GEN matid_FlxqM(long n, GEN T, ulong p) + GEN random_Flv(long n, ulong p) + GEN random_FpC(long d, GEN p) + GEN random_FpV(long d, GEN p) GEN scalar_Flm(long s, long n) GEN zCs_to_ZC(GEN C, long nbrow) GEN zMs_to_ZM(GEN M, long nbrow) From 738381521974b75c29e69614b4ea6d6891c4a6d4 Mon Sep 17 00:00:00 2001 From: Vincent Delecroix Date: Wed, 8 Apr 2020 08:25:20 +0200 Subject: [PATCH 2/2] use ** and not ^ for powers --- cypari2/gen.pyx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cypari2/gen.pyx b/cypari2/gen.pyx index 458eec1..b61c2b9 100644 --- a/cypari2/gen.pyx +++ b/cypari2/gen.pyx @@ -3229,7 +3229,7 @@ cdef class Gen(Gen_base): >>> pari = Pari() >>> x = pari('x') - >>> M = pari([[2*x + 5, x - 4], [-2*x^2 - 5*x, -x^2 + 4*x]]) + >>> M = pari([[2*x + 5, x - 4], [-2*x**2 - 5*x, -x**2 + 4*x]]) >>> M.ZabM_ker(pari.polcyclo(5), 5) [x; 1] """ @@ -3257,10 +3257,10 @@ cdef class Gen(Gen_base): >>> pari = Pari() >>> x = pari('x') - >>> M = pari([[2*x + 5, x - 4], [-2*x^2 - 5*x, -x^2 + 4*x]]) + >>> M = pari([[2*x + 5, x - 4], [-2*x**2 - 5*x, -x**2 + 4*x]]) >>> M.ZabM_indexrank(pari.polcyclo(5), 5) [Vecsmall([1]), Vecsmall([1])] - >>> M = pari([[2*x + 5, x - 3], [-2*x^2 - 5*x, -x^2 + 4*x]]) + >>> M = pari([[2*x + 5, x - 3], [-2*x**2 - 5*x, -x**2 + 4*x]]) >>> M.ZabM_indexrank(pari.polcyclo(5), 5) [Vecsmall([1, 2]), Vecsmall([1, 2])] """