rename functions

This commit is contained in:
filifa 2025-10-07 17:28:31 -04:00
parent a9c7f8091b
commit 26c197318e
10 changed files with 15 additions and 16 deletions

View File

@ -32,7 +32,7 @@ func divisors(cmd *cobra.Command, args []string) {
bufStdout := bufio.NewWriter(os.Stdout) bufStdout := bufio.NewWriter(os.Stdout)
defer bufStdout.Flush() defer bufStdout.Flush()
ch := sieve.DivisorsSieve(divisorsN, divisorsE, 1000) ch := sieve.Divisors(divisorsN, divisorsE, 1000)
for i := 0; ; i++ { for i := 0; ; i++ {
v, ok := <-ch v, ok := <-ch
if !ok { if !ok {

View File

@ -31,7 +31,7 @@ func mobius(cmd *cobra.Command, args []string) {
bufStdout := bufio.NewWriter(os.Stdout) bufStdout := bufio.NewWriter(os.Stdout)
defer bufStdout.Flush() defer bufStdout.Flush()
ch := sieve.MobiusSieve(mobiusN, 1000) ch := sieve.Mobius(mobiusN, 1000)
for i := 0; ; i++ { for i := 0; ; i++ {
v, ok := <-ch v, ok := <-ch
if !ok { if !ok {

View File

@ -32,7 +32,7 @@ func primeOmega(cmd *cobra.Command, args []string) {
bufStdout := bufio.NewWriter(os.Stdout) bufStdout := bufio.NewWriter(os.Stdout)
defer bufStdout.Flush() defer bufStdout.Flush()
ch := sieve.PrimeOmegaSieve(primeOmegaN, primeOmegaMul, 1000) ch := sieve.PrimeOmega(primeOmegaN, primeOmegaMul, 1000)
for i := 0; ; i++ { for i := 0; ; i++ {
v, ok := <-ch v, ok := <-ch
if !ok { if !ok {

View File

@ -31,7 +31,7 @@ func radical(cmd *cobra.Command, args []string) {
bufStdout := bufio.NewWriter(os.Stdout) bufStdout := bufio.NewWriter(os.Stdout)
defer bufStdout.Flush() defer bufStdout.Flush()
ch := sieve.RadicalSieve(radicalN, 1000) ch := sieve.Radical(radicalN, 1000)
for i := 0; ; i++ { for i := 0; ; i++ {
v, ok := <-ch v, ok := <-ch
if !ok { if !ok {

View File

@ -31,7 +31,7 @@ func totient(cmd *cobra.Command, args []string) {
bufStdout := bufio.NewWriter(os.Stdout) bufStdout := bufio.NewWriter(os.Stdout)
defer bufStdout.Flush() defer bufStdout.Flush()
for v := range sieve.TotientSieve(totientN, 1000) { for v := range sieve.Totient(totientN, 1000) {
if v == 0 { if v == 0 {
continue continue
} }

View File

@ -42,7 +42,6 @@ func updateMultiples(sieve []uint, x uint, p uint, n uint) {
if p*q >= n { if p*q >= n {
break break
} }
println(q)
// sigma_x(p^k) = p^(kx) + sigma_x(p^(k-1)) // sigma_x(p^k) = p^(kx) + sigma_x(p^(k-1))
sieve[p*q] = pow(p*q, x) + sieve[q] sieve[p*q] = pow(p*q, x) + sieve[q]
@ -50,9 +49,9 @@ func updateMultiples(sieve []uint, x uint, p uint, n uint) {
} }
/* /*
DivisorSieve computes sigma_x(k) for k=1 to n, where sigma_x is the divisor sum function. x sets the power each divisor is raised to. Divisors computes sigma_x(k) for k=1 to n, where sigma_x is the divisor sum function. x sets the power each divisor is raised to.
*/ */
func DivisorsSieve(n uint, x uint, buflen uint) chan uint { func Divisors(n uint, x uint, buflen uint) chan uint {
sieve := make([]uint, n) sieve := make([]uint, n)
sieve[0] = 0 sieve[0] = 0
for i := uint(1); i < n; i++ { for i := uint(1); i < n; i++ {

View File

@ -17,9 +17,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package sieve package sieve
/* /*
MobiusSieve computes mobius(k) for k=1 to n, where mobius is the Mobius function. Mobius computes mobius(k) for k=1 to n, where mobius is the Mobius function.
*/ */
func MobiusSieve(n uint, buflen uint) chan int { func Mobius(n uint, buflen uint) chan int {
sieve := make([]int, n) sieve := make([]int, n)
for i := 0; i < int(n); i++ { for i := 0; i < int(n); i++ {
sieve[i] = i sieve[i] = i

View File

@ -36,9 +36,9 @@ func primeOmegaUpdateMultiples(sieve []uint, p uint, n uint, multiplicity bool)
} }
/* /*
PrimeOmegaSieve computes omega(k) for k=1 to n, where omega is the prime omega function. If multiplicity is true, factors are counted with multiplicity. PrimeOmega computes omega(k) for k=1 to n, where omega is the prime omega function. If multiplicity is true, factors are counted with multiplicity.
*/ */
func PrimeOmegaSieve(n uint, multiplicity bool, buflen uint) chan uint { func PrimeOmega(n uint, multiplicity bool, buflen uint) chan uint {
sieve := make([]uint, n) sieve := make([]uint, n)
for i := uint(0); i < n; i++ { for i := uint(0); i < n; i++ {
sieve[i] = 0 sieve[i] = 0

View File

@ -35,9 +35,9 @@ func radicalUpdateMultiples(sieve []uint, p uint, n uint) {
} }
/* /*
RadicalSieve computes rad(k) for k=1 to n, where rad(n) is the radical of n. Radical computes rad(k) for k=1 to n, where rad(n) is the radical of n.
*/ */
func RadicalSieve(n uint, buflen uint) chan uint { func Radical(n uint, buflen uint) chan uint {
sieve := make([]uint, n) sieve := make([]uint, n)
sieve[0] = 0 sieve[0] = 0
for i := uint(1); i < n; i++ { for i := uint(1); i < n; i++ {

View File

@ -17,9 +17,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package sieve package sieve
/* /*
TotientSieve computes totient(k) for k=1 to n, where totient is Euler's totient function. buflen sets the buffer length of the returned channel. Larger buffer lengths can result in better performance at the cost of higher memory usage. Totient computes totient(k) for k=1 to n, where totient is Euler's totient function. buflen sets the buffer length of the returned channel. Larger buffer lengths can result in better performance at the cost of higher memory usage.
*/ */
func TotientSieve(n uint, buflen uint) chan uint { func Totient(n uint, buflen uint) chan uint {
totients := make([]uint, n) totients := make([]uint, n)
totients[0] = 0 totients[0] = 0
totients[1] = 1 totients[1] = 1