The discussion you linked to devolved into, "but it will cut off original length, so not a real inverse" there was also the corner case of i.0 (potential result of I.), fixed imo with: (#/.~@])`(~.@])`(0#~>:@(>./)@])}~`0:@.(0 = #) i.0 0
But, something that didn't come up in the thread is the easily invertible, (I. , #) 0 0 0 3 (I. , #) 0 0 0 1 3 4 as a non lossy conversion of indexes and boolean arrays. Though I support the idea of raw I. inverse being defined. Your verb seems to take great care to check for duplicates, and deal with an unsorted list of indexes. Is it worth considering: 1:`]`(0#~ >:@{:@])}~ 2 4 0 0 1 0 1 1:`]`(0#~ >:@{:@])}~ i.0 0 and then do /:~@:~. on input if it may not be sorted unique? ________________________________ On Wednesday, June 28, 2017, 4:21:03 AM EDT, Marshall Lochbaum <mwlochb...@gmail.com> wrote: All (I.)s used in my post refer to the monad. I meant that the monadic verb given by binding my dyadic verb to a left argument (which must be (i.n) for a large enough n) is a mostly-inverse to (I.). It's probably best to ignore my informal discussion if you plan on implementing this. There's a forum discussion starting at http://www.jsoftware.com/pipermail/general/2006-April/026874.html and I remember but can't find a more recent one that hit most of the same points. Your verb is the right approach except that you've forgotten that monad u`v`w} doesn't work the way you want it to; the correct implementation is regrettably (#/.~@])`(~.@])`(0#~>:@(>./)@])}~ Adding the above as an inverse to I. is very easy, but it would also be valuable to be able to specify the length of the result. There are some suggestions in this thread, which I haven't read fully. Allowing the fit conjunction to apply to a derived verb would probably be difficult. http://www.jsoftware.com/pipermail/programming/2010-September/020281.html (I'm kind of surprised I remembered to look for this thread at all, given that I state in it that I'm a Windows user!) Marshall On Tue, Jun 27, 2017 at 07:02:59PM -0400, Henry Rich wrote: > I see how (#/.~@])`(~.@])`[}is an inverse of monad I., but I don't see > how it is a left inverse of (presumably dyad) I. . Please explain. > > Also, it would be a problem to have a dyadic inverse of a monad, no? > Duals wouldn't work. Changing the suggestion to > > (#/.~)`~.`(0#~>:@(>./))} > > would address that. > > Henry Rich > > > > An efficient way to turn a list of intervals into a list of > > number-of-intervals-containing uses an obverse of monad (I.), which I am > > increasingly coming to believe is a major feature missing from J. To > > wit: > > > > x =. 4 7 2 4 1 7 8 > > (10$0) (#/.~@])`(~.@])`[}"1 x > > 0 1 1 0 2 0 0 2 1 0 > > I. (10$0) (#/.~@])`(~.@])`[}"1 x > > 1 2 4 4 7 7 8 > > (/:~x) -: I. (10$0) (#/.~@])`(~.@])`[}"1 x > > 1 > > > > The verb ((#/.~@])`(~.@])`[}) with an appropriate left argument is an > > left inverse to I. ignoring trailing zeros, and a right inverse to I. > > ignoring ordering. It counts, for each number in (i.n) where n is the > > length of the left argument, how many elements on the right are equal to > > it. To get our interval count, we just take this count for the starts of > > intervals, subtract the counts for ends of intervals, and do a running > > sum: > > > > > > --- > This email has been checked for viruses by AVG. > http://www.avg.com > > ---------------------------------------------------------------------- > 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