Skip to content

Commit a092c7e

Browse files
committed
Add iterators, Whitney numbers, characteristic polynomial, etc
1 parent 30b3d78 commit a092c7e

File tree

7 files changed

+770
-602
lines changed

7 files changed

+770
-602
lines changed

src/sage/matroids/basis_exchange_matroid.pxd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ cdef class BasisExchangeMatroid(Matroid):
6161
cpdef _augment(self, X, Y) noexcept
6262
cpdef _is_independent(self, F) noexcept
6363

64-
cpdef f_vector(self) noexcept
65-
cdef _f_vector_rec(self, object f_vec, bitset_t* flats, bitset_t* todo, long elt, long rnk) noexcept
64+
cpdef whitney_numbers2(self) noexcept
65+
cdef _whitney_numbers2_rec(self, object f_vec, bitset_t* flats, bitset_t* todo, long elt, long rnk) noexcept
6666
cpdef flats(self, R) noexcept
6767
cdef _flats_rec(self, SetSystem Rflats, long R, bitset_t* flats, bitset_t* todo, long elt, long rnk) noexcept
6868
cpdef coflats(self, R) noexcept

src/sage/matroids/basis_exchange_matroid.pyx

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,27 +1232,26 @@ cdef class BasisExchangeMatroid(Matroid):
12321232

12331233
# enumeration
12341234

1235-
cpdef f_vector(self) noexcept:
1235+
cpdef whitney_numbers2(self) noexcept:
12361236
r"""
1237-
Return the `f`-vector of the matroid.
1237+
Return the Whitney numbers of the second kind of the matroid.
12381238
1239-
The `f`-*vector* is a vector `(f_0, ..., f_r)`, where `f_i` is the
1240-
number of flats of rank `i`, and `r` is the rank of the matroid.
1239+
The Whitney numbers of the second kind are here encoded as a vector
1240+
`(W_0, ..., W_r)`, where `W_i` is the number of flats of rank `i`, and
1241+
`r` is the rank of the matroid.
12411242
1242-
OUTPUT:
1243-
1244-
List of integers.
1243+
OUTPUT: a list of integers
12451244
12461245
EXAMPLES::
12471246
12481247
sage: M = matroids.catalog.S8()
1249-
sage: M.f_vector()
1248+
sage: M.whitney_numbers2()
12501249
[1, 8, 22, 14, 1]
12511250
"""
12521251
cdef bitset_t *flats
12531252
cdef bitset_t *todo
12541253
if self._matroid_rank == 0:
1255-
return [0]
1254+
return [1]
12561255
flats = <bitset_t*>sig_malloc((self.full_rank() + 1) * sizeof(bitset_t))
12571256
todo = <bitset_t*>sig_malloc((self.full_rank() + 1) * sizeof(bitset_t))
12581257

@@ -1264,17 +1263,17 @@ cdef class BasisExchangeMatroid(Matroid):
12641263
bitset_clear(todo[0])
12651264
self.__closure(flats[0], todo[0])
12661265
bitset_complement(todo[0], flats[0])
1267-
self._f_vector_rec(f_vec, flats, todo, 0, 0)
1266+
self._whitney_numbers2_rec(f_vec, flats, todo, 0, 0)
12681267
for i in range(self.full_rank() + 1):
12691268
bitset_free(flats[i])
12701269
bitset_free(todo[i])
12711270
sig_free(flats)
12721271
sig_free(todo)
12731272
return f_vec
12741273

1275-
cdef _f_vector_rec(self, object f_vec, bitset_t* flats, bitset_t* todo, long elt, long i) noexcept:
1274+
cdef _whitney_numbers2_rec(self, object f_vec, bitset_t* flats, bitset_t* todo, long elt, long i) noexcept:
12761275
"""
1277-
Recursion for the f_vector method.
1276+
Recursion for the whitney_numbers2 method.
12781277
"""
12791278
cdef long e
12801279
f_vec[i] += 1
@@ -1287,7 +1286,7 @@ cdef class BasisExchangeMatroid(Matroid):
12871286
bitset_difference(todo[i + 1], flats[i + 1], flats[i])
12881287
if bitset_first(todo[i + 1]) == e:
12891288
bitset_copy(todo[i + 1], todo[i])
1290-
self._f_vector_rec(f_vec, flats, todo, e + 1, i + 1)
1289+
self._whitney_numbers2_rec(f_vec, flats, todo, e + 1, i + 1)
12911290
e = bitset_next(todo[i], e)
12921291

12931292
cpdef flats(self, r) noexcept:
@@ -1311,7 +1310,7 @@ cdef class BasisExchangeMatroid(Matroid):
13111310
EXAMPLES::
13121311
13131312
sage: M = matroids.catalog.S8()
1314-
sage: M.f_vector()
1313+
sage: M.whitney_numbers2()
13151314
[1, 8, 22, 14, 1]
13161315
sage: len(M.flats(2))
13171316
22
@@ -1386,7 +1385,7 @@ cdef class BasisExchangeMatroid(Matroid):
13861385
EXAMPLES::
13871386
13881387
sage: M = matroids.catalog.S8().dual()
1389-
sage: M.f_vector()
1388+
sage: M.whitney_numbers2()
13901389
[1, 8, 22, 14, 1]
13911390
sage: len(M.coflats(2))
13921391
22
@@ -1957,8 +1956,8 @@ cdef class BasisExchangeMatroid(Matroid):
19571956
else:
19581957
k = min(self.full_rank() - 1, 2)
19591958
fie, f_vec = self._flat_element_inv(k)
1960-
self._weak_invariant_var = hash(tuple([tuple([(f, len(fie[f])) for f in sorted(fie)]), f_vec]))
1961-
self._weak_partition_var = SetSystem(self._E, [fie[f] for f in sorted(fie)])
1959+
self._weak_invariant_var = hash(tuple([tuple([(f, len(fie[f])) for f in sorted(fie, key=str)]), f_vec]))
1960+
self._weak_partition_var = SetSystem(self._E, [fie[f] for f in sorted(fie, key=str)])
19621961
return self._weak_invariant_var
19631962

19641963
cpdef _weak_partition(self) noexcept:

src/sage/matroids/basis_matroid.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,9 +428,9 @@ cdef class BasisMatroid(BasisExchangeMatroid):
428428
sage: M = Matroid(bases=matroids.catalog.N2().bases())
429429
sage: M.truncation()
430430
Matroid of rank 5 on 12 elements with 702 bases
431-
sage: M.f_vector()
431+
sage: M.whitney_numbers2()
432432
[1, 12, 66, 190, 258, 99, 1]
433-
sage: M.truncation().f_vector()
433+
sage: M.truncation().whitney_numbers2()
434434
[1, 12, 66, 190, 258, 1]
435435
"""
436436
if self.full_rank() == 0:

src/sage/matroids/database_matroids.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ def P7():
541541
542542
sage: M = matroids.catalog.P7(); M
543543
P7: Ternary matroid of rank 3 on 7 elements, type 1+
544-
sage: M.f_vector()
544+
sage: M.whitney_numbers2()
545545
[1, 7, 11, 1]
546546
sage: M.has_minor(matroids.CompleteGraphic(4))
547547
False

src/sage/matroids/matroid.pxd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ cdef class Matroid(SageObject):
124124
cpdef coflats(self, r) noexcept
125125
cpdef hyperplanes(self) noexcept
126126
cpdef f_vector(self) noexcept
127+
cpdef whitney_numbers(self) noexcept
128+
cpdef whitney_numbers2(self) noexcept
127129
cpdef broken_circuits(self, ordering=*) noexcept
128130
cpdef no_broken_circuits_sets(self, ordering=*) noexcept
129131

@@ -213,6 +215,7 @@ cdef class Matroid(SageObject):
213215
cpdef _internal(self, B) noexcept
214216
cpdef _external(self, B) noexcept
215217
cpdef tutte_polynomial(self, x=*, y=*) noexcept
218+
cpdef characteristic_polynomial(self, l=*) noexcept
216219
cpdef flat_cover(self, solver=*, verbose=*, integrality_tolerance=*) noexcept
217220

218221
# misc

0 commit comments

Comments
 (0)