Skip to content

Commit 2e7f37d

Browse files
Butt4cak3leios
authored andcommitted
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
1 parent 8452646 commit 2e7f37d

File tree

84 files changed

+768
-765
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+768
-765
lines changed

.editorconfig

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
root = true
22

3-
# This file
4-
[.editorconfig]
5-
trim_trailing_whitespace = true
6-
insert_final_newline = true
7-
8-
# Pretty much everything should trim whitespace and have a final EOL
9-
[*.{c,clj,cpp,cs,css,elm,go,hs,html,jl,js,md,py,rs}]
3+
# Base for all text files
4+
[*]
105
trim_trailing_whitespace = true
116
insert_final_newline = true
7+
end_of_line = lf
128

139
# C
1410
[*.c]
@@ -69,6 +65,11 @@ indent_size = 2
6965
indent_style = space
7066
indent_size = 2
7167

68+
# OCAML
69+
[*.ml]
70+
indent_style = space
71+
indent_size = 2
72+
7273
# Python
7374
[*.py]
7475
indent_style = space

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Force all text files to have LF line endings
2+
* text=auto eol=lf

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# 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.
33
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.
44
The book can be found here: https://www.algorithm-archive.org/.
55
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.
88
If you would like to communicate more directly, please feel free to go to our discord: https://discord.gg/Pr2E9S6.
99

1010

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.
1212
Fortunately, there are a lot of algorithms out there, which means that there is a lot of content material available.
1313
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.
1414
That said, we'll still cover a few algorithms for fun that have very little, if any practical purpose.

TODO.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ I'll try to keep this list updated as I write more sections
2323
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
2424

2525
* **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!
2828

2929
Anyway, let me know what you think. I love the community we have here and appreciate all the conversations we've had so far!

book.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
},
2626
{
2727
"lang": "cs",
28-
"name": "C#"
28+
"name": "C#"
2929
},
3030
{
3131
"lang": "cpp",
@@ -79,7 +79,7 @@
7979
"lang": "LabVIEW",
8080
"name": "LabVIEW"
8181
}
82-
82+
8383
],
8484
"split": false
8585
}

book_ace.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
},
1919
{
2020
"lang": "cs",
21-
"name": "C#"
21+
"name": "C#"
2222
},
2323
{
2424
"lang": "c",
25-
"name": "C"
25+
"name": "C"
2626
}
2727
],
28-
"split": true
28+
"split": true
2929
},
3030
"include-codeblock": {
3131
"template": "ace",

chapters/FFT/code/julia/fft.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function cooley_tukey(x)
2525
half = div(N,2)
2626
factor = exp.(-2im*pi*n/N)
2727
return vcat(x_odd + x_even .* factor[1:half],
28-
x_odd - x_even .* factor[1:half])
28+
x_odd - x_even .* factor[1:half])
2929

3030
end
3131

@@ -84,7 +84,7 @@ function iterative_cooley_tukey(x)
8484
for k = 1:length(y)
8585
z[start_index+k-1] = y[k]
8686
end
87-
end
87+
end
8888
bnum = div(bnum,2)
8989
end
9090

chapters/FFT/cooley_tukey.md

+35-35
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
## What Makes a Fourier Transform Fast?
22

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).
44
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.
66

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 }}.
88
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.
99

1010
### What is a Fourier Transform?
1111

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.
1313
So, here it is in all it's glory!
1414

1515
$$F(\xi) = \int_{-\infty} ^\infty f(x) e^{-2 \pi i x \xi} dx$$
@@ -18,24 +18,24 @@ and
1818

1919
$$f(x) = \int_{-\infty} ^\infty F(\xi) e^{2 \pi i \xi x} d\xi$$
2020

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.
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.
2323
As I mentioned, this is not intuitive syntax, so please allow me to explain a bit.
2424

2525
Firstly, **what does the Fourier Transform do?**
2626

2727
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$$.
2828
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.
3030

3131
<p align="center">
3232
<img src="res/FT_example.png" width="500" height="250" />
3333
</p>
3434

35-
This is what the Fourier Transform does!
35+
This is what the Fourier Transform does!
3636
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.
3737

38-
Now, how does this relate to the transformations above?
38+
Now, how does this relate to the transformations above?
3939
Well, the easiest way is to substitute in the Euler's formula:
4040

4141
$$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:
4848

4949
$$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$$
5050

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.
5353

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.
5555
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.
5656

5757
### What is a Discrete Fourier Transform?
@@ -60,12 +60,12 @@ In principle, the Discrete Fourier Transform (DFT) is simply the Fourier transfo
6060

6161
$$X_k = \sum_{n=0}^{N-1} x_n \cdot e^{-2 \pi k n / N}$$
6262

63-
and
63+
and
6464

6565
$$x_n = \frac{1}{N} \sum_{k=0}^{N-1} X_k \cdot e^{2 \pi k n / N}$$
6666

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!
6969
For some reason, though, putting code to this transformation really helped me figure out what was actually going on.
7070

7171
{% method %}
@@ -83,21 +83,21 @@ For some reason, though, putting code to this transformation really helped me fi
8383
[import:2-11, lang:"julia"](code/julia/fft.jl)
8484
{% endmethod %}
8585

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!
8989
This matrix is the heart to the transformation itself!
9090

9191
```
92-
M = [1.0+0.0im 1.0+0.0im 1.0+0.0im 1.0+0.0im;
93-
1.0+0.0im 6.12323e-17-1.0im -1.0-1.22465e-16im -1.83697e-16+1.0im;
94-
1.0+0.0im -1.0-1.22465e-16im 1.0+2.44929e-16im -1.0-3.67394e-16im;
92+
M = [1.0+0.0im 1.0+0.0im 1.0+0.0im 1.0+0.0im;
93+
1.0+0.0im 6.12323e-17-1.0im -1.0-1.22465e-16im -1.83697e-16+1.0im;
94+
1.0+0.0im -1.0-1.22465e-16im 1.0+2.44929e-16im -1.0-3.67394e-16im;
9595
1.0+0.0im -1.83697e-16+1.0im -1.0-3.67394e-16im 5.51091e-16-1.0im]
9696
```
9797

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?
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?
101101

102102
Recursion!
103103

@@ -106,11 +106,11 @@ Recursion!
106106
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.
107107
The Cooley-Tukey algorithm calculates the DFT directly with fewer summations and without matrix multiplications.
108108
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.
112112
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.
114114

115115
In the end, the code looks like:
116116
{% method %}
@@ -128,14 +128,14 @@ In the end, the code looks like:
128128
[import:14-31, lang:"julia"](code/julia/fft.jl)
129129
{% endmethod %}
130130

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.
132132
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.
133133

134134
The above method is a perfectly valid FFT; however, it is missing the pictorial heart and soul of the Cooley-Tukey algorithm: Butterfly Diagrams.
135135

136136
### 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.
139139
This means that even though we need to be careful about how we add elements together, we are still ultimately performing the following operation:
140140

141141
$$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:
146146
$$\omega_N^k = e^{-2 \pi k / N}$$
147147

148148
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.
150150
We can represent this addition with the following (radix-2) butterfly:
151151

152152
<p align="center">
@@ -197,7 +197,7 @@ Here, the ordering of the array was simply divided into even and odd elements on
197197

198198
Ultimately, that's all I want to say about Fourier Transforms for now, but this chapter still needs a good amount of work!
199199
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+
201201
### Bibliography
202202

203203
{% references %} {% endreferences %}
@@ -238,11 +238,11 @@ Note: I implemented this in Julia because the code seems more straightforward in
238238
Some rather impressive scratch code was submitted by Jie and can be found here: https://scratch.mit.edu/projects/37759604/#editor
239239
{% endmethod %}
240240

241-
241+
242242
<script>
243243
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
244244
</script>
245-
$$
245+
$$
246246
\newcommand{\d}{\mathrm{d}}
247247
\newcommand{\bff}{\boldsymbol{f}}
248248
\newcommand{\bfg}{\boldsymbol{g}}

chapters/QI/QI.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Quantum Information
22

3-
Quantum information theory is... intense.
3+
Quantum information theory is... intense.
44
It requires a strong and fundamental understanding of classical information theory and quantum mechanics.
55
It is not obvious in any way and deserves many textbooks on it's own.
66
In fact, there are numerous textbooks on the subject already.

chapters/computational_geometry/computational_geometry.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Computational Geometry
22
When it comes to the different sectors of computational mathematics, there are none that bring me more joy than computational geometry.
33
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).
55
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!
66

77
<script>
88
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
99
</script>
10-
$$
10+
$$
1111
\newcommand{\d}{\mathrm{d}}
1212
\newcommand{\bff}{\boldsymbol{f}}
1313
\newcommand{\bfg}{\boldsymbol{g}}

chapters/computational_geometry/gift_wrapping/chan/chans.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script>
22
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
33
</script>
4-
$$
4+
$$
55
\newcommand{\d}{\mathrm{d}}
66
\newcommand{\bff}{\boldsymbol{f}}
77
\newcommand{\bfg}{\boldsymbol{g}}

chapters/computational_geometry/gift_wrapping/gift_wrapping.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Strictly speaking, though, the term is not entirely accurate for all convex hull
99
<script>
1010
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
1111
</script>
12-
$$
12+
$$
1313
\newcommand{\d}{\mathrm{d}}
1414
\newcommand{\bff}{\boldsymbol{f}}
1515
\newcommand{\bfg}{\boldsymbol{g}}

0 commit comments

Comments
 (0)