The Art of Machinery - Posts Tagged Computer ScienceComputer Science — Algorithms and data structures and other computational theory.
https://theartofmachinery.com/tags/compsci/
Extending Looped Music for Fun, Relaxation and Productivity<p>Some work (like programming) takes a lot of concentration, and I use noise-cancelling headphones
to help me work productively in silence. But for other work (like doing business paperwork), I prefer to have quiet
music in the background to help me stay focussed. Quiet background music is good for meditation or dozing, too. If you
can’t fall asleep or completely clear your mind, zoning out to some music is the next best thing.</p>
<p>The best music for that is simple and repetitive — something nice enough to listen too, but not distracting,
and okay to tune out of when needed. Computer game music is like that, by design, so there’s plenty of good background
music out there. The harder problem is finding samples that play for more than a few minutes.</p> <p>So I
made <a href="https://gitlab.com/sarneaud/loopx"><code class="language-plaintext
highlighter-rouge">loopx</code></a>, a tool that takes a sample of music that loops a few times, and
repeats the loop to make a long piece of music.</p> <p>When you’re listening to the same music loop for a
long time, even slight distortion becomes distracting. Making quality extended music audio out of real-world samples
(and doing it fast enough) takes a bit of maths and computer science. About ten years ago I was doing digital signal
processing (DSP) programming for industrial metering equipment, so this side project got me digging up some old theory
again.</p>
https://theartofmachinery.com/2021/03/12/loopx.html
https://theartofmachinery.com/2021/03/12/loopx.htmlFri, 12 Mar 2021 00:00:00 +0000Woothee (HTTP User Agent Parser)<p>I’ve written <a href="https://gitlab.com/sarneaud/woothee-d">a D implementation of the
Project Woothee multi-language HTTP user agent parser</a>. Here are some notes about what it’s useful for, and a
few things special about the D implementation.</p>
https://theartofmachinery.com/2020/11/14/woothee.html
https://theartofmachinery.com/2020/11/14/woothee.htmlSat, 14 Nov 2020 00:00:00 +0000Pi from High School Maths<p>Warning: I don’t think the stuff in this post has any direct practical application by itself
(unless you’re a nuclear war survivor and need to reconstruct maths from scratch or something). Sometimes I like to go
back to basics, though. Here’s a look at <math xmlns='http://www.w3.org/1998/Math/MathML'
display='inline'><semantics><mrow><mi>π</mi></mrow><annotation
encoding='application/x-tex'>\pi</annotation></semantics></math> and areas of curved shapes
without any calculus or transcendental functions.</p>
https://theartofmachinery.com/2020/10/26/pi_from_high_school_maths.html
https://theartofmachinery.com/2020/10/26/pi_from_high_school_maths.htmlMon, 26 Oct 2020 00:00:00 +0000Tricks with Pseudorandom Number Generators<p>Pseudorandom number generators (PRNGs) are often treated like a compromise: their output isn’t as
good as real random number generators, but they’re cheap and easy to use on computer hardware. But a special feature of
PRNGs is that they’re <em>reproducible</em> sources of random-looking data:</p> <figure
class="highlight"><pre><code class="language-d" data-lang="d"><span class="k">import</span>
<span class="n">std</span><span class="p">.</span><span
class="n">random</span><span class="p">;</span> <span class="k">import</span> <span
class="n">std</span><span class="p">.</span><span class="n">stdio</span><span
class="p">;</span> <span class="kt">void</span> <span class="n">main</span><span
class="p">()</span> <span class="p">{</span> <span class="c1">// Seed a PRNG and generate 10
pseudo-random numbers</span> <span class="k">auto</span> <span class="n">rng</span>
<span class="p">=</span> <span class="n">Random</span><span
class="p">(</span><span class="mi">42</span><span class="p">);</span> <span
class="k">foreach</span> <span class="p">(</span><span class="n">_</span><span
class="p">;</span> <span class="mf">0..10</span><span class="p">)</span> <span
class="n">write</span><span class="p">(</span><span class="n">uniform</span><span
class="p">(</span><span class="mi">0</span><span class="p">,</span> <span
class="mi">10</span><span class="p">,</span> <span class="n">rng</span><span
class="p">),</span> <span class="sc">' '</span><span class="p">);</span> <span
class="n">writeln</span><span class="p">();</span> <span class="c1">// Reset the PRNG, and
the same sequence is generated again</span> <span class="n">rng</span> <span
class="p">=</span> <span class="n">Random</span><span class="p">(</span><span
class="mi">42</span><span class="p">);</span> <span class="k">foreach</span> <span
class="p">(</span><span class="n">_</span><span class="p">;</span> <span
class="mf">0..10</span><span class="p">)</span> <span class="n">write</span><span
class="p">(</span><span class="n">uniform</span><span class="p">(</span><span
class="mi">0</span><span class="p">,</span> <span class="mi">10</span><span
class="p">,</span> <span class="n">rng</span><span class="p">),</span> <span
class="sc">' '</span><span class="p">);</span> <span class="n">writeln</span><span
class="p">();</span> <span class="c1">// Output:</span> <span class="c1">// 2 7 6 4 6 5 0 4
0 3</span> <span class="c1">// 2 7 6 4 6 5 0 4 0 3</span> <span
class="p">}</span></code></pre></figure> <p>This simple fact enables a few neat
tricks.</p>
https://theartofmachinery.com/2020/07/18/prng_tricks.html
https://theartofmachinery.com/2020/07/18/prng_tricks.htmlSat, 18 Jul 2020 00:00:00 +0000Glico (Weighted Rock Paper Scissors)<p>This still isn’t the blog post I said I was going to write about now, but I figured some game
theory would make a good post at the moment, especially when a lot of people I know are working at home with kids who
need entertaining. Here’s some stuff about a traditional Japanese kids’ game called Glico, a form of weighted Rock
Paper Scissors (RPS).</p>
https://theartofmachinery.com/2020/05/21/glico_weighted_rock_paper_scissors.html
https://theartofmachinery.com/2020/05/21/glico_weighted_rock_paper_scissors.htmlThu, 21 May 2020 00:00:00 +0000Some Useful Probability Facts for Systems Programming<p>Probability problems come up a lot in systems programming, and I’m using that term loosely to
mean everything from operating systems programming and networking, to building large online services, to creating
virtual worlds like in games. Here’s a bunch of rough-and-ready probability rules of thumb that are deeply related and
have many practical applications when designing systems.</p>
https://theartofmachinery.com/2020/01/27/systems_programming_probability.html
https://theartofmachinery.com/2020/01/27/systems_programming_probability.htmlMon, 27 Jan 2020 00:00:00 +0000Analysing D Code with KLEE<p><a href="https://klee.github.io/">KLEE</a> is a symbolic execution engine that can
rigorously verify or find bugs in software. It’s designed for C and C++, but it’s just an interpreter for LLVM bitcode
combined with theorem prover backends, so it can work with bitcode generated by <code class="language-plaintext
highlighter-rouge">ldc2</code>. One catch is that it needs a compatible bitcode port of the D runtime to run
normal D code. I’m still interested in getting KLEE to work with normal D code, but for now I’ve done some experiments
with <code class="language-plaintext highlighter-rouge">-betterC</code> D.</p>
https://theartofmachinery.com/2019/05/28/d_and_klee.html
https://theartofmachinery.com/2019/05/28/d_and_klee.htmlTue, 28 May 2019 00:00:00 +0000Why Sorting is O(N log N)<p>Any decent algorithms textbook will explain how fast sorting algorithms like quicksort and
heapsort are, but it doesn’t take crazy maths to prove that they’re as asymptotically fast as you can possibly
get.</p>
https://theartofmachinery.com/2019/01/05/sorting_is_nlogn.html
https://theartofmachinery.com/2019/01/05/sorting_is_nlogn.htmlSat, 05 Jan 2019 00:00:00 +0000Counting Sudoku Solution Grids using Monte Carlo<p>How many ways can you fill a 9x9 grid, obeying all the rules of the sudoku puzzle? The answer is
too big to just calculate directly on a computer, so an exact answer takes careful analysis. But if an absolutely exact
answer isn’t required, we can get a good statistical approximation using a Monte Carlo algorithm. As a bonus, the
algorithm doesn’t need any application-specific analysis and works on many other problems, too. It’s a handy “stupid
things that work” approach to solving problems.</p>
https://theartofmachinery.com/2017/08/14/monte_carlo_counting_sudoku_grids.html
https://theartofmachinery.com/2017/08/14/monte_carlo_counting_sudoku_grids.htmlMon, 14 Aug 2017 00:00:00 +0000Compression, Complexity and Software System Design<p>Information theory gives us a way to understand communication systems, by giving us a way to
understand what happens to information as it’s transmitted or re-encoded.</p> <p>We can also study what
happens to complexity in a software system as components depend on or interface each other. Just like we can make
rigorous arguments about how much information can be compressed, we can make arguments about how much complexity can be
simplified, and use this to make better choices when designing software systems.</p>
https://theartofmachinery.com/2017/06/25/compression_complexity_and_software.html
https://theartofmachinery.com/2017/06/25/compression_complexity_and_software.htmlSun, 25 Jun 2017 00:00:00 +0000