Coverage for /usr/lib/python3/dist-packages/sympy/polys/numberfields/exceptions.py: 100%

7 statements  

« prev     ^ index     » next       coverage.py v7.9.1, created at 2025-06-14 15:55 +0200

1"""Special exception classes for numberfields. """ 

2 

3 

4class ClosureFailure(Exception): 

5 r""" 

6 Signals that a :py:class:`ModuleElement` which we tried to represent in a 

7 certain :py:class:`Module` cannot in fact be represented there. 

8 

9 Examples 

10 ======== 

11 

12 >>> from sympy.polys import Poly, cyclotomic_poly, ZZ 

13 >>> from sympy.polys.matrices import DomainMatrix 

14 >>> from sympy.polys.numberfields.modules import PowerBasis, to_col, ClosureFailure 

15 >>> from sympy.testing.pytest import raises 

16 >>> T = Poly(cyclotomic_poly(5)) 

17 >>> A = PowerBasis(T) 

18 >>> B = A.submodule_from_matrix(2 * DomainMatrix.eye(4, ZZ)) 

19 

20 Because we are in a cyclotomic field, the power basis ``A`` is an integral 

21 basis, and the submodule ``B`` is just the ideal $(2)$. Therefore ``B`` can 

22 represent an element having all even coefficients over the power basis: 

23 

24 >>> a1 = A(to_col([2, 4, 6, 8])) 

25 >>> print(B.represent(a1)) 

26 DomainMatrix([[1], [2], [3], [4]], (4, 1), ZZ) 

27 

28 but ``B`` cannot represent an element with an odd coefficient: 

29 

30 >>> a2 = A(to_col([1, 2, 2, 2])) 

31 >>> print(raises(ClosureFailure, lambda: B.represent(a2))) 

32 <ExceptionInfo ClosureFailure('Element in QQ-span but not ZZ-span of this basis.')> 

33 

34 """ 

35 pass 

36 

37 

38class StructureError(Exception): 

39 r""" 

40 Represents cases in which an algebraic structure was expected to have a 

41 certain property, or be of a certain type, but was not. 

42 """ 

43 pass 

44 

45 

46class MissingUnityError(StructureError): 

47 r"""Structure should contain a unity element but does not.""" 

48 pass 

49 

50 

51__all__ = [ 

52 'ClosureFailure', 'StructureError', 'MissingUnityError', 

53]