Alternatively, “Practical Math for Programmers”.

All programming is math. Literally, programs are types are proofs — it’s math.

And yet, math isn’t programming. Most day-to-day programming plays with the transformation of strings, dates, and structures.

TODO

TODO

TODO

TODO

Code docs are written for other programmers. Math docs are written for, well, nobody really.

TODO

TODO

TODO

Math hacks! This presentation is filled with shortcuts you can make with math.

Examples of how to use math in practical programming.

Show how in all these examples, it’s better to design these systems with mathematics on-paper.
If you see *this*, you should think of *that*.

Express elegant representations to make life easier and avoid mistakes.

- First, find a
*good representation*on paper! Math is useful here. - Implement the representation in your code!

TODO

TODO

TODO

I personally prefer to have all of my if-statements accompanied by else-statements — it forces me to address every possible path of the conditional.
Whenever you’re selectively applying functions in cases, `identity`

makes a great default case.

```
if a < b:
x = f( x )
elif a > b:
x = g( x )
return x
if a < b:
x = f( x )
elif a > b:
x = g( x )
else:
x = identity( x )
if a < b:
h = f
elif a > b:
h = g
else:
h = identity
return h( x )
```

```
rescale:(A->B)->(X->Y)
function rescale() {
return ( ( new_max - new_min )
/ ( old_max - old_min )
)
* ( v - old_max )
+ new_max;
};
function rescale() {
const new_range = new_max - new_min;
const old_range = old_max - old_min;
return ( new_range / old_range )
* ( v - old_max )
+ ( new_max )
};
<!-- <todo: using pos/neg infinity as a max/min> -->
<!-- <todo: piping/composing functions into rescale> -->
```

TODO

Have you ever checked for duplicates in an array/list? What unnecessary work! In most languages, we have primitive sets to help with these cases.

Whenever you have groups of things where duplication is undesired and order doesn’t matter, consider using a set!

Here’s a real-life example:

```
result = []
for x in xs:
if x in white_list:
result.push( x )
return result
return xs.filter( x => x in white_list )
return intersect( xs, white_list )
```

And here’s another:

```
cats = cats_query(...)
mammals = mammals_query(...)
for( cat in cats ):
if cat not in mammals:
mammals.push( cat )
return mammals
return union( cats, mammals )
```

In short, whenever you’re comparing lists for membership, that should scream “set operations”!

Whenever you have a list of pairs, or an object where you need duplicate keys, you should think “map”!

TODO

Large systems often have a bunch of encapsulated objects. Category theory sometimes helps translate to/from different instances of classes.

If you find yourself needing to access lists of things in strange ways, you’ll often need the modulo operator!

```
while(true):
println( xs[ ++i % xs.length ] )
```

TODO

TODO

TODO

Most dynamic languages don’t give us union types!

What else are symbols good for?

```
f(x) = x + x
f = λx.x+x
f' = λx.λy.x+y
```

Whenever you hear the word “pipeline” you should think of composition!

```
y = f(x)
z = g(y)
z = f(g(x))
z = compose(f,g)(x)
```

In JS, it’s often better to make your functions curryable!

`const = x => y => x + y;`

TODO

TODO

TODO

TODO

TODO

TODO

TODO

TODO

TODO

TODO

TODO

TODO

```
if is_something( x ):
x = 0
return 0
return is_something( x )
? x
: 0
```

TODO

TODO

TODO

TODO

TODO

TODO

TODO

TODO

TODO

TODO

TODO

TODO

TODO

TODO

TODO

TODO

TODO

TODO

TODO

TODO

TODO

```
if x < 0:
return 0
else:
return x
return min( 0, x )
return max( min( 0, x ), 100 )
if x < y:
return x
else:
return y
return min( x, y )
max_of_xs = 0
for xs:
if x > max_of_xs:
max_of_xs = x
return max_of_xs
return max.apply( xs )
```

TODO

TODO

TODO

TODO

TODO

TODO

TODO

TODO

TODO

TODO

TODO

TODO

TODO

TODO

TODO