1. In a compiler, a method of computing the shortest path expression in a loop having a plurality of expressions, comprising: identifying candidate expressions from the plurality of loop expressions; partitioning candidate expressions into sets, including a first set; computing a cost matrix as a function of the sets; finding one or more paths through the cost matrix; detecting cycles in the paths; if there are cycles in the paths, breaking the cycles; generating one or more shortest path expressions as a function of the paths; and replacing one or more of the expressions in the loop with the shortest path expressions.