#include "pari.h" GEN matexp(GEN x,long prec) { long lx=lg(x),i,k,n, ltop = avma; GEN y,r,s,p1,p2; /* check that x is a square matrix */ if (typ(x) != t_MAT) err(typeer,"matexp"); if (lx == 1) return cgetg(1, t_MAT); if (lx != lg(x[1])) err(talker,"not a square matrix"); /* convert x to real or complex of real and compute its L2 norm */ s = gzero; r = cgetr(prec+1); affsr(1,r); x = gmul(r,x); for (i=1; i= -BITS_IN_LONG*(prec-1)) { k++; p2 = gdivgs(gmul(p2,p1),k); r = gdivgs(gmul(s,r),k); y = gadd(y,p2); } /* now square back n times if necessary */ for (i=0; i 0) prec = (long)(d*pariK1+3); printf("input your matrix in GP format:\n"); x = matexp(lisGEN(stdin), prec); sor(x, 'g', d, 0); exit(0); }