Bill Allombert on Thu, 07 Dec 2023 20:09:35 +0100


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

Re: norml2() with variables in vector?


On Thu, Dec 07, 2023 at 07:54:14PM +0100, hermann@stamm-wilbrandt.de wrote:
> There is no constant term in "v[1]^2+v[2]^2+v[3]^2" below.
> How can it be that "norml2(v)" reports 417 ?
> 
> $ gp -q
> ? G=[-102, -107, 93; 22, 23, -20; 1, 1, -1];
> ? v=G^-1*[a,b,c]~
> [3*a + (14*b - c), -2*a + (-9*b - 6*c), a + (5*b - 8*c)]~
> ? v[1]^2+v[2]^2+v[3]^2
> 14*a^2 + (130*b + 2*c)*a + (302*b^2 + 101*c^2)
> ? norml2(v)
> 417

You are victim of a strange PARI behaviour which is that some functions
are fully recursive so

norml2([a,b,c]) = norml2(a) + norml2(b) + norml2(c)
etc.

? (3^2+14^2+1^2)+(2^2+9^2+6^2)+(1^2+5^2+8^2)
%4 = 417

You probably want v~*v
? v~*v
%5 = 14*a^2+(130*b+2*c)*a+(302*b^2+101*c^2)

Cheers,
Bill