:'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
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│
││┌──┬──┬─┐│@│┌─┬─┐││ │ │
│││┌──┬
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
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
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$
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
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
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
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
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
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
┌─ 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'
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
>> 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
> 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
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
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
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
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
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"_))
.
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"_)))
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
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
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
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:
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"_
--
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
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 */]
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
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
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
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,
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
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
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
35 matches
Mail list logo