ArticleslgStudy

mathematics

J (programming language)

J (programming language) is a mathematics topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand J (programming language) rather than just read about it. In short: The J programming language, developed in the early 1990s by Kenneth E. Iverson and Roger Hui, is an array programming language based primarily on APL (also by Iverson).

J (programming language) — main illustration
J (programming language) — illustration

Key takeaways

  • J (programming language) belongs to mathematics; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect J (programming language) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of J (programming language) from memory before moving on to harder problems.

Reference excerpt

The J programming language, developed in the early 1990s by Kenneth E. Iverson and Roger Hui, is an array programming language based primarily on APL (also by Iverson). To avoid repeating the APL special-character problem, J uses only the basic ASCII character set, resorting to the use of the dot and colon as inflections to form short words similar to digraphs. Most such primary (or primitive) J words serve as mathematical symbols, with the dot or colon extending the meaning of the basic characters available. Also, many characters which in other languages often must be paired (such as [] {} "" `` or <>) are treated by J as stand-alone words or, when inflected, as single-character roots of multi-character words. J is a very terse array programming language, and is most suited to mathematical and statistical programming, especially when performing operations on matrices. It has also been used in extreme programming and network performance analysis. Like John Backus's languages FP and FL, J supports function-level programming via its tacit programming features. Unlike most languages that support object-oriented programming, J's flexible hierarchical namespace scheme (where every name exists in a specific locale) can be effectively used as a framework for both class-based and prototype-based object-oriented programming. Since March 2011, J is free and open-source software under the GNU General Public License version 3 (GPLv3). One may also purchase source under a negotiated license.

Examples J permits point-free style and function composition. Thus, its programs can be very terse and are considered difficult to read by some programmers. The "Hello, World!" program in J is:

This implementation of hello world reflects the traditional use of J – programs are entered into a J interpreter session, and the results of expressions are displayed. It's also possible to arrange for J scripts to be executed as standalone programs. Here's how this might look on a Unix system:

(Note that current j implementations install either jconsole or (because jconsole is used by java), ijconsole and likely install this to /usr/bin or some other directory (perhaps the Application directory on macOS). So, there's a system dependency here which the user would have to solve.) Historically, APL used / to indicate the fold, so +/1 2 3 was equivalent to 1+2+3. Meanwhile, division was represented with the mathematical division symbol (÷). Because ASCII does not include a division symbol per se, J uses % to represent division, as a visual approximation or reminder. (This illustrates something of the mnemonic character of J's tokens, and some of the quandaries imposed by the use of ASCII.) Defining a J function named avg to calculate the average of a list of numbers yields:

avg=: +/ % #

+/ sums the items of the array. # counts the number of items in the array. % divides the sum by the number of items. This is a test execution of the function:

avg 1 2 3 4 2.5

Above, avg is defined using a train of three verbs (+/, %, and #) termed a fork. Specifically, (V0 V1 V2) Ny is the same as (V0(Ny)) V1 (V2(Ny)) which shows some of the power of J. (Here V0, V1, and V2 denote verbs and Ny denotes a noun.) Some examples of using avg:

v=: ?. 20 $100 NB. a random vector v 46 55 79 52 54 39 60 57 60 94 46 78 13 18 51 92 78 60 90 62 avg v 59.2

4 avg\ v NB. moving average on periods of size 4 58 60 56 51.25 52.5 54 67.75 64.25 69.5 57.75 38.75 40 43.5 59.75 70.25 80 72.5

m=: ?. 4 5 $50 NB. a random matrix m 46 5 29 2 4 39 10 7 10 44 46 28 13 18 1 42 28 10 40 12

avg"1 m NB. apply avg to each rank 1 subarray (each row) of m 17.2 22 21.2 26.4

Rank is a crucial concept in J. Implementing quicksort, from the J Dictionary yields:

The following is an implementation of quicksort demonstrating tacit programming. The latter involves composing functions together and not referring explicitly to any variables. J's support for forks and hooks dictates rules on how arguments applied to this function will be applied to its component functions.

Sorting in J is usually accomplished using the built-in (primitive) verbs /: (sort up) and \: (sort down). User-defined sorts such as quicksort, above, typically are for illustration only. The following example demonstrates the usage of the self-reference verb $: to recursively calculate fibonacci numbers:

This recursion can also be accomplished by referring to the verb by name, although this is of course possible only if the verb is named:

The following expression exhibits pi with n digits and demonstrates the extended precision abilities of J:

n=: 50 NB. set n as the number of digits required <.@o. 10x^n NB. extended precision 10 to the nth * pi 314159265358979323846264338327950288419716939937510

Verbs and modifiers A program or routine – something that takes data as input and produces data as output – is called a verb. J has a rich set of predefined verbs, all of which work on multiple data types automatically: for example, the verb i. searches within arrays of any size to find matches:

User programs can be named and used wherever primitives are allowed. The power of J comes largely from its modifiers: symbols that take nouns and verbs as operands and apply the operands in a specified way. For example, the modifier / takes one operand, a verb to its left, and produces a verb that applies that verb between each item of its argument. That is, +/ is a verb, defined as 'apply + between the items of your argument' Thus, the sentence

produces the effect of

J has roughly two dozen of these modifiers. All of them can apply to any verb, even a user-written verb, and users may write their own modifiers. While modifiers are powerful individually, allowing

repeated execution, i. e. do-while conditional execution, i. e. if execution of regular or irregular subsets of arguments some of the modifiers control the order in which components are executed, allowing modifiers to be combined in any order to produce the unlimited variety of operations needed for practical programming.

Data types and structures J supports three simple types:

… excerpt ends here. Continue reading the full article.

Illustrations

J (programming language) illustration
J (programming language): Dissecting the Collatz sequence starting from 6
Dissecting the Collatz sequence starting from 6

Worked examples

Example 1 — a first encounter with J (programming language)

Start with the simplest possible case. Write down what J (programming language) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In mathematics, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to J (programming language) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about J (programming language) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of J (programming language)

In research
J (programming language) appears in mathematics research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses J (programming language) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
J (programming language) is common in secondary-school and first-year university syllabi. It links to neighbouring topics APL programming language family, Array programming languages, Class-based programming languages, so understanding it makes those chapters shorter.
In everyday life
Look for J (programming language) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study J (programming language) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what J (programming language) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain J (programming language) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is J (programming language) in simple terms?

The J programming language, developed in the early 1990s by Kenneth E. Iverson and Roger Hui, is an array programming language based primarily on APL (also by Iverson).

Why does J (programming language) matter?

Because it connects several mathematics ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study J (programming language)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on J (programming language).

Tags

  • APL programming language family
  • Array programming languages
  • Class-based programming languages
  • Dynamically typed programming languages
  • Function-level languages
  • Functional languages
  • Multi-paradigm programming languages
  • Numerical programming languages
  • Object-oriented programming languages
  • Programming languages

Keep exploring