-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding some multiplicative functions #68
Comments
Also, I would add a generic version, where you pass in a function f(p, e) which is applied to each prime power p^e in the factorization. So for the Moebius function, for example, one would use f(p, e) = -1 if e is 1, and zero otherwise. |
To add a bit more color, the implementation can be as simple as moebiusmu(f::Factorization{T}) where T <: Integer = reduce(*, e == 1 ? -1 : 0 for (p, e) in f; init=1)
moebiusmu(n::Integer) = moebiusmu(factor(n)) in the example of the Möbius function. For a function like |
Sounds like a good idea to me. But I would just call the functions |
I was looking for a
I suspect a Julia expert could make this cleaner. |
Also, if one only wants the number of divisors, the following is more efficient:
|
I have a slight bug in this code if |
I am considering adding some basic prime-factorization-related functions to 'Primes.jl', in particular some multiplicative functions (in the sense of number theory, i.e, such that f(a*b) = f(a)f(b) if a and b are relative prime).
Primes.jl already has totient (but it does not appear to be documented; I might fix this). I would add at least the Möbius function, the divisor function, and the Liouville function. Some of these functions I have used to help solve Project Euler problems. In Python, such functions are provided by SmyPy .
Similar to the totient function I would add two versions each, to have efficiency in case the
factorization is already known, e.g.:
Also, I would add
divisors(n::Integer)
anddivisors(f::Factorization{T})
which return an array (or an iterator) giving all the positive divisors of n.What do you think about this?
The text was updated successfully, but these errors were encountered: