summaryrefslogtreecommitdiff
path: root/factor_info.go
diff options
context:
space:
mode:
authorAdrien Hopkins <adrien.p.hopkins@gmail.com>2023-09-05 12:36:52 -0500
committerAdrien Hopkins <adrien.p.hopkins@gmail.com>2023-09-05 12:58:43 -0500
commit55981e7bb325f5dc84384e90c76a7f29005d62f8 (patch)
treee1786a0d98f3a36e2a8c669e472d22ab246eb3b9 /factor_info.go
parent8bb4a3b74712b16954b93ae18f4d3dcd5bea063b (diff)
Treat radices >2^16 as large unless -l set
These radices are large enough that: - there is no reason to use them as actual radices - calculating them takes a lot of time! Therefore, the exact MTC and radix type shouldn't be calculated by default. If you want to take the time, you still can with -l. I am keeping the original 2^32 limit even with -l, because the problem with that is not performance, it is that the resulting MTC could overflow a uint64 (also the CAN list only goes up to this range).
Diffstat (limited to 'factor_info.go')
-rw-r--r--factor_info.go23
1 files changed, 16 insertions, 7 deletions
diff --git a/factor_info.go b/factor_info.go
index 0d0bd40..62c3524 100644
--- a/factor_info.go
+++ b/factor_info.go
@@ -49,13 +49,22 @@ type FactorInfo struct {
DigitMap []factors.DigitType
}
-func GetFactorInfo(radix uint, fullMap bool) *FactorInfo {
+const (
+ // The maximum radix that will always be treated as normal
+ // (i.e. radix type and exact MTC will be calculated)
+ maxNormal = 1 << 16
+ // The max radix that will be treated as normal with -l
+ // above this, MTC can exceed the size of a uint64
+ maxExtended = 1 << 32
+)
+
+func GetFactorInfo(radix uint, fullMap bool, largeCalc bool) *FactorInfo {
r_factors := factors.Factors(radix)
slices.Sort(r_factors)
var r_type_ptr *factors.NumberType
var mtc_ptr *uint64
- if radix < 1<<32 {
+ if radix < maxNormal || (largeCalc && radix < maxExtended) {
r_type := factors.Type(uint32(radix))
r_type_ptr = &r_type
mtc := factors.MTC(uint64(radix))
@@ -91,15 +100,15 @@ func (fi *FactorInfo) WriteTo(w io.Writer) {
fmt.Fprintf(w, "Factors: %v (Score: %.4f)\n", fi.Factors, fi.Score)
fmt.Fprintln(w, "2345 Rank:", fi.BasicRank)
fmt.Fprintf(w, "Totative Digit Count: %d (%.3f%%)\n",
- fi.Totient, fi.TotativeRatio * 100.0)
+ fi.Totient, fi.TotativeRatio*100.0)
if fi.Type != nil {
writeTypeMessage(w, *fi.Type)
}
if fi.MTC != nil {
fmt.Fprintln(w, "Multiplication Table Complexity:", *fi.MTC)
} else {
- low_mtc_est := float64(fi.Radix)*float64(fi.Totient-2)
- high_mtc_est := float64(fi.Radix)*float64(fi.Radix-2)
+ low_mtc_est := float64(fi.Radix) * float64(fi.Totient-2)
+ high_mtc_est := float64(fi.Radix) * float64(fi.Radix-2)
fmt.Fprintf(w,
"Multiplication Table Complexity is between %.6g and %.6g.\n",
low_mtc_est, high_mtc_est)
@@ -119,8 +128,8 @@ func (fi *FactorInfo) WriteToCompact(w io.Writer) {
if fi.MTC != nil {
fmt.Fprintf(w, "MTC: %d | ", *fi.MTC)
} else {
- low_mtc_est := float32(fi.Radix)*float32(fi.Totient-2)
- high_mtc_est := float32(fi.Radix)*float32(fi.Radix-2)
+ low_mtc_est := float32(fi.Radix) * float32(fi.Totient-2)
+ 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)