You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Clean up whitespace related issues in entire project (#126)
* Removed trailing whitespace everywhere
* Cleaned up C# source files
Removed trailing whitespace, changed line endings from CRLF to LF and
removed the UTF-8 BOM
* Added a .gitattributes file
C# source files are now forced to have LF line endings
* EditorConfig rule to cover all text files
* Added more file types to .gitattributes
* Cleaned up OCAML source files
And also added them to .gitattributes and .editorconfig
* Added end_of_line = lf to .editorconfig
* Made .gitattributes way simpler
Copy file name to clipboardExpand all lines: README.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
# The Arcane Algorithm Archive
2
-
The Arcane Algorithm Archive is a collaborative effort to create a guide for all important algorithms in all languages.
2
+
The Arcane Algorithm Archive is a collaborative effort to create a guide for all important algorithms in all languages.
3
3
This goal is obviously too ambitious for a book of any size, but it is a great project to learn from and work on and will hopefully become an incredible resource for programmers in the future.
4
4
The book can be found here: https://www.algorithm-archive.org/.
5
5
The github repository can be found here: https://github.com/algorithm-archivists/algorithm-archive.
@@ -8,7 +8,7 @@ and livecoded on Twitch: https://www.twitch.tv/simuleios.
8
8
If you would like to communicate more directly, please feel free to go to our discord: https://discord.gg/Pr2E9S6.
9
9
10
10
11
-
Note that the this project is is essentially a book about algorithms collaboratively written by an online community.
11
+
Note that the this project is is essentially a book about algorithms collaboratively written by an online community.
12
12
Fortunately, there are a lot of algorithms out there, which means that there is a lot of content material available.
13
13
Unfortunately, this means that we will probably never cover every algorithm ever created and instead need to focus on what the community sees as useful and necessary.
14
14
That said, we'll still cover a few algorithms for fun that have very little, if any practical purpose.
Copy file name to clipboardExpand all lines: TODO.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -23,7 +23,7 @@ I'll try to keep this list updated as I write more sections
23
23
Here are points of discussion that need to be had about the Algorithm Archive before it gets too big and becomes too difficult to revise everything
24
24
25
25
***Should community-submitted code be clean or efficeint?** When it comes to writing code, I often feel readability is the most important factor to keep in mind; however, with the code submitted to this archive, there will be psudocode available to guide new folks through the process of writing the algorithm for the first time. For this reason, it might be best for the community to submit the most efficient code they can write in their own languages, commenting in any tricks to improve performance.
26
-
***Is the current method of writing optimal?** When I originally envisioned this project, I thought that I would do all the writing and the community would do (most of) the coding. That said, I am becoming more open to the idea of letting community members write for the Archive. The advantage to this is obvious: The book gets written faster. The disadvantage is also obvious: We lose focus and consistency throughout the book.
27
-
***We need a Logo.** I have no idea how to go about this. Maybe a logo contest at 16384 subscribers on youtube? The project will be large enough at that point to warrant a good logo. I really want something simple, though, like a [Trefoil Knot](https://en.wikipedia.org/wiki/Trefoil_knot#/media/File:Trefoil_knot_left.svg) or something. It kinda looks like 3 A's if you look at it the right way, and we'll definitely cover knot algorithms at some point because they are fascinating!
26
+
***Is the current method of writing optimal?** When I originally envisioned this project, I thought that I would do all the writing and the community would do (most of) the coding. That said, I am becoming more open to the idea of letting community members write for the Archive. The advantage to this is obvious: The book gets written faster. The disadvantage is also obvious: We lose focus and consistency throughout the book.
27
+
***We need a Logo.** I have no idea how to go about this. Maybe a logo contest at 16384 subscribers on youtube? The project will be large enough at that point to warrant a good logo. I really want something simple, though, like a [Trefoil Knot](https://en.wikipedia.org/wiki/Trefoil_knot#/media/File:Trefoil_knot_left.svg) or something. It kinda looks like 3 A's if you look at it the right way, and we'll definitely cover knot algorithms at some point because they are fascinating!
28
28
29
29
Anyway, let me know what you think. I love the community we have here and appreciate all the conversations we've had so far!
Copy file name to clipboardExpand all lines: chapters/FFT/cooley_tukey.md
+35-35
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,15 @@
1
1
## What Makes a Fourier Transform Fast?
2
2
3
-
If there were ever an algorithm to radically change the landscape of computer science and engineering by making seemingly impossible problems possible, it would be the Fast Fourier Transform (FFT).
3
+
If there were ever an algorithm to radically change the landscape of computer science and engineering by making seemingly impossible problems possible, it would be the Fast Fourier Transform (FFT).
4
4
On the surface, the algorithm seems like a simple application of recursion, and in principle, that is exactly what it is; however, the Fourier Transform is no ordinary transform -- it allows researchers and engineers to easily bounce back and forth between real space and frequency space and is the heart of many physics and engineering applications.
5
-
From calculating superfluid vortex positions to super-resolution imaging, Fourier Transforms lay at the heart of many scientific disciplines and are essential to many algorithms we will cover later in this book.
5
+
From calculating superfluid vortex positions to super-resolution imaging, Fourier Transforms lay at the heart of many scientific disciplines and are essential to many algorithms we will cover later in this book.
6
6
7
-
Simply put, the Fourier Transform is a beautiful application of complex number systems; however, it would rarely be used today if not for the ability to quickly perform the operation with Fast Fourier Transform, first introduced by the great Frederick Gauss in 1805 and later independently discovered by James Cooley and John Tukey in 1965 {{ "ct1965" | cite }}.
7
+
Simply put, the Fourier Transform is a beautiful application of complex number systems; however, it would rarely be used today if not for the ability to quickly perform the operation with Fast Fourier Transform, first introduced by the great Frederick Gauss in 1805 and later independently discovered by James Cooley and John Tukey in 1965 {{ "ct1965" | cite }}.
8
8
Gauss (of course) already had too many things named after him and Cooley and Tukey both had cooler names, so the most common algorithm for FFT's today is known as the Cooley-Tukey algorithm.
9
9
10
10
### What is a Fourier Transform?
11
11
12
-
To an outsider, the Fourier Transform looks like a mathematical mess -- certainly a far cry from the heroic portal between two domains I have depicted it to be; however, like most things, it's not as bad as it initially appears to be.
12
+
To an outsider, the Fourier Transform looks like a mathematical mess -- certainly a far cry from the heroic portal between two domains I have depicted it to be; however, like most things, it's not as bad as it initially appears to be.
13
13
So, here it is in all it's glory!
14
14
15
15
$$F(\xi) = \int_{-\infty} ^\infty f(x) e^{-2 \pi i x \xi} dx$$
Where $$F(\xi)$$ represents a function in frequency space, $$\xi$$ represents a value in frequency space, $$f(x)$$ represents a function in real space, and $$x$$ represents a value in the real space.
22
-
Note here that the only difference between the two exponential terms is a minus sign in the transformation to frequency space.
21
+
Where $$F(\xi)$$ represents a function in frequency space, $$\xi$$ represents a value in frequency space, $$f(x)$$ represents a function in real space, and $$x$$ represents a value in the real space.
22
+
Note here that the only difference between the two exponential terms is a minus sign in the transformation to frequency space.
23
23
As I mentioned, this is not intuitive syntax, so please allow me to explain a bit.
24
24
25
25
Firstly, **what does the Fourier Transform do?**
26
26
27
27
If we take a sum sinusoidal functions (like $$\sin(\omega t)$$ or $$\cos(\omega t)$$), we might find a complicated mess of waves between $$\pm 1$$.
28
28
Each constituent wave can be described by only one value: $$\omega$$.
29
-
So, instead of representing these curves as seen above, we could instead describe them as peaks in frequency space, as shown below.
29
+
So, instead of representing these curves as seen above, we could instead describe them as peaks in frequency space, as shown below.
After performing the transform, it is now much, much easier to understand precisely which frequencies are in our waveform, which is essential to most areas of signal processing.
37
37
38
-
Now, how does this relate to the transformations above?
38
+
Now, how does this relate to the transformations above?
39
39
Well, the easiest way is to substitute in the Euler's formula:
40
40
41
41
$$e^{2 \pi i \theta} = \cos(2 \pi \theta) + i \sin(2 \pi \theta)$$
@@ -48,10 +48,10 @@ and our function in real space into:
48
48
49
49
$$f(x) = \int_{-\infty} ^\infty F(\xi) (\cos(2 \pi \xi x) + i \sin(2 \pi \xi x))e^{2 \pi i \xi x} d\xi$$
50
50
51
-
Here, the $$\sin$$ and $$\cos$$ functions are clearly written in the formulas, so it looks much friendlier, right?
52
-
This means that a point in real space is defined by the integral over all space of it's corresponding frequency function multiplied by sinusoidal oscillations.
51
+
Here, the $$\sin$$ and $$\cos$$ functions are clearly written in the formulas, so it looks much friendlier, right?
52
+
This means that a point in real space is defined by the integral over all space of it's corresponding frequency function multiplied by sinusoidal oscillations.
53
53
54
-
Truth be told, even after seeing this math, I still didn't understand Fourier Transforms.
54
+
Truth be told, even after seeing this math, I still didn't understand Fourier Transforms.
55
55
Truth be told, I didn't understand it fully until I discretized real and frequency space to create the Discrete Fourier Transform (DFT), which is the only way to implement Fourier Transforms in code.
56
56
57
57
### What is a Discrete Fourier Transform?
@@ -60,12 +60,12 @@ In principle, the Discrete Fourier Transform (DFT) is simply the Fourier transfo
60
60
61
61
$$X_k = \sum_{n=0}^{N-1} x_n \cdot e^{-2 \pi k n / N}$$
62
62
63
-
and
63
+
and
64
64
65
65
$$x_n = \frac{1}{N} \sum_{k=0}^{N-1} X_k \cdot e^{2 \pi k n / N}$$
66
66
67
-
Where $$X_n$$ and $$x_n$$ are sequences of $$N$$ numbers in frequency and real space, respectively.
68
-
In principle, this is no easier to understand than the previous case!
67
+
Where $$X_n$$ and $$x_n$$ are sequences of $$N$$ numbers in frequency and real space, respectively.
68
+
In principle, this is no easier to understand than the previous case!
69
69
For some reason, though, putting code to this transformation really helped me figure out what was actually going on.
70
70
71
71
{% method %}
@@ -83,21 +83,21 @@ For some reason, though, putting code to this transformation really helped me fi
83
83
[import:2-11, lang:"julia"](code/julia/fft.jl)
84
84
{% endmethod %}
85
85
86
-
In this function, we define `n` to be a set of integers from $$0 \rightarrow N-1$$ and arrange them to be a column.
87
-
We then set `k` to be the same thing, but in a row.
88
-
This means that when we multiply them together, we get a matrix, but not just any matrix!
86
+
In this function, we define `n` to be a set of integers from $$0 \rightarrow N-1$$ and arrange them to be a column.
87
+
We then set `k` to be the same thing, but in a row.
88
+
This means that when we multiply them together, we get a matrix, but not just any matrix!
89
89
This matrix is the heart to the transformation itself!
It was amazing to me when I saw the transform for what it truly was: an actual transformation matrix!
99
-
That said, the Discrete Fourier Transform is slow -- primarily because matrix multiplication is slow, and as mentioned before, slow code is not particularly useful.
100
-
So what was the trick that everyone used to go from a Discrete fourier Transform to a *Fast* Fourier Transform?
98
+
It was amazing to me when I saw the transform for what it truly was: an actual transformation matrix!
99
+
That said, the Discrete Fourier Transform is slow -- primarily because matrix multiplication is slow, and as mentioned before, slow code is not particularly useful.
100
+
So what was the trick that everyone used to go from a Discrete fourier Transform to a *Fast* Fourier Transform?
101
101
102
102
Recursion!
103
103
@@ -106,11 +106,11 @@ Recursion!
106
106
The problem with using a standard DFT is that it requires a large matrix multiplications and sums over all elements, which are prohibitively complex operations.
107
107
The Cooley-Tukey algorithm calculates the DFT directly with fewer summations and without matrix multiplications.
108
108
If necessary, DFT's can still be calculated directly at the early stages of the FFT calculation.
109
-
The trick to the Cooley-Tukey algorithm is recursion.
110
-
In particular, we split the matrix we wish to perform the FFT on into two parts: one for all elements with even indices and another for all odd indices.
111
-
We then proceed to split the array again and again until we have a manageable array size to perform a DFT (or similar FFT) on.
109
+
The trick to the Cooley-Tukey algorithm is recursion.
110
+
In particular, we split the matrix we wish to perform the FFT on into two parts: one for all elements with even indices and another for all odd indices.
111
+
We then proceed to split the array again and again until we have a manageable array size to perform a DFT (or similar FFT) on.
112
112
We can also perform a similar re-ordering by using a bit reversal scheme, where we output each array index's integer value in binary and flip it to find the new location of that element.
113
-
With recursion, we can reduce the complexity to $$\sim \mathcal{O}(n \log n)$$, which is a feasible operation.
113
+
With recursion, we can reduce the complexity to $$\sim \mathcal{O}(n \log n)$$, which is a feasible operation.
114
114
115
115
In the end, the code looks like:
116
116
{% method %}
@@ -128,14 +128,14 @@ In the end, the code looks like:
128
128
[import:14-31, lang:"julia"](code/julia/fft.jl)
129
129
{% endmethod %}
130
130
131
-
As a side note, we are enforcing that the array must be a power of 2 for the operation to work.
131
+
As a side note, we are enforcing that the array must be a power of 2 for the operation to work.
132
132
This is a limitation of the fact that we are using recursion and dividing the array in 2 every time; however, if your array is not a power of 2, you can simply pad the leftover space with 0's until your array is a power of 2.
133
133
134
134
The above method is a perfectly valid FFT; however, it is missing the pictorial heart and soul of the Cooley-Tukey algorithm: Butterfly Diagrams.
135
135
136
136
### Butterfly Diagrams
137
-
Butterfly Diagrams show where each element in the array goes before, during, and after the FFT.
138
-
As mentioned, the FFT must perform a DFT.
137
+
Butterfly Diagrams show where each element in the array goes before, during, and after the FFT.
138
+
As mentioned, the FFT must perform a DFT.
139
139
This means that even though we need to be careful about how we add elements together, we are still ultimately performing the following operation:
140
140
141
141
$$X_k = \sum_{n=0}^{N-1} x_n \cdot e^{-2 \pi k n / N}$$
@@ -146,7 +146,7 @@ Basically, we split the array into a series of omega values:
146
146
$$\omega_N^k = e^{-2 \pi k / N}$$
147
147
148
148
And at each step, we use the appropriate term.
149
-
For example, imagine we need to perform an FFT of an array of only 2 elements.
149
+
For example, imagine we need to perform an FFT of an array of only 2 elements.
150
150
We can represent this addition with the following (radix-2) butterfly:
151
151
152
152
<palign="center">
@@ -197,7 +197,7 @@ Here, the ordering of the array was simply divided into even and odd elements on
197
197
198
198
Ultimately, that's all I want to say about Fourier Transforms for now, but this chapter still needs a good amount of work!
199
199
I'll definitely come back to this at some point, so let me know what you liked and didn't like and we can go from there!
200
-
200
+
201
201
### Bibliography
202
202
203
203
{% references %} {% endreferences %}
@@ -238,11 +238,11 @@ Note: I implemented this in Julia because the code seems more straightforward in
238
238
Some rather impressive scratch code was submitted by Jie and can be found here: https://scratch.mit.edu/projects/37759604/#editor
Copy file name to clipboardExpand all lines: chapters/computational_geometry/computational_geometry.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,13 @@
1
1
# Computational Geometry
2
2
When it comes to the different sectors of computational mathematics, there are none that bring me more joy than computational geometry.
3
3
In some sense, it is the foundation for almost every area of automatically generated two and three dimensional graphics.
4
-
If you have time to spend poring through some interesting research, I would definitely recommend going to the [arXiv.org section for computational geometry](https://arxiv.org/list/cs.CG/recent).
4
+
If you have time to spend poring through some interesting research, I would definitely recommend going to the [arXiv.org section for computational geometry](https://arxiv.org/list/cs.CG/recent).
5
5
We will add more to this section as the Archive evolves, so let me know of any algorithms that you would like to cover in the future!
0 commit comments