Repository navigation
Decide a node's modularity from cutters, not from every leaf - #16
Merged
Merged
Conversation
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
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.
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 moduleof
Gand not merely ofH. Since #14 it asked by comparing every leaf of thechild 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
Gexactly whenno cutter — taken in
G, not inH— of a consecutive pair inside it liesoutside 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.
leavesrebuilding each subtree once per levelleavesgathered a node's leaves by concatenating each child's into theparent's, with
leaves(x::Any) = [x]allocating per leaf. So one call costO(size · depth), and
strong_modulesasks every node. Collecting into a singlebuffer 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 hadstrong_modulesrecorded on #3 as Θ(n · depth) and as thething 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
Verification
vertex on all 44,534 nodes of the trees of 30,000 random digraphs — zero
disagreements.
masterover 4000 graphs and digraphs.every graph on n ≤ 6 against every starting order. All modular.
🤖 Generated with Claude Code
https://claude.ai/code/session_013w7XdHqa7ynpy1nN1j19Qp