Casper: A Projection-Based Neurosymbolic Layer for Scalable & Guaranteed Constraint Satisfaction

Lohith Konathala, Luca Andolfi, Eleonora GiunchigliaNeurIPS 2026

TL;DR

Deep neural networks are remarkably good at pattern recognition, yet notoriously bad at following hard rules—a dealbreaker when predicting invalid medication pairs or physically impossible routes. CASPER is a plug-and-play, differentiable neurosymbolic layer that guarantees 100% logical constraint satisfaction while scaling effortlessly to thousands of variables. By framing rule-following as a fast, closed-form geometric projection on a GPU, it finally breaks the longstanding trade-off between exactness and speed.

What Problem Does This Paper Address?

Suppose you train a neural network to navigate a map or prescribe drug combinations. Even if your model is 99% accurate on average, a single broken rule—walking through a solid wall or prescribing a fatal drug interaction—renders the entire prediction useless. Standard deep learning offers zero guarantees at test time that outputs will obey hard logical constraints.

Neurosymbolic AI tries to bridge this gap by combining neural networks with symbolic logic, but existing approaches hit a wall:

  • Exact methods compile rules into complex circuits or binary indicators, guaranteeing compliance but choking computationally as problem sizes grow.
  • Scalable methods rely on approximations (like sampling top-$k$ logical proofs or training neural surrogates), which run fast at scale, but forfeit the 100% safety guarantee.
Table 1: Comparison of CASPER against baselines on three properties. Guaranteed Satisfaction (Sat): method provably produces constraint-compliant outputs. Scalable (Scale): method manages to scale over most over the tasks in our experimental analysis, Automatic (Auto): no problem-specific engineering required.

The authors ask: Can we build an automated, differentiable layer that sits on top of any neural network, runs at massive scale, and mathematically guarantees every output obeys the rules?

Methods

CASPER (Categorical Argmax Satisfaction via ProjEction and Resolution) takes a neural network's raw probability predictions over categorical variables and nudges them onto the closest valid region of the probability simplex—ensuring the highest-probability choice (argmax) satisfies all logical constraints $\Pi$. It pulls this off via three clever mechanisms:

  1. Fast Surrogate Projection (Single Variable): Finding the exact closest valid probability vector in Euclidean space requires sorting probabilities, which bottlenecks GPUs. Instead, CASPER introduces a closed-form surrogate projection using a simple thresholding operation. It slightly over-corrects continuous probability values, reducing sequential GPU operations from $\mathcal{O}(\log^2 h)$ to $\mathcal{O}(\log h)$—yet provably selects the exact same winning argmax category as the slower exact projection.
  2. Offline Signed Resolution (Multiple Variables): To handle interacting variables, CASPER runs an offline compilation step using a classic multi-valued logic rule called signed resolution. Given an ordering of variables, it pre-computes "conflict clauses" backwards so that during inference, variables can be resolved sequentially (and parallelized when independent) without ever hitting a logical dead-end.
  3. Dual-Purpose $\ell_2$ Regularization: Projecting probabilities flattens certain directions in the layer's Jacobian, killing gradients during backpropagation. Adding a simple $\ell_2$ penalty between the raw and projected outputs simultaneously tightens the surrogate approximation and restores those zeroed-out gradients!

Datasets

The authors evaluate CASPER across three structured-prediction benchmarks (no new datasets are introduced, though existing ones are pushed to extreme scales):

  • Warcraft Pathfinding: Finding minimum-cost valid paths across $12\times 12$ and $30\times 30$ terrain grids rendered from Warcraft II tiles.
  • MNIST Arithmetic: MNIST-Sum (summing up to $n = 1024$ handwritten digits) and MNIST-Add (adding two $n$-digit numbers up to $n = 256$).
  • SatNet Visual Sudoku: 10,000 $9\times 9$ Sudoku boards built from handwritten MNIST digits (averaging ~36 hints per board).

Key Insights and Ideas

  • Exact Discrete Choices from Approximate Continuous Math: Theorem 3 and Corollary 2 reveal a neat mathematical free lunch: because sequential variable constraints only care about discrete argmax decisions made at previous steps, CASPER's fast continuous approximation never compounds errors across long variable chains. You get GPU speed with zero loss in logical fidelity.
  • Zero-Shot Post-Hoc Safety: Ablations show that slapping CASPER onto an already-trained, unconstrained neural network only at test time immediately boosts valid $12\times 12$ Warcraft paths from 62.5% to 100%, and jumps optimal paths from 59.7% to 78.3%—no retraining required.
  • A Geometry Fix for Vanishing Gradients: Proving that the $\ell_2$ distance between raw and projected predictions lives precisely in the orthogonal complement ($V^\perp$) of the projection's gradient subspace turns a standard regularizer into an exact mathematical cure for rank-deficient backpropagation.

Key Results

  • Warcraft Pathfinding: On $30\times 30$ grids, every exact neurosymbolic baseline times out (>5s per example), and approximate baselines yield valid paths less than 7% of the time. CASPER produces 100% valid paths and achieves 12.1% optimal paths, more than doubling the best scalable baseline (5.1%).
Figure 1: Qualitative example for Warcraft Pathfinding. GT stands for ground truth.
Table 2: Warcraft Pathfinding Task.
  • MNIST Arithmetic: CASPER is the only exact-satisfaction method to scale beyond $n=2$, smoothly reaching 1024 digits on MNIST-Sum at 240.3s per epoch (matching the speed of approximate tensor-sketching methods while beating their accuracy for all $n \ge 16$). Replacing CASPER's closed-form surrogate with an exact cvxpy solver causes it to time out at $n=1024$.
  • Sudoku Solving: Placed atop both a pretrained neural solver and a finetuned LLM (Qwen2.5-14B-Instruct), CASPER more than doubles intermediate board accuracy from ~25% to ~66%, while recovering nearly 95% of upstream CNN digit-recognition errors.

Limitations and Future Work

While inference is fast once compiled, the offline COMPILE step isn't magic: Theorem 5 shows its time and space complexity grow exponentially with the conflict width $w^\star(d)$ of the constraint graph along the chosen variable ordering $d$. If a problem has densely tangled constraints where every variable directly restricts every other variable, offline compilation faces the same worst-case exponential blowup as classical directional resolution. Furthermore, CASPER relies on a user-specified variable ordering, and on tasks where domain-specific dynamic programming exists (like hand-crafted carry recursions in DeepSoftLog for 100-digit MNIST-Add), tailored approximate/specialized architectures can still edge out CASPER in raw accuracy (28.0% vs. 13.8%). Explicit directions for future work are not discussed in the main paper.

Summary updated

Abstract

Many real-world problems demand exact constraint satisfaction to be meaningfully solved, yet existing neurosymbolic methods face a stark trade-off: those that guarantee satisfaction fail to scale, while those that scale must resort to approximation. Meanwhile, traditional deep learning approaches offer no satisfaction guarantees at all. In this paper, we propose Casper, a neurosymbolic layer that simultaneously (i) guarantees constraint satisfaction, (ii) scales at inference time, (iii) is fully automated, requiring no problem-specific engineering, and (iv) is fully differentiable, making it composable with any neural predictor both at training and at inference time. Casper casts constraint satisfaction as a closed-form Euclidean projection onto the constraint-feasible region, computable in a single forward pass. Experiments across MNIST arithmetic (up to 1024 digits), Sudoku solving, and Warcraft pathfinding show that Casper is the only method that produces guaranteed-valid outputs at scale: on 30×30 Warcraft grids, exact baselines time out and approximate ones produce valid paths less than 7% of the time, while Casper produces them 100% of the time.
BibTeX
@inproceedings{konathala2026casper,
  author = {Lohith Konathala and Luca Andolfi and Eleonora Giunchiglia},
  title = {{Casper: A Projection-Based Neurosymbolic Layer for Scalable \& Guaranteed Constraint Satisfaction}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=nKVmBxaagL},
}
Figure