fundamentals of sage

41 views
Skip to first unread message

Martin R

unread,
May 6, 2026, 4:50:59 AM (14 days ago) May 6
to sage-devel
Dear all,

I am trying to accumulate better understanding of some of the fundamentals of sage, such as the coercion system, parents, categories, etc.

Slowly working my way, I found the following in `parent.pyx`:
```
        EXAMPLES::

            sage: S3 = AlternatingGroup(3)                                              # needs sage.groups
            sage: G = SL(3, QQ)                                                         # needs sage.groups
            sage: p = S3[2]; p.matrix()                                                 # needs sage.groups
            [0 0 1]
            [1 0 0]
            [0 1 0]

        In general one cannot mix matrices and permutations::

            sage: # needs sage.groups
            sage: G(p)
            Traceback (most recent call last):
            ...
            TypeError: unable to convert (1,3,2) to a rational
            sage: phi = S3.hom(lambda p: G(p.matrix()), codomain=G)
            sage: phi(p)
            [0 0 1]
            [1 0 0]
            [0 1 0]
            sage: S3._unset_coercions_used()
            sage: S3.register_embedding(phi)

        By :issue:`14711`, coerce maps should be copied when using outside of
        the coercion system::

            sage: phi = copy(S3.coerce_embedding()); phi                                # needs sage.groups
            Generic morphism:
              From: Alternating group of order 3!/2 as a permutation group
              To:   Special Linear Group of degree 3 over Rational Field
            sage: phi(p)                                                                # needs sage.groups
            [0 0 1]
            [1 0 0]
            [0 1 0]

        This does not work since matrix groups are still old-style
        parents (see :issue:`14014`)::

            sage: G(p)                          # not implemented                       # needs sage.groups

        Though one can have a permutation act on the rows of a matrix::

            sage: G(1) * p                                                              # needs sage.groups
            [0 0 1]
            [1 0 0]
            [0 1 0]
```
If I understand correctly, matrix groups are *not* old-style parents anymore, can somebody confirm?
```
sage: type(G).mro()
[<class 'sage.groups.matrix_gps.linear.LinearMatrixGroup_generic_with_category'>,
 <class 'sage.groups.matrix_gps.linear.LinearMatrixGroup_generic'>,
 <class 'sage.groups.matrix_gps.named_group.NamedMatrixGroup_generic'>,
 <class 'sage.structure.unique_representation.CachedRepresentation'>,
 <class 'sage.structure.unique_representation.WithPicklingByInitArgs'>,
 <class 'sage.groups.matrix_gps.matrix_group.MatrixGroup_generic'>,
 <class 'sage.groups.matrix_gps.matrix_group.MatrixGroup_base'>,
 <class 'sage.groups.group.Group'>,
 <class 'sage.structure.parent.Parent'>,
 <class 'sage.structure.category_object.CategoryObject'>,
 <class 'sage.structure.sage_object.SageObject'>,
 <class 'sage.categories.category.JoinCategory.parent_class'>,
 <class 'sage.categories.groups.Groups.parent_class'>,
 <class 'sage.categories.monoids.Monoids.parent_class'>,
 <class 'sage.categories.semigroups.Semigroups.parent_class'>,
 <class 'sage.categories.magmas.Magmas.Unital.Inverse.parent_class'>,
 <class 'sage.categories.magmas.Magmas.Unital.parent_class'>,
 <class 'sage.categories.magmas.Magmas.parent_class'>,
 <class 'sage.categories.sets_cat.Sets.Infinite.parent_class'>,
 <class 'sage.categories.sets_cat.Sets.parent_class'>,
 <class 'sage.categories.sets_with_partial_maps.SetsWithPartialMaps.parent_class'>,
 <class 'sage.categories.objects.Objects.parent_class'>,
 <class 'object'>]
```
The comment beginning with "This does not work" was (essentially) added in https://github.com/sagemath/sage/issues/5891 (it was reworded later).

Do I understand correctly that this *should* work?

Many thanks,

Martin
Reply all
Reply to author
Forward
0 new messages