I haven't found more existing inverses, although some of them would be nice to 
have as primitive inverses.
While it is easy to assign an obverse to a primitive, some of the ones I listed 
can't be made to work using :. .
They would have to use trains, like ($ $ u@,) as an obverse to ravel, because 
they technically don't have inverses since they aren't bijective. That is, 
given a random result R, it is impossible to reliably link it to one and only 
one original argument.
,^:_1 R isn't very useful (($ $ ]); would only really be useful with &.
For example, m |.&., y <--> m ($@] $ |.&,) y could be useful:

y=: i.5 5
m=: 2
m |.&.(, :.(($M)&$)) M NB. m |.&.,
 2  3  4  5  6
 7  8  9 10 11
12 13 14 15 16
17 18 19 20 21
22 23 24  0  1

This works because it could be rewritten as (m&|.)&.... but the theoretical 
version using &. is much cleaner.
In the case of {, I imagine special code could speed up execution.

Louis

Sent from my iPhone

> On 03 Mar 2016, at 02:40, Henry Rich <[email protected]> wrote:
> 
> The page at
> 
> http://code.jsoftware.com/wiki/Vocabulary/Inverses#Obverses_Of_Primitives
> 
> has a good bit on what primitives have inverses, but it seems that you have 
> found some combinations not listed there.  Would you be willing to add what 
> you have found to that page?
> 
> Henry Rich
> 
>> On 3/2/2016 7:39 PM, Louis de Forcrand wrote:
>> The way J handles inverses to functions is quite unique and, while not
>> always very useful, can lead to compact but very descriptive code:
>> 
>> +/&.:*:    NB. distance
>> +&.^.    NB. multiplication
>> u&.(a.&i.)    NB. u applied to y’s indices in a., then indexed out of a.
>> etc.
>> 
>> However, some less easily invertible functions, such as , (ravel), {: and 
>> related,
>> A., m&{ , and others, don’t have a monadic inverse because they are “lossy” 
>> functions,
>> in that there is no function u such that
>> y -: u@v y    NB. where v is a lossy function
>> for an arbitrary y.
>> 
>> However, while there are other lossy functions which I have not cited, the 
>> ones I
>> did are particular in that they are invertible with trains of related dyadic 
>> functions:
>> 
>> u&., y    <—>    ($ $ u@,) y
>> u&.(m&{.) y    <—>    (m&}. , u@(m&{.)) y    NB. extends to others like }. 
>> etc.
>>                                    NB. although {. already has an inverse
>> u&.A. y    <—>    (A.~ u@A.) y
>> 
>> These are all simply “cosmetic”, in that you can obviously write them out
>> by hand, but then again, &. is basically cosmetic too. Nevertheless, it leads
>> to more elegant and concise code (and sometimes leads to new ways of
>> thinking about a problem). However, one inverse that could possibly
>> lead to (possibly big?) gains in speed with special code would be:
>> 
>> u&.(m&{) y    <—>    (m&}~ u@(m&{)) y
>> 
>> This might already be implemented for the fork case.
>> I’ve checked, and m&{ already has an inverse, although I don’t see what it’s
>> useful for.
>> 
>> On a side note, I’ve noticed that <;.1 has an inverse according to b._1, but
>> using it yields a nonce error (which means it hasn’t been implemented yet,
>> right?). <;._1@(m&,) could be recognised as a whole as well, so that
>> u&.(<;._1@(m&,)) y        <—>    ({. ;@, m ,&.> }.)@u@(<;._1@(m&,))
>> Or it could be added as an obverse to the cut standard library verb.
>> 
>> Again, this can all be done by hand, of course.
>> 
>> Louis
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
> 
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to