Skip to content

Conversation

user202729
Copy link
Contributor

@user202729 user202729 commented Oct 8, 2025

see the newly added doctest, they previously fail.

this is a combination of two bugs

  • pari qfsolve function may return a matrix, but the original code does not handle this case
  • after finding a solution x, it's possible that there's no vector e such that B(x, e) != 0. In this case for any vector v, self(v) = self(v+λx), therefore it suffice to find solution in some subspace complement to x, if there exists a solution then there must exist one in that subspace by adding appropriate multiple of x.

📝 Checklist

  • The title is concise and informative.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation and checked the documentation preview.

⌛ Dependencies

Copy link

github-actions bot commented Oct 8, 2025

Documentation preview for this PR (built with commit 8c3442a; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

Comment on lines +290 to +297
if i >= d:
# Restrict the quadratic form to a subspace complement to x, then solve recursively
# note that complementary_subform_to_vector returns the orthogonal (not necessary complement)
# subspace with respect to self, which is not what we want
i = next(i for i in range(d) if x[i])
from sage.quadratic_forms.quadratic_form import QuadraticForm
x = QuadraticForm(self.matrix().delete_rows([0]).delete_columns([0])).solve(c)
return vector([*x[:i], 0, *x[i:]])
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I understand this condition here and why it's relevant now and it wasn't here before.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it has always been relevant, the previous code is just buggy to not include it (to be more precise, this branch is guaranteed to be not hit if the quadratic form is non-degenerate). Try running the code with the fix above (t_MAT) but not the one here and you'll see the IndexError caused by i >= d.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I have just tried on some example. Thanks for catching that.

...
ArithmeticError: no solution found (local obstruction at some prime factor of det(self.matrix()))
"""
def check_obstruction(x):
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you want this to be a publicly-documented function or just an internal one? If internal, rename to _check_obstruction.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

functions local to another function's body is inaccessible outside anyway, doesn't matter.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah true I didn't notice it was internal, my bad

Comment on lines -221 to +261
N = Matrix(self.base_ring(), d+1, d+1)
N = matrix(self.base_ring(), d+1, d+1)
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the difference between the two constructors?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

essentially no difference, but since now Matrix is imported as a different entity (the type), I give the constructor the other name. You can't call the type like how you call the matrix constructor.

Copy link
Contributor

@JosePisco JosePisco left a comment

Choose a reason for hiding this comment

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

good for me 👍

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants