Is there some flag to let the Fortran compiler pre calculate a math expression before compiling it?. I have to write expressions that contain many small 4x4 matrix multiplications. The thing is, most of the elements of these small 4x4 matrices are zero, so in terms of performance it's better to actually do the multiplication manually and write down the resulting expression, that way you eliminate the unnecessary multiplications by 0. Doing this is error prone, and I thought that compiler optimizations like -O3 would take care of this but they don't. I read about tools like symPy and matlab that let you write expressions, manipulate and simplify them and generate the code for Fortran or C, but if there is some compiler flag for this would be even better.
I don't believe there is a compiler flag in Fortran for this, but there are Fortran libraries for sparse matrices that may give you some optimizations. This StackOverflow post discusses a BLAS library for use with them, although it seems like the user had some difficulty.