Skip to content

feat(math): add quadratic forms domain with evaluate, discriminant, signature (#1841) - #2027

Open
morluto wants to merge 1 commit into
mainfrom
agent/quadratic-forms-1841
Open

feat(math): add quadratic forms domain with evaluate, discriminant, signature (#1841)#2027
morluto wants to merge 1 commit into
mainfrom
agent/quadratic-forms-1841

Conversation

@morluto

@morluto morluto commented Aug 18, 2026

Copy link
Copy Markdown
Owner

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:

  • Identity form evaluation, diagonal forms, cross-term forms
  • Identity and diagonal discriminants
  • Positive definite, indefinite, and negative definite signature classification
  • Non-symmetric matrix rejection

Continue this on Linzumi

…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.
@morluto morluto added feature epic: execute Execute: math.run honesty, results, verify path domain: algebra Algebra and algebraic operations domain: number-theory Number theory, arithmetic, and arithmetic functions request: math-operation Request to add or extend a user-facing mathematical operation labels Aug 18, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@morluto morluto left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

morluto commented Aug 18, 2026

Copy link
Copy Markdown
Owner Author

Deep review summary

Verdict: REQUEST CHANGES — converting algebraic eigenvalues with int() destroys their signs and produces wrong inertia.

int(eigenval) is not a sign test. Symmetric integer matrices may have irrational eigenvalues between -1 and 1, and 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. The implementation converts them to 0 and 1, returning inertia (1,0,1) and is_indefinite=False. The true inertia is (1,1,0), so the form is indefinite.

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 det(A) kernel are exact. Calling det(A) the discriminant is representation- and convention-dependent; Gram determinant is less ambiguous unless the chosen quadratic-form convention is documented explicitly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain: algebra Algebra and algebraic operations domain: number-theory Number theory, arithmetic, and arithmetic functions epic: execute Execute: math.run honesty, results, verify path feature request: math-operation Request to add or extend a user-facing mathematical operation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant