Opened 4 years ago

# Euclidean spaces and vector calculus — at Version 31

Reported by: Owned by: egourgoulhon major sage-8.3 geometry Euclidean space, vector calculus, gradient, divergence, curl, Laplacian tmonteil Eric Gourgoulhon Travis Scrimshaw N/A public/manifolds/Euclidean_spaces ab249df0d9dc01064ef68dd366941fe38e5a8e13 #24622, #24792

This ticket implements Euclidean spaces as Riemannian manifolds diffeomorphic to Rn and equipped with a flat metric, which defines the Euclidean dot product. Using the operators introduced in #24622, this provides the standard operators of vector calculus: dot product, norm, cross product, gradient, divergence, curl and Laplacian, along with the standard coordinate systems (Cartesian, spherical, cylindrical, etc.).

See this ask.sagemath question for a motivation, as well as this one.

The implementation is performed via the parent class `EuclideanSpace`, which inherits from `PseudoRiemannianManifold` (introduced in #24622). Two subclasses are devoted to specific cases:

• `EuclideanPlane` for n=2
• `Euclidean3dimSpace` for n=3

The user interface for constructing an Euclidean space relies on the `EuclideanSpace.__classcall_private__` to direct to the appropriate subclass.

The implementation through the manifold framework allows for an easy use of various coordinate systems, along with the related transformations. However, the user interface does not assume any knowledge of Riemannian geometry. In particular, no direct manipulation of the metric tensor is required.

A minimal example is

```sage: E.<x,y,z> = EuclideanSpace(3)
sage: v = E.vector_field(-y, x, 0)
sage: v.display()
-y e_x + x e_y
sage: v[:]
[-y, x, 0]
sage: w = v.curl()
sage: w.display()
2 e_z
sage: w[:]
[0, 0, 2]
```

The transformation to spherical coordinates:

```sage: spherical.<r,th,ph> = E.spherical_coordinates()
sage: spherical_frame = E.spherical_frame()  # orthonormal frame (e_r, e_th, e_ph)
sage: v.display(spherical_frame)
sqrt(x^2 + y^2) e_ph
sage: v.display(spherical_frame, spherical)
r*sin(th) e_ph
sage: v[spherical_frame, :, spherical]
[0, 0, r*sin(th)]
sage: w.display(spherical_frame, spherical)
2*cos(th) e_r - 2*sin(th) e_th
sage: w[spherical_frame, :, spherical]
[2*cos(th), -2*sin(th), 0]
```

More detailed examples are in the following Jupyter notebooks:

This work is part of the SageManifolds project, see #18528 for an overview.

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

• Description modified (diff)

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

• Description modified (diff)

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

• Cc tmonteil added

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

• Branch set to public/manifolds/Euclidean_spaces
• Commit set to 4bf802027ddd8178ab17efa692bda2d877e0f8d6

This is a first sketch (not ready yet).

Last 10 new commits:

 ​55f356c `Improve documentation of pseudo-Riemannian manifolds` ​0fc661a `Remove method set_metric and improve doc of pseudo-Riemannian manifolds` ​b4dddf7 `Add operators Laplacian, d'Alembertian and curl on pseudo-Riemannian manifolds` ​040b01c `Add dot product and cross product of vector fields` ​46b8f66 `Add norm of vector fields.` ​135af97 `Add method volume_form() to class PseudoRiemannianManifold` ​38e8fd3 `Add global functions grad, div, curl, etc. for vector/tensor operators on pseudo-Riemannian manifolds` ​8309fdd `Improve documentation for operators on pseudo-Riemannian manifolds` ​29fc5c8 `Merge branch 'public/manifolds/pseudoRiemannian' of git://trac.sagemath.org/sage into Sage 8.2.beta5` ​4bf8020 `First draft of Euclidean spaces as Riemannian manifolds`

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

• Dependencies changed from #24622 to #24622, #24792

#24792 introduces more flexibility in naming the elements of vector frames, for instance using `(e_x, e_y, e_z)` for a coordinate frame instead of `(d/dx, d/dy, d/dz)`. The current ticket will therefore be build on it for a better user interface.

### comment:6 Changed 4 years ago by git

• Commit changed from 4bf802027ddd8178ab17efa692bda2d877e0f8d6 to f24a5f96a25d12b75c9d98a1b6749513673b4faa

Branch pushed to git repo; I updated commit sha1. New commits:

 ​a527e8e `First draft adding more flexibility in symbols of free module bases and vector frames` ​2d43a23 `More refactoring in vector frames` ​0840d54 `More work on vector frames` ​01681b8 `Add documentation for new options of vector frames` ​f24a5f9 `Merge branch 'public/manifolds/Euclidean_spaces' of git://trac.sagemath.org/sage into public/manifolds/more_basis_flexibility (branch of #24792)`

### comment:7 Changed 4 years ago by git

• Commit changed from f24a5f96a25d12b75c9d98a1b6749513673b4faa to d9302b65668e7f62b54306c4e4c916c73c72dc31

Branch pushed to git repo; I updated commit sha1. New commits:

 ​d9302b6 `Add documentation and doctests for Euclidean spaces`

### comment:8 follow-ups: ↓ 9 ↓ 26 Changed 4 years ago by kcrisman

I wonder whether some of this (in terms of the div/grad/curl) could be exposed in the symbolic calculus places, at least with some well-placed and well-formed examples that would be understandable to someone teaching Calc III to engineers (in the US framework) who may not be a differential geometer.

### comment:9 in reply to: ↑ 8 Changed 4 years ago by egourgoulhon

I wonder whether some of this (in terms of the div/grad/curl) could be exposed in the symbolic calculus places, at least with some well-placed and well-formed examples that would be understandable to someone teaching Calc III to engineers (in the US framework) who may not be a differential geometer.

Indeed, the aim here is to provide some interface which does not require any knowledge of differential geometry on manifolds. The class `EuclideanSpaceGeneric` does inherit from `PseudoRiemannianManifold`, but the end user has not to know it if he is not interested by this aspect and prefers to focus on vector calculus. Regarding examples, I plan to prepare some Jupyter notebooks and will expose them here, when the ticket is ready for review. Already, you can have a glimpse of the div/grad/curl capabilities introduced in the dependency #24622 in this notebook.

### comment:10 follow-up: ↓ 11 Changed 4 years ago by kcrisman

That's great! The reason I brought it up is because folders like `sage/calculus` and `sage/symbolic` might benefit from some good examples that are easy to find.

Is there a way to use something like (say) `vector([x^2+y,y^2+z,z^2+x])` as "vector field" immediately, without much (or any) of the formalism necessary in that notebook? I think that is how most end users I've talked to about this issue would want it. See e.g. https://ask.sagemath.org/question/10104/gradient-divergence-curl-and-vector-products/ and ticket:3021 for one version already in Sage - maybe these should be combined somehow, if possible.

### comment:11 in reply to: ↑ 10 Changed 4 years ago by egourgoulhon

Is there a way to use something like (say) `vector([x^2+y,y^2+z,z^2+x])` as "vector field" immediately, without much (or any) of the formalism necessary in that notebook?

Yes, this is precisely the aim of the current ticket. The above notebook is still at the level of semi-Riemannian manifolds (i.e. it illustrates only ticket #24622), while the user interface of the current ticket will be much simpler. It should also provide an easy way to change from Cartesian coordinates to e.g. polar or cylindrical ones.

See e.g. https://ask.sagemath.org/question/10104/gradient-divergence-curl-and-vector-products/ and ticket:3021 for one version already in Sage - maybe these should be combined somehow, if possible.

Thanks for pointing this version; I was not aware of it.

### comment:12 Changed 4 years ago by git

• Commit changed from d9302b65668e7f62b54306c4e4c916c73c72dc31 to 56a1a4a37f60f8f61ba8da18ece1e281c6c07aa9

Branch pushed to git repo; I updated commit sha1. New commits:

 ​9ddc467 `Add method set_name to classes VectorFrame and CoFrame` ​82c37b4 `Cut long lines in src/sage/manifolds/differentiable/vectorframe.py` ​95b2736 `Merge branch 'public/manifolds/more_basis_flexibility' of git://trac.sagemath.org/sage into Euclidean (to get latest version of the dependency #24792)` ​56a1a4a `Add method vector_field to Euclidean spaces + internal changes regarding charts and frames`

### comment:13 Changed 4 years ago by git

• Commit changed from 56a1a4a37f60f8f61ba8da18ece1e281c6c07aa9 to 70a2a749c2d5c07a85182c0d51fdc9f16d050b01

Branch pushed to git repo; I updated commit sha1. New commits:

 ​799066b `List entries of VectorFrame processed by __classcall_private__` ​da06d12 `Small improvement in treatment of symbol attributes of free module bases` ​244c1f4 `Merge branch 'public/manifolds/more_basis_flexibility' into 'public/manifolds/Euclidean_spaces' to get the latest version of dependency #24792 in #24623.` ​70a2a74 `Vector fields on Euclidean spaces can be initialized from a vector of symbolic expressions`

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

• Description modified (diff)

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

Here is some status update: functionalities regarding the 2-dimensional case are almost complete, as you can see in this demo worksheet (any feedback is of course appreciated). The 3-dimensional case is under preparation. The generic n-dimensional case, with n=1 or n>=4 is ready, since only Cartesian coordinates will be introduced (by default) in this case.

Regarding a question raised in comment:10, it is now possible to construct a vector field on an Euclidean space from a `vector` of symbolic expressions like this:

```v = E.vector_field(vector([-y,x]))
```

where `E` is the underlying Euclidean space.

### comment:16 Changed 4 years ago by git

• Commit changed from 70a2a749c2d5c07a85182c0d51fdc9f16d050b01 to 6e9fce6b191d1d1fcf84153ea90478c444687703

Branch pushed to git repo; I updated commit sha1. New commits:

 ​18b63a6 `Differential operators are no longer imported in the global namespace by PseudoRiemannianManifold.__init__` ​8367232 `Merge branch 'public/manifolds/pseudoRiemannian' of git://trac.sagemath.org/sage into 'public/manifolds/Euclidean_spaces' to get the latest version of the dependency #24622 in #24623.` ​6e9fce6 `First draft of Euclidean 3-spaces, with the Cartesian, spherical and cylindrical coordinate systems`

### comment:17 Changed 4 years ago by git

• Commit changed from 6e9fce6b191d1d1fcf84153ea90478c444687703 to 825ba7831fc3774455fd23b4c3b78dee3ee1fa0c

Branch pushed to git repo; I updated commit sha1. New commits:

 ​825ba78 `Add doctests to Euclidean spaces`

### comment:18 Changed 4 years ago by git

• Commit changed from 825ba7831fc3774455fd23b4c3b78dee3ee1fa0c to 88f12ed85714bfa068c0a4e8f911681771ca4f20

Branch pushed to git repo; I updated commit sha1. New commits:

 ​185e438 `Improve documentation of pseudo-Riemannian manifolds` ​52b10ee `Merge branch 'public/manifolds/pseudoRiemannian' of git://trac.sagemath.org/sage into 'public/manifolds/Euclidean_spaces' to get the final version of the dependency #24622 in #24623.` ​88f12ed `Improve documentation of Euclidean spaces`

### comment:19 Changed 4 years ago by git

• Commit changed from 88f12ed85714bfa068c0a4e8f911681771ca4f20 to 371e05ee9f2d118c8f4b1d13376668a85b6fa639

Branch pushed to git repo; I updated commit sha1. New commits:

 ​371e05e `Improve treatment of changes of frames in Euclidean spaces + documentation added`

### comment:20 Changed 4 years ago by git

• Commit changed from 371e05ee9f2d118c8f4b1d13376668a85b6fa639 to 8a87f70a8efbf5e5f57f682459fe984a8df92338

Branch pushed to git repo; I updated commit sha1. New commits:

 ​8a87f70 `Add scalar triple product in Euclidean spaces`

### comment:21 Changed 4 years ago by git

• Commit changed from 8a87f70a8efbf5e5f57f682459fe984a8df92338 to dd1951f87df19bdab818ded912e38579ad8f2fc5

Branch pushed to git repo; I updated commit sha1. New commits:

 ​dd1951f `Improve documentation of Euclidean spaces, especially of vector operators`

### comment:22 Changed 4 years ago by git

• Commit changed from dd1951f87df19bdab818ded912e38579ad8f2fc5 to d8b748baf218baf6d35b767d358553619a9045cb

Branch pushed to git repo; I updated commit sha1. New commits:

 ​7c4a9a9 `Merge branch 'public/manifolds/Euclidean_spaces' of git://trac.sagemath.org/sage into Sage 8.2.beta8.` ​d8b748b `Add references to Euclidean spaces and vector calculus in the Reference Manual`

### comment:23 Changed 4 years ago by git

• Commit changed from d8b748baf218baf6d35b767d358553619a9045cb to de74bb734f9f531bb6d991b14af20e58e6ebd683

Branch pushed to git repo; I updated commit sha1. New commits:

 ​de74bb7 `Slight reorganization of the documentation of Euclidean spaces`

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

• Description modified (diff)

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

• Status changed from new to needs_review

The documentation has been completed in the above commits and new Jupyter notebook examples have been added. This is now ready for review.

### comment:26 in reply to: ↑ 8 Changed 4 years ago by egourgoulhon

I wonder whether some of this (in terms of the div/grad/curl) could be exposed in the symbolic calculus places, at least with some well-placed and well-formed examples that would be understandable to someone teaching Calc III to engineers (in the US framework) who may not be a differential geometer.

I have added an entry "Vector Calculus" to `src/doc/en/reference/calculus/index.rst`. I have also added some `SEEALSO` sections in the definitions of `curl` and `div` in `src/sage/modules/free_module_element.pyx`, as well as in the definition of `gradient` in `src/sage/symbolic/expression.pyx`.

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

• Description modified (diff)

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

• Description modified (diff)

### comment:29 Changed 4 years ago by git

• Commit changed from de74bb734f9f531bb6d991b14af20e58e6ebd683 to 3578e5f49d0f8ef92fca4b7cb5e1d818fa49a633

Branch pushed to git repo; I updated commit sha1. New commits:

 ​b821dac `Merge branch 'public/manifolds/Euclidean_spaces' of git://trac.sagemath.org/sage into public/manifolds/Euclidean_spaces` ​3578e5f `Fusing EuclideanSpace function with EuclideanSpaceGeneric plus other misc reviewer changes.`

### comment:30 Changed 4 years ago by git

• Commit changed from 3578e5f49d0f8ef92fca4b7cb5e1d818fa49a633 to ab249df0d9dc01064ef68dd366941fe38e5a8e13

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

 ​ab249df `Fusing EuclideanSpace function with EuclideanSpaceGeneric plus other misc reviewer changes.`

### comment:31 Changed 4 years ago by tscrim

• Description modified (diff)
• Reviewers set to Travis Scrimshaw

Okay, I have made my way through the code. Overall, it looks good.

I remove the function `EuclideanSpace` and just used the `__classcall_private__` mechanism (provided by `UniqueRepresentation`) to make the class `EuclideanSpace` (formerly `EuclideanSpaceGeneric`) the main entry point.

There is something very subtle happening as some of the doctest output for display names of `arctan2(y, x)` needed to be `arctan(y/x)`. I do not understand why nor could I see what was causing this. It is not a blocker issue, but it is an indication that something might not be working properly.

The rest of my changes were mostly cosmetic.

Note: See TracTickets for help on using tickets.