Karim Belabas on Wed, 03 Oct 2018 18:12:09 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: vector version of gcdext?


* J E Cremona [2018-10-03 17:48]:
> The function gcd() allows 2 inputs as in gcd(2,3) or a vector of inputs as
> in gcd([6,10,15]),  but the extended version only allows the first form.
> It would not be hard to write an extended vector version (and I can of
> course write my own) -- feature request?

See ??mathnf ("For convenience, M is allowed to be a t_VEC...")

> One way to do this is using Smith Normal Form, i.e. matsnf.  But there is a
> problem when the input are polynomials:
> 
> 
>  H = [6,10,15]
> %3 = [6, 10, 15]
> ? matsnf(Mat(H),3)
> %4 = [Mat(1), [-5, -30, -14; 3, 15, 7; 0, 2, 1], Mat([0, 0, 1])]

? [v,U] = mathnf(H, 1);
? v
%3 = 
[1]

? U
%4 = 
[ 0 -5  1]

[-3  0  1]

[ 2  2 -1]

? H*U
%5 = [0, 0, 1]

> ? H = [x,x+1,x+2]
> %7 = [x, x + 1, x + 2]
> ? matsnf(Mat(H),3)
>   ***   at top-level: matsnf(Mat(H),3)
>   ***                 ^----------------
>   *** matsnf: inconsistent dimensions in gsmithall.
>   ***   Break loop: type 'break' to go back to GP prompt
> 
> I used the flag value 3=1+2 to get the multiplier matrices and allow
> polynomials

Flag 2 is obsolete: don't use it.Exact same construction works for
both integer and polynomials...

? [v,U] = mathnf(H, 1);
? v
%9 = 
[1]

? U
%10 = 
[-x - 2 -x - 1 -1]

[ x + 2      x  1]

[    -1      0  0]

? H*U
%11 = [0, 0, 1]

> , but (as is documented) this is only implemented for square
> matrices in the polynomial case.  That means that I can pad the matrix
> using n-1 rows of zeros and extract the answer, but I would prefer not to
> have to do this.

Using mathnf instead of matsnf should do the trick.

Cheers,

    K.B.
--
Karim Belabas, IMB (UMR 5251)  Tel: (+33) (0)5 40 00 26 17
Universite de Bordeaux         Fax: (+33) (0)5 40 00 21 23
351, cours de la Liberation    http://www.math.u-bordeaux.fr/~kbelabas/
F-33405 Talence (France)       http://pari.math.u-bordeaux.fr/  [PARI/GP]
`