Skip to content

Speed up poset characteristic polynomial computation by caching Möbius function #34971

@trevorkarn

Description

@trevorkarn

It appears that the built-in methods to compute the characteristic polynomial of a poset recompute Moebius function values redundantly, leading to slowdown. For example:

sage: P = characteristic_polynomial(posets.SetPartitions(7))
sage: %time S.characteristic_polynomial()
CPU times: user 27.2 ms, sys: 14.4 ms, total: 41.6 ms
Wall time: 69.4 ms
q^4 - 10*q^3 + 35*q^2 - 50*q + 24

but by memoizing:

sage: %time characteristic_polynomial(S)
CPU times: user 4.8 ms, sys: 212 µs, total: 5.01 ms
Wall time: 5.09 ms
t^4 - 10*t^3 + 35*t^2 - 50*t + 24

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions