BQN's Quantum Noise
-Preamble
-Preamble
+We will implement and test a compact quantum interpreter in the BQN1 programming language. Initially, we import the necessary system functions and define a 1-modifier for handling @@ -212,7 +207,7 @@
Preamble
Sin‿Cos‿GCD ← •math +Sin‿Cos‿GCD ← •math U ← •rand.Range _cp ← {(-´𝔽¨)⋈(+´𝔽¨)⟜⌽} @@ -226,16 +221,16 @@Preamble
Interpreter
-Interpreter
+The (400 chars2) quantum interpreter is based on references arXiv:1711.02086 and arXiv:1608.03355. For simplicity, we always measure at the end of the execution:
Q ← {𝕊qb‿sc‿r: +Q ← {𝕊qb‿sc‿r: wf ← (1⌾⊑⋈⊢)⥊⟜0 2⋆qb M‿K ← ⟨+˝∘×⎉1‿∞ _cp, {1𝕊𝕩:𝕩; 𝕨𝕊1:𝕨; 𝕨∾∘×⟜<_cp𝕩}⟩ E ← {0𝕊𝕩:1; K⍟(𝕨-1)˜𝕩} @@ -251,9 +246,9 @@Interpreter
Shor's algorithm
-Shor's algorithm
+As a test case, we employ the quantum circuit of Shor's algorithm for the number fifteen and base eleven, following references @@ -264,7 +259,7 @@
Shor's algorithm
n‿a‿qb‿r ← ⟨15, 11, 5, 0 U˜ 2⋆3⟩ +n‿a‿qb‿r ← ⟨15, 11, 5, 0 U˜ 2⋆3⟩ sc ← ⟨ ⟨0⟩‿g.h ⋄ ⟨1⟩‿g.h ⋄ ⟨2⟩‿g.h @@ -282,7 +277,7 @@Shor's algorithm
-@@ -296,9 +291,9 @@C >+˝{Q qb‿sc‿𝕩}¨ r +C >+˝{Q qb‿sc‿𝕩}¨ rShor's algorithm
Epilogue
-Epilogue
+Why the hieroglyphs, you may ask? The tacit and functional style, coupled with numerous combinators, makes programming feel like solving a fun algebraic puzzle rather than drafting a manifesto. @@ -317,7 +312,7 @@
Epilogue
+⟨ 44 64 ⟩@@ -330,7 +325,7 @@Epilogue
+┌─ ╵ '-' '´' '¨' '⋈' '+' '⟜' '⌽' '⊢' '≢' '⥊' '<' '=' '⌜' '˜' '↕' '∾' '○' '⌾' '⊸' '⊑' '÷' '√' '⊏' '⋆' '˝' '∘' '×' '⎉' '≡' '⊣' '⌊' '⁼' '≠' '⍟' '◶' '↓' '¬' '∊' '/' '»' '∨' '`' '>' '⍒' 8 8 10 5 8 3 6 7 1 5 9 6 3 12 6 5 2 5 7 9 5 1 1 5 4 8 5 1 3 3 1 1 5 1 2 1 1 1 1 1 1 2 3 1 @@ -351,7 +346,7 @@Epilogue
While the interpreter's performance is not particularly optimized, here is a comparison with the equivalent Common Lisp code: -+Benchmark 1: cbqn -f ./bqn/q.bqn Time (mean ± σ): 5.468 s ± 0.077 s [User: 5.427 s, System: 0.005 s] Range (min … max): 5.358 s … 5.535 s 5 runs @@ -374,7 +369,7 @@Epilogue
+Got 25361 samples (REPL): 25361 samples: 2│ Q ← {𝕊qb‿sc‿r: @@ -394,7 +389,8 @@Epilogue
-Try running the simulation in the BQN repl and explore it! The complete source code is hosted in a GitHub repository. +Try running the simulation in the BQN repl and explore it! This post is also available as an
org-mode
computational +notebook in a GitHub repository.
Scheming a mise-en-abîme in BQN
-Prelude
-Prelude
+We will build and interpreter for a subset of the Scheme programming language, following a Norvig's essay. An alternative reference would @@ -213,9 +208,9 @@
Prelude
A Lisp quine
-A Lisp quine
+Given the title of this post, I couldn't think of a better test for our interpreter than this one: diff --git a/spodat.html b/spodat.html index 2abf0cb..45923c4 100644 --- a/spodat.html +++ b/spodat.html @@ -192,11 +192,6 @@ .org-svg { } -
@@ -206,9 +201,9 @@Songs to pave the seasons
I have analyzed my Spotify data1 for the period 2016-2024. The results accurately represent my actual music taste. -Technical details
-Technical details
+This is a suitable task for an array language, so I rely on BQN which is my favorite one: @@ -240,15 +235,15 @@
Technical details
Top songs
-Top songs
+s Q spd
+┌─ ╵ 1 "Countless Skies" 2 "Divertimento I, K.136: Allegro" @@ -274,15 +269,15 @@Top songs
Top artists
-Top artists
+a Q spd
+┌─ ╵ 1 "Opeth" 2 "Wolfgang Amadeus Mozart" @@ -308,9 +303,9 @@Top artists
Bonus: Opeth anthology
-Bonus: Opeth anthology
+This is the Opeth album I would recommend to anyone. The query function needs to be modified a bit for generating it. But before that, let's look at the official discography: @@ -339,7 +334,7 @@
Bonus: Opeth anthology
+┌─ ╵ 1 "Ghost of Perdition" 2 "River"