Opened 5 years ago

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

Reported by: Owned by: egourgoulhon major sage-8.0 geometry coordinate function, scalar field, manifold tscrim Eric Gourgoulhon N/A public/manifolds/coord_function_arithm-22859 0960e64cbaf86ba418716fed4e41384c948c4eed

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

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.

### comment:1 Changed 5 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:

 ​0960e64 Do not check for a zero result in arithmetics of coordinate functions and scalar fields

### comment:2 Changed 5 years ago by egourgoulhon

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