TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Algebraic Patterns – Monoid Morphism

86 pointsby alipangover 8 years ago

5 comments

rawnlqover 8 years ago
The counting zeroes in &quot;100!&quot; problem is actually a common high school level math contest problem. You&#x27;re supposed to calculate it by hand, not with code. The trick was to notice<p>- number of trailing zeros is equal to times you can divide something by 10<p>- There are a lot more 2s than 5s as the divisor, so number of 5s is the limiting factor<p>- 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100 contribute (at least) a factor of 5 each<p>- 25, 50, 75, 100 contribute another factor of 5 each<p>So answer is 20 + 4 zeros.<p>I love monoids but I personally thought that was a bad example. Not only did it complicate the problem, it didn&#x27;t actually lead to any understanding that will let you write a generic and efficient solution for &quot;n!&quot;. Something like this O(log(n)):<p><pre><code> def countZeroes(n): count = 0 divisor = 5 while divisor &lt;= n: count += n &#x2F; divisor divisor *= 5 return count print countZeroes(100)</code></pre>
评论 #12610913 未加载
评论 #12610400 未加载
raphlinusover 8 years ago
I use monoid homomorphisms extensively in xi-editor, and have a couple of slides on it at my RustConf talk earlier this month. I hope to be writing up the ideas in more detail soon (both what I&#x27;ve implemented, and speculative explorations such as doing incremental syntax highlighting).
评论 #12612371 未加载
评论 #12611043 未加载
conistonwaterover 8 years ago
I don&#x27;t fully understand how category theory terms are helpful in programming. It always feels backwards to me, that first you write the code, then you look through the code and pick out all the places where category-theory terminology might appear. Monoids are nice and all, but in the end it&#x27;s just a name given to a specific design pattern: you may as well reason about it in terms of code.
评论 #12610910 未加载
评论 #12609924 未加载
评论 #12609845 未加载
评论 #12610873 未加载
评论 #12611213 未加载
评论 #12610997 未加载
评论 #12615025 未加载
评论 #12611603 未加载
评论 #12610935 未加载
Koshkinover 8 years ago
Ah... Monoids-shmonoids. While I appreciate abstract algebra, I feel that forcing it onto students of programming is a terrible idea. An entire generation of potential engineers and scientists (and even mathematicians) was lost when they started teaching children that geometric figures can only be &quot;congruent&quot; to each other, not &quot;equal&quot;. In the same way, I would have never been able to use, say, generic lists without giving this idea a second thought if they had told me first that those are an example of an important kind of &quot;endofunctor in the category of types&quot; (i.e. a monad).
jiehongover 8 years ago
Hi,<p>I&#x27;m new here :)<p>Each time I see something like that, I think it looks great, but I&#x27;m having a hard time understanding the meaning of the vocabulary used…<p>Is there any good (free?) resources out there to learn Monoids, Monads, traits, category theory, in short, anything used in functional languages?<p>This is something that clearly stops me from using functional languages more.
评论 #12611511 未加载
评论 #12611586 未加载
评论 #12611631 未加载
评论 #12611698 未加载
评论 #12611518 未加载
评论 #12611819 未加载