|
49 | 49 | from copy import copy |
50 | 50 | from functools import reduce |
51 | 51 |
|
52 | | -from sage.structure.parent import Parent |
53 | | -from sage.structure.element import ModuleElement, Vector, coercion_model |
| 52 | +from sage.homology.homology_group import HomologyGroup |
| 53 | +from sage.matrix.constructor import matrix |
| 54 | +from sage.matrix.matrix0 import Matrix |
54 | 55 | from sage.misc.cachefunc import cached_method |
55 | | - |
56 | | -from sage.rings.integer_ring import ZZ |
| 56 | +from sage.misc.latex import latex |
| 57 | +from sage.misc.persist import register_unpickle_override |
57 | 58 | from sage.modules.free_module import FreeModule |
58 | 59 | from sage.modules.free_module_element import vector |
59 | | -from sage.matrix.matrix0 import Matrix |
60 | | -from sage.matrix.constructor import matrix |
61 | | -from sage.misc.latex import latex |
62 | 60 | from sage.rings.fast_arith import prime_range |
63 | | -from sage.homology.homology_group import HomologyGroup |
64 | | -from sage.misc.persist import register_unpickle_override |
| 61 | +from sage.rings.integer_ring import ZZ |
| 62 | +from sage.structure.element import ModuleElement, Vector, coercion_model |
| 63 | +from sage.structure.parent import Parent |
65 | 64 |
|
66 | 65 |
|
67 | 66 | def _latex_module(R, m): |
68 | | - """ |
| 67 | + r""" |
69 | 68 | LaTeX string representing a free module over ``R`` of rank ``m``. |
70 | 69 |
|
71 | 70 | INPUT: |
@@ -1321,35 +1320,34 @@ def change_ring(X): |
1321 | 1320 | for order, gen in zip(orders, gens)] |
1322 | 1321 | else: |
1323 | 1322 | answer = [] |
1324 | | - else: |
1325 | | - if base_ring.is_field(): |
1326 | | - d_in_rank = self.rank(deg-differential, ring=base_ring) |
1327 | | - answer = HomologyGroup(d_out_nullity - d_in_rank, base_ring) |
1328 | | - elif base_ring == ZZ: |
1329 | | - if d_in.ncols() == 0: |
1330 | | - all_divs = [0] * d_out_nullity |
1331 | | - else: |
1332 | | - if algorithm in ['auto', 'no_chomp']: |
1333 | | - if ((d_in.ncols() > 300 and d_in.nrows() > 300) |
1334 | | - or (min(d_in.ncols(), d_in.nrows()) > 100 and |
1335 | | - d_in.ncols() + d_in.nrows() > 600)): |
1336 | | - algorithm = 'dhsw' |
1337 | | - else: |
1338 | | - algorithm = 'pari' |
1339 | | - if algorithm == 'dhsw': |
1340 | | - from sage.homology.matrix_utils import dhsw_snf |
1341 | | - all_divs = dhsw_snf(d_in, verbose=verbose) |
1342 | | - elif algorithm == 'pari': |
1343 | | - all_divs = d_in.elementary_divisors(algorithm) |
1344 | | - else: |
1345 | | - raise ValueError('unsupported algorithm') |
1346 | | - all_divs = all_divs[:d_out_nullity] |
1347 | | - # divisors equal to 1 produce trivial |
1348 | | - # summands, so filter them out |
1349 | | - divisors = [x for x in all_divs if x != 1] |
1350 | | - answer = HomologyGroup(len(divisors), base_ring, divisors) |
| 1323 | + elif base_ring.is_field(): |
| 1324 | + d_in_rank = self.rank(deg-differential, ring=base_ring) |
| 1325 | + answer = HomologyGroup(d_out_nullity - d_in_rank, base_ring) |
| 1326 | + elif base_ring == ZZ: |
| 1327 | + if d_in.ncols() == 0: |
| 1328 | + all_divs = [0] * d_out_nullity |
1351 | 1329 | else: |
1352 | | - raise NotImplementedError('only base rings ZZ and fields are supported') |
| 1330 | + if algorithm in ['auto', 'no_chomp']: |
| 1331 | + if ((d_in.ncols() > 300 and d_in.nrows() > 300) |
| 1332 | + or (min(d_in.ncols(), d_in.nrows()) > 100 and |
| 1333 | + d_in.ncols() + d_in.nrows() > 600)): |
| 1334 | + algorithm = 'dhsw' |
| 1335 | + else: |
| 1336 | + algorithm = 'pari' |
| 1337 | + if algorithm == 'dhsw': |
| 1338 | + from sage.homology.matrix_utils import dhsw_snf |
| 1339 | + all_divs = dhsw_snf(d_in, verbose=verbose) |
| 1340 | + elif algorithm == 'pari': |
| 1341 | + all_divs = d_in.elementary_divisors(algorithm) |
| 1342 | + else: |
| 1343 | + raise ValueError('unsupported algorithm') |
| 1344 | + all_divs = all_divs[:d_out_nullity] |
| 1345 | + # divisors equal to 1 produce trivial |
| 1346 | + # summands, so filter them out |
| 1347 | + divisors = [x for x in all_divs if x != 1] |
| 1348 | + answer = HomologyGroup(len(divisors), base_ring, divisors) |
| 1349 | + else: |
| 1350 | + raise NotImplementedError('only base rings ZZ and fields are supported') |
1353 | 1351 | return answer |
1354 | 1352 |
|
1355 | 1353 | def _homology_generators_snf(self, d_in, d_out, d_out_rank): |
@@ -1769,7 +1767,7 @@ def module_art(n): |
1769 | 1767 | return concatenated |
1770 | 1768 |
|
1771 | 1769 | def _latex_(self): |
1772 | | - """ |
| 1770 | + r""" |
1773 | 1771 | LaTeX print representation. |
1774 | 1772 |
|
1775 | 1773 | EXAMPLES:: |
|
0 commit comments