Skip to main content

Jinx

ci

An experimental interpreter for the J programming language, built on top of NumPy.

Implements many of J's primitives and tacit programming capabilities, and can be extended to support execution via other frameworks too.

Executing J

Start the interactive shell:

jinx

The shell prompt is four spaces, so commands appear indented. Internally, all multidimensional arrays are NumPy arrays. Verbs, conjunctions and adverbs are a mixture of Python and NumPy methods.

Here are some examples what Jinx can do so far:

  • Solve the "trapping rainwater" problem (solution taken from here):
    +/@((>./\ <. >./\.)-]) 0 1 0 2 1 0 1 3 2 1 2 1
6
  • Compute the correlation between two arrays of numbers (taken from here). This is a complex combination of different verbs, adverbs, conjunctions and trains:
    2 1 1 7 9 (+/@:* % *&(+/)&.:*:)&(- +/%#) 6 3 1 5 7
0.721332
  • Create identity matrices in inventive ways (see this essay):
    |.@~:\ @ ($&0) 3
1 0 0
0 1 0
0 0 1

    (i.@,~ = >: * i.) 3
1 0 0
0 1 0
0 0 1

    ((={:)\ @ i.) 3
1 0 0
0 1 0
0 0 1
  • Solve the Josephus problem (see this essay). Calculate the survivor's number for a circle of people of size N. Note the use of verb obverse and the rank conjunction:
    (1&|.&.#:)"0 >: i. 5 10    NB. N ranges from 1 to 50 here (arranged as a table)
 1  1  3  1  3  5  7  1  3  5
 7  9 11 13 15  1  3  5  7  9
11 13 15 17 19 21 23 25 27 29
31  1  3  5  7  9 11 13 15 17
19 21 23 25 27 29 31 33 35 37
  • Build nested boxes containing heterogeneous data types and print the contents:
    (<<'abc'),(<(<'de',.'fg'),(<<i. 5 2)),(<(<"0 ] % i. 2 2 3))
┌─────┬──────────┬────────────────────────────┐
│┌───┐│┌──┬─────┐│┌────────┬────────┬────────┐│
││abc│││df│┌───┐│││_       │1       │0.5     ││
│└───┘││eg││0 1│││├────────┼────────┼────────┤│
│     ││  ││2 3││││0.333333│0.25    │0.2     ││
│     ││  ││4 5│││└────────┴────────┴────────┘│
│     ││  ││6 7│││                            │
│     ││  ││8 9│││┌────────┬────────┬────────┐│
│     ││  │└───┘│││0.166667│0.142857│0.125   ││
│     │└──┴─────┘│├────────┼────────┼────────┤│
│     │          ││0.111111│0.1     │0.090909││
│     │          │└────────┴────────┴────────┘│
└─────┴──────────┴────────────────────────────┘

Easily Customisable

Everything is in Python. Adding new primitives is easy.

Update the primitives.py file with your new part of speech (e.g. a new verb such as +::). Write your implementation of this new part of speech in the relevant executor module (e.g. verbs.py) and then update the name-to-method mapping at the foot of that module. That's all that's needed.

Alternative Executors

Execution of sentences is backed by NumPy by default.

However Jinx is designed so that it's possible to implement the primitives using alternative frameworks too. Python many Machine Learning and Scientific Programming libraries that could be used to execution J code.

To prove this concept, there's highly experimental and incomplete support for JAX:

jinx --executor jax

Primitive verbs are JIT compiled and execute on JAX arrays:

    mean =: +/ % #
    mean 33 55 77 100 101
73.2

Warning

This project is experimental. There will be bugs, missing features and performance quirks.

Many key parts of J are not currently implemented (but might be in future). These include:

  • Differences in how names are interpreted and resolved at execution time.
  • Locales.
  • Definitions and direct definitions (using {{ ... }}).
  • Array types other than floats, integers and and strings.
  • Executing J scripts.
  • Control words.

Release files for jjinx 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jjinx 0.0.1
File Size Uploaded
jjinx-0.0.1.tar.gz 41.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jjinx 0.0.1
File Interpreter ABI Platform
jjinx-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 85.8 kB

Release files / jjinx-0.0.1.tar.gz

Download URL jjinx-0.0.1.tar.gz
Size 41.7 kB
Tags Source
SHA-256 checksum
How to use checksums
fad5e41aecdfc18fd215e80d42542d598d56ba55ed8151d61ab308419519932e
BLAKE2b-256 checksum
How to use checksums
cf07261fe7bb7f3e7c632851291136ab53dd945c48355d06246cbc59595fb3e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.13

Release files / jjinx-0.0.1-py3-none-any.whl

Download URL jjinx-0.0.1-py3-none-any.whl
Size 44.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1bfd32039d55dbab6d0e73a55d4bdacb560a735ed3af5990b0eb1df032598c3c
BLAKE2b-256 checksum
How to use checksums
b625384b0deac93cc522e18a61d5b2c20cf03baad20840d2288988aefe502d2c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.13

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page