Skip to content

Commit

Permalink
sagemathgh-37098: Fixed random_element() for fractional ideals in rat…
Browse files Browse the repository at this point in the history
…ional quaternion algebras

    
Added `QuaternionFractionalIdeal_rational.random_element()` to fix
random sampling in fractional ideals of quaternion algebras.

The method `.random_element()` of the ideal class refers to the ring
over which the ideal is defined, but for fractional ideals Sage often
(incorrectly) gives the base field of the algebra as a base ring. To
work around this, we implement a new function
`QuaternionFractionalIdeal_rational.random_element()` that hardcodes
$\mathbb{Z}$ to return a random $\mathbb{Z}$-linear combination of the
(lattice) generators of the fractional ideal.

Note: The deeper issue of separating ideals and fractional ideals still
remains - see sagemath#3680.

#sd123
    
URL: sagemath#37098
Reported by: Sebastian Spindler
Reviewer(s): Peter Bruin
  • Loading branch information
Release Manager committed Jan 20, 2024
2 parents 6224890 + 22f63e0 commit 507c389
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/sage/algebras/quatalg/quaternion_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -2295,6 +2295,20 @@ def __repr__(self):
"""
return 'Fractional ideal %s' % (self.gens(),)

def random_element(self, *args, **kwds):
"""
Return a random element in the rational fractional ideal ``self``.
EXAMPLES::
sage: B.<i,j,k> = QuaternionAlgebra(211)
sage: I = B.ideal([1, 1/4*j, 20*(i+k), 2/3*i])
sage: x = I.random_element() # random
sage: x in I
True
"""
return sum(ZZ.random_element(*args, **kwds) * g for g in self.gens())

def quaternion_order(self):
"""
Return the order for which this ideal is a left or right
Expand Down

0 comments on commit 507c389

Please sign in to comment.