Hacker News new | ask | show | jobs
by danso 5014 days ago
My day-to-day programming consists so much of process and simple boolean logic that I hardly ever use math more challenging than 1 + 1 and 1 != 0. It's great to review how math can greatly influence the potential of your code.
2 comments

My experience is that people who are aware of opportunities to use math find them. And people who are not aware conclude that they weren't really there.

For example are you a web developer? Have you started using A/B testing yet? If yes, that's math. If no, then you are in a position to make your employer a substantial amount of money.

For another example my very first project in my first programming job required me to build a set of canned reports. There was one user request which turned into, "We want to do this, but don't know if it is possible." I wound up using inclusion-exclusion techniques that I'd learned in grad school to solve that problem! (The problem was how to ship a local database without detailed information they shouldn't have about the rest of the company, and yet still be able to present reports comparing themselves to the rest of the company. And those reports had to drill down. So if you were responsible for 5 sites you'd be able to generate those reports for everyone that you could see, or for each site individually.)

> simple boolean logic

A SAT solver[1] can automatically figure out a range of acceptable solutions for your conditions. 'I want this goal, is there a way to make that happen?' Security people love this. SMT solvers are even crazier[2] and can automatically determine solutions to linear equations or inequalities (this comes in handy when analyzing loops). Z3 has an online version at [3].

Also, if you have a lot of nasty cascaded if-statements, a K-map[4] and espresso[5] can reduce those down to a minimal set of branches. Note that fewer branches means fewer branch prediction penalties, which means faster code!

[1] http://en.wikipedia.org/wiki/Boolean_satisfiability_problem

[2] http://media.tumblr.com/tumblr_m8ywn1iesH1r6uu3b.gif

[3] http://rise4fun.com/z3/tutorial/guide

[4] http://en.wikipedia.org/wiki/Karnaugh_map

[5] http://embedded.eecs.berkeley.edu/pubs/downloads/espresso/in... and ftp://ftp.cs.man.ac.uk/pub/amulet/balsa/other-software/espresso-ab-1.0.tar.gz