@@ -151,12 +151,6 @@ def permutation_sign(p: Iterable[int]) -> int:
151
151
return s
152
152
153
153
154
- def bit_count (i : int ) -> int :
155
- """Count the number of set bits in *i*."""
156
-
157
- return i .bit_count ()
158
-
159
-
160
154
def canonical_reordering_sign (a_bits : int , b_bits : int ) -> int :
161
155
"""Count the number of basis vector swaps required to
162
156
get the combination of *a_bits* and *b_bits* into canonical order.
@@ -629,7 +623,7 @@ def stringify(self, coeff_stringifier, enclosing_prec):
629
623
630
624
terms = []
631
625
for bits in sorted (self .data .keys (),
632
- key = lambda _bits : (bit_count (_bits ), _bits )):
626
+ key = lambda _bits : (_bits . bit_count (), _bits )):
633
627
coeff = self .data [bits ]
634
628
635
629
# {{{ try to find a stringifier
@@ -868,7 +862,7 @@ def inv(self):
868
862
(bits , coeff ), = self .data .items ()
869
863
870
864
# (1.1.54) in [HS]
871
- grade = bit_count (bits )
865
+ grade = bits . bit_count ()
872
866
if grade * (grade - 1 )// 2 % 2 :
873
867
coeff = - coeff
874
868
@@ -884,7 +878,7 @@ def rev(self):
884
878
"""
885
879
new_data = {}
886
880
for bits , coeff in self .data .items ():
887
- grade = bit_count (bits )
881
+ grade = bits . bit_count ()
888
882
if grade * (grade - 1 )// 2 % 2 == 0 :
889
883
new_data [bits ] = coeff
890
884
else :
@@ -900,7 +894,7 @@ def invol(self):
900
894
"""
901
895
new_data = {}
902
896
for bits , coeff in self .data .items ():
903
- grade = bit_count (bits )
897
+ grade = bits . bit_count ()
904
898
if grade % 2 == 0 :
905
899
new_data [bits ] = coeff
906
900
else :
@@ -989,7 +983,7 @@ def gen_blades(self, grade=None):
989
983
yield MultiVector ({bits : coeff }, self .space )
990
984
else :
991
985
for bits , coeff in self .data .items ():
992
- if bit_count (bits ) == grade :
986
+ if bits . bit_count () == grade :
993
987
yield MultiVector ({bits : coeff }, self .space )
994
988
995
989
def project (self , r ):
@@ -999,7 +993,7 @@ def project(self, r):
999
993
"""
1000
994
new_data = {}
1001
995
for bits , coeff in self .data .items ():
1002
- if bit_count (bits ) == r :
996
+ if bits . bit_count () == r :
1003
997
new_data [bits ] = coeff
1004
998
1005
999
return MultiVector (new_data , self .space )
@@ -1019,7 +1013,7 @@ def xproject(self, r, dtype=None):
1019
1013
def all_grades (self ):
1020
1014
"""Return a :class:`set` of grades occurring in *self*."""
1021
1015
1022
- return {bit_count (bits ) for bits , coeff in self .data .items ()}
1016
+ return {bits . bit_count () for bits , coeff in self .data .items ()}
1023
1017
1024
1018
def get_pure_grade (self ):
1025
1019
"""If *self* only has components of a single grade, return
@@ -1031,7 +1025,7 @@ def get_pure_grade(self):
1031
1025
result = None
1032
1026
1033
1027
for bits in self .data .keys ():
1034
- grade = bit_count (bits )
1028
+ grade = bits . bit_count ()
1035
1029
if result is None :
1036
1030
result = grade
1037
1031
elif result == grade :
@@ -1045,7 +1039,7 @@ def odd(self):
1045
1039
"""Extract the odd-grade blades."""
1046
1040
new_data = {}
1047
1041
for bits , coeff in self .data .items ():
1048
- if bit_count (bits ) % 2 :
1042
+ if bits . bit_count () % 2 :
1049
1043
new_data [bits ] = coeff
1050
1044
1051
1045
return MultiVector (new_data , self .space )
@@ -1054,7 +1048,7 @@ def even(self):
1054
1048
"""Extract the even-grade blades."""
1055
1049
new_data = {}
1056
1050
for bits , coeff in self .data .items ():
1057
- if bit_count (bits ) % 2 == 0 :
1051
+ if bits . bit_count () % 2 == 0 :
1058
1052
new_data [bits ] = coeff
1059
1053
1060
1054
return MultiVector (new_data , self .space )
0 commit comments