Skip to content

Commit 7227bd0

Browse files
committed
added a file to allow merge
2 parents d980303 + 19db513 commit 7227bd0

File tree

69 files changed

+2474
-1012
lines changed

Some content is hidden

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

69 files changed

+2474
-1012
lines changed

CONTRIBUTORS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ Nicole Mazzuca
33
Marius Becker
44
Gathros
55
Jeremie Gillet (- Jie -)
6+
Salim Khatib
7+
Hitesh C

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# The Arcane Algorithm Archive
22
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.
4-
The book can be found here: https://www.gitbook.com/book/leios/algorithm-archive/details.
5-
The github repository can be found here: https://github.com/leios/algorithm-archive.
4+
The book can be found here: https://www.algorithm-archive.org/.
5+
The github repository can be found here: https://github.com/algorithm-archivists/algorithm-archive.
66
Most algorithms have been covered on the youtube channel LeiosOS: https://www.youtube.com/user/LeiosOS
7-
and livecoded on Twitch: https://www.twitch.tv/simuleios
7+
and livecoded on Twitch: https://www.twitch.tv/simuleios.
8+
If you would like to communicate more directly, please feel free to go to our discord: https://discord.gg/Pr2E9S6.
9+
810

911
Note that the this project is is essentially a book about algorithms collaboratively written by an online community.
1012
Fortunately, there are a lot of algorithms out there, which means that there is a lot of content material available.

SUMMARY.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Summary
22

3-
* [README](README.md)
3+
* [Algorithm Archive](README.md)
44
* [TODO](TODO.md)
55
* [Introduction](chapters/introduction.md)
66
* [A Personal Note](chapters/getting_started.md)
@@ -46,5 +46,8 @@
4646
* [Physics Solvers](chapters/physics_solvers/physics_solvers.md)
4747
* [Verlet Integration](chapters/physics_solvers/verlet/verlet.md)
4848
* [Barnes-Hut](chapters/physics_solvers/barnes_hut.md)
49+
* [Quantum Systems](chapters/physics_solvers/quantum/quantum.md)
50+
* [Split-Operator Method](chapters/physics_solvers/quantum/split-op/split-op.md)
4951
* [Data Compression](chapters/data_compression/data_compression.md)
5052
* [Huffman Encoding](chapters/data_compression/huffman/huffman.md)
53+
* [Quantum Information](chapters/QI/QI.md)

book.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"gitbook": "3.x.x",
3-
"plugins": ["mathjax", "bibtex-cite", "creativecommons", "wordcount", "theme-api", "include-codeblock"],
3+
"plugins": ["mathjax", "bibtex-cite", "creativecommons", "wordcount", "theme-api", "include-codeblock", "ga"],
44
"lunr": {
55
"maxIndexSize": 1000000000
66
},
@@ -9,6 +9,9 @@
99
"fixlang": true,
1010
"unindent": true
1111
},
12+
"ga": {
13+
"token": "UA-118252470-1"
14+
},
1215
"theme-api": {
1316
"languages": [
1417
{

book_ace.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
3+
"plugins": ["mathjax", "bibtex-cite", "creativecommons", "wordcount", "theme-api", "include-codeblock", "ace"],
4+
"lunr": {
5+
"maxIndexSize": 1000000000
6+
},
7+
"pluginsConfig": {
8+
"theme-api": {
9+
"languages": [
10+
{
11+
"lang": "pseudo",
12+
"name": "Pseudocode",
13+
"default": true
14+
},
15+
{
16+
"lang": "jl",
17+
"name": "julia"
18+
},
19+
{
20+
"lang": "cs",
21+
"name": "C#"
22+
},
23+
{
24+
"lang": "c",
25+
"name": "C"
26+
}
27+
],
28+
"split": true
29+
},
30+
"include-codeblock": {
31+
"template": "ace",
32+
"unindent": true,
33+
"theme": "coffee"
34+
}
35+
}
36+
}

chapters/FFT/code/c/fft.c

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
#include <complex.h>
22
#include <math.h>
3+
#include <stdio.h>
34
#include <stdlib.h>
5+
#include <string.h>
46
#include <time.h>
5-
#include <stdio.h>
67

7-
#define PI 3.1415926535897932384626
8+
void dft(double complex *X, const size_t N) {
9+
double complex tmp[N];
10+
for (size_t i = 0; i < N; ++i) {
11+
tmp[i] = 0;
12+
for (size_t j = 0; j < N; ++j) {
13+
tmp[i] += X[j] * cexp(-2.0 * M_PI * I * j * i / N);
14+
}
15+
}
16+
17+
memcpy(X, tmp, N * sizeof(*X));
18+
}
819

920
void cooley_tukey(double complex *X, const size_t N) {
1021
if (N >= 2) {
@@ -21,38 +32,40 @@ void cooley_tukey(double complex *X, const size_t N) {
2132
cooley_tukey(X + N / 2, N / 2);
2233

2334
for (size_t i = 0; i < N / 2; ++i) {
24-
X[i + N / 2] = X[i] - cexp(-2.0 * I * PI * i / N) * X[i + N / 2];
35+
X[i + N / 2] = X[i] - cexp(-2.0 * I * M_PI * i / N) * X[i + N / 2];
2536
X[i] -= (X[i + N / 2]-X[i]);
2637
}
2738
}
2839
}
2940

3041
void bit_reverse(double complex *X, size_t N) {
31-
double complex temp;
32-
unsigned int b;
42+
for (int i = 0; i < N; ++i) {
43+
int n = i;
44+
int a = i;
45+
int count = (int)log2((double)N) - 1;
3346

34-
for (unsigned int i = 0; i < N; ++i) {
35-
b = i;
36-
b = (((b & 0xaaaaaaaa) >> 1) | ((b & 0x55555555) << 1));
37-
b = (((b & 0xcccccccc) >> 2) | ((b & 0x33333333) << 2));
38-
b = (((b & 0xf0f0f0f0) >> 4) | ((b & 0x0f0f0f0f) << 4));
39-
b = (((b & 0xff00ff00) >> 8) | ((b & 0x00ff00ff) << 8));
40-
b = ((b >> 16) | (b << 16)) >>
41-
(32 - (unsigned int) log2((double)N));
42-
if (b > i) {
43-
temp = X[b];
44-
X[b] = X[i];
45-
X[i] = temp;
46-
}
47+
n >>= 1;
48+
while (n > 0) {
49+
a = (a << 1) | (n & 1);
50+
count--;
51+
n >>= 1;
4752
}
53+
n = (a << count) & ((1 << (int)log2((double)N)) - 1);
54+
55+
if (n > i) {
56+
double complex tmp = X[i];
57+
X[i] = X[n];
58+
X[n] = tmp;
59+
}
60+
}
4861
}
4962

5063
void iterative_cooley_tukey(double complex *X, size_t N) {
5164
bit_reverse(X, N);
5265

5366
for (int i = 1; i <= log2((double)N); ++i) {
5467
int stride = pow(2, i);
55-
double complex w = cexp(-2.0 * I * PI / stride);
68+
double complex w = cexp(-2.0 * I * M_PI / stride);
5669
for (size_t j = 0; j < N; j += stride) {
5770
double complex v = 1.0;
5871
for (size_t k = 0; k < stride / 2; ++k) {

chapters/FFT/code/julia/fft.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function DFT(x)
55
# We want two vectors here for real space (n) and frequency space (k)
66
n = 0:N-1
77
k = n'
8-
transform_matrix = exp.(-2im * pi *n *k / N)
8+
transform_matrix = exp.(-2im*pi*n*k/N)
99
return transform_matrix*x
1010

1111
end
@@ -22,7 +22,6 @@ function cooley_tukey(x)
2222
x_even = x[2]
2323
end
2424
n = 0:N-1
25-
#n = n'
2625
half = div(N,2)
2726
factor = exp.(-2im*pi*n/N)
2827
return vcat(x_odd + x_even .* factor[1:half],

chapters/FFT/cooley_tukey.md

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,3 @@
1-
<script>
2-
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
3-
</script>
4-
$$
5-
\newcommand{\d}{\mathrm{d}}
6-
\newcommand{\bff}{\boldsymbol{f}}
7-
\newcommand{\bfg}{\boldsymbol{g}}
8-
\newcommand{\bfp}{\boldsymbol{p}}
9-
\newcommand{\bfq}{\boldsymbol{q}}
10-
\newcommand{\bfx}{\boldsymbol{x}}
11-
\newcommand{\bfu}{\boldsymbol{u}}
12-
\newcommand{\bfv}{\boldsymbol{v}}
13-
\newcommand{\bfA}{\boldsymbol{A}}
14-
\newcommand{\bfB}{\boldsymbol{B}}
15-
\newcommand{\bfC}{\boldsymbol{C}}
16-
\newcommand{\bfM}{\boldsymbol{M}}
17-
\newcommand{\bfJ}{\boldsymbol{J}}
18-
\newcommand{\bfR}{\boldsymbol{R}}
19-
\newcommand{\bfT}{\boldsymbol{T}}
20-
\newcommand{\bfomega}{\boldsymbol{\omega}}
21-
\newcommand{\bftau}{\boldsymbol{\tau}}
22-
$$
23-
241
## What Makes a Fourier Transform Fast?
252

263
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).
@@ -95,7 +72,7 @@ For some reason, though, putting code to this transformation really helped me fi
9572
{% sample lang="jl" %}
9673
[import:2-11, lang:"julia"](code/julia/fft.jl)
9774
{% sample lang="c" %}
98-
[import:2-11, lang:"julia"](code/julia/fft.jl)
75+
[import:7-19, lang:"c_cpp"](code/c/fft.c)
9976
{% sample lang="cpp" %}
10077
[import:2-11, lang:"julia"](code/julia/fft.jl)
10178
{% sample lang="hs" %}
@@ -140,7 +117,7 @@ In the end, the code looks like:
140117
{% sample lang="jl" %}
141118
[import:14-31, lang:"julia"](code/julia/fft.jl)
142119
{% sample lang="c" %}
143-
[import:9-28, lang:"c_cpp"](code/c/fft.c)
120+
[import:21-40, lang:"c_cpp"](code/c/fft.c)
144121
{% sample lang="cpp" %}
145122
[import:27-57, lang:"c_cpp"](code/c++/fft.cpp)
146123
{% sample lang="hs" %}
@@ -261,3 +238,27 @@ Note: I implemented this in Julia because the code seems more straightforward in
261238
Some rather impressive scratch code was submitted by Jie and can be found here: https://scratch.mit.edu/projects/37759604/#editor
262239
{% endmethod %}
263240

241+
242+
<script>
243+
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
244+
</script>
245+
$$
246+
\newcommand{\d}{\mathrm{d}}
247+
\newcommand{\bff}{\boldsymbol{f}}
248+
\newcommand{\bfg}{\boldsymbol{g}}
249+
\newcommand{\bfp}{\boldsymbol{p}}
250+
\newcommand{\bfq}{\boldsymbol{q}}
251+
\newcommand{\bfx}{\boldsymbol{x}}
252+
\newcommand{\bfu}{\boldsymbol{u}}
253+
\newcommand{\bfv}{\boldsymbol{v}}
254+
\newcommand{\bfA}{\boldsymbol{A}}
255+
\newcommand{\bfB}{\boldsymbol{B}}
256+
\newcommand{\bfC}{\boldsymbol{C}}
257+
\newcommand{\bfM}{\boldsymbol{M}}
258+
\newcommand{\bfJ}{\boldsymbol{J}}
259+
\newcommand{\bfR}{\boldsymbol{R}}
260+
\newcommand{\bfT}{\boldsymbol{T}}
261+
\newcommand{\bfomega}{\boldsymbol{\omega}}
262+
\newcommand{\bftau}{\boldsymbol{\tau}}
263+
$$
264+

chapters/QI/QI.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Quantum Information
2+
3+
Quantum information theory is... intense.
4+
It requires a strong and fundamental understanding of classical information theory and quantum mechanics.
5+
It is not obvious in any way and deserves many textbooks on it's own.
6+
In fact, there are numerous textbooks on the subject already.
7+
The purpose of this section isn't to outdo any of that fundamental knowledge.
8+
Instead, we will attempt to distill the knowledge into a short, intuitive summary, with the hopes of helping people to understand more about the topic and pursue it further on their own.
9+
10+
At the time of writing, true quantum computers do not exist.
11+
We do have some systems that are able to simulate qubits, they are not truly universal quantum computers.
12+
The closest market-ready system we currently have is D-WAVE, which boasts an impressive 128 qubits!
13+
14+
There are many places to start an introduction to quantum information theory, so we'll go through it one step at a time:
15+
16+
1. **Quantum bitlogic:** what is a qubit and how is it different than a classical bit?
17+
2. **Quantum gates and quantum circuits:** How do you fundamentally build a quantum algorithm?
18+
3. **Quantum computers in the wild:** Current experimental techniques to create a quantum computer and what makes them ill-suited as real quantum computers
19+
4. **A survey of current quantum algorithms:** There are a number of algorithms that promise fantastic advantages when performed on quantum computers and should really shake up the industry when they are finally experimentally realized.
20+
21+
As a note, item 3 might seem out of place for a book on algorithms, and I would tend to agree; however, at this point there is a phenominal amount of research being done to realize the first truly quantum computer and there are a number of potential systems that could work for this purpose.
22+
These systems will change how we think about and interface with quantum computation in the future and it is important to discuss where the field might be heading and when we can expect quantum computers at home.
23+
24+
Now, there are not too many languages that can compile quantum code.
25+
A while ago, we tried to make a quantum circuit compiler, which was modelled after the SPICE circuit simulator, but this was far from a computer language.
26+
At this point in time, it is impossible to tell what quantum computing languages will look like when we finally have a truly quantum machine, so for the time being, we will not ask for community code for the chapters related to quantum information.
27+
28+
basically, it's hard to imagine how to would adequately implement Shor's algorithm in C.
29+
As always, this section will be updated as we add more algorithms to the list.
30+

chapters/computational_geometry/computational_geometry.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# Computational Geometry
2+
When it comes to the different sectors of computational mathematics, there are none that bring me more joy than computational geometry.
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).
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!
6+
17
<script>
28
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
39
</script>
@@ -20,9 +26,3 @@ $$
2026
\newcommand{\bfomega}{\boldsymbol{\omega}}
2127
\newcommand{\bftau}{\boldsymbol{\tau}}
2228
$$
23-
24-
# Computational Geometry
25-
When it comes to the different sectors of computational mathematics, there are none that bring me more joy than computational geometry.
26-
In some sense, it is the foundation for almost every area of automatically generated two and three dimensional graphics.
27-
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).
28-
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!

chapters/computational_geometry/gift_wrapping/gift_wrapping.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# Gift Wrapping
2+
If given a "gift", here defined as a random distribution of points in two or three dimensions, gift-wrapping algorithms allow programmers to find its convex hull -- the smallest convex shape that holds all interior points.
3+
This is one of the many cases where the leap from two to three dimensions leads to an incredibly more complicated code.
4+
That said, there is a rich history of algorithms to solve this problem.
5+
6+
To be fair, only the Jarvis March is classified as *the* gift wrapping algorithm; however, it's a neat name to give algorithms that solve for the convex hull of a distribution of points.
7+
Strictly speaking, though, the term is not entirely accurate for all convex hull methods.
8+
19
<script>
210
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
311
</script>
@@ -21,10 +29,3 @@ $$
2129
\newcommand{\bftau}{\boldsymbol{\tau}}
2230
$$
2331

24-
# Gift Wrapping
25-
If given a "gift", here defined as a random distribution of points in two or three dimensions, gift-wrapping algorithms allow programmers to find its convex hull -- the smallest convex shape that holds all interior points.
26-
This is one of the many cases where the leap from two to three dimensions leads to an incredibly more complicated code.
27-
That said, there is an rich history of algorithms to solve this problem.
28-
29-
To be fair, only the Jarvis March is classified as *the* gift wrapping algorithm; however, it's a neat name to give algorithms that solve for the convex hull of a distribution of points.
30-
Strictly speaking, though, the term is not entirely accurate for all convex hull methods.

0 commit comments

Comments
 (0)