Skip to content
Prev Previous commit
Next Next commit
Add files via upload
  • Loading branch information
QuantumNovice authored Jul 20, 2019
commit 7df62b75c1e2b74682e965175a831b5a53223a49
42 changes: 0 additions & 42 deletions maths/mobius_function.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
'''
Refrences: https://en.wikipedia.org/wiki/M%C3%B6bius_function
'''

from prime_factors import prime_factors'''
Refrences: https://en.wikipedia.org/wiki/M%C3%B6bius_function
References: wikipedia:square free number
'''

Expand Down Expand Up @@ -84,44 +80,6 @@ def is_square_free(factors:List[int]) -> bool:
return False
return True

def mobius(n:int) -> int:
'''
Mobius function
>>> mobius(24)
0
>>> mobius(-1)
1
>>> mobius('asd')
Traceback (most recent call last):
...
TypeError: '<=' not supported between instances of 'int' and 'str'
>>> mobius(10**400)
0
>>> mobius(10**-400)
1
>>> mobius(-1424)
1
>>> mobius([1, '2', 2.0])
Traceback (most recent call last):
...
TypeError: '<=' not supported between instances of 'int' and 'list'
'''
factors = prime_factors(n)
if is_square_free(factors):
if len(factors)%2 == 0:
return 1
elif len(factors)%2 != 0:
return -1
else:
return 0

if __name__ == '__main__':
import doctest
doctest.testmod()

from is_square_free import is_square_free


def mobius(n:int) -> int:
'''
Mobius function
Expand Down