1 | initial version |
Unfortunately, it does not seem possible to add the codomain of a symbolic function in the list of assumptions known to Sage. However, you may define a Python function to perform the required simplifications; for instance:
def simplify_real(expr, *real_expr):
r"""
- ``expr``: symbolic expression to be simplified
- ``real_expr``: list of subexpressions of ``expr`` assumed to be real
"""
for s in real_expr:
expr = expr.subs({real_part(s): s,
imag_part(s): 0,
conjugate(s): s})
return expr.simplify_full()
You may use it as follows:
sage: t = var('t')
sage: a = function('a')
sage: y = I*a(t) + real_part(I+a(t)) + a(t).conjugate()
sage: simplify_real(y, a(t))
(I + 2)*a(t)
You may have more than one subexpression assumed to be real in the list of inputs:
sage: z = conjugate(a(t) + function('b')(t)) + imag_part(function('c')(t))
sage: simplify_real(z, a(t), b(t))
a(t) + b(t) + imagpart(c(t))
sage: simplify_real(z, a(t), b(t), c(t))
a(t) + b(t)
2 | No.2 Revision |
Unfortunately, it does not seem possible to add the codomain of a symbolic function in the list of assumptions known to Sage. However, you may define a Python function to perform the required simplifications; for instance:
def simplify_real(expr, *real_expr):
r"""
- ``expr``: symbolic expression to be simplified
- ``real_expr``: list of subexpressions of ``expr`` assumed to be real
"""
for s in real_expr:
expr = expr.subs({real_part(s): s,
imag_part(s): 0,
conjugate(s): s})
return expr.simplify_full()
You may use it as follows:
sage: t = var('t')
sage: a = function('a')
sage: y = I*a(t) + real_part(I+a(t)) + a(t).conjugate()
sage: simplify_real(y, a(t))
(I + 2)*a(t)
You may have more than one subexpression assumed to be real in the list of inputs:
sage: z = conjugate(a(t) + function('b')(t)) + imag_part(function('c')(t))
sage: simplify_real(z, a(t), b(t))
a(t) + b(t) + imagpart(c(t))
sage: simplify_real(z, a(t), b(t), c(t))
a(t) + b(t)
3 | No.3 Revision |
Unfortunately, it does not seem possible to add the codomain of a symbolic function in to the list of assumptions known to Sage. However, as a workaround, you may define a Python function to perform the required simplifications; for instance:
def simplify_real(expr, *real_expr):
r"""
- ``expr``: symbolic expression to be simplified
- ``real_expr``: list of subexpressions of ``expr`` assumed to be real
"""
for s in real_expr:
expr = expr.subs({real_part(s): s,
imag_part(s): 0,
conjugate(s): s})
return expr.simplify_full()
You may use it as follows:
sage: t = var('t')
sage: a = function('a')
sage: y = I*a(t) + real_part(I+a(t)) + a(t).conjugate()
sage: simplify_real(y, a(t))
(I + 2)*a(t)
You may have more than one subexpression assumed to be real in the list of inputs:
sage: z = conjugate(a(t) + function('b')(t)) + imag_part(function('c')(t))
sage: simplify_real(z, a(t), b(t))
a(t) + b(t) + imagpart(c(t))
sage: simplify_real(z, a(t), b(t), c(t))
a(t) + b(t)