Opened 4 years ago

Last modified 4 years ago

#22859 closed enhancement

Do not check for a zero result in arithmetics of coordinate functions and scalar fields — at Version 2

Reported by: egourgoulhon Owned by:
Priority: major Milestone: sage-8.0
Component: geometry Keywords: coordinate function, scalar field, manifold
Cc: tscrim Merged in:
Authors: Eric Gourgoulhon Reviewers:
Report Upstream: N/A Work issues:
Branch: public/manifolds/coord_function_arithm-22859 (Commits, GitHub, GitLab) Commit: 0960e64cbaf86ba418716fed4e41384c948c4eed
Dependencies: Stopgaps:

Status badges

Description (last modified by 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 great benefit in representing all the zero functions by a unique object (the zero of the parent). This tickets 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.

Change History (2)

comment:1 Changed 4 years ago by egourgoulhon

  • Branch set to public/manifolds/coord_function_arithm-22859
  • Commit set to 0960e64cbaf86ba418716fed4e41384c948c4eed
  • Status changed from new to needs_review

New commits:

0960e64Do not check for a zero result in arithmetics of coordinate functions and scalar fields

comment:2 Changed 4 years ago by egourgoulhon

  • Description modified (diff)
Note: See TracTickets for help on using tickets.