XOR
XOR (exclusive OR) assigns to two bits the label : 1 when they differ and 0 when they agree. This case verifies a trained network on continuous regions around the four binary inputs.
Network
Definition 1. Trained network over the reals.
Let . The frozen parameters are
Each coefficient is the exact rational value of a trained binary32 parameter, recorded in the parameter definition. Define , applied coordinatewise to vectors. The preactivation and hidden maps and the score function are
The four hidden coordinates are indexed by ; the two class scores are and . All operations in this definition use exact real arithmetic.
The hidden layer multiplies inputs by weights, adds biases, and sets negative results to zero. The output layer combines the hidden values into two scores; the larger score selects the class. Scores are not probabilities. Training fixes the 22 coefficients after 1,000 Adam steps with seed 7, using 36 labelled examples.
Specification
Definition 2. Input regions and correct labels.
Define the two closed bands and four boxes by
The boxes are disjoint, so the correct-label function is well-defined by for . Thus and have label 0; the other two boxes have label 1. No property is specified outside .
Definition 3. Correct-class margin and XOR specification.
For any score function , its correct-class margin on is
The regional specification is the predicate
This is the mathematical form of XorSpec. A positive margin makes the correct score strictly larger, independently of any rule for ties.
Theorem 1. Regional XOR correctness over the reals.
The frozen trained network satisfies . In fact,
Lean checks trainedNetwork_satisfies_spec and the stronger trainedNetwork_margin_half theorem.
Proof.
Fixing the signs of the four preactivations makes the margin affine. For each box and each activation case, substituting the frozen rational coefficients reduces the claim to linear inequalities, which Lean discharges. The bounds include every point on each box's boundary.
- Predicted class
- 1
- Correct-class margin
- 0.95275
- Required bound in the theorem
- ¼
The output layer combines the hidden values with another set of weights and biases. The larger score selects the class.
Binary32 arithmetic
Definition 4. Rounded evaluation.
Let denote binary32 rounding to nearest with ties to even and gradual underflow. A finite result is identified with its exact real value. Round each original input coordinate once:
Write for the decoded class- score obtained by running the frozen network on . Each multiplication and addition rounds separately, sums associate to the left, and biases are added last. Define the decoded score difference and its separately rounded margin by
The label refers to the original real input, including band endpoints that are not exactly representable in binary32.
Theorem 2. Regional XOR correctness in the binary32 model.
For every , both computed scores and the rounded margin are finite, and
Lean checks floatLibNetwork_margin_real for the scores and floatLibNetwork_sub_margin_real for the rounded subtraction.
Proof.
Input rounding and the forward computation give for each . ReLU does not increase error. The final subtraction introduces at most additional error. Combining these bounds with Theorem 1 yields
Both theorems are checked by Lean's kernel for the frozen parameters and the stated arithmetic. Whole-network correspondence with native execution, decimal input parsing, and deployed hardware remains unproved. A numerical report or checker result does not establish either universal theorem for a new checkpoint.
Reproduce
Requires elan and a C compiler. Dependencies are pinned; no checkpoint is needed to build the proofs.
git clone https://github.com/Varifold-Lab/neural-spec.git
cd neural-spec
lake exe cache get
lake build
lake env lean scripts/Audit.lean
lake exe xor infer ieee 0.1 0.9
Training and numerical checks
lake exe xor smoke
lake exe xor train 1000 7 artifacts/xor.state
lake exe xor check artifacts/xor.state
lake exe xor parity
check reloads the trained weights. New checkpoints require new proofs.