← Back to list

The Other Inverse of Rho

eric evers · 2025-11-24 12:39 · 0 claps · 1.5 min read
#apl #mathematics #programming #functional-programming
Open on Medium ↗
Wiki topics: 💻 · Programming 📐 · Mathematics

The Other Inverse of Rho

Two Wheels

Two Wheels

In APL there is a function rho, ⍴.

5 ⍴ 1 2 3
yields
1 2 3 1 2

Rho, ⍴ takes input data on the right. It duplicates the input data until it has output the size described on the left. The output has length 5, built from the input on the right.

⍴ 1 2 3 1 2
yields 
5

The first inverse of Rho, ⍴

Rho with one argument returns the shape of the input. But rho takes two arguments. I believe rho, ⍴, needs a second inverse, the input data. But not any input data, the shortest possible input data. Lets call the shortest input that could produce the output the “core” of the input. Let us calculate the core of a vector in APL.

a ← 1 2 3 1 2
b ← 5 ⍴ ⊂ a
c ← (1 2 3 4 5) ↑¨ b
d ← 1↑(5 4 3 2 1) ∘.⍴ c
e ← d = ⊂a

We want to calculate the core of 1 2 3 1 2.

Lets look at the values in our program:

a

1 2 3 1 2

b

│1 2 3 1 2│1 2 3 1 2│1 2 3 1 2│1 2 3 1 2│1 2 3 1 2│

c

│1│1 2│1 2 3│1 2 3 1│1 2 3 1 2│

d

│1 1 1 1 1│1 2 1 2 1│1 2 3 1 2│1 2 3 1 1│1 2 3 1 2│

e

│1 0 0 1 0│1 1 0 0 0│1 1 1 1 1│1 1 1 1 0│1 1 1 1 1│

1 2 3 is the third truncation that generates the first core because

1 1 1 1 1 indicates a complete match of the input: 1 2 3 1 2.

1 2 3 1 2 is the fifth truncation that generates the second core

but (1 2 3) is shorter than (1 2 3 1 2) so (1 2 3) is our winner.

So core (1 2 3 1 2) yields (1 2 3), which is the other inverse of rho, ⍴.


메타데이터
post_id
2af4cae44aec
slug
the-other-inverse-of-rho-2af4cae44aec
url
https://medium.com/@remindserfer/the-other-inverse-of-rho-2af4cae44aec
canonical_url
https://medium.com/@remindserfer/the-other-inverse-of-rho-2af4cae44aec
author_url
https://medium.com/@remindserfer
status
ok
fetched_at
2026-06-23 17:05:31