# Calculus method control¶

The class CalculusMethod governs the calculus methods (symbolic and numerical) to be used for coordinate computations on manifolds.

AUTHORS:

• Marco Mancini, (2017): initial version
class sage.manifolds.calculus_method.CalculusMethod(current=None, base_field_type='real')

Control of calculus methods used on coordinate charts of manifolds.

This class stores the possible calculus methods and permits to select some basic operations working on them. For the moment, only two calculus methods are implemented:

• Sage’s symbolic engine (Pynac/Maxima), implemented via the symbolic ring SR
• SymPy engine, denoted sympy hereafter

INPUT:

• current – (default: None) current symbolic method
• base_field_type – (default: 'real') base field type of the manifold (cf. base_field_type())

EXAMPLES:

sage: from sage.manifolds.calculus_method import CalculusMethod
sage: calc_meth = CalculusMethod()


In the display, the current method is pointed out by $$*$$:

sage: calc_meth
Possible calculus methods:
- SR (*) (default)
- sympy


The current method is changed by set():

sage: calc_meth.set('sympy')
sage: calc_meth
Possible calculus methods:
- SR (default)
- sympy (*)
sage: calc_meth.reset()
sage: calc_meth
Possible calculus methods:
- SR (*) (default)
- sympy

is_trivial_zero(expression, method=None)

Check if an expression is trivially equal to zero without any simplification.

INPUT:

• expression – expression
• method – (default: None) string defining the calculus method to use; if None the current calculus method of self is used.

OUTPUT:

• True is expression is trivially zero, False elsewhere.

EXAMPLES:

sage: from sage.manifolds.calculus_method import CalculusMethod
sage: calc_meth = CalculusMethod(base_field_type='real')
sage: f = sin(x) - sin(x)
sage: calc_meth.is_trivial_zero(f)
True
sage: calc_meth.is_trivial_zero(f._sympy_(), method='sympy')
True

sage: f = sin(x)^2 + cos(x)^2 - 1
sage: calc_meth.is_trivial_zero(f)
False
sage: calc_meth.is_trivial_zero(f._sympy_(), method='sympy')
False

reset()

Set the current symbolic method to default one.

EXAMPLES:

sage: from sage.manifolds.calculus_method import CalculusMethod
sage: calc_meth = CalculusMethod(base_field_type='complex')
sage: calc_meth.set('sympy')
sage: calc_meth
Possible calculus methods:
- SR (default)
- sympy (*)
sage: calc_meth.reset()
sage: calc_meth
Possible calculus methods:
- SR (*) (default)
- sympy

set(method)

Set the current calculus method.

• method – string defining the calculus method

EXAMPLES:

sage: from sage.manifolds.calculus_method import CalculusMethod
sage: calc_meth = CalculusMethod(base_field_type='complex')
sage: calc_meth.set('sympy')
sage: calc_meth
Possible calculus methods:
- SR (default)
- sympy (*)
sage: calc_meth.reset()

simplify(expression, method=None)

Apply some simplification chain to a given symbolic expression.

INPUT:

• expression – symbolic expression to simplify
• method – (default: None) string defining the calculus method to use; must be one of
• 'SR': Sage’s default symbolic engine (Symbolic Ring)
• 'sympy': SymPy
• None: the current calculus method of self is used.

EXAMPLES:

sage: M = Manifold(2, 'M', field='complex', structure='topological')
sage: X = M.chart('x y')
sage: f = x^2+sin(x)^2+cos(x)^2
sage: from sage.manifolds.calculus_method import CalculusMethod
sage: calc_meth = CalculusMethod(base_field_type='real')
sage: calc_meth.simplify(f)
x^2 + 1


Methods cannot be mixed:

sage: calc_meth.set('sympy')
sage: calc_meth.simplify(f)
Traceback (most recent call last):
...
AttributeError: 'sage.symbolic.expression.Expression' object has no attribute 'combsimp'


In the present case, one should either transform f to a SymPy object:

sage: calc_meth.simplify(f._sympy_())
x**2 + 1


or force the calculus method to be 'SR':

sage: calc_meth.simplify(f, method='SR')
x^2 + 1