Summary
Implement the random rotation matrix Π used by PolarQuant. This is the first mathematical building block — everything else depends on it.
Paper Reference
- Paper: arXiv 2504.19874, Section 1.3 and Algorithm 1
- Key property: Random rotation makes each coordinate follow Beta(d/2, d/2) → Gaussian N(0, 1/d) for large d
- The rotation must be Haar-distributed (uniformly random orthogonal matrix)
Requirements
Dense rotation (primary)
- Generate Haar-distributed random rotation via QR decomposition of Gaussian matrix
- Ensure det(Π) = +1 (proper rotation, not reflection) by correcting signs via diagonal of R
- Must be deterministic given a seed (for reproducibility)
- Input: dimension d, NumPy random generator
- Output: orthogonal matrix Π ∈ R^(d×d)
Fast structured rotation (optimization, can be deferred)
- Walsh-Hadamard + random sign flips: O(d log d) instead of O(d²)
- Pad to next power of 2
- Separate
apply_fast_rotation and apply_fast_rotation_transpose functions
- Batch version for multiple vectors
Tests Required (write FIRST)
- Orthogonality test: Π @ Π.T ≈ I (within numerical tolerance)
- Determinant test: det(Π) ≈ +1
- Deterministic test: same seed → same matrix
- Different seeds test: different seeds → different matrices
- Rotation preserves norms: ||Π @ x|| ≈ ||x|| for random x
- Rotation preserves inner products: ⟨Π@x, Π@y⟩ ≈ ⟨x, y⟩
- Post-rotation distribution test: after rotating many random unit vectors, each coordinate should have mean ≈ 0 and variance ≈ 1/d
- Fast rotation matches dense (if implemented): apply_fast_rotation(x) produces similar statistical properties
Acceptance Criteria
Summary
Implement the random rotation matrix Π used by PolarQuant. This is the first mathematical building block — everything else depends on it.
Paper Reference
Requirements
Dense rotation (primary)
Fast structured rotation (optimization, can be deferred)
apply_fast_rotationandapply_fast_rotation_transposefunctionsTests Required (write FIRST)
Acceptance Criteria