Skip to content

Conversation

@mantepse
Copy link
Contributor

@mantepse mantepse commented Sep 30, 2025

fix #40935 in tree related classes.

cf #40932

Should number_of_nodes also be an alias, or perhaps instead of n_nodes?
Should n_nodes_to_the_right, n_nodes_at_depth also be aliases?

Does this pollute the namespace too much?

@github-actions
Copy link

github-actions bot commented Sep 30, 2025

Documentation preview for this PR (built with commit 542ad45; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

@mantepse mantepse mentioned this pull request Oct 1, 2025
vbraun pushed a commit to vbraun/sage that referenced this pull request Oct 5, 2025
sagemathgh-40940: provide aliases for number_of_inversions and number_of_negative_ones
    
fix sagemath#40935 in ASM

as with sagemath#40939: we have to decide whether this does not pollute the name
space too much.
    
URL: sagemath#40940
Reported by: Martin Rubey
Reviewer(s): Frédéric Chapoton
vbraun pushed a commit to vbraun/sage that referenced this pull request Oct 5, 2025
sagemathgh-40941: provide alias number_of_longest_increasing_subsequences
    
fix sagemath#40935 in permutation

as with sagemath#40939: we have to decide whether this does not pollute the name
space too much.
    
URL: sagemath#40941
Reported by: Martin Rubey
Reviewer(s): Frédéric Chapoton
vbraun pushed a commit to vbraun/sage that referenced this pull request Oct 5, 2025
sagemathgh-40942: provide an alias number_of_relations
    
fix sagemath#40935 in posets

as with sagemath#40939: we have to decide whether this does not pollute the name
space too much.
    
URL: sagemath#40942
Reported by: Martin Rubey
Reviewer(s): Frédéric Chapoton
vbraun pushed a commit to vbraun/sage that referenced this pull request Oct 5, 2025
sagemathgh-40943: provide alias number_of_connected_components
    
fix sagemath#40935 for `connected_components`

as with sagemath#40939: we have to decide whether this does not pollute the name
space too much.
    
URL: sagemath#40943
Reported by: Martin Rubey
Reviewer(s): David Coudert
vbraun pushed a commit to vbraun/sage that referenced this pull request Oct 5, 2025
sagemathgh-40951: add methods for biconnected components
    
This PR do the following:
- add method `number_of_biconnected_components` to follow the proposal
of sagemath#40939
- add method `biconnected_components`
- move method `is_biconnected` from `graph.py` to `connectivity.pyx` and
expose it in `generic_graph.pyx`

The addition of method `biconnected_component_containing_vertex` is more
involved and deserves its own PR. Indeed, a cut vertex belongs to
multiple biconnected components.


### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [x] I have created tests covering the changes.
- [x] I have updated the documentation and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
    
URL: sagemath#40951
Reported by: David Coudert
Reviewer(s): Martin Rubey
vbraun pushed a commit to vbraun/sage that referenced this pull request Oct 5, 2025
sagemathgh-40940: provide aliases for number_of_inversions and number_of_negative_ones
    
fix sagemath#40935 in ASM

as with sagemath#40939: we have to decide whether this does not pollute the name
space too much.
    
URL: sagemath#40940
Reported by: Martin Rubey
Reviewer(s): Frédéric Chapoton
vbraun pushed a commit to vbraun/sage that referenced this pull request Oct 5, 2025
sagemathgh-40941: provide alias number_of_longest_increasing_subsequences
    
fix sagemath#40935 in permutation

as with sagemath#40939: we have to decide whether this does not pollute the name
space too much.
    
URL: sagemath#40941
Reported by: Martin Rubey
Reviewer(s): Frédéric Chapoton
vbraun pushed a commit to vbraun/sage that referenced this pull request Oct 5, 2025
sagemathgh-40942: provide an alias number_of_relations
    
fix sagemath#40935 in posets

as with sagemath#40939: we have to decide whether this does not pollute the name
space too much.
    
URL: sagemath#40942
Reported by: Martin Rubey
Reviewer(s): Frédéric Chapoton
vbraun pushed a commit to vbraun/sage that referenced this pull request Oct 5, 2025
sagemathgh-40943: provide alias number_of_connected_components
    
fix sagemath#40935 for `connected_components`

as with sagemath#40939: we have to decide whether this does not pollute the name
space too much.
    
URL: sagemath#40943
Reported by: Martin Rubey
Reviewer(s): David Coudert
vbraun pushed a commit to vbraun/sage that referenced this pull request Oct 5, 2025
sagemathgh-40951: add methods for biconnected components
    
This PR do the following:
- add method `number_of_biconnected_components` to follow the proposal
of sagemath#40939
- add method `biconnected_components`
- move method `is_biconnected` from `graph.py` to `connectivity.pyx` and
expose it in `generic_graph.pyx`

The addition of method `biconnected_component_containing_vertex` is more
involved and deserves its own PR. Indeed, a cut vertex belongs to
multiple biconnected components.


### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [x] I have created tests covering the changes.
- [x] I have updated the documentation and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
    
URL: sagemath#40951
Reported by: David Coudert
Reviewer(s): Martin Rubey
@mantepse
Copy link
Contributor Author

mantepse commented Oct 7, 2025

This is the last ticket concerning the transition to n_xxx or number_of_xxx. It would be good to finish this before the next release, for consistency.

@fchapoton
Copy link
Contributor

I am not happy with these changes. They make the methods less consistent than they were.

@mantepse
Copy link
Contributor Author

mantepse commented Oct 7, 2025

Let me also note the following idea (I think I asked about it already once, but I cannot find the place anymore). We can hide aliases from tab-completion (or rather: produce aliases hidden from tab-completion) as follows:

class AlternatingSignMatrix(...):
    ...
    def __init__(self, parent, asm):
        ...
        self._matrix = asm
        self.__setattr__('number_negative_ones', self.number_of_negative_ones)
        Element.__init__(self, parent)
  
    def __dir__(self):
        return [f for f in super().__dir__() if f != "number_negative_ones"]

I am quite sure that we could also make this more automatic by having a class decorator or something similar. Do you see any downsides, @fchapoton?

@mantepse
Copy link
Contributor Author

I am not happy with these changes. They make the methods less consistent than they were.

Sorry, I overlooked your comment. Could you provide an alternative? I think that we have n_xxx or number_of_xxx now everywhere, except here, don't we?

@mantepse
Copy link
Contributor Author

ping?

@fchapoton
Copy link
Contributor

I would prefer, for local consistency, to have "n_nodes_etc` for all these methods.

@mantepse
Copy link
Contributor Author

Would you also be OK with number_of_etc for all of them? This would be more consistent with the general scheme in combinat, and also with the fact that these are methods that actually have to do a computation, in contrast to, for example, Graph.n_vertices.

@fchapoton
Copy link
Contributor

as you wish

@mantepse
Copy link
Contributor Author

@fchapoton, I switched to number_of_nodes, this is more consistent with the rest of combinat. I think it would be good to get this (or an alternative) into the next release, because it is almost a universal convention (with some exceptions like nrows, ngens, nvars, ndigits, nbits, ncusps) that users can follow now.

@mantepse
Copy link
Contributor Author

ping?

Copy link
Contributor

@dcoudert dcoudert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

vbraun pushed a commit to vbraun/sage that referenced this pull request Nov 10, 2025
sagemathgh-40939: n_nodes and number_of_nodes_xxx in tree related classes
    
fix sagemath#40935 in tree related classes.

cf sagemath#40932

Should `number_of_nodes` also be an alias, or perhaps instead of
`n_nodes`?
Should `n_nodes_to_the_right`, `n_nodes_at_depth` also be aliases?

Does this pollute the namespace too much?
    
URL: sagemath#40939
Reported by: Martin Rubey
Reviewer(s): David Coudert
@vbraun vbraun merged commit 4c5defe into sagemath:develop Nov 11, 2025
24 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

harmonize xxx_number

4 participants