Replace Ideal by P.ideal.
Replace RR by QQbar, or by K where K.<sqrt3> = NumberField(x^2 - 3); in the latter case also replace sqrt(3) by sqrt3.
You may also want to do list(B) if B gets big.