See Rosen for general algorithm
See Rosen for general algorithm