Let us compare three, delfromend, dfe and dfm0yx, fixed versions [0, 1, 2
and 3] of the requested verb.
Their linear representations are respectively,
,. 5!:5@:<&.> ;:'delfromend dfe dfm0yx'
┌───────────────────────────────────────────────────────────────────┐
│([ #~ (i.~ (] - {) /:@/:)@:[ >: ([ i.~ ~.@:]) { 0 ,~ #/.~@:])~&.:|.│
├───────────────────────────────────────────────────────────────────┤
│] #~ #@[ = #@[ ({. i.&(,. (i:~ (] - {) /:@/:)) }.) [ i. , │
├───────────────────────────────────────────────────────────────────┤
│([ {~ [: ([ i. -.)&>/ ,&# <@$"0 1 [ /:@/:"1@i. , ,: ,~)~&.|. │
└───────────────────────────────────────────────────────────────────┘
Do they produce the same results?
same=. ((<2;~":0)`((*./)@:(-:/\))`) (`:6) (assert@:)
'cabd' (delfromend ; dfe ; dfm0yx)same 'cbaab'
'aaaa' (delfromend ; dfe ; dfm0yx)same 'cbaab'
(,<'a') (delfromend ; dfe ; <@:dfm0yx)same ;/ 'cbaab'
'aba' (delfromend ; dfe ; dfm0yx)same 'cbaaaba'
Apparently, they do. How do they perform with some big arguments?
stp=. ([ ((<;._1 '|Sentence|Space|Time|Space * Time') , (, */&.:>@:(1
2&{))@:(] ; 7!:2@:] ; 6!:2)&>) (10{a.) -.&a:@:(<;._2@,~) ]) ".@:('0 : 0'"_)
X=. 1111$'aba' [ Y=. 1111$ 'cbaaaba'
X (delfromend ; dfe ; dfm0yx)same Y
stp 666
X delfromend Y
X dfe Y
X dfm0yx Y
)
┌──────────────┬──────┬───────────┬────────────┐
│Sentence │Space │Time │Space * Time│
├──────────────┼──────┼───────────┼────────────┤
│X delfromend Y│92160 │5.00222e_5 │4.61004 │
├──────────────┼──────┼───────────┼────────────┤
│X dfe Y│182400│0.000137779│25.1309 │
├──────────────┼──────┼───────────┼────────────┤
│X dfm0yx Y│210944│4.04661e_5 │8.53609 │
└──────────────┴──────┴───────────┴────────────┘
X=. 111111$'aba' [ Y=. 111111$ 'cbaaaba'
X (delfromend ; dfe ; dfm0yx)same Y
stp 66
X delfromend Y
X dfe Y
X dfm0yx Y
)
┌──────────────┬────────┬──────────┬────────────┐
│Sentence │Space │Time │Space * Time│
├──────────────┼────────┼──────────┼────────────┤
│X delfromend Y│5511168 │0.00354605│19542.9 │
├──────────────┼────────┼──────────┼────────────┤
│X dfe Y│11536512│0.0286847 │330922 │
├──────────────┼────────┼──────────┼────────────┤
│X dfm0yx Y│13371392│0.0104728 │140035 │
└──────────────┴────────┴──────────┴────────────┘
References
[0] [Jprogramming] challenge: dyad -. but removing the number of copies of
x in y
[email protected] Mon, 25 Jul 2016
http://www.jsoftware.com/pipermail/programming/2016-July/045523.html
[1] [Jprogramming] challenge: dyad -. but removing the number of copies of
x in y
[email protected] Mon, 25 Jul 2016
http://www.jsoftware.com/pipermail/programming/2016-July/045522.html
[2] [Jprogramming] challenge: dyad -. but removing the number of copies of
x in y
[email protected] Mon, 25 Jul 2016
http://www.jsoftware.com/pipermail/programming/2016-July/045526.html
[3] [Jprogramming] challenge: dyad -. but removing the number
[email protected] Tue, 26 Jul 2016
http://www.jsoftware.com/pipermail/programming/2016-July/045527.html
On Mon, Jul 25, 2016 at 5:52 PM, Louis de Forcrand <[email protected]> wrote:
> Hi,
>
> My solution is based heavily on this:
> http://www.sudleyplace.com/APL/AnatomyOfAnIdiom.ahtml <
> http://www.sudleyplace.com/APL/AnatomyOfAnIdiom.ahtml>
>
> dfm0=: [ {~ [: ([ i. -.)&>/ ,&# <@$"0 1 [ /:@/:"1@i. , ,: ,~
> dfm1=: [: ; {."1@-.&(,&<"_1 +/@(* +/\"1)@=)
> x=: 'cabd' [ y=: 'cbaab'
>
> x (dfm0 ,: dfm1)~ y NB. uses same argument order as -.
> ab
> ab
> 18 54 (dfm0 ,: dfm1)&q: 54 18
> 0
> 0
>
> 3
> 3
> 'aaaa' (dfm0 ,: dfm1)~ 'cbaab'
> cbb
> cbb
>
> The version from Sudley "labels" the elements as follows:
>
>
> a b a c b a ; b a a b a a c Note how the first a is 0
> 0 4 1 6 5 2 ; 4 0 1 5 2 3 6 in both arguments, the first
> b is 4, etc.
>
> It then does usual set difference -. and proceeds to reindexing into the
> left argument.
>
> The second version is slightly slower but perhaps easier to understand:
> You can imagine taking each element of each argument and
> giving it a subscript equal to the number of elements which
> are equal to it and appear before it:
>
> a b a c b a ; b a a b a a c
> 0 0 1 0 1 2 ; 0 0 1 1 2 3 0
>
> It now suffices to remove the right argument from the left using -. and
> remove the
> subscripts from the result.
>
> The second method involves boxed searching under the hood, which takes
> slightly
> longer than a simple search between two integer lists. Thus the first
> method is
> slightly faster.
>
> 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