=============== LIBRARY RULES =============== From library maintainers: - The PyPI package and CLI are named libjay, but the Python import is jay (like pillow/PIL): pip install libjay, then import jay. - Braces in a program string always bind data ({name} is a parameter), never splice text into the program. - jay.j(...) and jay.apl(...) compile, bind and execute in one call; jay.j.compile(...) returns a reusable kernel with .bind() for defaults. - The APL implemented is the APL2/ISO line verified against GNU APL; trains and function assignment are extensions on by default, and Dyalog-specific readings are a planned dialect switch, not the default. - DataFrames map to a matrix rows-leading: J +/ sums each column, +/"1 sums each row; Arrow/numpy int64 and float64 columns cross zero-copy. - Columns with nulls or mixed numeric types are refused with an error naming the column; cast or fill explicitly rather than expecting coercion. - Errors point into the source string; 'not supported yet' means planned, 'not in the language' and 'closed by the sandbox' mean permanent. - Use kernel.explain() or libjay --explain to see how an expression parsed, what fused, and per-node result shapes. ### Install libjay Source: https://github.com/amyodov/libjay/blob/main/python/README.md Commands for installing the library or running the CLI tool. ```sh uvx libjay -e '(+/ % #) 3 1 4 1 5' # try the CLI with no install uv add libjay # or: pip install libjay ``` -------------------------------- ### Install and run libjay via CLI Source: https://github.com/amyodov/libjay/blob/main/README.md Commands for installing and executing libjay expressions using uv. ```sh uvx libjay -e '(+/ % #) 3 1 4 1 5' # 2.8 uvx libjay -e "⎕←'Hello, world!'" --lang apl # APL uv add libjay # or: pip install libjay ``` -------------------------------- ### Run libjay examples via CLI Source: https://github.com/amyodov/libjay/blob/main/examples/README.md Commands to execute J and APL scripts using uvx or uv run. ```sh uvx libjay hello.ijs # J: Hello, world! uvx libjay hello.apl # APL: Hello, world! uvx libjay stats.ijs # mean and range of a series uvx libjay reduce_axis.ijs # J: +/ sums along the LEADING axis uvx libjay reduce_axis.apl # APL: +/ trailing axis, +⌿ leading uvx libjay timeseries.ijs # a moving-window Bollinger z-score uvx libjay boxes.ijs # a boxed list of strings, opened and razed uvx libjay defs.ijs # an explicit verb, recursive, with if. uvx libjay dfn.apl # a dfn, with the ⍺← default-argument idiom uvx libjay trains.apl # a fork, an atop, a noun tine, a named tacit fn uvx libjay modifiers.ijs # explicit adverb/conjunction, {{ }}, a named adverb uvx libjay exact.ijs # extended integers and exact rationals uvx libjay complex.ijs # sqrt of a negative, polar form printf 'hello\n' | uvx libjay examples/input.apl # ⍞ reads a line, ⍞← echoes it printf 'hello\n' | uvx libjay examples/input.ijs # 1!:1 ]1 / 1!:2 ]2, same idea uv run --with libjay --no-project python quickstart.py # the Python API end to end ``` -------------------------------- ### Compile and run J expressions in C Source: https://github.com/amyodov/libjay/blob/main/docs/embedding.md Example demonstrating the compilation of a J expression and execution with input arguments. ```c jay_error *err = NULL; jay_program *p = jay_compile("(+/ % #) {x}", "j", -1, &err); if (!p) { /* jay_error_message(err), then jay_error_free(err) */ } const double xs[] = {1, 2, 3, 4}; const uint64_t shape[] = {4}; jay_value arg = {JAY_F64, 1, shape, xs}; jay_result *r = NULL; if (jay_run(p, &arg, 1, NULL, NULL, &r, &err) != 0) { /* ... */ } double mean = *(const double *)jay_result_data(r); /* 2.5 */ jay_result_free(r); jay_program_free(p); ``` -------------------------------- ### Output of input.apl / input.ijs Source: https://github.com/amyodov/libjay/blob/main/examples/README.md Execution output for piped input examples. ```text you said: hello ``` -------------------------------- ### Error rendering example Source: https://github.com/amyodov/libjay/blob/main/crates/libjay/README.md Example of a runtime error message rendered by the library. ```text length error: arguments do not agree: left shape 3, right shape 2 1 2 3 + 1 2 ^^^^^^^^^^^ note: frames first differ at axis 0: 3 vs 2 ``` -------------------------------- ### Fit Conjunction Examples Source: https://github.com/amyodov/libjay/blob/main/docs/coverage.md Examples of using the fit conjunction for comparison tolerance and shifting. ```J =!.0 ``` ```J x |.!.f y ``` ```J |.!.f y ``` -------------------------------- ### Execute libjay via CLI Source: https://github.com/amyodov/libjay/blob/main/python/README.md Examples of running J and APL code, reading from stdin, and executing files via the libjay command-line tool. ```sh libjay -e '(+/ % #) 3 1 4 1 5' # 2.8 libjay -e "⎕←'Hello, world!'" --lang apl # APL echo 'hello' | libjay -e '⍞' --lang apl # reads the process's stdin libjay examples/hello.apl # a file; the extension # picks the language libjay --explain -e '+/ {w} * {x}' # the structure, not a result ``` -------------------------------- ### Gerund Representation Examples Source: https://github.com/amyodov/libjay/blob/main/docs/coverage.md Examples of how gerunds are represented as boxed data. ```J +`- ``` ```J +/`- ``` ```J 0`1 ``` -------------------------------- ### Constant Verbs Source: https://github.com/amyodov/libjay/blob/main/docs/coverage.md Examples of constant verbs and explicit definition syntax. ```J 2 3: 4 ``` ```J 3 : 'y+1' ``` -------------------------------- ### APL Operators and Functional Composition Source: https://github.com/amyodov/libjay/blob/main/docs/coverage.md Usage examples for various APL operators including each, outer product, and functional composition. ```APL 2ר1 2 3 ``` ```APL ⍴¨'ab' 'cde' ``` ```APL 1 2 3∘.×1 2 3 ``` ```APL -\1 2 3 ``` ```APL (+/⌺3)1 2 3 4 5 ``` -------------------------------- ### Adverb Usage Source: https://github.com/amyodov/libjay/blob/main/docs/coverage.md Examples of various J adverbs including insert, table, and boolean functions. ```J 1 2 3 +/ 10 20 ``` ```J 'ab' ,/ 'cd' ``` ```J 99 ( program.run_on(d, &args, &mut sink)?, None => program.run(&args, &mut sink)?, }; ``` -------------------------------- ### Perform I/O operations in Python Source: https://github.com/amyodov/libjay/blob/main/python/README.md Demonstrates reading from stdin using APL expressions and custom input callables. ```python jay.apl("⍞") # reads a line from this process's stdin jay.apl("⎕", input=lambda: "2+2") # 4 — the line is run as APL lines = iter(["a", "b"]) jay.apl("⍞,⍞", input=lambda: next(lines, None)) # any callable will do ``` -------------------------------- ### Execute APL trains Source: https://github.com/amyodov/libjay/blob/main/python/README.md Demonstrates the use of APL fork and atop syntax within the Python interface. ```python jay.apl("(+/÷≢) 3 1 4 1 5") # 2.8 — a fork: sum ÷ count, unnamed jay.apl("M←+/÷≢ ⋄ M 3 1 4 1 5") # 2.8 — the same fork, named M ``` -------------------------------- ### Build and link libjay C ABI Source: https://github.com/amyodov/libjay/blob/main/docs/embedding.md Commands to build the C library and link it against a C application. ```sh cargo build -p libjay-capi --release cc app.c -Icrates/libjay-capi/include -Ltarget/release -ljay -o app ``` -------------------------------- ### Use big integers and exact rationals Source: https://github.com/amyodov/libjay/blob/main/python/README.md Illustrates the conversion of J's arbitrary-precision integers and exact ratios to Python's int and Fraction types. ```python jay.j("! 30x") # 265252859812191058636308480000000, a plain int jay.j("1r2 + 1r3") # Fraction(5, 6) ``` -------------------------------- ### Output of exact.ijs Source: https://github.com/amyodov/libjay/blob/main/examples/README.md Execution output for exact.ijs. ```text 265252859812191058636308480000000 5r6 15511210043330985984000000 ``` -------------------------------- ### Snapshot file format Source: https://github.com/amyodov/libjay/blob/main/docs/testing.md Structure of snapshot files mapping expressions to implementation-specific outputs. ```text = 2+2 the sentence > gnu: 4 one line of what GNU APL answered > dyalog: 4 one line of what Dyalog answered ``` -------------------------------- ### Define J adverbs and conjunctions Source: https://github.com/amyodov/libjay/blob/main/python/README.md Shows how to compile and execute J explicit definitions using adverbs and conjunctions. ```python jay.j.compile("twice =. 1 : 'u u y'\n*: twice 2")() # 16 — applies *: twice jay.j.compile("dbl =. {{u+u}}\n*: dbl 3")() # 18 — u+u: u plus u ``` -------------------------------- ### Output of defs.ijs Source: https://github.com/amyodov/libjay/blob/main/examples/README.md Execution output for defs.ijs. ```text fac 5: 120 720 ``` -------------------------------- ### Formatting Boxed Arrays Source: https://github.com/amyodov/libjay/blob/main/docs/coverage.md Demonstrates how the format operator converts boxed arrays into character representations. ```J $ ": 1;2 3 ``` ```J $ ": 5 ``` ```J $ ": i. 2 3 4 ``` -------------------------------- ### String Splitting Idiom Source: https://github.com/amyodov/libjay/blob/main/docs/coverage.md Demonstrates the use of the cut conjunction to split a string. ```J <;._2 'a,b,c,' ``` -------------------------------- ### Compile and bind kernels Source: https://github.com/amyodov/libjay/blob/main/python/README.md Compiling J expressions into reusable kernels and binding data to them for efficient execution. ```python import jay k = jay.j.compile("+/ {weights} * {data}") k({"weights": w, "data": chunk1}) k({"weights": w, "data": chunk2}) k2 = k.bind({"weights": w}) # a new kernel; w rides along k2({"data": chunk3}) # only the changing part at call time ``` -------------------------------- ### Execute J and APL expressions Source: https://github.com/amyodov/libjay/blob/main/README.md Demonstrates the difference in axis summation behavior between J and APL. ```python jay.j("+/ i. 2 3") # [3 5 7] — J sums along the LEADING axis jay.apl("+/2 3⍴⍳6") # [6 15] — APL sums along the TRAILING axis jay.apl("+⌿2 3⍴⍳6") # [5 7 9] — APL's leading-axis sum ``` -------------------------------- ### Process boxed arrays and lists Source: https://github.com/amyodov/libjay/blob/main/python/README.md Demonstrates how Python lists are converted to boxed arrays in J and back to nested Python data. ```python jay.j("# &.> {names}", {"names": ["ab", "cde"]}).tolist() # [2, 3] jay.j("{names}", {"names": ["ab", "cde"]}).tolist() # ['ab', 'cde'] ``` -------------------------------- ### Boxing Level Application Source: https://github.com/amyodov/libjay/blob/main/docs/coverage.md Applying verbs at specific boxing levels using L: and S:. ```J 1 ,L:0 (3;4) ``` -------------------------------- ### Catenation shape mismatch behavior Source: https://github.com/amyodov/libjay/blob/main/docs/coverage.md Demonstrates how catenation handles shape differences in J compared to APL. ```J 1 2 3 , i. 2 2 ``` ```J (2 2⍴⍳4) ⍪ 1 2 3 ``` -------------------------------- ### Record new primitives to corpus Source: https://github.com/amyodov/libjay/blob/main/docs/testing.md Use the devtools crate to record new expressions into a corpus file, optionally using the --missing flag to preserve existing entries. ```bash cargo run -p libjay-devtools -- record j corpus/j/arithmetic.txt ``` ```bash cargo run -p libjay-devtools -- record j corpus/j/arithmetic.txt --missing ``` -------------------------------- ### Setting Kernel Precision Source: https://github.com/amyodov/libjay/blob/main/python/README.md Explicitly requests single-precision (f32) execution for a kernel deployment. ```python g = k.deploy("gpu", precision="f32") # yes, I want f32 ``` -------------------------------- ### Add libjay dependency Source: https://github.com/amyodov/libjay/blob/main/crates/libjay/README.md Use cargo to add the libjay crate to your project. ```sh cargo add libjay ``` -------------------------------- ### Execute J expression with boxed vector input Source: https://github.com/amyodov/libjay/blob/main/docs/coverage.md Demonstrates passing a list of strings to a J expression, which results in a boxed vector. ```python j("# &.> {names}", {"names": ["ab", "cde"]}) ``` -------------------------------- ### Corpus file paths Source: https://github.com/amyodov/libjay/blob/main/docs/testing.md Standard directory structure for input corpus files and their corresponding snapshot files. ```text crates/libjay/tests/corpus/j/arithmetic.txt the inputs crates/libjay/tests/snapshots/j/arithmetic.snap what jconsole answered ``` -------------------------------- ### Output of stats.ijs Source: https://github.com/amyodov/libjay/blob/main/examples/README.md Execution output for stats.ijs. ```text 3.875 8 ``` -------------------------------- ### Output of dfn.apl Source: https://github.com/amyodov/libjay/blob/main/examples/README.md Execution output for dfn.apl. ```text max, mean, min: 9 3.875 1 no left argument, the default 1: 3 1 4 left argument 10: 30 10 40 ``` -------------------------------- ### Configure Dyalog Oracle Path Source: https://github.com/amyodov/libjay/blob/main/docs/testing.md Set the environment variable to specify the location of the Dyalog interpreter if it is not in a standard directory. ```sh export LIBJAY_ORACLE_DYALOG=/path/to/mapl ``` -------------------------------- ### Output of boxes.ijs Source: https://github.com/amyodov/libjay/blob/main/examples/README.md Execution output for boxes.ijs. ```text boxed names: +--+---+-+ |ab|cde|f| +--+---+-+ length of each, opened by &.>, so the answer comes back boxed too: +-+-+-+ |2|3|1| +-+-+-+ joined back together (raze): abcdef ``` -------------------------------- ### Output of timeseries.ijs Source: https://github.com/amyodov/libjay/blob/main/examples/README.md Execution output for timeseries.ijs. ```text closes: 100 101 99 102 104 103 105 107 106 108 109 107 z-score of each window: _1.22474 1.06904 1.13555 0 1.22474 1.22474 0 1.22474 1.06904 _1.22474 ``` -------------------------------- ### Explain compiled expressions Source: https://github.com/amyodov/libjay/blob/main/python/README.md Prints the internal structure of a compiled J expression to understand how it is executed. ```python k = jay.j.compile("+/ {w} * {x}", {"w": [1.0, 2.0, 3.0]}) print(k.explain({"x": [4.0, 5.0, 6.0]})) ``` -------------------------------- ### Record Dyalog APL Results Source: https://github.com/amyodov/libjay/blob/main/docs/testing.md Execute the recording tool to capture Dyalog APL outputs for the corpus. ```sh cargo run -p libjay-devtools -- record apl --impl dyalog ``` -------------------------------- ### Output of reduce_axis.ijs Source: https://github.com/amyodov/libjay/blob/main/examples/README.md Execution output for reduce_axis.ijs. ```text 0 1 2 3 4 5 3 5 7 3 12 ``` -------------------------------- ### Generate test expressions Source: https://github.com/amyodov/libjay/blob/main/docs/testing.md Command to generate new test expressions and append them to the language-specific corpus file. ```sh cargo run -p libjay-devtools -- gen j --count 300 --seed 0x9E3779B97F4A7C15 ``` -------------------------------- ### Evaluate a string as a J program Source: https://github.com/amyodov/libjay/blob/main/docs/coverage.md Compiles and executes a string within the current scope. ```J ". 'a =. 3' ``` -------------------------------- ### Implementing a custom read callback Source: https://github.com/amyodov/libjay/blob/main/docs/embedding.md The read callback must return the number of bytes written to the buffer, a value larger than the buffer capacity to request a larger buffer, or a negative value to signal end of input. ```c static int read_line(char *buf, size_t cap, void *userdata) { FILE *f = (FILE *)userdata; static char *line = NULL; static size_t n = 0; if (line == NULL && getline(&line, &n, f) < 0) return -1; /* end of input */ size_t len = strcspn(line, "\n"); if (len > cap) return (int)len; /* ask again with a bigger buffer */ memcpy(buf, line, len); free(line); line = NULL; n = 0; return (int)len; } ``` -------------------------------- ### Output of complex.ijs Source: https://github.com/amyodov/libjay/blob/main/examples/README.md Execution output for complex.ijs. ```text 0j2 2 1.5708 0.707107j0.707107 ``` -------------------------------- ### Record interpreter outputs Source: https://github.com/amyodov/libjay/blob/main/docs/testing.md Commands to record corpus results for specific languages or themes, including options for checking drift or filling missing data. ```sh # every corpus file of a language cargo run -p libjay-devtools -- record j # one theme (a path, or the bare name) cargo run -p libjay-devtools -- record j arithmetic # re-measure and fail on any drift, writing nothing cargo run -p libjay-devtools -- record j --check # record only what the snapshot does not have yet cargo run -p libjay-devtools -- record j --missing # a second implementation of the same language, into its own key cargo run -p libjay-devtools -- record apl --impl dyalog # corpus and snapshot sizes cargo run -p libjay-devtools -- stats ``` -------------------------------- ### Output of reduce_axis.apl Source: https://github.com/amyodov/libjay/blob/main/examples/README.md Execution output for reduce_axis.apl. ```text 1 2 3 4 5 6 6 15 5 7 9 ``` -------------------------------- ### Persisting Data on Device Source: https://github.com/amyodov/libjay/blob/main/python/README.md Uses upload to keep data on the device, preventing redundant transfers during repeated kernel calls. ```python g = jay.j.compile("+/ {w} * {x}").deploy("gpu") pinned = g.bind({"w": g.upload(w), "x": g.upload(x)}) pinned() # no upload ``` -------------------------------- ### Perform zero-copy data operations Source: https://github.com/amyodov/libjay/blob/main/python/README.md Integrates Polars and NumPy data with J, utilizing the Arrow C data interface for efficient memory handling. ```python import numpy as np, polars as pl df = pl.DataFrame({"open": [...], "close": [...]}) # M rows × N columns jay.j("+/ {df}", {"df": df}) # each column summed over all rows jay.j('+/"1 {df}', {"df": df}) # each row summed v = jay.j("2 * {x}", {"x": np.arange(10**8)}) # zero-copy in pl.Series(v) # zero-copy out ``` -------------------------------- ### Execute J expressions in Python Source: https://github.com/amyodov/libjay/blob/main/README.md Use the jay module to execute J language expressions, including support for passing data dictionaries. ```python import jay jay.j("+/ 1 2 3 4") # 10 — "+/" inserts + between the numbers jay.j("(+/ % #) {x}", {"x": [3.0, 1.0, 4.0, 1.0, 5.0]}) # 2.8 — the mean ``` -------------------------------- ### Corpus file format Source: https://github.com/amyodov/libjay/blob/main/docs/testing.md Syntax for defining expressions, comments, and IO settings within corpus files. ```text // a comment; a blank line is ignored too @ io=0 ⎕IO for the lines after it (APL; 1 unless said) 2 + 2 an expression ? why the two differ a note (divergences.txt only) ``` -------------------------------- ### Applying Each to Boxes Source: https://github.com/amyodov/libjay/blob/main/docs/coverage.md Uses the each adverb to apply a function to the contents of boxes. ```J # &.> 'ab';'cde' ``` ```J 1 ,&.> 1;2 ``` -------------------------------- ### Output of trains.apl Source: https://github.com/amyodov/libjay/blob/main/examples/README.md Execution output for trains.apl. ```text 3.875 ¯9 9.75 3.875 ``` -------------------------------- ### Analyze APL Statistics Source: https://github.com/amyodov/libjay/blob/main/docs/testing.md Commands to inspect expression-level disagreements and answer counts across the APL corpus. ```sh # what the two disagree about, expression by expression cargo run -p libjay-devtools -- stats apl --dialect-diff # how many answers each key holds cargo run -p libjay-devtools -- stats apl ``` -------------------------------- ### Agenda and Evoke Conjunctions Source: https://github.com/amyodov/libjay/blob/main/docs/coverage.md Using agenda and evoke conjunctions to select and apply verbs. ```J (<.`>.)@.(2&<) ``` ```J ((+`-)`:0) 5 ``` ```J ((+`*)`:3) 1 2 3 4 ``` -------------------------------- ### Output of modifiers.ijs Source: https://github.com/amyodov/libjay/blob/main/examples/README.md Execution output for modifiers.ijs. ```text 16 4 18 10 ``` -------------------------------- ### Use t-strings for type-safe interpolation Source: https://github.com/amyodov/libjay/blob/main/python/README.md Using t-strings on Python 3.14+ to provide type contracts and defaults for interpolated values. ```python k = jay.j.compile(t"+/ {weights} * {data}") k() # computes on the interpolated samples k({"data": other}) # override at call time ``` -------------------------------- ### Define a mean verb Source: https://github.com/amyodov/libjay/blob/main/docs/coverage.md Assigns a verb to a name during parsing, allowing it to be used in subsequent expressions. ```J mean =. +/ % # ``` -------------------------------- ### Handle complex numbers Source: https://github.com/amyodov/libjay/blob/main/python/README.md Shows zero-copy transfer of complex numbers between Python and J. ```python jay.j("{z} * {z}", {"z": 3 + 4j}) # (-7+24j) jay.j("%: _4") # 2j — square root of a negative ``` -------------------------------- ### APL Dfn Operators Source: https://github.com/amyodov/libjay/blob/main/docs/coverage.md Defining and using operators within dfns using ⍺⍺ and ⍵⍵. ```APL +{⍺⍺/⍵}1 2 3 ``` ```APL TWICE←{⍺⍺ ⍺⍺ ⍵} ⋄ -TWICE 5 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.