Repository: sagemath/sage

Issue:
cartan subtype depends on interval
### Steps To Reproduce

```sage
B = crystals.Tableaux(['A',5],shape=[3,2,1])

cta = B.cartan_type().subtype([1,2,3]) # has expected class <class 'sage.combinat.root_system.type_A.CartanType'>
ctb = B.cartan_type().subtype([2,3]) # has different class <class 'sage.combinat.root_system.type_relabel.CartanType_finite_with_superclass'>

type(cta),type(ctb),type(B.cartan_type()) # check
```

### Expected Behavior

Expected type(cta),type(ctb),type(B.cartan_type()) to agree

### Actual Behavior

The type of the subtype depends on the (sub) interval (of the Dynkin diagram) defining it.

### Additional Information

_No response_

### Environment

```markdown
- **OS**: 13.4.1 (c)
- **Sage Version**: 10.0
```


### Checklist

- [X] I have searched the existing issues for a bug report that matches the one I want to file, without success.
- [X] I have read the documentation and troubleshoot guide


Discussion:
@tscrim submitted

Resolving patch:
diff --git a/src/sage/combinat/root_system/cartan_matrix.py b/src/sage/combinat/root_system/cartan_matrix.py
--- a/src/sage/combinat/root_system/cartan_matrix.py
+++ b/src/sage/combinat/root_system/cartan_matrix.py
@@ -589,7 +589,7 @@ def subtype(self, index_set):
         """
         ind = self.index_set()
         I = [ind.index(i) for i in index_set]
-        return CartanMatrix(self.matrix_from_rows_and_columns(I, I), index_set)
+        return CartanMatrix(self.matrix_from_rows_and_columns(I, I), index_set=index_set)
 
     def rank(self):
         r"""
@@ -1135,13 +1135,39 @@ def find_cartan_type_from_matrix(CM):
         ['C', 3] relabelled by {1: 0, 2: 1, 3: 2}
         sage: CM = CartanMatrix([[2,-1,-2], [-1,2,-1], [-2,-1,2]])
         sage: find_cartan_type_from_matrix(CM)
+
+    TESTS:
+
+    Check that :issue:`35987` is fixed::
+
+        sage: from sage.combinat.root_system.cartan_matrix import find_cartan_type_from_matrix
+        sage: cm = CartanMatrix(['A',7]).subtype([2,3,5])
+        sage: find_cartan_type_from_matrix(cm)
+        A2xA1 relabelled by {1: 2, 2: 3, 3: 5}
+
+        sage: cm = CartanMatrix(['B',10,1]).subtype([0,1,2,3,5,6,8,9,10])
+        sage: ct = find_cartan_type_from_matrix(cm); ct
+        D4xB3xA2 relabelled by {1: 0, 2: 2, 3: 1, 4: 3, 5: 8, 6: 9, 7: 10, 8: 5, 9: 6}
+        sage: ct.dynkin_diagram()
+            O 3
+            |
+            |
+        O---O---O
+        0   2   1
+        O---O=>=O
+        8   9   10
+        O---O
+        5   6
+        D4xB3xA2 relabelled by {1: 0, 2: 2, 3: 1, 4: 3, 5: 8, 6: 9, 7: 10, 8: 5, 9: 6}
     """
     types = []
+    relabel = []
     for S in CM.dynkin_diagram().connected_components_subgraphs():
         S = DiGraph(S) # We need a simple digraph here
         n = S.num_verts()
         # Build the list to test based upon rank
         if n == 1:
+            relabel.append({1: S.vertices()[0]})
             types.append(CartanType(['A', 1]))
             continue
 
@@ -1178,7 +1204,8 @@ def find_cartan_type_from_matrix(CM):
             T = DiGraph(ct.dynkin_diagram()) # We need a simple digraph here
             iso, match = T.is_isomorphic(S, certificate=True, edge_labels=True)
             if iso:
-                types.append(ct.relabel(match))
+                types.append(ct)
+                relabel.append(match)
                 found = True
                 break
 
@@ -1189,10 +1216,20 @@ def find_cartan_type_from_matrix(CM):
             T = DiGraph(ct.dynkin_diagram()) # We need a simple digraph here
             iso, match = T.is_isomorphic(S, certificate=True, edge_labels=True)
             if iso:
-                types.append(ct.relabel(match))
+                types.append(ct)
+                relabel.append(match)
                 found = True
                 break
         if not found:
             return None
 
-    return CartanType(types)
+    if len(types) == 1:
+        # Irreducible, so just relabel
+        return CartanType(types[0]).relabel(relabel[0])
+    ct = CartanType(types)
+    # ct._index_relabelling is a dict ``(ind, j): i``, where i is an index of
+    #   ``ct``, ``ind`` is the position in the list of types, and j is the
+    #   corresponding index of the type number ``ind``.
+    # In other words, the j-th node of ``types[ind]`` is the i-th node of ``ct``.
+    mapping = {i: relabel[d[0]][d[1]] for d, i in ct._index_relabelling.items()}
+    return ct.relabel(mapping)


Test patch: