From ebdc5107b8b2bd69a65a34a6276fc64b84d210ec Mon Sep 17 00:00:00 2001 From: Adrien Hopkins Date: Tue, 5 Sep 2023 11:15:28 -0500 Subject: Remove totative ratio from factors API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This value can easily be calculated as φ(r)/r. There is no need to have this now that I have a function φ(r) (renamed to its mathematical name, Totient). I removed totative ratio instead of totient because, while it is more important, totient is an integer while totative ratio is a float. This means that the totative ratio can be calculated exactly from the totient, but not the other way round. --- factors/factors_test.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'factors/factors_test.go') diff --git a/factors/factors_test.go b/factors/factors_test.go index af91e70..745fd2c 100644 --- a/factors/factors_test.go +++ b/factors/factors_test.go @@ -67,17 +67,25 @@ var totativeRatioCases = map[uint]float64{ 30: 4.0 / 15.0, 60: 4.0 / 15.0, 120: 4.0 / 15.0, } +func totativeRatio(n uint) float64 { + if n == 0 { + panic("0 has no totative ratio!") + } + + return float64(Totient(n)) / float64(n) +} + func TestTotativeRatio(t *testing.T) { - tableTest(t, TotativeRatio, totativeRatioCases, stdEquals, "TotativeRatio") + tableTest(t, totativeRatio, totativeRatioCases, stdEquals, "TotativeRatio") } -var totativeCountCases = map[uint]uint{ - 1: 1, 2: 1, 3: 2, 4: 2, 6: 2, 7: 6, 8: 4, 12: 4, +var totientCases = map[uint]uint{ + 0: 0, 1: 1, 2: 1, 3: 2, 4: 2, 6: 2, 7: 6, 8: 4, 12: 4, 14: 6, 15: 8, 30: 8, 60: 16, 120: 32, } func TestTotativeCount(t *testing.T) { - tableTest(t, TotativeCount, totativeCountCases, stdEquals, "TotativeCount") + tableTest(t, Totient, totientCases, stdEquals, "Totient") } var factorScoreCases = map[uint]float64{ -- cgit v1.2.3