# how to define the codomain of a symbolic function

Hi, I'm perfoming some basic differential calculations in General Relativity.

I created a function a(t), where t is one of the chart coordinates:

a = function('a')(t)

I do not want to define how it depends on t since I'm calculating stuff like Cristoffel symbols, Einstein equations, etc and I want to keep the resulting formulas independent from the functional behaviour of a(t).

This function appears to be a complex one (i.e. I see the bar over it sometimes - complex conjugate). This is boring since the calculations does not simplify by themselves.

Is there a way to "assume" that the codomain of the function are the Real Numbers? It would be great also to specify only a range, like (0,+\infty).

Thanks

edit retag close merge delete

Sort by » oldest newest most voted

Unfortunately, it does not seem possible to add the codomain of a symbolic function 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)

more

Thank you very much!

I found useful especially because I can use it also for derivatives: simplify_real(expression, a(t),diff(a(t),t))

I wrote a similar simple function for assuming that a function is positive: in this way in the expressions a lot of factor simplifies. I suppose that also this assumption cannot be added in Sage.

In your opinion can thees functions be implemented as a method for expressions in a future release?

( 2018-01-14 04:34:03 -0500 )edit