Implement Whitney 2-isomorphism for graphs and graphic matroids - #42630
Open
cxzhong wants to merge 3 commits into
Open
Implement Whitney 2-isomorphism for graphs and graphic matroids#42630cxzhong wants to merge 3 commits into
cxzhong wants to merge 3 commits into
Conversation
|
Documentation preview for this PR (built with commit 51dbc8b; changes) is ready! 🎉 |
cxzhong
marked this pull request as ready for review
August 7, 2026 03:04
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #42595.
This also includes the groundset-size regression fix from #42574.
Summary
Graph.is_2isomorphicusing block decomposition, SPQR trees, and colored canonical forms;certificate=Truereturn a versioned, replayable Whitney-operation witness rather than only an edge bijection;Graph.verify_2isomorphism_certificateto validate and replay vertex cleavings, Whitney twists, vertex identifications, and isolated-vertex adjustments;GraphicMatroid._is_isomorphic, while preserving the matroid API's groundset-mapping certificate;GraphicMatroid, so it does not build an operation sequence that it would immediately discard;Matroid(G)/GraphicMatroid(G)groundset rules;cg()inline definitions from.pxdfiles into their owning.pyxmodules, preventing unused local copies in unrelated generated extensions.Motivation and root cause
GraphicMatroid._is_isomorphicpreviously had a graph fast path only when the other matroid was 3-connected. General graphic matroids fell back to regular-matroid isomorphism, and the fast path could also lose size information after simplifying loops and parallel edges. That is the regression addressed by #42574.Whitney's 2-isomorphism theorem gives the right graph-level equivalence: two graphs represent isomorphic cycle matroids exactly when their edge occurrences can be related by vertex cleavings/identifications, Whitney twists, and a final graph isomorphism. The implementation uses Sage's existing block and SPQR decomposition machinery and does not enumerate subsets or possible twist sequences.
Certificate format
On success,
G.is_2isomorphic(H, certificate=True)returns(True, witness), wherewitnesscontains:version(currently1);edge_mapping, a bijection between positions inlist(G.edge_iterator())andlist(H.edge_iterator());operations, containing explicitvertex_cleaving,whitney_twist,vertex_identification,delete_isolated_vertex, andadd_isolated_vertexsteps;vertex_mapping, the final normalized graph isomorphism.The public verifier uses private edge-occurrence IDs, checks each operation's preconditions, requires the final vertex map to be a bijection, and compares every final edge incidence with the target. Malformed or tampered witnesses return
Falseinstead of leaking parsing exceptions.Performance
Local timings below use Sage 10.10.beta8 / CPython 3.12. Each function is warmed once; the new paths use the median of 5 runs and the previous paths use the median of 3 runs, with
gc.collect()before each sample. Absolute timings are machine-dependent; the relative comparisons use the same process and inputs.For the SPQR rows, "Previous path" is the generic
RegularMatroidfallback. For the wheel rows, it is the previous 3-connectedGraphicMatroidfast path, including its connectivity check.multi_k4(4))multi_k4(8))multi_k4(16))For the 21-edge SPQR case, the previous regular-matroid certificate path took 459.56 ms versus 3.85 ms for the new mapping-only
GraphicMatroidcertificate path (about 119x faster). On the 3,072-edge graph, constructing the full replayable Graph witness adds about 13% over the boolean result.Complete benchmark source
Save this as
benchmark_two_isomorphism.pyand run./sage -python benchmark_two_isomorphism.py.Validation
ruff(normal and preview configuration),relint,git diff --check, Cython compilation, and linking passed;ninja -C builddir -nreports no work to do;graphic_matroidC source no longer contains localDenseGraphBackend_cg,SparseGraphBackend_cg, orStaticSparseBackend_cgcopies.Known limitation
The generated sequence is deterministic and replayable, but is not promised to use the minimum number of Whitney operations. Because every twist explicitly serializes one edge side, deeply nested SPQR decompositions can produce a witness with quadratic total serialized size. The boolean path and the
GraphicMatroidedge-mapping-only certificate path do not pay this output cost.