Skip to content

Commit 2f09edd

Browse files
committed
Add sponsor badge
1 parent 50e1bf4 commit 2f09edd

1 file changed

Lines changed: 147 additions & 0 deletions

File tree

README.md

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
[![Sponsor](https://img.shields.io/badge/Sponsor-%E2%9D%A4-pink?logo=github)](https://github.com/sponsors/hyperpolymath)
2+
3+
// SPDX-License-Identifier: MPL-2.0
4+
// Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk>
5+
= Bqniser
6+
Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>
7+
:toc: left
8+
:icons: font
9+
10+
== What Is This?
11+
12+
**BQNiser** scans your existing code for array computation patterns -- loops,
13+
maps, folds, reductions, comprehensions -- and rewrites them as optimised
14+
https://mlochbaum.github.io/BQN/[BQN] array primitives.
15+
16+
BQN (by Marshall Lochbaum) is an array language descended from APL/J/K.
17+
It brings first-class functions, trains (`∘ ○ ⊸ ⟜`), under/structural-under
18+
combinators (``), rank polymorphism, and leading-axis theory to array
19+
processing. BQNiser lets you harness 10-100x speedups on array-heavy
20+
workloads *without learning BQN yourself*.
21+
22+
Where your Python loop takes 200ms to filter-then-reduce a million-row column,
23+
a single BQN expression using `/` (replicate), `` (reverse), or `` (grade-up)
24+
completes in under 2ms via https://github.com/dzaima/CBQN[CBQN]'s vectorised
25+
runtime.
26+
27+
== How It Works
28+
29+
BQNiser follows the https://github.com/hyperpolymath/iseriser[-iser pattern]:
30+
you describe *what* you want; the tool generates *everything*.
31+
32+
1. **Manifest** (`bqniser.toml`) -- describe your workload, entry points, data shapes
33+
2. **Source Analysis** -- AST-based detection of array patterns in Rust, Python, or Julia source
34+
3. **Pattern Matching** -- map detected patterns to BQN primitives:
35+
- Nested loops over arrays -> `¨` (each), `` (table)
36+
- Accumulate/reduce -> `´` (fold), `` ` `` (scan)
37+
- Filter -> `/` (replicate) with boolean mask
38+
- Sort/rank -> `` (grade-up), `` (grade-down)
39+
- Reshape/transpose -> `` (reshape), `` (transpose)
40+
- Concatenation -> `` (join)
41+
- Index selection -> `` (select)
42+
- Reversal -> `` (reverse), `` (under) for structural transforms
43+
4. **Idris2 ABI** (`src/interface/abi/`) -- formal proofs that each rewrite preserves
44+
input-output equivalence (dependent types guarantee correctness)
45+
5. **BQN Codegen** -- emit optimised BQN source using trains and tacit style
46+
6. **CBQN FFI Bridge** (`src/interface/ffi/`) -- Zig-based C-ABI bridge to the
47+
https://github.com/dzaima/CBQN[CBQN] runtime, so generated BQN runs
48+
in-process with zero serialisation overhead
49+
50+
== Key Value
51+
52+
* **10-100x on array operations** -- vectorised BQN primitives beat scalar loops
53+
* **Automatic pattern detection** -- finds optimisable code via AST analysis
54+
* **Equivalence proofs** -- Idris2 dependent types prove rewrites preserve semantics
55+
* **Gradual adoption** -- replace hot loops one at a time, keep the rest untouched
56+
* **Zero BQN knowledge required** -- the tool generates all BQN and FFI code
57+
* **Rank polymorphism** -- BQN's leading-axis theory means primitives generalise
58+
across any number of dimensions automatically
59+
60+
== BQN Primitives Reference
61+
62+
BQNiser targets these core primitives and combinators:
63+
64+
[cols="1,2,3"]
65+
|===
66+
| Glyph | Name | Detected Pattern
67+
68+
| `` | Join | `concat`, `append`, `extend`
69+
| `` | Reverse | `reversed()`, `[::-1]`
70+
| `` | Grade Up | `sorted()`, `argsort`
71+
| `` | Grade Down | `sorted(reverse=True)`
72+
| `/` | Replicate | `filter`, boolean indexing
73+
| `` | Select | `arr[indices]`, `take`, `gather`
74+
| `` | Reshape | `reshape`, `flatten`, `ravel`
75+
| `` | Transpose | `transpose`, `T`, axis permutation
76+
| `¨` | Each | `map`, list comprehension
77+
| `` | Table | nested `map`, outer product
78+
| `´` | Fold | `reduce`, `foldl`, `inject`
79+
| `` ` `` | Scan | `accumulate`, `scanl`, prefix sums
80+
| `` | Under | structural transforms, lens-like updates
81+
| `∘○⊸⟜` | Trains | function composition, tacit pipelines
82+
|===
83+
84+
== Architecture
85+
86+
```
87+
bqniser.toml src/interface/abi/ src/interface/ffi/
88+
┌──────────┐ ┌─────────────────┐ ┌─────────────────┐
89+
│ Manifest │──parse──→│ Idris2 ABI │──gen──→│ Zig FFI │
90+
│ (TOML) │ │ (Types, Layout, │ │ (CBQN embedding │
91+
└──────────┘ │ Foreign) │ │ C-ABI bridge) │
92+
│ └────────┬────────┘ └────────┬────────┘
93+
│ │ │
94+
▼ ▼ ▼
95+
┌──────────┐ ┌─────────────────┐ ┌─────────────────┐
96+
│ Rust CLI │──scan──→ │ Pattern Matcher │──emit─→│ BQN Codegen │
97+
│ (clap) │ │ (AST → BQN map)│ │ (.bqn files) │
98+
└──────────┘ └─────────────────┘ └─────────────────┘
99+
```
100+
101+
* **Rust CLI** -- parses manifest, invokes AST analysis, orchestrates generation
102+
* **Pattern Matcher** -- maps source-level patterns to BQN primitive candidates
103+
* **Idris2 ABI** -- proves BQN value layout (array header + shape vector + data cells),
104+
proves rewrite equivalence for each transformation
105+
* **BQN Codegen** -- emits idiomatic BQN using trains, under, and tacit definitions
106+
* **Zig FFI** -- bridges CBQN's C API (`BQN_NewEval`, `BQN_Call`, value accessors),
107+
handles BQN value lifecycle and memory management
108+
109+
Part of the https://github.com/hyperpolymath/iseriser[-iser family] of
110+
acceleration frameworks.
111+
112+
== Use Cases
113+
114+
* **Data processing pipelines** -- ETL stages with heavy filtering, sorting, reshaping
115+
* **Scientific computing** -- matrix operations, statistical reductions, signal processing
116+
* **Financial analytics** -- rolling windows, aggregations, time-series transforms
117+
* **Compiler/transpiler backends** -- batch AST transformations as array operations
118+
* **ETL optimisation** -- replace row-by-row processing with bulk array primitives
119+
120+
== Quick Start
121+
122+
```bash
123+
# Initialise a manifest
124+
bqniser init
125+
126+
# Edit bqniser.toml to describe your workload
127+
# (see examples/ for patterns)
128+
129+
# Generate BQN + FFI artifacts
130+
bqniser generate
131+
132+
# Build everything
133+
bqniser build
134+
135+
# Run
136+
bqniser run
137+
```
138+
139+
== Status
140+
141+
**Codebase in progress.** Architecture defined, CLI scaffolded, Idris2 ABI types
142+
and Zig FFI bridge stubbed. Pattern detection engine and BQN codegen are the
143+
active development frontier.
144+
145+
== License
146+
147+
SPDX-License-Identifier: MPL-2.0

0 commit comments

Comments
 (0)