Casper: A Projection-Based Neurosymbolic Layer for Scalable & Guaranteed Constraint Satisfaction
Organizations: Imperial College London
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 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.
Figures & tables
| Method | SPL [ 3 ] | CCN+ [ 25 ] | DSL [ 35 ] | Scallop [ 30 ] | A-NeSI [ 49 ] | CTSketch [ 10 ] | Casper |
|---|---|---|---|---|---|---|---|
| Sat | ✓ | ✓ | ✗ | ✗ | ✗ | ✗ | ✓ |
| Scale | ✗ | ✗ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Auto | ✓ | ✓ | ✓ | ✓ | ✓ | ✗ | ✓ |
| 12 12 | 30 30 | |||
| Method | Optimal(%) | Consistent (%) | Optimal(%) | Consistent (%) |
| ResNet-18 | 59.7\mbox{\scriptsize\pm 1.2} | 62.5\mbox{\scriptsize\pm 1.0} | 5.1\mbox{\scriptsize\pm 0.6} | 6.4\mbox{\scriptsize\pm 1.1} |
| Exact Methods | ||||
| DPL | T/O | T/O | T/O | T/O |
| CCN+ | 74.2\mbox{\scriptsize\pm 0.6} | \mathbf{100.0}\mbox{\scriptsize\pm\mathbf{0.0}} | T/O | T/O |
| SPL | T/O | T/O | T/O | T/O |
| Method / | |||||
|---|---|---|---|---|---|
| Exact Methods | |||||
| DPL | 58.4 | T/O | T/O | T/O | T/O |
| CCN+ | 26.9 | T/O | T/O | T/O | T/O |
| SPL | 4.1 | T/O | T/O | T/O | T/O |
| Approximate Methods | |||||
| A-NeSI | 11.8 | 24.7 | 66.4 | 232.3 | 995.8 |
| Method | NeuroAcc | RecRate | PipeAcc |
|---|---|---|---|
| Board solver from [ 11 ] | |||
| A-NesI | 18.9\mbox{\scriptsize\pm 7.3} | 89.5\mbox{\scriptsize\pm 1.3} | 70.0\mbox{\scriptsize\pm 24.7} |
| CTSketch | 25.2\mbox{\scriptsize\pm 0.3} | 88.2\mbox{\scriptsize\pm 2.3} | 81.0\mbox{\scriptsize\pm 1.7} |
| Casper | 66.0 | 94.2 | 84.7 |
| LLM board solver (Qwen2.5-14B-Instruct finetuned) | |||
| A-NesI | 25.6\mbox{\scriptsize\pm 0.2} | 94.7\mbox{\scriptsize\pm 0.7} | 68.3\mbox{\scriptsize\pm 2.4} |
Appendix figures & tables11 assets
Supplementary material from the paper’s appendix.
Appendix
| BE-bel | Compile | |
| Variables, ordering | , | , |
| Max. domain size | ||
| Input functions | conditional probability table | relations , |
| Number of inputs | ||
| Combination | product | natural join |
| Marginalization | sum | projection |
| Label | Terrain Type | Cost |
|---|---|---|
| Land | Grass / Open Ground | 0.8 |
| Dirt | Dirt / Coast | 1.2 |
| Forest & Mountains | Forest | 5.3 |
| Forest & Mountains | Mountains | 7.7 |
| Water | Water | 9.2 |
| Peak Memory (GB) | Epoch Time (s) | |||
| Method | ||||
| Exact Methods | ||||
| DPL | T/O | T/O | T/O | T/O |
| SPL | T/O | T/O | T/O | T/O |
| CCN+ | 9.93 | T/O | 202.8 | T/O |
| Approximate Methods | ||||
| Method | EM | Optimal | Hamming | Consistent | |||
|---|---|---|---|---|---|---|---|
| == | |||||||
| ResNet-18 | 58.5\mbox{\scriptsize\pm 1.4} | 59.7\mbox{\scriptsize\pm 1.2} | 60.4\mbox{\scriptsize\pm 1.2} | 61.4\mbox{\scriptsize\pm 1.1} | 61.8\mbox{\scriptsize\pm 1.2} | 98.3\mbox{\scriptsize\pm 0.1} | 62.5\mbox{\scriptsize\pm 1.0} |
| Exact Methods | |||||||
| CCN+ | 68.6\mbox{\scriptsize\pm 0.8} | 74.2\mbox{\scriptsize\pm 0.6} | 76.5\mbox{\scriptsize\pm 0.5} | 81.6\mbox{\scriptsize\pm 0.1} | 84.2\mbox{\scriptsize\pm 0.2} | 97.5\mbox{\scriptsize\pm 0.0} | \mathbf{100.0}\mbox{\scriptsize\pm 0.0} |
| SPL | T/O | T/O | T/O | T/O | T/O | T/O | T/O |
| DPL | T/O | T/O | T/O | T/O | T/O | T/O | T/O |
| Method | EM | Optimal | Hamming | Consistent | |||
|---|---|---|---|---|---|---|---|
| == | |||||||
| ResNet-18 | 5.1\mbox{\scriptsize\pm 0.6} | 5.1\mbox{\scriptsize\pm 0.6} | 5.3\mbox{\scriptsize\pm 0.7} | 5.9\mbox{\scriptsize\pm 0.9} | 6.1\mbox{\scriptsize\pm 0.9} | 97.5\mbox{\scriptsize\pm 0.0} | 6.4\mbox{\scriptsize\pm 1.1} |
| Exact Methods | |||||||
| CCN+ | T/O | T/O | T/O | T/O | T/O | T/O | T/O |
| SPL | T/O | T/O | T/O | T/O | T/O | T/O | T/O |
| DPL | T/O | T/O | T/O | T/O | T/O | T/O | T/O |
| Method | sum 2 | sum 16 | sum 64 | sum 256 | sum 1024 |
|---|---|---|---|---|---|
| Exact Methods | |||||
| DPL | 97.2\mbox{\scriptsize\pm 0.5} | T/O | T/O | T/O | T/O |
| SPL | 96.7\mbox{\scriptsize\pm 0.5} | T/O | T/O | T/O | T/O |
| CCN+ | \mathbf{97.4\mbox{\scriptsize\pm 0.7}} | T/O | T/O | T/O | T/O |
| Approximate Methods | |||||
| A-NeSI | 96.0\mbox{\scriptsize\pm 0.2} | 27.8\mbox{\scriptsize\pm 4.6} | 12.9\mbox{\scriptsize\pm 1.6} | 5.1\mbox{\scriptsize\pm 0.1} | 2.0\mbox{\scriptsize\pm 0.2} |
| Metric | No Casper | Casper (Inference) | Casper (Train + Inference) |
|---|---|---|---|
| Digit Acc. (%) | 98.8\mbox{\scriptsize\pm 0.1} | 98.9\mbox{\scriptsize\pm 0.2} | 99.0 |
| Sum Acc. (%) | 4.3\mbox{\scriptsize\pm 0.6} | 84.0\mbox{\scriptsize\pm 2.9} | \mathbf{85.8\mbox{\scriptsize\pm 1.6}} |
| Consistency (%) | 4.3\mbox{\scriptsize\pm 0.6} | 100.0 | 100.0 |
| Avg. Edit | N/A | ||
| Method | add 1 | add 2 | add 4 | add 15 | add 100 | add 256 |
|---|---|---|---|---|---|---|
| Exact Methods | ||||||
| DPL | 97.1\mbox{\scriptsize\pm 0.2} | 89.5\mbox{\scriptsize\pm 0.6} | T/O | T/O | T/O | T/O |
| SPL | 96.7\mbox{\scriptsize\pm 0.6} | T/O | T/O | T/O | T/O | T/O |
| CCN+ | 98.4\mbox{\scriptsize\pm 0.2} | T/O | T/O | T/O | T/O | T/O |
| Approximate Methods | ||||||
| A-NeSI | 97.4\mbox{\scriptsize\pm 0.2} | 96.3\mbox{\scriptsize\pm 0.4} | 93.1\mbox{\scriptsize\pm 0.7} | 76.9\mbox{\scriptsize\pm 2.3} | ERR | ERR |
| Operand 1 | Operand 2 | Sum | ||||||
| Method | Exact | Macro | Exact | Macro | Exact | Macro | ||
| DPL | 98.4\mbox{\scriptsize\pm 0.2} | 98.4\mbox{\scriptsize\pm 0.2} | 98.5\mbox{\scriptsize\pm 0.2} | 98.5\mbox{\scriptsize\pm 0.2} | 97.1\mbox{\scriptsize\pm 0.2} | 97.9\mbox{\scriptsize\pm 0.2} | ||
| SPL | 98.5\mbox{\scriptsize\pm 0.4} | 98.5\mbox{\scriptsize\pm 0.4} | 98.1\mbox{\scriptsize\pm 0.4} | 98.1\mbox{\scriptsize\pm 0.4} | 96.7\mbox{\scriptsize\pm 0.6} | 97.6\mbox{\scriptsize\pm 0.4} | ||
| CCN+ | \mathbf{99.2\mbox{\scriptsize\pm 0.1}} | \mathbf{99.2\mbox{\scriptsize\pm 0.1}} | 99.0\mbox{\scriptsize\pm 0.1} | 99.0\mbox{\scriptsize\pm 0.1} | 98.4\mbox{\scriptsize\pm 0.2} | \mathbf{98.9\mbox{\scriptsize\pm 0.1}} | ||
| A-NeSI | 98.6\mbox{\scriptsize\pm 0.2} | 98.6\mbox{\scriptsize\pm 0.2} | 98.7\mbox{\scriptsize\pm 0.2} | 98.7\mbox{\scriptsize\pm 0.2} | 97.4\mbox{\scriptsize\pm 0.2} | 98.2\mbox{\scriptsize\pm 0.2} | ||
| Scallop | 97.7\mbox{\scriptsize\pm 0.5} | 97.7\mbox{\scriptsize\pm 0.5} | 97.5\mbox{\scriptsize\pm 0.5} | 97.5\mbox{\scriptsize\pm 0.5} | 95.3\mbox{\scriptsize\pm 0.7} | 96.6\mbox{\scriptsize\pm 0.5} | ||
| Peak Memory (MB) | Epoch Time (s) | |||||||||
| Method / | ||||||||||
| Exact Methods | ||||||||||
| DPL | 20.1 | T/O | T/O | T/O | T/O | 58.4 | T/O | T/O | T/O | T/O |
| SPL | 39.8 | T/O | T/O | T/O | T/O | 4.1 | T/O | T/O | T/O | T/O |
| CCN+ | 56.7 | T/O | T/O | T/O | T/O | 26.9 | T/O | T/O | T/O | T/O |
| Approximate Methods | ||||||||||
Neuro-Symbolic Reasoning
Neuro-symbolic reasoning combines learned neural models with explicit logic, rules, knowledge structures, or executable tools to solve structured tasks.
See all 300 papers