Re: [Jprogramming] APL Exercises

2017-12-02 Thread Linda Alvord
:'x * ([:([:%: +/)*:) y' (2 g 1 2 3)-:2 g2 1 2 3 1 Linda -Original Message- From: Programming [mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Henry Rich Sent: Saturday, December 2, 2017 1:29 PM To: programm...@jsoftware.com Subject: Re: [Jprogramming] APL E

Re: [Jprogramming] APL Exercises

2017-12-02 Thread Roger Hui
You can use the verb display to see what the interpreter thinks of your input verb. For example, having chosen the box & tree & parens display form, I get: y=: 3 ,./^:2@(*/)^:yNB. input ┌───┬──┬─┐ │┌─┬─┬─┐│^:│3│ ││┌──┬──┬─┐│@│┌─┬─┐││ │ │ │││┌──┬

Re: [Jprogramming] APL Exercises

2017-12-02 Thread Raul Miller
That looks correct - you can always test your expressions - if the result changes you know you've done it wrong. Personally, though, it's difficult for me to imagine how an inverse of a ;._3 adverb would work. Logically, I suppose, you might be looking for something that tessellates the result (wh

Re: [Jprogramming] APL Exercises

2017-12-02 Thread Henry Rich
There are no exceptions, only rules: see http://code.jsoftware.com/wiki/Vocabulary/Modifiers#Grouping_And_Order_Of_Execution Henry Rich On 12/2/2017 1:02 PM, Andrew Dabrowski wrote: On 12/02/2017 02:17 AM, Roger Hui wrote: SC =: 3 : '(3 3$4>i.5) ,./^:2@(*/)^:y ,.1' SC confuses me.  I would

Re: [Jprogramming] APL Exercises

2017-12-02 Thread Andrew Dabrowski
On 12/02/2017 02:17 AM, Roger Hui wrote: SC =: 3 : '(3 3$4>i.5) ,./^:2@(*/)^:y ,.1' SC confuses me. I would have thought that (3 3$4>i.5) (*/)^:y ,.1 The left operand of the power operator ^: is ,./^:2@(*/) . Oh, I parsed it as (3 3$4>i.5) (,./^:2) @ ((*/)^:y) ,.1 but it should be (3 3$

Re: [Jprogramming] APL Exercises

2017-12-02 Thread Roger Hui
Interesting. In Mathematica, how easy is it to use the various Cantor solutions to do the following? Cantor =: 3 : ', 1 0 1 */^:y ,1' (+/%#)@Cantor"0 i.4 5 1 0.67 0.440.2962960.197531 0.131687 0.0877915 0.0585277 0.0390184 0.0260123 0.0173415 0.01156

Re: [Jprogramming] APL Exercises

2017-12-02 Thread Murray Eisenberg
AOn 1 Dec 2017 05:33:02 +,"Dabrowski, Andrew John" mailto:dabro...@indiana.edu>> wrote: > > On 11/29/2017 11:40 PM, Roger Hui wrote: >> 2.5 Cantor Set >> >> Write a function to compute the Cantor set of order n, n>:0. >> >>Cantor 0 >> 1 >>Cantor 1 >> 1 0 1 >>Cantor 2 >> 1 0 1 0 0

Re: [Jprogramming] APL Exercises

2017-12-02 Thread Henry Rich
Here, integer is no worse than Boolean because the first execution is y * 3. Henry RIch On 12/2/2017 2:31 AM, Arie Groeneveld wrote: But in this case:    20 (6!:2) ',@((,.>:)@*&3)^:(]`(1"_)) 18' 0.0604128    20 (6!:2) ',@((,.>:)@*&3)^:(]`1:) 18' 0.057749 ??? Op 02-12-17 om 04:23 schreef Hen

Re: [Jprogramming] APL Exercises

2017-12-02 Thread Henry Rich
You're right - I guess I must have changed that somewhere along the way.  The older version I was running produced integer, as did J6.02.  But I reckon my diagnosis is right. Henry Rich On 12/2/2017 6:56 AM, bill lam wrote: 1: already produced Boolean. datatype 1: 0 boolean JVERSIO

Re: [Jprogramming] APL Exercises

2017-12-02 Thread Henry Rich
Wise counsel. Henry Rich On 12/1/2017 10:38 PM, Raul Miller wrote: I don't think we should be shooting for always. If you need a complex 1, for example, it can sometimes make sense to pre-generate a complex 1 to avoid conversion costs. But using the most compact form does seem to be consistent

Re: [Jprogramming] APL Exercises

2017-12-02 Thread bill lam
1: already produced Boolean. datatype 1: 0 boolean JVERSION Engine: j806/j64/android Beta: commercial/2017-08-24T10:38:29 Library: 8.06.05 J Android: 1.0.16/23 Platform: Android 64 (arm64-v8a) Installer: unknown InstallPath: /storage/emulated/0/Android/data/com.jsoftware.j.android/files Co

Re: [Jprogramming] APL Exercises

2017-12-02 Thread Linda Alvord
┌─ 1 0 1 ── @ ─┤ ┌─┼─ / ─ * │ │ └─ ] └─ ^: ─┤ │ ┌─ ] └─┴─ 1: Linda -Original Message- From: Programming [mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Henry Rich Sent: Friday, December 1, 2017 10:23 PM To: programm...@jsoftware.com Subject: Re: [Jprogramming] APL Exercises I see what'

Re: [Jprogramming] APL Exercises

2017-12-01 Thread Arie Groeneveld
But in this case:    20 (6!:2) ',@((,.>:)@*&3)^:(]`(1"_)) 18' 0.0604128    20 (6!:2) ',@((,.>:)@*&3)^:(]`1:) 18' 0.057749 ??? Op 02-12-17 om 04:23 schreef Henry Rich: I see what's happening.  1"_ produces a Boolean, while 1: produces an integer.  In this case the Boolean is better.  I'm not s

Re: [Jprogramming] APL Exercises

2017-12-01 Thread Roger Hui
>> SC =: 3 : '(3 3$4>i.5) ,./^:2@(*/)^:y ,.1' > > SC confuses me. I would have thought that > > (3 3$4>i.5) (*/)^:y ,.1 The left operand of the power operator ^: is ,./^:2@(*/) . > I claim the examples in my message unambiguously specify the extended H > problem. More details (and solutions) ca

Re: [Jprogramming] APL Exercises

2017-12-01 Thread Daniel Lyons
> On Dec 1, 2017, at 10:13 PM, Dabrowski, Andrew John > wrote: > > I don't want to sound like a shill for Mathematica, but it's a great > package with a great ecosystem; it's just obscenely expensive. It's really beautiful. I have seen videos about it, I love the notebook idea (Jupyter is

Re: [Jprogramming] APL Exercises

2017-12-01 Thread Dabrowski, Andrew John
On 12/01/2017 01:20 AM, Roger Hui wrote: > Cantor =: 3 : ', 1 0 1 */^:y ,1' > SC =: 3 : '(3 3$4>i.5) ,./^:2@(*/)^:y ,.1' Nice!  The first algorithm can easily be implemented in Mathematica with cantor2[n_] := Nest[Flatten@Outer[Times, #, {1, 0, 1}] &, {1}, n] Mathematica also allows many solu

Re: [Jprogramming] APL Exercises

2017-12-01 Thread Raul Miller
I don't think we should be shooting for always. If you need a complex 1, for example, it can sometimes make sense to pre-generate a complex 1 to avoid conversion costs. But using the most compact form does seem to be consistent with the rest of the system. Thanks, -- Raul On Fri, Dec 1, 2017

Re: [Jprogramming] APL Exercises

2017-12-01 Thread Henry Rich
I see what's happening.  1"_ produces a Boolean, while 1: produces an integer.  In this case the Boolean is better.  I'm not sure whether it always would be; what do you think? Henry Rich On 12/1/2017 9:12 AM, Raul Miller wrote: Huh... I can reproduce that 10x speed difference: timespac

Re: [Jprogramming] APL Exercises

2017-12-01 Thread Roger Hui
Andrew Dabrowski: Since you are a self-confessed "newbie", in my original code I tried to be as straightforward as I can make it. The follow-up posts by others is typical of what happens in this community/forum. I guess it's one of the features of J/APL -- people study different ways of solving

Re: [Jprogramming] APL Exercises

2017-12-01 Thread Arie Groeneveld
For those interested. The relation with A005836 is: e.g. A005836=:,@((,.>:)@*&3)^:(]`(0"_))    ts 'Q=.1 (2* ,@((,.>:)@*&3)^:(]`(0"_)) 18)} (3^18)$0' 0.138805 5.45267e8    Q-:c1 18 1 Op 01-12-17 om 13:23 schreef Arie Groeneveld: Another iterator: (slower and fatter) ,@(,0,:])^:(]`(1"_)) .

Re: [Jprogramming] APL Exercises

2017-12-01 Thread Henry Rich
Sure does.  Put it on the bug list & I'll fix it when I have some time. Henry Rich On 12/1/2017 9:12 AM, Raul Miller wrote: Huh... I can reproduce that 10x speed difference: timespacex 'c0 17' 0.078233 2.01328e8 timespacex 'c01 17' 0.761976 1.61061e9 c0 ,@((1 0 1 */ ])^:(]`(1"_)))

Re: [Jprogramming] APL Exercises

2017-12-01 Thread 'Mike Day' via Programming
indeed! On 01/12/2017 14:12, Raul Miller wrote: Huh... I can reproduce that 10x speed difference: timespacex 'c0 17' 0.078233 2.01328e8 timespacex 'c01 17' 0.761976 1.61061e9 c0 ,@((1 0 1 */ ])^:(]`(1"_))) c01 ,@((1 0 1 */ ])^:(]`1:)) This seems bizarre. Thanks, --- Thi

Re: [Jprogramming] APL Exercises

2017-12-01 Thread Raul Miller
Huh... I can reproduce that 10x speed difference: timespacex 'c0 17' 0.078233 2.01328e8 timespacex 'c01 17' 0.761976 1.61061e9 c0 ,@((1 0 1 */ ])^:(]`(1"_))) c01 ,@((1 0 1 */ ])^:(]`1:)) This seems bizarre. Thanks, -- Raul On Fri, Dec 1, 2017 at 8:53 AM, 'Mike Day' via Programmi

Re: [Jprogramming] APL Exercises

2017-12-01 Thread 'Mike Day' via Programming
In case Arie doesn't get round to it,  I note that your (Raul's) msg below is timed here,  in my GMT time-zone,  as "Fri, 1 Dec 2017 08:10:13 -0500" while Arie's comparison between verbs c0 and c1 is timed as "Fri, 1 Dec 2017 12:53:58 +0100" - NL presumably. In case it's disappeared from your inb

Re: [Jprogramming] APL Exercises

2017-12-01 Thread Raul Miller
I can find a message where you used 1: in the expression, but I haven't found any message from you where you talk about 1: vs. 1"_ - is it possible I have not received it yet? Thanks, -- Raul On Fri, Dec 1, 2017 at 7:59 AM, Arie Groeneveld wrote: > > > Op 01-12-17 om 13:55 schreef Raul Miller:

Re: [Jprogramming] APL Exercises

2017-12-01 Thread Arie Groeneveld
Op 01-12-17 om 13:55 schreef Raul Miller: That gerund form of ^: is cute. I need to remember and use it. That said, note that you can shorten it slightly: ,@(,0,:])^:(]`1:) See my previous message about the use of 1: and 1"_ --

Re: [Jprogramming] APL Exercises

2017-12-01 Thread Raul Miller
That gerund form of ^: is cute. I need to remember and use it. That said, note that you can shorten it slightly: ,@(,0,:])^:(]`1:) You can also rearrange it, if you want: (,@,0,:])^:(]`1:) Or, (,0&*,])^:(]`1:) Or you could use 0"0 instead of 0&* (but why would you do that?). I still p

Re: [Jprogramming] APL Exercises

2017-12-01 Thread Arie Groeneveld
Another iterator: (slower and fatter) ,@(,0,:])^:(]`(1"_)) ... and there's an interesting(?) relation with OEIS sequence A005836. Op 01-12-17 om 12:53 schreef Arie Groeneveld: How about    c0=:,@((1 0 1 */])^:(]`(1"_)))    5 ts ' c0 18' 0.123306 6.71091e8 compared to:    c01=:,@((1 0 1 */]

Re: [Jprogramming] APL Exercises

2017-12-01 Thread Raul Miller
Nice, my cantor was longer and more complicated: Cantor=: (*,0&*,*)^:]`1:@.(0-:]) SC=: 3 :'(,~,.~)^:y,1' Thanks, -- Raul On Fri, Dec 1, 2017 at 1:20 AM, Roger Hui wrote: > Cantor =: 3 : ', 1 0 1 */^:y ,1' > SC =: 3 : '(3 3$4>i.5) ,./^:2@(*/)^:y ,.1' > > Recursive solutions using the Mathe

Re: [Jprogramming] APL Exercises

2017-12-01 Thread Arie Groeneveld
How about    c0=:,@((1 0 1 */])^:(]`(1"_)))    5 ts ' c0 18' 0.123306 6.71091e8 compared to:    c01=:,@((1 0 1 */])^:(]`(1:)))    5 ts ' c01 18' 1.23536 5.36871e9 and    5 ts ' c1 18' 0.0948998 6.03985e8    (c0-:c1)18 1 Op 01-12-17 om 10:32 schreef Marshall Lochbaum: And for computing lar

Re: [Jprogramming] APL Exercises

2017-12-01 Thread 'Mike Day' via Programming
fwiw,  I cribbed some Python code a while ago to achieve a pretty fast J function. Unfortunately,  I haven't kept a reference to its source, although I do have notes explaining the algorithm.   Virtually the same code may be used to derive the sum of primes less than some limit.  Perhaps surprisi

Re: [Jprogramming] APL Exercises

2017-12-01 Thread Marshall Lochbaum
And for computing large Cantor sets really fast, you can use a recursive method: c0 =. 3 :', */&1 0 1^:y 1' c1 =. 3 :', (*/~(3^y-2^l)&{.) , */~^:(l=.<.2^.y) 1 0 1' (c0 -: c1) 18 1 10 (6!:2) 'c0 18' 1.22999 10 (6!:2) 'c1 18' 0.0728543 The J solution makes it easy to figure this out,

Re: [Jprogramming] APL Exercises

2017-11-30 Thread Roger Hui
Next exercise: How many primes are < 1e9? You can of course use PrimePi in Mathematica, or p: in J. But suppose those functions are not available. How would you compute that in your favorite language? The erroneous answer 50847478 is cited in various textbooks and even has a name, Bertelsen’s

Re: [Jprogramming] APL Exercises

2017-11-30 Thread Roger Hui
Cantor =: 3 : ', 1 0 1 */^:y ,1' SC =: 3 : '(3 3$4>i.5) ,./^:2@(*/)^:y ,.1' Recursive solutions using the Mathematica ReplaceAll (/.) idea are also possible, using indexing ({): Cantor1=: 3 : 'if. 0=y do. ,1 else. ,(Cantor1 y-1){0,:1 0 1 end.' SC1=: 3 : 'if. 0=y do. ,.1 else. ,./^:2 (SC1

Re: [Jprogramming] APL Exercises

2017-11-30 Thread Dabrowski, Andrew John
On 11/29/2017 11:40 PM, Roger Hui wrote: > 2.5 Cantor Set > > Write a function to compute the Cantor set of order n, n>:0. > > Cantor 0 > 1 > Cantor 1 > 1 0 1 > Cantor 2 > 1 0 1 0 0 0 1 0 1 > Cantor 3 > 1 0 1 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 1 0 1 > In Mathematica: cantor