First time here? Check out the FAQ!

Ask Your Question
2

how to define the codomain of a symbolic function

asked 7 years ago

scollovati gravatar image

updated 7 years ago

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

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
3

answered 7 years ago

eric_g gravatar image

updated 7 years ago

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)
Preview: (hide)
link

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 ( 7 years ago )

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: 7 years ago

Seen: 513 times

Last updated: Jan 04 '18