An alternative skeleton for IS
IS1 =: (,&< ((] (] #~ [ e.~ {."1@]) 1 {:: [) ; ] (] #~ [ e.~ {."1@]) 0 {:: [)
{."1@[ -. -.&:({."1))&(({. , #)/.~)&(/:~)
1 2 2 4 IS1 4 2 2 4 3 5
│2 2│2 2│
│4 2│4 1│
IS produces equal number of rows from each side, sorting each side first, also
ensures that each table is in same order.
and, it looks promissing in timing (806)
timespacex 'a IS a+499999'
0.363648 4.62554e8
so replacing ;
IS =: (,&< ((] (] #~ [ e.~ {."1@]) 1 {:: [) ({."1@[ #~ <.&:({:"1)) ] (] #~ [
e.~ {."1@]) 0 {:: [) {."1@[ -. -.&:({."1))&(({. , #)/.~)&(/:~)
timespacex 'a IS a+499999'
0.401744 5.36873e8
# a IS a+49999
7813188
________________________________
From: R.E. Boss <[email protected]>
To: "[email protected]" <[email protected]>
Sent: Tuesday, October 30, 2018 5:46 AM
Subject: [Jprogramming] Intersection and Union of (multi)sets
IMO we should interpret the intersection and the union of two (multi)sets (sets
X with X >:&# ~.X) in the same way as is done by the GCD and the LCM of two
numbers.
So for two numbers N and M with (multi)sets of primefactors A and B, we should
have (N +. M) = */(A IS B) and (N *. M) = */ (A UN B), with IS=intersection and
UN = union of the (multi)sets A and B.
Obviously we require (A IS B) =&(/:~) B IS A and also (A UN B) =&(/:~) B UN A
for all (multi)sets A and B.
E.g.
1 2 3 3 3 IS 3 3 3 3 3 4 5 6
3 3 3
1 2 3 3 3 UN 3 3 3 3 3 4 5 6
1 2 3 3 3 3 3 4 5 6
What are elegant and efficient J-definitions for IS and UN?
I have constructed
UN_reb=: ([:(~.@{.#~ {. >.//.{:) |:@,&(({.,#)/.~))
and
IS_reb=: ([:(~.@{.#~ {. <.//.{:) ([|:@, ],~ 0,.~ -.~&:({."1),
-.&:({."1))&(({. , #)/.~))
1 2 3 3 3 UN_reb 3 3 3 3 3 4 5 6
1 2 3 3 3 3 3 4 5 6
1 2 3 3 3 IS_reb 3 3 3 3 3 4 5 6
3 3 3
1 2 3 3 3 UN_reb~ 3 3 3 3 3 4 5 6
3 3 3 3 3 4 5 6 1 2
1 2 3 3 3 IS_reb~ 3 3 3 3 3 4 5 6
3 3 3
a=: 1e7?.@#1e6
ts'a UN_reb a+499999'
0.76631908 4.6996013e8
#a UN_reb a+49999
12186812
ts'a IS_reb a+499999'
0.76073743 3.3554592e8
#a IS_reb a+49999
7813188
R.E. Boss
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm