Tally: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
Miraheze>Marshall
(→‎Documentation: NARS2000)
Miraheze>Marshall
Line 36: Line 36:
== History ==
== History ==


Tally was introduced in [[J]] using the symbol <source lang=j inline>#</source>, and adopted in APL by [[Dyalog APL 14.0]]. It was later added to [[NARS2000]] and [[GNU APL]] and has been included in many recents APLs based on Dyalog, such as [[ngn/apl]], [[dzaima/APL]], and [[APL\iv]].
Tally was introduced in [[J]] using the symbol <source lang=j inline>#</source>, and was present in [[NARS2000]] by 2010 using the symbol <source lang=apl inline>></source>. The symbol <source lang=apl inline>≢</source> for Tally was introduced in [[Dyalog APL 14.0]], and quickly adopted by NARS2000. It was later added to [[GNU APL]] and has been included in many recent APLs based on Dyalog, such as [[ngn/apl]], [[dzaima/APL]], and [[APL\iv]].


== External links ==
== External links ==

Revision as of 10:20, 19 November 2019

Tally () is a primitive monadic function which returns the number of major cells in its argument. The Tally of an array is also the first element of its shape, or 1 if it is a scalar (since a scalar is its own major cell by convention). Tally counts the first axis rather than the last because the number of major cells is more useful in leading axis theory.

Examples

Tally can compute the length of a numeric vector or string.

      ≢⍳12
12
      ≢'string'
6

It gives the length of the first axis in a higher-rank array. Tally applied to an array's shape gives its rank.

      ≢5 4 3 2⍴1 'b' 3 'd'  
5
      ≢⍴5 4 3 2⍴1 'b' 3 'd'
4

The Tally of a scalar is always 1.

      ≢3.14
1

Description

Tally returns the length of the first axis of its argument if it has any axes (that is, if it is not a scalar), and 1 otherwise. This can be modelled easily with Shape and First:

Tally ← {⊃(⍴⍵),1}

An alternative implementation is to count the major cells by turning each into a scalar 1 with the Rank operator, then adding them up:

Tally ← +⌿ {1}⍤¯1

History

Tally was introduced in J using the symbol #, and was present in NARS2000 by 2010 using the symbol >. The symbol for Tally was introduced in Dyalog APL 14.0, and quickly adopted by NARS2000. It was later added to GNU APL and has been included in many recent APLs based on Dyalog, such as ngn/apl, dzaima/APL, and APL\iv.

External links

Lessons

Documentation

APL built-ins [edit]
Primitives (Timeline) Functions
Scalar
Monadic ConjugateNegateSignumReciprocalMagnitudeExponentialNatural LogarithmFloorCeilingFactorialNotPi TimesRollTypeImaginarySquare RootRound
Dyadic AddSubtractTimesDivideResiduePowerLogarithmMinimumMaximumBinomialComparison functionsBoolean functions (And, Or, Nand, Nor) ∙ GCDLCMCircularComplexRoot
Non-Scalar
Structural ShapeReshapeTallyDepthRavelEnlistTableCatenateReverseRotateTransposeRazeMixSplitEncloseNestCut (K)PairLinkPartitioned EnclosePartition
Selection FirstPickTakeDropUniqueIdentityStopSelectReplicateExpandSet functions (IntersectionUnionWithout) ∙ Bracket indexingIndexCartesian ProductSort
Selector Index generatorGradeIndex OfInterval IndexIndicesDealPrefix and suffix vectors
Computational MatchNot MatchMembershipFindNub SieveEncodeDecodeMatrix InverseMatrix DivideFormatExecuteMaterialiseRange
Operators Monadic EachCommuteConstantReplicateExpandReduceWindowed ReduceScanOuter ProductKeyI-BeamSpawnFunction axisIdentity (Null, Ident)
Dyadic BindCompositions (Compose, Reverse Compose, Beside, Withe, Atop, Over) ∙ Inner ProductDeterminantPowerAtUnderRankDepthVariantStencilCutDirect definition (operator)Identity (Lev, Dex)
Quad names Index originComparison toleranceMigration levelAtomic vector