The New J Math

From J Wiki
Jump to navigation Jump to search

The New J Math

>> << Plus Pri JfC LJ Phr Dic Voc !: Rel NuVoc wd Help 

>> << Plus Where_to_Start 

  | ⇑wel | ←top | ↑prv | ↓skp | +exm | ∇exp | ↔rel | ⇔adv | →top | ⇒are |

 The J programming language makes three important innovations over most others.  The most obvious and most advertised is that all data objects are treated as dynamically dimensioned arrays.  An equally powerful feature is the introduction of adverbs and conjunctions to control and combine its primitive operations in various useful ways.  A less advertised feature is J's regularization and uniformization of arithmetic notation for specification via linear streams of characters.  A concomitant feature is compaction, minimizing the span of code one needs to read, in order to recognize what it can accomplish.  Each of these differences can pose a stumbling block to easy adoption, requiring unlearning some long-ingrained habits and learning some new vocabulary.

Especially if you grew up with Traditional Math in the 50's or New Math in the 60's, you may have missed out on the New-New Maths of the 70's and 90's--introduced in APL and J.

Gone are the fussy rules of inter-operation precedence and the variation betweeen formats for operation application, array access, and function calls. You may lose a bit of elegance (and typographical complication) when writing a division involving two computed values, or the visual emphasis of using a large Sigma or Pi. It also has to be admitted that having only one set of bracketing symbols can lead to confusing pile-ups in deeper nests. (The otherwise more deeply nested argument to any verb can, however, be moved by Reflex to its right side, where outermost parentheses are unnecessary. A deep nest may also be broken into named components for clarity, usually at little extra computational cost.

Precedence

  | ⇑wel | ←top | ↑prv | ↓skp | +exm | ∇exp | ↔rel | ⇔adv | →top | ⇒are |

 The precedence of one verb (operation or function) to be performed before another in a sentence (formula or expression) depends entirely on its position. Within each parenthesized phrase (sub-expression), each is performed, starting from the right end, with its result passed to the next verb on its left. Whenever a noun or noun result (data) is shown immediately to the left of a verb, that verb will be the one to process it, in dyadic mode. (When right and left arguments each result from computation, you should expect the right argument to be processed before the left one, when using the J-interpreter in Version 9 or earlier. Some future version may offer a way to permit parallel processing.) 
Traditional Math J Math Alternate result
   10 - 5 + 3    (10 - 5) + 3    10 - 5 + 3
8 8 2

Symbols

  | ⇑wel | ←top | ↑prv | ↓skp | +exm | ∇exp | ↔rel | ⇔adv | →top | ⇒are |

 All of the mathematical and other actions built in as primitive tools of the J language are designated by brief symbol combinations of ASCII characters.  The period and/or colon are often appended to other symbols to inflect (distinguish) different uses for a wide variety of purposes.  Most primitives can also easily be assigned more traditional names for readability by novices and non-J readers.  Here are samples of some frequently used verbs, highlighting differences from customary mathematical notation.
Old Math J Math Optional form(s) Definitions
   10 * 5 / 3    10 * 5 % 3    10 times 5 divby 3 [1] Times
1.66667 1.66667 1.66667 [2] Divide
   1 / 3    % 3    recip 3 [3] Reciprocal
0.33333 0.33333 0.33333
   √ 3    %: 3    sqrt 3 [4] Square root
1.73205 1.73205 1.73205
   3√ 3    3 %: 3    cubrt 3 [5] Root
1.44225 1.44225 1.44225
   [lowbrack] 1.73205    <. 1.73205    floor 1.73205 [6] Floor
1 1 1
   | -1.7 |    | _1.7    mag _1.7 [7] Magnitude
1.7 1.7 1.7
   10 mod 3    3 | 10    3 res 10 [8] Residue
1 1 1
   25    2 ^ 5    2 pow 5 [9] Power
32 32 32
   4²    *: 4    sqr 4 [10] Square
16 16 16
   log10 1000    10 ^. 1000    10 log 1000 [11] Logarithm
3 3 3
   e³    ^ 3    exp 3 [12] Exponential
20.0855 20.0855 20.0855
   epi * i    ^ o. 0j1    exp pitimes 0j1 [13] Pi Times
_1 _1 _1
   | 2 + 5i |    | 2j5    mag 2j5 [14] Complex
5.38516 5.38516 5.38516 [15] Magnitude
   a b c 3    'a' 'b' 'c' '3'    'a','b','c','3' [16] Append
value error: c syntax error abc3
   314e_2 pi e    314e_2 , pi , e    1.414   3.1416   2.718 [17] Append
syntax error 3.14 3.14159 2.71828 3.14 3.1416 2.718
   √(22 + 52)    %: (*: 2) + *: 5    %: +/ *: 2 5 [18] ArrayProcessing
5.38516 5.38516 5.38516 [19] Insert
   1, 2, 3, 4, 5    i. 5    integers 5 [20] Integers
1,2,3,4,5 0 1 2 3 4 0 1 2 3 4
   'abcdef' [6,1,3,5];    5 0 2 4 { 'abcdef'    5 0 2 4 from 'abcdef' [21] From
face face face

End

  | ⇑wel | ←top | ↑prv | ↓skp | +exm | ∇exp | ↔rel | ⇔adv | →top | ⇒are |