Raze: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
(Created page with ":''The symbol <source lang=apl inline>⊃</source> is more commonly used for First or Mix.'' {{Built-in|Raze|⊃}}, or <source lang=j inline>;</source> in J, is a...")
 
(→‎External links: WAR ON RAZE)
 
(9 intermediate revisions by 2 users not shown)
Line 1: Line 1:
:''The symbol <source lang=apl inline></source> is more commonly used for [[First]] or [[Mix]].''
:''The Down Arrow <syntaxhighlight lang=apl inline></syntaxhighlight> is more often used for [[Split]], and the [[Right Shoe]] symbol <syntaxhighlight lang=apl inline>⊃</syntaxhighlight> for [[First]] or [[Mix]].''


{{Built-in|Raze|}}, or <source lang=j inline>;</source> in [[J]], is a [[monadic function]] which combines [[element]] arrays of a [[nested]] [[vector]] along the first [[axis]] (in accordance with [[leading axis theory]]). Thus, the [[major cell]]s of the Raze of an array are the major cells of its element arrays: unlike [[Mix]], which removes a level of [[depth]] while keeping outer and inner axes separate, Raze merges the outer vector's axis with the first axis of each element. Raze is present in [[A+]] and [[J]].
{{Built-in|Raze|}}, <syntaxhighlight lang=apl inline>⊃</syntaxhighlight> in [[A+]], <syntaxhighlight lang=j inline>;</syntaxhighlight> in [[J]], or '''Join''' (<code>∾</code>) in [[BQN]], is a [[monadic function]] which combines [[element]] arrays of a [[nested]] [[vector]] along the first [[axis]] (in accordance with [[leading axis theory]]). Thus, the [[major cell]]s of the Raze of an array are the major cells of its element arrays: unlike [[Mix]], which removes a level of [[depth]] while keeping outer and inner axes separate, Raze merges the outer vector's axis with the first axis of each element. Raze is present in [[SHARP APL]], [[A+]], [[J]], and [[BQN]].


== Examples ==
== Examples ==


Raze can turn a vector of vectors into a single vector. Unlike [[Mix]], it inserts no [[fill element]]s.
Raze can turn a vector of vectors into a single vector. Unlike [[Mix]], it inserts no [[fill element]]s.
<source lang=apl>
<syntaxhighlight lang=apl>
       ⊃(2 3 4;0 1;5)
       ⊃(2 3 4;0 1;5)
2 3 4 0 1 5
2 3 4 0 1 5
</source>
</syntaxhighlight>
{{Works in|[[A+]]}}
{{Works in|[[A+]]}}
When elements of the argument have rank more than 1, Raze combines them along the leading axis, like [[Catenate First]]. In A+, the elements must have the same rank and major cell shape or an error results; in J, lower-rank arrays are promoted to a higher rank and arrays are padded with fills to a common major cell shape.
When elements of the argument have rank more than 1, Raze combines them along the leading axis, like [[Catenate First]]. In A+, the elements must have the same rank and major cell shape or an error results; in J, lower-rank arrays are promoted to a higher rank and arrays are padded with fills to a common major cell shape.
<source lang=apl>
<syntaxhighlight lang=apl>
       ⊃(⍳2 2;-⍳4 2)
       ⊃(⍳2 2;-⍳4 2)
  0  1
  0  1
Line 20: Line 20:
¯4 ¯5
¯4 ¯5
¯6 ¯7
¯6 ¯7
</source>
</syntaxhighlight>
{{Works in|[[A+]]}}
{{Works in|[[A+]]}}


== Properties ==
== Properties ==


Raze is similar to the [[Catenate]] [[reduction]] <source lang=apl inline>↑⍪/</source>. If <source lang=apl inline>X</source> is a vector whose elements have equal and positive [[rank]], then <source lang=apl inline>↑⍪/X</source> is the Raze of <source lang=apl inline>X</source>. The definition differs if <source lang=apl inline>X</source> is a [[singleton]] vector with [[scalar]] elements, because the Raze of <source lang=apl inline>X</source> will be a vector while the reduction implementation results in a scalar (or, in [[NARS2000]], a [[DOMAIN ERROR]]). This is because Raze treats scalar elements of its argument as singleton vectors, a convention which may be viewed as [[scalar rank extension]] or as a result of the idea that a scalar's only [[major cell]] is itself.
Raze is similar to the [[Catenate]] [[reduction]] <syntaxhighlight lang=apl inline>↑⍪/</syntaxhighlight>. If <syntaxhighlight lang=apl inline>X</syntaxhighlight> is a vector whose elements have equal and positive [[rank]], then <syntaxhighlight lang=apl inline>↑⍪/X</syntaxhighlight> is the Raze of <syntaxhighlight lang=apl inline>X</syntaxhighlight>. The definition differs if <syntaxhighlight lang=apl inline>X</syntaxhighlight> is a [[singleton]] vector with [[scalar]] elements, because the Raze of <syntaxhighlight lang=apl inline>X</syntaxhighlight> will be a vector while the reduction implementation results in a scalar (or, in [[NARS2000]], a [[DOMAIN ERROR]]). This is because Raze treats scalar elements of its argument as singleton vectors, a convention which may be viewed as [[scalar rank extension]] or as a result of the idea that a scalar's only [[major cell]] is itself.


Raze is the [[inverse]] of [[Partition]] and [[Partitioned Enclose]] on vectors: partitioning, then razing, a vector gives that vector back. It is also an inverse to partition functions which partition major cells along the first axis, although few partition functions do this.
Raze is the [[inverse]] of [[Partition]] and [[Partitioned Enclose]] on vectors: partitioning, then razing, a vector gives that vector back. It is also an inverse to partition functions which partition major cells along the first axis, although few partition functions do this.
== High-rank extension ==
Raze can be extended to an argument array of rank greater than 1, allowing it to merge [[wikipedia:Block matrix|block matrices]] or higher-dimensional structures. This extension is part of [[BQN]], but has not been implemented in any APL, and would not be backwards-compatible in J, since J's Raze implicitly ravels its argument.
The axes of a high-rank argument should be paired with those of its element arrays, starting at the first axis (much like [[prefix agreement]]). The elements can be merged without adding fills when the length of an element along a particular axis depends only on its position along that axis in the outer array. That is, in <syntaxhighlight lang=apl inline>⊃X</syntaxhighlight>, <syntaxhighlight lang=apl inline>⍴¨X</syntaxhighlight> must match <syntaxhighlight lang=apl inline>⊃∘.,/S</syntaxhighlight>, where S is a vector containing <syntaxhighlight lang=apl inline>≢⍴X</syntaxhighlight> vectors followed by any number of scalars. In this case, the shape of <syntaxhighlight lang=apl inline>⊃X</syntaxhighlight> is <syntaxhighlight lang=apl inline>+/¨S</syntaxhighlight>. The result can be computed by performing a modified 1-dimensional Raze several times. The modified Raze should maintain some number of leading inner element axes. With the [[Rank operator]] (<syntaxhighlight lang=apl inline>⍤</syntaxhighlight>) we might write <syntaxhighlight lang=apl inline>⍪⍤(1-≢⍴X)/X</syntaxhighlight> for a single step in the process, thus reducing along the last axis and catenating along the same axis.
If the element arrays of <syntaxhighlight lang=apl inline>X</syntaxhighlight> do not satisfy the shape requirements, they could be padded with [[fill]]s to force this requirement to hold.
== History ==
Raze was defined as monadic <syntaxhighlight lang=apl inline>↓</syntaxhighlight> in [[A Dictionary of APL]] in 1987, and added to [[SHARP APL]] in version 20, released in 1989.<ref>[[IPSA]]. [https://archive.org/details/sharp-apl-release-20.0-guide-for-apl-programmers "SHARP APL Release 20.0: Guide for APL Programmers"].</ref> It appears in [[J]]'s initial 1990 release as <syntaxhighlight lang=j inline>}.</syntaxhighlight> (that is, also paired with [[Drop]]) but was moved to <syntaxhighlight lang=j inline>;</syntaxhighlight> in 1991.<ref>[[Jsoftware]]. [https://code.jsoftware.com/wiki/Help/Release/J_4.05/Implementation_Status J 4.05 Implementation Status]. Version 3.2.</ref> The glyph <syntaxhighlight lang=apl inline>⊃</syntaxhighlight> is used instead in [[A+]].


== External links ==
== External links ==
* [https://gist.github.com/chrispsn/af6844b80687462814fc39d4b97399a6 War on Raze] by Chris Pearson


=== Documentation ===
=== Documentation ===


* J [https://www.jsoftware.com/help/dictionary/d330.htm Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/semi NuVoc]
* J [https://www.jsoftware.com/help/dictionary/d330.htm Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/semi NuVoc]
* [https://mlochbaum.github.io/BQN/doc/join.html BQN]
== References ==
<references/>
{{APL built-ins}}[[Category:Primitive functions]]

Latest revision as of 23:25, 29 January 2024

The Down Arrow is more often used for Split, and the Right Shoe symbol for First or Mix.

Raze (), in A+, ; in J, or Join () in BQN, is a monadic function which combines element arrays of a nested vector along the first axis (in accordance with leading axis theory). Thus, the major cells of the Raze of an array are the major cells of its element arrays: unlike Mix, which removes a level of depth while keeping outer and inner axes separate, Raze merges the outer vector's axis with the first axis of each element. Raze is present in SHARP APL, A+, J, and BQN.

Examples

Raze can turn a vector of vectors into a single vector. Unlike Mix, it inserts no fill elements.

      ⊃(2 3 4;0 1;5)
2 3 4 0 1 5
Works in: A+

When elements of the argument have rank more than 1, Raze combines them along the leading axis, like Catenate First. In A+, the elements must have the same rank and major cell shape or an error results; in J, lower-rank arrays are promoted to a higher rank and arrays are padded with fills to a common major cell shape.

      ⊃(⍳2 2;-⍳4 2)
 0  1
 2  3
 0 ¯1
¯2 ¯3
¯4 ¯5
¯6 ¯7
Works in: A+

Properties

Raze is similar to the Catenate reduction ↑⍪/. If X is a vector whose elements have equal and positive rank, then ↑⍪/X is the Raze of X. The definition differs if X is a singleton vector with scalar elements, because the Raze of X will be a vector while the reduction implementation results in a scalar (or, in NARS2000, a DOMAIN ERROR). This is because Raze treats scalar elements of its argument as singleton vectors, a convention which may be viewed as scalar rank extension or as a result of the idea that a scalar's only major cell is itself.

Raze is the inverse of Partition and Partitioned Enclose on vectors: partitioning, then razing, a vector gives that vector back. It is also an inverse to partition functions which partition major cells along the first axis, although few partition functions do this.

High-rank extension

Raze can be extended to an argument array of rank greater than 1, allowing it to merge block matrices or higher-dimensional structures. This extension is part of BQN, but has not been implemented in any APL, and would not be backwards-compatible in J, since J's Raze implicitly ravels its argument.

The axes of a high-rank argument should be paired with those of its element arrays, starting at the first axis (much like prefix agreement). The elements can be merged without adding fills when the length of an element along a particular axis depends only on its position along that axis in the outer array. That is, in ⊃X, ⍴¨X must match ⊃∘.,/S, where S is a vector containing ≢⍴X vectors followed by any number of scalars. In this case, the shape of ⊃X is +/¨S. The result can be computed by performing a modified 1-dimensional Raze several times. The modified Raze should maintain some number of leading inner element axes. With the Rank operator () we might write ⍪⍤(1-≢⍴X)/X for a single step in the process, thus reducing along the last axis and catenating along the same axis.

If the element arrays of X do not satisfy the shape requirements, they could be padded with fills to force this requirement to hold.

History

Raze was defined as monadic in A Dictionary of APL in 1987, and added to SHARP APL in version 20, released in 1989.[1] It appears in J's initial 1990 release as }. (that is, also paired with Drop) but was moved to ; in 1991.[2] The glyph is used instead in A+.

External links

Documentation

References

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