Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove a function composition from totientSum by using a better choice for triangle #58

Merged
merged 1 commit into from
Jul 21, 2017

Conversation

incertia
Copy link
Contributor

This also better matches the formula described in mathworld.
On the other hand, totientSum = (`div` 2) . (+1) . generalInversion ((^2) . fromIntegral) is another candidate by following the formula from wikipedia, which kills a where clause as well.

The latter might offer very minor performance improvements due to shuffling around of arithmetic operations.

I chose to keep using the triangle inversion formula because that was the previously used formula.

@cartazio
Copy link
Collaborator

pardon my possible confusion, but what does this commit achieve? could you walk me through your reasoning a bit more?

@Bodigrim
Copy link
Owner

Bodigrim commented Jul 19, 2017

Well, it is a small, but still valuable improvement IMO. I am for it. To make it even more valuable, @incertia, could you please also add case totientSum n = 0 for non-positive n (instead of internal error, which is current behaviour!) and reflect this change in comment and in tests?

I'd rather keep version with triangle, and add a link to the source of formula in comment.

@incertia
Copy link
Contributor Author

all it really does is avoid a composition with (+1) in the definition of totientSum and match the formula in the first search result for "euler totient sum" to avoid any possible confusion if someone examines the source and doesn't recognize the formula used

apart from that, not much.

@incertia
Copy link
Contributor Author

incertia commented Jul 19, 2017

I made the changes @Bodigrim mentioned as well as added two special test cases (totientSum 0 should be 0, and totientSum (negative number) should be 0). If you guys are ready to merge the changes I can squash the commits.

@cartazio
Copy link
Collaborator

oh ok, i read the diff wrong, i thought you had added the (+1) . :)))))

my bad!

i leave @Bodigrim to make the call as he sees fit :)

@Bodigrim
Copy link
Owner

@incertia please use haddock markup for URLs.

@incertia
Copy link
Contributor Author

I added angle brackets around the URLs and force pushed a squash.

@Bodigrim Bodigrim merged commit c0e68b2 into Bodigrim:master Jul 21, 2017
@Bodigrim
Copy link
Owner

Great! Thanks for your contribution.

@cartazio cartazio mentioned this pull request Sep 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants