Skip to content

Decide a node's modularity from cutters, not from every leaf - #16

Merged
StefanKarpinski merged 1 commit into
masterfrom
sk/module-of-cutters
Aug 25, 2026
Merged

StefanKarpinski merged 1 commit into
masterfrom
sk/module-of-cutters

Conversation

@StefanKarpinski

Copy link
Copy Markdown
Owner

A digraph whose symmetric part has a module tree of depth Θ(n) took 12.79s at
n = 2000
, and its cost per word of input rose from 1400 to 6400 as it grew
rather than staying put. It is 1.60s now, flat at about 600–790 ns/word.

Two things were paying for that, and neither was the one I predicted.

The check I added in #14

sort_leaves! asks, of each child of a degenerate node, whether it is a module
of G and not merely of H. Since #14 it asked by comparing every leaf of the
child against every vertex outside the node
— O(|child| · |outside|), which on
a deep tree costs more than the rest of the decomposition put together.

McConnell & de Montgolfier 2005, lemma 12: a node is a module of G exactly when
no cutter — taken in G, not in H — of a consecutive pair inside it lies
outside it. Those consecutive-pair cutters are what the tree was built from in
#11, they fold up the tree in a single pass, and the question is O(1) per node
afterwards.

leaves rebuilding each subtree once per level

leaves gathered a node's leaves by concatenating each child's into the
parent's, with leaves(x::Any) = [x] allocating per leaf. So one call cost
O(size · depth), and strong_modules asks every node. Collecting into a single
buffer makes it O(size).

A correction to #3

Theorem 8 of the same paper bounds the leaves of all strong modules together by
2m + 3n. I had strong_modules recorded on #3 as Θ(n · depth) and as the
thing capping the linear-time overlap components from #4. That was wrong.
A
deep module tree forces a dense graph — a nested chain of strong modules of sizes
2…n has Σ|M| = Θ(n²), and Σ|M| ≤ 2m+3n — so the module sets are O(n + m) and were
never the bound. Measured against that bound, Σ|M|/(n+m) ≤ 1.00 across random,
star, path, nested and dense graphs. I will correct the issue.

Effect

n arcs before after ns/word after
250 16,937 0.0476s 0.0204s 598
500 67,930 0.3603s 0.0824s 604
1000 236,738 1.9210s 0.3687s 777
2000 1,012,758 12.7856s 1.5975s 788

Verification

  • The cutter criterion agrees with comparing every leaf against every outside
    vertex on all 44,534 nodes of the trees of 30,000 random digraphs — zero
    disagreements.
  • Output identical to master over 4000 graphs and digraphs.
  • 1,440,000 digraph permutations over four generators; 5,670,000 symmetric ones;
    every graph on n ≤ 6 against every starting order. All modular.

🤖 Generated with Claude Code

https://claude.ai/code/session_013w7XdHqa7ynpy1nN1j19Qp

A digraph whose symmetric part has a module tree of depth Θ(n) took 12.79s at
n = 2000, against 1.60s now, and its cost per word of input went from 1400 to
6400 as it grew rather than staying put.

Two things were paying for that, and neither was what I expected.

sort_leaves! asks, of each child of a degenerate node, whether it is a module of
G and not merely of H. Since #14 it asked by comparing every leaf of the child
against every vertex outside the node, which is O(|child| · |outside|) and on a
deep tree costs more than the rest of the decomposition together. McConnell & de
Montgolfier 2005, lemma 12: a node is a module of G exactly when no cutter --
taken in G, not in H -- of a consecutive pair inside it lies outside it. The
cutters of consecutive pairs are what the tree was built from, they fold up the
tree in one pass, and the question is O(1) a node afterwards.

leaves gathered a node's leaves by concatenating each child's, so every subtree
was rebuilt once per level above it and a single call cost O(size · depth).
Collecting into one buffer makes it O(size). By theorem 8 of the same paper the
leaves of all the strong modules together are at most 2m + 3n, so this should
cost the size of the graph; measured against that bound the ratio is at most
1.00 across random, star, path, nested and dense graphs.

That theorem also corrects something I had recorded on #3: I had strong_modules
down as Θ(n · depth) and as the thing bounding the linear time overlap
components from #4. It is not. A deep module tree forces a dense graph -- a
nested chain of strong modules of sizes 2..n has Σ|M| = Θ(n²), and Σ|M| ≤ 2m+3n
-- so the module sets are O(n + m) and were never the bound.

        n       arcs      before       after   ns/word after
      250      16937     0.0476s     0.0204s             598
      500      67930     0.3603s     0.0824s             604
     1000     236738     1.9210s     0.3687s             777
     2000    1012758    12.7856s     1.5975s             788

Flat per word: linear in the input for a shape that was not.

The cutter criterion agrees with comparing every leaf against every outside
vertex on all 44,534 nodes of the trees of 30,000 random digraphs. Output is
identical to master over 4000 graphs and digraphs. 1,440,000 digraph
permutations over four generators, 5,670,000 symmetric ones, and every graph on
n ≤ 6 against every starting order: all modular.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013w7XdHqa7ynpy1nN1j19Qp
@StefanKarpinski
StefanKarpinski merged commit a46c84c into master Aug 25, 2026
15 checks passed
@StefanKarpinski
StefanKarpinski deleted the sk/module-of-cutters branch August 25, 2026 19:19
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.

1 participant