Teaching Use of A Computation Server to Science Students

 

 

 

Dr. Roelof K. Brouwer

Department of Computing Science

University College of the Cariboo

Kamloops , British Columbia

V2C 5 N3

 

 

1      Introduction

 

Part of the training for a science major should be how to use a computer for performing scientific computations. Usually this will involve instructing a computer which is generally called programming. The learning of programming however presented several problems:

*    the student is required to think procedurally at the level of the computer

*    the student is required to learn complex definitions and syntax

*    the student has to learn a complex interface (for example VBasic)

*    the student has to learn about compilation

Instructing the computer should not require the student to learn to think like a machine. Ideally the computer should operate at the level of thinking of its client. This is possible with a high level language such as, J, that has been used for teaching use of a computation server to first year science students at UCC.

Following are some guidelines on what may be expected from a computation server which facilitates learning to use a computer for doing computational work for scientists. The tool described here has been used in COMP 100 which is a required course for all students planning to obtain a degree in science.

The paper starts with a description of what is required of an easy to learn but yet powerful computation server and then goes on to describe a language that fits these requirements. Following are examples to illustrate the points made. Note that examples of expressions and functions can be directly executed if the computation server described here is implemented on a computer.

 

2      Requirements for an Easy to Learn Computation Server

 

2.1  Feedback

A very important component in learning is quick feedback. The programming environment is therefore very key in that quick feedback should be provided with minimal effort. This has made Scheme for instance much easier to learn by students than may have been expected

 

2.2  Lack of Effort Required

A good motivator for trying something and encouraging creativityis the lack of effort required beyond the effort of thinking. The cost of trying out something should be very low to encourage students to learn by trying out or experimenting. Thus the server should allow its human client to try out crazy ideas very quickly. An important consideration therefore is the amount of extras required to solve a problem. Extras are such things as type declarations. It should normally not be necessary for a student to write a sequence of statements rather than an expression to get work done by a computation server. Details should be left to the computation server as much as possible. If the elements in a list are to be added together it should require no more than a command to add the elements in the list. Students should be able to command their computation server to add the elements in a list without specifically telling the computation server to initialize an accumulator and add the elements one at a time. This will only get in the way of dealing with arrays and vectors. The level of task description should be no more detailed than that which would be required by a human computation server. The algorithm in pseudocode should be almost identical to the code for the computation server; a computation server which executes algorithms almost directly.

 

2.3  Meaningful Notation and Names for Functions

It should be possible for the programmer to make up his own names for the primitive functions out of which expressions are built just as she can make up her own names for the variables in her program. To the human programmer names are more than combinations of characters. Names stand for concepts and if the programmer is allowed to use his own names for concepts it will be that much easier for him/her to code a correct program. With the right choice of names for not only user-defined functions and variables but also built in functions it will be that much easier for the programmer to think about the solution correctly.

2.4  The Importance of the right notation

Thinking and language are very closely related. Comprehensibility of ideas may be simplified by correct use of symbols. Use of functions that apply directly to arrays for example allows the user to restrict his thinking to the arrays without having to think about their components and how they are manipulated. The high level operations are desirable because they directly represent natural units of thought. High level operations help in chunking or grouping which helps the human to deal with complexity. Mathematicians simplify notation in order to clearly express complex ideas. A concise notation helps the user grasp the intellectual content of an algorithm without distraction due to irrelevant and extraneous matters prescribed by a machine. Users of many traditional programming languages are required to analyze a problem far beyond the level that clear human comprehension requires. For the sake of the computer many details of the computation must be specified. Concise notation on the other hand allows one to carry less notational baggage so that one can concentrate more clearly on the concepts being represented or the relationships between them. That notation is very important in the solving of problems is demonstrated by the quotations of several famous people, some of which appear below. These quotations are referenced in [Jordon 1991]

“By relieving the brain of all unnecessary work, a good notation sets it free to concentrate on more advanced problems, and in effect increases the mental power of the race…  By the aid of symbolism we can make transitions in reasonings almost mechanically by the eye. “ A.N. Whitehead

“Nothing in the history of mathematics is to me so surprising or impressive as the power it has gained by its notation or language…  But in Napier’s time, when there was practically no notation, his discovery or invention [of logarithms] was accomplished by mind alone, without any aid from symbols.” J.W.L. Glaisher

“The quantity of meaning compressed into small space by algebraic signs, is another circumstance that facilitates the reasonings we are accustomed to carry on by their aid.” Charles Babbage

“The argument that Leibniz used when he introduced and standardized the familiar mathematical symbols is still valid. Through proper symbolism, “ indeed the labour of thought is wonderfully diminished” [Cajori, 1928].

“The symbolic form of our work has been forced upon us by necessity; without its help we must have been unable to perform the requisite reasoning”. Whitehead and Russell

 

2.5  Consistency of Notation

When something new is to be learned, consistency is very important. Consistency reduces the need to remember exceptions and thereby prevent mental-overload.

Interestingly enough mathematical notation for function argument placement is inconsistent. In case of summation the argument is to the right. In case of factorial it is to the left. For absolute value it is between two symbols. For exponentiation there is no symbol. For subscripting (we often forget that subscripting is also a function) there is no symbol either. The = sign is used to denote both a relation and the copula in name assignment. For example does x=4 represent a relation or an assignment.

In case of the computation server the effect of primitive functions should follow consistent patterns.

 

3      J as a Computation Server 

 

A computation server which goes a long ways in terms of the requirements just mentioned is the interpreter J loaded onto a PC. “J is a modern high-performance general-purpose programming language that is ideal for complex analytics and data manipulation.” according to its creator K. Iverson. J is a concise, general purpose, high-level and powerful computer programming language. Dr. Iverson also invented APL, the predecessor of J, as a mathematical notation in the late 1950s. In the mid-1960s, his notation was implemented as a programming language, called APL (A Programming Language), for use by IBM's central research staff at the Thomas J. Watson Research Laboratory.

J has a mnemonic one- or two-character spelling for primitives. That is J represents each of its high level functions by one or two symbols. It is highly interactive which means very quick feedback to facilitate rapid learning. It has immediate execution mode allowing immediate execution of expressions and function definition mode. It is particularly strong in the mathematical, statistical, and logical analysis of arrays of data that is applicable in science.

J has adopted terms from English grammar that better fit the grammar of J than do the terms commonly used in mathematics and in programming languages. Thus, a function such as addition is also called a verb (because it performs an action), and an entity that modifies a verb (not available in most programming languages) is accordingly called an adverb. A verb specifies an “action” upon a noun or nouns which correspond to data. An adverb, called operator sometimes, is an entity that applies to a function or verb to produce a related derived function or verb. Adverbs take functions as operands and produce new functions called derived functions as a result.

A conjunction applies to two verbs in the manner of the copulative ( connecting) conjunction as in the phrase “run and hide” The systematic use of adverbs and conjunctions to modify verbs, provides a rich set of operations based upon a rather small set of verbs. For example, +/a denotes the sum over a list a, and */a denotes the product over a, and a */ b is the multiplication table of a and b. This particular operator or adverb / is called reduction. The operator / applies to other function, producing new verbs such as >./ (max of a list), or <./ (min of a list), and may therefore obviate the use of many symbols such as the capital Greek sigma and pi for summation and product.

Grammatical rules determine the order of execution of a sentence. In J the rules of grammar determine the order in which the phrases are interpreted. There is no order-of-execution hierarchy among functions to be learned since an order of preference with more than 200 primitives would be onerous. Execution proceeds from right to left. The assignment which is the last thing to be done is on the extreme left. Note the consistency here. In an unparenthesized expression the right argument of any verb is the result of the entire phrase to its right.

Each symbol or symbol pair represents two functions. The symbol or symbol pair will be used monadically if there is only a right argument and dyadically if there is a left and right argument. Thus _ a means to negate a and b – a means subtraction. You may think of – a as 0 – a. Similarly % a is 1 divided by a and b % a is b divided by a.

 

4      Processing of Data Aggragates

 

A century ago both Sylvester and Gibbs urged us to think in terms of arrays. Most computer languages (what Backus called the Von Neumann bottleneck), force us, however, to work with scalars. Structure of the data should determine how algorithms are applied rather than determining the controls that the programmer inserts into a program (Brown 1991).

The power of the J language comes from its direct manipulation of aggregates of data in the form of arrays. Computers excel where aggregates are manipulated, where the descriptive details of a function do not grow with the size of the aggregates being manipulated, and where one description suffices to cover a large population of aggregates. Because of its power in aggregate manipulation, J has many more primitive functions than other languages. Rather than adding to complexity, this multiplicity actually simplifies. Whenever a typical processing requirement arises, J has a primitive function that naturally performs it. Learning the properties and uses of these primitives adds but a little to the labor of J mastery. Shortly after encountering a function one sees how it ‘fits: in’ with others already understood and soon it begins to participate in program constructions in a natural way.

Surprisingly all J primitive functions get used and none are arcane and of questionable utility. A client soon acquires skill in combining these functions artfully into phrases commonly called ‘idioms’, that are frequently used and that extend every programmer’s arsenal of programming constructions.

Considering that J text is often one-third to one-fifth the size of equivalent text in another language, J programs turn out to be as understandable as those in other languages. The very richness of the set of J functions that makes its mastery so challenging makes the learning of other languages much easier once J is learned.

 

5      An Example of Writing Expressions in J

 

For example, suppose there are four salesmen in your company whose employee ID numbers are 101, 112, 126, and 128.  Create a variable Salesmen that is a list of the employee ID numbers for these four salesmen.  Enter:

          Salesmen =. 101 112 126 128

During the first three months of this year, the salesmen's revenues were:

Salesman 101 $1075  $3023  $4010

Salesman 112 $2075  $750   $1189

Salesman 126 $2211  $3117  $2288

Salesman 128 $2779  $1077  $1928

Create a variable Sales that is a matrix of this sales data:

          Sales=.4 3$1075 3023 4010 2075 750 1189 2211 3117 2288 2779 1077 1928

          Sales

1075   3023   4010

2075   750     1189

2211   3117   2288

2779   1077   1928

Notice that each row in the matrix corresponds to one salesman's revenues for the first three months of the year.  Row 1 corresponds to Salesman 101, Row 2 corresponds to Salesman 112, and so on.

Where is Salesman 101 in the variable Salesmen?  Enter:

          Salesmen=101

1 0 0 0

What are the revenue figures for Salesman 101?  Use the list of 0s and 1s to select the row in Sales that contains the revenue figures.

          1 0 0 0#Sales

 1075 3023 4010

Or you can simply search the matrix using the variable Salesmen:

          (Salesmen=101)#Sales

1075 3023 4010

Remember, the total number of 0s and 1s in the expression must equal the number of rows (or columns) in the character matrix.  If the total number of 0s and 1s in the expression is not equal to the number of rows (or columns), the system displays an error message.

6      Programming in J

 

6.1  Introduction

A lot of the work to be done for the client by the computation server can be specified by the writing of a single expression with the actual arguments in place. Simple expressions can solve fairly complex problems. In case of J programming in a sense consists of building expressions. Expressions can be debugged by executing parts of the expression. If it is desired to execute an expression several times it is possible to replace the expression with a tacit definition of a function which does not include arguments nor placeholders for arguments. If more than one expression is required to define the function then explicit programming may be used to define the solution to the problem

6.2  Tacit Programming

A tacit definition of a function is one without explicit mention of its arguments [Hui 1991]. The advantages of tacit programming are brevity, the allowance for significant formal manipulations of definitions and simplification of the introduction of programming into any topic.  Tacit programming is pure functional programming since arguments are not referred to explicitly. It appears to lead to efficient execution and invites parallel processing. No variables are assigned and no explicit reference is made to the arguments [McIntyre 1991].

Following are several examples. The verbs have been defined in two ways. One way is in terms of J primitives directly and the other in programmable friendly terms. First the primitives that will be used later are given some suggestive names for use by J. Using these names can make J programs almost self documenting. Note that a verb can be defined in top down fashion, that is with detail presented later. Remember that each primitive consists of 1 or two symbols whose meaning is provided in the J dictionary, a copy of which appears in the appendix. An expert J programmer would use combinations of primitives directly while for students it is more meaningful to use the names as they appear on the left side of the definitions below.

Following are some re-definitions of primitives made by the client to be used in other expressions. “=:” is the symbol pair for definition. The left side below is the user defined name and the right side is a J primitive.

be_head=. }.

count=: #

curtail=:}:

divided_by=: %

dot_product=:+/ .*

floor=: >.

left_argument=:[

of=:@

product=:*/

root=:square_root=:%:

square=: *:

sum=:+/

 

Following are some definitions of verbs which use these primitives. Two forms are given and either form can be used depending upon how versatile the programmer is in J primitives. Note that the definitions do not have to appear in any particular order.

 

 

Mean of a list of numbers is the sum divided by the number of elements.

mean =: +/ % #

or

mean=. sum divided_by count

 

 

Deviation is mean subtracted from values

dev=: - +/%#

or

dev =. –mean

 

 

Sum of squares of deviations

ss =. + / @ * : @ dev

or

ss=: sum of square of dev

 

 

Variance is mean of square – square of mean

variance =. (+/%#) @*: - *: @ mean

or

variance=: mean of square - square of mean

 

 

Standard deviation is square root of variance

sd =. % : @ variance

or

sd=: square_root of variance

 

 

A number is an integer if it is equal to its floor

integer=: = <.

or

integer=: = floor

 

 

The geometric mean  is the nth root of the product

geometric_mean=:# %: */

or

geometric_mean=: count root product

 

 

Rate of Change from amounts

rate_of_change=. be_head divided_by curtail

or

rate_of_change=: }.%}:

 

 

Mean of x weighted by y

mean_of_x_weighted_by_y =: +/ .* % # @]

or

mean_of_x_weighted_by_y =: dot_product divided_by count

 

Following is an example shown in various stages of development

Weighted mean in mathematical terms

S ai wi / Swi

 

 as a J expression

+/w*a % +/w

 

in tacit form

weighted_mean=:+/@* % +/@ [

or

weighted_mean=: sum of product divided_by sum of left_argument

 

further examples

The weighted mean of a£b

S ½bi-ai ½(ai £bi)S ½bi-ai ½

special_weighted_mean=: | @ - weighted_mean £

Note that no arguments are required.

 

mathematical expression

 in J form with arguments

 

(x >. / . * w) % (%: + / x x w)

 

In tacit form without arguments

 (>. / . * ) % %: @ (+/ @ *)

 

mathematical expression

 

 

in J form with arguments

(x >. /. * w) % ((>. / x) * (>. / w))

 

in tacit form

 >. / . * %  >. / @ [ * >./ @]

 

 

6.3  Explicit programming in J and Writing Executable pseudo-code- Example

Verbs can also be defined explicitly and may require more than one expression as may be expected especially in the case of interactive programs. Following are some examples of explicit definitions of functions which again show that J can be made as programmable friendly as is desired. It is quite possible to write executable pseudo code using J.

 

Example 1

 

Algorithm

 

Display the height of an object, falling under the force of gravity until the height reaches 0

 

            1.         Get the initial data

                        1.1       Get the tower_height

                        1.2       Get the delta_time for which to do the calculations

            2.         Initialize the time_passed and current_height

            3.         While the current_height is greater than zero

                        3.1       Print the time_passed and current_height

                        3.2       Calculate the new time_passed and new current_height according to:

                                    time_passed <--time_passed + delta_time

                                    current_height <--  tower_height - 0.5 * g * square of t

            4.         Print "SPLATT"

 

 

Pseudo-code

 

g <-- 9.80665 (* gravitational constant*)

get tower_height

get  delta_time

let time_passed be 0

let current_height be tower_height

while current_height > 0            do

            write time_passed, current_height

            time_passed ¬time_passed + delta_time

            time_passed ¬ tower_height - 0.5 * g * square of time_passed

end of while

write "SPLATT"

 

 

Algorithm Coded in J

 

gravitation_simulation=: verb define

NB. simulate falling object with delta_time  time interval

write_to_screen ‘input height of tower’

tower_height=. get_number

write_to_screen ‘input time interval

delta_time=.get_number

g =. 9.80665  NB. gravitational constant

time_passed =.0

current_height =.tower_height

while. (current_height > 0) do.

            write_to_screen ' Time Passed  =  ', 10.3 format time_passed

            write_to_screen 'Current Height = ', 10.3 format current_height

            time_passed=.time_passed + delta_time

            current_height =. tower_height - 0.5 * g *square of time_passed

end.

write_to_screen 'SPLATT'

time_passed

)

 Note that the names for both the verbs and the nouns, including the names for the built in functions or primitives, are chosen by the programmer,.

 

NB. dictionary for verb or function names

format=: ": NB. format

from_keyboard=:1

get_character=:get_characters=: 1!:1

get_number=:get_numbers=: ".@get_characters NB. numeric key board input

sum=:+/

write_to_screen=: (1!:3)&2

one_halve=:-:

ten_power=:10&^

square=:*:

 

 

Example 2

 

Find the square root of a number by successive approximation

 

Crude Algorithm

 

Find the square root of N.

1.         approximate, estimate the value X

2.         add the estimate , X, to N and divide the result by 2

3.         square it and see how close it is to N

4.         if not close enough, go back to step 2 with new approximation

 

Refined Algorithm

 

1.         estimate¬ 1

2.         repeat until close enough

                        2.1       estimate<--  (N/estimate +estimate)/2

2.2       write estimate

            2.2.      square_of_estimate<--square of estimate

until 0.001>absolute value of (square_of_estimate-N)/N

 

Algorithm coded in J

 

square_root=: verb define

:

estimate=. 1

 NB. check if square of estimate is close enough

 NB. the left argument determines the number of places accuracy

 NB. behind the decimal that is required

 NB. the right argument is the number whose root is to be found

whilst. (ten_power-x.)<|(y.-square estimate)% y. do.

            estimate=. one_halve (estimate+ y. % estimate)

NB. the new estimate is the average of the current estimate

NB.  and the number divided by the current estimate

            write_to_screen 20.8 format estimate

end.

)

 

7           Advantages of J

 

Following is a description of some of the advantages of J.

1.     The treatment of vectors, matrices, and other arrays as single entities.

J is particularly strong in the mathematical, statistical, and logical analysis of arrays of data that is applicable in science.Because of the extension of functions to arrays, programs are much shorter, easier to write, debug, and modify than programs in scalar-oriented languages. Array bounds-checking prevents J programs from clearing memory or crashing the system. Primitive functions, which apply to multidimensional arrays, have loops built into them, saving the programmer from having to write many of the loops that are required in other languages. Extra lines of code and loops are only a burden for the programmer and do not contribute to the conceptualization of the process (Jordon 1991). The user can interactively create and transform complex informational structures.

2.     The use of functional or tacit programming that requires no explicit mention of the arguments of a function (program) being defined.

3.     The use of assignment to assign names to functions (as in sum=:+/ and mean=:sum % #).

4.     J is highly interactive which means very quick feedback to facilitate rapid learning.

Since J is interpreted, programs can be run as soon as you finish editing them. With no compilation or linking required the user is left free to experiment with ideas and variations of ideas. It encourages and facilitates rapid prototyping and modification of applications. Personal involvement is continual. It has immediate execution mode allowing immediate execution of expressions and function definition mode. For debugging it is possible to examine the variables of a faulty program, experiment with different expressions, edit the program, and resume execution once you fix the problem.

5.     No requirement for type declarations.

6.     Dynamic creation of variables.

7.     No anomalous constructions such as bracket indexing.

8.     Designed without the typical constraint of the Von-Neumann mind set. (Jordon 1991)

9.     Inherently parrallel because almost all primitive operations are defined on arrays of objects. The calculation of every individual data element is independent of the other (Willhoft 1991).

J seems to appeal to the right hemisphere of the human brain which is specialized for holistic thinking (Jordon 1991). Users of J are encouraged to think holistically since operating or collections of data is in general, no more difficult than operating on single entities. Operations such as sorting, searching, and selection are built into the language as primitives.

Whereas many computer languages began as tools for specifying machine instructions in a system-independent way, J was designed as a powerful, mathematically-inspired executable notation unhindered by many of the inconvenient, limiting aspects of computer hardware. J was not designed with machine instructions in mind unlike procedural languages like C and Pascal which generally have a relatively simple relationship between the language and machine instructions. C and Pascal are languages for writing machine instructions in a nice system-independent way. J programs contain less detail than programs implementing the same function in languages like ALGOL 60, Fortran or C++. A machine carrying out J code has greater freedom since its required behavior is less explicit. In J the results are specified rather than the detailed means for getting there.

machine.

 

8           Summary

 

Using a computer for computational work should not require a student to think in terms of the low level operations as are found in procedural languages like C++ or Fortran any more than a computer scientists should think at the level of machine language when she is using the computer to solve problems. Rather than handicapping the problem solver by requiring her to think at a level lower than the solution of the problem the computer should assist by demanding instructions at no lower a level than is demanded by expressing the solution in non-ambiguous terms. The user should not have to declare things about the solution of the problem that are not innately characteristic of the solution such as the type of the variables used. The user should be able to test out parts of her algorithm by passing them on to the computation server without having to package it in a complete program. The user should be able to make up her own names not used for user defined functions but also for built in functions. J satisfies all these requirements.

Note that only a fraction of the primitives would be dealt with in a first course for science students.

 

 

 

Acknowledgement

Thanks to Don Johnson of the department of computing science at University College of the Cariboo for many of his suggestions made in several reviews during the production of this paper.

 

 

9           References

 

Alfonseca, M. Advanced applications of APL:  logic programming, neural networks, and hypertext IBM Systems Journal, Vol. 30, No. 4, 1991 pp. 543-553

Blaauw, G. A. and F. P. Brooks. Computer Architecture. Concepts and Evolution. Addison Wesley 1997

Brown, J.A.,H.P. Crowder.APL 2:  Getting Started. IBM Systems Journal, Vol. 30, No. 4, 1991 pp. 433-445

Burke,C. et al. Phrases Iverson Software Incorporated 1996

Cajori, F., A. History of Mathematical Notations, The Open Court Publishing Company, La Salle, Illinois, 1928.

Gilman, L. A. J. Rose APL An Interactive Approach John Wiley & Sons 1974

Hui, R. K. W. Hui, Iverson, K. E. ,E. E. McDonnell. Tacit Definition. APL Quote Quad 1991 pp202-211

Hui, R. K. W. , K. E. Iverson Dictionary Iverson Software Incorporated. 1991

Iverson, K.E. A personal view of APL. IBM Systems Journal, Vol. 30, No. 4, 1991 pp. 582-593

Iverson, E. B. Primer Iverson Software 1996

Jordon, S. Friis, E.S. The Foundations of Suitability of APL 2 for Music. IBM Systems Journal, Vol. 30, No. 4, 1991 pp. 513-526

McIntyre, D.B. Language as an intellectual tool: From hieroglyphics to APL. IBM Systems Journal, Vol. 30, No. 4, 1991 pp. 554-581

Peele, H. A. Teaching Secondary Mathematics with J. hapeele@educ.umass.edu

Pountain, D. The Joy of J. Byte September 1995

Stokes, R. Learning J.  http://dspace.dial.com/rstokes/book.htm

Thompson, N.D. APL2 as a specification language for statistics. IBM Systems Journal, Vol. 30, No. 4, 1991 pp. 539-542.

Willhoft, R.G. Parallel expression in the APL2 Language. IBM Systems Journal, Vol. 30, No. 4, 1991 pp. 498-512.


 

10       Appendices

10.1                        Appendix 1 J Dictionary

Following is the list of primitives which are part of the J language. Each primitive comes in 6 forms monadic or dyadic, bare, with “.” or with “:.” A primitive is monadic if there is only a right argument. It is dyadic if there is a left and right argument.

 

BARE

DOT

COLON

=

<

>

_

Self-Classify · Equal

Box · Less Than

Open · Larger Than

Negative Sign/Infinity

Is (Local)

Floor · Lesser Of

Ceiling · Larger Of

Indeterminate

Is (Global)

Decrem · Less Or Equal

Increm · Larg Or Equal

Infinity

+

*

-

%

Conjugate· Plus

Signum · Times

Negate · Minus

Reciprocal · Divided By

Real/Imaginary · GCD (Or)

Length/Angle · LCM (And)

Not (1 & -) · Less

Matrix Inverse · Mat Divide

Double · Not-Or

Square · Not-And

Halve · Match

Square Root · Root

^

$

~

|

Exponential · Power

Shape Of · Shape

Reflex · Pass · EVOKE

Magnitude · Residue

Natural Log · Logarithm

 

Nub ·

Reverse · Rotate (Shift)

Power

Self-Reference

Nub Sieve · Not-Equal

Transpose

.

:

'

;

Det · Dot Product

Explicit · Monad/Dyad

Ravel · Append

Raze · Link

Even

Obverse

Ravel Items · Stitch

Cut

Odd

Adverse

Itemize · Laminate

Word Formation ·

#

!

/

\

Tally · Copy

Factorial · Out Of

Insert · Table · INSERT

Prefix · Infix · TRAIN

Base 2 · Base

Fit (Customize)

Oblique · Key · APPEND

Suffix · Outfix

Antibase 2 · Antibase

Foreign

Grade Up · Sort

Grade Down · Sort

[

]

{

}

Same · Left

Same · Right

Catalogue · From

Item Amend · Amend

Lev

Dex

Head · Take

Behead · Drop

Cap

Identity

Tail ·

Curtail ·

"

`

@

&

?

Rank · CONSTANT

Tie (Gerund)

Atop

Bond/Compose

Roll · Deal

Do ·

 

Agenda

Under (Dual)

Roll · Deal (fixed seed)

Format

Evoke Gerund

At

Appose

a.

b.

D.

E.

i.

Alphabet

Boolean/Basic

Derivative

· Member of Interval

Integer · Index Of

a:       Ace (boxed empty)

c.       Characteristic Values

D:       Secant Slope

f.       Fix

j.       Imaginary · Complex

A.       Atomic Permute

C.       Cycle-Dir · Perm

e.       Raze In · Member

H.          Hypergeometric

L.       L: Level, Level

NB.

p:

t.

_9: etc

Comment

Prime

Taylor Coefficient

Constant fns (_9: to 9: )

o.       Pi Times · Circle fn

q:       Prime Factors

t:       Weighted Taylor Coef

p.       Polynomial

r.       Angle · Polar

T.       Taylor Verb

 


 

10.2                        The Computation Server

The computation server discussed here is a plain vanilla personal computer loaded with the J system in addition to the operating system of course. We can imagine that this together forms the J virtual computer with a very high level machine language.

Specifically “J for Windows 9x/NT provides a complete programming system, including Windows GUI, GDI and OpenGL graphics, a spreadsheet, memory-mapped files for access to very large datasets, and conventional ODBC and OLE database access. J is designed to integrate smoothly with other programs. For example, J can be used as a heavy-duty calculation server for Excel, an ActiveX control for a Web page, or a 32-bit DLL called from a C program. J is available under Windows, WindowsCE, Mac, UNIX and Linux. The core language is identical in all versions, and programs not making use of platform-dependent features will work unchanged on all systems.” [ http://www.jsoftware.com ] “As well as including a general purpose programming language, the J system also provides:

*    an integrated development environment

*    standard libraries, utilities, and packages

*    a form designer for your application forms (windows)

*    an event-driven graphical user interface to your application

*    several methods of interfacing with other programming languages and applications

*    rapid application prototyping and development

*    royalty-free distribution of run-time versions of your application” [Iverson 1996]

To facilitate teaching and learning of J there are labs and demos on

*    Events programming

*    Graphics

*    Sockets and the internet

*    Recursion

*    Plot package

*    Statistics

*    Socket server

A site for the latest information on the latest version of J is www.jsoftware.com/home.html. This site also has free documentation. ftp://watserv1.uwaterloo.ca/languages/j/j3/index.html . is the site for a free but not latest version of the J interpreter.


 

10.3    Appendix 2

Some further interesting examples of code

/:’ ‘ &=                                                        NB. move all blanks to the end of the list

(/:' ' &= )'eee  ff g h jjj'

eeeffghjjj    

 

}.%}:                                                   NB. rate of change from amounts

(}.%}:) 3 4 5 6 7

1.33333 1.25 1.2 1.16667

 

#/.~                                                    NB. frequency count of items y

(#/.~) 2 3 4 3 2 4 5 6 5 4 3 5 6 

3 3 3 2

 

+/ .= ,                                                NB. how many x in y

3 +/ .= , 2 3 4 3 2 4 5 6 5 4 3 5 6 

3

 

=<.                                                     NB. integer test

 

Factorial

 

factorial=: 1: ` (]*factorial@<:) @. *                  NB. factorial

factorial “0 i.6

 

 

(1: ` (]*$:@<:) @. *)  “0 i.6                             NB. $: for self reference

 

NB. tower of hanoi

h=: b ` (p,.q,.r)@.c

c=: 1: < [

b=: 2&,@ [ $ ]

p=: <:@[ h 1: A. ]

q=: 1: h ]

r=: <:@ [ h 5: A. ]

 

tower of Hanoi

(2&,@[ $ ])`((<:@[ $: 1: A. ]) ,. (1: $: ]) ,. <:@[ $: 5: A. ])@.(1: < [)

or

(,.@}:)`((<:@[ $: 1: A. ]) ,. (1: $: ]) ,. <:@[ $: 5: A. ])@.(1: < [)

 

 

member_scores=:wmean nor_by_var @ nor_by_mean

member_scores=:wmean nor_by_var @ nor_by_max

 

NB. left agument is vector of weights. Right argument

NB. is an array of scores

NB. rows correspond to judges or evaluators

NB. columns correspond to contestants

NB. marks for an evaluator are divided by the mean for

NB. the evaluator to reduce effect of high scorers

NB. marks for an evaluator are multiplied by variance

NB. for the evaluator

 

disf=: (% mean)@member_scores

NB. distribution factors to distribute a team mark

 

mean=: +/%#

NB.mean is sum divided by number of elements

 

wmean=: +/@:*%+/@[

NB. Weighted mean. Weights are applied to the rows.

 

var=: (mean@:*:)-*:@mean

NB. variance is mean of squares - square of mean

 

nor_by_mean=:(% mean"1)*(mean @,)

NB.divide rows by their means and multiply

NB.by  mean of means

 

nor_by_max=: ]% >./"1

NB. divide elements in each row by the maximum in the row

 

nor_by_var=: (* var "1)% (mean@: (var "1))

NB.nor_by_var=:(*%[:mean])(var"1)

NB. nor_by_var=: (*var "1)%(var@,)

NB. multiply rows by their variance and divide

NB. by mean of variances