function to compute term P of U,V,W (Table II)
function P(i,l,a,b,R_1,R_lm1) {
    
    var ri1, rim1, ri0, ret;
    ri1 = R_1[i+1][1+1];
    rim1 = R_1[i+1][-1+1];
    ri0 = R_1[i+1][0+1];
    
    if (b==-l) {
        ret = ri1*R_lm1[a+l-1][0] + rim1*R_lm1[a+l-1][2*l-2];
    }
    else {
        if (b==l) ret = ri1*R_lm1[a+l-1][2*l-2] - rim1*R_lm1[a+l-1][0];
        else ret = ri0*R_lm1[a+l-1][b+l-1];
    }
    return ret;
}