# IojSp

From J Wiki

# Special Code

## An Implementation of J

Many primitives contain special code for certain arguments to effect time and/or space savings not available to general arguments. Moreover, some phrases are "recognized" and are supported by special code. For example, the dyad of the hook ($,) is exactly the reshape of APL (denoted by r); its implementation avoids actually ravelling the right argument, and in so doing saves both time and space:

ts=: 6!:2 , 7!:2@] x=: 11 13 17 19 23 y=: 29 7 23 11 19$'sesquipedalian' (x ($,) y) -: x $, y 1 ts 'x ($,) y' 0.00773981 2.09818e6 ts 'x $, y' 0.0170125 3.14662e6

Instances of such special code are listed below:

= dyad word-parallel operation on Boolean arguments for the following verbs: = < <. <: > >. >: +. +: * *. *: ^ ~: | ! <.@f both avoids non-integer intermediate results on extended precision integers >.@f both avoids non-integer intermediate results on extended precision integers + dyad also * and -; on Windows, assembly code for integer arguments for the vector-vector, vector-scalar, and scalar-vector cases ^ dyad x^y works by repeated multiplication if x is real and y is integral m&|@^ dyad avoids exponentiation for extended precision arguments m&|@(n&^) monad avoids exponentiation for extended precision arguments +/ .* dyad special code -/ .* monad special code in general; special code for square matrices; special code for arrays of 2-by-2 matrices $, dyad also ($,)"r; avoids ravel f;.1 both also f;._1 f;.2 f;._2; avoids building argument cells for several verbs: < $ , # [ ] {. {: <@}. <@}: ; also <&}. <@:}. etc. f;.3 both also f;._3; special code for matrix right arguments # dyad special code for Boolean left arguments # i.@# monad also (# i.&#), etc.; avoids i. on Boolean arguments #: i.@(*/) monad also (#: i.&(*/)), etc.; special code for non-negative integer vectors =/ monad also < <: > >: +. +: * *. *: ~:; word-parallel operations on Boolean arguments +/ monad also * and -; on Windows, assembly code for integer arguments ,/ monad linear time ,./ monad linear time ,.&.>/ monad linear time ;/ monad linear time f/@, monad also f/@:, f/&, f/&:,; avoids ravel #/. dyad avoids building argument cells /: both also \:; special code for several data types; special code for arguments with 5 items or less =/\ monad also +. *. ~:; word-parallel operations on Boolean arguments +/\ monad also * and -; on Windows, assembly code for integer arguments =/\. monad also < <: > >: +. +: *. *: ~:; word-parallel operations on Boolean arguments +/\. monad also * and -; on Windows, assembly code for integer arguments { dyad special code for right arguments of several data types; special code for integer left arguments; special code for indexing first two axes <"1@[ { ] dyad avoids <"1 if left argument is integer array a=: c}x,y,:z - avoids catenation and lamination; in-place if c is Boolean and a is x or y y=: x i}y - in-place f"r both numerous verbs have integrated rank support: = < <. <: > >. >: + +. +: * *. *: - -: % ^ ~: | |. |: $ , ,. ,: # ! [ ] { {. {: }. }: / /: \ \. \: e. i. i: o. p. p: ? monad also ?.; special code if argument is identically 2 ? dyad also ?.; special code if left argument is much smaller than right argument E. monad special code for Boolean and literal vector arguments i. monad also i:; special case for length-1 arguments i. dyad also e. and i:; special code for several data types; special code for i.!.0; special code for arguments with many identical columns

Next • Previous • Index • Table of Contents