Bill Allombert on Sun, 11 Feb 2024 13:31:32 +0100


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

Re: GP cross product?


On Sun, Feb 11, 2024 at 01:44:24AM +0100, hermann@stamm-wilbrandt.de wrote:
> I searched for "cross" and "vector product" in GP user's guide and found
> nothing.
> I searched mailing lists unsuccessfully as well.

Yes, the cross product almost never occur in number theory.

> Then by Wikipedia definition perhaps simpler:
> 
> ?
> cross=(a,b)->[a[2]*b[3]-a[3]*b[2],a[3]*b[1]-a[1]*b[3],a[1]*b[2]-a[2]*b[1]];

Yes this is probably the best.
 
> First I came up with this:
> 
> ? cross=(a,b)->{m=matdet(Mat([[i,j,k]~,a~,b~]));[polcoef(m,1,i),polcoef(m,1,j),polcoef(m,1,k)]};

Just for the record, never use polynomial unknowns for linear algebra.
Instead just compute the values over a basis.
Here you have a linear map
(i,j,k) -> matdet(Mat([[i,j,k]~,a~,b~])) = C[1]*i+C[2]*j+C[3]*k
Just compute the values over the basis (1,0,0) (0,1,0), (0,0,1).

cross(a,b)=[matdet(Mat([[1,0,0]~,a~,b~])),matdet(Mat([[0,1,0]~,a~,b~])),matdet(Mat([[0,0,1]~,a~,b~]))];


a=[a1,a2,a3];b=[b1,b2,b3];
cross(a,b)=[matdet(Mat([[1,0,0]~,a~,b~])),matdet(Mat([[0,1,0]~,a~,b~])),matdet(Mat([[0,0,1]~,a~,b~]))];
cross1(a,b)={m=matdet(Mat([[i,j,k]~,a~,b~]));[polcoef(m,1,i),polcoef(m,1,j),polcoef(m,1,k)]};
cross2(a,b)=[a[2]*b[3]-a[3]*b[2],a[3]*b[1]-a[1]*b[3],a[1]*b[2]-a[2]*b[1]];
cross(a,b)
cross1(a,b)
cross2(a,b)
%5 = [b3*a2-b2*a3,-b3*a1+b1*a3,b2*a1-b1*a2]
%6 = [b3*a2-b2*a3,-b3*a1+b1*a3,b2*a1-b1*a2]
%7 = [b3*a2-b2*a3,-b3*a1+b1*a3,b2*a1-b1*a2]

Good!

Cheers,
Bill