Forcing Symbolic Variables to Always be Real
I am having a problem, I am trying to do algebra with a function of multiple variables, but Sage is assuming the variables could be complex numbers, which I do not want to do. I have a minimal working example that shows the problem. I am using the method discussed at this Google thread on the issue. I actually want to use the commented out equation, but I can't even get the behaviour right for a purely real (at least conceptually) function.
R, r, L, omega, k, s = var('R r L omega k s')
assume(R, 'real')
assume(r, 'real')
assume(L, 'real')
assume(omega, 'real')
assume(k, 'real')
assume(s, 'real')
R.conjugate().simplify()
r.conjugate().simplify()
L.conjugate().simplify()
omega.conjugate().simplify()
k.conjugate().simplify()
s.conjugate().simplify()
#Z(R,r,L,k,omega,s) = R + I * omega * L + ((s * omega**2 * L**2 * k**2) * (r - I * omega * L)) / (r**2 + omega**2 * s **2 * L**2)
Z(s,L) = s * L
show(Z.diff(s))
Z
show(Z)
(s, L) |--> L*s
(s, L) |--> -(imag_part(L)*D[0](imag_part)(s) - real_part(L)*D[0](real_part)(s))/abs(L*s) + (imag_part(L)*imag_part(s) - real_part(L)*real_part(s))*L/(abs(L*s)*conjugate(L)*conjugate(s))
The derivative of the argument of s*L
with respect to s
should be zero by definition, since both s
and L
are purely real variables. Why is Sage assuming the following two things: that real variables all of a sudden become complex, and that s
and L
are related to each other. I want them to be real independent real variables. Always. How do I 'enforce' this?