Reduction to canonical form