Opened 3 years ago

Closed 3 years ago

# Customizing simplifications in symbolic calculus on manifolds

Reported by: Owned by: egourgoulhon major sage-8.8 geometry simplification, symbolic, manifolds tscrim Eric Gourgoulhon Travis Scrimshaw N/A 80b87d8 80b87d805f31ca9095f24ce834c20579de099ded

### Description

Currently the end user has no direct control of the simplification algorithm used in coordinate calculus on manifolds. For instance, if the manifold is real and the coordinate calculus method is Sage's default symbolic engine (SR), the simplifying function is simplify_chain_real. This function is quite exhaustive (similar to `simplify_full()`) but since it is invoked at each elementary step of a calculation, the computation can be quite slow. In some cases, it would be desirable to use a lighter simplifying function. See for instance this ask.sagemath question.

This ticket proposes some interface for passing any user-defined simplifying function. As an example, let us perform the addition of two scalar fields on a 2-dimensional real smooth manifold:

```sage: M = Manifold(2, 'M')
sage: X.<x,y> = M.chart()
sage: f = M.scalar_field(cos(x)^2)
sage: g = M.scalar_field(sin(x)^2)
sage: s = f + g
```

Thanks to the use of `simplify_chain_real` in the `_add_` operator, the result is automatically simplified:

```sage: s.display()
M --> R
(x, y) |--> 1
```

With the code indroduce in this ticket, one can replace `simplify_chain_real` by any function, for instance Sage's `simplify`:

```sage: M.set_simplify_function(simplify)
sage: s = f + g
sage: s.display()
M --> R
(x, y) |--> cos(x)^2 + sin(x)^2
```

As we can see, the capabilities of `simplify` are quite limited! Let us replace it by a user-defined function:

```sage: def simpl(expr):
....:     return expr.simplify_trig()
....:
sage: M.set_simplify_function(simpl)
sage: s = f + g
sage: s.display()
M --> R
(x, y) |--> 1
```

For more flexibility, it is possible to provide a different simplifying function for each chart on the manifold, via

```sage: X.calculcus_method().set_simplify_function(simpl)
```

Besides, this ticket improves the documentation and functionalities of the class CalculusMethod, which governs the various symbolic backends available on manifolds (SR and SymPy at the moment).

### comment:1 Changed 3 years ago by egourgoulhon

• Branch set to public/manifolds/custom_simplifications
• Commit set to 80b87d805f31ca9095f24ce834c20579de099ded

New commits:

 ​9b16e40 `Add possibility to custom the simplification algorithm in coordinate calculus on manifolds` ​80b87d8 `Minor cleaning (flake8) in the code for customized simplifications on manifolds`

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

• Cc tscrim added
• Status changed from new to needs_review

### comment:3 Changed 3 years ago by tscrim

• Reviewers set to Travis Scrimshaw
• Status changed from needs_review to positive_review

LGTM.

### comment:4 Changed 3 years ago by egourgoulhon

Thank you for the review!

### comment:5 Changed 3 years ago by vbraun

• Branch changed from public/manifolds/custom_simplifications to 80b87d805f31ca9095f24ce834c20579de099ded
• Resolution set to fixed
• Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.