Array optimizations

Very frequently I use array operations such as:

  • maxval(abs(a-b)) for finding maximum error between a and b.
  • sqrt(dot_product(array,array)) or even sqrt(sum(x**2)) to compute a norm. There is now a norm2 intrinsic for this.

I think the compiler optimizer should be able to recognize such common expressions and generate optimal code for those.

Implementation: this could be an ASR pass that recognized such expressions and replaces them with internal functions. Alternatively, once we have some general framework for simplifying such array operations (perhaps using Mathematics of Arrays), it could handle such a case.