diff options
Diffstat (limited to 'factors/digit_map.go')
| -rw-r--r-- | factors/digit_map.go | 57 |
1 files changed, 49 insertions, 8 deletions
diff --git a/factors/digit_map.go b/factors/digit_map.go index a16f018..7c56a1e 100644 --- a/factors/digit_map.go +++ b/factors/digit_map.go @@ -2,11 +2,25 @@ package factors import "fmt" +/* +A DigitType represents the number-theoretical type of a digit in a radix. +It is composed of two parts: + - The regularity index, which is the exponent of the smallest power + of the radix that the digit's regular part (as defined by [Split]) + is a factor of. + - The totative type, which is the [TotativeType] of + the radix's totative part (as defined by [Split]). + +The zero value of DigitType is the type 00, +the type that the digit zero has in every nonzero radix. +*/ type DigitType struct { regularity uint8 totativeType TotativeType } +// TotativeType classifies the totative parts (as determined by [Split]) +// of digits in radices. type TotativeType byte const ( @@ -42,16 +56,28 @@ var ( // instead of the number; this is to keep the code 2 characters long const maxDisplayRegularity = 7 -// The regularity index of a number in a radix, the smallest power of the +// The regularity index of a number in a radix - the smallest power of the // radix that is divisible by the number's regular part. +// +// If this is zero, and the digit isn't, this digit is a totative. func (dt DigitType) Regularity() uint8 { return dt.regularity } -// The type of a number's totative part in a radix +// TotativeType returns the type of a number's totative part in a radix. +// This is one of the possible values of [TotativeType]. func (dt DigitType) TotativeType() TotativeType { return dt.totativeType } -// String returns a string representation of the digit type -// as a two-character code - the first representing regularity, -// the second totative type +// String returns a string representation of the digit type. +// +// This representation is a two-character code. +// The first character is the type's [DigitType.Regularity], +// or "+" if it is above 7. +// The second character is a character representing the [TotativeType]: +// - [Regular] is 'R' +// - [Omega] is 'ω' +// - [Alpha] is 'α' +// - [Pseudoneighbour] is 'N' +// - [Opaque] is 'P' (to avoid confusing it with [Zero]) +// - [Zero] is '0' func (dt DigitType) String() string { var rString string if dt.regularity > maxDisplayRegularity { @@ -92,7 +118,19 @@ func splitPF(digit, radix PrimeFactorization) (regular, totative uint) { return regular, totative } -// Splits a digit in a radix into its regular and totative parts +/* +Split splits a digit in a radix into its regular and totative parts. +The regular part will be a divisor of some power of the radix. +The totative part will be coprime to the radix, +except if the digit or radix are zero. +The product of the regular and totative parts will be equal to the digit. + +Special cases (follow from PrimeFactorize(0) = 0^1): + + Split(0, x) = 1, 0 + Split(x, 0) = 1, x + Split(0, 0) = 0, 1 +*/ func Split(digit, radix uint) (regular, totative uint) { return splitPF(PrimeFactorize(digit), PrimeFactorize(radix)) } @@ -129,7 +167,8 @@ func calcTotativeType(totative, radix uint) TotativeType { } } -// Gets the regularity and totative type of one digit in a radix +// Gets the regularity and totative type of one digit in a radix. +// // In radix zero, zero is type 1R, one is type 0R, and everything else is 0P. func GetDigitType(digit, radix uint) DigitType { radixPF := PrimeFactorize(radix) @@ -140,7 +179,9 @@ func GetDigitType(digit, radix uint) DigitType { return DigitType{regularity, totativeType} } -// Gets the regularity and totative type of each digit in a radix +// DigitMap gets the [DigitType] of every digit in a radix. +// +// DigitMap(0) returns an empty slice. func DigitMap(radix uint) []DigitType { radixPF := PrimeFactorize(radix) types := make([]DigitType, radix, radix) |
