Skip to content

Do not check for a zero result in arithmetics of coordinate functions and scalar fields #22859

@egourgoulhon

Description

@egourgoulhon

In the arithmetics of symbolic coordinate functions (methods sage.manifolds.coord_func_symb.CoordFunctionSymb._add_, _sub_, _mul_ and _div_), the final result (res below) is checked against zero as follows:

if res == 0:
    return self.parent().zero()

Now, for complicated expressions, such a check involves Maxima and is very slow. Moreover, there is no real benefit in representing all the zero functions by a unique object (the zero of the function ring). This ticket proposes therefore to remove the check.
It also removes a similar check in the arithmetics of scalar fields (class sage.manifolds.scalarfield.ScalarField).

The gain in performance is quite significant:
sage -tp --long src/sage/manifolds/ (with 8 cores) yields

Total time for all tests: 245.9 seconds
    cpu time: 1570.5 seconds
    cumulative wall time: 1689.6 seconds

instead of

Total time for all tests: 300.5 seconds
    cpu time: 1757.9 seconds
    cumulative wall time: 1876.0 seconds

On computationally demanding worksheets, like the Kerr spacetime one, the gain is even greater: the total time for running all cells is 386 s, instead of 610 s.

Besides, the method is_zero of class CoordFunctionSymb is replaced by a method __bool__ (with an alias to __nonzero__ for Python 2 compatibility), leaving the method is_zero only in the base class sage.structure.element.Element.

CC: @tscrim

Component: geometry

Keywords: coordinate function, scalar field

Author: Eric Gourgoulhon

Branch/Commit: 94e8c68

Reviewer: Travis Scrimshaw

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions