Opened 5 months ago

Closed 4 months ago

#31883 closed defect (fixed)

Refine category of ScalarField

Reported by: mkoeppe Owned by:
Priority: major Milestone: sage-9.4
Component: manifolds Keywords:
Cc: egourgoulhon, tscrim, gh-mjungmath Merged in:
Authors: Matthias Koeppe Reviewers: Travis Scrimshaw
Report Upstream: N/A Work issues:
Branch: cd3ca79 (Commits, GitHub, GitLab) Commit: cd3ca79ab94f48321cc9aa3f0b34c1b3db4e405e
Dependencies: Stopgaps:

Status badges

Description

A ScalarField on a topological manifold is supposed to be a continuous map -- but this is not reflected by the category of its parent.

sage: M = Manifold(2, 'R^2', structure='topological')
sage: c_cart.<x,y> = M.chart()
sage: r_squared = M.scalar_field(x^2+y^2)
sage: r_squared.parent().category()
Category of commutative algebras over Symbolic Ring
sage: r_squared.codomain()
AttributeError: 'ScalarFieldAlgebra_with_category.element_class' object has no attribute 'codomain'

Change History (12)

comment:1 Changed 5 months ago by mkoeppe

Unfortunately, trying to make ScalarField a subclass of Map leads to:

---> 50 class ScalarField(CommutativeAlgebraElement, ModuleElementWithMutability, Map):
     51     r"""
     52     Scalar field on a topological manifold.

TypeError: multiple bases have instance lay-out conflict

comment:2 Changed 5 months ago by mkoeppe

  • Branch set to u/mkoeppe/refine_category_of_scalarfield

comment:3 Changed 5 months ago by mkoeppe

  • Authors set to Matthias Koeppe
  • Commit set to 1942c714237d5f2996587bfeda80404b57720696
  • Status changed from new to needs_review

Anyway, here is a simple solution


New commits:

1942c71ScalarField.codomain: New, put scalar fields in category of continuous maps

comment:4 Changed 5 months ago by tscrim

  • Reviewers set to Travis Scrimshaw

Green bot => positive review.

comment:5 Changed 5 months ago by tscrim

sage -t --long --random-seed=0 src/sage/graphs/graph.py  # 1 doctest failed
sage -t --long --random-seed=0 src/sage/manifolds/differentiable/scalarfield_algebra.py  # 2 doctests failed
sage -t --long --random-seed=0 src/doc/en/thematic_tutorials/vector_calculus/vector_calc_advanced.rst  # 1 doctest failed
sage -t --long --random-seed=0 src/doc/en/thematic_tutorials/vector_calculus/vector_calc_plane.rst  # 1 doctest failed

The one in graph.py doesn't seem like an error related to this ticket, but the others are trivial. Please make the changes and check that graph.py is indeed unrelated. Once done, you can set a positive review.

comment:6 Changed 5 months ago by git

  • Commit changed from 1942c714237d5f2996587bfeda80404b57720696 to cd3ca79ab94f48321cc9aa3f0b34c1b3db4e405e

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

cd3ca79Update doctests for refined category of ScalarField

comment:7 Changed 5 months ago by mkoeppe

The failing doctest in graph.py is unrelated and is fixed by #31848

comment:8 Changed 5 months ago by tscrim

  • Status changed from needs_review to positive_review

Thanks.

comment:9 Changed 5 months ago by mkoeppe

Thank you!

comment:10 Changed 5 months ago by egourgoulhon

I agree with the code added in this ticket, but let me seize the opportunity to point out some current inconsistency in the manifold set up, which is due to the lack of a proper real field in Sage (cf. #24456):

  1. the base field of a real manifold is RR
  2. the base ring of the algebra of scalar fields on a manifold is SR

Of course, from a pure mathematical side, 1 and 2 should be identical.

The basic reason for 1 is RR being the simplest proxy for the genuine real field, albeit all (symbolic) computations on manifolds have nothing to do with 53 bits of precision...

The basic reason for 2 is to naturally allow for algebra operations like a*f, where a is a symbolic variable and f a scalar field.

If #24456 converges some day, both 1 and 2 should be set to the real field object that will emerge from it. Meanwhile, we have

sage: M = Manifold(2, 'M')
sage: CM = M.scalar_field_algebra()
sage: M.base_field()
Real Field with 53 bits of precision
sage: CM.base_ring()
Symbolic Ring

With the codomain() method introduced in this ticket, we have in addition

sage: X.<x,y> = M.chart() 
sage: f = M.scalar_field(x^2)
sage: f.codomain() is f.domain().base_field()
True

which is nice, but

sage: f.codomain() is f.parent().base_ring()
False

Moreover, for images of scalar fields, we have

sage: p = M((pi, 0))
sage: f(p)
pi^2
sage: f(p) in f.codomain()
True

but this holds only because pi^2 can be converted to an element of RR. Otherwise, the test fails:

sage: a = var('a', domain='real')
sage: p = M((a, 0))
sage: f(p) in f.codomain()
False

f(p) not lying in f.codomain() is certainly something we do not want, but this is currently a consequence of the inconsistency 1 <-> 2 mentioned above. The latter could be removed by making SR the base field of manifolds. But then a real manifold and a complex one would appear as having the same base field (according to base_field()).

Finally, it's worth to stress that in practice, the inconsistency 1 <-> 2 is a rather mild one: to my knowledge, it has never triggered any error nor yield any false result in actual computations on manifolds (apart from the trivial CM.base_ring() is M.base_field() being false).

comment:11 Changed 5 months ago by mkoeppe

Thanks a lot for sharing these insights!

comment:12 Changed 4 months ago by vbraun

  • Branch changed from u/mkoeppe/refine_category_of_scalarfield to cd3ca79ab94f48321cc9aa3f0b34c1b3db4e405e
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.