Navigation Menu

Skip to content

Commit

Permalink
escape latex
Browse files Browse the repository at this point in the history
Inlines require escaping with backticks

Displays require escaping with a div tag
  • Loading branch information
blaenk committed Oct 11, 2018
1 parent 47b223a commit 787aeda
Show file tree
Hide file tree
Showing 19 changed files with 2,033 additions and 1,091 deletions.
614 changes: 307 additions & 307 deletions content/notes/algorithms.md

Large diffs are not rendered by default.

96 changes: 49 additions & 47 deletions content/notes/computer-architecture.md

Large diffs are not rendered by default.

16 changes: 9 additions & 7 deletions content/notes/cpp.md
Expand Up @@ -624,15 +624,15 @@ uint8_t var = -1;

The value `-1` is encoded by first representing it as a positive number:

$$ 0000\ 0001 $$
<div>$$ 0000\ 0001 $$</div>

The digits are then flipped, so that 1s become 0s and vice versa:

$$ 1111\ 1110 $$
<div>$$ 1111\ 1110 $$</div>

Finally, the value is incremented by 1 to arrive at the Two's Complement representation of `-1`:

$$ 1111\ 1111 $$
<div>$$ 1111\ 1111 $$</div>

When this value is assigned to an unsigned integer, the value is simply interpreted as if it were unsigned to begin with. Therefore, this value is interpreted as being `255`.

Expand Down Expand Up @@ -660,24 +660,26 @@ The modulus operation `%` simply calculates the remainder of the left expression

The equation generally used to calculate the modulus is:

$$ \text{mod}(a, n) = a - \lfloor a / n \rfloor * n $$
<div>$$ \text{mod}(a, n) = a - \lfloor a / n \rfloor * n $$</div>

The operation `-1 % 256` yields the result `255` with this implementation. This is the result yielded in languages such as Python and Ruby.

C and C++ uses the same equation as the above, **but** the division operation has an additional restriction when used with negative operands:

$$ \text{div}(-a, n) = \text{div}(a, -n) = -(a/n) $$
<div>$$ \text{div}(-a, n) = \text{div}(a, -n) = -(a/n) $$</div>

With these definitions, the division of `-1 / 256` in the above equation becomes `-(1 / 256)`. The result of `1 / 256` is zero due to truncation. The negation of this result is still zero, so the result of the modulus operation is simply `-1`, which is **very different** from the result of `256` yielded above without these restrictions.

Given the above restriction on the division operation with negative operands, the definition of the modulus operation with negative operands can be simplified to:

<div>
$$
\begin{align}
\text{mod}(\phantom {-} a, -n) &= \phantom {-} \text{mod}(a, n) \\
\text{mod}(-a, \phantom {-} n) &= -\text{mod}(a, n)
\end{align}
$$
</div>

# Exceptions

Expand Down Expand Up @@ -3729,7 +3731,7 @@ std::pair<int, int> bounds = std::minmax(std::rand() % v.size(),
std::rand() % v.size());
```

The `nth_element` function selects the $n^\text {th}$ element from the sorted order of the range, i.e. the $n^\text {th}$-order statistic. A comparison function can be specified.
The `nth_element` function selects the `$n^\text {th}$` element from the sorted order of the range, i.e. the `$n^\text {th}$`-order statistic. A comparison function can be specified.

This is like Quicksort's partitioning, so the range is modified so that the element pointed to by `nth` becomes the `nth` element of the sorted order of the range. All elements to the left of the iterator are less than or equal to that element and all elements to the right of the iterator are greater than that element.

Expand Down Expand Up @@ -3838,7 +3840,7 @@ v = {1, 1, 1, 1};

The `partial_sum` function successively computes the sums of increasing sub-ranges of the input range and copies each sum into the output iterator. A custom sum function can be provided. Specifically, the result is such that:

$$ \text {dest}[i] = \sum_0^i \text {src}[i] $$
<div>$$ \text {dest}[i] = \sum_0^i \text {src}[i] $$</div>

This can be useful for example to compute the [maximal sub-array](https://en.wikipedia.org/wiki/Maximum_subarray_problem).

Expand Down
4 changes: 2 additions & 2 deletions content/notes/cryptography.md
Expand Up @@ -6,7 +6,7 @@ date = 2016-05-04
kind = "concept"
+++

Diffie-Hellman key exchange works by agreeing on two publicly shared values: a large prime number $q$ and a primitive root $g$. Alice and Bob each generate a _secret key_---a large random number---$x_a$ and $x_b$ respectively, and each raise the _primitive root_ to the power of the _secret key_, modulo the _large prime number_.
Diffie-Hellman key exchange works by agreeing on two publicly shared values: a large prime number `$q$` and a primitive root `$g$`. Alice and Bob each generate a _secret key_---a large random number---`$x_a$` and `$x_b$` respectively, and each raise the _primitive root_ to the power of the _secret key_, modulo the _large prime number_.

<div>
$$
Expand All @@ -28,7 +28,7 @@ k_{ab} &= y_a^{x_b} \bmod q
$$
</div>

Given a prime number $q$, a primitive root $g$ is a number such that every number from 1 up to $q - 1$ can be computed by raising the primitive root to some number $k$.
Given a prime number `$q$`, a primitive root `$g$` is a number such that every number from 1 up to `$q - 1$` can be computed by raising the primitive root to some number `$k$`.

<div>
$$
Expand Down
12 changes: 7 additions & 5 deletions content/notes/game-development.md
Expand Up @@ -156,12 +156,13 @@ I learned linear algebra and related 3D math using math and Direct3D texts which
### Handedness
The handedness of a system has an effect on the directions of the positive $z$-axis, positive rotation, and the cross-product. These can easily be determined by using the [right-hand rule](http://en.wikipedia.org/wiki/Right-hand_rule) or left-hand rule. It's important to realize that this has _nothing_ to do with row or column-major notation.
The handedness of a system has an effect on the directions of the positive `$z$`-axis, positive rotation, and the cross-product. These can easily be determined by using the [right-hand rule](http://en.wikipedia.org/wiki/Right-hand_rule) or left-hand rule. It's important to realize that this has _nothing_ to do with row or column-major notation.
### Representation
Row-major notation means that when indexing or denoting a matrix' size, the row is written first, and vice versa with column-major notation. Given a row-major matrix $R$, the column-major matrix $C$ is derived by deriving the transpose $R^{T}$:
Row-major notation means that when indexing or denoting a matrix' size, the row is written first, and vice versa with column-major notation. Given a row-major matrix `$R$`, the column-major matrix `$C$` is derived by deriving the transpose `$R^{T}$`:
<div>
$$
\begin{align}
R &=
Expand All @@ -179,6 +180,7 @@ C = R^T &=
\end{bmatrix}
\end{align}
$$
</div>
### Storage
Expand All @@ -189,11 +191,11 @@ When it comes to matrix storage in memory, the key is that they are both stored
When multiplying vectors with matrices, row-major notation requires pre-multiplication; the vector must appear to the left of the matrix. Column-major notation requires post-multiplication. This has the effect that the row-major, pre-multiplication transformation:
$$ vMVP $$
<div>$$ vMVP $$</div>
Must be expressed as follows in column-major notation:
$$ M^T V^T P^T v^T $$
<div>$$ M^T V^T P^T v^T $$</div>
However, row-major and column-major matrices are already transposes of each other, and as a result they are [stored](#storage) the same way in memory. This means that no actual transposing has to take place!
Expand All @@ -207,7 +209,7 @@ The most common optimization is to treat the world as a composition of _chunks_,
A chunk may be represented by a volumetric grid such as a 3D array, optimized into a flat slab of memory indexed with the formula:
$$ \text {chunk}[x + (y * \text {size}_x) + (z * \text {size}_x * \text {size}_y)] $$
<div>$$ \text {chunk}[x + (y * \text {size}_x) + (z * \text {size}_x * \text {size}_y)] $$</div>
The problem with this is that a lot of space is wasted for empty cells. A 16x16x16 chunk size where every cell conveys its information within one byte of data yields 4096 bytes, or 4 kilobytes. If every single cell in the chunk is empty except for one, then 4095 bytes are being wasted. That's 99.9% of the space allocated for the chunk.
Expand Down
4 changes: 2 additions & 2 deletions content/notes/haskell.md
Expand Up @@ -142,9 +142,9 @@ x <$ y = pure x <* y

# Parallelism

Amdahl's law places an upper bound on potential speedup that may be available by adding more processors. The expected speedup $S$ can be described as a function of the number of processors $N$ and the percentage of runtime that can be parallelized $P$. The implications are that the potential speedup increasingly becomes negligible with the increase in processors, but more importantly that most programs have a theoretical maximum amount of parallelism.
Amdahl's law places an upper bound on potential speedup that may be available by adding more processors. The expected speedup `$S$` can be described as a function of the number of processors `$N$` and the percentage of runtime that can be parallelized `$P$`. The implications are that the potential speedup increasingly becomes negligible with the increase in processors, but more importantly that most programs have a theoretical maximum amount of parallelism.

$$S(N) = \frac {1} {(1 - P) + \frac P N}$$
<div>$$S(N) = \frac {1} {(1 - P) + \frac P N}$$</div>

<img src="/images/notes/haskell/amdahls-law.png" class="center">

Expand Down
4 changes: 2 additions & 2 deletions content/notes/java.md
Expand Up @@ -1570,7 +1570,7 @@ The `LinkedList` class extends `AbstractSequentialList` and implements `List`, `

The `HashSet` class extends `AbstractSet` and implements `Set`, and provides hash table behavior. Two of the constructors accept a capacity argument (default 16), with one of them accepting a load capacity argument (default 0.75) known as _fill ratio_, which determines how full the hash set can be before it is grown, and as such it must be a value between 0.0 and 1.0. In other words, the hash set is grown when:

$$ \text{# of elements} \gt \text{capacity} \cdot \text{fill ratio} $$
<div>$$ \text{# of elements} \gt \text{capacity} \cdot \text{fill ratio} $$</div>

### LinkedHashSet

Expand Down Expand Up @@ -1875,7 +1875,7 @@ There are also specialized variants of the `Optional` class for primitives which

## Random

The `Random` class is a pseudorandom number generator. A variety of different kinds of numbers can be extracted from `Random` via different methods such as `nextBoolean`, `nextBytes`, `nextInt`, and so on. The `nextBytes` method in particular takes an array and fills it with the randomly generated values. The `nextInt` method has an overload that accepts an upper bound so that numbers are generated within the range $[0, n)$.
The `Random` class is a pseudorandom number generator. A variety of different kinds of numbers can be extracted from `Random` via different methods such as `nextBoolean`, `nextBytes`, `nextInt`, and so on. The `nextBytes` method in particular takes an array and fills it with the randomly generated values. The `nextInt` method has an overload that accepts an upper bound so that numbers are generated within the range `$[0, n)$`.

The seed can be passed to one of the constructor overloads or reset after the fact with the `setSeed` method.

Expand Down

0 comments on commit 787aeda

Please sign in to comment.