Skip to content

Instantly share code, notes, and snippets.

@amalex5
amalex5 / symdiff.hs
Created March 31, 2016 18:06
symbolic differentiation is SO EASY in haskell!
-- i mean, this is basically just a high school formula sheet
-- that happens to also be valid haskell
-- (we're differentiating against "Symbol")
diff (Symbol) = Val 1
diff (Neg x) = Neg (diff x)
diff (Add x y) = Add (diff x) (diff y)
diff (Mul x y) = Add (Mul (diff x) y ) (Mul x (diff y))
diff (Sub x y) = diff (Add x (Neg y))
diff (Pow x (Val n)) = Mul (Val n) (Pow x (Val (n - 1) ) )

NEVER WRITE A FOR LOOP AGAIN

or, fun folding with map/reduce/filter

andrew alexander

(This is a loose transcription (in some parts, an expansion) of a five-minute talk I gave at the Recurse Center on February 18th, 2016. All of the code I live-coded, so the written version loses some of the pedagological power of narrating my thought process as I type. The code below happens to be JavaScript, but most languages have equivalents.)

ANDREW LONG-TERM TO-DO LIST (DRAFT, FEB 2016)

this is a cleaned-up version of a list i've been adding to for the past several years. i'm not a huge fan of it, because it leaves out the MOST IMPORTANT life to-do: have a successful and productive career (and family). almost everything on this list ("climb mt. rainier!") is secondary to that. too much of this list is about ME (it's things I want). but my life isn't about me. my life is (or ought to be) about things greater than me. i want to (and ought to) devote myself to things outside of myself.

a lot of the items are really specific ("make kimchi") and others more general; some of these are straightforward ("make kimchi") and others a lot harder ("be less self-centered").

i intend this to be a malleable document, but i want to have a cleaned-up, date-stamped draft, representing a reasonable facsimile of what's on my mind right now.

BOOKS