30
30
# ****************************************************************************
31
31
32
32
import re
33
- import os
33
+ from pathlib import Path
34
34
35
35
from sage .env import SAGE_ENV
36
36
from sage .misc .cachefunc import cached_method , cached_function
48
48
from sage .misc .lazy_import import lazy_import
49
49
lazy_import ('sage.categories.simplicial_sets' , 'SimplicialSets' )
50
50
51
+ kenzo_path = Path (SAGE_ENV ['SAGE_EXTCODE' ]) / 'kenzo'
52
+
51
53
52
54
# ######################################################################
53
55
# The nerve of a finite monoid, used in sage.categories.finite_monoid.
@@ -96,7 +98,7 @@ def __init__(self, monoid):
96
98
# of monoid elements). Omit the base point.
97
99
self ._simplex_data = ()
98
100
99
- def __eq__ (self , other ):
101
+ def __eq__ (self , other ) -> bool :
100
102
"""
101
103
Return ``True`` if ``self`` and ``other`` are equal.
102
104
@@ -119,7 +121,7 @@ def __eq__(self, other):
119
121
and self ._monoid == other ._monoid
120
122
and self .base_point () == other .base_point ())
121
123
122
- def __ne__ (self , other ):
124
+ def __ne__ (self , other ) -> bool :
123
125
"""
124
126
Return the negation of `__eq__`.
125
127
@@ -214,13 +216,13 @@ def n_skeleton(self, n):
214
216
face_dict [(g ,)] = x
215
217
start = 1
216
218
217
- for d in range (start + 1 , n + 1 ):
219
+ for d in range (start + 1 , n + 1 ):
218
220
for g in monoid :
219
221
if g == one :
220
222
continue
221
223
new_faces = {}
222
224
for t in face_dict .keys ():
223
- if len (t ) != d - 1 :
225
+ if len (t ) != d - 1 :
224
226
continue
225
227
# chain: chain of group elements to multiply,
226
228
# as a tuple.
@@ -235,8 +237,8 @@ def n_skeleton(self, n):
235
237
236
238
# Compute faces of x.
237
239
faces = [face_dict [chain [1 :]]]
238
- for i in range (d - 1 ):
239
- product = chain [i ] * chain [i + 1 ]
240
+ for i in range (d - 1 ):
241
+ product = chain [i ] * chain [i + 1 ]
240
242
if product == one :
241
243
# Degenerate.
242
244
if d == 2 :
@@ -294,11 +296,11 @@ def Sphere(n):
294
296
w_0 = AbstractSimplex (0 , name = 'w_0' )
295
297
return SimplicialSet_finite ({v_0 : None , w_0 : None }, base_point = v_0 ,
296
298
name = 'S^0' )
297
- degens = range (n - 2 , - 1 , - 1 )
299
+ degens = range (n - 2 , - 1 , - 1 )
298
300
degen_v = v_0 .apply_degeneracies (* degens )
299
301
sigma = AbstractSimplex (n , name = 'sigma_{}' .format (n ),
300
302
latex_name = '\\ sigma_{}' .format (n ))
301
- return SimplicialSet_finite ({sigma : [degen_v ] * (n + 1 )}, base_point = v_0 ,
303
+ return SimplicialSet_finite ({sigma : [degen_v ] * (n + 1 )}, base_point = v_0 ,
302
304
name = 'S^{}' .format (n ),
303
305
latex_name = 'S^{{{}}}' .format (n ))
304
306
@@ -616,22 +618,20 @@ def ComplexProjectiveSpace(n):
616
618
latex_name = 'CP^{2}' )
617
619
return K
618
620
if n == 3 :
619
- file = os . path . join ( SAGE_ENV [ 'SAGE_EXTCODE' ], 'kenzo' , 'CP3.txt' )
621
+ file = kenzo_path / 'CP3.txt'
620
622
data = simplicial_data_from_kenzo_output (file )
621
- v = [_ for _ in data .keys () if _ .dimension () == 0 ][0 ]
622
- K = SimplicialSet_finite (data , base_point = v , name = 'CP^3' ,
623
- latex_name = 'CP^{3}' )
624
- return K
623
+ v = [sigma for sigma in data if sigma .dimension () == 0 ][0 ]
624
+ return SimplicialSet_finite (data , base_point = v , name = 'CP^3' ,
625
+ latex_name = 'CP^{3}' )
625
626
if n == 4 :
626
- file = os . path . join ( SAGE_ENV [ 'SAGE_EXTCODE' ], 'kenzo' , 'CP4.txt' )
627
+ file = kenzo_path / 'CP4.txt'
627
628
data = simplicial_data_from_kenzo_output (file )
628
- v = [_ for _ in data .keys () if _ .dimension () == 0 ][0 ]
629
- K = SimplicialSet_finite (data , base_point = v , name = 'CP^4' ,
630
- latex_name = 'CP^{4}' )
631
- return K
629
+ v = [sigma for sigma in data if sigma .dimension () == 0 ][0 ]
630
+ return SimplicialSet_finite (data , base_point = v , name = 'CP^4' ,
631
+ latex_name = 'CP^{4}' )
632
632
633
633
634
- def simplicial_data_from_kenzo_output (filename ):
634
+ def simplicial_data_from_kenzo_output (filename ) -> dict :
635
635
"""
636
636
Return data to construct a simplicial set, given Kenzo output.
637
637
@@ -649,7 +649,8 @@ def simplicial_data_from_kenzo_output(filename):
649
649
650
650
sage: from sage.topology.simplicial_set_examples import simplicial_data_from_kenzo_output
651
651
sage: from sage.topology.simplicial_set import SimplicialSet
652
- sage: sphere = os.path.join(SAGE_ENV['SAGE_EXTCODE'], 'kenzo', 'S4.txt')
652
+ sage: from pathlib import Path
653
+ sage: sphere = Path(SAGE_ENV['SAGE_EXTCODE']) / 'kenzo' /'S4.txt'
653
654
sage: S4 = SimplicialSet(simplicial_data_from_kenzo_output(sphere)) # needs pyparsing
654
655
sage: S4.homology(reduced=False) # needs pyparsing
655
656
{0: Z, 1: 0, 2: 0, 3: 0, 4: Z}
@@ -667,7 +668,7 @@ def simplicial_data_from_kenzo_output(filename):
667
668
dim_idx = data .find ('Dimension = {}:' .format (dim ), start )
668
669
while dim_idx != - 1 :
669
670
start = dim_idx + len ('Dimension = {}:' .format (dim ))
670
- new_dim_idx = data .find ('Dimension = {}:' .format (dim + 1 ), start )
671
+ new_dim_idx = data .find ('Dimension = {}:' .format (dim + 1 ), start )
671
672
if new_dim_idx == - 1 :
672
673
end = len (data )
673
674
else :
0 commit comments