Loïc Grenié on Mon, 18 Nov 2024 15:13:07 +0100


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

Re: Is there a function for sum of square matrix antidiagonal like "trace()" for main diagonal?


On Mon 18 Nov 2024 at 13:27, Hermann wrote:
I used below code, is there something shorter?

   assert(isprime(trace(ps)));
   assert(isprime(vecsum([ps[i,#ps+1-i]|i<-[1..#ps]])));

     You can define a function atr (antitrace):

atr(M)=my(j=#M+1);sum(i=1,#M,j--;M[i,j]);

       Hope this helps,

             Loïc