I followed the reference below to the end of chapter 31 of Stokes concerning
Mandelbrot:

makegrid =: 3 : 0
    'LL UR delta' =. y
    'xmin ymin' =. +. LL
    'xmax ymax' =. +. UR
    xn =. <. (xmax-xmin) % delta
    yn =. <. (ymax-ymin) % delta
    (|.(ymin + delta * i. yn))  (j. ~/) (xmin + delta * i. xn)
)
     makegrid _2j3 4j5 1.0
_2j4 _1j4 0j4 1j4 2j4 3j4
_2j3 _1j3 0j3 1j3 2j3 3j3
    
     GRID =:  makegrid _2.5j_1 1j1 0.005
     
       mfn1 =: 3 : 0  
    NB.        y is one pixel-position
    v =. 0j0
    n =. 0
    while. (2 > | v) *. (n < MAXITER) do.
        v  =. y + *: v
        n =. n+1
    end.
    n
)

 MAXITER =: 64                NB. maximum number of iterations
   
image1 =: mfn1 " 0 GRID

 require '~addons/graphics/viewmat/viewmat.ijs'
 viewmat image1

 e1 ; t1 =: 6!:2 e1 =: 'image1 =: mfn1 " 0 GRID NB. Wikipedia scalar'
 
 mfn2 =: (<: 2:)@|@(] ((*:@] + [)^:((<: 2:)@|@])^: MAXITER ) 0:) 
   
t2 =: 6!:2 e2 =: 'image2 =: mfn2 "0 GRID NB. Rosetta '
2 2 $ e1; t1; e2; t2

viewmat image1
viewmat image2

This script works in J8 jqt but not in J8 jhs.  To see the images in jqt,
allow the script to run and then repeat:

Viewmat image1 and viewmat image2 in jijx.

Also Stokes has a reference to Rosetta code for J version of Mandelbrot.
The version there does not work in either  jhs or jqt.

Linda

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Jan-Pieter
Jacobs
Sent: Sunday, May 19, 2013 8:55 AM
To: [email protected]
Subject: Re: [Jprogramming] newbie help: how to avoid division by zero

I think pointing people here:
http://www.rogerstokes.free-online.co.uk/31.htm might be good start.

It touches exactly these topics of replacing repeated scalar operations with
vector operations.
These techniques are applicable in any other language which is able to do
vector operations directly (eg. Matlab).
I hope this is the next version of the docs in preparation? It seems that
the version of Learning J on the jsoftware.com does not contain this chapter
(yet).

Jan-Pieter

2013/5/19 Linda Alvord <[email protected]>:
> I think you missed my point.
>
> In the vocabulary in "Control Structures" you provide hints to formulate
this:
>
>     if. y<0 do. c elseif. y>:0 do. d end.
>
> A beginner who finds this is likely to assume that this is the best way to
provide a conditional solution in J.
>
> Sadly, they are likely to work to master the use of this structure. A
better way is not there for them to see.  I'm suggesting that a better way
(or the best known option at the current time) be provided right there.
>
>    c*y<0)+(d*y>:0)
>
> Often these better ways appear on wiki pages. They are only brought to
light by some link on the forum which would otherwise never be found.
>
> If gems like this one were to appear in the vocabulary section it would
encourage faster development of good writing skills.
>
> So much of the give and take of the forum reduces concepts to a simpler
way of solving problems. It would be great if those "better ways" could find
their way into the vocabulary.
>
> Linda
>
> -----Original Message-----
> From: [email protected] 
> [mailto:[email protected]] On Behalf Of Roger 
> Hui
> Sent: Saturday, May 18, 2013 7:03 PM
> To: Programming forum
> Subject: Re: [Jprogramming] newbie help: how to avoid division by zero
>
> We don't do anyone any favors by providin
>   if. y<0 do. c elseif. y>:0 do. d end.
> instead of
>   c*y<0)+(d*y>:0)
>
>
> For one thing, the former has to work scalar-by-scalar, and for now and
for the forseeable future it'll be orders of magnitude slower that the
latter expression.
>
>> There are many places where newer and better ways of doing things 
>> could
> be added to save lots of new users many pitfalls.
>
> Yes, we have newer and better ways of doing things; it's called array
thinking, and booleans returning 0 and 1 instead of false and true, and ...
>
>
>
> On Sat, May 18, 2013 at 1:41 PM, Linda Alvord
<[email protected]>wrote:
>
>>    try=: 3 : 0
>>    c=:12
>>    d=:14
>>    if. c*y<0 do. c elseif. d*y>:0 do. d end.
>>    )
>>    try _3
>> 12
>>    try 0
>> 14
>>    try 3
>> 14
>>
>>    c=:12
>>    d=:14
>>    y=:_3
>>    (c*y<0)+(d*y>:0)
>> 12
>>    x=:0
>>    (c*y<0)+(d*y>:0)
>> 12
>>    x=:3
>>    (c*y<0)+(d*y>:0)
>> 12
>>
>> Roger, Most people seem to go first to the vocabulary to find a 
>> starting place to solve their problems.
>>
>> Wouldn't it be useful to go to "Control Structures" to find a major 
>> improvement such as the one you just wrote:
>>
>>    if. c*y<0 do. c elseif. d*y>:0 do. d end.
>> or:
>>   (c*y<0)+(d*y>:0)
>>
>> There are many places where newer and better ways of doing things 
>> could be added to save lots of new users many pitfalls.
>>
>> Linda
>>
> ----------------------------------------------------------------------
> 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

Reply via email to