From 7fa8cf9666cd3427dd078bb4a5fdb9fa30c94b09 Mon Sep 17 00:00:00 2001 From: Adrien Hopkins Date: Thu, 7 Sep 2023 11:38:32 -0500 Subject: Calculate type of all radices without -l MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit factors.Type now supports all numbers; I have used lookup arrays instead of determining whether a number is SAN or not. There are only 117 elements to store, and this makes the algorithm Θ(1), so it's an improvement. Also, I have changed the size of some integer values to correspond to this change - they now indicate the size of numbers they can accept. The only outputs that are hidden for large radices are: - The digit map, which goes up to 36 because I don't have any more digits beyond that point - The multiplication table complexity, which is estimated above 2^16 (for performance), and can optionally be extended to 2^32 (above this, the output could overflow a uint64). --- factor_info.go | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) (limited to 'factor_info.go') diff --git a/factor_info.go b/factor_info.go index 522112a..03c81f3 100644 --- a/factor_info.go +++ b/factor_info.go @@ -32,7 +32,7 @@ type factorInfo struct { // Whether or not this radix is part of any special factor-related classes. // This is not calculated if the radix is too large - in this case // this field will be nil. - Type *factors.NumberType + Type factors.NumberType // An estimate of the complexity of the radix's multiplication table. // This is not calculated if the radix is too large - in this case // this field will be nil. @@ -58,20 +58,14 @@ const ( maxExtended = 1 << 32 ) -func getFactorInfo(radix uint, fullMap bool, largeCalc bool) *factorInfo { +func getFactorInfo(radix uint, fullMap bool, exactMTCLarge bool) *factorInfo { r_factors := factors.Factors(radix) slices.Sort(r_factors) - var r_type_ptr *factors.NumberType - var mtc_ptr *uint64 - if radix < maxNormal || (largeCalc && radix < maxExtended) { - r_type := factors.Type(uint32(radix)) - r_type_ptr = &r_type - mtc := factors.MTC(uint64(radix)) + var mtc_ptr *uint64 = nil + if radix < maxNormal || (exactMTCLarge && radix < maxExtended) { + mtc := factors.MTC(uint32(radix)) mtc_ptr = &mtc - } else { - r_type_ptr = nil - mtc_ptr = nil } var digitMap []factors.DigitType @@ -91,7 +85,7 @@ func getFactorInfo(radix uint, fullMap bool, largeCalc bool) *factorInfo { return &factorInfo{radix, factors.PrimeFactorize(radix), r_factors, factors.Score(radix), totativeCount, totativeRatio, - factors.BasicRank(radix), r_type_ptr, mtc_ptr, + factors.BasicRank(radix), factors.Type(radix), mtc_ptr, math.Log(float64(radix)), digitMap} } @@ -101,9 +95,7 @@ func (fi *factorInfo) writeTo(w io.Writer) { fmt.Fprintln(w, "2345 Rank:", fi.BasicRank) fmt.Fprintf(w, "Totative Digit Count: %d (%.3f%%)\n", fi.Totient, fi.TotativeRatio*100.0) - if fi.Type != nil { - writeTypeMessage(w, *fi.Type) - } + writeTypeMessage(w, fi.Type) if fi.MTC != nil { fmt.Fprintln(w, "Multiplication Table Complexity:", *fi.MTC) } else { @@ -122,9 +114,7 @@ func (fi *factorInfo) writeTo(w io.Writer) { func (fi *factorInfo) writeToCompact(w io.Writer) { fmt.Fprintf(w, "%d = %s | σ(r)/r: %.2f | φ(r)/r: %.3f\n", fi.Radix, fi.PrimeFactorization, fi.Score, fi.TotativeRatio) - if fi.Type != nil { - fmt.Fprintf(w, "%s | ", typeAbbrev(*fi.Type)) - } + fmt.Fprintf(w, "%s | ", typeAbbrev(fi.Type)) if fi.MTC != nil { fmt.Fprintf(w, "MTC: %d | ", *fi.MTC) } else { -- cgit v1.2.3