Define, optimize, and evaluate mathematical expressions involving multi-dimensional arrays efficiently