Sketch language optimization algorithm