diff --git a/cheatfiles/math-as-code.md b/cheatfiles/math-as-code.md
new file mode 100644
index 0000000..93a0072
--- /dev/null
+++ b/cheatfiles/math-as-code.md
@@ -0,0 +1,1074 @@
+# math-as-code
+
+>[Chinese translation (中文版)](./README-zh.md)
+
+This is a reference to ease developers into mathematical notation by showing comparisons with JavaScript code.
+
+Motivation: Academic papers can be intimidating for self-taught game and graphics programmers. :)
+
+This guide is not yet finished. If you see errors or want to contribute, please [open a ticket](https://github.com/Jam3/math-as-code/issues) or send a PR.
+
+> **Note**: For brevity, some code examples make use of [npm packages](https://www.npmjs.com/). You can refer to their GitHub repos for implementation details.
+
+
+
+# foreword
+
+Mathematical symbols can mean different things depending on the author, context and the field of study (linear algebra, set theory, etc). This guide may not cover *all* uses of a symbol. In some cases, real-world references (blog posts, publications, etc) will be cited to demonstrate how a symbol might appear in the wild.
+
+For a more complete list, refer to [Wikipedia - List of Mathematical Symbols](https://en.wikipedia.org/wiki/List_of_mathematical_symbols).
+
+For simplicity, many of the code examples here operate on floating point values and are not numerically robust. For more details on why this may be a problem, see [Robust Arithmetic Notes](https://github.com/mikolalysenko/robust-arithmetic-notes) by Mikola Lysenko.
+
+# contents
+
+- [variable name conventions](#variable-name-conventions)
+- [equals `=` `≈` `≠` `:=`](#equals-symbols)
+- [square root and complex numbers `√` *`i`*](#square-root-and-complex-numbers)
+- [dot & cross `·` `×` `∘`](#dot--cross)
+ - [scalar multiplication](#scalar-multiplication)
+ - [vector multiplication](#vector-multiplication)
+ - [dot product](#dot-product)
+ - [cross product](#cross-product)
+- [sigma `Σ`](#sigma) - *summation*
+- [capital Pi `Π`](#capital-pi) - *products of sequences*
+- [pipes `||`](#pipes)
+ - [absolute value](#absolute-value)
+ - [Euclidean norm](#euclidean-norm)
+ - [determinant](#determinant)
+- [hat **`â`**](#hat) - *unit vector*
+- ["element of" `∈` `∉`](#element)
+- [common number sets `ℝ` `ℤ` `ℚ` `ℕ`](#common-number-sets)
+- [function `ƒ`](#function)
+ - [piecewise function](#piecewise-function)
+ - [common functions](#common-functions)
+ - [function notation `↦` `→`](#function-notation)
+- [prime `′`](#prime)
+- [floor & ceiling `⌊` `⌉`](#floor--ceiling)
+- [arrows](#arrows)
+ - [material implication `⇒` `→`](#material-implication)
+ - [equality `<` `≥` `≫`](#equality)
+ - [conjunction & disjunction `∧` `∨`](#conjunction--disjunction)
+- [logical negation `¬` `~` `!`](#logical-negation)
+- [intervals](#intervals)
+- [more...](#more)
+
+## variable name conventions
+
+There are a variety of naming conventions depending on the context and field of study, and they are not always consistent. However, in some of the literature you may find variable names to follow a pattern like so:
+
+- *s* - italic lowercase letters for scalars (e.g. a number)
+- **x** - bold lowercase letters for vectors (e.g. a 2D point)
+- **A** - bold uppercase letters for matrices (e.g. a 3D transformation)
+- *θ* - italic lowercase Greek letters for constants and special variables (e.g. [polar angle *θ*, *theta*](https://en.wikipedia.org/wiki/Spherical_coordinate_system))
+
+This will also be the format of this guide.
+
+## equals symbols
+
+There are a number of symbols resembling the equals sign `=`. Here are a few common examples:
+
+- `=` is for equality (values are the same)
+- `≠` is for inequality (value are not the same)
+- `≈` is for approximately equal to (`π ≈ 3.14159`)
+- `:=` is for definition (A is defined as B)
+
+In JavaScript:
+
+```js
+// equality
+2 === 3
+
+// inequality
+2 !== 3
+
+// approximately equal
+almostEqual(Math.PI, 3.14159, 1e-5)
+
+function almostEqual(a, b, epsilon) {
+ return Math.abs(a - b) <= epsilon
+}
+```
+
+You might see the `:=`, `=:` and `=` symbols being used for *definition*.[1]
+
+For example, the following defines *x* to be another name for 2*kj*.
+
+![equals1](http://latex.codecogs.com/svg.latex?x%20%3A%3D%202kj)
+
+
+
+In JavaScript, we might use `var` to *define* our variables and provide aliases:
+
+```js
+var x = 2 * k * j
+```
+
+However, this is mutable, and only takes a snapshot of the values at that time. Some languages have pre-processor `#define` statements, which are closer to a mathematical *define*.
+
+A more accurate *define* in JavaScript (ES6) might look a bit like this:
+
+```js
+const f = (k, j) => 2 * k * j
+```
+
+The following, on the other hand, represents equality:
+
+![equals2](http://latex.codecogs.com/svg.latex?x%20%3D%202kj)
+
+
+
+The above equation might be interpreted in code as an [assertion](https://developer.mozilla.org/en-US/docs/Web/API/console/assert):
+
+```js
+console.assert(x === (2 * k * j))
+```
+
+## square root and complex numbers
+
+A square root operation is of the form:
+
+![squareroot](http://latex.codecogs.com/svg.latex?%5Cleft%28%5Csqrt%7Bx%7D%5Cright%29%5E2%20%3D%20x)
+
+
+
+In programming we use a `sqrt` function, like so:
+
+```js
+var x = 9;
+console.log(Math.sqrt(x));
+//=> 3
+```
+
+Complex numbers are expressions of the form ![complex](http://latex.codecogs.com/svg.latex?a&space;+&space;ib), where ![a](http://latex.codecogs.com/svg.latex?a) is the real part and ![b](http://latex.codecogs.com/svg.latex?b) is the imaginary part. The imaginary number ![i](http://latex.codecogs.com/svg.latex?i) is defined as:
+
+![imaginary](http://latex.codecogs.com/svg.latex?i%3D%5Csqrt%7B-1%7D).
+
+
+In JavaScript, there is no built-in functionality for complex numbers, but there are some libraries that support complex number arithmetic. For example, using [mathjs](https://www.npmjs.com/package/mathjs):
+
+```js
+var math = require('mathjs')
+
+var a = math.complex(3, -1)
+//=> { re: 3, im: -1 }
+
+var b = math.sqrt(-1)
+//=> { re: 0, im: -1 }
+
+console.log(math.multiply(a, b).toString())
+//=> '1 + 3i'
+```
+
+The library also supports evaluating a string expression, so the above could be re-written as:
+
+```js
+console.log(math.eval('(3 - i) * i').toString())
+//=> '1 + 3i'
+```
+
+Other implementations:
+
+- [immutable-complex](https://www.npmjs.com/package/immutable-complex)
+- [complex-js](https://www.npmjs.com/package/complex-js)
+- [Numeric-js](http://www.numericjs.com/)
+
+## dot & cross
+
+The dot `·` and cross `×` symbols have different uses depending on context.
+
+They might seem obvious, but it's important to understand the subtle differences before we continue into other sections.
+
+#### scalar multiplication
+
+Both symbols can represent simple multiplication of scalars. The following are equivalent:
+
+![dotcross1](http://latex.codecogs.com/svg.latex?5%20%5Ccdot%204%20%3D%205%20%5Ctimes%204)
+
+
+
+In programming languages we tend to use asterisk for multiplication:
+
+```js
+var result = 5 * 4
+```
+
+Often, the multiplication sign is only used to avoid ambiguity (e.g. between two numbers). Here, we can omit it entirely:
+
+![dotcross2](http://latex.codecogs.com/svg.latex?3kj)
+
+
+
+If these variables represent scalars, the code would be:
+
+```js
+var result = 3 * k * j
+```
+
+#### vector multiplication
+
+To denote multiplication of one vector with a scalar, or element-wise multiplication of a vector with another vector, we typically do not use the dot `·` or cross `×` symbols. These have different meanings in linear algebra, discussed shortly.
+
+Let's take our earlier example but apply it to vectors. For element-wise vector multiplication, you might see an open dot `∘` to represent the [Hadamard product](https://en.wikipedia.org/wiki/Hadamard_product_%28matrices%29).[2]
+
+![dotcross3](http://latex.codecogs.com/svg.latex?3%5Cmathbf%7Bk%7D%5Ccirc%5Cmathbf%7Bj%7D)
+
+
+
+In other instances, the author might explicitly define a different notation, such as a circled dot `⊙` or a filled circle `●`.[3]
+
+Here is how it would look in code, using arrays `[x, y]` to represent the 2D vectors.
+
+```js
+var s = 3
+var k = [ 1, 2 ]
+var j = [ 2, 3 ]
+
+var tmp = multiply(k, j)
+var result = multiplyScalar(tmp, s)
+//=> [ 6, 18 ]
+```
+
+Our `multiply` and `multiplyScalar` functions look like this:
+
+```js
+function multiply(a, b) {
+ return [ a[0] * b[0], a[1] * b[1] ]
+}
+
+function multiplyScalar(a, scalar) {
+ return [ a[0] * scalar, a[1] * scalar ]
+}
+```
+
+Similarly, matrix multiplication typically does not use the dot `·` or cross symbol `×`. Matrix multiplication will be covered in a later section.
+
+#### dot product
+
+The dot symbol `·` can be used to denote the [*dot product*](https://en.wikipedia.org/wiki/Dot_product) of two vectors. Sometimes this is called the *scalar product* since it evaluates to a scalar.
+
+![dotcross4](http://latex.codecogs.com/svg.latex?%5Cmathbf%7Bk%7D%5Ccdot%20%5Cmathbf%7Bj%7D)
+
+
+
+It is a very common feature of linear algebra, and with a 3D vector it might look like this:
+
+```js
+var k = [ 0, 1, 0 ]
+var j = [ 1, 0, 0 ]
+
+var d = dot(k, j)
+//=> 0
+```
+
+The result `0` tells us our vectors are perpendicular. Here is a `dot` function for 3-component vectors:
+
+```js
+function dot(a, b) {
+ return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]
+}
+```
+
+#### cross product
+
+The cross symbol `×` can be used to denote the [*cross product*](https://en.wikipedia.org/wiki/Cross_product) of two vectors.
+
+![dotcross5](http://latex.codecogs.com/svg.latex?%5Cmathbf%7Bk%7D%5Ctimes%20%5Cmathbf%7Bj%7D)
+
+
+
+In code, it would look like this:
+
+```js
+var k = [ 0, 1, 0 ]
+var j = [ 1, 0, 0 ]
+
+var result = cross(k, j)
+//=> [ 0, 0, -1 ]
+```
+
+Here, we get `[ 0, 0, -1 ]`, which is perpendicular to both **k** and **j**.
+
+Our `cross` function:
+
+```js
+function cross(a, b) {
+ var ax = a[0], ay = a[1], az = a[2],
+ bx = b[0], by = b[1], bz = b[2]
+
+ var rx = ay * bz - az * by
+ var ry = az * bx - ax * bz
+ var rz = ax * by - ay * bx
+ return [ rx, ry, rz ]
+}
+```
+
+For other implementations of vector multiplication, cross product, and dot product:
+
+- [gl-vec3](https://github.com/stackgl/gl-vec3)
+- [gl-vec2](https://github.com/stackgl/gl-vec2)
+- [vectors](https://github.com/hughsk/vectors) - includes n-dimensional
+
+## sigma
+
+The big Greek `Σ` (Sigma) is for [Summation](https://en.wikipedia.org/wiki/Summation). In other words: summing up some numbers.
+
+![sigma](http://latex.codecogs.com/svg.latex?%5Csum_%7Bi%3D1%7D%5E%7B100%7Di)
+
+
+
+Here, `i=1` says to start at `1` and end at the number above the Sigma, `100`. These are the lower and upper bounds, respectively. The *i* to the right of the "E" tells us what we are summing. In code:
+
+```js
+var sum = 0
+for (var i = 1; i <= 100; i++) {
+ sum += i
+}
+```
+
+The result of `sum` is `5050`.
+
+**Tip:** With whole numbers, this particular pattern can be optimized to the following:
+
+```js
+var n = 100 // upper bound
+var sum = (n * (n + 1)) / 2
+```
+
+Here is another example where the *i*, or the "what to sum," is different:
+
+![sum2](http://latex.codecogs.com/svg.latex?%5Csum_%7Bi%3D1%7D%5E%7B100%7D%282i+1%29)
+
+
+
+In code:
+
+```js
+var sum = 0
+for (var i = 1; i <= 100; i++) {
+ sum += (2 * i + 1)
+}
+```
+
+The result of `sum` is `10200`.
+
+The notation can be nested, which is much like nesting a `for` loop. You should evaluate the right-most sigma first, unless the author has enclosed them in parentheses to alter the order. However, in the following case, since we are dealing with finite sums, the order does not matter.
+
+![sigma3](http://latex.codecogs.com/svg.latex?%5Csum_%7Bi%3D1%7D%5E%7B2%7D%5Csum_%7Bj%3D4%7D%5E%7B6%7D%283ij%29)
+
+
+
+In code:
+
+```js
+var sum = 0
+for (var i = 1; i <= 2; i++) {
+ for (var j = 4; j <= 6; j++) {
+ sum += (3 * i * j)
+ }
+}
+```
+
+Here, `sum` will be `135`.
+
+## capital Pi
+
+The capital Pi or "Big Pi" is very similar to [Sigma](#sigma), except we are using multiplication to find the product of a sequence of values.
+
+Take the following:
+
+![capitalPi](http://latex.codecogs.com/svg.latex?%5Cprod_%7Bi%3D1%7D%5E%7B6%7Di)
+
+
+
+In code, it might look like this:
+
+```js
+var value = 1
+for (var i = 1; i <= 6; i++) {
+ value *= i
+}
+```
+
+Where `value` will evaluate to `720`.
+
+## pipes
+
+Pipe symbols, known as *bars*, can mean different things depending on the context. Below are three common uses: [absolute value](#absolute-value), [Euclidean norm](#euclidean-norm), and [determinant](#determinant).
+
+These three features all describe the *length* of an object.
+
+#### absolute value
+
+![pipes1](http://latex.codecogs.com/svg.latex?%5Cleft%20%7C%20x%20%5Cright%20%7C)
+
+
+
+For a number *x*, `|x|` means the absolute value of *x*. In code:
+
+```js
+var x = -5
+var result = Math.abs(x)
+// => 5
+```
+
+#### Euclidean norm
+
+![pipes4](http://latex.codecogs.com/svg.latex?%5Cleft%20%5C%7C%20%5Cmathbf%7Bv%7D%20%5Cright%20%5C%7C)
+
+
+
+For a vector **v**, `‖v‖` is the [Euclidean norm](https://en.wikipedia.org/wiki/Norm_%28mathematics%29#Euclidean_norm) of **v**. It is also referred to as the "magnitude" or "length" of a vector.
+
+Often this is represented by double-bars to avoid ambiguity with the *absolute value* notation, but sometimes you may see it with single bars:
+
+![pipes2](http://latex.codecogs.com/svg.latex?%5Cleft%20%7C%20%5Cmathbf%7Bv%7D%20%5Cright%20%7C)
+
+
+
+Here is an example using an array `[x, y, z]` to represent a 3D vector.
+
+```js
+var v = [ 0, 4, -3 ]
+length(v)
+//=> 5
+```
+
+The `length` function:
+
+```js
+function length (vec) {
+ var x = vec[0]
+ var y = vec[1]
+ var z = vec[2]
+ return Math.sqrt(x * x + y * y + z * z)
+}
+```
+
+Other implementations:
+
+- [magnitude](https://github.com/mattdesl/magnitude/blob/864ff5a7eb763d34bf154ac5f5332d7601192b70/index.js) - n-dimensional
+- [gl-vec2/length](https://github.com/stackgl/gl-vec2/blob/21f460a371540258521fd2f720d80f14e87bd400/length.js) - 2D vector
+- [gl-vec3/length](https://github.com/stackgl/gl-vec3/blob/507480fa57ba7c5fb70679cf531175a52c48cf53/length.js) - 3D vector
+
+#### determinant
+
+![pipes3](http://latex.codecogs.com/svg.latex?%5Cleft%20%7C%5Cmathbf%7BA%7D%20%5Cright%20%7C)
+
+
+
+For a matrix **A**, `|A|` means the [determinant](https://en.wikipedia.org/wiki/Determinant) of matrix **A**.
+
+Here is an example computing the determinant of a 2x2 matrix, represented by a flat array in column-major format.
+
+```js
+var determinant = require('gl-mat2/determinant')
+
+var matrix = [ 1, 0, 0, 1 ]
+var det = determinant(matrix)
+//=> 1
+```
+
+Implementations:
+
+- [gl-mat4/determinant](https://github.com/stackgl/gl-mat4/blob/c2e2de728fe7eba592f74cd02266100cc21ec89a/determinant.js) - also see [gl-mat3](https://github.com/stackgl/gl-mat3) and [gl-mat2](https://github.com/stackgl/gl-mat2)
+- [ndarray-determinant](https://www.npmjs.com/package/ndarray-determinant)
+- [glsl-determinant](https://www.npmjs.com/package/glsl-determinant)
+- [robust-determinant](https://www.npmjs.com/package/robust-determinant)
+- [robust-determinant-2](https://www.npmjs.com/package/robust-determinant-2) and [robust-determinant-3](https://www.npmjs.com/package/robust-determinant-3), specifically for 2x2 and 3x3 matrices, respectively
+
+## hat
+
+In geometry, the "hat" symbol above a character is used to represent a [unit vector](https://en.wikipedia.org/wiki/Unit_vector). For example, here is the unit vector of **a**:
+
+![hat](http://latex.codecogs.com/svg.latex?%5Chat%7B%5Cmathbf%7Ba%7D%7D)
+
+
+
+In Cartesian space, a unit vector is typically length 1. That means each part of the vector will be in the range of -1.0 to 1.0. Here we *normalize* a 3D vector into a unit vector:
+
+```js
+var a = [ 0, 4, -3 ]
+normalize(a)
+//=> [ 0, 0.8, -0.6 ]
+```
+
+Here is the `normalize` function, operating on 3D vectors:
+
+```js
+function normalize(vec) {
+ var x = vec[0]
+ var y = vec[1]
+ var z = vec[2]
+ var squaredLength = x * x + y * y + z * z
+
+ if (squaredLength > 0) {
+ var length = Math.sqrt(squaredLength)
+ vec[0] = vec[0] / length
+ vec[1] = vec[1] / length
+ vec[2] = vec[2] / length
+ }
+ return vec
+}
+```
+
+Other implementations:
+
+- [gl-vec3/normalize](https://github.com/stackgl/gl-vec3/blob/507480fa57ba7c5fb70679cf531175a52c48cf53/normalize.js) and [gl-vec2/normalize](https://github.com/stackgl/gl-vec2/blob/21f460a371540258521fd2f720d80f14e87bd400/normalize.js)
+- [vectors/normalize-nd](https://github.com/hughsk/vectors/blob/master/normalize-nd.js) (n-dimensional)
+
+## element
+
+In set theory, the "element of" symbol `∈` and `∋` can be used to describe whether something is an element of a *set*. For example:
+
+![element1](http://latex.codecogs.com/svg.latex?A%3D%5Cleft%20%5C%7B3%2C9%2C14%7D%7B%20%5Cright%20%5C%7D%2C%203%20%5Cin%20A)
+
+
+
+Here we have a set of numbers *A* `{ 3, 9, 14 }` and we are saying `3` is an "element of" that set.
+
+A simple implementation in ES5 might look like this:
+
+```js
+var A = [ 3, 9, 14 ]
+
+A.indexOf(3) >= 0
+//=> true
+```
+
+However, it would be more accurate to use a `Set` which only holds unique values. This is a feature of ES6.
+
+```js
+var A = new Set([ 3, 9, 14 ])
+
+A.has(3)
+//=> true
+```
+
+The backwards `∋` is the same, but the order changes:
+
+![element2](http://latex.codecogs.com/svg.latex?A%3D%5Cleft%20%5C%7B3%2C9%2C14%7D%7B%20%5Cright%20%5C%7D%2C%20A%20%5Cni%203)
+
+
+
+You can also use the "not an element of" symbols `∉` and `∌` like so:
+
+![element3](http://latex.codecogs.com/svg.latex?A%3D%5Cleft%20%5C%7B3%2C9%2C14%7D%7B%20%5Cright%20%5C%7D%2C%206%20%5Cnotin%20A)
+
+
+
+## common number sets
+
+You may see some some large [Blackboard](https://en.wikipedia.org/wiki/Blackboard_bold) letters among equations. Often, these are used to describe sets.
+
+For example, we might describe *k* to be an [element of](#element) the set `ℝ`.
+
+![real](http://latex.codecogs.com/svg.latex?k%20%5Cin%20%5Cmathbb%7BR%7D)
+
+
+
+Listed below are a few common sets and their symbols.
+
+#### `ℝ` real numbers
+
+The large `ℝ` describes the set of *real numbers*. These include integers, as well as rational and irrational numbers.
+
+JavaScript treats floats and integers as the same type, so the following would be a simple test of our *k* ∈ ℝ example:
+
+```js
+function isReal (k) {
+ return typeof k === 'number' && isFinite(k);
+}
+```
+
+*Note:* Real numbers are also *finite*, as in, *not infinite.*
+
+#### `ℚ` rational numbers
+
+Rational numbers are real numbers that can be expressed as a fraction, or *ratio* (like `⅗`). Rational numbers cannot have zero as a denominator.
+
+This also means that all integers are rational numbers, since the denominator can be expressed as 1.
+
+An irrational number, on the other hand, is one that cannot be expressed as a ratio, like π (PI).
+
+#### `ℤ` integers
+
+An integer, i.e. a real number that has no fractional part. These can be positive or negative.
+
+A simple test in JavaScript might look like this:
+
+```js
+function isInteger (n) {
+ return typeof n === 'number' && n % 1 === 0
+}
+```
+
+#### `ℕ` natural numbers
+
+A natural number, a positive and non-negative integer. Depending on the context and field of study, the set may or may not include zero, so it could look like either of these:
+
+```js
+{ 0, 1, 2, 3, ... }
+{ 1, 2, 3, 4, ... }
+```
+
+The former is more common in computer science, for example:
+
+```js
+function isNaturalNumber (n) {
+ return isInteger(n) && n >= 0
+}
+```
+
+#### `ℂ` complex numbers
+
+A complex number is a combination of a real and imaginary number, viewed as a co-ordinate in the 2D plane. For more info, see [A Visual, Intuitive Guide to Imaginary Numbers](http://betterexplained.com/articles/a-visual-intuitive-guide-to-imaginary-numbers/).
+
+## function
+
+[Functions](https://en.wikipedia.org/wiki/Function_%28mathematics%29) are fundamental features of mathematics, and the concept is fairly easy to translate into code.
+
+A function relates an input to an output value. For example, the following is a function:
+
+![function1](http://latex.codecogs.com/svg.latex?x%5E%7B2%7D)
+
+
+
+We can give this function a *name*. Commonly, we use `ƒ` to describe a function, but it could be named `A(x)` or anything else.
+
+![function2](http://latex.codecogs.com/svg.latex?f%5Cleft%20%28x%20%5Cright%20%29%20%3D%20x%5E%7B2%7D)
+
+
+
+In code, we might name it `square` and write it like this:
+
+```js
+function square (x) {
+ return Math.pow(x, 2)
+}
+```
+
+Sometimes a function is not named, and instead the output is written.
+
+![function3](http://latex.codecogs.com/svg.latex?y%20%3D%20x%5E%7B2%7D)
+
+
+
+In the above example, *x* is the input, the relationship is *squaring*, and *y* is the output.
+
+Functions can also have multiple parameters, like in a programming language. These are known as *arguments* in mathematics, and the number of arguments a function takes is known as the *arity* of the function.
+
+![function4](http://latex.codecogs.com/svg.latex?f%28x%2Cy%29%20%3D%20%5Csqrt%7Bx%5E2%20+%20y%5E2%7D)
+
+
+
+In code:
+
+```js
+function length (x, y) {
+ return Math.sqrt(x * x + y * y)
+}
+```
+
+### piecewise function
+
+Some functions will use different relationships depending on the input value, *x*.
+
+The following function *ƒ* chooses between two "sub functions" depending on the input value.
+
+![piecewise1](http://latex.codecogs.com/svg.latex?f%28x%29%3D%20%5Cbegin%7Bcases%7D%20%5Cfrac%7Bx%5E2-x%7D%7Bx%7D%2C%26%20%5Ctext%7Bif%20%7D%20x%5Cgeq%201%5C%5C%200%2C%20%26%20%5Ctext%7Botherwise%7D%20%5Cend%7Bcases%7D)
+
+
+
+This is very similar to `if` / `else` in code. The right-side conditions are often written as **"for x < 0"** or **"if x = 0"**. If the condition is true, the function to the left is used.
+
+In piecewise functions, **"otherwise"** and **"elsewhere"** are analogous to the `else` statement in code.
+
+```js
+function f (x) {
+ if (x >= 1) {
+ return (Math.pow(x, 2) - x) / x
+ } else {
+ return 0
+ }
+}
+```
+
+### common functions
+
+There are some function names that are ubiquitous in mathematics. For a programmer, these might be analogous to functions "built-in" to the language (like `parseInt` in JavaScript).
+
+One such example is the *sgn* function. This is the *signum* or *sign* function. Let's use [piecewise function](#piecewise-function) notation to describe it:
+
+![sgn](http://latex.codecogs.com/svg.latex?sgn%28x%29%20%3A%3D%20%5Cbegin%7Bcases%7D%20-1%26%20%5Ctext%7Bif%20%7D%20x%20%3C%200%5C%5C%200%2C%20%26%20%5Ctext%7Bif%20%7D%20%7Bx%20%3D%200%7D%5C%5C%201%2C%20%26%20%5Ctext%7Bif%20%7D%20x%20%3E%200%5C%5C%20%5Cend%7Bcases%7D)
+
+
+
+In code, it might look like this:
+
+```js
+function sgn (x) {
+ if (x < 0) return -1
+ if (x > 0) return 1
+ return 0
+}
+```
+
+See [signum](https://github.com/scijs/signum) for this function as a module.
+
+Other examples of such functions: *sin*, *cos*, *tan*.
+
+### function notation
+
+In some literature, functions may be defined with more explicit notation. For example, let's go back to the `square` function we mentioned earlier:
+
+![function2](http://latex.codecogs.com/svg.latex?f%5Cleft%20%28x%20%5Cright%20%29%20%3D%20x%5E%7B2%7D)
+
+
+
+It might also be written in the following form:
+
+![mapsto](http://latex.codecogs.com/svg.latex?f%20%3A%20x%20%5Cmapsto%20x%5E2)
+
+
+
+The arrow here with a tail typically means "maps to," as in *x maps to x2*.
+
+Sometimes, when it isn't obvious, the notation will also describe the *domain* and *codomain* of the function. A more formal definition of *ƒ* might be written as:
+
+![funcnot](http://latex.codecogs.com/svg.latex?%5Cbegin%7Balign*%7D%20f%20%3A%26%5Cmathbb%7BR%7D%20%5Crightarrow%20%5Cmathbb%7BR%7D%5C%5C%20%26x%20%5Cmapsto%20x%5E2%20%5Cend%7Balign*%7D)
+
+
+
+A function's *domain* and *codomain* is a bit like its *input* and *output* types, respectively. Here's another example, using our earlier *sgn* function, which outputs an integer:
+
+![domain2](http://latex.codecogs.com/svg.latex?sgn%20%3A%20%5Cmathbb%7BR%7D%20%5Crightarrow%20%5Cmathbb%7BZ%7D)
+
+
+
+The arrow here (without a tail) is used to map one *set* to another.
+
+In JavaScript and other dynamically typed languages, you might use documentation and/or runtime checks to explain and validate a function's input/output. Example:
+
+```js
+/**
+ * Squares a number.
+ * @param {Number} a real number
+ * @return {Number} a real number
+ */
+function square (a) {
+ if (typeof a !== 'number') {
+ throw new TypeError('expected a number')
+ }
+ return Math.pow(a, 2)
+}
+```
+
+Some tools like [flowtype](http://flowtype.org/) attempt to bring static typing into JavaScript.
+
+Other languages, like Java, allow for true method overloading based on the static types of a function's input/output. This is closer to mathematics: two functions are not the same if they use a different *domain*.
+
+## prime
+
+The prime symbol (`′`) is often used in variable names to describe things which are similar, without giving it a different name altogether. It can describe the "next value" after some transformation.
+
+For example, if we take a 2D point *(x, y)* and rotate it, you might name the result *(x′, y′)*. Or, the *transpose* of matrix **M** might be named **M′**.
+
+In code, we typically just assign the variable a more descriptive name, like `transformedPosition`.
+
+For a mathematical [function](#function), the prime symbol often describes the *derivative* of that function. Derivatives will be explained in a future section. Let's take our earlier function:
+
+![function2](http://latex.codecogs.com/svg.latex?f%5Cleft%20%28x%20%5Cright%20%29%20%3D%20x%5E%7B2%7D)
+
+
+
+Its derivative could be written with a prime `′` symbol:
+
+![prime1](http://latex.codecogs.com/svg.latex?f%27%28x%29%20%3D%202x)
+
+
+
+In code:
+
+```js
+function f (x) {
+ return Math.pow(x, 2)
+}
+
+function fPrime (x) {
+ return 2 * x
+}
+```
+
+Multiple prime symbols can be used to describe the second derivative *ƒ′′* and third derivative *ƒ′′′*. After this, authors typically express higher orders with roman numerals *ƒ*IV or superscript numbers *ƒ*(n).
+
+## floor & ceiling
+
+The special brackets `⌊x⌋` and `⌈x⌉` represent the *floor* and *ceil* functions, respectively.
+
+![floor](http://latex.codecogs.com/svg.latex?floor%28x%29%20%3D%20%5Clfloor%20x%20%5Crfloor)
+
+
+
+![ceil](http://latex.codecogs.com/svg.latex?ceil%28x%29%20%3D%20%5Clceil%20x%20%5Crceil)
+
+
+
+In code:
+
+```js
+Math.floor(x)
+Math.ceil(x)
+```
+
+When the two symbols are mixed `⌊x⌉`, it typically represents a function that rounds to the nearest integer:
+
+![round](http://latex.codecogs.com/svg.latex?round%28x%29%20%3D%20%5Clfloor%20x%20%5Crceil)
+
+
+
+In code:
+
+```js
+Math.round(x)
+```
+
+## arrows
+
+Arrows are often used in [function notation](#function-notation). Here are a few other areas you might see them.
+
+#### material implication
+
+Arrows like `⇒` and `→` are sometimes used in logic for *material implication.* That is, if A is true, then B is also true.
+
+![material1](http://latex.codecogs.com/svg.latex?A%20%5CRightarrow%20B)
+
+
+
+Interpreting this as code might look like this:
+
+```js
+if (A === true) {
+ console.assert(B === true)
+}
+```
+
+The arrows can go in either direction `⇐` `⇒`, or both `⇔`. When *A ⇒ B* and *B ⇒ A*, they are said to be equivalent:
+
+![material-equiv](http://latex.codecogs.com/svg.latex?A%20%5CLeftrightarrow%20B)
+
+
+
+#### equality
+
+In math, the `<` `>` `≤` and `≥` are typically used in the same way we use them in code: *less than*, *greater than*, *less than or equal to* and *greater than or equal to*, respectively.
+
+```js
+50 > 2 === true
+2 < 10 === true
+3 <= 4 === true
+4 >= 4 === true
+```
+
+On rare occasions you might see a slash through these symbols, to describe *not*. As in, *k* is "not greater than" *j*.
+
+![ngt](http://latex.codecogs.com/svg.latex?k%20%5Cngtr%20j)
+
+
+
+The `≪` and `≫` are sometimes used to represent *significant* inequality. That is, *k* is an [order of magnitude](https://en.wikipedia.org/wiki/Order_of_magnitude) larger than *j*.
+
+![orderofmag](http://latex.codecogs.com/svg.latex?k%20%5Cgg%20j)
+
+
+
+In mathematics, *order of magnitude* is rather specific; it is not just a "really big difference." A simple example of the above:
+
+```js
+orderOfMagnitude(k) > orderOfMagnitude(j)
+```
+
+And below is our `orderOfMagnitude` function, using [Math.trunc](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc) (ES6).
+
+```js
+function log10(n) {
+ // logarithm in base 10
+ return Math.log(n) / Math.LN10
+}
+
+function orderOfMagnitude (n) {
+ return Math.trunc(log10(n))
+}
+```
+
+*Note:* This is not numerically robust.
+
+See [math-trunc](https://www.npmjs.com/package/math-trunc) for a ponyfill in ES5.
+
+#### conjunction & disjunction
+
+Another use of arrows in logic is conjunction `∧` and disjunction `∨`. They are analogous to a programmer's `AND` and `OR` operators, respectively.
+
+The following shows conjunction `∧`, the logical `AND`.
+
+![and](http://latex.codecogs.com/svg.latex?k%20%3E%202%20%5Cland%20k%20%3C%204%20%5CLeftrightarrow%20k%20%3D%203)
+
+
+
+In JavaScript, we use `&&`. Assuming *k* is a natural number, the logic implies that *k* is 3:
+
+```js
+if (k > 2 && k < 4) {
+ console.assert(k === 3)
+}
+```
+
+Since both sides are equivalent `⇔`, it also implies the following:
+
+```js
+if (k === 3) {
+ console.assert(k > 2 && k < 4)
+}
+```
+
+The down arrow `∨` is logical disjunction, like the OR operator.
+
+![logic-or](http://latex.codecogs.com/svg.latex?A%20%5Clor%20B)
+
+
+
+In code:
+
+```js
+A || B
+```
+
+## logical negation
+
+Occasionally, the `¬`, `~` and `!` symbols are used to represent logical `NOT`. For example, *¬A* is only true if A is false.
+
+Here is a simple example using the *not* symbol:
+
+![negation](http://latex.codecogs.com/svg.latex?x%20%5Cneq%20y%20%5CLeftrightarrow%20%5Clnot%28x%20%3D%20y%29)
+
+
+
+An example of how we might interpret this in code:
+
+```js
+if (x !== y) {
+ console.assert(!(x === y))
+}
+```
+
+*Note:* The tilde `~` has many different meanings depending on context. For example, *row equivalence* (matrix theory) or *same order of magnitude* (discussed in [equality](#equality)).
+
+## intervals
+
+Sometimes a function deals with real numbers restricted to some range of values, such a constraint can be represented using an *interval*
+
+For example we can represent the numbers between zero and one including/not including zero and/or one as:
+
+- Not including zero or one: ![interval-opened-left-opened-right](http://latex.codecogs.com/svg.latex?%280%2C%201%29)
+
+
+
+- Including zero or but not one: ![interval-closed-left-opened-right](http://latex.codecogs.com/svg.latex?%5B0%2C%201%29)
+
+
+
+- Not including zero but including one: ![interval-opened-left-closed-right](http://latex.codecogs.com/svg.latex?%280%2C%201%5D)
+
+
+
+- Including zero and one: ![interval-closed-left-closed-right](http://latex.codecogs.com/svg.latex?%5B0%2C%201%5D)
+
+
+
+For example we to indicate that a point `x` is in the unit cube in 3D we say:
+
+![interval-unit-cube](http://latex.codecogs.com/svg.latex?x%20%5Cin%20%5B0%2C%201%5D%5E3)
+
+
+
+In code we can represent an interval using a two element 1d array:
+
+```js
+var nextafter = require('nextafter')
+
+var a = [nextafter(0, Infinity), nextafter(1, -Infinity)] // open interval
+var b = [nextafter(0, Infinity), 1] // interval closed on the left
+var c = [0, nextafter(1, -Infinity)] // interval closed on the right
+var d = [0, 1] // closed interval
+```
+
+Intervals are used in conjunction with set operations:
+
+- *intersection* e.g. ![interval-intersection](http://latex.codecogs.com/svg.latex?%5B3%2C%205%29%20%5Ccap%20%5B4%2C%206%5D%20%3D%20%5B4%2C%205%29)
+
+
+
+- *union* e.g. ![interval-union](http://latex.codecogs.com/svg.latex?%5B3%2C%205%29%20%5Ccup%20%5B4%2C%206%5D%20%3D%20%5B3%2C%206%5D)
+
+
+
+- *difference* e.g. ![interval-difference-1](http://latex.codecogs.com/svg.latex?%5B3%2C%205%29%20-%20%5B4%2C%206%5D%20%3D%20%5B3%2C%204%29) and ![interval-difference-2](http://latex.codecogs.com/svg.latex?%5B4%2C%206%5D%20-%20%5B3%2C%205%29%20%3D%20%5B5%2C%206%5D)
+
+
+
+
+In code:
+
+```js
+var Interval = require('interval-arithmetic')
+var nexafter = require('nextafter')
+
+var a = Interval(3, nexafter(5, -Infinity))
+var b = Interval(4, 6)
+
+Interval.intersection(a, b)
+// {lo: 4, hi: 4.999999999999999}
+
+Interval.union(a, b)
+// {lo: 3, hi: 6}
+
+Interval.difference(a, b)
+// {lo: 3, hi: 3.9999999999999996}
+
+Interval.difference(b, a)
+// {lo: 5, hi: 6}
+```
+
+See:
+
+- [next-after](https://github.com/scijs/nextafter)
+- [interval-arithmetic](https://github.com/maurizzzio/interval-arithmetic)
+
+## more...
+
+Like this guide? Suggest some [more features](https://github.com/Jam3/math-as-code/issues/1) or send us a Pull Request!
+
+## Contributing
+
+For details on how to contribute, see [CONTRIBUTING.md](./CONTRIBUTING.md).
+
+## License
+
+MIT, see [LICENSE.md](http://github.com/Jam3/math-as-code/blob/master/LICENSE.md) for details.
+
+[1]: http://mimosa-pudica.net/improved-oren-nayar.html#images
+[2]: http://buzzard.ups.edu/courses/2007spring/projects/million-paper.pdf
+[3]: https://www.math.washington.edu/~morrow/464_12/fft.pdf
\ No newline at end of file