feat(math): add quadratic forms domain with evaluate, discriminant, signature (#1841) - #2027
feat(math): add quadratic forms domain with evaluate, discriminant, signature (#1841)#2027morluto wants to merge 1 commit into
Conversation
…ignature Create the quadratic_forms domain with three operations: - quadratic_form.evaluate.compute: exact q(x) = x^T A x for an integral symmetric matrix and integer vector. - quadratic_form.discriminant.compute: exact det(A) via SymPy integer matrix computation. - quadratic_form.signature.compute: inertia (n_pos, n_neg, n_zero) via SymPy eigenvalue computation, with definiteness classification. Partially addresses #1841.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
morluto
left a comment
There was a problem hiding this comment.
Review verdict: blocked — eigenvalue signs are destroyed by integer conversion
int(eigenval) is not a sign test. Symmetric integer matrices can have irrational algebraic eigenvalues between -1 and 1, and Python/SymPy integer conversion truncates them to zero.
Canonical counterexample:
A = ((0, 1),
(1, 1))Its eigenvalues are (1 ± sqrt(5))/2, approximately -0.618 and 1.618. This implementation converts them to 0 and 1, returning (n_positive, n_negative, n_zero) = (1,0,1) and is_indefinite=False. The true inertia is (1,1,0) and the form is indefinite.
Please compute inertia by an exact sign-preserving method—e.g. exact symmetric congruence/LDL-style elimination with pivoting, or exact real-root/sign isolation—not by casting algebraic numbers. Add this matrix and a singular semidefinite matrix as regression tests. Sage's quadratic-form API defines the signature vector precisely as counts of positive, negative, and zero eigenvalues, so truncation cannot be part of the semantics.
The evaluation kernel and det(A) kernel are exact. Naming det(A) a “discriminant” is convention-dependent across quadratic-form representations; Gram determinant would be less ambiguous unless the chosen convention is documented explicitly.
Deep review summaryVerdict: REQUEST CHANGES — converting algebraic eigenvalues with
Canonical counterexample: A = ((0, 1),
(1, 1))Its eigenvalues are Compute inertia by an exact sign-preserving method, such as exact symmetric congruence/LDL-style elimination with pivoting or exact real-root/sign isolation. Add this matrix and a singular semidefinite matrix as regressions. The evaluation kernel and |
Summary
Create the domain with three operations, partially addressing #1841.
Operations
quadratic_form.evaluate.compute— Exact integer evaluation q(x) = x^T A x for an integral symmetric matrix and integer vector.quadratic_form.discriminant.compute— Exact determinant det(A) via SymPy integer matrix computation.quadratic_form.signature.compute— Inertia (n_positive, n_negative, n_zero) via SymPy eigenvalue computation, with positive/negative definite and indefinite classification.Library choice
SymPy's and provide exact integer matrix operations, avoiding floating-point approximations and hand-rolled eigenvalue algorithms.
Tests
9 known-answer tests covering:
Continue this on Linzumi