hermann on Sun, 08 Oct 2023 17:43:31 +0200


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

Re: efficient foursquare() and/or threesquare1m4() functions


On 2023-10-08 12:30, Bill Allombert wrote:
Yes, you need to read the documentation...

? Q=[41,50,1;50,61,0;1,0,62]
%1 = [41,50,1;50,61,0;1,0,62]
? M=qfgaussred(Q)
%2 = [41,50/41,1/41;0,1/41,-50;0,0,1]
? D=matrix(#M,#M,i,j,if(i==j,M[i,j]))
%3 = [41,0,0;0,1/41,0;0,0,1]
? R=matrix(#M,#M,i,j,if(i==j,1,M[i,j]))
%4 = [1,50/41,1/41;0,1,-50;0,0,1]
? R~*D*R == Q
%5 = 1
? R~^-1*Q*R^-1
%6 = [41,0,0;0,1/41,0;0,0,1]

The documentation [??qfgaussred] examples were on binary
qudratic forms only.

Thanks for demonstrating use of qfgaussred() for ternary
quadratic form. Setting

? N=R^-1
%13 =
[1 -50/41 -61]

[0      1  50]

[0      0   1]

?

now gives what I asked for, a diagonal matrix:

? N~*Q*N
%14 =
[41    0 0]

[ 0 1/41 0]

[ 0    0 1]

?

But it is not the matrix I wanted to get [a diagonal
matrix with permutation of the elements {1,5,6}
becausse 1^2+5^2+6^2==62].


I found a brute force way to determine the matrix M.
There are 6 permutations, I tried to get matdiagonal([1,5,6]) first.

I started with Q, and set M with 9 variables and determine S:

? Q=[41,50,1;50,61,0;1,0,62];
? M=[a,b,c;d,e,f;g,h,i];
? S=M~*Q*M;
?

S is symmetric:

? S==S~
1
?

These are the non-diagonal entries:

? S[1,2]
(41*b + (50*e + h))*a + ((50*d + g)*b + (61*e*d + 62*h*g))
? S[1,3]
(41*c + (50*f + i))*a + ((50*d + g)*c + (61*f*d + 62*i*g))
? S[2,3]
(41*c + (50*f + i))*b + ((50*e + h)*c + (61*f*e + 62*i*h))
?

These are the diagonal entries, that I want to be 1, 5 and 6:

? S[1,1]
41*a^2 + (100*d + 2*g)*a + (61*d^2 + 62*g^2)
? S[2,2]
41*b^2 + (100*e + 2*h)*b + (61*e^2 + 62*h^2)
? S[3,3]
41*c^2 + (100*f + 2*i)*c + (61*f^2 + 62*i^2)
?


Now I use wolframscript "Solve[]" to determine solutions
(all Raspberry computers have free Mathematica license):

In[1]:= R=Solve[{(41*b + (50*e + h))*a + ((50*d + g)*b + (61*e*d + 62*h*g))==0,
(41*c + (50*f + i))*a + ((50*d + g)*c + (61*f*d + 62*i*g))==0,
(41*c + (50*f + i))*b + ((50*e + h)*c + (61*f*e + 62*i*h))==0,
41*a^2 + (100*d + 2*g)*a + (61*d^2 + 62*g^2)==1,
41*b^2 + (100*e + 2*h)*b + (61*e^2 + 62*h^2)==5,
41*c^2 + (100*f + 2*i)*c + (61*f^2 + 62*i^2)==6},
{a,b,c,d,e,f,g,h,i}]
...
...
In[2]:= Length[R]

Out[2]= 56

In[3]:= R[[56]]
62 5 61 3 Out[3]= {a -> Sqrt[3782], b -> 0, c -> 0, d -> -50 Sqrt[--], e -> Sqrt[--], f -> 0, g -> -Sqrt[--], h -> 0, i -> Sqrt[--]} 61 61 62 31
In[4]:=


Now back to PARI/GP:

? M=[sqrt(3782),0,0;-50*sqrt(62/61),sqrt(5/61),0;-sqrt(61/62),0,sqrt(3/31)]

[61.497967446087191801041303617898363588 0 0]

[-50.408170037776386722165002965490461957 0.28629916715693410895608268247437548775 0]

[-0.99190270074334180324260167125642521916 0 0.31108550841912758050838809830427945755]

? M~*Q*M

[0.99999999999999999999999999999999995693 0.E-35 0.E-37]

[0.E-35 5.0000000000000000000000000000000000000 0]

[0.E-37 0 6.0000000000000000000000000000000000000]

?


I will try the other 5 permutations of {1,5,6} on whether a
"nicer" matrix M is available ...


Regards,

Hermann.