topos.functors.profunctors.cfg.compare

CFG Comparison — profunctor D : E × E^op restricted to CFGs.

Pairwise comparison of two ControlFlowGraph instances. The CFG captures intra-procedural control flow; comparing two CFGs lets us reason about how a refactor changed branching shape without being misled by lexical churn (whitespace, renames) the AST distance picks up.

Three orthogonal signals are exposed:

cyclomatic_delta   : signed change in McCabe complexity
edge_kind_l1       : L1 distance between edge-kind histograms
                      (a single number in ``[0, 2]``)
longest_path_delta : signed change in longest acyclic entry→exit path

A composite CFGComparison packages all three plus the raw per-side measurements so callers can render whatever summary they need.

class topos.functors.profunctors.cfg.compare.CFGComparison(cyclomatic_delta, edge_kind_l1, longest_path_delta, source_metrics, target_metrics)[source]

Bases: object

Pairwise comparison summary for two control-flow graphs.

cyclomatic_delta
edge_kind_l1
longest_path_delta
source_metrics
target_metrics
property changed

True iff any signal reports a non-zero divergence.

topos.functors.profunctors.cfg.compare.cyclomatic_delta(source, target)[source]

Signed change in McCabe cyclomatic complexity (target − source).

topos.functors.profunctors.cfg.compare.edge_kind_histogram(cfg)[source]

Count edges grouped by EdgeKind.

topos.functors.profunctors.cfg.compare.edge_kind_l1_distance(source, target)[source]

L1 distance between the two edge-kind histograms, normalized to probability distributions. Result lies in [0, 1] (half of the raw L1, matching the convention used elsewhere in the codebase).

topos.functors.profunctors.cfg.compare.longest_path_delta(source, target)[source]

Signed change in longest acyclic entry→exit path length.

topos.functors.profunctors.cfg.compare.compare_cfg(source, target)[source]

Run the full CFG comparison suite for a single pair of graphs.