每条判决都是对实测事实的整数或精确有理数算术,每条规则都追溯到实现它的源码行。
下面每一条都给出规则本身、它判什么、写明了的保证(如有)与参与的常数,并链到工作原理页上的推导和引出实现行的方法学册。
任何长度至少为 t 的归一化公共 token 串都必然共享至少一个指纹:Schleimer 等人 SIGMOD'03 的 no-miss 下界,作为正确性契约。
t = window + kgram - 1 = 26 + 25 - 1 = 50 tokens
任何长度至少为 t 的归一化公共 token 子串,必然包含 t - k + 1 = w 个连续 k-gram(即一整个完整窗口);而窗口最小值的选取只依赖该窗口内部的内容,所以两份拷贝必选出同一个最小值。
Zhang-Shasha 编辑距离恒为整数,故 TSED ≥ 0.85 的近似克隆由精确的交叉相乘判定。
TSED(a, b) = (max(n1, n2) - ted(a, b)) / max(n1, n2) clone ⇔ TSED >= 0.85 cloneDecidesWith (num, den) t n1 n2 = (mx - t) * den >= num * mx where mx = max n1 n2
ted 是单位代价的 Zhang-Shasha(删 = 插 = 1,kind 码相同时 relabel = 0,否则 1),恒为整数,所以比较是精确的交叉相乘,边界两侧都可判定:在 max = 100 时 ted 15 是克隆、ted 16 不是。
两段文档在 5 词 shingle 上 Jaccard ≥ 0.80、或存在 50 词逐字连续段即判重复;MinHash/LSH 只负责提名候选对。
dupDecidesWith num den inter union = inter * den >= num * union dupVerdictWith (num, den, vfloor) inter union run = dupDecidesWith num den inter union || run >= vfloor
MinHash/LSH 只是粗筛,且无 RNG:置换下标本身就是盐。
克隆组成员的差异处成为洞,每个不同的取值向量对应一个参数:至多 6 个,且确有省行才可行。
align : T1/T2 isomorphic, holes = differing leaves; T3 the tree-edit mapping narrowed top-down, relabels and unequal gaps are holes params : one per distinct value vector; feasible iff every hole is an expression or a name, params ≤ 6 and savings > 0
这一运算是反统一:取每个成员都是其实例的最小一般骨架,用各成员自己的值填上骨架的洞即还原该成员。
目录多样性与布局散度全程用精确有理数:熵族与 KL 族里不取对数的成员,因而每条边界都可判定。
tsallis2 cs = 1 - Σ (c/N)^2 -- and = 0 when N == 0
tsallis2Norm cs = tsallis2 cs / (1 - 1/n) -- n = nonzero bins, n > 1
chi2 pairs = Σ_{r > 0} (p - q)^2 / q -- p = o/Σo, q = r/Σr
perMille r = floor (r * 1000)
Shannon 熵与 KL 散度需要对数(无理数,因而不可精确判定),所以本家族改为发布同族中在有理数下封闭的成员:Tsallis-2 多样性与 χ² f-散度,全程跑在 Data.Ratio 上。
若某个 bin 参考质量为 0 而观测质量非 0,χ² 返回 Nothing:那是一次拒绝而不是一个零,报告会点名那些目录。
每个目录的模块度贡献除以它最多能挣到的份额:从不外引为 1000‰,恰在零模型期望处为 0。
rho = q / qMax = (e*m − o*i) / (mu*(m − mu))
设目录内部边数为 e、出质量 o、入质量 i、关联质量 mu = e + crossOut + crossIn、全树边数 m,则一个目录的 Newman 贡献为 q = e/m − o*i/m^2;质量为 mu 的目录最多能挣到的(每条关联边都在内部时)是 qMax = mu(m−mu)/m^2。
最便宜的弧从环里切掉之后,目录排成层;每个目录的不稳定度以整数千分数给出。
cuts : per SCC, a subset programme when it has ≤ 14 directories (exact 1), else Eades–Lin–Smyth + redundancy pass (exact 0)
layers : level(d) = 0 when nothing leaves d, else 1 + max level of what d points at, the cut arcs removed
metrics: fanIn, fanOut, instability = ⌊1000 · out ÷ (in + out)⌋, −1 when nothing touches the directory
使图无环的最便宜弧集逐个强连通分量求出:两个分量之间的弧不在任何环上,所以全图的最小值就是各分量最小值的并。
各判轴在凸的尺寸罚分下折成一个 0–1000 分;每个文件的上限只缩不涨,增长超过 max(+2 %, +10) 即判负。
raw = sum_i (w_i * p_i * violCost)
wTotal = sum_i w_i -- derived, never a literal
score = max 0 (scoreScale - raw `div` (violCostNeutral * wTotal))
p(x) = 0 if x <= S
= pMax if H <= S -- degenerate fallback
= pMax * ((x - S) / (H - S))^2 if S < x <= H
= pMax * (1 + 2*(x - H)/(H - S)) if x > H -- C¹ 线性臂
判轴 0 是唯一一条不是计数的轴:对文件尺寸的凸罚,精确 Rational,越过硬线之后仍单调上升。
把七条判轴折叠成一个 0–1000 的分数,并对着一份只准收紧的基线银行把门。
tolerated(c) = max (c * tolNum `div` tolDen) (c + tolAbs)
added = current \ baseline -- non-empty => fail
removed = baseline \ current -- informational; drives the shrink
fail 位是六个具名条件的析取:ratchet_over、discrete_added、floor、dedup_budget、knobs_digest、rows_dropped。
SonarSource 的认知复杂度,连同其自家分析器没有实现的 S3776 附录 B1 递归增量:调用环由核找出,每个环成员各加一次。
+1 for each method in a recursion cycle, whether direct or indirect
罚分曲线是凸的且 p(0) = 0,故超可加:一条缝的收益从不为负,再与切割的代价比较。
benefitMilli(u) = max 0 (floor (1000 * (p(total) - p(end_u) - p(total - end_u))))
costMilli(u) = crossRefs(u) * roiRefMilli
+ cutClones(end_u) * roiCloneMilli
+ crossChurn(u) * roiChurnMilli
+ roiPhiMilli
viable ⇔ b >= c -- ROI >= 1, evaluated without division
收益是拆分退回来的那部分软区罚分,算在与判决家族同一条凸曲线上,直接 import 而不是重新推一遍;因为 p 是凸的且 p(0) = 0,故超可加,所以那个方括号非负。
趋势取成对斜率的中位数:一个野点提交拽不动它半步。
x_i = ts_i % 86400 -- seconds to days, exact ratio
y_i = (score_i * 1000000) % scale_i
slope = median{ (y_j - y_i) / (x_j - x_i) : x_i ≠ x_j } -- Theil-Sen
slope < -band → 2 (degrading)
slope > band → 0 (improving)
otherwise → 1 (flat) where band = floorMicro
斜率取成对斜率的中位数(trend/2):一个野点(测出来的坏提交)能把最小二乘的均值拽到任何地方,却拽不动中位数半步。
活的入口都到不了的文件即死;环由 Tarjan 强连通分量只找一次,只报不判。
arcs = { (s,d) | [s,d,kind,rung] ∈ edges, rung <= minRung, kind ∉ inert }
reach = ⋃ { reachable(G, s) | s ∈ entries(entryMask, flags) }
public = testBit flags 0
referenced = indeg >= 1 over kept arcs
judged = i ∉ reach
code = 1 + public + 2*referenced -- the lookup table is the authority
环只报不判;没有入口种子的环岛仅凭可达性就已判死,无需特例。
在每个函数的控制流图上求可达,在它的变量上做逆向活跃性分析。
kind 0 : unreachable = no path from the entry, one finding per maximal run of seqs kind 1 : dead_store = a write no path reads before the next write or the exit (backward liveness) kind 2 : unused_local = no read · kind 3 : unused_param = no read (advice, never judged)
活跃入集在整张图上解到 in = transfer(∪ in of successors) 的不动点。
在索引自身的事实上逐层半朴素求值的 Datalog;每个答案都带着推出它的那棵推导树。
dead(F) :- file(F), not reach(F).
strata : a head sits above every negated or aggregated body predicate; a negative edge inside an SCC is a program error
eval : semi-naive per stratum over lazy bitmask indexes; the first derivation of a tuple is its provenance
集合语义,最小模型。
整数 BM25(k1 = 6/5、b = 3/4)为一个单元排出最像它的单元;仓内 PPMI 可以拓宽查询,只作建议。
score = Σ w · idf · 22·tf·avg / (10·tf·avg + 3·avg + 9·len) (k1 = 6/5, b = 3/4; integer fixed point)
widen = top-m PPMI neighbours at ≤ ½ weight (opt-in view; never evidence)
role ⇔ (N ≥ 1 ∧ C ≥ 1) ∨ (N ≥ 2 ∧ shapeEqual) (judged in Haskell over similar/1; advisory only)
PPMI(a, b) = max(0, log2(n_ab · N / (n_a · n_b)))
Rust 发查询袋与每候选九个整数一行;Haskell 用精确有理数排序并施加角色合取;名字、词与路径永不过线。