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.

The Mathematical Hacker (2012)

168 pointsby nochalmost 6 years ago

23 comments

jacobolusalmost 6 years ago
&gt; <i>But rarely in these discussions will you find relevant mathematical considerations. If the goal is to compute a Fibonacci number or a factorial, the proper solution is not a recursive function, but rather knowledge of mathematics.</i><p>If you want precise results for large sizes, then the integer-arithmetic recurrence is faster than computing the square root of 5 to very high precision and raising it to the nth power.<p>The author’s “proper solution” might better be named the “naive undergraduate introductory linear algebra student solution”. Or maybe “18th century analytic solution ignorant of computer number formats”.<p>&gt; <i>They run in constant [...] time</i><p>If we are going to artificially limit ourselves to numbers smaller than the precision of e.g. double precision floats, then the integer algorithms might just as well be considered “constant time”, where the constant is just whatever it takes to compute the largest value we are considering.<p>Or alternately we can just precompute and cache the entire set of them if we want. There are only 78.<p>Here’s a Javascript implementation<p><pre><code> const fibcache = [ 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465, 14930352, 24157817, 39088169, 63245986, 102334155, 165580141, 267914296, 433494437, 701408733, 1134903170, 1836311903, 2971215073, 4807526976, 7778742049, 12586269025, 20365011074, 32951280099, 53316291173, 86267571272, 139583862445, 225851433717, 365435296162, 591286729879, 956722026041, 1548008755920, 2504730781961, 4052739537881, 6557470319842, 10610209857723, 17167680177565, 27777890035288, 44945570212853, 72723460248141, 117669030460994, 190392490709135, 308061521170129, 498454011879264, 806515533049393, 1304969544928657, 2111485077978050, 3416454622906707, 5527939700884757, 8944394323791464]; const fibonacci = (n) =&gt; fibcache[n];</code></pre>
评论 #20144228 未加载
评论 #20144869 未加载
评论 #20144518 未加载
评论 #20144960 未加载
kccqzyalmost 6 years ago
Let&#x27;s just accept that there are different kinds of math and people are interested in different kinds of math. The lisp school may especially like the beauty of recursion (recursion theory, aka computability theory <i>is</i> a branch of math), and the fortran school may like the beauty of calculus and numeric computing. This isn&#x27;t necessarily exclusive. I can write a naïve recursive function for Fibonacci numbers, or I can derive the &quot;constant-time&quot; formula using generating functions on the fly. Or I can find a method better than both using matrix exponentiation. These are all math. There&#x27;s no need to denigrate one school over another, just like there&#x27;s no need to denigrate one branch of math over another.
nextosalmost 6 years ago
I agree with his main point.<p>Programming will become true engineering soon. In a few decades, we will be building mainstream software with formal guarantees. And for that, there&#x27;s tons of abstract algebra needed as a foundation, once you try to digest [1-6] and whatever replaces them in the future.<p>It&#x27;s tragic most CS programs do not emphasize this a bit more.<p>[1] <a href="https:&#x2F;&#x2F;www.elsevier.com&#x2F;books&#x2F;lectures-on-the-curry-howard-isomorphism&#x2F;sorensen&#x2F;978-0-444-52077-7" rel="nofollow">https:&#x2F;&#x2F;www.elsevier.com&#x2F;books&#x2F;lectures-on-the-curry-howard-...</a><p>[2] <a href="https:&#x2F;&#x2F;softwarefoundations.cis.upenn.edu&#x2F;" rel="nofollow">https:&#x2F;&#x2F;softwarefoundations.cis.upenn.edu&#x2F;</a><p>[3] <a href="https:&#x2F;&#x2F;www.cis.upenn.edu&#x2F;~bcpierce&#x2F;tapl&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.cis.upenn.edu&#x2F;~bcpierce&#x2F;tapl&#x2F;</a><p>[4] <a href="https:&#x2F;&#x2F;www.springer.com&#x2F;gb&#x2F;book&#x2F;9783540654100" rel="nofollow">https:&#x2F;&#x2F;www.springer.com&#x2F;gb&#x2F;book&#x2F;9783540654100</a><p>[5] <a href="http:&#x2F;&#x2F;www.concrete-semantics.org&#x2F;" rel="nofollow">http:&#x2F;&#x2F;www.concrete-semantics.org&#x2F;</a><p>[6] <a href="http:&#x2F;&#x2F;adam.chlipala.net&#x2F;frap&#x2F;" rel="nofollow">http:&#x2F;&#x2F;adam.chlipala.net&#x2F;frap&#x2F;</a>
评论 #20143517 未加载
dkarlalmost 6 years ago
I think the greatest link is aesthetic, the instinct for power and simplicity. Mathematics and programming are both the creation of weightless structures that are limited only by their tractability by human intellect.<p>Of course that perspective ignores two important things: physical constraints on performance, and the relationship of data to facts in the real world. From these constraints programming also takes on the characteristics of natural science and engineering. These considerations come into play as well, but so often the limiting resource is human time and intellectual bandwidth, requiring a simpler, easier solution.<p>In mathematics, the scale can be much grander than anything yet produced in computing. Calculus is just breathtaking -- the signature accomplishment of the greatest mathematicians of their time, refined over hundreds of years into a tool that can be wielded by ordinary teenagers. It might seem shallow to compare such a sweeping achievement to mundane programming tasks such as writing enterprise business logic. Yet, if you ignore scale and universality, the intellectual task is the same: to take something that requires careful thought and close familiarity with the product requirements today, and boil it down to something that can be understand at a glance six months from now by someone who was not involved in the initial development. To distill patterns of thought internalized via close familiarity with the motivating problems into easily defined and digested concepts.
anaphoralmost 6 years ago
Leslie Lamport (of Paxos, LaTeX, and TLA+ fame) has been making this point for years. Basically that in order to design a piece of software, you need to be able to create a spec, and the best way of doing that is through mathematics.<p>E.g.<p>- <a href="https:&#x2F;&#x2F;lamport.azurewebsites.net&#x2F;tla&#x2F;math-knowledge.html" rel="nofollow">https:&#x2F;&#x2F;lamport.azurewebsites.net&#x2F;tla&#x2F;math-knowledge.html</a><p>- <a href="https:&#x2F;&#x2F;youtu.be&#x2F;-4Yp3j_jk8Q" rel="nofollow">https:&#x2F;&#x2F;youtu.be&#x2F;-4Yp3j_jk8Q</a>
评论 #20143433 未加载
bloafalmost 6 years ago
This question of the relationship between math and CS always boggles my mind. Computers are, in a very real sense, <i>automatic math machines.</i> Programmers are, in a very real sense, telling the automatic math machines <i>what math to do.</i><p>Now we&#x27;ve built ourselves a large number of layers of abstraction in an attempt to forget these things. And with those abstraction layers, programmers can be reasonably productive without having to think about their problems in terms of the math that the underlying math machine is doing. But in my mind, if someone wants to call themselves a <i>computer scientist,</i> they are necessarily concerned with the underlying math being done.
评论 #20144007 未加载
iainmerrickalmost 6 years ago
Besides the question of whether the Fibonacci sequence is a good or bad example, here’s a different objection to the author’s thesis:<p>If software development is ripe for a mathematics-driven leap forward, just like logistics and baseball, why hasn’t it happened yet?<p>If software developers and baseball coaches were both sitting next to low-hanging fruit that merely required a bit of mathematical knowledge and spreadsheet-wrangling to exploit, I would have expected the people already using computers -- the software developers -- to find it first. What’s different, and why?<p>It could be that software is inherently less amenable to statistical and numeric approaches than baseball, and that’s just the way it is. When you look at baseball the right way, you have a great mass of data with fairly simple and consistent rules, ideal for a statistical approach. When you look at a typical software system, you have a mass of special-case business logic, with no real simplifying assumption to be found.<p>In cases where “big data” is available, successful companies <i>are</i> using statistics to exploit regularities in the system.<p>So maybe what the author is arguing for is already happening, albeit on an somewhat smaller and slower scale, and maybe this is inherent in the nature of software.<p>Applied mathematics, basically calculus, is great but it can’t do everything. The author seems to be ignoring discrete mathematics (which a lot of the “Lisp hacks” he dismisses would fall under). Then there are sociological issues, such as documentation, unit testing, debugging, modularity, maintenance of legacy systems.<p>Plenty of researchers have tried applying a data-driven approach to testing and debugging, and I think it’s safe to say no-one has completely cracked it yet. If another recent paper posted here is to be believed, we don’t even know if there’s a significant difference in bug rates between static and dynamic typing.
karmakazealmost 6 years ago
Article misses the point on recursion. It isn&#x27;t about solving the study questions. They were only chosen as self-contained examples. A better example is navigating tree structures or divide and conquer algorithms but that requires more context. Math is useful because it&#x27;s a common language we expect to have been exposed to before programming.<p>&gt; Lisp-school essayists [...] spend their time worrying about how to make code more abstract. This kind of thinking may lead to compact, powerful code bases, but in the language of economics, there is an opportunity cost. If you’re thinking about your code, you’re not thinking about the world outside, and the equations that might best describe it.<p>Another way of saying the same thing in a positive light is to say that these things <i>have already been thought about</i> and can be applied to take advantage of opportunities where applicable.<p>&gt; Although the early years in the twenty-first century seem to be favoring the Lisp-school philosophy, I predict the balance of the century will belong to the Fortran-school programmers<p>This part does seem to be happening. Just look at Apache Storm v2 port from Clojure to Java:<p><i>&quot;While Storm’s Clojure implementation served it well for many years, it was often cited as a barrier for entry to new contributors. Storm’s codebase is now more accessible to developers who don’t want to learn Clojure in order to contribute.&quot;</i>[0]<p>[0] <a href="https:&#x2F;&#x2F;www.dm4r.com&#x2F;tech&#x2F;apache-storm-v2-0-porting-from-clojure-to-pure-java-performance-upgrades-more&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.dm4r.com&#x2F;tech&#x2F;apache-storm-v2-0-porting-from-clo...</a>
Gondolinalmost 6 years ago
The Fibonacci example is interesting. If you want arbitrary precision, then the naive recursive method is exponential in $n$ to compute $F_n$. The loop method (recursive method with cache) is in $O(n^2)$. Indeed you only have $n$ steps in the loop, but at step $k$ you add $F_k$ and $F_{k+1}$ which have $O(k)$ bits so the total costs is $O(n^2)$. Finally the matrix&#x2F;formal \sqrt{5} algorithm costs $O(n log n)$.<p>Indeed, using fast exponentiations, you only need $O(log n) matrix multiplications. But the dominant cost is actually at the last step, where you multiply two numbers of size $O(n)$ bits for a total cost of $O(n log n)$.<p>Speaking of mathematics in programming: I find it remarkable that the recent convergence of async programming into the use of promises and async&#x2F;await (in python, js, rust...) is a weak form of the continuation monad. And the continuation monad is a form of the &#x27;not not&#x27; Lawrere topology!
Ragib_Zamanalmost 6 years ago
Not to say anything about the central thesis of the post, but the two examples of how deeper mathematical knowledge can lead to better programming are just terrible examples. As someone whose background was originally mathematics and starting programming relatively late, I can very much relate to thinking Binet&#x27;s formula for Fibonacci numbers or gamma function for factorials might be faster than recursive methods. But when you actually learn about how ints, floats and their arithmetic is implemented at a low level, how cache and memory works etc, you realise that recursive methods for those two problems are actually your best bet, both for speed and accuracy. So ironically, these are examples where knowing much about low level coding and computing architecture helps you more than knowing more advanced mathematics.
评论 #20144875 未加载
User23almost 6 years ago
No mention of Hoare triples, predicate transformers, loop invariants, or any of the other formal machinery that was discovered 50 years ago and thoroughly solves the problem. The author means well, but this is completely uninformative.<p>Dijkstra was trained as a Mathematical Engineer for example. Fact is, if astronomers had the mindset of most programmers, they&#x27;d call their field Telescope Science.
评论 #20145904 未加载
评论 #20144566 未加载
评论 #20143399 未加载
dangalmost 6 years ago
2013: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=6953774" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=6953774</a><p>2012: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=4915328" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=4915328</a>
wwwestonalmost 6 years ago
&gt; the Lisp hacker is more likely to ask the irrelevant question: how can I reduce these two functions down to one function?<p>Except... mathematicians are <i>very</i> frequently going to be doing the same thing: asking if there is some generalization that covers two seemingly independent cases. Otherwise, the author should&#x2F;would probably be talking about Stirling&#x27;s approximation instead of the log gamma function in that piece.<p>More knowledge of mathematics relevant to a given domain an application is written for might often be a good thing -- I think that&#x27;s an overarching point worth examining.<p>But if you&#x27;re going really to look to mathematics as a guiding light, it&#x27;s not going to be super useful in criticizing the drive for abstraction.
cdbyralmost 6 years ago
While we’re talking about metaphors: this reminds me of the distinction between craft and art. Where one is the creation or something elegant and functional (craft, lisp), the other treats more important the ideas being put into practice (art, fortran).<p>I think the article’s artificially limiting its point to mathematics - there are plenty of other disciplines where we can find well-tread useful metaphors, etc.
评论 #20144773 未加载
webdvaalmost 6 years ago
This is an excellent article. It motivated me to adopt a more Fortran morality, where my assumptions or so function first on underlying scientific principles, when I search for practical problems to solve.
throwawaymathalmost 6 years ago
Unfortunately I have to strongly disagree with the author&#x27;s central thesis.<p><i>&gt; But I think that most programmers who are serious about what they do should know calculus (the real kind), linear algebra, and statistics. The reason has nothing to do with programming per se — compilers, data structures, and all that — but rather the role of programming in the economy...One way to read the history of business in the twentieth century is a series of transformations whereby industries that “didn’t need math” suddenly found themselves critically depending on it.</i><p>There are two ways to interpret the claim that more programmers should know advanced math. One of them, which the author preempts, is the idea that programmers will improve their own work through significant mathematical maturity. It seems the author and I already agree that <i>isn&#x27;t</i> the case, so I won&#x27;t address this interpretation. But I still consider this interpretation to be more defensible than the other one.<p>The other way to interpret it, which the author seems to be explicitly pushing, is that programmers with a strong mathematical background will be better situated to proactively find fertile areas of the economy which can be improved through a combination of computing and advanced math. I don&#x27;t believe this is realistic. None of the author&#x27;s specific examples - control theory, optimization, linear programming, econometrics, or Black-Scholes - were pioneered by generalist engineers with a strong grounding in mathematics. They were just applied mathematicians (and in a few of those cases, repurposed pure mathematicians).<p>Likewise the bar is constantly rising. Knowing calculus, linear algebra and statistics won&#x27;t empower you to make significant, groundbreaking improvements to any major field. That knowledge is necessary but insufficient. What&#x27;s considered low hanging fruit these days is something that could be conceivably noticed and tackled by a postdoc. Mathematics itself is ossifying as a field of specialists, to the point where prominent researchers within subfields like algebraic geometry can be unfamiliar with each other&#x27;s principal work.<p>This is really why find the appeal to economic advancement less than convincing - every advancement the author mentions has an implicit foundation in specialization. Historically, the most notable advancements in technology have come about through division of labor and cross-pollination. You would be better served by having two collaborating teams of mathematicians and engineers than by a team of engineers who know undergraduate math. It&#x27;s already common for applied mathematicians to be able to program competently; they dominate the authorship of fast, low level math libraries. If you need them, hire them.<p>Conversely, I would argue we should actually <i>reduce</i> the education for more developers, not add even more material to it. Most developers already don&#x27;t need to learn a significant amount of the material in a standard computer science degree. Piling on math courses isn&#x27;t going to be a fundamental improvement for the vast majority of engineers working on real world software.
评论 #20144579 未加载
评论 #20143992 未加载
zakeriaalmost 6 years ago
Fast forward a few years, now with the demand of learning-based software, there is no doubt that mathematics is indeed a requirement for data-driven software.<p>Although you may not need to know the math to build such software, given the tools that we have available. However you would need to know the math in order to understand the limitations, pros&#x2F;cons of a particular ML algorithm for a given application (at the very least).
btrettelalmost 6 years ago
Theoretical fluid dynamicist here. I&#x27;m fairly decent with math, or at least solving differential equations. Related to the essay, I&#x27;ve always found it odd how many people with a CS background tend to &quot;compute first, ask questions later.&quot; My experience has been that analyzing a problem first is generally a good idea, but CS folks typically don&#x27;t in my experience. Exact or good approximate solutions to problems often exist, perhaps only for relatively simple problems, but still.<p>Sometimes computation is necessary, but that doesn&#x27;t mean you&#x27;ll save time by avoiding analysis entirely. When mathematical analysis succeeds, the time saved can be considerable. And you can combine both, e.g., recently I sped up a non-linear algebraic equation solver for my work by using an ansatz that I derived using the perturbation method. (Also probably helps the solver converge to the right solution.)<p>One possible explanation: <a href="https:&#x2F;&#x2F;en.wiktionary.org&#x2F;wiki&#x2F;if_all_you_have_is_a_hammer,_everything_looks_like_a_nail" rel="nofollow">https:&#x2F;&#x2F;en.wiktionary.org&#x2F;wiki&#x2F;if_all_you_have_is_a_hammer,_...</a>
评论 #20143829 未加载
valwalmost 6 years ago
A huge 3rd category of programmers is entirely missing: those that don&#x27;t care about <i>abstraction</i> at all, be it mathematical or linguistic. I think the priority for our industry is to get those on board, then we can discuss what tools for abstraction they should specialize in.
ltr_almost 6 years ago
just doing a double click on the Fibonacci Solution :hypothetically speaking, can a compiler take the recursive solution and optimize it to the Binet&#x27;s formula in machine code? . and obviously apply that technique to other similar problems?.
评论 #20143749 未加载
justinmeinersalmost 6 years ago
Just wrote an article about the same topic:<p><a href="https:&#x2F;&#x2F;gist.github.com&#x2F;justinmeiners&#x2F;f7d08f99e7e9b8b84f0183ddaa7e830c" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;justinmeiners&#x2F;f7d08f99e7e9b8b84f0183...</a>
abalajialmost 6 years ago
I agree with the point that the author brings up but I think there is a broader point to discuss with regards to a mathematical focus in education. China, for example, is putting a large focus on applying a mathematical modeling perspective to their K-12 education, just look at the results of the MCM of the past few years. [1] I was lucky to be exposed to that frame of thinking in high school and I think it will become ever the more important in all areas, not just hacking, for people to have some sort of training in that respect.<p>[1] <a href="https:&#x2F;&#x2F;www.comap.com&#x2F;undergraduate&#x2F;contests&#x2F;mcm&#x2F;contests&#x2F;2019&#x2F;results&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.comap.com&#x2F;undergraduate&#x2F;contests&#x2F;mcm&#x2F;contests&#x2F;20...</a>
haecceityalmost 6 years ago
Knuth is one of the few authors that shows the derivation of the Binet&#x27;s formula for Fibonacci numbers.
评论 #20144912 未加载
评论 #20143720 未加载