Tacitly...
". noun define -. CRLF
CombBit=.
>@:(,.&.>/)@:(<@:#:"1)@:(3&({::))@:(<@:(>@:(,.&.>/)@:(3&({::))) 3}
])@:((<@:(2&({::) 23 b.&.> ,.&.>/\.@:(3&({::))) 3} ])@:(<@:((((_1
) 33 b. 0 { ]) , [: (2 (((_2) 32 b. 2 | [) 23 b. (_1) 33 b. ])/\ ]
) ])&.>@:(3&({::))`(((_1) 33 b. 1 {. ])&.>@:(3&({::)))@.(1 = 5&({:
:))) 3} ])^:(0&({::)))@:(<@:((1&({::) - 0&({::)) (([ $ <@:(0 $~ 0
,~ ])) , <@:(0 $~ 1 ,~ ])) 5&({::)) 3} ])@:(<@:(<"_1@:(<.@:(6&({::
) % 4&({::)) |."0 1 (0 $~ 1 -~ 5&({::)) (,"1 0) 2 ^&.x: 4&({::) |
6&({::))) 2} ])@:(<@:(1&({::) - >:@:i.@:>:@:(1&({::) - 0&({::))) 6
} ])@:(<@:(>.@:(1&({::) % 4&({::))) 5} ])@:(<@:(63"_) 4} ])@:(,&(<
;._1 ' K Z N L P')@:;)
)
stp 111
2 combbit 4
2 CombBit 4
)
┌─────────────┬─────┬─────────────┬────────────┐
│Sentence │Space│Time │Space * Time│
├─────────────┼─────┼─────────────┼────────────┤
│ 2 combbit 4│10624│4.90142688e_5│0.520727591 │
├─────────────┼─────┼─────────────┼────────────┤
│ 2 CombBit 4│5760 │3.55993312e_5│0.205052148 │
└─────────────┴─────┴─────────────┴────────────┘
stp 3
12 combbit 24
12 CombBit 24
)
┌───────────────┬─────────┬───────────┬────────────┐
│Sentence │Space │Time │Space * Time│
├───────────────┼─────────┼───────────┼────────────┤
│ 12 combbit 24│134227712│0.149703502│20094358.6 │
├───────────────┼─────────┼───────────┼────────────┤
│ 12 CombBit 24│134222848│0.146431023│19654388.9 │
└───────────────┴─────────┴───────────┴────────────┘
stp 2
60 combbit 64
60 CombBit 64
)
┌───────────────┬─────────┬───────────┬────────────┐
│Sentence │Space │Time │Space * Time│
├───────────────┼─────────┼───────────┼────────────┤
│ 60 combbit 64│135275520│0.599563054│81106203.9 │
├───────────────┼─────────┼───────────┼────────────┤
│ 60 CombBit 64│152047488│0.595164851│90493320.6 │
└───────────────┴─────────┴───────────┴────────────┘
NB. Using the J Wicked Toolkit (beware of line-wrapping)...
or=.23 b.
lshift=.33 b.
lrot=. 32 b.
shift=. 2 ((_2 lrot 2 | [) or _1 lshift ])/\ ]
'X Y K Z N L P'=. 7 Fetch
update=. [tv
Z (((((_1 lshift 0 { ]) , [: shift ])&.>) o Z)`(((_1 lshift 1 {. ])&.>) o
Z)@.(1 = L)) h
Z (K or&.> ,.&.>/\. o Z) h
)
CombBit=. [tv f.
'K Z N L P'local o ;
N ((<:##:_1 (32 b.) 1)"_) h
L (>. o (Y % N)) h
P (Y - >: o i. o >: o (Y - X)) h
K (<"_1 o (<. o (P % N) |."0 1 (0 $~ 1 -~ L) ,"1 0 (2 ^&.x: N | P))) h
Z ((Y - X) (([ $ <@:(0 $~ 0 ,~ ])) , <@:(0 $~ 1 ,~ ])) L) h
update^:X
Z (> o (,.&.>/) o Z) h
(> o (,.&.>/) o (< o #:"1) o Z)
)
66 Wrap 'CombBit'
66 Wrap 'CombBit'
>@:(,.&.>/)@:(<@:#:"1)@:(3&({::))@:(<@:(>@:(,.&.>/)@:(3&({::))) 3}
])@:((<@:(2&({::) 23 b.&.> ,.&.>/\.@:(3&({::))) 3} ])@:(<@:((((_1
) 33 b. 0 { ]) , [: (2 (((_2) 32 b. 2 | [) 23 b. (_1) 33 b. ])/\ ]
) ])&.>@:(3&({::))`(((_1) 33 b. 1 {. ])&.>@:(3&({::)))@.(1 = 5&({:
:))) 3} ])^:(0&({::)))@:(<@:((1&({::) - 0&({::)) (([ $ <@:(0 $~ 0
,~ ])) , <@:(0 $~ 1 ,~ ])) 5&({::)) 3} ])@:(<@:(<"_1@:(<.@:(6&({::
) % 4&({::)) |."0 1 (0 $~ 1 -~ 5&({::)) (,"1 0) 2 ^&.x: 4&({::) |
6&({::))) 2} ])@:(<@:(1&({::) - >:@:i.@:>:@:(1&({::) - 0&({::))) 6
} ])@:(<@:(>.@:(1&({::) % 4&({::))) 5} ])@:(<@:(63"_) 4} ])@:(,&(<
;._1 ' K Z N L P')@:;)
On Tue, Nov 14, 2017 at 11:18 AM, Erling Hellenäs <[email protected]>
wrote:
> Hi all!
>
> This version uses half of the memory, the same as previous combbit.
> Changes marked.
>
> x=:12
> y=:24
> ts'x combbit y'
> 0.126954 1.34228e8
> ts'x combbitOld y'
> 0.111495 1.33655e8
>
> combbit=: 4 : 0
> or=. 23 b.
> lshift=. 33 b.
> lrot=. 32 b.
> shift=. 2 ((_2 lrot 2 | [) or _1 lshift ])/\ ]
> n=. <:##:_1 (32 b.) 1
> l=. >.y%n
> p=. y->:i.>:d=.y-x
> k=. <"_1(<.p%n)|."0 1((l-1)$0),"1 0 [2 ^&.x: n|p
> z=. (d$<(l,0)$0),<(l,1)$0
> for. i.x do.
> if. l=1 do.
> NB. a=. (_1 lshift 1 {. ])&.> z
> z=. (_1 lshift 1 {. ])&.> z
> else.
> NB. a=. ((_1 lshift 0 { ]) , [: shift ])&.> z
> z=. ((_1 lshift 0 { ]) , [: shift ])&.> z
> end.
> NB. b=. ,.&.>/\. a
> z=. ,.&.>/\. z
> NB. z=. k (or)&.> b
> z=. k (or)&.> z
> end.
> NB. z=. >,.&.>/ ([:<#:)"1 >,.&.>/z
> z=. >,.&.>/z
> z=. ([:<#:)"1 z
> z=. >,.&.>/ z
> z
> )
>
> Cheers,
>
> Erling Hellenäs
>
>
> Den 2017-11-14 kl. 16:53, skrev 'Mike Day' via Programming:
>
>> Correction - there is a slight saving in memory! (see my msg below)
>>
>> ts'combbit /3 70' NB. using intermediate arrays "a" and "b"
>>
>> 0.0385736 1.26221e7
>>
>> load 'c:/d/j806/user/comb.ijs'
>>
>> ts'combbit /3 70' NB. replacing z without recourse to "a" or "b"
>>
>> 0.03962 1.12704e7
>>
>>
>> Sorry for slip,
>> Mike
>>
>> On 14/11/2017 15:47, 'Mike Day' via Programming wrote:
>>
>>> Clever.
>>> In looking (again!) for an unboxed version, I've noticed that you
>>> don't need the intermediate arrays, "a" and "b", which look like
>>> a debugging aid.
>>>
>>> You can use z immediately in the two alternative replacements
>>> within the "if l" loop,
>>> eg
>>> z =. ((_1 lshift 1 {. ]))each z NB. for y < word size
>>>
>>> and then
>>> z=.k or each ,.each /\. z
>>>
>>> in the outer "for i" loop.
>>> (I find "each" easier to remember and to read!)
>>>
>>> Having said that, the memory saving seems to be zero!
>>>
>>> Mike
>>>
>>> On 14/11/2017 09:22, Erling Hellenäs wrote:
>>>
>>>> Hi all!
>>>>
>>>> The general version of combbit improved. The comparison is with the
>>>> limited version.
>>>>
>>>> x=:12
>>>> y=:24
>>>> ts'x combbit y'
>>>> 0.125539 2.16831e8
>>>> ts'x combbitOld y'
>>>> 0.107966 1.33655e8
>>>>
>>>> combbit=: 4 : 0
>>>> or=.23 b.
>>>> lshift=.33 b.
>>>> lrot=. 32 b.
>>>> shift=. 2 ((_2 lrot 2 | [) or _1 lshift ])/\ ]
>>>> n=.<:##:_1 (32 b.) 1
>>>> l=.>.y%n
>>>> p=.y->:i.>:d=.y-x
>>>> k=.<"_1(<.p%n)|."0 1((l-1)$0),"1 0 [2 ^&.x: n|p
>>>> z=.(d$<(l,0)$0),<(l,1)$0
>>>> for. i.x do.
>>>> if. l=1 do.
>>>> a=.((_1 lshift 1 {. ]))&.> z
>>>> else.
>>>> a=.((_1 lshift 0 { ]),[:shift ])&.> z
>>>> end.
>>>> b=.,.&.>/\. a
>>>> z=.k (or)&.> b
>>>> end.
>>>> z=.>,.&.>/ ([:<#:)"1 >,.&.>/z
>>>> z
>>>> )
>>>>
>>>> I hit a strange feature:
>>>>
>>>> a=:,:100000000?100000000
>>>> $a
>>>> 1 100000000
>>>> ts'2 */\a'
>>>> 1.03032 3.22123e9
>>>> $2 */\a
>>>> 0 100000000
>>>>
>>>> Even though 2 */\a gives an empty result, it takes a considerable time
>>>> to execute.
>>>>
>>>> Cheers,
>>>>
>>>> Erling Hellenäs
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> Den 2017-11-14 kl. 06:12, skrev Jose Mario Quintana:
>>>>
>>>>> I could not resist... :)
>>>>>
>>>>> ". noun define -. CRLF
>>>>>
>>>>> CombBit=.
>>>>>
>>>>> @:(,.&.>/)@:((-@:(5&({::)) {. -@:(4&({::) | 1&({::)) , <.@:(1&({:
>>>>>>
>>>>> :) % 4&({::)) # 4&({::)) <@:([ {."1 #:@:])"0 1 >@:(,.&.>/)@:(3&({:
>>>>> :)))@:((<@:(2&({::) 23 b.&.> ,.&.>/\.@:((2 (((_2) 32 b. 2 #: [) 23
>>>>> b. (_1) 33 b. ])/\ ])@:(0 , ])&.>)@:(3&({::))) 3} ])^:(0&({::)))@
>>>>> :(<@:((1&({::) - 0&({::)) (([ $ <@:(0 $~ 0 ,~ ])) , <@:(0 $~ 1 ,~
>>>>> ])) 5&({::)) 3} ])@:(<@:(<"_1@:(<.@:(6&({::) % 4&({::)) |."0 1 (0
>>>>> $~ 1 -~ 5&({::)) (,"1 0) 2 ^&.x: 4&({::) #: 6&({::))) 2} ])@:(<@:(
>>>>> 1&({::) - >:@:i.@:>:@:(1&({::) - 0&({::))) 6} ])@:(<@:(>.@:(1&({::
>>>>> ) % 4&({::))) 5} ])@:(<@:(63"_) 4} ])@:(,&(<;._1 ' K Z N L P')@:;)
>>>>>
>>>>> )
>>>>>
>>>>> A performance sample is,
>>>>>
>>>>> stp 111
>>>>>
>>>>> 2 combbit 4
>>>>> 2 CombBit 4
>>>>>
>>>>> )
>>>>> ┌───────────┬─────┬─────────────┬────────────┐
>>>>> │Sentence │Space│Time │Space * Time│
>>>>> ├───────────┼─────┼─────────────┼────────────┤
>>>>> │2 combbit 4│13056│3.45637285e_5│0.451264039 │
>>>>> ├───────────┼─────┼─────────────┼────────────┤
>>>>> │2 CombBit 4│5888 │2.24359098e_5│0.132102637 │
>>>>> └───────────┴─────┴─────────────┴────────────┘
>>>>>
>>>>> stp 2
>>>>>
>>>>> 60 combbit 64
>>>>> 60 CombBit 64
>>>>>
>>>>> )
>>>>> ┌─────────────┬─────────┬───────────┬────────────┐
>>>>> │Sentence │Space │Time │Space * Time│
>>>>> ├─────────────┼─────────┼───────────┼────────────┤
>>>>> │60 combbit 64│178304896│0.774408636│138080851 │
>>>>> ├─────────────┼─────────┼───────────┼────────────┤
>>>>> │60 CombBit 64│178297088│0.751941586│134068995 │
>>>>> └─────────────┴─────────┴───────────┴────────────┘
>>>>>
>>>>> The verb CombBit was produced using the J Wicked Toolkit as follows
>>>>> (beware
>>>>> of line-wrapping),
>>>>>
>>>>> or=.23 b.
>>>>> lshift=.33 b.
>>>>> lrot=. 32 b.
>>>>> shift=. 2 ((_2 lrot 2 #: [) or _1 lshift ])/\ ]
>>>>>
>>>>> 'X Y K Z N L P'=. 7 Fetch
>>>>>
>>>>> CombBit=. [tv f.
>>>>> 'K Z N L P'local o ;
>>>>>
>>>>> N ((<:##:_1 (32 b.) 1)"_) h NB. n=.<:##:_1 (32 b.) 1
>>>>> L (>. o (Y % N)) h NB. l=.>.y%n
>>>>> P (Y - >: o i. o >: o (Y - X)) h NB. y->:i.>:d=.y-x
>>>>> K (<"_1 o (<. o (P % N) |."0 1 (0 $~ 1 -~ L) ,"1 0 (2 ^&.x: N #:
>>>>> P))) h
>>>>> NB. <"_1(<.p%n)|."0 1((l-1)$0),"1 0 [2 ^&.x: n#:p
>>>>> Z ((Y - X) (([ $ <@:(0 $~ 0 ,~ ])) , <@:(0 $~ 1 ,~ ])) L) h
>>>>> NB. z=.((y-x)$<(l,0)$0),<(l,1)$0
>>>>> (Z (K or&.> ,.&.>/\.@:(shift@:(0 , ])&.>)@:Z) h)^:X
>>>>> NB. for. i.x do. z=. k (or)&.> ,.&.>/\. ([:shift 0,])&.> z end.
>>>>> >@:(,.&.>/)@:(((-@:L){. -@:(N | Y) , (<.@:(Y % N))# N) (<@:([ {."1
>>>>> #:@:])"0 1) >@:(,.&.>/)@:Z)
>>>>> NB. >,.&.>/((-l){.-(n|y),(<.y%n)#n) ([:<[{."1[:#:])"0 1 >,.&.>/z
>>>>> )
>>>>>
>>>>> 66 Wrap 'CombBit'
>>>>>
>>>>>> @:(,.&.>/)@:((-@:(5&({::)) {. -@:(4&({::) | 1&({::)) , <.@:(1&({:
>>>>>>
>>>>> :) % 4&({::)) # 4&({::)) <@:([ {."1 #:@:])"0 1 >@:(,.&.>/)@:(3&({:
>>>>> :)))@:((<@:(2&({::) 23 b.&.> ,.&.>/\.@:((2 (((_2) 32 b. 2 #: [) 23
>>>>> b. (_1) 33 b. ])/\ ])@:(0 , ])&.>)@:(3&({::))) 3} ])^:(0&({::)))@
>>>>> :(<@:((1&({::) - 0&({::)) (([ $ <@:(0 $~ 0 ,~ ])) , <@:(0 $~ 1 ,~
>>>>> ])) 5&({::)) 3} ])@:(<@:(<"_1@:(<.@:(6&({::) % 4&({::)) |."0 1 (0
>>>>> $~ 1 -~ 5&({::)) (,"1 0) 2 ^&.x: 4&({::) #: 6&({::))) 2} ])@:(<@:(
>>>>> 1&({::) - >:@:i.@:>:@:(1&({::) - 0&({::))) 6} ])@:(<@:(>.@:(1&({::
>>>>> ) % 4&({::))) 5} ])@:(<@:(63"_) 4} ])@:(,&(<;._1 ' K Z N L P')@:;)
>>>>>
>>>>> It can certainly be simplified, but I will pass. :)
>>>>>
>>>>>
>>>>>
>>>>> On Mon, Nov 13, 2017 at 10:31 AM, Erling Hellenäs <
>>>>> [email protected]>
>>>>> wrote:
>>>>>
>>>>> Hi all!
>>>>>>
>>>>>> A new combbit with the limit lifted. Unfortunately somewhat slower.
>>>>>>
>>>>>> x=:12
>>>>>> y=:24
>>>>>> ts'x combbit y'
>>>>>> 0.213853 2.34326e8
>>>>>> ts'x combbitOld y'
>>>>>> 0.108748 1.33655e8
>>>>>>
>>>>>> combbit=: 4 : 0
>>>>>> or=.23 b.
>>>>>> lshift=.33 b.
>>>>>> lrot=. 32 b.
>>>>>> shift=. 2 ((_2 lrot 2 #: [) or _1 lshift ])/\ ]
>>>>>> n=.<:##:_1 (32 b.) 1
>>>>>> l=.>.y%n
>>>>>> p=.y->:i.>:d=.y-x
>>>>>> k=.<"_1(<.p%n)|."0 1((l-1)$0),"1 0 [2 ^&.x: n#:p
>>>>>> z=.(d$<(l,0)$0),<(l,1)$0
>>>>>> for. i.x do. z=. k (or)&.> ,.&.>/\. ([:shift 0,])&.> z end.
>>>>>>
>>>>>>> ,.&.>/((-l){.-(n|y),(<.y%n)#n) ([:<[{."1[:#:])"0 1 >,.&.>/z
>>>>>>>
>>>>>> )
>>>>>>
>>>>>> Cheers,
>>>>>>
>>>>>> Erling Hellenäs
>>>>>>
>>>>>>
>>>>>>
>>>>>> Den 2017-11-13 kl. 11:37, skrev Raul Miller:
>>>>>>
>>>>>> Hmm... nice.
>>>>>>>
>>>>>>> combbit pulls out way ahead by working with a more compact and fixed
>>>>>>> width representation, which makes sense. You give up being able to do
>>>>>>> things like 3 combbit 100, but that might not be relevant in some
>>>>>>> contexts.
>>>>>>>
>>>>>>> That said, I'd probably put those -: test cases in asserts rather
>>>>>>> than
>>>>>>> running them as readable output. I'd also be tempted to make a few
>>>>>>> other changes. (Most of which I've not included here, for
>>>>>>> comparability purposes.)
>>>>>>>
>>>>>>> Also, of course, when I run this I get different times. But timing
>>>>>>> differences of up to 30% are typical and anything less than a factor
>>>>>>> of 2 isn't really interesting.
>>>>>>>
>>>>>>> x=:5
>>>>>>> y=:10
>>>>>>> 1000 ts 'x comb y'
>>>>>>> 2.7068e_5 50944
>>>>>>> 1000 ts'x combbool y'
>>>>>>> 2.3684e_5 22528
>>>>>>> 1000 ts'x combbit y'
>>>>>>> 1.8143e_5 21376
>>>>>>> 1000 ts'x combbitub y'
>>>>>>> 3.1611e_5 13824
>>>>>>> 1000 ts'x CombBool y'
>>>>>>> 2.1586e_5 14976
>>>>>>> 1000 ts'x CombBit y'
>>>>>>> 1.3287e_5 15232
>>>>>>> 1000 ts'x bitcomb y'
>>>>>>> 1.8703e_5 50688
>>>>>>> 1000 ts'x combboolT y'
>>>>>>> 2.1642e_5 15744
>>>>>>>
>>>>>>> x=:12
>>>>>>> y=:24
>>>>>>> ts 'x comb y'
>>>>>>> 0.705435 9.02647e8
>>>>>>> ts'x combbool y'
>>>>>>> 0.240168 2.82336e8
>>>>>>> ts'x combbit y'
>>>>>>> 0.124814 1.33655e8
>>>>>>> ts'x combbitub y'
>>>>>>> 0.123766 1.17444e8
>>>>>>> ts'x CombBool y'
>>>>>>> 0.234092 2.33133e8
>>>>>>> ts'x CombBit y'
>>>>>>> 0.121827 1.33654e8
>>>>>>> ts'x bitcomb y'
>>>>>>> 1.30437 1.34218e9
>>>>>>> ts'x combboolT y'
>>>>>>> 0.216018 2.33135e8
>>>>>>>
>>>>>>> x=:55
>>>>>>> y=:60
>>>>>>> ts 'x comb y'
>>>>>>> 48.7158 1.40301e10
>>>>>>> ts'x combbool y'
>>>>>>> 5.9218 2.29064e9
>>>>>>> ts'x combbit y'
>>>>>>> 0.829234 6.75567e8
>>>>>>> ts'x combbitub y'
>>>>>>> 0.6971 6.71092e8
>>>>>>> ts'x CombBool y'
>>>>>>> 5.56716 1.71798e9
>>>>>>> ts'x CombBit y'
>>>>>>> 0.765956 6.75566e8
>>>>>>> NB.ts'x bitcomb y' -limit error
>>>>>>> ts'x combboolT y'
>>>>>>> 5.67477 1.71798e9
>>>>>>>
>>>>>>> Thanks,
>>>>>>>
>>>>>>>
>>>>>>> ----------------------------------------------------------------------
>>>>>>
>>>>>> For information about J forums see http://www.jsoftware.com/forum
>>>>>> s.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
>>>>
>>>
>>>
>>> ---
>>> This email has been checked for viruses by Avast antivirus software.
>>> https://www.avast.com/antivirus
>>>
>>> ----------------------------------------------------------------------
>>> 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
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm