Changes

Jump to navigation Jump to search

Readability

653 bytes added, 08:04, 27 September 2020
r←(+/x×y)÷(xVar×yVar)×0.5</pre>
This also avoids reusing variable names, and thus ensures that the code can be rerun from any point. The chosen additional variable names are still short, but quite indicative of what they signify ([[wikipedia:variance|variance]]). Finally, the <source lang=apl inline>.5</source> is expanded to <source lang=apl inline>0.5</source> which helps to clarify that this is a decimal number and not an [[inner product]].
 
A more modern approach breaks out the symmetry into a utility function [[train]], and uses [[leading axis theory]] combined with [[operator]]s and reordering of terms to avoid parentheses (which would otherwise require a mental stack to understand). Finally, the correlation coefficient is defined as a stand-alone function, using [[inner product]] to combine [[sum]]mation with [[multiply|multiplication]]
<source lang=apl>Var←+/2*⍨⊢-+⌿÷≢
R←2×+.×÷×⍥Var
r←x R y</source>
Note that <source lang=apl inline>+⌿÷≢</source> is an [[idiom]] (common phrase) and is read as ''average'' by even moderately experienced APL programmers.
=== IBM ===

Navigation menu