Skip to content

Instantly share code, notes, and snippets.

@cloud-on-prem
Forked from lancejpollard/index.md
Created June 16, 2012 12:18

Revisions

  1. @lancejpollard lancejpollard revised this gist May 1, 2012. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion index.md
    Original file line number Diff line number Diff line change
    @@ -208,7 +208,9 @@ Cardinality. The number of items in the set.

    ### `A×B`

    Cross product.
    Cross product. The cross product is a binary operation on two vectors in a three-dimensional Euclidean space that results in another vector which is perpendicular to the plane containing the two input vectors.

    http://stackoverflow.com/questions/243945/calculating-a-2d-vectors-cross-product

    ``` coffeescript
    # A = {1, 2}
  2. @lancejpollard lancejpollard revised this gist Mar 17, 2012. 1 changed file with 12 additions and 0 deletions.
    12 changes: 12 additions & 0 deletions index.md
    Original file line number Diff line number Diff line change
    @@ -274,6 +274,18 @@ f(g(x)) #=> 26

    ### `∃! x: P(x)`

    ### `P(A|B)`

    The probability of the event A occurring given that B occurs.

    ### `A ⊥ B`

    A is an event whose probability is independent of event B.

    ### `A ∝ B`

    The problem A can be polynomially reduced to the problem B.

    ### `W⊥`

    `W⊥` means the orthogonal complement of W (where W is a subspace of the inner product space V), the set of all vectors in V orthogonal to every vector in W.
  3. @lancejpollard lancejpollard revised this gist Mar 17, 2012. 1 changed file with 18 additions and 0 deletions.
    18 changes: 18 additions & 0 deletions index.md
    Original file line number Diff line number Diff line change
    @@ -381,6 +381,24 @@ transposeMatrix([[1, 2, 3], [4, 5, 6]])
    #=> [[1, 4], [2, 5], [3, 6]]
    ```

    ### Binomial Coefficient

    ``` coffeescript
    binomial = (n, k) ->
    coeff = 1
    i = n - k

    coeff *= i while i++ < n

    i = 1

    coeff /= i while i++ < k

    coeff

    alert binomial(5, 2)
    ```

    ## Library?

    It'd be cool if there was a library that could parse TeX-like [jqmath](http://mathscribe.com/author/jqmath.html) format into code:
  4. @lancejpollard lancejpollard revised this gist Mar 17, 2012. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions index.md
    Original file line number Diff line number Diff line change
    @@ -133,6 +133,10 @@ A = [1, 2, 3]
    B = [1, 4, 5, 6]
    ```

    ### `ℝ2`

    The two-dimensional [vector space](http://en.wikipedia.org/wiki/Vector_space) of real numbers in mathematics.

    ### ``, `N`

    Natural numbers. Integers that can physically exist, i.e. only positive integers. Has different meanings. Means either `{ 0, 1, 2, 3, …}` or `{ 1, 2, 3, …}`.
  5. @lancejpollard lancejpollard revised this gist Mar 17, 2012. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions index.md
    Original file line number Diff line number Diff line change
    @@ -270,6 +270,12 @@ f(g(x)) #=> 26

    ### `∃! x: P(x)`

    ### `W⊥`

    `W⊥` means the orthogonal complement of W (where W is a subspace of the inner product space V), the set of all vectors in V orthogonal to every vector in W.

    <img src='http://upload.wikimedia.org/wikipedia/en/math/a/0/e/a0eb2e83f679f2dbb70e61a9182eb57a.png' />

    ### `||x||`

    Norm of the element x. The length of the array. Always positive.
  6. @lancejpollard lancejpollard revised this gist Mar 16, 2012. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion index.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    ## Sets == Arrays
    ## Sets =~ Arrays

    A set is basically an array of unique items.

    ### `(A,B)`

  7. @lancejpollard lancejpollard revised this gist Mar 16, 2012. 1 changed file with 58 additions and 0 deletions.
    58 changes: 58 additions & 0 deletions index.md
    Original file line number Diff line number Diff line change
    @@ -311,6 +311,64 @@ exampleSum = (n) ->
    exampleSum(10) #=> 605
    ```

    ### Matrix Addition

    The sum `A+B` of two m-by-n matrices `A` and `B` is calculated with:

    `(A + B)i,j = Ai,j + Bi,j`, where `1 ≤ i ≤ m` and `1 ≤ j ≤ n`.

    ``` coffeescript
    addMatrices = (a, b) ->
    result = []

    for rowA, rowI in a
    rowB = b[rowI]
    rowResult = []

    for columnA, columnI in rowA
    columnB = rowB[columnI]
    columnResult = columnA + columnB
    rowResult.push(columnResult)

    result.push(rowResult)

    result

    addMatrices([[1, 2], [3, 4]], [[5, 6], [7, 8]])
    #=> [[1 + 5, 2 + 6], [3 + 7, 4 + 8]]
    #=> [[6, 8], [10, 12]]
    ```

    ### Matrix Transposition

    The transpose of an m-by-n matrix A is the n-by-m matrix `AT` formed by turning rows into columns and vice versa:

    `(AT)i,j = Aj,i`

    ``` coffeescript
    transposeMatrix = (matrix) ->
    result = []
    columnCount = matrix[0].length
    rowCount = matrix.length

    # construct new arrays
    i = 0
    while i < columnCount
    column = []

    result[i] = column
    i += 1

    for row, i in matrix
    for column, j in row
    result[j][i] = column

    result

    transposeMatrix([[1, 2, 3], [4, 5, 6]])
    #=> [[1, 4], [2, 5], [3, 6]]
    ```

    ## Library?

    It'd be cool if there was a library that could parse TeX-like [jqmath](http://mathscribe.com/author/jqmath.html) format into code:
  8. @lancejpollard lancejpollard revised this gist Mar 16, 2012. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions index.md
    Original file line number Diff line number Diff line change
    @@ -291,6 +291,10 @@ innerProduct = (u, v) ->
    innerProduct([2, 3], [-1, 5]) #=> 13
    ```

    ### `det(A)`, `|A|`

    Determinant of a matrix.

    ## Examples

    ### `$$∑↙{i=0}↖n i={n(n+1)}/2$$`
  9. @lancejpollard lancejpollard revised this gist Mar 16, 2012. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions index.md
    Original file line number Diff line number Diff line change
    @@ -212,6 +212,7 @@ Cross product.
    # [[1, x], [1, y], [1, z], [2, x], [2, y], [2, z]]
    A = [1, 2]
    B = [x, y, z]
    # crossProduct function???
    ```

    ### `A·B`
  10. @lancejpollard lancejpollard revised this gist Mar 16, 2012. 1 changed file with 23 additions and 0 deletions.
    23 changes: 23 additions & 0 deletions index.md
    Original file line number Diff line number Diff line change
    @@ -267,6 +267,29 @@ f(g(x)) #=> 26

    ### `∃! x: P(x)`

    ### `||x||`

    Norm of the element x. The length of the array. Always positive.

    ``` coffeescript
    [1, 2, 3].length #=> 3
    ```

    ### `⟨u,v⟩`

    The inner product of u and v, where u and v are members of an inner product space.

    ``` coffeescript
    # x = (2, 3)
    # y = (−1, 5)
    # ⟨x, y⟩ = 2 × −1 + 3 × 5 = 13

    innerProduct = (u, v) ->
    crossProduct(u) + crossProduct(v)

    innerProduct([2, 3], [-1, 5]) #=> 13
    ```

    ## Examples

    ### `$$∑↙{i=0}↖n i={n(n+1)}/2$$`
  11. @lancejpollard lancejpollard revised this gist Mar 16, 2012. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions index.md
    Original file line number Diff line number Diff line change
    @@ -216,15 +216,15 @@ B = [x, y, z]

    ### `A·B`

    Cross product.
    Dot product.

    <img src='http://upload.wikimedia.org/wikipedia/en/math/2/1/4/21467e485cbafd1a308e388211257ad6.png' />

    ``` coffeescript
    # one dimensional vector
    A = [1, 2, 3]
    B = [4, 5, 6]
    crossProduct = (a, b) =>
    dotProduct = (a, b) =>
    n = a.length # or b.length
    i = 0
    result = 0
  12. @lancejpollard lancejpollard revised this gist Mar 16, 2012. 1 changed file with 22 additions and 0 deletions.
    22 changes: 22 additions & 0 deletions index.md
    Original file line number Diff line number Diff line change
    @@ -214,6 +214,28 @@ A = [1, 2]
    B = [x, y, z]
    ```

    ### `A·B`

    Cross product.

    <img src='http://upload.wikimedia.org/wikipedia/en/math/2/1/4/21467e485cbafd1a308e388211257ad6.png' />

    ``` coffeescript
    # one dimensional vector
    A = [1, 2, 3]
    B = [4, 5, 6]
    crossProduct = (a, b) =>
    n = a.length # or b.length
    i = 0
    result = 0

    while i < n
    result += (a[i] * b[i])
    i += 1

    result
    ```

    ### `f: X → Y`

    Function f maps the set X into the set Y. Or, there is a function f such that X is converted to Y.
  13. @lancejpollard lancejpollard revised this gist Mar 16, 2012. 1 changed file with 11 additions and 0 deletions.
    11 changes: 11 additions & 0 deletions index.md
    Original file line number Diff line number Diff line change
    @@ -16,6 +16,17 @@ Unordered set.
    {"a": 1, "b": 2} == {"b": 2, "a": 1}
    ```

    ### `A ∆ B`

    Symmetric difference. The set of elements in exactly one of A or B. The unique items when you combine A and B.

    ``` coffeescript
    # {1,5,6,8} ∆ {2,5,8} = {1,2,6}
    A = [1, 5, 6, 8]
    B = [2, 5, 8]
    # A ∆ B = [1, 2, 6]
    ```

    ### `A ⊇ B`

    A is a superset of B. The A array has all items the B array has.
  14. @lancejpollard lancejpollard revised this gist Mar 16, 2012. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions index.md
    Original file line number Diff line number Diff line change
    @@ -228,6 +228,12 @@ x = 10
    f(g(x)) #=> 26
    ```

    ### `∀ x: P(x)`

    ### `∃ x: P(x)`

    ### `∃! x: P(x)`

    ## Examples

    ### `$$∑↙{i=0}↖n i={n(n+1)}/2$$`
  15. @lancejpollard lancejpollard revised this gist Mar 16, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion index.md
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@
    Ordered set.

    ``` coffeescript
    [1, 2] != [1, 2]
    [1, 2] != [2, 1]
    ```

    ### `{A,B}`
  16. @lancejpollard lancejpollard revised this gist Mar 16, 2012. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions index.md
    Original file line number Diff line number Diff line change
    @@ -194,6 +194,8 @@ Cardinality. The number of items in the set.
    Cross product.

    ``` coffeescript
    # A = {1, 2}
    # B = {x, y, z}
    # A×B = {(a, b) : a A, b B}
    # A×B = {(1, x), (1, y), (1, z), (2, x), (2, y), (2, z)}
    # [[1, x], [1, y], [1, z], [2, x], [2, y], [2, z]]
  17. @lancejpollard lancejpollard revised this gist Mar 16, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion index.md
    Original file line number Diff line number Diff line change
    @@ -203,7 +203,7 @@ B = [x, y, z]

    ### `f: X → Y`

    Function f maps the set X into the set Y.
    Function f maps the set X into the set Y. Or, there is a function f such that X is converted to Y.

    ``` coffeescript
    X = [1, 2, 3]
  18. @lancejpollard lancejpollard revised this gist Mar 16, 2012. 1 changed file with 15 additions and 1 deletion.
    16 changes: 15 additions & 1 deletion index.md
    Original file line number Diff line number Diff line change
    @@ -201,7 +201,7 @@ A = [1, 2]
    B = [x, y, z]
    ```

    ## `f: X → Y`
    ### `f: X → Y`

    Function f maps the set X into the set Y.

    @@ -212,6 +212,20 @@ f = array.reverse
    f(X) == Y
    ```

    ### `(f∘g)(x)`

    Function composition.

    ``` coffeescript
    # f(x) := 2x
    # g(x) := x + 3
    # (f∘g)(x) = 2(x + 3)
    f = (x) -> 2 * x
    g = (x) -> x + 3
    x = 10
    f(g(x)) #=> 26
    ```

    ## Examples

    ### `$$∑↙{i=0}↖n i={n(n+1)}/2$$`
  19. @lancejpollard lancejpollard revised this gist Mar 16, 2012. 1 changed file with 11 additions and 0 deletions.
    11 changes: 11 additions & 0 deletions index.md
    Original file line number Diff line number Diff line change
    @@ -201,6 +201,17 @@ A = [1, 2]
    B = [x, y, z]
    ```

    ## `f: X → Y`

    Function f maps the set X into the set Y.

    ``` coffeescript
    X = [1, 2, 3]
    Y = [3, 2, 1]
    f = array.reverse
    f(X) == Y
    ```

    ## Examples

    ### `$$∑↙{i=0}↖n i={n(n+1)}/2$$`
  20. @lancejpollard lancejpollard revised this gist Mar 16, 2012. 1 changed file with 12 additions and 0 deletions.
    12 changes: 12 additions & 0 deletions index.md
    Original file line number Diff line number Diff line change
    @@ -189,6 +189,18 @@ Cardinality. The number of items in the set.
    [3, 5, 7, 9].length
    ```

    ### `A×B`

    Cross product.

    ``` coffeescript
    # A×B = {(a, b) : a A, b B}
    # A×B = {(1, x), (1, y), (1, z), (2, x), (2, y), (2, z)}
    # [[1, x], [1, y], [1, z], [2, x], [2, y], [2, z]]
    A = [1, 2]
    B = [x, y, z]
    ```

    ## Examples

    ### `$$∑↙{i=0}↖n i={n(n+1)}/2$$`
  21. @lancejpollard lancejpollard revised this gist Mar 15, 2012. 1 changed file with 18 additions and 1 deletion.
    19 changes: 18 additions & 1 deletion index.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,21 @@
    ## Sets == Arrays

    ### `(A,B)`

    Ordered set.

    ``` coffeescript
    [1, 2] != [1, 2]
    ```

    ### `{A,B}`

    Unordered set.

    ``` coffeescript
    {"a": 1, "b": 2} == {"b": 2, "a": 1}
    ```

    ### `A ⊇ B`

    A is a superset of B. The A array has all items the B array has.
    @@ -276,4 +292,5 @@ P = subsetGreaterThanZero([-1, 0, 1, 2]) #=> [1, 2]
    - http://en.wikipedia.org/wiki/List_of_mathematical_symbols
    - http://www.esi2.us.es/~mbilbao/pdffiles/DiestelGT.pdf
    - http://mathscribe.com/author/jqmath.html
    - http://en.wikipedia.org/wiki/Help:Displaying_a_formula
    - http://en.wikipedia.org/wiki/Help:Displaying_a_formula
    - http://plato.stanford.edu/entries/set-theory/primer.html
  22. @lancejpollard lancejpollard revised this gist Mar 15, 2012. 1 changed file with 13 additions and 0 deletions.
    13 changes: 13 additions & 0 deletions index.md
    Original file line number Diff line number Diff line change
    @@ -258,6 +258,19 @@ graph =
    averageDegree(graph) #=> 4
    ```

    ### `P = {G | X(G) > 0}`

    ``` coffeescript
    x = (set) ->
    # magic!
    set.length

    subsetGreaterThanZero = (G) ->
    x(G) > 0

    P = subsetGreaterThanZero([-1, 0, 1, 2]) #=> [1, 2]
    ```

    ## Resources

    - http://en.wikipedia.org/wiki/List_of_mathematical_symbols
  23. @lancejpollard lancejpollard revised this gist Mar 15, 2012. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion index.md
    Original file line number Diff line number Diff line change
    @@ -262,4 +262,5 @@ averageDegree(graph) #=> 4

    - http://en.wikipedia.org/wiki/List_of_mathematical_symbols
    - http://www.esi2.us.es/~mbilbao/pdffiles/DiestelGT.pdf
    - http://mathscribe.com/author/jqmath.html
    - http://mathscribe.com/author/jqmath.html
    - http://en.wikipedia.org/wiki/Help:Displaying_a_formula
  24. @lancejpollard lancejpollard revised this gist Mar 15, 2012. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions index.md
    Original file line number Diff line number Diff line change
    @@ -229,6 +229,10 @@ So, for each item in the array, execute the function: `d(v)`. Simple as that, t

    All together. The degree of a graph is [arbitrarily] defined by this: for each vertex in the graph, count the number of edges, and divide by the number of vertices. That is, it's the average number of edges per vertex! Are you kidding me! All that just for a simple average?

    Here's the equation again:

    <img src='http://i.imgur.com/Wq3BO.png'/>

    In code, that looks like this:

    ``` coffeescript
  25. @lancejpollard lancejpollard revised this gist Mar 15, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion index.md
    Original file line number Diff line number Diff line change
    @@ -219,7 +219,7 @@ alert math("[1, 2, 3] ∪ [1, 2, 3, 4, 5]")

    What is this saying (from the [Graph Theory](http://www.esi2.us.es/~mbilbao/pdffiles/DiestelGT.pdf) book)??

    Well, `:=` means "I want to call the thing on the right the thing on the left". So call that `` equation `d(g)`. It's arbitrary. He's saying `d(v)` is going to be called the "degree" of a vertex, which he's defining as "the number of edges on that vertex". Then he's saying `d(G)` is going to be called the "degree" of the whole graph.
    Well, `:=` means "I want to call the thing on the right the thing on the left". So call that `` equation `d(g)`. It's arbitrary. He's saying `d(v)` is going to be called the "degree" of a vertex, which he's defining as "the number of edges on that vertex". Then he's saying `d(G)` is going to be called the "degree" of the whole graph. He's basically just naming his functions and variables!

    Then `1/|V|`. He defines `V` to be the number of vertices in a graph. So, number of items in an array, or `array.length`, so `1/vertices.length`.

  26. @lancejpollard lancejpollard revised this gist Mar 15, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion index.md
    Original file line number Diff line number Diff line change
    @@ -219,7 +219,7 @@ alert math("[1, 2, 3] ∪ [1, 2, 3, 4, 5]")

    What is this saying (from the [Graph Theory](http://www.esi2.us.es/~mbilbao/pdffiles/DiestelGT.pdf) book)??

    Well, `:=` means "I want to call the thing on the right the thing on the left". So call that `` equation `d(g)`. It's arbitrary. He's saying `d(v)` is going to be called the "degree" of a vertex, which he means "the number of edges on that vertex". Then he's saying `d(G)` is going to be called the "degree" of the whole graph.
    Well, `:=` means "I want to call the thing on the right the thing on the left". So call that `` equation `d(g)`. It's arbitrary. He's saying `d(v)` is going to be called the "degree" of a vertex, which he's defining as "the number of edges on that vertex". Then he's saying `d(G)` is going to be called the "degree" of the whole graph.

    Then `1/|V|`. He defines `V` to be the number of vertices in a graph. So, number of items in an array, or `array.length`, so `1/vertices.length`.

  27. @lancejpollard lancejpollard revised this gist Mar 15, 2012. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion index.md
    Original file line number Diff line number Diff line change
    @@ -213,7 +213,9 @@ math = (string) ->
    alert math("[1, 2, 3] ∪ [1, 2, 3, 4, 5]")
    ```

    <h3>Average Degree of a Graph: <a name='graph-theory-equation' href='#graph-theory-equation'><img src='http://i.imgur.com/Wq3BO.png'/></a></h3>
    <h3><a name='graph-theory-equation' href='#graph-theory-equation'>#</a>Average Degree of a Graph</h3>

    <img src='http://i.imgur.com/Wq3BO.png'/>

    What is this saying (from the [Graph Theory](http://www.esi2.us.es/~mbilbao/pdffiles/DiestelGT.pdf) book)??

  28. @lancejpollard lancejpollard revised this gist Mar 15, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion index.md
    Original file line number Diff line number Diff line change
    @@ -213,7 +213,7 @@ math = (string) ->
    alert math("[1, 2, 3] ∪ [1, 2, 3, 4, 5]")
    ```

    <h3><a name='graph-theory-equation' href='#graph-theory-equation'><img src='http://i.imgur.com/Wq3BO.png'/></a></h3>
    <h3>Average Degree of a Graph: <a name='graph-theory-equation' href='#graph-theory-equation'><img src='http://i.imgur.com/Wq3BO.png'/></a></h3>

    What is this saying (from the [Graph Theory](http://www.esi2.us.es/~mbilbao/pdffiles/DiestelGT.pdf) book)??

  29. @lancejpollard lancejpollard revised this gist Mar 15, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion index.md
    Original file line number Diff line number Diff line change
    @@ -213,7 +213,7 @@ math = (string) ->
    alert math("[1, 2, 3] ∪ [1, 2, 3, 4, 5]")
    ```

    <h3><a name='graph-theory-equation' href='name='#graph-theory-equation'><img src='http://i.imgur.com/Wq3BO.png'/></a></h3>
    <h3><a name='graph-theory-equation' href='#graph-theory-equation'><img src='http://i.imgur.com/Wq3BO.png'/></a></h3>

    What is this saying (from the [Graph Theory](http://www.esi2.us.es/~mbilbao/pdffiles/DiestelGT.pdf) book)??

  30. @lancejpollard lancejpollard revised this gist Mar 15, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion index.md
    Original file line number Diff line number Diff line change
    @@ -213,7 +213,7 @@ math = (string) ->
    alert math("[1, 2, 3] ∪ [1, 2, 3, 4, 5]")
    ```

    <h3 id='graph-theory-equation'><img src='http://i.imgur.com/Wq3BO.png'/></h3>
    <h3><a name='graph-theory-equation' href='name='#graph-theory-equation'><img src='http://i.imgur.com/Wq3BO.png'/></a></h3>

    What is this saying (from the [Graph Theory](http://www.esi2.us.es/~mbilbao/pdffiles/DiestelGT.pdf) book)??