1 | initial version |
WorksForMe(TM) on Sagemath 9.3.beta5 :
sage: reset()
sage: version()
'SageMath version 9.3.beta5, Release Date: 2020-12-27'
sage: var('A, L, G, R, f, k, n, q, u, beta, gamma', domain="positive") # Shortcut
(A, L, G, R, f, k, n, q, u, beta, gamma)
sage: expr_complex = (I*R^2*f^3*k*q*A*u/ ((2*pi*L*R^2*G*f^4*k^2*q - 2*pi*L*R^2*G*f^4*q - 2*pi*L*R^2*beta^2*G*q + (2*I*pi*L*R^2*beta*gamma*q + 2*I*pi*L*R*(beta + q))*G*f^3 + 2*(pi*(beta^2 + 1)*L*R^2*q + pi*L*R*beta*gamma*q + pi*L*beta)*G*f^2+ (-2*I*pi*L*R^2*beta*gamma*q - 2*I*pi*(beta^2*q + beta)*L*R)*G*f)*n))
sage: R1=(expr_complex.real()^2+expr_complex.imag()^2).factor()
sage: R2=(sqrt(expr_complex.real()^2+expr_complex.imag()^2)^2).factor()
sage: bool(R1==R2)
True
sage: R3=((sqrt(expr_complex.real()^2+expr_complex.imag()^2).factor())^2).factor()
sage: bool(R1==R3)
True
sage: bool(R2==R3)
True
HTH,
2 | No.2 Revision |
WorksForMe(TM) on Sagemath 9.3.beta5 :
sage: reset()
sage: version()
'SageMath version 9.3.beta5, Release Date: 2020-12-27'
sage: var('A, L, G, R, f, k, n, q, u, beta, gamma', domain="positive") # Shortcut
(A, L, G, R, f, k, n, q, u, beta, gamma)
sage: expr_complex = (I*R^2*f^3*k*q*A*u/ ((2*pi*L*R^2*G*f^4*k^2*q - 2*pi*L*R^2*G*f^4*q - 2*pi*L*R^2*beta^2*G*q + (2*I*pi*L*R^2*beta*gamma*q + 2*I*pi*L*R*(beta + q))*G*f^3 + 2*(pi*(beta^2 + 1)*L*R^2*q + pi*L*R*beta*gamma*q + pi*L*beta)*G*f^2+ (-2*I*pi*L*R^2*beta*gamma*q - 2*I*pi*(beta^2*q + beta)*L*R)*G*f)*n))
sage: R1=(expr_complex.real()^2+expr_complex.imag()^2).factor()
sage: R2=(sqrt(expr_complex.real()^2+expr_complex.imag()^2)^2).factor()
sage: bool(R1==R2)
True
sage: R3=((sqrt(expr_complex.real()^2+expr_complex.imag()^2).factor())^2).factor()
sage: bool(R1==R3)
True
sage: bool(R2==R3)
True
HTH,
EDIT : The expressins are correct, but indeed, Sage
's default mechanism for substitutions faits to work on R3. Sympy
's subs
works :
sage: import sympy
sage: bool(sympy.sympify(R3).subs(f,2*beta)._sage_()==R1.subs(f=2*beta))
True
More troubling : mathematica
seems to faile somehow :
sage: bool(mathematica.Replace(R3,mathematica.Rule(f,2*beta)).sage()==R1.subs(f=2*beta))
False
And, indeed,
sage: bool(R3.subs(f=2*beta)==R1.subs(f=2*beta))
never returns.
This is now Trac#31137.