Parameters

Statistic
W = min(W+, W), where W+ is the sum of positive ranks and N = n(n+1)/2.
Performance notes

The original Python version enumerated all 2n sign configurations. This implementation uses dynamic programming to compute the exact distribution of W+ (subset-sum counts), then maps it to W = min(W+, N−W+):

  • Time: from O(n·2n) down to O(n·N), where N = n(n+1)/2.
  • Counts use BigInt to avoid overflow; probabilities are compared as exact fractions.
  • Cached per n: the distribution is computed once and reused.

Results

Total rank sum N
Critical value Wcrit
P(W ≤ Wcrit)
Distribution (default: PMF P(W=w))

Note: Column headers show “one-tailed α / two-tailed α”. Since the statistic is W=min(W+,W), tables are often published for two-tailed α; for a one-tailed test, you can use the corresponding two-tailed 2α threshold.