Here is the output of the code below.
Case 1 - original code
10.4887875965689
3.32958130339336
1.39111866114059e-12 + 6.95559330500737e-6*I
-1.23801031100746e-21 - 3.80973535432766e-16*I
0.00139260822082924
4.17782466328442e-24
Case 2 - use N(Q), N(R)
10.4887875965689
3.32958130339336
1.39111866114058e-12 + 6.95559330500736e-6*I
-1.23801031100746e-21 - 3.80973535432766e-16*I
4.83802782246652e-11
1.45140834701674e-31
Case 3 - do not use factor()
10.4887875965689
3.32958130339336
1.39111866114058e-12 + 6.95559330500736e-6*I
-1.23801031100746e-21 - 3.80973535432766e-16*I
4.83802782246651e-11
1.45140834701674e-31
Case 3 - use N(Q), N(R), and do not use factor()
10.4887875965689
3.32958130339336
1.39111866114058e-12 + 6.95559330500736e-6*I
-1.23801031100746e-21 - 3.80973535432766e-16*I
4.83802782246651e-11
1.45140834701674e-31
I expect the results for X2 and Y2 (last two lines of each case) to be (nearly) the same in all cases. However, the results in case 1 are widely different from those in cases 2-4. Am I doing something wrong or is this indeed a bug in factor()? I am using Sage 9.3.
var('x, y', domain='positive')
var('p, q, r', domain='positive')
P = 1
Q = 3/174465461165747500*pi*sqrt(92821652156334811582567480952850314403/10*pi^2
/(224*pi + 45*sqrt(448*pi + 2025) + 2025)
+ 98489794142024498175862287197250000*pi*sqrt(448*pi + 2025)
/(224*pi + 45*sqrt(448*pi + 2025) + 2025)
+ 7713517620898636162808584411766250000*pi
/(224*pi + 45*sqrt(448*pi + 2025) + 2025)
+ 659225266976959904108326638192187500
*sqrt(448*pi + 2025)/(224*pi + 45*sqrt(448*pi + 2025) + 2025)
+ 29665137013963195684874698718648437500
/(224*pi + 45*sqrt(448*pi + 2025) + 2025))
R = 9/280*sqrt(448*pi + 2025) + 81/56
### Case 1 ###
eqn_1 = Q + 1/25000*I*sqrt(3/10)*pi*p*y == 1/62500*(6000*pi + 3*I*pi*p - 30000000000*I*pi/p)*x
eqn_2 = I*sqrt(3/10)*pi*p*x == (4000*pi + I*pi*p + 25000*R - 10000000000*I*pi/p)*y
S = solve([eqn_1, eqn_2], x, y, solution_dict=True)[0]
X = S[x]
Y = S[y]
X2 = (X.real()^2 + X.imag()^2).factor()
Y2 = (Y.real()^2 + Y.imag()^2).factor()
print("\nCase 1 - original code")
print(N(Q))
print(N(R))
print(N(X(p=P)))
print(N(Y(p=P)))
print(N(X2(p=P)))
print(N(Y2(p=P)))
### Case 2 ###
Q = N(Q)
R = N(R)
eqn_1 = Q + 1/25000*I*sqrt(3/10)*pi*p*y == 1/62500*(6000*pi + 3*I*pi*p - 30000000000*I*pi/p)*x
eqn_2 = I*sqrt(3/10)*pi*p*x == (4000*pi + I*pi*p + 25000*R - 10000000000*I*pi/p)*y
S = solve([eqn_1, eqn_2], x, y, solution_dict=True)[0]
X = S[x]
Y = S[y]
X2 = (X.real()^2 + X.imag()^2).factor()
Y2 = (Y.real()^2 + Y.imag()^2).factor()
print("\nCase 2 - use N(Q), N(R)")
print(N(Q))
print(N(R))
print(N(X(p=P)))
print(N(Y(p=P)))
print(N(X2(p=P)))
print(N(Y2(p=P)))
### Case 3 ###
eqn_1 = Q + 1/25000*I*sqrt(3/10)*pi*p*y == 1/62500*(6000*pi + 3*I*pi*p - 30000000000*I*pi/p)*x
eqn_2 = I*sqrt(3/10)*pi*p*x == (4000*pi + I*pi*p + 25000*R - 10000000000*I*pi/p)*y
S = solve([eqn_1, eqn_2], x, y, solution_dict=True)[0]
X = S[x]
Y = S[y]
X2 = X.real()^2 + X.imag()^2
Y2 = Y.real()^2 + Y.imag()^2
print("\nCase 3 - do not use factor()")
print(N(Q))
print(N(R))
print(N(X(p=P)))
print(N(Y(p=P)))
print(N(X2(p=P)))
print(N(Y2(p=P)))
### Case 3 ###
Q = N(Q)
R = N(R)
eqn_1 = Q + 1/25000*I*sqrt(3/10)*pi*p*y == 1/62500*(6000*pi + 3*I*pi*p - 30000000000*I*pi/p)*x
eqn_2 = I*sqrt(3/10)*pi*p*x == (4000*pi + I*pi*p + 25000*R - 10000000000*I*pi/p)*y
S = solve([eqn_1, eqn_2], x, y, solution_dict=True)[0]
X = S[x]
Y = S[y]
X2 = X.real()^2 + X.imag()^2
Y2 = Y.real()^2 + Y.imag()^2
print("\nCase 3 - use N(Q), N(R), and do not use factor()")
print(N(Q))
print(N(R))
print(N(X(p=P)))
print(N(Y(p=P)))
print(N(X2(p=P)))
print(N(Y2(p=P)))