summaryrefslogtreecommitdiff
path: root/factor_info.go
diff options
context:
space:
mode:
authorAdrien Hopkins <adrien.p.hopkins@gmail.com>2024-11-20 21:40:06 -0500
committerAdrien Hopkins <adrien.p.hopkins@gmail.com>2024-11-20 21:40:06 -0500
commit6cba5dc72cda8c7bd527ae1e094a8bf678a8e83c (patch)
tree3e7f46efdec360bf7186f6c5b8f90bef637d2dbe /factor_info.go
parent2d14a6bc2e9df90aa55646def21c36bcc7aaac48 (diff)
Change logarithms to binary
After thinking about how I want to best represent logarithms, I think the best way is to see them as equivalent to the size of a digit. Binary logarithms allow for using a familiar unit (bits) to represent this size. Nepers exist for the natural logarithm, but almost no one uses them. Also, because binary is the smallest base out there, this value will always be ≥1. This means I'm making the most out of my digits! This does mean that digit length isn't immediately obvious, but this is the same idea as "1 km = 1000 m" meaning that the number of km is 1/1000 the number of m - using the regular logarithm is like associating the km with the number 1000, using the reciprocoal is like associating it with 1/1000=0.001. Documentation has been changed to reflect this.
Diffstat (limited to 'factor_info.go')
-rw-r--r--factor_info.go14
1 files changed, 6 insertions, 8 deletions
diff --git a/factor_info.go b/factor_info.go
index 1988b2c..8939f5a 100644
--- a/factor_info.go
+++ b/factor_info.go
@@ -55,11 +55,9 @@ type factorInfo struct {
// This is not calculated if the radix is too large - in this case
// this field will be nil.
MTC *uint64
- // The radix's natural logarithm. This determines the length of numbers
- // in this radix - higher Ln means numbers take up fewer digits.
- // If c = log(a)/log(b), then numbers in radix b will be around
- // c times longer than numbers in radix a.
- Ln float64
+ // The radix's base-2 logarithm.
+ // One digit in this radix is equivalent to this many bits.
+ Log2 float64
// Information about each digit's compatibility with the radix.
// This determines what kind of decimal expansion the digit's
// reciprocoal has and what patterns are in its row of the multiplication
@@ -113,7 +111,7 @@ func getFactorInfo(a args) *factorInfo {
return &factorInfo{radix, factors.PrimeFactorize(radix),
r_factors, factors.Score(radix), totativeCount, totativeRatio,
totativeDigits, factors.BasicRank(radix), factors.Type(radix),
- mtc_ptr, math.Log(float64(radix)), digitMap}
+ mtc_ptr, math.Log2(float64(radix)), digitMap}
}
func (fi *factorInfo) writeTo(w io.Writer) {
@@ -140,7 +138,7 @@ func (fi *factorInfo) writeTo(w io.Writer) {
"Multiplication Table Complexity is between %.6g and %.6g.\n",
low_mtc_est, high_mtc_est)
}
- fmt.Fprintf(w, "Natural Logarithm: %.3f\n", fi.Ln)
+ fmt.Fprintf(w, "Base-2 Logarithm: %.3f\n", fi.Log2)
if len(fi.DigitMap) > 0 {
writeDigitMap(w, fi.DigitMap)
}
@@ -157,7 +155,7 @@ func (fi *factorInfo) writeToCompact(w io.Writer) {
high_mtc_est := float32(fi.Radix) * float32(fi.Radix-2)
fmt.Fprintf(w, "%.4g ≤ MTC ≤ %.4g | ", low_mtc_est, high_mtc_est)
}
- fmt.Fprintf(w, "ln: %.2f", fi.Ln)
+ fmt.Fprintf(w, "log2: %.2f", fi.Log2)
fmt.Fprintln(w)
if len(fi.DigitMap) > 0 {
writeDigitMapCompact(w, fi.DigitMap)