Solving peg solitaire by pure chance

2021-06-12, post № 245

C, #board-game

In all the years I regularly glanced at our peg solitaire on the board game shelf, seldomly even playing it and attempting a solve — moving 31 out of the total 32 pegs such that the final peg ends up at the board’s center —, yet never succeeded. The closest I got always left two or three pegs standing far between each other, calling doom for my solve.

One lobe cleared.

Not being able to solve this game, the other day I had the idea of pseudo-random game space exploration, my optimism driven by both the moderate number of pegs as well as the strict monotonicity of the game leading to all solutions being of the same length and thus in a sense equal — bearing in mind consecutive hops in the same direction are not considered as a singular move.

Wholly brainfuck

2021-05-15, post № 244

C, brainfuck, #querying

Sparked by a vague idea to query the space of all brainfuck programs — which indeed came to fruition and is detailed in my recent paper Going for a miniKanren implementation. — I thought to capture a miniscule glimpse of said space in a two-dimensional visualization:

All 2^{12+12} generalized 𝟨-long brainfuck programs’ initial three bytes of output.

Cogent chimeras compelling chastised computing

2021-04-17, post № 243

poem, #doubt

Insightful sparks, a forceful nudge —
distant glory or arcane mist:
now wobbly treading trodden paths,
sensing tender sprawling fates …
A step is taken.
A step is taken to one’s side.
Lured in by wonderous ideals,
a gate is shut, the key expunged.
But is what one seeks on this flank to be found?
Or has one only shown themselves:
what one wants most do not;
since never urged to do inquire
about attaining what they never
have proven to be all they could accept?
Away with all the doubt!
One tightly clings to specks deemed fit.
It cannot, must not, dare not crumble!
The flimsy veil begins to lift.
What now? Where to? Once one has sipped?
Stuck in between, not free, not flocking.
Gazing through bars into the veldt
whose sparse and slanted Terminaliae
crash down, they too reveil a fence.

— Jonathan Frech, April of 2021

A source location identification regression in GHC triggered by seven bytes

2021-03-22, post № 242

haskell, compiler-bug, #ghc, #parsing

Working on a minimal XML parser which does both build a data structure and remember its nodes’ source origin, I discarded the second part of a two-tuple by not requiring anything to be present. Yet instead of informing me that a mapping cannot be deconstructed, GHC 8.10.4 gave me an obscure error message:

% runhaskell Xml.hs

<no location info>: error: Tuple section in pattern context

Thankfully I sometimes adhere to a mindfully incremental approach and was not as bewilderingly disoriented as I could have been — after all, a there is an error message possesses little more value than solely stating an executable cannot be built.

Inspecting the probable location I had intelligence on, I managed to extract a seven long byte sequence which triggers a <no location info> compilation error:


Yet compilers are squeamish and shapeshifting entities — especially with regards to diagnostic capabilities. Whilst j(0,)=0 cannot be traced, j(,0)=0 induces the expected and appropriate error. As such, I tested the phenomenon using varying GHC versions:

% ghc --version && printf '%s' 'j(0,)=0' > /tmp/nli.hs && ghc /tmp/nli.hs 2>&1 \
cmdand cmdand>     | grep -q '<no location info>' ; echo $?
The Glorious Glasgow Haskell Compilation System, version 8.10.4
% ghc --version && printf '%s' 'j(0,)=0' > /tmp/nli.hs && ghc /tmp/nli.hs 2>&1 \
cmdand cmdand>     | grep -q '<no location info>' ; echo $?
The Glorious Glasgow Haskell Compilation System, version 8.8.4

To my surprise, I seemed to have found a GHC regression — triggered by only seven bytes.

Alas, this regression is a known one: Another <no location info> error (Tuple section in pattern context) has been opened on the 8th of March 2021, with its comments identifying it as a regression. Yet the fix outlined and performed is as much resolving an aspect of the issue as is it making a stylistic decision — myself facing the same problem of source location corseness, I am leaning further and further towards the approach of less pedantically accurate reporting allowing for a more minimal implementation.

Intriguingly Matured Graphics

2021-03-20, post № 241

imagery, Pygame, #throwback, #png, #colorful

Following digital excavation efforts at my disk’s deep directories, I stumbled upon a collection of colorful pseudo-random walk graphics. Since they are dated September of 2015 and were generated using unidiomatic slow snake script, their only property of note is a visually jolly aura; the following three possess a particularly vibrant one:

Autumn Colors
Deep Blue
Woven Violet

Cellular circuit simulation

2021-02-20, post № 240

c++, grid-world, #binary, #logic, #gate, #ppm

Inspired by grid worlds, non-linear notation and two-dimensional esolangs, I have attempted to design a few ASCII-art languages myself, none satisfactory enough for publication. Without the toolchain to interact in a non-typewriter manner — both on the software as well as on the hardware side — paired with the need for an apt encoding to facilitate higher-order capabilities, I could not manage to create something which stands on its own feet as a proper language, as opposed to nothing more than a convoluted yet primitive processor emulator.

In the fall of 2020, when I was tasked to teach elementary binary semantics courtesy of a brand new mandatory lecture at my university — constructing half-adders from basic gates and combining them to build full adders —, I thought that exactly this bare-bones grid world might be a fruitful endeavor for constructing and combining gates with a visualization of the entropy’s movement across the circuit (one might foolishly think of a bit meandering across a wire, although this interpretation has no physical merit to it).
Within a few hours, I had managed to settle on a grid world definition together with an under 200 lines long interpreter for it. As I opted for an ASCII-CLI-look — significantly boosting development time —, I added image output facilities for this blog post (for which I swiftly designed a few pixel glyphs; only those used by the grid world), avoiding the need to take screenshots of my terminal emulator.

Source: cellular-circuit-simulation.cpp, building: Makefile
Circuits: cellular-circuit-simulation_adder.circuit, cellular-circuit-simulation_odometer.circuit, cellular-circuit-simulation_spiral.circuit

The grid world

As in most grid worlds, non-inert characters are kept to a minimum: there are two entropy sources 0 and 1, the unary negation gate ! and three binary gates &, | and ^. All other characters except the space allow entropic bits to replicate, the special jumpers < and > allow to cross a gap of three characters, rendering interleaving wires possible.

Designing a 𝟥-bit adder

Calculating 0b110 + 0b011 == 0b1001 using a 𝟥-bit adder (input bits are interleaved, less significant bits reside on the left).

Visualizing cycles in row-major transposition encodings

2021-01-23, post № 239

mathematics, programming, c++, shell, #matrix, #encoding, #permutation, #rainbow

A matrix A\in \mathcal{D}^{h\times w} of discretely representable entries \mathcal{D} may be linearly layed out in memory using row-major order, concatenating successive rows into a contiguous (h\cdot w \cdot\texttt{sizeof}\,\mathcal{D})-bytes long array. Such a representation, however, is disruptive to the matrix’ two-dimensional nature: whilst horizontally neighboring elements remain neighbors, vertically neighboring entries are torn apart by insertion of w non-neighboring elements. As such, on matrices naturally defined operations get distorted by this encoding.
One such inherently two-dimensional operation is matrix transposition. In the realm of matrices, \mathcal{D}^{h\times w}\neq\mathcal{D}^{w\times h} are for nonsquare dimensions semantically different, being mapped to one another by transposition. Projecting onto their encoding, this semantic is lost and one is left with a permutation on memory \bullet^\top\in\mathrm{Sym}(\{1,\dots,hw\}).
To visualize this permutation, its cycle decomposition is computed of which each cycle is given a color of the rainbow dyeing this cycle’s corresponding two-dimensional pixels when interpreting its path on the underlying array in the semantics of the original matrix.

Initial transposition cycles

Above listed are all visualizations for 1\leq h\leq 8,1\leq w\leq 16, shuffled. Whilst some behave extremely regularly — for example square matrices’ transposition permutations decompose into transpositions —, others are wildly intricate. Each of them adheres to a rotational symmetry; the top left and bottom right are fixed points.

Factoids #2

2020-12-26, post № 238

mathematics, #bijection, #calculus, #Lipschitz, #naturals

VII) Cardinality coercion: \mathbb{R}\hookleftarrow\{\mathbb{N}\to\mathbb{N}\}\twoheadrightarrow\mathbb{R}

Claim. There exist both \iota:\{\mathbb{N}\to\mathbb{N}\}\hookrightarrow\mathbb{R} together with \pi:\{\mathbb{N}\to\mathbb{N}\}\twoheadrightarrow\mathbb{R}.
Proof. Iota. Define \iota:\{\mathbb{N}\to\mathbb{N}\}\hookrightarrow\mathbb{R} via
    \iota(a):=\quad&\sum_{j=1}^\infty 2^{\left(1-\sum_{i=1}^{j}(1+a(i))\right)}\cdot(2^{a(j)}-1)\\
    =\quad&\left(0.\underbrace{1111\dots11}_{\times a(1)}0\underbrace{111\dots11111}_{\times a(2)}0\dots\right)_2
and observe any sequence’s reconstructibility by dyadic expansion.
Pi. Define \pi:\{\mathbb{N}\to\mathbb{N}\}\twoheadrightarrow\mathbb{R} via
    \pi(a):=\quad&a(1)+\sum_{j=2}^\infty 2^{1-j}\cdot\delta_{a(j)\in 2\mathbb{Z}}\\
    =\quad&a(1)+\left(0.\delta_{a(2)\in 2\mathbb{Z}}\delta_{a(3)\in 2\mathbb{Z}}\delta_{a(4)\in 2\mathbb{Z}}\dots\right)_2
and observe any real’s constructibility by dyadic expansion.

Thus, \{\mathbb{N}\to\mathbb{N}\}\cong\mathbb{R} in \mathbf{(SET)} is shown.

Jonathan Frech's blog; built 2022/01/16 06:13:11 CET