Ask Your Question
2

how to define the codomain of a symbolic function

asked 2017-12-29 23:15:57 +0100

scollovati gravatar image

updated 2017-12-30 11:36:19 +0100

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 flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2018-01-04 14:32:40 +0100

eric_g gravatar image

updated 2018-01-04 15:27:42 +0100

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)
edit flag offensive delete link more

Comments

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?

scollovati gravatar imagescollovati ( 2018-01-14 11:34:03 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-12-29 23:15:57 +0100

Seen: 462 times

Last updated: Jan 04 '18