TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Crash course in mathematical notation for programmers

5 点作者 athesyn超过 12 年前

1 comment

csense超过 12 年前
Love the idea of the post!<p>But there some issues:<p>Sum and product should use range(n+1). Math notation includes both endpoints; Python excludes the right endpoint.<p>The sum code could be written closer to the mathematical "idiom" as sum(a(i) for i in range(n)).<p>Using 'l' (lowercase L) as a variable is bad because it looks like '1' (literal one) in many fonts. Call your list 'u' or something, not 'l'.<p>The binary search code ends abruptly. Maybe it was eaten by the CMS?<p>And general suggestions:<p>Split big-O notation into different article, since it's a large topic.<p>The circle operator is often used for function composition; Python's Pythonicness makes it easy to say something like circ = lambda f, g : lambda <i>a, </i><i>k : f(g(</i>a, <i></i>k))<p>You should also mention that sometimes symbols depend on context. Operators in Python can have different semantics if they're overloaded; identical names can have different meaning due to scope effects, or if different libraries are imported. Likewise, notations in math can have different meanings; you have to be aware of both commonly accepted "default" meanings (just like '+' has built-in meanings for ints, floats, lists and strings) and any less-standard meaning that may have been defined in previous "code" (mathematical text).