summaryrefslogtreecommitdiff
path: root/factor_info.go
diff options
context:
space:
mode:
authorAdrien Hopkins <adrien.p.hopkins@gmail.com>2023-09-07 13:15:40 -0500
committerAdrien Hopkins <adrien.p.hopkins@gmail.com>2023-09-07 13:15:40 -0500
commit3cfb1fdcbe83c1ee4adf8e370f0922ca41c472c6 (patch)
tree2695b9decec500c1c5137b79e8fd83a95961c2a0 /factor_info.go
parent7fa8cf9666cd3427dd078bb4a5fdb9fa30c94b09 (diff)
Add ability to display specific totative digits
Instead of just saying how many totative digits there are, the new -t flag allows the user to determine the specific digits. All totatives will end in one of these digits, and all primes are either factors or totatives. This feature is not useful in comparing radices, only learning one you have already chosen. Because there can be so many totatives (p - 1 of them for primes!), this is not displayed by default. The digit map (without -f) gives this information, and beyond its range every number will have more than 8 totatives, so do not use this flag if you only want the count.
Diffstat (limited to 'factor_info.go')
-rw-r--r--factor_info.go28
1 files changed, 21 insertions, 7 deletions
diff --git a/factor_info.go b/factor_info.go
index 03c81f3..bcfc3b1 100644
--- a/factor_info.go
+++ b/factor_info.go
@@ -26,6 +26,8 @@ type factorInfo struct {
// The fraction of digits that are totatives (numbers that share no
// factors with the radix - they are the worst kind of digits)
TotativeRatio float64
+ // The totative digits of this radix. May be nil if this was not requested.
+ TotativeDigits []uint32
// A rank measuring how well the radix works with the most elementary
// numbers and ratios
BasicRank string
@@ -58,18 +60,25 @@ const (
maxExtended = 1 << 32
)
-func getFactorInfo(radix uint, fullMap bool, exactMTCLarge bool) *factorInfo {
+func getFactorInfo(a args) *factorInfo {
+ radix := a.Radix
+
r_factors := factors.Factors(radix)
slices.Sort(r_factors)
+ var totativeDigits []uint32 = nil
+ if a.TotativeDigits && radix < maxExtended {
+ totativeDigits = factors.TotativeDigits(uint32(radix))
+ }
+
var mtc_ptr *uint64 = nil
- if radix < maxNormal || (exactMTCLarge && radix < maxExtended) {
+ if radix < maxNormal || (a.ExactMTCLarge && radix < maxExtended) {
mtc := factors.MTC(uint32(radix))
mtc_ptr = &mtc
}
var digitMap []factors.DigitType
- if fullMap {
+ if a.FullMap {
digitMap = make([]factors.DigitType, maxSmallRadix)
for d := 0; d < maxSmallRadix; d++ {
digitMap[d] = factors.GetDigitType(uint(d), radix)
@@ -85,16 +94,21 @@ func getFactorInfo(radix uint, fullMap bool, exactMTCLarge bool) *factorInfo {
return &factorInfo{radix, factors.PrimeFactorize(radix),
r_factors, factors.Score(radix), totativeCount, totativeRatio,
- factors.BasicRank(radix), factors.Type(radix), mtc_ptr,
- math.Log(float64(radix)), digitMap}
+ totativeDigits, factors.BasicRank(radix), factors.Type(radix),
+ mtc_ptr, math.Log(float64(radix)), digitMap}
}
func (fi *factorInfo) writeTo(w io.Writer) {
fmt.Fprintln(w, fi.Radix, "=", fi.PrimeFactorization)
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)
+ if fi.TotativeDigits != nil {
+ fmt.Fprintf(w, "Totative Digits: %v (%.3f%%)\n",
+ fi.TotativeDigits, fi.TotativeRatio*100.0)
+ } else {
+ fmt.Fprintf(w, "Totative Digit Count: %d (%.3f%%)\n",
+ fi.Totient, fi.TotativeRatio*100.0)
+ }
writeTypeMessage(w, fi.Type)
if fi.MTC != nil {
fmt.Fprintln(w, "Multiplication Table Complexity:", *fi.MTC)