Opened 3 years ago
Closed 3 years ago
#27601 closed enhancement (fixed)
Customizing simplifications in symbolic calculus on manifolds
Reported by: | egourgoulhon | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | sage-8.8 |
Component: | geometry | Keywords: | simplification, symbolic, manifolds |
Cc: | tscrim | Merged in: | |
Authors: | Eric Gourgoulhon | Reviewers: | Travis Scrimshaw |
Report Upstream: | N/A | Work issues: | |
Branch: | 80b87d8 (Commits, GitHub, GitLab) | Commit: | 80b87d805f31ca9095f24ce834c20579de099ded |
Dependencies: | Stopgaps: |
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).
Change History (5)
comment:1 Changed 3 years ago by
- Branch set to public/manifolds/custom_simplifications
- Commit set to 80b87d805f31ca9095f24ce834c20579de099ded
comment:2 Changed 3 years ago by
- Cc tscrim added
- Status changed from new to needs_review
comment:3 Changed 3 years ago by
- Reviewers set to Travis Scrimshaw
- Status changed from needs_review to positive_review
LGTM.
comment:4 Changed 3 years ago by
Thank you for the review!
comment:5 Changed 3 years ago by
- Branch changed from public/manifolds/custom_simplifications to 80b87d805f31ca9095f24ce834c20579de099ded
- Resolution set to fixed
- Status changed from positive_review to closed
New commits:
Add possibility to custom the simplification algorithm in coordinate calculus on manifolds
Minor cleaning (flake8) in the code for customized simplifications on manifolds