Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Trac #33100: use a more reliable abs() replacement in is_hermitian().
Browse files Browse the repository at this point in the history
Some finite fields for which is_hermitian() otherwise works are
missing abs(). Here we use the square root of z*z.conjugate() as a
replacement, which appears to work in all of the cases we care about.
Note that this would probably do the wrong thing if you tried to use
a nonzero tolerance with an (exact) finite field.
  • Loading branch information
orlitzky committed Feb 12, 2022
1 parent b553988 commit c4977c4
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/sage/matrix/matrix0.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4043,17 +4043,18 @@ cdef class Matrix(sage.structure.element.Matrix):
for (i,j) in self.nonzero_positions():
d = self.get_unsafe(i,j) - s*self.get_unsafe(j,i).conjugate()

# avoid abs() which is missing for finite fields.
if d > tolerance or -d > tolerance:
# abs() support is spotty
if (d*d.conjugate()).sqrt() > tolerance:
self.cache(key, False)
return False
else:
for i in range(self._nrows):
for j in range(i+1):
d = ( self.get_unsafe(i,j)
- s*self.get_unsafe(j,i).conjugate() )
# avoid abs() which is missing for finite fields.
if d > tolerance or -d > tolerance:

# abs() support is spotty
if (d*d.conjugate()).sqrt() > tolerance:
self.cache(key, False)
return False

Expand Down

0 comments on commit c4977c4

Please sign in to comment.