Snake API: Mathematical Foundations

Charles Dana · Monce SAS · May 2026

snake.aws.monce.ai · /paper · /architecture · /economics

Four pieces of math live inside this endpoint: (1) the Dana Theorem — why SAT for classification is constructive, not search-based. (2) The arbitrator — how Snake and fuzzy combine into a probability-summing ranking. (3) Confidence semantics — what a 0.85 actually means. (4) Audit & CPU equations — how every clause and every cycle maps to an inequality you can verify.


1. The Dana Theorem (2024)

Theorem. For any indicator function f : {0,1}n → {0,1} over a finite discrete domain, there exists a CNF formula φ such that φ(x) = ¬f(x) for all x, and φ can be constructed in polynomial time in |dom f|.

Proof sketch (constructive). Let T = {x : f(x) = 1} (target / members) and F = {x : f(x) = 0} (non-members), both finite. For each f ∈ F:

  1. There must exist some t ∈ T and some feature index k such that fk ≠ tk (otherwise f would equal t).
  2. The literal ℓk(x) := [xk ≠ fk] evaluates to true on at least one t ∈ T and false on f.
  3. Take a disjunction of such literals over an uncovered subset of F: this clause Ci excludes a non-empty subset of non-members without excluding any member (by construction, a literal ℓk chosen to discriminate f from some t can be checked against all t ∈ T; if it excludes any t, pick a different k from the remaining n − 1 indices).
  4. The conjunction φ(x) = Λi Ci(x) over clauses covering all of F satisfies φ(t) = 1 for every t ∈ T and φ(f) = 0 for every f ∈ F.

Number of clauses < |F| (each clause excludes at least one element). Cost per clause: O(|F| · n). Total: O(|F|2 · n), polynomial. With bucketing into chunks of size b: O((|T| + |F|) · b · n), linear in data.

What this doesn't claim: that SAT is in P. SAT is NP-complete because, for arbitrary CNFs, finding a satisfying assignment is hard. Dana's theorem flips the question: we don't solve SAT, we construct a SAT instance directly from data, then evaluate it (also polynomial). The data is the assignment. The hardness of SAT applies to a different problem.


2. Snake Inference: probability from clause votes

For class C and query x, Snake stores L stochastic layers, each with one CNF φC,ℓ. Define the layer-vote indicator:

vC,ℓ(x) := 𝟙[ φC,ℓ(x) = 0 ]

(x is consistent with class C in layer ℓ.) The query's probability of being in class C is the empirical vote rate:

P(C | x) = (1 / L) · Σℓ=1..L vC,ℓ(x)

The denominator is L (not |classes|) because clauses are independent per layer, and each layer votes for at most one class given x. Sum over classes:

ΣC P(C | x) ≤ 1

with equality iff every layer reaches a verdict (no abstentions). In practice the API re-normalizes the returned distribution so Σ = 1 over the top-k candidates.

2.1 Why SAT 100% ≡ exact match

If x is a known synonym of class C* in the training population, then for every layer ℓ, φC*,ℓ(x) = 0 by construction (the clause was built to exclude non-members of C*, and x ∈ C*). So:

P(C* | x) = (1/L) · Σ 1 = 1.0

Conversely, if P(C* | x) = 1.0, every layer voted for C*, which (modulo the bucket assignment, see Snake v5.0.0 lookalike origins) means x sits inside C*'s consistent set in every layer's bucket. SAT confidence 1.0 is the formal statement of “exact synonym”. v5.4.6 dropped the separate hash lookup because this equivalence makes it redundant.


3. The Arbitrator: Snake + Fuzzy with Σ = 1.0

The /query endpoint with include_fuzzy_candidates=true returns two pools:

Concatenating the two response lists gives a sum ≈ 2.0 with overlap. The arbitrator fuses them into a single probability distribution.

3.1 Definition

For each candidate c in the union of both pools:

raw(c) = PS(c) + PF(c)

(treating PS(c) = 0 if c not in Snake's pool, and similarly for fuzzy.)

Parb(c) = raw(c) / Z, where Z = Σc raw(c)

3.2 The Σ = 1.0 invariant

Claim. Σc Parb(c) = 1, for any non-empty candidate union.

Proof. Σc Parb(c) = Σc raw(c) / Z = Z / Z = 1. The only failure mode is Z = 0, which occurs only when both pools are empty. The endpoint guards against this by returning an empty list rather than dividing by zero.

3.3 The “Both wins” magic

Suppose three candidates: A votes 0.5 from Snake and 0.4 from fuzzy. B votes 0.5 from Snake only. C votes 0.6 from fuzzy only. Total raw = 0.9 + 0.5 + 0.6 = 2.0. Then:

CandidatePSPFrawParb
A (Both)0.50.40.945%
C (Fuzzy only)00.60.630%
B (Snake only)0.500.525%

A wins despite having a lower max-source confidence than C (0.4 vs 0.6) because being voted by both sources is itself the strongest signal. This is the only ranking that falls out of the Σ = 1.0 constraint without ad-hoc weighting.

3.4 Why no 0.5/0.5 weighting?

One could write Parb(c) = α PS(c) + (1−α) PF(c). This forces a hyperparameter α that depends on the relative trust we put in each source. The arbitrator's pure-sum-then-renormalize formulation is equivalent to α = 0.5 only when both pools are individually unit-sum, which is exactly the regime we're in. So α = 0.5 is not chosen, it's derived.


4. Confidence semantics

4.1 What does “Snake confidence 0.85” mean?

Operationally: out of L = 5 stochastic layers, 4.25 of them voted that x is consistent with the predicted class. Concretely with L = 5, allowable values are {0, 0.2, 0.4, 0.6, 0.8, 1.0}. The 0.85 you see in API responses is post-renormalization across top-k.

4.2 Threshold theory

The default tier-1 threshold θ = 0.80 (configurable via SNAKE_CONFIDENCE_THRESHOLD) corresponds to at least 4 out of 5 layers agreeing. This is a fairness bound: with random SAT clauses, the chance that 4/5 independent layers vote for the same class spuriously decays geometrically in L.

P(false agreement ≥ 4/5) ≤ Σk=4..5 C(5,k) pk (1−p)5−k

For uniform-random p = 1/|classes|, with 1,000 classes (a typical factory): false agreement probability is bounded above by ~5 × 10−12. The tier-1 threshold is operationally safe.

4.3 Why fuzzy uses a different scale

Fuzzy returns Levenshtein-similarity scores in [0, 1]. The 0.50 threshold (FUZZY_THRESHOLD) is a calibration choice, not a probability. It corresponds to roughly “at least half the characters match modulo edit distance.” The two thresholds — SAT 0.80 and fuzzy 0.50 — are not directly comparable; the arbitrator's renormalization is what bridges them.


5. Audit equations

Every Snake response with include_audit=true exposes the SAT reasoning trail. For a query x classified as C with audit row {layer, bucket, clause, literal}:

audit(x, C) = { (ℓ, b, Ci, ℓk) : x satisfies all Ci in layer ℓ bucket b }

The audit trail makes Snake's prediction reproducible character by character. If a human disagrees, they can pinpoint which literal was the deciding one and either:

The closed-loop equation is:

snake_learning ∪ denominations − taboo → populate_models → φC,ℓ

Each rebuild solves for φ given the current curated population. Hasna's corrections become tomorrow's clauses.


6. CPU enhancement: vectorized clause evaluation

Snake v5.4.6 ships a Cython-accelerated _accel.pyx for the inner loop. The hot path is clause evaluation: given a query x and N clauses, compute φ(x) = Λi Ci(x). The naive Python loop is:

Tnaive(N, n) = O(N · mean(|Ci|) · per-literal-cost)

Cython brings the per-literal cost from ~1 µs (Python attribute access + dict lookup) to ~30 ns (C struct + indexed array lookup), a ~33× speedup. For a typical factory's field model (~5,000 clauses, mean clause size ~8 literals):

ImplementationPer-clause costPer-query φ eval
Pure Python~8 µs~40 ms
Cython _accel~240 ns~1.2 ms
Speedup~33×

The end-to-end /query latency of ~3.7 ms includes: HTTP parse (~0.5 ms), Snake clause eval (~1.2 ms), fuzzy candidate fetch (~0.3 ms when enabled), arbitrator merge (~0.1 ms), JSON serialization (~0.5 ms), TLS round-trip (~1 ms). Cython is the largest single contributor.

6.1 Why this matters at scale

At 260 q/s sustained on a single instance, the 1.2 ms inner loop is the load-bearing piece. If we regressed to pure Python, throughput would drop to ~30 q/s and the EC2 spec would need to triple to keep latency below 100 ms. Cython is the difference between this workload running on one r6i.4xlarge and needing a fleet.


7. Summary

Charles Dana · Monce SAS · snake.aws.monce.ai · deployed 2026-05-20
Co-Authored-By: Claude (Anthropic)