Set difference

53 views
Skip to first unread message

Steve Graham

unread,
Feb 11, 2020, 7:49:51 AM2/11/20
to Kona Users
In J, you can calculate the set difference as such:

   'a b c d ' -. ' '

abcd


   i. 10

0 1 2 3 4 5 6 7 8 9


(i.10) -. 2 3 5 7

0 1 4 6 8 9


Is there anything similar in Kona?


Thanks, Steve

Kevin Lawler

unread,
Feb 11, 2020, 8:42:28 AM2/11/20
to kona...@googlegroups.com
i think these are the reserved verbs _dv and _dvl

speaking as apls we can accomplish this using "x[where not x in y]",
ie, create a linear boolean list of presence of x in y, then negate it
and index x on it.

this is one of several paths. on this path the primary optimization
point is "x in y" which is voluminous in scope. depends on type,
attribute, ...

secondarily you can optimize "A. index B. where C. not" on the boolean list
> --
> You received this message because you are subscribed to the Google Groups "Kona Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to kona-user+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/kona-user/2f29ee99-c122-4494-a9b4-e8a100632152%40googlegroups.com.

Kevin Lawler

unread,
Feb 11, 2020, 8:55:30 AM2/11/20
to kona...@googlegroups.com
kona is using

#define __dv "{x _dvl ,y}"
#define __dvl "{x@&(#y)=y?/:x}"

this is just a more awkward formulation of the previous.

y?/:x is find each of x in y, return size of the list if not found (a
kludge), so comparing for equality with this list size ((#y)=) gives
you the negated boolean list as before. the rest is the same

"?/:" adds another level of indirection before you can optimize `in`.
also backwards...?

Steve Graham

unread,
Feb 11, 2020, 9:15:46 AM2/11/20
to Kona Users
Thanks for these, Kevin.  Steve


On Tuesday, February 11, 2020 at 5:55:30 AM UTC-8, Kevin wrote:
kona is using

#define __dv    "{x _dvl ,y}"
#define __dvl   "{x@&(#y)=y?/:x}"

this is just a more awkward formulation of the previous.

y?/:x is find each of x in y, return size of the list if not found (a
kludge), so comparing for equality with this list size ((#y)=) gives
you the negated boolean list as before. the rest is the same

"?/:" adds another level of indirection before you can optimize `in`.
also backwards...?


On Tue, Feb 11, 2020 at 7:42 AM Kevin Lawler <kevin...@gmail.com> wrote:
>
> i think these are the reserved verbs _dv and _dvl
>
> speaking as apls we can accomplish this using "x[where not x in y]",
> ie, create a linear boolean list of presence of x in y, then negate it
> and index x on it.
>
> this is one of several paths. on this path the primary optimization
> point is "x in y" which is voluminous in scope. depends on type,
> attribute, ...
>
> secondarily you can optimize  "A. index B. where C. not" on the boolean list
>
> On Tue, Feb 11, 2020 at 6:49 AM Steve Graham
> <solitary....@gmail.com> wrote:
> >
> > In J, you can calculate the set difference as such:
> >
> >    'a b c d ' -. ' '
> >
> > abcd
> >
> >
> >    i. 10
> >
> > 0 1 2 3 4 5 6 7 8 9
> >
> >
> > (i.10) -. 2 3 5 7
> >
> > 0 1 4 6 8 9
> >
> >
> > Is there anything similar in Kona?
> >
> >
> > Thanks, Steve
> >
> > --
> > You received this message because you are subscribed to the Google Groups "Kona Users" group.
> > To unsubscribe from this group and stop receiving emails from it, send an email to kona...@googlegroups.com.

Kevin Lawler

unread,
Feb 11, 2020, 10:33:18 AM2/11/20
to kona...@googlegroups.com
other top-level optimizations for setminus exist. eg, if you know the
lists are sorted and the ends don't overlap then there is an O(1)
algo. just return x. but (if I remember) the core complexity is
contained in "x in y", where the bulk handling of element presence
occurs.

there are other entanglements with setminus. "setminus" is probably
not an apt descriptor, since, for instance it is desirable for the
operation to be order-preserving, and there is a certain cost to doing
so. (I think I proposed the name "except".) beyond that, handling of
duplicates is desirable, as implied.

On Tue, Feb 11, 2020 at 8:15 AM Steve Graham
> To unsubscribe from this group and stop receiving emails from it, send an email to kona-user+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/kona-user/aa832bf0-0119-48ff-80c9-bc444f4c1d3f%40googlegroups.com.

Steve Graham

unread,
Feb 11, 2020, 5:16:04 PM2/11/20
to Kona Users
I started using Nils Holm's array language, Klong, and frequently solve Programming Praxis problems with it.

I came up with this:

word@&{~" "=$x}'word::" Programming Praxis "

Nils suggested something like this: 

word@&{1=x}'#'=(!#word),word?" "

Do you use Kona in a commercial setting?
Reply all
Reply to author
Forward
0 new messages