1. A method for operating a compiler, the method comprising: utilizing a computer to perform: scanning program code to identify a first algebraic expression specified by the program code, wherein the first algebraic expression includes two or more mutually-compatible binary operations and three or more input operands, wherein the three or more input operands include two or more scalar operands and one or more array operands; and operating on the first algebraic expression to obtain a final algebraic expression by: (a) computing a rank vector for each of the three or more input operands, wherein the rank vector for any given one of the three or more input operands includes a first component that is based on an invariance rank of the input operand and a second component that is based on a dimension of the input operand, and (b) performing transformations on selected subexpressions of the first algebraic expression, wherein the transformations include one or more commute transformations and one or more associate transformations, wherein each of the commute transformations exchanges input operands of a corresponding one of the two or more binary operations to order the input operands according to an ordering of possible states of the rank vector, wherein the ordering of possible states gives precedence to the first component over the second component; wherein the final algebraic expression specifies an order of execution for the two or more binary operations such that the three or more input operands are combined in an order that agrees with the ordering of possible states of the rank vector.