Array arguments to verbs containing loops : A confused Newbies Question 
Author Message
 Array arguments to verbs containing loops : A confused Newbies Question

I am evaluating J and I am much impressed with its capacity to process
arrays simply.
but in trying to  implement  a mandelbrot set example , I  seem only to get
a single number  
out  of the array being input to the verb and not the output of an array
which I desire.
does the inclusion of a looping control structure i.e.. while. prevent the
verb from processing
more than one input argument?   or is there an other cause?  and is there a
work around?

mbz =. 3 : 0
NB. Mandelbrot taking complex
NB. argument
    c =. y.
    z =. 0j0
count =. _1
while. ( count < 128) *. ( 2 > |z ) do.  
            z =. c + *:z
        count =. >:count
end.
count
)

a=. _0.5j_0.65
mbz a       NB. a single argument
11             NB. Works Fine !

   ]a=. _2+0.5* i.7
_2 _1.5 _1 _0.5 0 0.5 1

   ]b=. j.(_1.5+ 0.5* i.7)
0j_1.5 0j_1 0j_0.5 0 0j0.5 0j1 0j1.5

 ]c=. |:a+/|.b                NB. an array of input arguments
 _2j1.5    _1.5j1.5  _1j1.5    _0.5j1.5   0j1.5   0.5j1.5    1j1.5
 _2j1       _1.5j1     _1j1      _0.5j1      0j1     0.5j1       1j1
 _2j0.5    _1.5j0.5   _1j0.5   _0.5j0.5   0j0.5   0.5j0.5   1j0.5
 _2         _1.5         _1        _0.5        0        0.5         1
_2j_0.5   _1.5j_0.5  _1j_0.5 _0.5j_0.5 0j_0.5 0.5j_0.5  1j_0.5
_2j_1     _1.5j_1     _1j_1   _0.5j_1     0j_1    0.5j_1     1j_1
_2j_1.5  _1.5j_1.5  _1j_1.5 _0.5j_1.5  0j_1.5  0.5j_1.5 1j_1.5

   mbz c
0              NB. only returns the result of the first argument

Any help understanding the cause of this effect or in finding the
proper documentation or resource is greatly appreciated

        sincerly
Jeff Peters



Fri, 22 Oct 1999 03:00:00 GMT  
 Array arguments to verbs containing loops : A confused Newbies Question

Quote:
>    mbz c
> 0              NB. only returns the result of the first argument
> ... cause of this effect ...
> ... finding the proper documentation ...

Your question can be answered at the macro and micro level.

To understand what happens, look up the control structures entry
in the Dictionary (I believe it's under ": (Explicit Definition)")
and the interpretation of the Test blocks in particular.

To fix your mandelbrot program, don't patch around that condition,
but visit the entry for the Rank conjunction (").

                                        I hope this helps and doesn't
                                        spoil the fun.

                                        Martin Neitzel
PS:  Try  1 2 3 j./ 4 5 7 8



Sun, 24 Oct 1999 03:00:00 GMT  
 Array arguments to verbs containing loops : A confused Newbies Question


Quote:
>I am evaluating J and I am much impressed with its capacity to process arrays simply.
>but in trying to  implement  a mandelbrot set example , I  seem only to get a single number  
>out  of the array being input to the verb and not the output of an array which I desire.
>does the inclusion of a looping control structure i.e.. while. prevent the verb from processing
>more than one input argument?   or is there an other cause?  and is there a work around?
>mbz =. 3 : 0
>NB. Mandelbrot taking complex
>NB. argument
>    c =. y.
>    z =. 0j0
>count =. _1
>while. ( count < 128) *. ( 2 > |z ) do.

Note that the above test actually returns an ARRAY result
when you pass it an array.  The J documentation states:

The last sentence executed in a T block is tested for a
non-zero value in its leading atom, and the result of
the test determines the block to be executed next.

Essentially, although J is array-capable, its control
structures are not.  What this means is that mbz really
only works the way you want for a single item.  Not a big
problem.  You simply tack on a "0 (to make it mbz"0) and
J will calculate the function for each scalar.  While you
may think that this somehow is a heresy against array
processing, think of "0 as an encapsulation of the application
of a single function over the elements of an array.  That is,
once you define the function for a scalar, "0 gives you the
function for an array, without loops or nothin'.

Quote:
>Any help understanding the cause of this effect or in finding the
>proper documentation or resource is greatly appreciated

>        sincerly
>Jeff Peters


--
|\/| Randy A MacDonald       |"You just ASK them?"

     BSc(Math) UNBF '83      | APL: If you can say it, it's done.

                             | Also http://www.godin.com/godin/
------------------------------------------------<-NTP>----{ gnat }-


Sun, 24 Oct 1999 03:00:00 GMT  
 Array arguments to verbs containing loops : A confused Newbies Question



Quote:
> does the inclusion of a looping control structure i.e.. while. prevent
the
> verb from processing
> more than one input argument?   or is there an other cause?  and is there
a
> work around?

> mbz =. 3 : 0
> NB. Mandelbrot taking complex
> NB. argument
>     c =. y.
>     z =. 0j0
> count =. _1
> while. ( count < 128) *. ( 2 > |z ) do.      
>        z =. c + *:z
>    count =. >:count
> end.
> count
> )

> a=. _0.5j_0.65
> mbz a       NB. a single argument
> 11             NB. Works Fine !

Date:         Wed, 7 May 1997 07:15:30 -0300
From: "L-Soft list server at LISTSERV.UNB.CA (1.8c)"



You  are   not  authorized  to   send  mail  to   the  APL-L  list   from
your

from
another of  your accounts,  or perhaps  when using  another mail  program
which
generates slightly  different addresses, but  LISTSERV has no way  to
associate
this other account or address with yours. If you need assistance or if you
have
any question  regarding the policy of  the APL-L list, please  contact the
list

------------------------ Rejected message (114 lines)
-------------------------


        by unb.ca (8.8.5/970423-08:45) with ESMTP id HAA00878

Received: from mainframe (ip203-87.cc.interlog.com [207.34.203.87]) by
smtp.interlog.com (8.8.3/8.7.6) with SMTP id GAA21422 for



X-Mailer: Windows Eudora Light Version 1.5.4 (32)
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Date: Wed, 07 May 1997 06:15:45 -0400


Subject: Mandelbrot set


- Show quoted text -

Quote:
>does the inclusion of a looping control structure i.e.. while. prevent the
>verb from processing
>more than one input argument?   or is there an other cause?  and is there
a
>work around?
>mbz =. 3 : 0
>NB. Mandelbrot taking complex
>NB. argument
>    c =. y.
>    z =. 0j0
>count =. _1
>while. ( count < 128) *. ( 2 > |z ) do.      
>        z =. c + *:z
>    count =. >:count
>end.
>count
>)
>a=. _0.5j_0.65
>mbz a       NB. a single argument
>11             NB. Works Fine !  

It should suffice to use mbz"0, but you may be interested
in the following alternative approach using a three-element
argument of original argument, count, and z:

     arg=. 0&{"1
   count=. 1&{"1
       z=. 2&{"1


   a=. _0.5j_0.65

   f a,0,0
_0.5j_0.65 1 _0.5j_0.65
   powers=. f^:0 1 2 3 4 a,0,0
   powers
_0.5j_0.65 0                   0
_0.5j_0.65 1          _0.5j_0.65
_0.5j_0.65 2             _0.6725
_0.5j_0.65 3    _0.0477437j_0.65
_0.5j_0.65 4 _0.920221j_0.587933
   count powers
0 1 2 3 4
   z powers
0 _0.5j_0.65 _0.6725 _0.0477437j_0.65 _0.920221j_0.587933

The use of a single argument a instead of a,0,0 may be provided
as follows:

   3&{. a
_0.5j_0.65 0 0


   mb a
_0.5j_0.65 1 _0.5j_0.65


   ]c=._2 1.5 table 7 3  NB. First three columns of Peters table
 _2j1.5  _1.5j1.5  _1j1.5
   _2j1    _1.5j1    _1j1
 _2j0.5  _1.5j0.5  _1j0.5
     _2      _1.5      _1
_2j_0.5 _1.5j_0.5 _1j_0.5
  _2j_1   _1.5j_1   _1j_1
_2j_1.5 _1.5j_1.5 _1j_1.5

   all=. mb ^: 5 "0 c
   $ all
7 3 3
   z all
  199592j_157063   _27591j15008.2   3339.31j_4130.14
     _4874j14747 147.129j_997.756              55j91
395.233j_545.027  1.91016j18.7188  _2.61839j0.890381
               2         _1.11424                 _1
 395.233j545.027 1.91016j_18.7188 _2.61839j_0.890381
    _4874j_14747  147.129j997.756             55j_91
   199592j157063  _27591j_15008.2    3339.31j4130.14
   count all
5 5 5
5 5 5
5 5 5
5 5 5
5 5 5
5 5 5
5 5 5

The complete definition of mb may be seen by fixing it as follows:

   mb f.

The controlled execution of mb might best be provided by using the




Sun, 24 Oct 1999 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Array arguments to verbs containing loops : A confused Newbies

2. MS 5.0 - C programmer confused: Redeclared array argument

3. Newbies' Question: Array of objects

4. What confuses the newbies: An unscientific study

5. 1d array containing means of a 2d array

6. DEALLOCATE of a derived type array containing pointer array components

7. array components containing arrays

8. Arrays: Build array in multiple for loops or replace array elements

9. array section as actual argument where dummy argument is INTENT(OUT)

10. Detecting uninitialized subroutine argument used as array bound of another argument

11. Question about assumed shape array arguments

12. Allocatable arrays as arguments to subroutine questions

 

 
Powered by phpBB® Forum Software