rslt ← {larg} (fn ##.invs) rarg ⍝ Symbolic inverse.
[invs] applies the inverse of its function operand to (between) its argument(s).
This implementation is rather slow to be of much practical use but may be of
some theoretical interest. In the notes that follow, the operator is represented
by symbol ⍫.
NB: from Dyalog V11, this operator is available as a language primitive.
The operand may be a primitive function:
+ - × ÷ | * ⍟ ○ ~ = ⍳ ⍴ ≠ ⌽ ⊖ ⍉ / \ ⌿ ⍀ ⊥ ⊤ ↓ ↑ ⊃ ⊂ ⍋ ⍒ ⍎ ⍕ ⌹
or one of:
{⍺} {⍵} {⍺ ⍵} {⍵ ⍵}
or an expression formed by combining these functions with primitive operators:
∘ compose
⍨ commute
¨ each
∘. outer product
[·] axis
\ ⍀ scan
For example:
÷∘1.8∘(-∘32) ⍝ Fahrenheit to Celsius function.
Note that inverses may be defined for only a subset of the domain of a primitive
function. For example: inverses for = and ≠ are defined for boolean arguments;
monadic ⍋ and ⍒, for permutations of ⍳⍴⍵; and monadic ×, for (possibly nested)
arrays containing only items ¯1 0 1.
Technical notes:
In the following, ⍺⍺ and ⍵⍵ represent functions, and ⍺ and ⍵, variables.
For monadic operand function ⍺⍺, the monadic inverse (⍺⍺ ⍫) is characterised by:
⍵ ≡ (⍺⍺ ⍫) ⍺⍺ ⍵
⍵ ≡ ⍺⍺ (⍺⍺ ⍫) ⍵
For a dyadic function, the left inverse (→⍫), by:
⍵ ≡ ⍺ (⍺⍺ →⍫) ⍺ ⍺⍺ ⍵
⍵ ≡ ⍺ ⍺⍺ ⍺ (⍺⍺ →⍫) ⍵
and the right inverse (⍫←), by:
⍺ ≡ (⍺ ⍺⍺ ⍵) ⍺⍺ ⍫← ⍵
⍺ ≡ (⍺ ⍺⍺ ⍫← ⍵) ⍺⍺ ⍵
Operator [invs] returns the _left_ inverse for a dyadic function.
Primitive Functions: The monadic, left and right inverse of each supported prim-
itive function, are defined in a table within the [invs] operator. Vectors of
left and right inverses are passed into the inner operator [inv] where they are
named [li] and [ri] respectively. The sense of the inverse is reversed on proc-
essing ⍺⍺⍨ commute or ⍺⍺∘⍵ composition, by reversing these inverse vectors.
Primitive Operators: The inverse of a function derived by each of the supported
operators is as follows.
Each ⍺⍺¨⍵
⍺⍺ ⍫ ¨ => ⍺⍺ ¨ ⍫ ⍝ Inverse distributes.
example:
↓¨invs ('hello' 'world')('upper' 'lower')
hello upper
world lower
Commute ⍺⍺⍨⍵
⍺⍺ ⍨ →⍫ => ⍺⍺ ⍫← ⍨ ⍝ Inverse commutes.
example:
2 3-⍨invs 8 17
10 20
Compose ⍺⍺∘⍵⍵ ⍵ (form 1&4)
⍺⍺∘⍵⍵ ⍫ ⍵ => ⍵⍵⍫ ∘ (⍺⍺⍫) ⍵
⍺ ⍺⍺∘⍵⍵ ⍫ ⍵ => ⍵⍵⍫ ∘ (⍺∘⍺⍺⍫) ⍵
example:
↓∘⍉¨invs('hello' 'world')('upper' 'lower')
hw ul
eo po
lr pw
ll ee
od rr
1 +∘÷ invs 1.25
4
Compose ⍺∘⍵⍵ ⍵ (form 2)
⍺∘⍵⍵ ⍫ ⍵ => ⍺ ⍵⍵ ⍫ ⍵
example:
2∘⌽invs 'llo worldhe'
hello world
Compose ⍺⍺∘⍵ ⍺ (form 3)
⍺⍺∘⍵ →⍫ ⍺ => ⍵ ⍺⍺ ⍫← ⍺
example:
*∘2 invs 1 4 9 16
1 2 3 4
Outer product ⍺ ∘.⍺⍺ ⍵
⍺ ∘.⍺⍺ ⍫ ⍵ => (⍬⍴⍺)⍺⍺ ⍫ ((⍴⍴⍺)↓⍴⍵)⍴⍵
example:
1 2 3∘.+invs 1 2 3 ∘.+ 4 5 6
4 5 6
Examples:
×\invs 1 2 6 24 120 ⍝ inverse scan.
1 2 3 4 5
↓invs ↓2 5⍴'helloworld' ⍝ inverse of split is mix.
hello
world
○ ○invs 1 2 3 4 ⍝ pi times.
1 2 3 4
1 1 0 0 =invs 1 0 1 0 ⍝ = ⍫ on boolean vector.
1 0 0 1
(1 1)(0 0)≠invs(1 0)(1 0) ⍝ ≠ ⍫ on nested boolean array.
0 1 1 0
2 2 2⊥invs 5 ⍝ ⊥ ⍫ with vector left argument.
1 0 1
⍳invs 1 2 3∘.,1 2 3 4 ⍝ ⍳ ⍫ on nested array.
3 4
mat vec ⍝ small matrix and vector.
4 4 1 2 5 6
8 1 1
1 2 5
vec ≡ ⌹∘mat(⌹∘mat)invs vec ⍝ inverse of matrix divide.
1
+⍀∘(⌽¨)∘⍳invs +⍀(⌽¨)⍳2 2 ⍝ inverse with compound operand.
2 2
f2c←(÷∘1.8)∘(-∘32) ⍝ Fahrenheit to Celsius conversion.
f2c (32 212)(¯40 ¯459.4)
0 100 ¯40 ¯273
c2f←f2c invs ⍝ Celsius to Fahrenheit conversion.
c2f (0 100)(¯40 ¯273)
32 212 ¯40 ¯459.4
1 2 3∘.×invs 1 2 3∘.×4 5 6 ⍝ inverse of outer product.
4 5 6
1 2 3 4+[2]invs 3 4⍴⍳12 ⍝ inverse of scalar function with axes.
0 0 0 0
4 4 4 4
8 8 8 8
1 0 1 0 1/[1]invs 3 3⍴⍳9 ⍝ inverse of replicate with axes.
1 2 3
0 0 0
4 5 6
0 0 0
7 8 9
⍝ For more examples, see: →inverse←.
See also: inverse invr pow
Back to: contents
Back to: Dyalog APL
Trouble seeing APL font?