Skip to content

Simplifications in calculus on manifolds with derivatives of symbolic functions #24199

@egourgoulhon

Description

@egourgoulhon

The function sage.manifolds.utilities.simplify_sqrt_real, which is involved in calculus on manifolds (see here), does not simplify sqrt's as soon as the expression contains some derivative of a symbolic function:

sage: from sage.manifolds.utilities import simplify_sqrt_real
sage: f = function('f')
sage: assume(x<1)
sage: simplify_sqrt_real(sqrt(x^2-2*x+1))  # OK
-x + 1
sage: simplify_sqrt_real(sqrt(x^2-2*x+1) * diff(f(x), x))  # nothing done
sqrt(x^2 - 2*x + 1)*diff(f(x), x)

The same limitation holds for derivatives denoted by D[...] instead of diff:

sage: y = var('y'); s = sqrt(x^2-2*x+1) * diff(f(x), x).subs(x=y^2); s
sqrt(x^2 - 2*x + 1)*D[0](f)(y^2)
sage: simplify_sqrt_real(s)  # nothing done
sqrt(x^2 - 2*x + 1)*D[0](f)(y^2)

Similarly, the function sage.manifolds.utilities.simplify_abs_trig does not perform any simplification when a derivative is present:

sage: from sage.manifolds.utilities import simplify_abs_trig
sage: assume(x>0); assumptions()
[x < 1, x > 0]
sage: simplify_abs_trig(abs(sin(x)))  # OK
sin(x)
sage: simplify_abs_trig(abs(sin(x)) * diff(f(x), x))  # nothing done
abs(sin(x))*diff(f(x), x)

The code introduced in this ticket repairs this. We have now, with the same assumptions as above:

sage: simplify_sqrt_real(sqrt(x^2-2*x+1) * diff(f(x), x))
-(x - 1)*diff(f(x), x)
sage: simplify_sqrt_real(s)
-(x - 1)*D[0](f)(y^2)
sage: simplify_abs_trig(abs(sin(x)) * diff(f(x), x))
sin(x)*diff(f(x), x)

In addition, simplify_abs_trig is now capable to treat abs(cos(...)):

sage: simplify_abs_trig(abs(cos(x))) # recall that 0 < x < 1 < pi/2
cos(x)
sage: simplify_abs_trig(abs(cos(x+2)))
-cos(x + 2)
sage: simplify_abs_trig(abs(cos(x+2)) * diff(f(x), x))
-cos(x + 2)*diff(f(x), x)

CC: @man74cio @rll2021 @tscrim

Component: geometry

Keywords: manifold calculus

Author: Eric Gourgoulhon

Branch/Commit: public/manifolds/better_simplifications-24199 @ 6eb6bde

Reviewer: Travis Scrimshaw

Issue created by migration from https://trac.sagemath.org/ticket/24199

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions