Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add iterators, Whitney numbers, characteristic polynomial, etc #37361

Merged
merged 24 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a092c7e
Add iterators, Whitney numbers, characteristic polynomial, etc
gmou3 Feb 15, 2024
4ffa282
More internal iterators and cythonization
gmou3 Feb 16, 2024
cbb774b
Merge branch 'develop' into matroid.pyx
gmou3 Feb 25, 2024
0e88a87
Suggestions by tscrim
gmou3 Feb 27, 2024
a4b643d
Merge branch 'develop' into matroid.pyx
gmou3 Mar 1, 2024
7628632
More tests
gmou3 Mar 8, 2024
c229ba2
Merge remote-tracking branch 'sagemath/develop' into matroid.pyx
gmou3 Mar 8, 2024
2c49852
Merge branch 'matroid.pyx' of https://github.com/gmou3/sage into matr…
gmou3 Mar 8, 2024
c3aa9cd
Merge remote-tracking branch 'sagemath/develop' into matroid.pyx
gmou3 Mar 26, 2024
f5d3701
Docsting suggestions by mkoeppe
gmou3 Mar 26, 2024
bc80bf9
Suggestions by tscrim
gmou3 Mar 26, 2024
2caff02
More suggestions by mkoeppe
gmou3 Mar 26, 2024
36ed3ca
Add missing noexcept clauses
tornaria Mar 12, 2024
77a5f66
Remove deprecated noexcept clauses
tornaria Mar 12, 2024
f05d44f
More deprecated noexcept clauses
tornaria Mar 12, 2024
0f4460e
Fix doctest
tornaria Mar 12, 2024
161d993
Revert "Workaround warning in cython 3.0.9 (#37560)"
tornaria Mar 24, 2024
8eeba35
src/sage/numerical: Incidental style fixes
mkoeppe Mar 25, 2024
bcc326d
Incidental style fixes
mkoeppe Mar 25, 2024
603d884
Merge branch 'develop' into matroid.pyx
gmou3 Apr 1, 2024
4b95fc9
Suggestions by tscrim
gmou3 Apr 4, 2024
17f2931
Merge branch 'develop' into matroid.pyx
gmou3 Apr 4, 2024
919a07d
Merge branch 'matroid.pyx' of https://github.com/gmou3/sage into matr…
gmou3 Apr 4, 2024
236361b
Merge remote-tracking branch 'tornaria/noexcept' into matroid.pyx
gmou3 Apr 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/sage/matroids/basis_exchange_matroid.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ cdef class BasisExchangeMatroid(Matroid):
cpdef _augment(self, X, Y) noexcept
cpdef _is_independent(self, F) noexcept

cpdef f_vector(self) noexcept
cdef _f_vector_rec(self, object f_vec, bitset_t* flats, bitset_t* todo, long elt, long rnk) noexcept
cpdef whitney_numbers2(self) noexcept
cdef _whitney_numbers2_rec(self, object f_vec, bitset_t* flats, bitset_t* todo, long elt, long rnk) noexcept
cpdef flats(self, R) noexcept
cdef _flats_rec(self, SetSystem Rflats, long R, bitset_t* flats, bitset_t* todo, long elt, long rnk) noexcept
cpdef coflats(self, R) noexcept
Expand Down
33 changes: 16 additions & 17 deletions src/sage/matroids/basis_exchange_matroid.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1232,27 +1232,26 @@ cdef class BasisExchangeMatroid(Matroid):

# enumeration

cpdef f_vector(self) noexcept:
cpdef whitney_numbers2(self) noexcept:
r"""
Return the `f`-vector of the matroid.
Return the Whitney numbers of the second kind of the matroid.

The `f`-*vector* is a vector `(f_0, ..., f_r)`, where `f_i` is the
number of flats of rank `i`, and `r` is the rank of the matroid.
The Whitney numbers of the second kind are here encoded as a vector
`(W_0, ..., W_r)`, where `W_i` is the number of flats of rank `i`, and
gmou3 marked this conversation as resolved.
Show resolved Hide resolved
`r` is the rank of the matroid.

OUTPUT:

List of integers.
OUTPUT: a list of integers

EXAMPLES::

sage: M = matroids.catalog.S8()
sage: M.f_vector()
sage: M.whitney_numbers2()
[1, 8, 22, 14, 1]
"""
cdef bitset_t *flats
cdef bitset_t *todo
if self._matroid_rank == 0:
return [0]
return [1]
flats = <bitset_t*>sig_malloc((self.full_rank() + 1) * sizeof(bitset_t))
todo = <bitset_t*>sig_malloc((self.full_rank() + 1) * sizeof(bitset_t))

Expand All @@ -1264,17 +1263,17 @@ cdef class BasisExchangeMatroid(Matroid):
bitset_clear(todo[0])
self.__closure(flats[0], todo[0])
bitset_complement(todo[0], flats[0])
self._f_vector_rec(f_vec, flats, todo, 0, 0)
self._whitney_numbers2_rec(f_vec, flats, todo, 0, 0)
for i in range(self.full_rank() + 1):
bitset_free(flats[i])
bitset_free(todo[i])
sig_free(flats)
sig_free(todo)
return f_vec

cdef _f_vector_rec(self, object f_vec, bitset_t* flats, bitset_t* todo, long elt, long i) noexcept:
cdef _whitney_numbers2_rec(self, object f_vec, bitset_t* flats, bitset_t* todo, long elt, long i) noexcept:
"""
Recursion for the f_vector method.
Recursion for the whitney_numbers2 method.
"""
cdef long e
f_vec[i] += 1
Expand All @@ -1287,7 +1286,7 @@ cdef class BasisExchangeMatroid(Matroid):
bitset_difference(todo[i + 1], flats[i + 1], flats[i])
if bitset_first(todo[i + 1]) == e:
bitset_copy(todo[i + 1], todo[i])
self._f_vector_rec(f_vec, flats, todo, e + 1, i + 1)
self._whitney_numbers2_rec(f_vec, flats, todo, e + 1, i + 1)
e = bitset_next(todo[i], e)

cpdef flats(self, r) noexcept:
Expand All @@ -1311,7 +1310,7 @@ cdef class BasisExchangeMatroid(Matroid):
EXAMPLES::

sage: M = matroids.catalog.S8()
sage: M.f_vector()
sage: M.whitney_numbers2()
[1, 8, 22, 14, 1]
sage: len(M.flats(2))
22
Expand Down Expand Up @@ -1386,7 +1385,7 @@ cdef class BasisExchangeMatroid(Matroid):
EXAMPLES::

sage: M = matroids.catalog.S8().dual()
sage: M.f_vector()
sage: M.whitney_numbers2()
[1, 8, 22, 14, 1]
sage: len(M.coflats(2))
22
Expand Down Expand Up @@ -1957,8 +1956,8 @@ cdef class BasisExchangeMatroid(Matroid):
else:
k = min(self.full_rank() - 1, 2)
fie, f_vec = self._flat_element_inv(k)
self._weak_invariant_var = hash(tuple([tuple([(f, len(fie[f])) for f in sorted(fie)]), f_vec]))
self._weak_partition_var = SetSystem(self._E, [fie[f] for f in sorted(fie)])
self._weak_invariant_var = hash(tuple([tuple([(f, len(fie[f])) for f in sorted(fie, key=str)]), f_vec]))
self._weak_partition_var = SetSystem(self._E, [fie[f] for f in sorted(fie, key=str)])
gmou3 marked this conversation as resolved.
Show resolved Hide resolved
return self._weak_invariant_var

cpdef _weak_partition(self) noexcept:
Expand Down
4 changes: 2 additions & 2 deletions src/sage/matroids/basis_matroid.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,9 @@ cdef class BasisMatroid(BasisExchangeMatroid):
sage: M = Matroid(bases=matroids.catalog.N2().bases())
sage: M.truncation()
Matroid of rank 5 on 12 elements with 702 bases
sage: M.f_vector()
sage: M.whitney_numbers2()
[1, 12, 66, 190, 258, 99, 1]
sage: M.truncation().f_vector()
sage: M.truncation().whitney_numbers2()
[1, 12, 66, 190, 258, 1]
"""
if self.full_rank() == 0:
Expand Down
2 changes: 1 addition & 1 deletion src/sage/matroids/database_matroids.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ def P7():

sage: M = matroids.catalog.P7(); M
P7: Ternary matroid of rank 3 on 7 elements, type 1+
sage: M.f_vector()
sage: M.whitney_numbers2()
[1, 7, 11, 1]
sage: M.has_minor(matroids.CompleteGraphic(4))
False
Expand Down
12 changes: 12 additions & 0 deletions src/sage/matroids/matroid.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,15 @@ cdef class Matroid(SageObject):
cpdef coflats(self, r) noexcept
cpdef hyperplanes(self) noexcept
cpdef f_vector(self) noexcept
cpdef whitney_numbers(self) noexcept
cpdef whitney_numbers2(self) noexcept
cpdef broken_circuits(self, ordering=*) noexcept
cpdef no_broken_circuits_sets(self, ordering=*) noexcept

# polytopes
cpdef matroid_polytope(self) noexcept
cpdef independence_matroid_polytope(self) noexcept

# isomorphism
cpdef is_isomorphic(self, other, certificate=*) noexcept
cpdef _is_isomorphic(self, other, certificate=*) noexcept
Expand All @@ -153,6 +159,7 @@ cdef class Matroid(SageObject):
cpdef modular_cut(self, subsets) noexcept
cpdef linear_subclasses(self, line_length=*, subsets=*) noexcept
cpdef extensions(self, element=*, line_length=*, subsets=*) noexcept
cpdef coextensions(self, element=*, coline_length=*, subsets=*) noexcept

# connectivity
cpdef simplify(self) noexcept
Expand Down Expand Up @@ -213,14 +220,19 @@ cdef class Matroid(SageObject):
cpdef _internal(self, B) noexcept
cpdef _external(self, B) noexcept
cpdef tutte_polynomial(self, x=*, y=*) noexcept
cpdef characteristic_polynomial(self, l=*) noexcept
cpdef flat_cover(self, solver=*, verbose=*, integrality_tolerance=*) noexcept

# misc
cpdef automorphism_group(self) noexcept
cpdef bergman_complex(self) noexcept
cpdef augmented_bergman_complex(self) noexcept
cpdef broken_circuit_complex(self, ordering=*) noexcept

# visualization
cpdef plot(self,B=*,lineorders=*,pos_method=*,pos_dict=*,save_pos=*) noexcept
cpdef show(self,B=*,lineorders=*,pos_method=*,pos_dict=*,save_pos=*,lims=*) noexcept
cpdef _fix_positions(self,pos_dict=*,lineorders=*) noexcept

# construction
cpdef direct_sum(self, matroids) noexcept
Loading
Loading