Ticket #6762: 6762-in-qa.patch

File 6762-in-qa.patch, 1.7 KB (added by robertwb, 12 years ago)
  • sage/algebras/quatalg/quaternion_algebra.py

    # HG changeset patch
    # User Robert Bradshaw <robertwb@math.washington.edu>
    # Date 1250414213 25200
    # Node ID 3d818c9be3620b5a8d3ea323f204e657d4cac4c7
    # Parent  55d0de322e72bafaac2ce7fbef9b526b16fe9fa4
    Trac #6762, add __contains__ to quaternion algebra ideals over Q.
    
    diff -r 55d0de322e72 -r 3d818c9be362 sage/algebras/quatalg/quaternion_algebra.py
    a b  
    5252from sage.structure.sequence import Sequence
    5353from sage.structure.element import is_Element
    5454from sage.modules.free_module import VectorSpace, FreeModule
     55from sage.modules.free_module_element import vector
    5556
    5657import quaternion_algebra_element
    5758import quaternion_algebra_cython
     
    17791780        #    that N(alpha) = N(I)*N(J) as explained by Pizer.
    17801781        c = IJbar.theta_series_vector(2)[1]
    17811782        return c != 0
     1783   
     1784    def __contains__(self, x):
     1785        """
     1786        Returns whether x is in self.
     1787       
     1788        EXAMPLES::
     1789            sage: R.<i,j,k> = QuaternionAlgebra(-3, -13)
     1790            sage: I = R.ideal([2+i, 3*i, 5*j, j+k])
     1791            sage: 2+i in I
     1792            True
     1793            sage: 2+i+j+k in I
     1794            True
     1795            sage: 1+i in I
     1796            False
     1797            sage: 101*j + k in I
     1798            True
     1799        """
     1800        try:
     1801            x = self.quaternion_algebra()(x)
     1802            return self.basis_matrix().transpose().solve_right(vector(x)) in ZZ**4
     1803        except (ValueError, TypeError):
     1804            return False
    17821805
    17831806#######################################################################
    17841807# Some utility functions that are needed here and are too