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.

Crash course in mathematical notation for programmers

5 pointsby athesynover 12 years ago

1 comment

csenseover 12 years ago
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).