http://wiki.nars2000.org/api.php?action=feedcontributions&user=Sudleyplace&feedformat=atomNARS2000 - User contributions [en]2024-03-28T09:01:40ZUser contributionsMediaWiki 1.38.4http://wiki.nars2000.org/index.php?title=Ball_Arithmetic&diff=3377Ball Arithmetic2018-10-26T20:02:29Z<p>Sudleyplace: /* Distract */</p>
<hr />
<div>==Introduction==<br />
<br />
Ball<ref name="BallArithmetic">NARS2000 Wiki, [http://arblib.org Ball Arithmetic]</ref> and Interval Arithmetic<ref name="IntervalArithmetic">Wikipedia, [https://en.wikipedia.org/wiki/Interval_arithmetic Interval Arithmetic]</ref> both refer to the same idea of calculating with arbitrary precision inexact numbers &mdash; that is, with a range of floating point values instead of a single representative. This allows such numbers to reflect their inexactness explicitly.<br />
<br />
"The most common use is to keep track of and handle rounding errors directly during the calculation and of uncertainties in the knowledge of the exact values of physical and technical parameters. The latter often arise from measurement errors and tolerances for components or '''due to limits on computational accuracy'''. Interval arithmetic also helps find reliable and guaranteed solutions to equations and optimization problems."<ref name="IntervalArithmetic" /><br />
<br />
The difference between the two is in how each approach represents its values: Interval Arithmetic uses the two ends of the interval <apll>[a, b]</apll> whereas Ball Arithmetic uses a Ball with a Midpoint and Radius. Each has its advantages. Interval Arithmetic is implemented by several libraries such as MPFI<ref name="MPFI">[http://perso.ens-lyon.fr/nathalie.revol/software.html MPFI]</ref> and Ball Arithmetic is implemented by ARB<ref name="BallArithmetic" />.<br />
<br />
This feature uses the ARB<ref name="BallArithmetic" /> library to implement Ball Arithmetic.<br />
<br />
==Environment==<br />
<br />
In the examples below, unless otherwise specified, the precision of multi-precision floating-point numbers is set to <apll>53</apll> bits via <apll>⎕FPC←53</apll> which is the same precision as standard double-precision numbers. The Printing Precision is set to <apll>17</apll> digits via <apll>⎕PP←17</apll> so as to display the maximum number of significant digits at <apll>53</apll> bits of precision. The Comparison Tolerance is set via <apll>⎕CT←1<_E/>¯10</apll>.<br />
<br />
==Calculating With Ball Arithmetic==<br />
<br />
If you have ever entered an expression such as<br />
<br />
<apll><pre><br />
÷3<br />
0.3333333333333333<br />
</pre></apll><br />
<br />
undoubtedly, you are aware that the result is inexact. Moreover, as you incorporate into your code the many other functions that produce inexact numbers, you should be wondering "How does the accumulation of inexactness affect my results?".<br />
<br />
The answer to that question lies in the province of [https://en.wikipedia.org/wiki/Numerical_analysis Numerical Analysis] where it is described as "the study of algorithms that use numerical approximation". In general, applying the techniques of Numerical Analysis often involves time-consuming analysis. Fortunately, Ball Arithmetic is an easy to use alternative to that. That is, instead of analyzing the algorithm, run the algorithm with all calculations done with Ball Arithmetic.<br />
<br />
Here is the same expression in Ball Arithmetic (use Alt-‘q’ or Ctrl-‘q’, depending on your keyboard layout, to enter the <apll><_pom/></apll> symbol):<br />
<br />
<apll><pre><br />
÷3<_pom/><br />
0.3333333333333333<_pom/>5.6<_E/>¯17<br />
</pre></apll><br />
<br />
Essentially, each Ball Arithmetic number carries with it an explicit Radius that describes the interval which contains the true value. Because Ball Arithmetic data propagates throughout a calculation and is never demoted to a lower datatype, its advantage is that after each operation the resulting Ball reliably includes the true answer. Across an entire algorithm, the final result is a Ball that indicates explicitly how precise it is, thus eliminating the guesswork as to the effect on the algorithm of the inexactness of the input and any other inexact constants used.<br />
<br />
For example,<br />
<br />
<apll><pre><br />
sqrt←{⍺←= ⋄ {0.5×⍵+⍺÷⍵}⍣⍺⍨⍵} ⍝ Calculate square root using Newton's method<br />
√2<_pom/><br />
1.414213562373095<_pom/>2.2<_E/>¯16<br />
sqrt 2<_pom/><br />
1.414213562373095<_pom/>1.1<_E/>¯15 <br />
10 sqrt 2<_pom/><br />
1.414213562373095<_pom/>2.8<_E/>¯15 <br />
100 sqrt 2<_pom/><br />
1.414213562373095<_pom/>3.3<_E/>¯14 <br />
1000 sqrt 2<_pom/><br />
1.414213562373095<_pom/>3.3<_E/>¯13 <br />
10000 sqrt 2<_pom/><br />
1.414213562373095<_pom/>3.5<_E/>¯12<br />
</pre></apll><br />
<br />
As you can see, after a few iterations, the accuracy of the result doesn't improve. However, because it is an iterative algorithm, the precision worsens as the number of iterations increases. Only by using Ball Arithmetic can you see just how the precision of the result is affected.<br />
<br />
To demonstrate with an extreme example, consider the following function:<br />
<br />
<apll><pre><br />
f←{⍪⍵-3√(⍵*3)-⍵*2}<br />
f 10*3×⍳5<br />
0.33344450621439137<br />
0.3333334452472627 <br />
0.33333444595336914<br />
0.3348388671875 <br />
2.25<br />
</pre></apll><br />
<br />
Without knowing much about this ([https://en.wikipedia.org/wiki/Condition_number ill-conditioned]) algorithm, you have no reason to suspect these results. As it turns out, there's a mathematical proof that as the argument increases to infinity, the algorithm converges to <apll>÷3</apll>. Only when you calculate with Ball Arithmetic do you see that there is a problem:<br />
<br />
<apll><pre><br />
f 10*3×⍳5<_pom/><br />
0.3334445062153009<_pom/>2.2<_E/>¯12 <br />
0.3333334461785853<_pom/>4.3<_E/>¯9 <br />
0.333337664604187<_pom/>0.0000062<br />
0.3385009765625<_pom/>0.0085<br />
1.25<_pom/>5<br />
</pre></apll><br />
<br />
As you can see, the precision worsens quickly to the point where the result is meaningless. The last line even says that the answer lies somewhere between <apll>¯3.75</apll> and <apll>6.25</apll>. In other words, that answer is so '''imprecise''' as to be '''inaccurate'''! At higher powers of ten, the answers only worsen.<br />
<br />
The good news with Ball Arithmetic is that if you need greater precision, just increase the value of <apll>⎕FPC</apll>. For example,<br />
<br />
<apll><pre><br />
⎕FPC←128 ⋄ ⎕PP←40<br />
sqrt 2<_pom/><br />
1.41421356237309504880168872420969807857<_pom/>5.9<_E/>¯39<br />
</pre></apll><br />
<br />
In the case of an ill-conditioned algorithm, we just push the problem off a bit, but not very far &mdash; the problem is that the algorithm requires infinite precision:<br />
<br />
<apll><pre><br />
f 10*3×⍳10<_pom/><br />
0.333444506214021971364848444464298690637<_pom/>3.4<_E/>¯35<br />
0.333333444444506172880658466392407138179<_pom/>1.1<_E/>¯31<br />
0.333333333444444444506172839632668381652<_pom/>1.6<_E/>¯28<br />
0.333333333333444444444444547458328123363<_pom/>2.2<_E/>¯25<br />
0.333333333333333444444619474517508476812<_pom/>3.2<_E/>¯22<br />
0.333333333333333333552432522356445687706<_pom/>1.3<_E/>¯19<br />
0.333333333333333491771410805881714622956<_pom/>4.5<_E/>¯16<br />
0.333333333333417414223731611855328083038<_pom/>4.5<_E/>¯13<br />
0.33333333363771089352667331695556640625<_pom/>4.5<_E/>¯10 <br />
0.3333334587514400482177734375<_pom/>2.6<_E/>¯7<br />
</pre></apll><br />
<br />
While your floating point code might not be so ill-conditioned, the only way to be sure of its results is one of<br />
<br />
<ul><br />
<li>Hire a Numerical Analyst</li><br />
<li>Become a Numerical Analyst</li><br />
<li>Use Ball Arithmetic</li><br />
</ul><br />
<br />
==Ball Arithmetic Numbers==<br />
<br />
A Ball Arithmetic number consist of two parts: a Midpoint and Radius. The Midpoint value represents the middle of the Ball and the Radius represents the distance around the Ball of possible values. There is no way to tell which value in the Ball is the correct answer &mdash; you should assume that all values are potential candidates. <br />
<br />
The precision at which the Midpoint and Radius are stored depends upon the current value of <apll>⎕FPC</apll>. For example, the following display<br />
<br />
<apll><pre><br />
⎕FPC←53<br />
÷3<_pom/><br />
0.3333333333333333<_pom/>5.6<_E/>¯17<br />
</pre></apll><br />
<br />
indicates that the number <apll>÷3<_pom/></apll> has a Midpoint of <apll>0.3333333333333333</apll> at <apll>53</apll>-bit precision and a Radius of <apll>5.6<_E/>¯17</apll>. The Midpoint is stored as a variable precision number, and the Radius is stored as a low-precision number.<br />
<br />
Alternatively,<br />
<br />
<apll><pre><br />
⎕FPC←128 ⋄ ⎕PP←40<br />
÷3<_pom/><br />
0.333333333333333333333333333333333333332<_pom/>1.5<_E/>¯39<br />
</pre></apll><br />
<br />
shows the corresponding value at a higher precision and correspondingly narrower Radius.<br />
<br />
<p><br />
The approximate number of digits of precision for a given value of <apll>⎕FPC</apll> is about <apll>10⍟2*⎕FPC</apll>. The value of <apll>⎕FPC</apll> for a given required precision is about <apll>⌈2⍟10*digits</apll>.<br />
</p><br />
<br />
<p><br />
The current <apll>⎕FPC</apll> precision<br />
should be sufficient to cover both the midpoint and the radius<br />
of all ball numbers being used.<br />
Otherwise,<br />
some results might be misleading.<br />
</p><br />
<br />
<p><br />
For example,<br />
</p><br />
<p><apll><br />
2v*⎕fpc←128<br />
3.402823669E38<br />
⍟ ⎕← * 1±1e¯1000<br />
2.718281828±1.2E¯38<br />
1±7.3E¯39<br />
</apll></p><br />
<br />
<p><br />
What happened? -- <apll>⎕FPC</apll> was too small!<br />
</p><br />
<br />
<p><apll><br />
2v*⎕fpc←4096<br />
1.044388881E1233<br />
⍟ ⎕← * 1±1e¯1000<br />
2.718281828±2.7E¯1000<br />
1±1E¯1000<br />
</apll></p><br />
<br />
<p> </p><br />
<br />
A Ball describes a range of '''variable-precision floating point numbers''', and so the expression <apll>23<_pom/>1</apll> represents the set of Real numbers between <apll>22</apll> and <apll>24</apll>, inclusive, '''not''' the three integers <apll>22</apll>, <apll>23</apll>, <apll>24</apll>.<br />
<br />
<p class="note" style=" background-color:lightcyan;">In general, suffix notation on Ball Arithmetic constants should be sufficient for '''almost all purposes'''. That is, the Radius is already correctly calculated for constants such as <apll>23<_pom/></apll> whose Radius is zero, and <apll>1.2<_pom/></apll> whose Radius at <apll>53</apll> bits of precision is on the order of <apll>2*¯53</apll> (because of the inexactness of the Midpoint <apll>1.2</apll>) which displays as <apll>1.2<_pom/>2.2<_E/>¯16</apll>. Although the input notation supports it, the need to override the default Radius should be '''quite rare'''.</p><br />
<br />
==New Functions and Operator==<br />
<br />
===Functions To Convert To And From Ball Arithmetic Numbers===<br />
<br />
A Ball Arithmetic constant number may be created through notation (as seen above). Otherwise, a Ball Arithmetic number also may be created from its constituent parts under program control with a new primitive function '''Contract''', and separated into its constituent parts with a new primitive function '''Distract'''.<br />
<br />
====Contract====<br />
<br />
'''Contract''' is a monadic function (<apll>≤R</apll>) whose right argument is a Real array. It may be used to create a Ball Arithmetic number from the one- or two-elements of its Real number Midpoint and (optional) Real number Radius. The Axis Operator may specify any length <apll>1</apll> or <apll>2</apll> coordinate along which the conversion takes place. It converts the first element along the specified dimension to the Midpoint of the result and (if present) the second element to its Radius. If the second element is not present (i.e., length <apll>1</apll> coordinate), the Radius used is calculated from the precision of the Midpoint.<br />
<br />
<apll><pre><br />
≤23<br />
23<br />
≤1.2<br />
1.2<_pom/>1.1<_E/>¯16<br />
≤1.3 1<_E/>¯20<br />
1.3<_pom/>1<_E/>¯20<br />
≤1r2 1<_E/>¯20<br />
0.5<_pom/>1<_E/>¯20<br />
≤○1<br />
3.141592653589793<_pom/>1.1<_E/>¯16 <br />
≤(○1) 1<_E/>¯20<br />
3.141592653589793<_pom/>1<_E/>¯20 <br />
</pre></apll><br />
<br />
The domain of this function is limited to Real numbers. Hypercomplex numbers signal a <apll>DOMAIN ERROR</apll>.<br />
<br />
====Distract====<br />
<br />
'''Distract''' is a monadic function (<apll>≥R</apll>) whose right argument is a Real array. It may be used to separate out a Ball Arithmetic's Midpoint and Radius into two distinct values. The Axis Operator may specify the place where the new length <apll>2</apll> coordinate is to be inserted. The pair of values along this new coordinate are the Midpoint and Radius of the corresponding number from the right argument. If the number can be represented exactly, the Radius is zero.<br />
<br />
<apll><pre><br />
⎕PP←10<br />
≥1.2<br />
1.2 1.1102230246251565<_E/>¯16<br />
≥1.2<_x/><br />
6<_r/>5 0<br />
≥1.2<_v/><br />
1.2 1.110223024625157<_E/>¯16<br />
≥1.2<_pom/><br />
1.2 2.220446049250313<_E/>¯16<br />
≥1.5<br />
1.5 0<br />
≥1.5<_x/><br />
3<_r/>2 0<br />
≥1.5<_v/><br />
1.5 1.110223024625157<_E/>¯16<br />
≥1.5<_pom/><br />
1.5 0<br />
a←(○1<_pom/>)×⍳4<br />
a,'|',≥a<br />
3.141592654<_pom/>4.4<_E/>¯16 | 3.141592654 4.440892148<_E/>¯16<br />
6.283185307<_pom/>8.9<_E/>¯16 | 6.283185307 8.881784296<_E/>¯16<br />
9.424777961<_pom/>1.3<_E/>¯15 | 9.424777961 1.332267643<_E/>¯15<br />
12.56637061<_pom/>1.8<_E/>¯15 | 12.56637061 1.776356859<_E/>¯15<br />
</pre></apll><br />
<br />
These numbers can be represented exactly:<br />
<br />
<apll><pre><br />
≥⍳4<_pom/><br />
1 0<br />
2 0<br />
3 0<br />
4 0<br />
≥[2]⍳4<_pom/><br />
1 0<br />
2 0<br />
3 0<br />
4 0<br />
≥[1]⍳4<_pom/><br />
1 2 3 4<br />
0 0 0 0<br />
</pre></apll><br />
<br />
The domain of this function is limited to Real numbers. Hypercomplex numbers signal a <apll>DOMAIN ERROR</apll>. To see the Midpoint-Radius of a Hypercomplex number, first '''Dilate''' it so as to separate out the coefficients and then apply '''Distract''' to extract the Midpoint-Radius as in <apll>≥&gt;R</apll>.<br />
<br />
For example,<br />
<br />
<apll><pre> x←2<_pom/>0<_i/>0<_pom/>1<br />
≥ x<br />
DOMAIN ERROR<br />
≥ x<br />
∧<br />
≥> x<br />
2 0<br />
0 1<br />
<≤≥> x<br />
2<_pom/>0<_i/>0<_pom/>1<br />
</pre></apll><br />
<br />
====Identities====<br />
<br />
The Contract of the Distract of a number both along the same axis, returns the same number.<br />The Distract of the Contract of a number both along the same length two axis, returns the same number.<br />
<br />
===Operator To Provide Arbitrary Precision Specific Derived Functions===<br />
<br />
The DoubleTilde monadic operator (<apll>≈</apll>, Alt-'Q' or Alt-shift-'q') takes a primitive function as its left operand and produces an arbitrary-precision-specific derived function.<br />
<br />
This operator should be considered preliminary.<br />
<br />
====Conversion Between Balls and Intervals====<br />
<br />
At the moment, the monadic derived function is defined for two primitive functions.<br />
<br />
Because Ball Arithmetic has a close relationship with Interval Arithmetic, it may be desirable to convert between the two forms: Endpoint to Midpoint-Radius and its inverse. The resulting derived function is not scalar.<br />
<br />
For example,<br />
<br />
<apll><pre><br />
x←0<_pom/>∞ 1<_pom/>2<br />
≥≈x<br />
¯∞ ∞<br />
¯1 3<br />
≥[1]≈x<br />
¯∞ ¯1<br />
∞ 3<br />
≥[2]≈x<br />
¯∞ ∞<br />
¯1 3<br />
≤≈≥≈x<br />
0<_pom/>∞ 1<_pom/>2<br />
≤≈≥[2]≈x<br />
0<_pom/>∞ 1<_pom/>2<br />
≤[2]≈≥≈x<br />
0<_pom/>∞ 1<_pom/>2<br />
≤[2]≈≥[2]≈x<br />
0<_pom/>∞ 1<_pom/>2 <br />
≤[1]≈≥[1]≈x<br />
0<_pom/>∞ 1<_pom/>2 <br />
</pre></apll><br />
<br />
The domain of these functions is limited to Real numbers. Hypercomplex numbers signal a <apll>DOMAIN ERROR</apll>. To see the Endpoints of a Hypercomplex number, first '''Dilate''' it so as to separate out the coefficients and then apply <apll>≥≈</apll> to extract the Endpoints as in <apll>≥≈&gt;R</apll>.<br />
<br />
For example,<br />
<br />
<apll><pre> ≥≈ 2±0i0±1<br />
DOMAIN ERROR<br />
≥≈ 2±0i0±1<br />
∧<br />
≥≈>2±0i0±1<br />
2 2<br />
¯1 1<br />
<≤≈≥≈>2±0i0±1<br />
2±0i0±1<br />
</pre></apll><br />
<br />
====Union and Intersection of Balls====<br />
<br />
The left operand of the DoubleTilde operator is defined for the '''Union''' and '''Intersection''' functions (<apll>∪∩</apll>) as follows: <br />
<br />
Because Ball arithmetic numbers represent a range of floating point numbers, at times it is desirable to produce their Union or Intersection.<br />
<br />
For example,<br />
<br />
<apll><pre><br />
x←0.5<pom/>0.5 ⍝ The interval [0,1]<br />
x∪≈x+2 ⍝ The interval [0,1] ∪ [2,3] ←→ [0,3]<br />
1.5<pom/>1.5<br />
x∪≈x+1 ⍝ The interval [0,1] ∪ [1,2] ←→ [0,2]<br />
1<pom/>1 <br />
x∩≈x+1 ⍝ The interval [0,1] ∩ [1,2] ←→ [1,1]<br />
1<br />
</pre></apll><br />
<br />
If two Balls have no points in common, the result is a NaN (<apll>∅</apll>):<br />
<br />
<apll><pre><br />
x∩≈x+1.1 ⍝ The interval [0,1] ∩ [1.1,2.1] ←→ ∅<br />
∅<br />
</pre></apll><br />
<br />
The identity element for <apll>∩≈</apll> is <apll>0±∞</apll>.<br />
<br />
The derived functions are scalar.<br />
<br />
====Comparison Functions====<br />
<br />
The left operand of the DoubleTilde operator is defined for the six comparison functions (<apll>&lt;≤=≥&gt;≠</apll>) as follows:<br />
<br />
For <apll><i>f</i></apll> as one of the above six functions, <apll>L<i>f</i>≈R</apll> is TRUE iff for all <apll>t∊L</apll> and <apll>u∊R</apll>, then <apll>&nbsp;&nbsp;t f u&nbsp;&nbsp;</apll> is TRUE. These comparisons are all done with <apll>⎕CT←0</apll> because, in a sense, Ball comparisons carry their own Fuzz.<br />
<br />
For example,<br />
<br />
<apll><pre> (L R)←4<_pom/>1 6<_pom/>1<br />
L<≈R<br />
0<br />
L≤≈R<br />
1<br />
</pre></apll><br />
<br />
The derived functions are scalar.<br />
<br />
====Containing Functions====<br />
<br />
The left operand of the DoubleTilde operator is defined for two containing functions (<apll>⊂⊃</apll>) as follows:<br />
<br />
The expression <apll>L⊂≈R</apll> is TRUE iff for all <apll>t∊L</apll> it is TRUE that <apll>t∊R</apll> and that the containment is strict &mdash; that is, none of the endpoints match.<br />
<br />
The expression <apll>L⊃≈R</apll> is TRUE iff <apll>R⊂≈L</apll> is TRUE.<br />
<br />
For example,<br />
<br />
<apll><pre><br />
(L R)←6±4 6±2<br />
L⊃≈R<br />
1<br />
R⊂≈L<br />
1<br />
</pre></apll><br />
<br />
The derived functions are scalar.<br />
<br />
====Positional Relationships====<br />
<br />
For <apll>L</apll> and <apll>R</apll> as finite intervals with non-zero Radii (i.e., multi-valued), here are the possible '''Relative Positions''' between the two Intervals, where <apll>L0</apll>, <apll>L1</apll> and <apll>R0</apll>, <apll>R1</apll> are the endpoints of <apll>L</apll> and <apll>R</apll>, respectively &mdash; <apll>(L0 L1)←≥≈L</apll> and <apll>(R0 R1)←≥≈R</apll>:<br />
<br />
<table border="1" cellspacing="0" rowspacing="5" style="font-family:APL385, SImPL;"><br />
<th>Relative<br/>Positions</th><br />
<th>Endpoint<br/>Relationships</th><br />
<th colspan="2">Defining<br/>Expressions</th><br />
<th>Sample Data<br/>L &nbsp; R</th><br />
<th>Distinct<br/>Ball<br/>{⍺∘≈⍵}</th><br />
<br />
<tr><br />
<td>&nbsp;├──L──┤<br/>&nbsp;├──R──┤&nbsp;</td><br />
<td>&nbsp;L0 L1≡R0 R1&nbsp;</td><br />
<td>&nbsp;L=≈R&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 6<_pom/>4&nbsp;</td><br />
<td>&nbsp;&nbsp;0&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──L──┤<br/>&nbsp;├──R─┤&nbsp;</td><br />
<td>&nbsp;(L0=R0)∧L1&gt;R1&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 5<_pom/>3&nbsp;</td><br />
<td>&nbsp;&nbsp;1&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──L─┤<br/>&nbsp;├──R──┤&nbsp;</td><br />
<td>&nbsp;(L0=R0)∧L1&lt;R1&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 7<_pom/>5&nbsp;</td><br />
<td>&nbsp;¯1&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──L──┤<br/>&nbsp;&nbsp;├──R─┤&nbsp;</td><br />
<td>&nbsp;(L0&lt;R0)∧L1=R1&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 7<_pom/>3&nbsp;</td><br />
<td>&nbsp;&nbsp;2&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;&nbsp;├──L─┤<br/>&nbsp;├──R──┤&nbsp;</td><br />
<td>&nbsp;(L0&gt;R0)∧L1=R1&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 5<_pom/>5&nbsp;</td><br />
<td>&nbsp;¯2&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──L──┤<br/>&nbsp;&nbsp;├─R─┤&nbsp;</td><br />
<td>&nbsp;(L0&lt;R0)∧L1&gt;R1&nbsp;</td><br />
<td>&nbsp;L⊃≈R&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 6<_pom/>2&nbsp;</td><br />
<td>&nbsp;&nbsp;3&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;&nbsp;├─L─┤<br/>&nbsp;├──R──┤&nbsp;</td><br />
<td>&nbsp;(L0&gt;R0)∧L1&lt;R1&nbsp;</td><br />
<td>&nbsp;L⊂≈R&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 6<_pom/>6&nbsp;</td><br />
<td>&nbsp;¯3&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──L──┤<br/>&nbsp;&nbsp;├──R──┤&nbsp;</td><br />
<td>&nbsp;(L0&lt;R0)∧(L1&lt;R1)∧L1&gt;R0&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 8<_pom/>4&nbsp;</td><br />
<td>&nbsp;&nbsp;4&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;&nbsp;├──L──┤<br/>&nbsp;├──R──┤&nbsp;</td><br />
<td>&nbsp;(L0&gt;R0)∧(L1&gt;R1)∧L0&lt;R1&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 4<_pom/>4&nbsp;</td><br />
<td>&nbsp;¯4&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──L──┼──R──┤&nbsp;</td><br />
<td>&nbsp;L1=R0&nbsp;</td><br />
<td>&nbsp;(L≤≈R)&gt;L&lt;≈R&nbsp;</td><br />
<td>&nbsp;L=∀R&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 14<_pom/>4&nbsp;</td><br />
<td>&nbsp;&nbsp;5&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──R──┼──L──┤&nbsp;</td><br />
<td>&nbsp;L0=R1&nbsp;</td><br />
<td>&nbsp;(L≥≈R)&gt;L&gt;≈R&nbsp;</td><br />
<td>&nbsp;L=∃R&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 0<_pom/>2&nbsp;</td><br />
<td>&nbsp;¯5&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──L──┤&nbsp;├──R──┤&nbsp;</td><br />
<td>&nbsp;L1&lt;R0&nbsp;</td><br />
<td>&nbsp;L&lt;≈R&nbsp;</td><br />
<td>&nbsp;L&lt;∀R&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 17<_pom/>5&nbsp;</td><br />
<td>&nbsp;&nbsp;6&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──R──┤&nbsp;├──L──┤&nbsp;</td><br />
<td>&nbsp;L0&gt;R1&nbsp;</td><br />
<td>&nbsp;L&gt;≈R&nbsp;</td><br />
<td>&nbsp;L&gt;∃R&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 0<_pom/>1&nbsp;</td><br />
<td>&nbsp;¯6&nbsp;</td><br />
</tr><br />
</table><br />
<br />
The above table can be interpreted as follows:<br />
<br />
<ul><br />
<li>The first column lists all possible '''Relative Positions''' two finite non-zero Radii (i.e., multi-valued) Balls may assume.</li><br />
<li>The second column lists the '''Endpoint Relationship''' that defines the corresponding '''Relative Position'''.</li><br />
<li>The third column lists a '''Defining Expression''' using the '''DoubleTilde''' operator that is TRUE for the corresponding '''Relative Position''' and FALSE for all of the other '''Relative Positions''' in different rows.</li><br />
<li>The fourth column lists a '''Defining Expression''' using the '''Always''' and '''Possibly''' operators [http://forum.nars2000.org/ball-arithmetic-t614.html#p1803 proposed] by David Rabenhorst.</li><br />
<li>The fifth column contains '''Sample Data''' that defines the corresponding '''Relative Position'''.</li><br />
<li>The sixth column gives the value of the '''Distinct Ball''' function <apll>{⍺∘≈⍵}</apll> when executed on the '''Sample Data'''.</li><br />
</ul><br />
<br />
Note the table is organized such that apart from the first row (whose '''Endpoint Relationship''' is Symmetric in <apll>L</apll> and <apll>R</apll>) the rows occur in six pairs where the '''Endpoint Relationship''' for each row in the pair can be obtained from the other by swapping <apll>L</apll> and <apll>R</apll>. The pairs of rows are ordered roughly by the amount of overlap between the two Balls.<br />
<br />
As you can see, we are missing '''Defining Expressions''' for several of the '''Relative Positions'''. I was hoping that this table would be filled in with more detail so it would serve as a measure of whether or not we had a complete set of functions/operators which could be used to tell apart all of the '''Relative Positions''' without having to resort to the '''Distinct Ball''' function <apll>{⍺∘≈⍵}</apll> constructed explicitly for this purpose. Please add to this table if you find a missing expression, or wish to propose whole new functions and/or operators.<br />
<br />
If you would like to try a '''Defining Expression''' on the '''Sample Data''', collect the data into a <apll>13</apll> by <apll>2</apll> matrix, put your '''Defining Expression''' into (say) an Anonymous Function and reduce the same data matrix along the last coordinate &mdash; if you have a successful function, you should see a <apll>13</apll>-element Boolean vector with a single one in it. For example,<br />
<br />
<apll><pre><br />
sd←6<_pom/>4,⍪6<_pom/>4 5<_pom/>3 7<_pom/>5 7<_pom/>3 5<_pom/>5 6<_pom/>2 6<_pom/>6 8<_pom/>4 4<_pom/>4 14<_pom/>4 0<_pom/>2 17<_pom/>5 0<_pom/>1<br />
{(⍺≤≈⍵)>⍺<≈⍵}/sd<br />
0 0 0 0 0 0 0 0 0 1 0 0 0 <br />
{(⍺≥≈⍵)>⍺>≈⍵}/sd<br />
0 0 0 0 0 0 0 0 0 0 1 0 0 <br />
{⍺<≈⍵}/sd<br />
0 0 0 0 0 0 0 0 0 0 0 1 0 <br />
{⍺>≈⍵}/sd<br />
0 0 0 0 0 0 0 0 0 0 0 0 1<br />
</pre></apll><br />
<br />
Finally, the following example shows that the '''Sample Data''' are all distinct:<br />
<br />
<apll><pre><br />
{⍺∘≈⍵}/sd<br />
0 1 ¯1 2 ¯2 3 ¯3 4 ¯4 5 ¯5 6 ¯6<br />
</pre></apll><br />
<br />
==Hypercomplex Ball Arithmetic==<br />
<br />
Ball Arithmetic also extends to all Hypercomplex numbers (Complex, Quaternion, and Octonion) such as <apll>1.2<_pom/><_i/>2.2</apll> which represents a Complex Ball Arithmetic number whose '''Real''' part is <apll>1.2<_pom/></apll> and whose '''Imaginary''' part is <apll>2.2<_pom/></apll>. Note that the display of that number (at <apll>53</apll> bits of precision)<br />
<br />
<apll><pre><br />
1.2<_pom/><_i/>2.2<br />
1.2<_pom/>2.2<_E/>¯16<_i/>2.2<_pom/>4.4<_E/>¯16<br />
</pre></apll><br />
<br />
demonstrates the inexactness of both floating point coefficients.<br />
<br />
==Small v. Large Radii==<br />
<br />
Ball Arithmetic works best when given small Radii, that is, small relative to the Midpoint. Calculations on large Radii numbers such as <apll>0<_i/>0.5<_pom/>0.5</apll> don't always produce useful results. For example,<br />
<br />
<apll><pre><br />
⎕PP←8 ⍝ To reduce fractional clutter<br />
x←0<_i/>0.5<_pom/>0.5<br />
√x<br />
0.4267767<_pom/>0.57<_i/>0<_pom/>1.4<br />
</pre></apll><br />
<br />
Unfortunately in this case, because the Radius is so large it overwhelms the Midpoint, as can be seen when we Square the Square Root:<br />
<br />
<apll><pre><br />
(√x)*2<br />
0.18213835<_pom/>2.8<_i/>0<_pom/>2.8<br />
x=(√x)*2<br />
0<br />
</pre></apll><br />
<br />
These calculations work better using smaller Radii, such as<br />
<br />
<apll><pre><br />
y←0<_i/>0.5<_pom/>0.5<_E/>¯30<br />
√y<br />
0.5<_pom/>2.5<_E/>¯31<_i/>0.5<_pom/>7.5<_E/>¯31<br />
(√y)*2<br />
0<_pom/>1<_E/>¯30<_i/>0.5<_pom/>1<_E/>¯30 <br />
y=(√y)*2<br />
1<br />
</pre></apll><br />
<br />
where Square Root now returns a meaningful result, and its Square returns the original value.<br />
<br />
==Mixed Notation==<br />
<br />
The notation for Ball Arithmetic may be combined with other Point Notations in many ways, such as<br />
<br />
<apll><pre><br />
1<_p/>1<_pom/><br />
3.141592653589793<_pom/>4.4<_E/>¯16 <br />
1<_x/>1<_pom/><br />
2.718281828459045<_pom/>4.5<_E/>¯16<br />
</pre></apll><br />
<br />
For more details about combining different forms of Point Notation, see [[Point_Notation|Point Notation]] and in particular the section on [[Point_Notation#Mixed_Notation|Mixed Notation]].<br />
<br />
==Implementation==<br />
<br />
===Datataypes===<br />
<br />
This feature adds four new datatypes to the language: one each for the four Division Algebras. Note that marking any one of the Hypercomplex coefficients as a Ball automatically marks them all as Balls.<br />
{|<br />
|-<br />
|Real||&nbsp;&nbsp;&nbsp;&nbsp;<apll>23<_pom/></apll> or <apll>1.2<_pom/></apll><br />
|-<br />
|Complex||&nbsp;&nbsp;&nbsp;&nbsp;<apll>23<_i/>1.2<_pom/></apll><br />
|-<br />
|Quaternion||&nbsp;&nbsp;&nbsp;&nbsp;<apll>23<_i/>1.2<_j/>0.5<_k/>¯3.14<_pom/></apll><br />
|-<br />
|Octonion||&nbsp;&nbsp;&nbsp;&nbsp;<apll>23<_i/>1.2<_j/>0.5<_k/>¯3.14<l/>¯3<_ij/>19<_jk/>¯3<_kl/>6<_pom/></apll><br />
|}<br />
<br />
===Primitive Functions===<br />
<br />
As described above, this feature adds two new monadic primitive functions '''Contract''' (<apll>≤R</apll>) and its inverse '''Distract''' (<apll>≥R</apll>), along with one new monadic primitive operator '''DoubleTilde''' <apll>f≈ R</apll> and <apll>L f≈ R</apll>.<br />
<br />
All primitive and system functions and operators are extended to work with Ball Arithmetic, so you can test out this feature on all algorithms, with the exception of trying to find the Factorial of a multiple-precision/Ball Arithmetic Hypercomplex number, in which case you are temporarily out of luck.<br />
<br />
==Workspace Version Number==<br />
<br />
For the moment, if you save a workspace which contains a Ball Arithmetic number in a variable, the workspace version number is <apll>0.03</apll>. Otherwise, the version number is <apll>0.02</apll>. Workspaces with Ball Arithmetic Numbers may not be loaded by an earlier version of the interpreter.<br />
<br />
==Pending Design Decisions==<br />
<br />
<ul><br />
<li>The direct comparison functions (<apll>&lt;≤=≥&gt;≠≡≢</apll>) and indirect ones (<apll>⍳⍸∊⍷⍒⍋</apll>) are currently implemented to compare the Midpoints of the arguments ignoring the Radius &mdash; this may change.</li><br />
<li>The Floor function and its related functions (Ceiling, Residue, GCD, LCM, and Encode) are currently implemented to execute on the Midpoints of the arguments ignoring the Radius &mdash; this may change.</li><br />
<li>We need new primitives to describe the different ways in which Balls can intersect/overlap, possibly through a new monadic operator (perhaps &#x2248;) on the existing direct and indirect comparison and Floor-related functions.</li><br />
<li>Certain primitives are defined on limited ranges, and sometimes multiple ranges where it might use different algorithms for different ranges (e.g. <apll>L!R</apll>). There are open questions about how to handle a Ball that spans two or more of these ranges as to how to calculate the result.</li><br />
<li>Infinity and NaN have not been given any special treatment as yet. The results are whatever ARB has chosen which we may need to override.</li><br />
</ul><br />
<br />
==Download==<br />
<br />
This feature is available as an Alpha release &mdash; it may be downloaded from the [http://www.nars2000.org/download/binaries/alpha/ Alpha] release directory.<br />
<br />
==Acknowledgements==<br />
<br />
<ul><br />
<li>The Arb team has contributed their Ball Arithmetic<ref name="BallArithmetic" /> code which made this feature possible.</li><br />
<li>David Rabenhorst has contributed many very useful ideas and many hours debugging the implementation.</li><br />
</ul><br />
<br />
==References==<br />
<br />
<references /></div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=Ball_Arithmetic&diff=3376Ball Arithmetic2018-10-26T19:54:23Z<p>Sudleyplace: /* Distract */</p>
<hr />
<div>==Introduction==<br />
<br />
Ball<ref name="BallArithmetic">NARS2000 Wiki, [http://arblib.org Ball Arithmetic]</ref> and Interval Arithmetic<ref name="IntervalArithmetic">Wikipedia, [https://en.wikipedia.org/wiki/Interval_arithmetic Interval Arithmetic]</ref> both refer to the same idea of calculating with arbitrary precision inexact numbers &mdash; that is, with a range of floating point values instead of a single representative. This allows such numbers to reflect their inexactness explicitly.<br />
<br />
"The most common use is to keep track of and handle rounding errors directly during the calculation and of uncertainties in the knowledge of the exact values of physical and technical parameters. The latter often arise from measurement errors and tolerances for components or '''due to limits on computational accuracy'''. Interval arithmetic also helps find reliable and guaranteed solutions to equations and optimization problems."<ref name="IntervalArithmetic" /><br />
<br />
The difference between the two is in how each approach represents its values: Interval Arithmetic uses the two ends of the interval <apll>[a, b]</apll> whereas Ball Arithmetic uses a Ball with a Midpoint and Radius. Each has its advantages. Interval Arithmetic is implemented by several libraries such as MPFI<ref name="MPFI">[http://perso.ens-lyon.fr/nathalie.revol/software.html MPFI]</ref> and Ball Arithmetic is implemented by ARB<ref name="BallArithmetic" />.<br />
<br />
This feature uses the ARB<ref name="BallArithmetic" /> library to implement Ball Arithmetic.<br />
<br />
==Environment==<br />
<br />
In the examples below, unless otherwise specified, the precision of multi-precision floating-point numbers is set to <apll>53</apll> bits via <apll>⎕FPC←53</apll> which is the same precision as standard double-precision numbers. The Printing Precision is set to <apll>17</apll> digits via <apll>⎕PP←17</apll> so as to display the maximum number of significant digits at <apll>53</apll> bits of precision. The Comparison Tolerance is set via <apll>⎕CT←1<_E/>¯10</apll>.<br />
<br />
==Calculating With Ball Arithmetic==<br />
<br />
If you have ever entered an expression such as<br />
<br />
<apll><pre><br />
÷3<br />
0.3333333333333333<br />
</pre></apll><br />
<br />
undoubtedly, you are aware that the result is inexact. Moreover, as you incorporate into your code the many other functions that produce inexact numbers, you should be wondering "How does the accumulation of inexactness affect my results?".<br />
<br />
The answer to that question lies in the province of [https://en.wikipedia.org/wiki/Numerical_analysis Numerical Analysis] where it is described as "the study of algorithms that use numerical approximation". In general, applying the techniques of Numerical Analysis often involves time-consuming analysis. Fortunately, Ball Arithmetic is an easy to use alternative to that. That is, instead of analyzing the algorithm, run the algorithm with all calculations done with Ball Arithmetic.<br />
<br />
Here is the same expression in Ball Arithmetic (use Alt-‘q’ or Ctrl-‘q’, depending on your keyboard layout, to enter the <apll><_pom/></apll> symbol):<br />
<br />
<apll><pre><br />
÷3<_pom/><br />
0.3333333333333333<_pom/>5.6<_E/>¯17<br />
</pre></apll><br />
<br />
Essentially, each Ball Arithmetic number carries with it an explicit Radius that describes the interval which contains the true value. Because Ball Arithmetic data propagates throughout a calculation and is never demoted to a lower datatype, its advantage is that after each operation the resulting Ball reliably includes the true answer. Across an entire algorithm, the final result is a Ball that indicates explicitly how precise it is, thus eliminating the guesswork as to the effect on the algorithm of the inexactness of the input and any other inexact constants used.<br />
<br />
For example,<br />
<br />
<apll><pre><br />
sqrt←{⍺←= ⋄ {0.5×⍵+⍺÷⍵}⍣⍺⍨⍵} ⍝ Calculate square root using Newton's method<br />
√2<_pom/><br />
1.414213562373095<_pom/>2.2<_E/>¯16<br />
sqrt 2<_pom/><br />
1.414213562373095<_pom/>1.1<_E/>¯15 <br />
10 sqrt 2<_pom/><br />
1.414213562373095<_pom/>2.8<_E/>¯15 <br />
100 sqrt 2<_pom/><br />
1.414213562373095<_pom/>3.3<_E/>¯14 <br />
1000 sqrt 2<_pom/><br />
1.414213562373095<_pom/>3.3<_E/>¯13 <br />
10000 sqrt 2<_pom/><br />
1.414213562373095<_pom/>3.5<_E/>¯12<br />
</pre></apll><br />
<br />
As you can see, after a few iterations, the accuracy of the result doesn't improve. However, because it is an iterative algorithm, the precision worsens as the number of iterations increases. Only by using Ball Arithmetic can you see just how the precision of the result is affected.<br />
<br />
To demonstrate with an extreme example, consider the following function:<br />
<br />
<apll><pre><br />
f←{⍪⍵-3√(⍵*3)-⍵*2}<br />
f 10*3×⍳5<br />
0.33344450621439137<br />
0.3333334452472627 <br />
0.33333444595336914<br />
0.3348388671875 <br />
2.25<br />
</pre></apll><br />
<br />
Without knowing much about this ([https://en.wikipedia.org/wiki/Condition_number ill-conditioned]) algorithm, you have no reason to suspect these results. As it turns out, there's a mathematical proof that as the argument increases to infinity, the algorithm converges to <apll>÷3</apll>. Only when you calculate with Ball Arithmetic do you see that there is a problem:<br />
<br />
<apll><pre><br />
f 10*3×⍳5<_pom/><br />
0.3334445062153009<_pom/>2.2<_E/>¯12 <br />
0.3333334461785853<_pom/>4.3<_E/>¯9 <br />
0.333337664604187<_pom/>0.0000062<br />
0.3385009765625<_pom/>0.0085<br />
1.25<_pom/>5<br />
</pre></apll><br />
<br />
As you can see, the precision worsens quickly to the point where the result is meaningless. The last line even says that the answer lies somewhere between <apll>¯3.75</apll> and <apll>6.25</apll>. In other words, that answer is so '''imprecise''' as to be '''inaccurate'''! At higher powers of ten, the answers only worsen.<br />
<br />
The good news with Ball Arithmetic is that if you need greater precision, just increase the value of <apll>⎕FPC</apll>. For example,<br />
<br />
<apll><pre><br />
⎕FPC←128 ⋄ ⎕PP←40<br />
sqrt 2<_pom/><br />
1.41421356237309504880168872420969807857<_pom/>5.9<_E/>¯39<br />
</pre></apll><br />
<br />
In the case of an ill-conditioned algorithm, we just push the problem off a bit, but not very far &mdash; the problem is that the algorithm requires infinite precision:<br />
<br />
<apll><pre><br />
f 10*3×⍳10<_pom/><br />
0.333444506214021971364848444464298690637<_pom/>3.4<_E/>¯35<br />
0.333333444444506172880658466392407138179<_pom/>1.1<_E/>¯31<br />
0.333333333444444444506172839632668381652<_pom/>1.6<_E/>¯28<br />
0.333333333333444444444444547458328123363<_pom/>2.2<_E/>¯25<br />
0.333333333333333444444619474517508476812<_pom/>3.2<_E/>¯22<br />
0.333333333333333333552432522356445687706<_pom/>1.3<_E/>¯19<br />
0.333333333333333491771410805881714622956<_pom/>4.5<_E/>¯16<br />
0.333333333333417414223731611855328083038<_pom/>4.5<_E/>¯13<br />
0.33333333363771089352667331695556640625<_pom/>4.5<_E/>¯10 <br />
0.3333334587514400482177734375<_pom/>2.6<_E/>¯7<br />
</pre></apll><br />
<br />
While your floating point code might not be so ill-conditioned, the only way to be sure of its results is one of<br />
<br />
<ul><br />
<li>Hire a Numerical Analyst</li><br />
<li>Become a Numerical Analyst</li><br />
<li>Use Ball Arithmetic</li><br />
</ul><br />
<br />
==Ball Arithmetic Numbers==<br />
<br />
A Ball Arithmetic number consist of two parts: a Midpoint and Radius. The Midpoint value represents the middle of the Ball and the Radius represents the distance around the Ball of possible values. There is no way to tell which value in the Ball is the correct answer &mdash; you should assume that all values are potential candidates. <br />
<br />
The precision at which the Midpoint and Radius are stored depends upon the current value of <apll>⎕FPC</apll>. For example, the following display<br />
<br />
<apll><pre><br />
⎕FPC←53<br />
÷3<_pom/><br />
0.3333333333333333<_pom/>5.6<_E/>¯17<br />
</pre></apll><br />
<br />
indicates that the number <apll>÷3<_pom/></apll> has a Midpoint of <apll>0.3333333333333333</apll> at <apll>53</apll>-bit precision and a Radius of <apll>5.6<_E/>¯17</apll>. The Midpoint is stored as a variable precision number, and the Radius is stored as a low-precision number.<br />
<br />
Alternatively,<br />
<br />
<apll><pre><br />
⎕FPC←128 ⋄ ⎕PP←40<br />
÷3<_pom/><br />
0.333333333333333333333333333333333333332<_pom/>1.5<_E/>¯39<br />
</pre></apll><br />
<br />
shows the corresponding value at a higher precision and correspondingly narrower Radius.<br />
<br />
<p><br />
The approximate number of digits of precision for a given value of <apll>⎕FPC</apll> is about <apll>10⍟2*⎕FPC</apll>. The value of <apll>⎕FPC</apll> for a given required precision is about <apll>⌈2⍟10*digits</apll>.<br />
</p><br />
<br />
<p><br />
The current <apll>⎕FPC</apll> precision<br />
should be sufficient to cover both the midpoint and the radius<br />
of all ball numbers being used.<br />
Otherwise,<br />
some results might be misleading.<br />
</p><br />
<br />
<p><br />
For example,<br />
</p><br />
<p><apll><br />
2v*⎕fpc←128<br />
3.402823669E38<br />
⍟ ⎕← * 1±1e¯1000<br />
2.718281828±1.2E¯38<br />
1±7.3E¯39<br />
</apll></p><br />
<br />
<p><br />
What happened? -- <apll>⎕FPC</apll> was too small!<br />
</p><br />
<br />
<p><apll><br />
2v*⎕fpc←4096<br />
1.044388881E1233<br />
⍟ ⎕← * 1±1e¯1000<br />
2.718281828±2.7E¯1000<br />
1±1E¯1000<br />
</apll></p><br />
<br />
<p> </p><br />
<br />
A Ball describes a range of '''variable-precision floating point numbers''', and so the expression <apll>23<_pom/>1</apll> represents the set of Real numbers between <apll>22</apll> and <apll>24</apll>, inclusive, '''not''' the three integers <apll>22</apll>, <apll>23</apll>, <apll>24</apll>.<br />
<br />
<p class="note" style=" background-color:lightcyan;">In general, suffix notation on Ball Arithmetic constants should be sufficient for '''almost all purposes'''. That is, the Radius is already correctly calculated for constants such as <apll>23<_pom/></apll> whose Radius is zero, and <apll>1.2<_pom/></apll> whose Radius at <apll>53</apll> bits of precision is on the order of <apll>2*¯53</apll> (because of the inexactness of the Midpoint <apll>1.2</apll>) which displays as <apll>1.2<_pom/>2.2<_E/>¯16</apll>. Although the input notation supports it, the need to override the default Radius should be '''quite rare'''.</p><br />
<br />
==New Functions and Operator==<br />
<br />
===Functions To Convert To And From Ball Arithmetic Numbers===<br />
<br />
A Ball Arithmetic constant number may be created through notation (as seen above). Otherwise, a Ball Arithmetic number also may be created from its constituent parts under program control with a new primitive function '''Contract''', and separated into its constituent parts with a new primitive function '''Distract'''.<br />
<br />
====Contract====<br />
<br />
'''Contract''' is a monadic function (<apll>≤R</apll>) whose right argument is a Real array. It may be used to create a Ball Arithmetic number from the one- or two-elements of its Real number Midpoint and (optional) Real number Radius. The Axis Operator may specify any length <apll>1</apll> or <apll>2</apll> coordinate along which the conversion takes place. It converts the first element along the specified dimension to the Midpoint of the result and (if present) the second element to its Radius. If the second element is not present (i.e., length <apll>1</apll> coordinate), the Radius used is calculated from the precision of the Midpoint.<br />
<br />
<apll><pre><br />
≤23<br />
23<br />
≤1.2<br />
1.2<_pom/>1.1<_E/>¯16<br />
≤1.3 1<_E/>¯20<br />
1.3<_pom/>1<_E/>¯20<br />
≤1r2 1<_E/>¯20<br />
0.5<_pom/>1<_E/>¯20<br />
≤○1<br />
3.141592653589793<_pom/>1.1<_E/>¯16 <br />
≤(○1) 1<_E/>¯20<br />
3.141592653589793<_pom/>1<_E/>¯20 <br />
</pre></apll><br />
<br />
The domain of this function is limited to Real numbers. Hypercomplex numbers signal a <apll>DOMAIN ERROR</apll>.<br />
<br />
====Distract====<br />
<br />
'''Distract''' is a monadic function (<apll>≥R</apll>) whose right argument is a Real array. It may be used to separate out a Ball Arithmetic's Midpoint and Radius into two distinct values. The Axis Operator may specify the place where the new length <apll>2</apll> coordinate is to be inserted. The pair of values along this new coordinate are the Midpoint and Radius of the corresponding number from the right argument. If the number can be represented exactly, the Radius is zero.<br />
<br />
<apll><pre><br />
⎕PP←10<br />
≥1.2<br />
1.2 1.1102230246251565<_E/>¯16<br />
≥1.2<_x/><br />
6<_r/>5 0<br />
≥1.2<_v/><br />
1.2 1.110223024625157<_E/>¯16<br />
≥1.2<_pom/><br />
1.2 2.220446049250313<_E/>¯16<br />
≥1.5<br />
1.5 0<br />
≥1.5<_x/><br />
3<_r/>2 0<br />
≥1.5<_v/><br />
1.5 1.110223024625157<_E/>¯16<br />
≥1.5<_pom/><br />
1.5 0<br />
a←(○1<_pom/>)×⍳4<br />
a,'|',≥a<br />
3.141592654<_pom/>4.4<_E/>¯16 | 3.141592654 4.440892148<_E/>¯16<br />
6.283185307<_pom/>8.9<_E/>¯16 | 6.283185307 8.881784296<_E/>¯16<br />
9.424777961<_pom/>1.3<_E/>¯15 | 9.424777961 1.332267643<_E/>¯15<br />
12.56637061<_pom/>1.8<_E/>¯15 | 12.56637061 1.776356859<_E/>¯15<br />
</pre></apll><br />
<br />
These numbers can be represented exactly:<br />
<br />
<apll><pre><br />
≥⍳4<_pom/><br />
1 0<br />
2 0<br />
3 0<br />
4 0<br />
≥[2]⍳4<_pom/><br />
1 0<br />
2 0<br />
3 0<br />
4 0<br />
≥[1]⍳4<_pom/><br />
1 2 3 4<br />
0 0 0 0<br />
</pre></apll><br />
<br />
The domain of this function is limited to Real numbers. Hypercomplex numbers signal a <apll>DOMAIN ERROR</apll>. To see the Midpoint-radius of a Hypercomplex number, first '''Dilate''' it so as to separate out the coefficients and then apply <apll>≥</apll> to extract the Midpoinit-radius as in <apll>≥&gt;R</apll>.<br />
<br />
For example,<br />
<br />
<apll><pre> ≥ 2±0i0±1<br />
DOMAIN ERROR<br />
≥ 2±0i0±1<br />
∧<br />
≥> 2±0i0±1<br />
2 0<br />
0 1<br />
<≤≥> 2±0i0±1<br />
2±0i0±1<br />
</pre></apll><br />
<br />
====Identities====<br />
<br />
The Contract of the Distract of a number both along the same axis, returns the same number.<br />The Distract of the Contract of a number both along the same length two axis, returns the same number.<br />
<br />
===Operator To Provide Arbitrary Precision Specific Derived Functions===<br />
<br />
The DoubleTilde monadic operator (<apll>≈</apll>, Alt-'Q' or Alt-shift-'q') takes a primitive function as its left operand and produces an arbitrary-precision-specific derived function.<br />
<br />
This operator should be considered preliminary.<br />
<br />
====Conversion Between Balls and Intervals====<br />
<br />
At the moment, the monadic derived function is defined for two primitive functions.<br />
<br />
Because Ball Arithmetic has a close relationship with Interval Arithmetic, it may be desirable to convert between the two forms: Endpoint to Midpoint-Radius and its inverse. The resulting derived function is not scalar.<br />
<br />
For example,<br />
<br />
<apll><pre><br />
x←0<_pom/>∞ 1<_pom/>2<br />
≥≈x<br />
¯∞ ∞<br />
¯1 3<br />
≥[1]≈x<br />
¯∞ ¯1<br />
∞ 3<br />
≥[2]≈x<br />
¯∞ ∞<br />
¯1 3<br />
≤≈≥≈x<br />
0<_pom/>∞ 1<_pom/>2<br />
≤≈≥[2]≈x<br />
0<_pom/>∞ 1<_pom/>2<br />
≤[2]≈≥≈x<br />
0<_pom/>∞ 1<_pom/>2<br />
≤[2]≈≥[2]≈x<br />
0<_pom/>∞ 1<_pom/>2 <br />
≤[1]≈≥[1]≈x<br />
0<_pom/>∞ 1<_pom/>2 <br />
</pre></apll><br />
<br />
The domain of these functions is limited to Real numbers. Hypercomplex numbers signal a <apll>DOMAIN ERROR</apll>. To see the Endpoints of a Hypercomplex number, first '''Dilate''' it so as to separate out the coefficients and then apply <apll>≥≈</apll> to extract the Endpoints as in <apll>≥≈&gt;R</apll>.<br />
<br />
For example,<br />
<br />
<apll><pre> ≥≈ 2±0i0±1<br />
DOMAIN ERROR<br />
≥≈ 2±0i0±1<br />
∧<br />
≥≈>2±0i0±1<br />
2 2<br />
¯1 1<br />
<≤≈≥≈>2±0i0±1<br />
2±0i0±1<br />
</pre></apll><br />
<br />
====Union and Intersection of Balls====<br />
<br />
The left operand of the DoubleTilde operator is defined for the '''Union''' and '''Intersection''' functions (<apll>∪∩</apll>) as follows: <br />
<br />
Because Ball arithmetic numbers represent a range of floating point numbers, at times it is desirable to produce their Union or Intersection.<br />
<br />
For example,<br />
<br />
<apll><pre><br />
x←0.5<pom/>0.5 ⍝ The interval [0,1]<br />
x∪≈x+2 ⍝ The interval [0,1] ∪ [2,3] ←→ [0,3]<br />
1.5<pom/>1.5<br />
x∪≈x+1 ⍝ The interval [0,1] ∪ [1,2] ←→ [0,2]<br />
1<pom/>1 <br />
x∩≈x+1 ⍝ The interval [0,1] ∩ [1,2] ←→ [1,1]<br />
1<br />
</pre></apll><br />
<br />
If two Balls have no points in common, the result is a NaN (<apll>∅</apll>):<br />
<br />
<apll><pre><br />
x∩≈x+1.1 ⍝ The interval [0,1] ∩ [1.1,2.1] ←→ ∅<br />
∅<br />
</pre></apll><br />
<br />
The identity element for <apll>∩≈</apll> is <apll>0±∞</apll>.<br />
<br />
The derived functions are scalar.<br />
<br />
====Comparison Functions====<br />
<br />
The left operand of the DoubleTilde operator is defined for the six comparison functions (<apll>&lt;≤=≥&gt;≠</apll>) as follows:<br />
<br />
For <apll><i>f</i></apll> as one of the above six functions, <apll>L<i>f</i>≈R</apll> is TRUE iff for all <apll>t∊L</apll> and <apll>u∊R</apll>, then <apll>&nbsp;&nbsp;t f u&nbsp;&nbsp;</apll> is TRUE. These comparisons are all done with <apll>⎕CT←0</apll> because, in a sense, Ball comparisons carry their own Fuzz.<br />
<br />
For example,<br />
<br />
<apll><pre> (L R)←4<_pom/>1 6<_pom/>1<br />
L<≈R<br />
0<br />
L≤≈R<br />
1<br />
</pre></apll><br />
<br />
The derived functions are scalar.<br />
<br />
====Containing Functions====<br />
<br />
The left operand of the DoubleTilde operator is defined for two containing functions (<apll>⊂⊃</apll>) as follows:<br />
<br />
The expression <apll>L⊂≈R</apll> is TRUE iff for all <apll>t∊L</apll> it is TRUE that <apll>t∊R</apll> and that the containment is strict &mdash; that is, none of the endpoints match.<br />
<br />
The expression <apll>L⊃≈R</apll> is TRUE iff <apll>R⊂≈L</apll> is TRUE.<br />
<br />
For example,<br />
<br />
<apll><pre><br />
(L R)←6±4 6±2<br />
L⊃≈R<br />
1<br />
R⊂≈L<br />
1<br />
</pre></apll><br />
<br />
The derived functions are scalar.<br />
<br />
====Positional Relationships====<br />
<br />
For <apll>L</apll> and <apll>R</apll> as finite intervals with non-zero Radii (i.e., multi-valued), here are the possible '''Relative Positions''' between the two Intervals, where <apll>L0</apll>, <apll>L1</apll> and <apll>R0</apll>, <apll>R1</apll> are the endpoints of <apll>L</apll> and <apll>R</apll>, respectively &mdash; <apll>(L0 L1)←≥≈L</apll> and <apll>(R0 R1)←≥≈R</apll>:<br />
<br />
<table border="1" cellspacing="0" rowspacing="5" style="font-family:APL385, SImPL;"><br />
<th>Relative<br/>Positions</th><br />
<th>Endpoint<br/>Relationships</th><br />
<th colspan="2">Defining<br/>Expressions</th><br />
<th>Sample Data<br/>L &nbsp; R</th><br />
<th>Distinct<br/>Ball<br/>{⍺∘≈⍵}</th><br />
<br />
<tr><br />
<td>&nbsp;├──L──┤<br/>&nbsp;├──R──┤&nbsp;</td><br />
<td>&nbsp;L0 L1≡R0 R1&nbsp;</td><br />
<td>&nbsp;L=≈R&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 6<_pom/>4&nbsp;</td><br />
<td>&nbsp;&nbsp;0&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──L──┤<br/>&nbsp;├──R─┤&nbsp;</td><br />
<td>&nbsp;(L0=R0)∧L1&gt;R1&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 5<_pom/>3&nbsp;</td><br />
<td>&nbsp;&nbsp;1&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──L─┤<br/>&nbsp;├──R──┤&nbsp;</td><br />
<td>&nbsp;(L0=R0)∧L1&lt;R1&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 7<_pom/>5&nbsp;</td><br />
<td>&nbsp;¯1&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──L──┤<br/>&nbsp;&nbsp;├──R─┤&nbsp;</td><br />
<td>&nbsp;(L0&lt;R0)∧L1=R1&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 7<_pom/>3&nbsp;</td><br />
<td>&nbsp;&nbsp;2&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;&nbsp;├──L─┤<br/>&nbsp;├──R──┤&nbsp;</td><br />
<td>&nbsp;(L0&gt;R0)∧L1=R1&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 5<_pom/>5&nbsp;</td><br />
<td>&nbsp;¯2&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──L──┤<br/>&nbsp;&nbsp;├─R─┤&nbsp;</td><br />
<td>&nbsp;(L0&lt;R0)∧L1&gt;R1&nbsp;</td><br />
<td>&nbsp;L⊃≈R&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 6<_pom/>2&nbsp;</td><br />
<td>&nbsp;&nbsp;3&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;&nbsp;├─L─┤<br/>&nbsp;├──R──┤&nbsp;</td><br />
<td>&nbsp;(L0&gt;R0)∧L1&lt;R1&nbsp;</td><br />
<td>&nbsp;L⊂≈R&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 6<_pom/>6&nbsp;</td><br />
<td>&nbsp;¯3&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──L──┤<br/>&nbsp;&nbsp;├──R──┤&nbsp;</td><br />
<td>&nbsp;(L0&lt;R0)∧(L1&lt;R1)∧L1&gt;R0&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 8<_pom/>4&nbsp;</td><br />
<td>&nbsp;&nbsp;4&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;&nbsp;├──L──┤<br/>&nbsp;├──R──┤&nbsp;</td><br />
<td>&nbsp;(L0&gt;R0)∧(L1&gt;R1)∧L0&lt;R1&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 4<_pom/>4&nbsp;</td><br />
<td>&nbsp;¯4&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──L──┼──R──┤&nbsp;</td><br />
<td>&nbsp;L1=R0&nbsp;</td><br />
<td>&nbsp;(L≤≈R)&gt;L&lt;≈R&nbsp;</td><br />
<td>&nbsp;L=∀R&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 14<_pom/>4&nbsp;</td><br />
<td>&nbsp;&nbsp;5&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──R──┼──L──┤&nbsp;</td><br />
<td>&nbsp;L0=R1&nbsp;</td><br />
<td>&nbsp;(L≥≈R)&gt;L&gt;≈R&nbsp;</td><br />
<td>&nbsp;L=∃R&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 0<_pom/>2&nbsp;</td><br />
<td>&nbsp;¯5&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──L──┤&nbsp;├──R──┤&nbsp;</td><br />
<td>&nbsp;L1&lt;R0&nbsp;</td><br />
<td>&nbsp;L&lt;≈R&nbsp;</td><br />
<td>&nbsp;L&lt;∀R&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 17<_pom/>5&nbsp;</td><br />
<td>&nbsp;&nbsp;6&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──R──┤&nbsp;├──L──┤&nbsp;</td><br />
<td>&nbsp;L0&gt;R1&nbsp;</td><br />
<td>&nbsp;L&gt;≈R&nbsp;</td><br />
<td>&nbsp;L&gt;∃R&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 0<_pom/>1&nbsp;</td><br />
<td>&nbsp;¯6&nbsp;</td><br />
</tr><br />
</table><br />
<br />
The above table can be interpreted as follows:<br />
<br />
<ul><br />
<li>The first column lists all possible '''Relative Positions''' two finite non-zero Radii (i.e., multi-valued) Balls may assume.</li><br />
<li>The second column lists the '''Endpoint Relationship''' that defines the corresponding '''Relative Position'''.</li><br />
<li>The third column lists a '''Defining Expression''' using the '''DoubleTilde''' operator that is TRUE for the corresponding '''Relative Position''' and FALSE for all of the other '''Relative Positions''' in different rows.</li><br />
<li>The fourth column lists a '''Defining Expression''' using the '''Always''' and '''Possibly''' operators [http://forum.nars2000.org/ball-arithmetic-t614.html#p1803 proposed] by David Rabenhorst.</li><br />
<li>The fifth column contains '''Sample Data''' that defines the corresponding '''Relative Position'''.</li><br />
<li>The sixth column gives the value of the '''Distinct Ball''' function <apll>{⍺∘≈⍵}</apll> when executed on the '''Sample Data'''.</li><br />
</ul><br />
<br />
Note the table is organized such that apart from the first row (whose '''Endpoint Relationship''' is Symmetric in <apll>L</apll> and <apll>R</apll>) the rows occur in six pairs where the '''Endpoint Relationship''' for each row in the pair can be obtained from the other by swapping <apll>L</apll> and <apll>R</apll>. The pairs of rows are ordered roughly by the amount of overlap between the two Balls.<br />
<br />
As you can see, we are missing '''Defining Expressions''' for several of the '''Relative Positions'''. I was hoping that this table would be filled in with more detail so it would serve as a measure of whether or not we had a complete set of functions/operators which could be used to tell apart all of the '''Relative Positions''' without having to resort to the '''Distinct Ball''' function <apll>{⍺∘≈⍵}</apll> constructed explicitly for this purpose. Please add to this table if you find a missing expression, or wish to propose whole new functions and/or operators.<br />
<br />
If you would like to try a '''Defining Expression''' on the '''Sample Data''', collect the data into a <apll>13</apll> by <apll>2</apll> matrix, put your '''Defining Expression''' into (say) an Anonymous Function and reduce the same data matrix along the last coordinate &mdash; if you have a successful function, you should see a <apll>13</apll>-element Boolean vector with a single one in it. For example,<br />
<br />
<apll><pre><br />
sd←6<_pom/>4,⍪6<_pom/>4 5<_pom/>3 7<_pom/>5 7<_pom/>3 5<_pom/>5 6<_pom/>2 6<_pom/>6 8<_pom/>4 4<_pom/>4 14<_pom/>4 0<_pom/>2 17<_pom/>5 0<_pom/>1<br />
{(⍺≤≈⍵)>⍺<≈⍵}/sd<br />
0 0 0 0 0 0 0 0 0 1 0 0 0 <br />
{(⍺≥≈⍵)>⍺>≈⍵}/sd<br />
0 0 0 0 0 0 0 0 0 0 1 0 0 <br />
{⍺<≈⍵}/sd<br />
0 0 0 0 0 0 0 0 0 0 0 1 0 <br />
{⍺>≈⍵}/sd<br />
0 0 0 0 0 0 0 0 0 0 0 0 1<br />
</pre></apll><br />
<br />
Finally, the following example shows that the '''Sample Data''' are all distinct:<br />
<br />
<apll><pre><br />
{⍺∘≈⍵}/sd<br />
0 1 ¯1 2 ¯2 3 ¯3 4 ¯4 5 ¯5 6 ¯6<br />
</pre></apll><br />
<br />
==Hypercomplex Ball Arithmetic==<br />
<br />
Ball Arithmetic also extends to all Hypercomplex numbers (Complex, Quaternion, and Octonion) such as <apll>1.2<_pom/><_i/>2.2</apll> which represents a Complex Ball Arithmetic number whose '''Real''' part is <apll>1.2<_pom/></apll> and whose '''Imaginary''' part is <apll>2.2<_pom/></apll>. Note that the display of that number (at <apll>53</apll> bits of precision)<br />
<br />
<apll><pre><br />
1.2<_pom/><_i/>2.2<br />
1.2<_pom/>2.2<_E/>¯16<_i/>2.2<_pom/>4.4<_E/>¯16<br />
</pre></apll><br />
<br />
demonstrates the inexactness of both floating point coefficients.<br />
<br />
==Small v. Large Radii==<br />
<br />
Ball Arithmetic works best when given small Radii, that is, small relative to the Midpoint. Calculations on large Radii numbers such as <apll>0<_i/>0.5<_pom/>0.5</apll> don't always produce useful results. For example,<br />
<br />
<apll><pre><br />
⎕PP←8 ⍝ To reduce fractional clutter<br />
x←0<_i/>0.5<_pom/>0.5<br />
√x<br />
0.4267767<_pom/>0.57<_i/>0<_pom/>1.4<br />
</pre></apll><br />
<br />
Unfortunately in this case, because the Radius is so large it overwhelms the Midpoint, as can be seen when we Square the Square Root:<br />
<br />
<apll><pre><br />
(√x)*2<br />
0.18213835<_pom/>2.8<_i/>0<_pom/>2.8<br />
x=(√x)*2<br />
0<br />
</pre></apll><br />
<br />
These calculations work better using smaller Radii, such as<br />
<br />
<apll><pre><br />
y←0<_i/>0.5<_pom/>0.5<_E/>¯30<br />
√y<br />
0.5<_pom/>2.5<_E/>¯31<_i/>0.5<_pom/>7.5<_E/>¯31<br />
(√y)*2<br />
0<_pom/>1<_E/>¯30<_i/>0.5<_pom/>1<_E/>¯30 <br />
y=(√y)*2<br />
1<br />
</pre></apll><br />
<br />
where Square Root now returns a meaningful result, and its Square returns the original value.<br />
<br />
==Mixed Notation==<br />
<br />
The notation for Ball Arithmetic may be combined with other Point Notations in many ways, such as<br />
<br />
<apll><pre><br />
1<_p/>1<_pom/><br />
3.141592653589793<_pom/>4.4<_E/>¯16 <br />
1<_x/>1<_pom/><br />
2.718281828459045<_pom/>4.5<_E/>¯16<br />
</pre></apll><br />
<br />
For more details about combining different forms of Point Notation, see [[Point_Notation|Point Notation]] and in particular the section on [[Point_Notation#Mixed_Notation|Mixed Notation]].<br />
<br />
==Implementation==<br />
<br />
===Datataypes===<br />
<br />
This feature adds four new datatypes to the language: one each for the four Division Algebras. Note that marking any one of the Hypercomplex coefficients as a Ball automatically marks them all as Balls.<br />
{|<br />
|-<br />
|Real||&nbsp;&nbsp;&nbsp;&nbsp;<apll>23<_pom/></apll> or <apll>1.2<_pom/></apll><br />
|-<br />
|Complex||&nbsp;&nbsp;&nbsp;&nbsp;<apll>23<_i/>1.2<_pom/></apll><br />
|-<br />
|Quaternion||&nbsp;&nbsp;&nbsp;&nbsp;<apll>23<_i/>1.2<_j/>0.5<_k/>¯3.14<_pom/></apll><br />
|-<br />
|Octonion||&nbsp;&nbsp;&nbsp;&nbsp;<apll>23<_i/>1.2<_j/>0.5<_k/>¯3.14<l/>¯3<_ij/>19<_jk/>¯3<_kl/>6<_pom/></apll><br />
|}<br />
<br />
===Primitive Functions===<br />
<br />
As described above, this feature adds two new monadic primitive functions '''Contract''' (<apll>≤R</apll>) and its inverse '''Distract''' (<apll>≥R</apll>), along with one new monadic primitive operator '''DoubleTilde''' <apll>f≈ R</apll> and <apll>L f≈ R</apll>.<br />
<br />
All primitive and system functions and operators are extended to work with Ball Arithmetic, so you can test out this feature on all algorithms, with the exception of trying to find the Factorial of a multiple-precision/Ball Arithmetic Hypercomplex number, in which case you are temporarily out of luck.<br />
<br />
==Workspace Version Number==<br />
<br />
For the moment, if you save a workspace which contains a Ball Arithmetic number in a variable, the workspace version number is <apll>0.03</apll>. Otherwise, the version number is <apll>0.02</apll>. Workspaces with Ball Arithmetic Numbers may not be loaded by an earlier version of the interpreter.<br />
<br />
==Pending Design Decisions==<br />
<br />
<ul><br />
<li>The direct comparison functions (<apll>&lt;≤=≥&gt;≠≡≢</apll>) and indirect ones (<apll>⍳⍸∊⍷⍒⍋</apll>) are currently implemented to compare the Midpoints of the arguments ignoring the Radius &mdash; this may change.</li><br />
<li>The Floor function and its related functions (Ceiling, Residue, GCD, LCM, and Encode) are currently implemented to execute on the Midpoints of the arguments ignoring the Radius &mdash; this may change.</li><br />
<li>We need new primitives to describe the different ways in which Balls can intersect/overlap, possibly through a new monadic operator (perhaps &#x2248;) on the existing direct and indirect comparison and Floor-related functions.</li><br />
<li>Certain primitives are defined on limited ranges, and sometimes multiple ranges where it might use different algorithms for different ranges (e.g. <apll>L!R</apll>). There are open questions about how to handle a Ball that spans two or more of these ranges as to how to calculate the result.</li><br />
<li>Infinity and NaN have not been given any special treatment as yet. The results are whatever ARB has chosen which we may need to override.</li><br />
</ul><br />
<br />
==Download==<br />
<br />
This feature is available as an Alpha release &mdash; it may be downloaded from the [http://www.nars2000.org/download/binaries/alpha/ Alpha] release directory.<br />
<br />
==Acknowledgements==<br />
<br />
<ul><br />
<li>The Arb team has contributed their Ball Arithmetic<ref name="BallArithmetic" /> code which made this feature possible.</li><br />
<li>David Rabenhorst has contributed many very useful ideas and many hours debugging the implementation.</li><br />
</ul><br />
<br />
==References==<br />
<br />
<references /></div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=Ball_Arithmetic&diff=3375Ball Arithmetic2018-10-26T19:42:19Z<p>Sudleyplace: /* Distract */</p>
<hr />
<div>==Introduction==<br />
<br />
Ball<ref name="BallArithmetic">NARS2000 Wiki, [http://arblib.org Ball Arithmetic]</ref> and Interval Arithmetic<ref name="IntervalArithmetic">Wikipedia, [https://en.wikipedia.org/wiki/Interval_arithmetic Interval Arithmetic]</ref> both refer to the same idea of calculating with arbitrary precision inexact numbers &mdash; that is, with a range of floating point values instead of a single representative. This allows such numbers to reflect their inexactness explicitly.<br />
<br />
"The most common use is to keep track of and handle rounding errors directly during the calculation and of uncertainties in the knowledge of the exact values of physical and technical parameters. The latter often arise from measurement errors and tolerances for components or '''due to limits on computational accuracy'''. Interval arithmetic also helps find reliable and guaranteed solutions to equations and optimization problems."<ref name="IntervalArithmetic" /><br />
<br />
The difference between the two is in how each approach represents its values: Interval Arithmetic uses the two ends of the interval <apll>[a, b]</apll> whereas Ball Arithmetic uses a Ball with a Midpoint and Radius. Each has its advantages. Interval Arithmetic is implemented by several libraries such as MPFI<ref name="MPFI">[http://perso.ens-lyon.fr/nathalie.revol/software.html MPFI]</ref> and Ball Arithmetic is implemented by ARB<ref name="BallArithmetic" />.<br />
<br />
This feature uses the ARB<ref name="BallArithmetic" /> library to implement Ball Arithmetic.<br />
<br />
==Environment==<br />
<br />
In the examples below, unless otherwise specified, the precision of multi-precision floating-point numbers is set to <apll>53</apll> bits via <apll>⎕FPC←53</apll> which is the same precision as standard double-precision numbers. The Printing Precision is set to <apll>17</apll> digits via <apll>⎕PP←17</apll> so as to display the maximum number of significant digits at <apll>53</apll> bits of precision. The Comparison Tolerance is set via <apll>⎕CT←1<_E/>¯10</apll>.<br />
<br />
==Calculating With Ball Arithmetic==<br />
<br />
If you have ever entered an expression such as<br />
<br />
<apll><pre><br />
÷3<br />
0.3333333333333333<br />
</pre></apll><br />
<br />
undoubtedly, you are aware that the result is inexact. Moreover, as you incorporate into your code the many other functions that produce inexact numbers, you should be wondering "How does the accumulation of inexactness affect my results?".<br />
<br />
The answer to that question lies in the province of [https://en.wikipedia.org/wiki/Numerical_analysis Numerical Analysis] where it is described as "the study of algorithms that use numerical approximation". In general, applying the techniques of Numerical Analysis often involves time-consuming analysis. Fortunately, Ball Arithmetic is an easy to use alternative to that. That is, instead of analyzing the algorithm, run the algorithm with all calculations done with Ball Arithmetic.<br />
<br />
Here is the same expression in Ball Arithmetic (use Alt-‘q’ or Ctrl-‘q’, depending on your keyboard layout, to enter the <apll><_pom/></apll> symbol):<br />
<br />
<apll><pre><br />
÷3<_pom/><br />
0.3333333333333333<_pom/>5.6<_E/>¯17<br />
</pre></apll><br />
<br />
Essentially, each Ball Arithmetic number carries with it an explicit Radius that describes the interval which contains the true value. Because Ball Arithmetic data propagates throughout a calculation and is never demoted to a lower datatype, its advantage is that after each operation the resulting Ball reliably includes the true answer. Across an entire algorithm, the final result is a Ball that indicates explicitly how precise it is, thus eliminating the guesswork as to the effect on the algorithm of the inexactness of the input and any other inexact constants used.<br />
<br />
For example,<br />
<br />
<apll><pre><br />
sqrt←{⍺←= ⋄ {0.5×⍵+⍺÷⍵}⍣⍺⍨⍵} ⍝ Calculate square root using Newton's method<br />
√2<_pom/><br />
1.414213562373095<_pom/>2.2<_E/>¯16<br />
sqrt 2<_pom/><br />
1.414213562373095<_pom/>1.1<_E/>¯15 <br />
10 sqrt 2<_pom/><br />
1.414213562373095<_pom/>2.8<_E/>¯15 <br />
100 sqrt 2<_pom/><br />
1.414213562373095<_pom/>3.3<_E/>¯14 <br />
1000 sqrt 2<_pom/><br />
1.414213562373095<_pom/>3.3<_E/>¯13 <br />
10000 sqrt 2<_pom/><br />
1.414213562373095<_pom/>3.5<_E/>¯12<br />
</pre></apll><br />
<br />
As you can see, after a few iterations, the accuracy of the result doesn't improve. However, because it is an iterative algorithm, the precision worsens as the number of iterations increases. Only by using Ball Arithmetic can you see just how the precision of the result is affected.<br />
<br />
To demonstrate with an extreme example, consider the following function:<br />
<br />
<apll><pre><br />
f←{⍪⍵-3√(⍵*3)-⍵*2}<br />
f 10*3×⍳5<br />
0.33344450621439137<br />
0.3333334452472627 <br />
0.33333444595336914<br />
0.3348388671875 <br />
2.25<br />
</pre></apll><br />
<br />
Without knowing much about this ([https://en.wikipedia.org/wiki/Condition_number ill-conditioned]) algorithm, you have no reason to suspect these results. As it turns out, there's a mathematical proof that as the argument increases to infinity, the algorithm converges to <apll>÷3</apll>. Only when you calculate with Ball Arithmetic do you see that there is a problem:<br />
<br />
<apll><pre><br />
f 10*3×⍳5<_pom/><br />
0.3334445062153009<_pom/>2.2<_E/>¯12 <br />
0.3333334461785853<_pom/>4.3<_E/>¯9 <br />
0.333337664604187<_pom/>0.0000062<br />
0.3385009765625<_pom/>0.0085<br />
1.25<_pom/>5<br />
</pre></apll><br />
<br />
As you can see, the precision worsens quickly to the point where the result is meaningless. The last line even says that the answer lies somewhere between <apll>¯3.75</apll> and <apll>6.25</apll>. In other words, that answer is so '''imprecise''' as to be '''inaccurate'''! At higher powers of ten, the answers only worsen.<br />
<br />
The good news with Ball Arithmetic is that if you need greater precision, just increase the value of <apll>⎕FPC</apll>. For example,<br />
<br />
<apll><pre><br />
⎕FPC←128 ⋄ ⎕PP←40<br />
sqrt 2<_pom/><br />
1.41421356237309504880168872420969807857<_pom/>5.9<_E/>¯39<br />
</pre></apll><br />
<br />
In the case of an ill-conditioned algorithm, we just push the problem off a bit, but not very far &mdash; the problem is that the algorithm requires infinite precision:<br />
<br />
<apll><pre><br />
f 10*3×⍳10<_pom/><br />
0.333444506214021971364848444464298690637<_pom/>3.4<_E/>¯35<br />
0.333333444444506172880658466392407138179<_pom/>1.1<_E/>¯31<br />
0.333333333444444444506172839632668381652<_pom/>1.6<_E/>¯28<br />
0.333333333333444444444444547458328123363<_pom/>2.2<_E/>¯25<br />
0.333333333333333444444619474517508476812<_pom/>3.2<_E/>¯22<br />
0.333333333333333333552432522356445687706<_pom/>1.3<_E/>¯19<br />
0.333333333333333491771410805881714622956<_pom/>4.5<_E/>¯16<br />
0.333333333333417414223731611855328083038<_pom/>4.5<_E/>¯13<br />
0.33333333363771089352667331695556640625<_pom/>4.5<_E/>¯10 <br />
0.3333334587514400482177734375<_pom/>2.6<_E/>¯7<br />
</pre></apll><br />
<br />
While your floating point code might not be so ill-conditioned, the only way to be sure of its results is one of<br />
<br />
<ul><br />
<li>Hire a Numerical Analyst</li><br />
<li>Become a Numerical Analyst</li><br />
<li>Use Ball Arithmetic</li><br />
</ul><br />
<br />
==Ball Arithmetic Numbers==<br />
<br />
A Ball Arithmetic number consist of two parts: a Midpoint and Radius. The Midpoint value represents the middle of the Ball and the Radius represents the distance around the Ball of possible values. There is no way to tell which value in the Ball is the correct answer &mdash; you should assume that all values are potential candidates. <br />
<br />
The precision at which the Midpoint and Radius are stored depends upon the current value of <apll>⎕FPC</apll>. For example, the following display<br />
<br />
<apll><pre><br />
⎕FPC←53<br />
÷3<_pom/><br />
0.3333333333333333<_pom/>5.6<_E/>¯17<br />
</pre></apll><br />
<br />
indicates that the number <apll>÷3<_pom/></apll> has a Midpoint of <apll>0.3333333333333333</apll> at <apll>53</apll>-bit precision and a Radius of <apll>5.6<_E/>¯17</apll>. The Midpoint is stored as a variable precision number, and the Radius is stored as a low-precision number.<br />
<br />
Alternatively,<br />
<br />
<apll><pre><br />
⎕FPC←128 ⋄ ⎕PP←40<br />
÷3<_pom/><br />
0.333333333333333333333333333333333333332<_pom/>1.5<_E/>¯39<br />
</pre></apll><br />
<br />
shows the corresponding value at a higher precision and correspondingly narrower Radius.<br />
<br />
<p><br />
The approximate number of digits of precision for a given value of <apll>⎕FPC</apll> is about <apll>10⍟2*⎕FPC</apll>. The value of <apll>⎕FPC</apll> for a given required precision is about <apll>⌈2⍟10*digits</apll>.<br />
</p><br />
<br />
<p><br />
The current <apll>⎕FPC</apll> precision<br />
should be sufficient to cover both the midpoint and the radius<br />
of all ball numbers being used.<br />
Otherwise,<br />
some results might be misleading.<br />
</p><br />
<br />
<p><br />
For example,<br />
</p><br />
<p><apll><br />
2v*⎕fpc←128<br />
3.402823669E38<br />
⍟ ⎕← * 1±1e¯1000<br />
2.718281828±1.2E¯38<br />
1±7.3E¯39<br />
</apll></p><br />
<br />
<p><br />
What happened? -- <apll>⎕FPC</apll> was too small!<br />
</p><br />
<br />
<p><apll><br />
2v*⎕fpc←4096<br />
1.044388881E1233<br />
⍟ ⎕← * 1±1e¯1000<br />
2.718281828±2.7E¯1000<br />
1±1E¯1000<br />
</apll></p><br />
<br />
<p> </p><br />
<br />
A Ball describes a range of '''variable-precision floating point numbers''', and so the expression <apll>23<_pom/>1</apll> represents the set of Real numbers between <apll>22</apll> and <apll>24</apll>, inclusive, '''not''' the three integers <apll>22</apll>, <apll>23</apll>, <apll>24</apll>.<br />
<br />
<p class="note" style=" background-color:lightcyan;">In general, suffix notation on Ball Arithmetic constants should be sufficient for '''almost all purposes'''. That is, the Radius is already correctly calculated for constants such as <apll>23<_pom/></apll> whose Radius is zero, and <apll>1.2<_pom/></apll> whose Radius at <apll>53</apll> bits of precision is on the order of <apll>2*¯53</apll> (because of the inexactness of the Midpoint <apll>1.2</apll>) which displays as <apll>1.2<_pom/>2.2<_E/>¯16</apll>. Although the input notation supports it, the need to override the default Radius should be '''quite rare'''.</p><br />
<br />
==New Functions and Operator==<br />
<br />
===Functions To Convert To And From Ball Arithmetic Numbers===<br />
<br />
A Ball Arithmetic constant number may be created through notation (as seen above). Otherwise, a Ball Arithmetic number also may be created from its constituent parts under program control with a new primitive function '''Contract''', and separated into its constituent parts with a new primitive function '''Distract'''.<br />
<br />
====Contract====<br />
<br />
'''Contract''' is a monadic function (<apll>≤R</apll>) whose right argument is a Real array. It may be used to create a Ball Arithmetic number from the one- or two-elements of its Real number Midpoint and (optional) Real number Radius. The Axis Operator may specify any length <apll>1</apll> or <apll>2</apll> coordinate along which the conversion takes place. It converts the first element along the specified dimension to the Midpoint of the result and (if present) the second element to its Radius. If the second element is not present (i.e., length <apll>1</apll> coordinate), the Radius used is calculated from the precision of the Midpoint.<br />
<br />
<apll><pre><br />
≤23<br />
23<br />
≤1.2<br />
1.2<_pom/>1.1<_E/>¯16<br />
≤1.3 1<_E/>¯20<br />
1.3<_pom/>1<_E/>¯20<br />
≤1r2 1<_E/>¯20<br />
0.5<_pom/>1<_E/>¯20<br />
≤○1<br />
3.141592653589793<_pom/>1.1<_E/>¯16 <br />
≤(○1) 1<_E/>¯20<br />
3.141592653589793<_pom/>1<_E/>¯20 <br />
</pre></apll><br />
<br />
The domain of this function is limited to Real numbers. Hypercomplex numbers signal a <apll>DOMAIN ERROR</apll>.<br />
<br />
====Distract====<br />
<br />
'''Distract''' is a monadic function (<apll>≥R</apll>) whose right argument is a Real array. It may be used to separate out a Ball Arithmetic's Midpoint and Radius into two distinct values. The Axis Operator may specify the place where the new length <apll>2</apll> coordinate is to be inserted. The pair of values along this new coordinate are the Midpoint and Radius of the corresponding number from the right argument. If the number can be represented exactly, the Radius is zero.<br />
<br />
<apll><pre><br />
⎕PP←10<br />
≥1.2<br />
1.2 1.1102230246251565<_E/>¯16<br />
≥1.2<_x/><br />
6<_r/>5 0<br />
≥1.2<_v/><br />
1.2 1.110223024625157<_E/>¯16<br />
≥1.2<_pom/><br />
1.2 2.220446049250313<_E/>¯16<br />
≥1.5<br />
1.5 0<br />
≥1.5<_x/><br />
3<_r/>2 0<br />
≥1.5<_v/><br />
1.5 1.110223024625157<_E/>¯16<br />
≥1.5<_pom/><br />
1.5 0<br />
a←(○1<_pom/>)×⍳4<br />
a,'|',≥a<br />
3.141592654<_pom/>4.4<_E/>¯16 | 3.141592654 4.440892148<_E/>¯16<br />
6.283185307<_pom/>8.9<_E/>¯16 | 6.283185307 8.881784296<_E/>¯16<br />
9.424777961<_pom/>1.3<_E/>¯15 | 9.424777961 1.332267643<_E/>¯15<br />
12.56637061<_pom/>1.8<_E/>¯15 | 12.56637061 1.776356859<_E/>¯15<br />
</pre></apll><br />
<br />
These numbers can be represented exactly:<br />
<br />
<apll><pre><br />
≥⍳4<_pom/><br />
1 0<br />
2 0<br />
3 0<br />
4 0<br />
≥[2]⍳4<_pom/><br />
1 0<br />
2 0<br />
3 0<br />
4 0<br />
≥[1]⍳4<_pom/><br />
1 2 3 4<br />
0 0 0 0<br />
</pre></apll><br />
<br />
The domain of this function is limited to Real numbers. Hypercomplex numbers signal a <apll>DOMAIN ERROR</apll>.<br />
<br />
====Identities====<br />
<br />
The Contract of the Distract of a number both along the same axis, returns the same number.<br />The Distract of the Contract of a number both along the same length two axis, returns the same number.<br />
<br />
===Operator To Provide Arbitrary Precision Specific Derived Functions===<br />
<br />
The DoubleTilde monadic operator (<apll>≈</apll>, Alt-'Q' or Alt-shift-'q') takes a primitive function as its left operand and produces an arbitrary-precision-specific derived function.<br />
<br />
This operator should be considered preliminary.<br />
<br />
====Conversion Between Balls and Intervals====<br />
<br />
At the moment, the monadic derived function is defined for two primitive functions.<br />
<br />
Because Ball Arithmetic has a close relationship with Interval Arithmetic, it may be desirable to convert between the two forms: Endpoint to Midpoint-Radius and its inverse. The resulting derived function is not scalar.<br />
<br />
For example,<br />
<br />
<apll><pre><br />
x←0<_pom/>∞ 1<_pom/>2<br />
≥≈x<br />
¯∞ ∞<br />
¯1 3<br />
≥[1]≈x<br />
¯∞ ¯1<br />
∞ 3<br />
≥[2]≈x<br />
¯∞ ∞<br />
¯1 3<br />
≤≈≥≈x<br />
0<_pom/>∞ 1<_pom/>2<br />
≤≈≥[2]≈x<br />
0<_pom/>∞ 1<_pom/>2<br />
≤[2]≈≥≈x<br />
0<_pom/>∞ 1<_pom/>2<br />
≤[2]≈≥[2]≈x<br />
0<_pom/>∞ 1<_pom/>2 <br />
≤[1]≈≥[1]≈x<br />
0<_pom/>∞ 1<_pom/>2 <br />
</pre></apll><br />
<br />
The domain of these functions is limited to Real numbers. Hypercomplex numbers signal a <apll>DOMAIN ERROR</apll>. To see the Endpoints of a Hypercomplex number, first '''Dilate''' it so as to separate out the coefficients and then apply <apll>≥≈</apll> to extract the Endpoints as in <apll>≥≈&gt;R</apll>.<br />
<br />
For example,<br />
<br />
<apll><pre> ≥≈ 2±0i0±1<br />
DOMAIN ERROR<br />
≥≈ 2±0i0±1<br />
∧<br />
≥≈>2±0i0±1<br />
2 2<br />
¯1 1<br />
<≤≈≥≈>2±0i0±1<br />
2±0i0±1<br />
</pre></apll><br />
<br />
====Union and Intersection of Balls====<br />
<br />
The left operand of the DoubleTilde operator is defined for the '''Union''' and '''Intersection''' functions (<apll>∪∩</apll>) as follows: <br />
<br />
Because Ball arithmetic numbers represent a range of floating point numbers, at times it is desirable to produce their Union or Intersection.<br />
<br />
For example,<br />
<br />
<apll><pre><br />
x←0.5<pom/>0.5 ⍝ The interval [0,1]<br />
x∪≈x+2 ⍝ The interval [0,1] ∪ [2,3] ←→ [0,3]<br />
1.5<pom/>1.5<br />
x∪≈x+1 ⍝ The interval [0,1] ∪ [1,2] ←→ [0,2]<br />
1<pom/>1 <br />
x∩≈x+1 ⍝ The interval [0,1] ∩ [1,2] ←→ [1,1]<br />
1<br />
</pre></apll><br />
<br />
If two Balls have no points in common, the result is a NaN (<apll>∅</apll>):<br />
<br />
<apll><pre><br />
x∩≈x+1.1 ⍝ The interval [0,1] ∩ [1.1,2.1] ←→ ∅<br />
∅<br />
</pre></apll><br />
<br />
The identity element for <apll>∩≈</apll> is <apll>0±∞</apll>.<br />
<br />
The derived functions are scalar.<br />
<br />
====Comparison Functions====<br />
<br />
The left operand of the DoubleTilde operator is defined for the six comparison functions (<apll>&lt;≤=≥&gt;≠</apll>) as follows:<br />
<br />
For <apll><i>f</i></apll> as one of the above six functions, <apll>L<i>f</i>≈R</apll> is TRUE iff for all <apll>t∊L</apll> and <apll>u∊R</apll>, then <apll>&nbsp;&nbsp;t f u&nbsp;&nbsp;</apll> is TRUE. These comparisons are all done with <apll>⎕CT←0</apll> because, in a sense, Ball comparisons carry their own Fuzz.<br />
<br />
For example,<br />
<br />
<apll><pre> (L R)←4<_pom/>1 6<_pom/>1<br />
L<≈R<br />
0<br />
L≤≈R<br />
1<br />
</pre></apll><br />
<br />
The derived functions are scalar.<br />
<br />
====Containing Functions====<br />
<br />
The left operand of the DoubleTilde operator is defined for two containing functions (<apll>⊂⊃</apll>) as follows:<br />
<br />
The expression <apll>L⊂≈R</apll> is TRUE iff for all <apll>t∊L</apll> it is TRUE that <apll>t∊R</apll> and that the containment is strict &mdash; that is, none of the endpoints match.<br />
<br />
The expression <apll>L⊃≈R</apll> is TRUE iff <apll>R⊂≈L</apll> is TRUE.<br />
<br />
For example,<br />
<br />
<apll><pre><br />
(L R)←6±4 6±2<br />
L⊃≈R<br />
1<br />
R⊂≈L<br />
1<br />
</pre></apll><br />
<br />
The derived functions are scalar.<br />
<br />
====Positional Relationships====<br />
<br />
For <apll>L</apll> and <apll>R</apll> as finite intervals with non-zero Radii (i.e., multi-valued), here are the possible '''Relative Positions''' between the two Intervals, where <apll>L0</apll>, <apll>L1</apll> and <apll>R0</apll>, <apll>R1</apll> are the endpoints of <apll>L</apll> and <apll>R</apll>, respectively &mdash; <apll>(L0 L1)←≥≈L</apll> and <apll>(R0 R1)←≥≈R</apll>:<br />
<br />
<table border="1" cellspacing="0" rowspacing="5" style="font-family:APL385, SImPL;"><br />
<th>Relative<br/>Positions</th><br />
<th>Endpoint<br/>Relationships</th><br />
<th colspan="2">Defining<br/>Expressions</th><br />
<th>Sample Data<br/>L &nbsp; R</th><br />
<th>Distinct<br/>Ball<br/>{⍺∘≈⍵}</th><br />
<br />
<tr><br />
<td>&nbsp;├──L──┤<br/>&nbsp;├──R──┤&nbsp;</td><br />
<td>&nbsp;L0 L1≡R0 R1&nbsp;</td><br />
<td>&nbsp;L=≈R&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 6<_pom/>4&nbsp;</td><br />
<td>&nbsp;&nbsp;0&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──L──┤<br/>&nbsp;├──R─┤&nbsp;</td><br />
<td>&nbsp;(L0=R0)∧L1&gt;R1&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 5<_pom/>3&nbsp;</td><br />
<td>&nbsp;&nbsp;1&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──L─┤<br/>&nbsp;├──R──┤&nbsp;</td><br />
<td>&nbsp;(L0=R0)∧L1&lt;R1&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 7<_pom/>5&nbsp;</td><br />
<td>&nbsp;¯1&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──L──┤<br/>&nbsp;&nbsp;├──R─┤&nbsp;</td><br />
<td>&nbsp;(L0&lt;R0)∧L1=R1&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 7<_pom/>3&nbsp;</td><br />
<td>&nbsp;&nbsp;2&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;&nbsp;├──L─┤<br/>&nbsp;├──R──┤&nbsp;</td><br />
<td>&nbsp;(L0&gt;R0)∧L1=R1&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 5<_pom/>5&nbsp;</td><br />
<td>&nbsp;¯2&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──L──┤<br/>&nbsp;&nbsp;├─R─┤&nbsp;</td><br />
<td>&nbsp;(L0&lt;R0)∧L1&gt;R1&nbsp;</td><br />
<td>&nbsp;L⊃≈R&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 6<_pom/>2&nbsp;</td><br />
<td>&nbsp;&nbsp;3&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;&nbsp;├─L─┤<br/>&nbsp;├──R──┤&nbsp;</td><br />
<td>&nbsp;(L0&gt;R0)∧L1&lt;R1&nbsp;</td><br />
<td>&nbsp;L⊂≈R&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 6<_pom/>6&nbsp;</td><br />
<td>&nbsp;¯3&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──L──┤<br/>&nbsp;&nbsp;├──R──┤&nbsp;</td><br />
<td>&nbsp;(L0&lt;R0)∧(L1&lt;R1)∧L1&gt;R0&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 8<_pom/>4&nbsp;</td><br />
<td>&nbsp;&nbsp;4&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;&nbsp;├──L──┤<br/>&nbsp;├──R──┤&nbsp;</td><br />
<td>&nbsp;(L0&gt;R0)∧(L1&gt;R1)∧L0&lt;R1&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 4<_pom/>4&nbsp;</td><br />
<td>&nbsp;¯4&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──L──┼──R──┤&nbsp;</td><br />
<td>&nbsp;L1=R0&nbsp;</td><br />
<td>&nbsp;(L≤≈R)&gt;L&lt;≈R&nbsp;</td><br />
<td>&nbsp;L=∀R&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 14<_pom/>4&nbsp;</td><br />
<td>&nbsp;&nbsp;5&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──R──┼──L──┤&nbsp;</td><br />
<td>&nbsp;L0=R1&nbsp;</td><br />
<td>&nbsp;(L≥≈R)&gt;L&gt;≈R&nbsp;</td><br />
<td>&nbsp;L=∃R&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 0<_pom/>2&nbsp;</td><br />
<td>&nbsp;¯5&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──L──┤&nbsp;├──R──┤&nbsp;</td><br />
<td>&nbsp;L1&lt;R0&nbsp;</td><br />
<td>&nbsp;L&lt;≈R&nbsp;</td><br />
<td>&nbsp;L&lt;∀R&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 17<_pom/>5&nbsp;</td><br />
<td>&nbsp;&nbsp;6&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──R──┤&nbsp;├──L──┤&nbsp;</td><br />
<td>&nbsp;L0&gt;R1&nbsp;</td><br />
<td>&nbsp;L&gt;≈R&nbsp;</td><br />
<td>&nbsp;L&gt;∃R&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 0<_pom/>1&nbsp;</td><br />
<td>&nbsp;¯6&nbsp;</td><br />
</tr><br />
</table><br />
<br />
The above table can be interpreted as follows:<br />
<br />
<ul><br />
<li>The first column lists all possible '''Relative Positions''' two finite non-zero Radii (i.e., multi-valued) Balls may assume.</li><br />
<li>The second column lists the '''Endpoint Relationship''' that defines the corresponding '''Relative Position'''.</li><br />
<li>The third column lists a '''Defining Expression''' using the '''DoubleTilde''' operator that is TRUE for the corresponding '''Relative Position''' and FALSE for all of the other '''Relative Positions''' in different rows.</li><br />
<li>The fourth column lists a '''Defining Expression''' using the '''Always''' and '''Possibly''' operators [http://forum.nars2000.org/ball-arithmetic-t614.html#p1803 proposed] by David Rabenhorst.</li><br />
<li>The fifth column contains '''Sample Data''' that defines the corresponding '''Relative Position'''.</li><br />
<li>The sixth column gives the value of the '''Distinct Ball''' function <apll>{⍺∘≈⍵}</apll> when executed on the '''Sample Data'''.</li><br />
</ul><br />
<br />
Note the table is organized such that apart from the first row (whose '''Endpoint Relationship''' is Symmetric in <apll>L</apll> and <apll>R</apll>) the rows occur in six pairs where the '''Endpoint Relationship''' for each row in the pair can be obtained from the other by swapping <apll>L</apll> and <apll>R</apll>. The pairs of rows are ordered roughly by the amount of overlap between the two Balls.<br />
<br />
As you can see, we are missing '''Defining Expressions''' for several of the '''Relative Positions'''. I was hoping that this table would be filled in with more detail so it would serve as a measure of whether or not we had a complete set of functions/operators which could be used to tell apart all of the '''Relative Positions''' without having to resort to the '''Distinct Ball''' function <apll>{⍺∘≈⍵}</apll> constructed explicitly for this purpose. Please add to this table if you find a missing expression, or wish to propose whole new functions and/or operators.<br />
<br />
If you would like to try a '''Defining Expression''' on the '''Sample Data''', collect the data into a <apll>13</apll> by <apll>2</apll> matrix, put your '''Defining Expression''' into (say) an Anonymous Function and reduce the same data matrix along the last coordinate &mdash; if you have a successful function, you should see a <apll>13</apll>-element Boolean vector with a single one in it. For example,<br />
<br />
<apll><pre><br />
sd←6<_pom/>4,⍪6<_pom/>4 5<_pom/>3 7<_pom/>5 7<_pom/>3 5<_pom/>5 6<_pom/>2 6<_pom/>6 8<_pom/>4 4<_pom/>4 14<_pom/>4 0<_pom/>2 17<_pom/>5 0<_pom/>1<br />
{(⍺≤≈⍵)>⍺<≈⍵}/sd<br />
0 0 0 0 0 0 0 0 0 1 0 0 0 <br />
{(⍺≥≈⍵)>⍺>≈⍵}/sd<br />
0 0 0 0 0 0 0 0 0 0 1 0 0 <br />
{⍺<≈⍵}/sd<br />
0 0 0 0 0 0 0 0 0 0 0 1 0 <br />
{⍺>≈⍵}/sd<br />
0 0 0 0 0 0 0 0 0 0 0 0 1<br />
</pre></apll><br />
<br />
Finally, the following example shows that the '''Sample Data''' are all distinct:<br />
<br />
<apll><pre><br />
{⍺∘≈⍵}/sd<br />
0 1 ¯1 2 ¯2 3 ¯3 4 ¯4 5 ¯5 6 ¯6<br />
</pre></apll><br />
<br />
==Hypercomplex Ball Arithmetic==<br />
<br />
Ball Arithmetic also extends to all Hypercomplex numbers (Complex, Quaternion, and Octonion) such as <apll>1.2<_pom/><_i/>2.2</apll> which represents a Complex Ball Arithmetic number whose '''Real''' part is <apll>1.2<_pom/></apll> and whose '''Imaginary''' part is <apll>2.2<_pom/></apll>. Note that the display of that number (at <apll>53</apll> bits of precision)<br />
<br />
<apll><pre><br />
1.2<_pom/><_i/>2.2<br />
1.2<_pom/>2.2<_E/>¯16<_i/>2.2<_pom/>4.4<_E/>¯16<br />
</pre></apll><br />
<br />
demonstrates the inexactness of both floating point coefficients.<br />
<br />
==Small v. Large Radii==<br />
<br />
Ball Arithmetic works best when given small Radii, that is, small relative to the Midpoint. Calculations on large Radii numbers such as <apll>0<_i/>0.5<_pom/>0.5</apll> don't always produce useful results. For example,<br />
<br />
<apll><pre><br />
⎕PP←8 ⍝ To reduce fractional clutter<br />
x←0<_i/>0.5<_pom/>0.5<br />
√x<br />
0.4267767<_pom/>0.57<_i/>0<_pom/>1.4<br />
</pre></apll><br />
<br />
Unfortunately in this case, because the Radius is so large it overwhelms the Midpoint, as can be seen when we Square the Square Root:<br />
<br />
<apll><pre><br />
(√x)*2<br />
0.18213835<_pom/>2.8<_i/>0<_pom/>2.8<br />
x=(√x)*2<br />
0<br />
</pre></apll><br />
<br />
These calculations work better using smaller Radii, such as<br />
<br />
<apll><pre><br />
y←0<_i/>0.5<_pom/>0.5<_E/>¯30<br />
√y<br />
0.5<_pom/>2.5<_E/>¯31<_i/>0.5<_pom/>7.5<_E/>¯31<br />
(√y)*2<br />
0<_pom/>1<_E/>¯30<_i/>0.5<_pom/>1<_E/>¯30 <br />
y=(√y)*2<br />
1<br />
</pre></apll><br />
<br />
where Square Root now returns a meaningful result, and its Square returns the original value.<br />
<br />
==Mixed Notation==<br />
<br />
The notation for Ball Arithmetic may be combined with other Point Notations in many ways, such as<br />
<br />
<apll><pre><br />
1<_p/>1<_pom/><br />
3.141592653589793<_pom/>4.4<_E/>¯16 <br />
1<_x/>1<_pom/><br />
2.718281828459045<_pom/>4.5<_E/>¯16<br />
</pre></apll><br />
<br />
For more details about combining different forms of Point Notation, see [[Point_Notation|Point Notation]] and in particular the section on [[Point_Notation#Mixed_Notation|Mixed Notation]].<br />
<br />
==Implementation==<br />
<br />
===Datataypes===<br />
<br />
This feature adds four new datatypes to the language: one each for the four Division Algebras. Note that marking any one of the Hypercomplex coefficients as a Ball automatically marks them all as Balls.<br />
{|<br />
|-<br />
|Real||&nbsp;&nbsp;&nbsp;&nbsp;<apll>23<_pom/></apll> or <apll>1.2<_pom/></apll><br />
|-<br />
|Complex||&nbsp;&nbsp;&nbsp;&nbsp;<apll>23<_i/>1.2<_pom/></apll><br />
|-<br />
|Quaternion||&nbsp;&nbsp;&nbsp;&nbsp;<apll>23<_i/>1.2<_j/>0.5<_k/>¯3.14<_pom/></apll><br />
|-<br />
|Octonion||&nbsp;&nbsp;&nbsp;&nbsp;<apll>23<_i/>1.2<_j/>0.5<_k/>¯3.14<l/>¯3<_ij/>19<_jk/>¯3<_kl/>6<_pom/></apll><br />
|}<br />
<br />
===Primitive Functions===<br />
<br />
As described above, this feature adds two new monadic primitive functions '''Contract''' (<apll>≤R</apll>) and its inverse '''Distract''' (<apll>≥R</apll>), along with one new monadic primitive operator '''DoubleTilde''' <apll>f≈ R</apll> and <apll>L f≈ R</apll>.<br />
<br />
All primitive and system functions and operators are extended to work with Ball Arithmetic, so you can test out this feature on all algorithms, with the exception of trying to find the Factorial of a multiple-precision/Ball Arithmetic Hypercomplex number, in which case you are temporarily out of luck.<br />
<br />
==Workspace Version Number==<br />
<br />
For the moment, if you save a workspace which contains a Ball Arithmetic number in a variable, the workspace version number is <apll>0.03</apll>. Otherwise, the version number is <apll>0.02</apll>. Workspaces with Ball Arithmetic Numbers may not be loaded by an earlier version of the interpreter.<br />
<br />
==Pending Design Decisions==<br />
<br />
<ul><br />
<li>The direct comparison functions (<apll>&lt;≤=≥&gt;≠≡≢</apll>) and indirect ones (<apll>⍳⍸∊⍷⍒⍋</apll>) are currently implemented to compare the Midpoints of the arguments ignoring the Radius &mdash; this may change.</li><br />
<li>The Floor function and its related functions (Ceiling, Residue, GCD, LCM, and Encode) are currently implemented to execute on the Midpoints of the arguments ignoring the Radius &mdash; this may change.</li><br />
<li>We need new primitives to describe the different ways in which Balls can intersect/overlap, possibly through a new monadic operator (perhaps &#x2248;) on the existing direct and indirect comparison and Floor-related functions.</li><br />
<li>Certain primitives are defined on limited ranges, and sometimes multiple ranges where it might use different algorithms for different ranges (e.g. <apll>L!R</apll>). There are open questions about how to handle a Ball that spans two or more of these ranges as to how to calculate the result.</li><br />
<li>Infinity and NaN have not been given any special treatment as yet. The results are whatever ARB has chosen which we may need to override.</li><br />
</ul><br />
<br />
==Download==<br />
<br />
This feature is available as an Alpha release &mdash; it may be downloaded from the [http://www.nars2000.org/download/binaries/alpha/ Alpha] release directory.<br />
<br />
==Acknowledgements==<br />
<br />
<ul><br />
<li>The Arb team has contributed their Ball Arithmetic<ref name="BallArithmetic" /> code which made this feature possible.</li><br />
<li>David Rabenhorst has contributed many very useful ideas and many hours debugging the implementation.</li><br />
</ul><br />
<br />
==References==<br />
<br />
<references /></div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=Ball_Arithmetic&diff=3374Ball Arithmetic2018-10-26T19:36:56Z<p>Sudleyplace: /* Contract */</p>
<hr />
<div>==Introduction==<br />
<br />
Ball<ref name="BallArithmetic">NARS2000 Wiki, [http://arblib.org Ball Arithmetic]</ref> and Interval Arithmetic<ref name="IntervalArithmetic">Wikipedia, [https://en.wikipedia.org/wiki/Interval_arithmetic Interval Arithmetic]</ref> both refer to the same idea of calculating with arbitrary precision inexact numbers &mdash; that is, with a range of floating point values instead of a single representative. This allows such numbers to reflect their inexactness explicitly.<br />
<br />
"The most common use is to keep track of and handle rounding errors directly during the calculation and of uncertainties in the knowledge of the exact values of physical and technical parameters. The latter often arise from measurement errors and tolerances for components or '''due to limits on computational accuracy'''. Interval arithmetic also helps find reliable and guaranteed solutions to equations and optimization problems."<ref name="IntervalArithmetic" /><br />
<br />
The difference between the two is in how each approach represents its values: Interval Arithmetic uses the two ends of the interval <apll>[a, b]</apll> whereas Ball Arithmetic uses a Ball with a Midpoint and Radius. Each has its advantages. Interval Arithmetic is implemented by several libraries such as MPFI<ref name="MPFI">[http://perso.ens-lyon.fr/nathalie.revol/software.html MPFI]</ref> and Ball Arithmetic is implemented by ARB<ref name="BallArithmetic" />.<br />
<br />
This feature uses the ARB<ref name="BallArithmetic" /> library to implement Ball Arithmetic.<br />
<br />
==Environment==<br />
<br />
In the examples below, unless otherwise specified, the precision of multi-precision floating-point numbers is set to <apll>53</apll> bits via <apll>⎕FPC←53</apll> which is the same precision as standard double-precision numbers. The Printing Precision is set to <apll>17</apll> digits via <apll>⎕PP←17</apll> so as to display the maximum number of significant digits at <apll>53</apll> bits of precision. The Comparison Tolerance is set via <apll>⎕CT←1<_E/>¯10</apll>.<br />
<br />
==Calculating With Ball Arithmetic==<br />
<br />
If you have ever entered an expression such as<br />
<br />
<apll><pre><br />
÷3<br />
0.3333333333333333<br />
</pre></apll><br />
<br />
undoubtedly, you are aware that the result is inexact. Moreover, as you incorporate into your code the many other functions that produce inexact numbers, you should be wondering "How does the accumulation of inexactness affect my results?".<br />
<br />
The answer to that question lies in the province of [https://en.wikipedia.org/wiki/Numerical_analysis Numerical Analysis] where it is described as "the study of algorithms that use numerical approximation". In general, applying the techniques of Numerical Analysis often involves time-consuming analysis. Fortunately, Ball Arithmetic is an easy to use alternative to that. That is, instead of analyzing the algorithm, run the algorithm with all calculations done with Ball Arithmetic.<br />
<br />
Here is the same expression in Ball Arithmetic (use Alt-‘q’ or Ctrl-‘q’, depending on your keyboard layout, to enter the <apll><_pom/></apll> symbol):<br />
<br />
<apll><pre><br />
÷3<_pom/><br />
0.3333333333333333<_pom/>5.6<_E/>¯17<br />
</pre></apll><br />
<br />
Essentially, each Ball Arithmetic number carries with it an explicit Radius that describes the interval which contains the true value. Because Ball Arithmetic data propagates throughout a calculation and is never demoted to a lower datatype, its advantage is that after each operation the resulting Ball reliably includes the true answer. Across an entire algorithm, the final result is a Ball that indicates explicitly how precise it is, thus eliminating the guesswork as to the effect on the algorithm of the inexactness of the input and any other inexact constants used.<br />
<br />
For example,<br />
<br />
<apll><pre><br />
sqrt←{⍺←= ⋄ {0.5×⍵+⍺÷⍵}⍣⍺⍨⍵} ⍝ Calculate square root using Newton's method<br />
√2<_pom/><br />
1.414213562373095<_pom/>2.2<_E/>¯16<br />
sqrt 2<_pom/><br />
1.414213562373095<_pom/>1.1<_E/>¯15 <br />
10 sqrt 2<_pom/><br />
1.414213562373095<_pom/>2.8<_E/>¯15 <br />
100 sqrt 2<_pom/><br />
1.414213562373095<_pom/>3.3<_E/>¯14 <br />
1000 sqrt 2<_pom/><br />
1.414213562373095<_pom/>3.3<_E/>¯13 <br />
10000 sqrt 2<_pom/><br />
1.414213562373095<_pom/>3.5<_E/>¯12<br />
</pre></apll><br />
<br />
As you can see, after a few iterations, the accuracy of the result doesn't improve. However, because it is an iterative algorithm, the precision worsens as the number of iterations increases. Only by using Ball Arithmetic can you see just how the precision of the result is affected.<br />
<br />
To demonstrate with an extreme example, consider the following function:<br />
<br />
<apll><pre><br />
f←{⍪⍵-3√(⍵*3)-⍵*2}<br />
f 10*3×⍳5<br />
0.33344450621439137<br />
0.3333334452472627 <br />
0.33333444595336914<br />
0.3348388671875 <br />
2.25<br />
</pre></apll><br />
<br />
Without knowing much about this ([https://en.wikipedia.org/wiki/Condition_number ill-conditioned]) algorithm, you have no reason to suspect these results. As it turns out, there's a mathematical proof that as the argument increases to infinity, the algorithm converges to <apll>÷3</apll>. Only when you calculate with Ball Arithmetic do you see that there is a problem:<br />
<br />
<apll><pre><br />
f 10*3×⍳5<_pom/><br />
0.3334445062153009<_pom/>2.2<_E/>¯12 <br />
0.3333334461785853<_pom/>4.3<_E/>¯9 <br />
0.333337664604187<_pom/>0.0000062<br />
0.3385009765625<_pom/>0.0085<br />
1.25<_pom/>5<br />
</pre></apll><br />
<br />
As you can see, the precision worsens quickly to the point where the result is meaningless. The last line even says that the answer lies somewhere between <apll>¯3.75</apll> and <apll>6.25</apll>. In other words, that answer is so '''imprecise''' as to be '''inaccurate'''! At higher powers of ten, the answers only worsen.<br />
<br />
The good news with Ball Arithmetic is that if you need greater precision, just increase the value of <apll>⎕FPC</apll>. For example,<br />
<br />
<apll><pre><br />
⎕FPC←128 ⋄ ⎕PP←40<br />
sqrt 2<_pom/><br />
1.41421356237309504880168872420969807857<_pom/>5.9<_E/>¯39<br />
</pre></apll><br />
<br />
In the case of an ill-conditioned algorithm, we just push the problem off a bit, but not very far &mdash; the problem is that the algorithm requires infinite precision:<br />
<br />
<apll><pre><br />
f 10*3×⍳10<_pom/><br />
0.333444506214021971364848444464298690637<_pom/>3.4<_E/>¯35<br />
0.333333444444506172880658466392407138179<_pom/>1.1<_E/>¯31<br />
0.333333333444444444506172839632668381652<_pom/>1.6<_E/>¯28<br />
0.333333333333444444444444547458328123363<_pom/>2.2<_E/>¯25<br />
0.333333333333333444444619474517508476812<_pom/>3.2<_E/>¯22<br />
0.333333333333333333552432522356445687706<_pom/>1.3<_E/>¯19<br />
0.333333333333333491771410805881714622956<_pom/>4.5<_E/>¯16<br />
0.333333333333417414223731611855328083038<_pom/>4.5<_E/>¯13<br />
0.33333333363771089352667331695556640625<_pom/>4.5<_E/>¯10 <br />
0.3333334587514400482177734375<_pom/>2.6<_E/>¯7<br />
</pre></apll><br />
<br />
While your floating point code might not be so ill-conditioned, the only way to be sure of its results is one of<br />
<br />
<ul><br />
<li>Hire a Numerical Analyst</li><br />
<li>Become a Numerical Analyst</li><br />
<li>Use Ball Arithmetic</li><br />
</ul><br />
<br />
==Ball Arithmetic Numbers==<br />
<br />
A Ball Arithmetic number consist of two parts: a Midpoint and Radius. The Midpoint value represents the middle of the Ball and the Radius represents the distance around the Ball of possible values. There is no way to tell which value in the Ball is the correct answer &mdash; you should assume that all values are potential candidates. <br />
<br />
The precision at which the Midpoint and Radius are stored depends upon the current value of <apll>⎕FPC</apll>. For example, the following display<br />
<br />
<apll><pre><br />
⎕FPC←53<br />
÷3<_pom/><br />
0.3333333333333333<_pom/>5.6<_E/>¯17<br />
</pre></apll><br />
<br />
indicates that the number <apll>÷3<_pom/></apll> has a Midpoint of <apll>0.3333333333333333</apll> at <apll>53</apll>-bit precision and a Radius of <apll>5.6<_E/>¯17</apll>. The Midpoint is stored as a variable precision number, and the Radius is stored as a low-precision number.<br />
<br />
Alternatively,<br />
<br />
<apll><pre><br />
⎕FPC←128 ⋄ ⎕PP←40<br />
÷3<_pom/><br />
0.333333333333333333333333333333333333332<_pom/>1.5<_E/>¯39<br />
</pre></apll><br />
<br />
shows the corresponding value at a higher precision and correspondingly narrower Radius.<br />
<br />
<p><br />
The approximate number of digits of precision for a given value of <apll>⎕FPC</apll> is about <apll>10⍟2*⎕FPC</apll>. The value of <apll>⎕FPC</apll> for a given required precision is about <apll>⌈2⍟10*digits</apll>.<br />
</p><br />
<br />
<p><br />
The current <apll>⎕FPC</apll> precision<br />
should be sufficient to cover both the midpoint and the radius<br />
of all ball numbers being used.<br />
Otherwise,<br />
some results might be misleading.<br />
</p><br />
<br />
<p><br />
For example,<br />
</p><br />
<p><apll><br />
2v*⎕fpc←128<br />
3.402823669E38<br />
⍟ ⎕← * 1±1e¯1000<br />
2.718281828±1.2E¯38<br />
1±7.3E¯39<br />
</apll></p><br />
<br />
<p><br />
What happened? -- <apll>⎕FPC</apll> was too small!<br />
</p><br />
<br />
<p><apll><br />
2v*⎕fpc←4096<br />
1.044388881E1233<br />
⍟ ⎕← * 1±1e¯1000<br />
2.718281828±2.7E¯1000<br />
1±1E¯1000<br />
</apll></p><br />
<br />
<p> </p><br />
<br />
A Ball describes a range of '''variable-precision floating point numbers''', and so the expression <apll>23<_pom/>1</apll> represents the set of Real numbers between <apll>22</apll> and <apll>24</apll>, inclusive, '''not''' the three integers <apll>22</apll>, <apll>23</apll>, <apll>24</apll>.<br />
<br />
<p class="note" style=" background-color:lightcyan;">In general, suffix notation on Ball Arithmetic constants should be sufficient for '''almost all purposes'''. That is, the Radius is already correctly calculated for constants such as <apll>23<_pom/></apll> whose Radius is zero, and <apll>1.2<_pom/></apll> whose Radius at <apll>53</apll> bits of precision is on the order of <apll>2*¯53</apll> (because of the inexactness of the Midpoint <apll>1.2</apll>) which displays as <apll>1.2<_pom/>2.2<_E/>¯16</apll>. Although the input notation supports it, the need to override the default Radius should be '''quite rare'''.</p><br />
<br />
==New Functions and Operator==<br />
<br />
===Functions To Convert To And From Ball Arithmetic Numbers===<br />
<br />
A Ball Arithmetic constant number may be created through notation (as seen above). Otherwise, a Ball Arithmetic number also may be created from its constituent parts under program control with a new primitive function '''Contract''', and separated into its constituent parts with a new primitive function '''Distract'''.<br />
<br />
====Contract====<br />
<br />
'''Contract''' is a monadic function (<apll>≤R</apll>) whose right argument is a Real array. It may be used to create a Ball Arithmetic number from the one- or two-elements of its Real number Midpoint and (optional) Real number Radius. The Axis Operator may specify any length <apll>1</apll> or <apll>2</apll> coordinate along which the conversion takes place. It converts the first element along the specified dimension to the Midpoint of the result and (if present) the second element to its Radius. If the second element is not present (i.e., length <apll>1</apll> coordinate), the Radius used is calculated from the precision of the Midpoint.<br />
<br />
<apll><pre><br />
≤23<br />
23<br />
≤1.2<br />
1.2<_pom/>1.1<_E/>¯16<br />
≤1.3 1<_E/>¯20<br />
1.3<_pom/>1<_E/>¯20<br />
≤1r2 1<_E/>¯20<br />
0.5<_pom/>1<_E/>¯20<br />
≤○1<br />
3.141592653589793<_pom/>1.1<_E/>¯16 <br />
≤(○1) 1<_E/>¯20<br />
3.141592653589793<_pom/>1<_E/>¯20 <br />
</pre></apll><br />
<br />
The domain of this function is limited to Real numbers. Hypercomplex numbers signal a <apll>DOMAIN ERROR</apll>.<br />
<br />
====Distract====<br />
<br />
'''Distract''' is a monadic function (<apll>≥R</apll>) whose right argument is a Real array. It may be used to separate out a Ball Arithmetic's Midpoint and Radius into two distinct values. The Axis Operator may specify the place where the new length <apll>2</apll> coordinate is to be inserted. The pair of values along this new coordinate are the Midpoint and Radius of the corresponding number from the right argument. If the number can be represented exactly, the Radius is zero.<br />
<br />
<apll><pre><br />
⎕PP←10<br />
≥1.2<br />
1.2 1.1102230246251565<_E/>¯16<br />
≥1.2<_x/><br />
6<_r/>5 0<br />
≥1.2<_v/><br />
1.2 1.110223024625157<_E/>¯16<br />
≥1.2<_pom/><br />
1.2 2.220446049250313<_E/>¯16<br />
≥1.5<br />
1.5 0<br />
≥1.5<_x/><br />
3<_r/>2 0<br />
≥1.5<_v/><br />
1.5 1.110223024625157<_E/>¯16<br />
≥1.5<_pom/><br />
1.5 0<br />
a←(○1<_pom/>)×⍳4<br />
a,'|',≥a<br />
3.141592654<_pom/>4.4<_E/>¯16 | 3.141592654 4.440892148<_E/>¯16<br />
6.283185307<_pom/>8.9<_E/>¯16 | 6.283185307 8.881784296<_E/>¯16<br />
9.424777961<_pom/>1.3<_E/>¯15 | 9.424777961 1.332267643<_E/>¯15<br />
12.56637061<_pom/>1.8<_E/>¯15 | 12.56637061 1.776356859<_E/>¯15<br />
</pre></apll><br />
<br />
These numbers can be represented exactly:<br />
<br />
<apll><pre><br />
≥⍳4<_pom/><br />
1 0<br />
2 0<br />
3 0<br />
4 0<br />
≥[2]⍳4<_pom/><br />
1 0<br />
2 0<br />
3 0<br />
4 0<br />
≥[1]⍳4<_pom/><br />
1 2 3 4<br />
0 0 0 0<br />
</pre></apll><br />
<br />
====Identities====<br />
<br />
The Contract of the Distract of a number both along the same axis, returns the same number.<br />The Distract of the Contract of a number both along the same length two axis, returns the same number.<br />
<br />
===Operator To Provide Arbitrary Precision Specific Derived Functions===<br />
<br />
The DoubleTilde monadic operator (<apll>≈</apll>, Alt-'Q' or Alt-shift-'q') takes a primitive function as its left operand and produces an arbitrary-precision-specific derived function.<br />
<br />
This operator should be considered preliminary.<br />
<br />
====Conversion Between Balls and Intervals====<br />
<br />
At the moment, the monadic derived function is defined for two primitive functions.<br />
<br />
Because Ball Arithmetic has a close relationship with Interval Arithmetic, it may be desirable to convert between the two forms: Endpoint to Midpoint-Radius and its inverse. The resulting derived function is not scalar.<br />
<br />
For example,<br />
<br />
<apll><pre><br />
x←0<_pom/>∞ 1<_pom/>2<br />
≥≈x<br />
¯∞ ∞<br />
¯1 3<br />
≥[1]≈x<br />
¯∞ ¯1<br />
∞ 3<br />
≥[2]≈x<br />
¯∞ ∞<br />
¯1 3<br />
≤≈≥≈x<br />
0<_pom/>∞ 1<_pom/>2<br />
≤≈≥[2]≈x<br />
0<_pom/>∞ 1<_pom/>2<br />
≤[2]≈≥≈x<br />
0<_pom/>∞ 1<_pom/>2<br />
≤[2]≈≥[2]≈x<br />
0<_pom/>∞ 1<_pom/>2 <br />
≤[1]≈≥[1]≈x<br />
0<_pom/>∞ 1<_pom/>2 <br />
</pre></apll><br />
<br />
The domain of these functions is limited to Real numbers. Hypercomplex numbers signal a <apll>DOMAIN ERROR</apll>. To see the Endpoints of a Hypercomplex number, first '''Dilate''' it so as to separate out the coefficients and then apply <apll>≥≈</apll> to extract the Endpoints as in <apll>≥≈&gt;R</apll>.<br />
<br />
For example,<br />
<br />
<apll><pre> ≥≈ 2±0i0±1<br />
DOMAIN ERROR<br />
≥≈ 2±0i0±1<br />
∧<br />
≥≈>2±0i0±1<br />
2 2<br />
¯1 1<br />
<≤≈≥≈>2±0i0±1<br />
2±0i0±1<br />
</pre></apll><br />
<br />
====Union and Intersection of Balls====<br />
<br />
The left operand of the DoubleTilde operator is defined for the '''Union''' and '''Intersection''' functions (<apll>∪∩</apll>) as follows: <br />
<br />
Because Ball arithmetic numbers represent a range of floating point numbers, at times it is desirable to produce their Union or Intersection.<br />
<br />
For example,<br />
<br />
<apll><pre><br />
x←0.5<pom/>0.5 ⍝ The interval [0,1]<br />
x∪≈x+2 ⍝ The interval [0,1] ∪ [2,3] ←→ [0,3]<br />
1.5<pom/>1.5<br />
x∪≈x+1 ⍝ The interval [0,1] ∪ [1,2] ←→ [0,2]<br />
1<pom/>1 <br />
x∩≈x+1 ⍝ The interval [0,1] ∩ [1,2] ←→ [1,1]<br />
1<br />
</pre></apll><br />
<br />
If two Balls have no points in common, the result is a NaN (<apll>∅</apll>):<br />
<br />
<apll><pre><br />
x∩≈x+1.1 ⍝ The interval [0,1] ∩ [1.1,2.1] ←→ ∅<br />
∅<br />
</pre></apll><br />
<br />
The identity element for <apll>∩≈</apll> is <apll>0±∞</apll>.<br />
<br />
The derived functions are scalar.<br />
<br />
====Comparison Functions====<br />
<br />
The left operand of the DoubleTilde operator is defined for the six comparison functions (<apll>&lt;≤=≥&gt;≠</apll>) as follows:<br />
<br />
For <apll><i>f</i></apll> as one of the above six functions, <apll>L<i>f</i>≈R</apll> is TRUE iff for all <apll>t∊L</apll> and <apll>u∊R</apll>, then <apll>&nbsp;&nbsp;t f u&nbsp;&nbsp;</apll> is TRUE. These comparisons are all done with <apll>⎕CT←0</apll> because, in a sense, Ball comparisons carry their own Fuzz.<br />
<br />
For example,<br />
<br />
<apll><pre> (L R)←4<_pom/>1 6<_pom/>1<br />
L<≈R<br />
0<br />
L≤≈R<br />
1<br />
</pre></apll><br />
<br />
The derived functions are scalar.<br />
<br />
====Containing Functions====<br />
<br />
The left operand of the DoubleTilde operator is defined for two containing functions (<apll>⊂⊃</apll>) as follows:<br />
<br />
The expression <apll>L⊂≈R</apll> is TRUE iff for all <apll>t∊L</apll> it is TRUE that <apll>t∊R</apll> and that the containment is strict &mdash; that is, none of the endpoints match.<br />
<br />
The expression <apll>L⊃≈R</apll> is TRUE iff <apll>R⊂≈L</apll> is TRUE.<br />
<br />
For example,<br />
<br />
<apll><pre><br />
(L R)←6±4 6±2<br />
L⊃≈R<br />
1<br />
R⊂≈L<br />
1<br />
</pre></apll><br />
<br />
The derived functions are scalar.<br />
<br />
====Positional Relationships====<br />
<br />
For <apll>L</apll> and <apll>R</apll> as finite intervals with non-zero Radii (i.e., multi-valued), here are the possible '''Relative Positions''' between the two Intervals, where <apll>L0</apll>, <apll>L1</apll> and <apll>R0</apll>, <apll>R1</apll> are the endpoints of <apll>L</apll> and <apll>R</apll>, respectively &mdash; <apll>(L0 L1)←≥≈L</apll> and <apll>(R0 R1)←≥≈R</apll>:<br />
<br />
<table border="1" cellspacing="0" rowspacing="5" style="font-family:APL385, SImPL;"><br />
<th>Relative<br/>Positions</th><br />
<th>Endpoint<br/>Relationships</th><br />
<th colspan="2">Defining<br/>Expressions</th><br />
<th>Sample Data<br/>L &nbsp; R</th><br />
<th>Distinct<br/>Ball<br/>{⍺∘≈⍵}</th><br />
<br />
<tr><br />
<td>&nbsp;├──L──┤<br/>&nbsp;├──R──┤&nbsp;</td><br />
<td>&nbsp;L0 L1≡R0 R1&nbsp;</td><br />
<td>&nbsp;L=≈R&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 6<_pom/>4&nbsp;</td><br />
<td>&nbsp;&nbsp;0&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──L──┤<br/>&nbsp;├──R─┤&nbsp;</td><br />
<td>&nbsp;(L0=R0)∧L1&gt;R1&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 5<_pom/>3&nbsp;</td><br />
<td>&nbsp;&nbsp;1&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──L─┤<br/>&nbsp;├──R──┤&nbsp;</td><br />
<td>&nbsp;(L0=R0)∧L1&lt;R1&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 7<_pom/>5&nbsp;</td><br />
<td>&nbsp;¯1&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──L──┤<br/>&nbsp;&nbsp;├──R─┤&nbsp;</td><br />
<td>&nbsp;(L0&lt;R0)∧L1=R1&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 7<_pom/>3&nbsp;</td><br />
<td>&nbsp;&nbsp;2&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;&nbsp;├──L─┤<br/>&nbsp;├──R──┤&nbsp;</td><br />
<td>&nbsp;(L0&gt;R0)∧L1=R1&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 5<_pom/>5&nbsp;</td><br />
<td>&nbsp;¯2&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──L──┤<br/>&nbsp;&nbsp;├─R─┤&nbsp;</td><br />
<td>&nbsp;(L0&lt;R0)∧L1&gt;R1&nbsp;</td><br />
<td>&nbsp;L⊃≈R&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 6<_pom/>2&nbsp;</td><br />
<td>&nbsp;&nbsp;3&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;&nbsp;├─L─┤<br/>&nbsp;├──R──┤&nbsp;</td><br />
<td>&nbsp;(L0&gt;R0)∧L1&lt;R1&nbsp;</td><br />
<td>&nbsp;L⊂≈R&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 6<_pom/>6&nbsp;</td><br />
<td>&nbsp;¯3&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──L──┤<br/>&nbsp;&nbsp;├──R──┤&nbsp;</td><br />
<td>&nbsp;(L0&lt;R0)∧(L1&lt;R1)∧L1&gt;R0&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 8<_pom/>4&nbsp;</td><br />
<td>&nbsp;&nbsp;4&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;&nbsp;├──L──┤<br/>&nbsp;├──R──┤&nbsp;</td><br />
<td>&nbsp;(L0&gt;R0)∧(L1&gt;R1)∧L0&lt;R1&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 4<_pom/>4&nbsp;</td><br />
<td>&nbsp;¯4&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──L──┼──R──┤&nbsp;</td><br />
<td>&nbsp;L1=R0&nbsp;</td><br />
<td>&nbsp;(L≤≈R)&gt;L&lt;≈R&nbsp;</td><br />
<td>&nbsp;L=∀R&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 14<_pom/>4&nbsp;</td><br />
<td>&nbsp;&nbsp;5&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──R──┼──L──┤&nbsp;</td><br />
<td>&nbsp;L0=R1&nbsp;</td><br />
<td>&nbsp;(L≥≈R)&gt;L&gt;≈R&nbsp;</td><br />
<td>&nbsp;L=∃R&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 0<_pom/>2&nbsp;</td><br />
<td>&nbsp;¯5&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──L──┤&nbsp;├──R──┤&nbsp;</td><br />
<td>&nbsp;L1&lt;R0&nbsp;</td><br />
<td>&nbsp;L&lt;≈R&nbsp;</td><br />
<td>&nbsp;L&lt;∀R&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 17<_pom/>5&nbsp;</td><br />
<td>&nbsp;&nbsp;6&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──R──┤&nbsp;├──L──┤&nbsp;</td><br />
<td>&nbsp;L0&gt;R1&nbsp;</td><br />
<td>&nbsp;L&gt;≈R&nbsp;</td><br />
<td>&nbsp;L&gt;∃R&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 0<_pom/>1&nbsp;</td><br />
<td>&nbsp;¯6&nbsp;</td><br />
</tr><br />
</table><br />
<br />
The above table can be interpreted as follows:<br />
<br />
<ul><br />
<li>The first column lists all possible '''Relative Positions''' two finite non-zero Radii (i.e., multi-valued) Balls may assume.</li><br />
<li>The second column lists the '''Endpoint Relationship''' that defines the corresponding '''Relative Position'''.</li><br />
<li>The third column lists a '''Defining Expression''' using the '''DoubleTilde''' operator that is TRUE for the corresponding '''Relative Position''' and FALSE for all of the other '''Relative Positions''' in different rows.</li><br />
<li>The fourth column lists a '''Defining Expression''' using the '''Always''' and '''Possibly''' operators [http://forum.nars2000.org/ball-arithmetic-t614.html#p1803 proposed] by David Rabenhorst.</li><br />
<li>The fifth column contains '''Sample Data''' that defines the corresponding '''Relative Position'''.</li><br />
<li>The sixth column gives the value of the '''Distinct Ball''' function <apll>{⍺∘≈⍵}</apll> when executed on the '''Sample Data'''.</li><br />
</ul><br />
<br />
Note the table is organized such that apart from the first row (whose '''Endpoint Relationship''' is Symmetric in <apll>L</apll> and <apll>R</apll>) the rows occur in six pairs where the '''Endpoint Relationship''' for each row in the pair can be obtained from the other by swapping <apll>L</apll> and <apll>R</apll>. The pairs of rows are ordered roughly by the amount of overlap between the two Balls.<br />
<br />
As you can see, we are missing '''Defining Expressions''' for several of the '''Relative Positions'''. I was hoping that this table would be filled in with more detail so it would serve as a measure of whether or not we had a complete set of functions/operators which could be used to tell apart all of the '''Relative Positions''' without having to resort to the '''Distinct Ball''' function <apll>{⍺∘≈⍵}</apll> constructed explicitly for this purpose. Please add to this table if you find a missing expression, or wish to propose whole new functions and/or operators.<br />
<br />
If you would like to try a '''Defining Expression''' on the '''Sample Data''', collect the data into a <apll>13</apll> by <apll>2</apll> matrix, put your '''Defining Expression''' into (say) an Anonymous Function and reduce the same data matrix along the last coordinate &mdash; if you have a successful function, you should see a <apll>13</apll>-element Boolean vector with a single one in it. For example,<br />
<br />
<apll><pre><br />
sd←6<_pom/>4,⍪6<_pom/>4 5<_pom/>3 7<_pom/>5 7<_pom/>3 5<_pom/>5 6<_pom/>2 6<_pom/>6 8<_pom/>4 4<_pom/>4 14<_pom/>4 0<_pom/>2 17<_pom/>5 0<_pom/>1<br />
{(⍺≤≈⍵)>⍺<≈⍵}/sd<br />
0 0 0 0 0 0 0 0 0 1 0 0 0 <br />
{(⍺≥≈⍵)>⍺>≈⍵}/sd<br />
0 0 0 0 0 0 0 0 0 0 1 0 0 <br />
{⍺<≈⍵}/sd<br />
0 0 0 0 0 0 0 0 0 0 0 1 0 <br />
{⍺>≈⍵}/sd<br />
0 0 0 0 0 0 0 0 0 0 0 0 1<br />
</pre></apll><br />
<br />
Finally, the following example shows that the '''Sample Data''' are all distinct:<br />
<br />
<apll><pre><br />
{⍺∘≈⍵}/sd<br />
0 1 ¯1 2 ¯2 3 ¯3 4 ¯4 5 ¯5 6 ¯6<br />
</pre></apll><br />
<br />
==Hypercomplex Ball Arithmetic==<br />
<br />
Ball Arithmetic also extends to all Hypercomplex numbers (Complex, Quaternion, and Octonion) such as <apll>1.2<_pom/><_i/>2.2</apll> which represents a Complex Ball Arithmetic number whose '''Real''' part is <apll>1.2<_pom/></apll> and whose '''Imaginary''' part is <apll>2.2<_pom/></apll>. Note that the display of that number (at <apll>53</apll> bits of precision)<br />
<br />
<apll><pre><br />
1.2<_pom/><_i/>2.2<br />
1.2<_pom/>2.2<_E/>¯16<_i/>2.2<_pom/>4.4<_E/>¯16<br />
</pre></apll><br />
<br />
demonstrates the inexactness of both floating point coefficients.<br />
<br />
==Small v. Large Radii==<br />
<br />
Ball Arithmetic works best when given small Radii, that is, small relative to the Midpoint. Calculations on large Radii numbers such as <apll>0<_i/>0.5<_pom/>0.5</apll> don't always produce useful results. For example,<br />
<br />
<apll><pre><br />
⎕PP←8 ⍝ To reduce fractional clutter<br />
x←0<_i/>0.5<_pom/>0.5<br />
√x<br />
0.4267767<_pom/>0.57<_i/>0<_pom/>1.4<br />
</pre></apll><br />
<br />
Unfortunately in this case, because the Radius is so large it overwhelms the Midpoint, as can be seen when we Square the Square Root:<br />
<br />
<apll><pre><br />
(√x)*2<br />
0.18213835<_pom/>2.8<_i/>0<_pom/>2.8<br />
x=(√x)*2<br />
0<br />
</pre></apll><br />
<br />
These calculations work better using smaller Radii, such as<br />
<br />
<apll><pre><br />
y←0<_i/>0.5<_pom/>0.5<_E/>¯30<br />
√y<br />
0.5<_pom/>2.5<_E/>¯31<_i/>0.5<_pom/>7.5<_E/>¯31<br />
(√y)*2<br />
0<_pom/>1<_E/>¯30<_i/>0.5<_pom/>1<_E/>¯30 <br />
y=(√y)*2<br />
1<br />
</pre></apll><br />
<br />
where Square Root now returns a meaningful result, and its Square returns the original value.<br />
<br />
==Mixed Notation==<br />
<br />
The notation for Ball Arithmetic may be combined with other Point Notations in many ways, such as<br />
<br />
<apll><pre><br />
1<_p/>1<_pom/><br />
3.141592653589793<_pom/>4.4<_E/>¯16 <br />
1<_x/>1<_pom/><br />
2.718281828459045<_pom/>4.5<_E/>¯16<br />
</pre></apll><br />
<br />
For more details about combining different forms of Point Notation, see [[Point_Notation|Point Notation]] and in particular the section on [[Point_Notation#Mixed_Notation|Mixed Notation]].<br />
<br />
==Implementation==<br />
<br />
===Datataypes===<br />
<br />
This feature adds four new datatypes to the language: one each for the four Division Algebras. Note that marking any one of the Hypercomplex coefficients as a Ball automatically marks them all as Balls.<br />
{|<br />
|-<br />
|Real||&nbsp;&nbsp;&nbsp;&nbsp;<apll>23<_pom/></apll> or <apll>1.2<_pom/></apll><br />
|-<br />
|Complex||&nbsp;&nbsp;&nbsp;&nbsp;<apll>23<_i/>1.2<_pom/></apll><br />
|-<br />
|Quaternion||&nbsp;&nbsp;&nbsp;&nbsp;<apll>23<_i/>1.2<_j/>0.5<_k/>¯3.14<_pom/></apll><br />
|-<br />
|Octonion||&nbsp;&nbsp;&nbsp;&nbsp;<apll>23<_i/>1.2<_j/>0.5<_k/>¯3.14<l/>¯3<_ij/>19<_jk/>¯3<_kl/>6<_pom/></apll><br />
|}<br />
<br />
===Primitive Functions===<br />
<br />
As described above, this feature adds two new monadic primitive functions '''Contract''' (<apll>≤R</apll>) and its inverse '''Distract''' (<apll>≥R</apll>), along with one new monadic primitive operator '''DoubleTilde''' <apll>f≈ R</apll> and <apll>L f≈ R</apll>.<br />
<br />
All primitive and system functions and operators are extended to work with Ball Arithmetic, so you can test out this feature on all algorithms, with the exception of trying to find the Factorial of a multiple-precision/Ball Arithmetic Hypercomplex number, in which case you are temporarily out of luck.<br />
<br />
==Workspace Version Number==<br />
<br />
For the moment, if you save a workspace which contains a Ball Arithmetic number in a variable, the workspace version number is <apll>0.03</apll>. Otherwise, the version number is <apll>0.02</apll>. Workspaces with Ball Arithmetic Numbers may not be loaded by an earlier version of the interpreter.<br />
<br />
==Pending Design Decisions==<br />
<br />
<ul><br />
<li>The direct comparison functions (<apll>&lt;≤=≥&gt;≠≡≢</apll>) and indirect ones (<apll>⍳⍸∊⍷⍒⍋</apll>) are currently implemented to compare the Midpoints of the arguments ignoring the Radius &mdash; this may change.</li><br />
<li>The Floor function and its related functions (Ceiling, Residue, GCD, LCM, and Encode) are currently implemented to execute on the Midpoints of the arguments ignoring the Radius &mdash; this may change.</li><br />
<li>We need new primitives to describe the different ways in which Balls can intersect/overlap, possibly through a new monadic operator (perhaps &#x2248;) on the existing direct and indirect comparison and Floor-related functions.</li><br />
<li>Certain primitives are defined on limited ranges, and sometimes multiple ranges where it might use different algorithms for different ranges (e.g. <apll>L!R</apll>). There are open questions about how to handle a Ball that spans two or more of these ranges as to how to calculate the result.</li><br />
<li>Infinity and NaN have not been given any special treatment as yet. The results are whatever ARB has chosen which we may need to override.</li><br />
</ul><br />
<br />
==Download==<br />
<br />
This feature is available as an Alpha release &mdash; it may be downloaded from the [http://www.nars2000.org/download/binaries/alpha/ Alpha] release directory.<br />
<br />
==Acknowledgements==<br />
<br />
<ul><br />
<li>The Arb team has contributed their Ball Arithmetic<ref name="BallArithmetic" /> code which made this feature possible.</li><br />
<li>David Rabenhorst has contributed many very useful ideas and many hours debugging the implementation.</li><br />
</ul><br />
<br />
==References==<br />
<br />
<references /></div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=Ball_Arithmetic&diff=3367Ball Arithmetic2018-10-23T20:10:35Z<p>Sudleyplace: /* Conversion Between Balls and Intervals */</p>
<hr />
<div>==Introduction==<br />
<br />
Ball<ref name="BallArithmetic">NARS2000 Wiki, [http://arblib.org Ball Arithmetic]</ref> and Interval Arithmetic<ref name="IntervalArithmetic">Wikipedia, [https://en.wikipedia.org/wiki/Interval_arithmetic Interval Arithmetic]</ref> both refer to the same idea of calculating with arbitrary precision inexact numbers &mdash; that is, with a range of floating point values instead of a single representative. This allows such numbers to reflect their inexactness explicitly.<br />
<br />
"The most common use is to keep track of and handle rounding errors directly during the calculation and of uncertainties in the knowledge of the exact values of physical and technical parameters. The latter often arise from measurement errors and tolerances for components or '''due to limits on computational accuracy'''. Interval arithmetic also helps find reliable and guaranteed solutions to equations and optimization problems."<ref name="IntervalArithmetic" /><br />
<br />
The difference between the two is in how each approach represents its values: Interval Arithmetic uses the two ends of the interval <apll>[a, b]</apll> whereas Ball Arithmetic uses a Ball with a Midpoint and Radius. Each has its advantages. Interval Arithmetic is implemented by several libraries such as MPFI<ref name="MPFI">[http://perso.ens-lyon.fr/nathalie.revol/software.html MPFI]</ref> and Ball Arithmetic is implemented by ARB<ref name="BallArithmetic" />.<br />
<br />
This feature uses the ARB<ref name="BallArithmetic" /> library to implement Ball Arithmetic.<br />
<br />
==Environment==<br />
<br />
In the examples below, unless otherwise specified, the precision of multi-precision floating-point numbers is set to <apll>53</apll> bits via <apll>⎕FPC←53</apll> which is the same precision as standard double-precision numbers. The Printing Precision is set to <apll>17</apll> digits via <apll>⎕PP←17</apll> so as to display the maximum number of significant digits at <apll>53</apll> bits of precision. The Comparison Tolerance is set via <apll>⎕CT←1<_E/>¯10</apll>.<br />
<br />
==Calculating With Ball Arithmetic==<br />
<br />
If you have ever entered an expression such as<br />
<br />
<apll><pre><br />
÷3<br />
0.3333333333333333<br />
</pre></apll><br />
<br />
undoubtedly, you are aware that the result is inexact. Moreover, as you incorporate into your code the many other functions that produce inexact numbers, you should be wondering "How does the accumulation of inexactness affect my results?".<br />
<br />
The answer to that question lies in the province of [https://en.wikipedia.org/wiki/Numerical_analysis Numerical Analysis] where it is described as "the study of algorithms that use numerical approximation". In general, applying the techniques of Numerical Analysis often involves time-consuming analysis. Fortunately, Ball Arithmetic is an easy to use alternative to that. That is, instead of analyzing the algorithm, run the algorithm with all calculations done with Ball Arithmetic.<br />
<br />
Here is the same expression in Ball Arithmetic (use Alt-‘q’ or Ctrl-‘q’, depending on your keyboard layout, to enter the <apll><_pom/></apll> symbol):<br />
<br />
<apll><pre><br />
÷3<_pom/><br />
0.3333333333333333<_pom/>5.6<_E/>¯17<br />
</pre></apll><br />
<br />
Essentially, each Ball Arithmetic number carries with it an explicit Radius that describes the interval which contains the true value. Because Ball Arithmetic data propagates throughout a calculation and is never demoted to a lower datatype, its advantage is that after each operation the resulting Ball reliably includes the true answer. Across an entire algorithm, the final result is a Ball that indicates explicitly how precise it is, thus eliminating the guesswork as to the effect on the algorithm of the inexactness of the input and any other inexact constants used.<br />
<br />
For example,<br />
<br />
<apll><pre><br />
sqrt←{⍺←= ⋄ {0.5×⍵+⍺÷⍵}⍣⍺⍨⍵} ⍝ Calculate square root using Newton's method<br />
√2<_pom/><br />
1.414213562373095<_pom/>2.2<_E/>¯16<br />
sqrt 2<_pom/><br />
1.414213562373095<_pom/>1.1<_E/>¯15 <br />
10 sqrt 2<_pom/><br />
1.414213562373095<_pom/>2.8<_E/>¯15 <br />
100 sqrt 2<_pom/><br />
1.414213562373095<_pom/>3.3<_E/>¯14 <br />
1000 sqrt 2<_pom/><br />
1.414213562373095<_pom/>3.3<_E/>¯13 <br />
10000 sqrt 2<_pom/><br />
1.414213562373095<_pom/>3.5<_E/>¯12<br />
</pre></apll><br />
<br />
As you can see, after a few iterations, the accuracy of the result doesn't improve. However, because it is an iterative algorithm, the precision worsens as the number of iterations increases. Only by using Ball Arithmetic can you see just how the precision of the result is affected.<br />
<br />
To demonstrate with an extreme example, consider the following function:<br />
<br />
<apll><pre><br />
f←{⍪⍵-3√(⍵*3)-⍵*2}<br />
f 10*3×⍳5<br />
0.33344450621439137<br />
0.3333334452472627 <br />
0.33333444595336914<br />
0.3348388671875 <br />
2.25<br />
</pre></apll><br />
<br />
Without knowing much about this ([https://en.wikipedia.org/wiki/Condition_number ill-conditioned]) algorithm, you have no reason to suspect these results. As it turns out, there's a mathematical proof that as the argument increases to infinity, the algorithm converges to <apll>÷3</apll>. Only when you calculate with Ball Arithmetic do you see that there is a problem:<br />
<br />
<apll><pre><br />
f 10*3×⍳5<_pom/><br />
0.3334445062153009<_pom/>2.2<_E/>¯12 <br />
0.3333334461785853<_pom/>4.3<_E/>¯9 <br />
0.333337664604187<_pom/>0.0000062<br />
0.3385009765625<_pom/>0.0085<br />
1.25<_pom/>5<br />
</pre></apll><br />
<br />
As you can see, the precision worsens quickly to the point where the result is meaningless. The last line even says that the answer lies somewhere between <apll>¯3.75</apll> and <apll>6.25</apll>. In other words, that answer is so '''imprecise''' as to be '''inaccurate'''! At higher powers of ten, the answers only worsen.<br />
<br />
The good news with Ball Arithmetic is that if you need greater precision, just increase the value of <apll>⎕FPC</apll>. For example,<br />
<br />
<apll><pre><br />
⎕FPC←128 ⋄ ⎕PP←40<br />
sqrt 2<_pom/><br />
1.41421356237309504880168872420969807857<_pom/>5.9<_E/>¯39<br />
</pre></apll><br />
<br />
In the case of an ill-conditioned algorithm, we just push the problem off a bit, but not very far &mdash; the problem is that the algorithm requires infinite precision:<br />
<br />
<apll><pre><br />
f 10*3×⍳10<_pom/><br />
0.333444506214021971364848444464298690637<_pom/>3.4<_E/>¯35<br />
0.333333444444506172880658466392407138179<_pom/>1.1<_E/>¯31<br />
0.333333333444444444506172839632668381652<_pom/>1.6<_E/>¯28<br />
0.333333333333444444444444547458328123363<_pom/>2.2<_E/>¯25<br />
0.333333333333333444444619474517508476812<_pom/>3.2<_E/>¯22<br />
0.333333333333333333552432522356445687706<_pom/>1.3<_E/>¯19<br />
0.333333333333333491771410805881714622956<_pom/>4.5<_E/>¯16<br />
0.333333333333417414223731611855328083038<_pom/>4.5<_E/>¯13<br />
0.33333333363771089352667331695556640625<_pom/>4.5<_E/>¯10 <br />
0.3333334587514400482177734375<_pom/>2.6<_E/>¯7<br />
</pre></apll><br />
<br />
While your floating point code might not be so ill-conditioned, the only way to be sure of its results is one of<br />
<br />
<ul><br />
<li>Hire a Numerical Analyst</li><br />
<li>Become a Numerical Analyst</li><br />
<li>Use Ball Arithmetic</li><br />
</ul><br />
<br />
==Ball Arithmetic Numbers==<br />
<br />
A Ball Arithmetic number consist of two parts: a Midpoint and Radius. The Midpoint value represents the middle of the Ball and the Radius represents the distance around the Ball of possible values. There is no way to tell which value in the Ball is the correct answer &mdash; you should assume that all values are potential candidates. <br />
<br />
The precision at which the Midpoint and Radius are stored depends upon the current value of <apll>⎕FPC</apll>. For example, the following display<br />
<br />
<apll><pre><br />
⎕FPC←53<br />
÷3<_pom/><br />
0.3333333333333333<_pom/>5.6<_E/>¯17<br />
</pre></apll><br />
<br />
indicates that the number <apll>÷3<_pom/></apll> has a Midpoint of <apll>0.3333333333333333</apll> at <apll>53</apll>-bit precision and a Radius of <apll>5.6<_E/>¯17</apll>. The Midpoint is stored as a variable precision number, and the Radius is stored as a low-precision number.<br />
<br />
Alternatively,<br />
<br />
<apll><pre><br />
⎕FPC←128 ⋄ ⎕PP←40<br />
÷3<_pom/><br />
0.333333333333333333333333333333333333332<_pom/>1.5<_E/>¯39<br />
</pre></apll><br />
<br />
shows the corresponding value at a higher precision and correspondingly narrower Radius.<br />
<br />
A Ball describes a range of '''variable-precision floating point numbers''', and so the expression <apll>23<_pom/>1</apll> represents the set of Real numbers between <apll>22</apll> and <apll>24</apll>, inclusive, '''not''' the three integers <apll>22</apll>, <apll>23</apll>, <apll>24</apll>.<br />
<br />
<p class="note" style=" background-color:lightcyan;">In general, suffix notation on Ball Arithmetic constants should be sufficient for '''almost all purposes'''. That is, the Radius is already correctly calculated for constants such as <apll>23<_pom/></apll> whose Radius is zero, and <apll>1.2<_pom/></apll> whose Radius at <apll>53</apll> bits of precision is on the order of <apll>2*¯53</apll> (because of the inexactness of the Midpoint <apll>1.2</apll>) which displays as <apll>1.2<_pom/>2.2<_E/>¯16</apll>. Although the input notation supports it, the need to override the default Radius should be '''quite rare'''.</p><br />
<br />
==New Functions and Operator==<br />
<br />
===Functions To Convert To And From Ball Arithmetic Numbers===<br />
<br />
A Ball Arithmetic constant number may be created through notation (as seen above). Otherwise, a Ball Arithmetic number also may be created from its constituent parts under program control with a new primitive function '''Contract''', and separated into its constituent parts with a new primitive function '''Distract'''.<br />
<br />
====Contract====<br />
<br />
'''Contract''' is a monadic function (<apll>≤R</apll>) whose right argument is a Real array. It may be used to create a Ball Arithmetic number from the one- or two-elements of its Midpoint and (optional) Radius. The Axis Operator may specify any length <apll>1</apll> or <apll>2</apll> coordinate along which the conversion takes place. It converts the first element along the specified dimension to the Midpoint of the result and (if present) the second element to its Radius. If the second element is not present (i.e., length <apll>1</apll> coordinate), the Radius used is calculated from the precision of the Midpoint.<br />
<br />
<apll><pre><br />
≤23<br />
23<br />
≤1.2<br />
1.2<_pom/>1.1<_E/>¯16<br />
≤1.3 1<_E/>¯20<br />
1.3<_pom/>1<_E/>¯20<br />
≤1r2 1<_E/>¯20<br />
0.5<_pom/>1<_E/>¯20<br />
≤○1<br />
3.141592653589793<_pom/>1.1<_E/>¯16 <br />
≤(○1) 1<_E/>¯20<br />
3.141592653589793<_pom/>1<_E/>¯20 <br />
</pre></apll><br />
<br />
====Distract====<br />
<br />
'''Distract''' is a monadic function (<apll>≥R</apll>) whose right argument is a Real array. It may be used to separate out a Ball Arithmetic's Midpoint and Radius into two distinct values. The Axis Operator may specify the place where the new length <apll>2</apll> coordinate is to be inserted. The pair of values along this new coordinate are the Midpoint and Radius of the corresponding number from the right argument. If the number can be represented exactly, the Radius is zero.<br />
<br />
<apll><pre><br />
⎕PP←10<br />
≥1.2<br />
1.2 1.1102230246251565<_E/>¯16<br />
≥1.2<_x/><br />
6<_r/>5 0<br />
≥1.2<_v/><br />
1.2 1.110223024625157<_E/>¯16<br />
≥1.2<_pom/><br />
1.2 2.220446049250313<_E/>¯16<br />
≥1.5<br />
1.5 0<br />
≥1.5<_x/><br />
3<_r/>2 0<br />
≥1.5<_v/><br />
1.5 1.110223024625157<_E/>¯16<br />
≥1.5<_pom/><br />
1.5 0<br />
a←(○1<_pom/>)×⍳4<br />
a,'|',≥a<br />
3.141592654<_pom/>4.4<_E/>¯16 | 3.141592654 4.440892148<_E/>¯16<br />
6.283185307<_pom/>8.9<_E/>¯16 | 6.283185307 8.881784296<_E/>¯16<br />
9.424777961<_pom/>1.3<_E/>¯15 | 9.424777961 1.332267643<_E/>¯15<br />
12.56637061<_pom/>1.8<_E/>¯15 | 12.56637061 1.776356859<_E/>¯15<br />
</pre></apll><br />
<br />
These numbers can be represented exactly:<br />
<br />
<apll><pre><br />
≥⍳4<_pom/><br />
1 0<br />
2 0<br />
3 0<br />
4 0<br />
≥[2]⍳4<_pom/><br />
1 0<br />
2 0<br />
3 0<br />
4 0<br />
≥[1]⍳4<_pom/><br />
1 2 3 4<br />
0 0 0 0<br />
</pre></apll><br />
<br />
====Identities====<br />
<br />
The Contract of the Distract of a number both along the same axis, returns the same number.<br />The Distract of the Contract of a number both along the same length two axis, returns the same number.<br />
<br />
===Operator To Provide Arbitrary Precision Specific Derived Functions===<br />
<br />
The DoubleTilde monadic operator (<apll>≈</apll>, Alt-'Q' or Alt-shift-'q') takes a primitive function as its left operand and produces an arbitrary-precision-specific derived function.<br />
<br />
This operator should be considered preliminary.<br />
<br />
====Conversion Between Balls and Intervals====<br />
<br />
At the moment, the monadic derived function is defined for two primitive functions.<br />
<br />
Because Ball Arithmetic has a close relationship with Interval Arithmetic, it may be desirable to convert between the two forms: Endpoint to Midpoint-Radius and its inverse. The resulting derived function is not scalar.<br />
<br />
For example,<br />
<br />
<apll><pre><br />
x←0<_pom/>∞ 1<_pom/>2<br />
≥≈x<br />
¯∞ ∞<br />
¯1 3<br />
≥[1]≈x<br />
¯∞ ¯1<br />
∞ 3<br />
≥[2]≈x<br />
¯∞ ∞<br />
¯1 3<br />
≤≈≥≈x<br />
0<_pom/>∞ 1<_pom/>2<br />
≤≈≥[2]≈x<br />
0<_pom/>∞ 1<_pom/>2<br />
≤[2]≈≥≈x<br />
0<_pom/>∞ 1<_pom/>2<br />
≤[2]≈≥[2]≈x<br />
0<_pom/>∞ 1<_pom/>2 <br />
≤[1]≈≥[1]≈x<br />
0<_pom/>∞ 1<_pom/>2 <br />
</pre></apll><br />
<br />
The domain of these functions is limited to Real numbers. Hypercomplex numbers signal a <apll>DOMAIN ERROR</apll>. To see the Endpoints of a Hypercomplex number, first '''Dilate''' it so as to separate out the coefficients and then apply <apll>≥≈</apll> to extract the Endpoints as in <apll>≥≈&gt;R</apll>.<br />
<br />
For example,<br />
<br />
<apll><pre> ≥≈ 2±0i0±1<br />
DOMAIN ERROR<br />
≥≈ 2±0i0±1<br />
∧<br />
≥≈>2±0i0±1<br />
2 2<br />
¯1 1<br />
<≤≈≥≈>2±0i0±1<br />
2±0i0±1<br />
</pre></apll><br />
<br />
====Union and Intersection of Balls====<br />
<br />
The left operand of the DoubleTilde operator is defined for the '''Union''' and '''Intersection''' functions (<apll>∪∩</apll>) as follows: <br />
<br />
Because Ball arithmetic numbers represent a range of floating point numbers, at times it is desirable to produce their Union or Intersection.<br />
<br />
For example,<br />
<br />
<apll><pre><br />
x←0.5<pom/>0.5 ⍝ The interval [0,1]<br />
x∪≈x+2 ⍝ The interval [0,1] ∪ [2,3] ←→ [0,3]<br />
1.5<pom/>1.5<br />
x∪≈x+1 ⍝ The interval [0,1] ∪ [1,2] ←→ [0,2]<br />
1<pom/>1 <br />
x∩≈x+1 ⍝ The interval [0,1] ∩ [1,2] ←→ [1,1]<br />
1<br />
</pre></apll><br />
<br />
If two Balls have no points in common, the result is a NaN (<apll>∅</apll>):<br />
<br />
<apll><pre><br />
x∩≈x+1.1 ⍝ The interval [0,1] ∩ [1.1,2.1] ←→ ∅<br />
∅<br />
</pre></apll><br />
<br />
The identity element for <apll>∩≈</apll> is <apll>0±∞</apll>.<br />
<br />
The derived functions are scalar.<br />
<br />
====Comparison Functions====<br />
<br />
The left operand of the DoubleTilde operator is defined for the six comparison functions (<apll>&lt;≤=≥&gt;≠</apll>) as follows:<br />
<br />
For <apll><i>f</i></apll> as one of the above six functions, <apll>L<i>f</i>≈R</apll> is TRUE iff for all <apll>t∊L</apll> and <apll>u∊R</apll>, then <apll>&nbsp;&nbsp;t f u&nbsp;&nbsp;</apll> is TRUE. These comparisons are all done with <apll>⎕CT←0</apll> because, in a sense, Ball comparisons carry their own Fuzz.<br />
<br />
For example,<br />
<br />
<apll><pre> (L R)←4<_pom/>1 6<_pom/>1<br />
L<≈R<br />
0<br />
L≤≈R<br />
1<br />
</pre></apll><br />
<br />
The derived functions are scalar.<br />
<br />
====Containing Functions====<br />
<br />
The left operand of the DoubleTilde operator is defined for two containing functions (<apll>⊂⊃</apll>) as follows:<br />
<br />
The expression <apll>L⊂≈R</apll> is TRUE iff for all <apll>t∊L</apll> it is TRUE that <apll>t∊R</apll> and that the containment is strict &mdash; that is, none of the endpoints match.<br />
<br />
The expression <apll>L⊃≈R</apll> is TRUE iff <apll>R⊂≈L</apll> is TRUE.<br />
<br />
For example,<br />
<br />
<apll><pre><br />
(L R)←6±4 6±2<br />
L⊃≈R<br />
1<br />
R⊂≈L<br />
1<br />
</pre></apll><br />
<br />
The derived functions are scalar.<br />
<br />
====Positional Relationships====<br />
<br />
For <apll>L</apll> and <apll>R</apll> as finite intervals with non-zero Radii (i.e., multi-valued), here are the possible '''Relative Positions''' between the two Intervals, where <apll>L0</apll>, <apll>L1</apll> and <apll>R0</apll>, <apll>R1</apll> are the endpoints of <apll>L</apll> and <apll>R</apll>, respectively &mdash; <apll>(L0 L1)←≥≈L</apll> and <apll>(R0 R1)←≥≈R</apll>:<br />
<br />
<table border="1" cellspacing="0" rowspacing="5" style="font-family:APL385, SImPL;"><br />
<th>Relative<br/>Positions</th><br />
<th>Endpoint<br/>Relationships</th><br />
<th colspan="2">Defining<br/>Expressions</th><br />
<th>Sample Data<br/>L &nbsp; R</th><br />
<th>Distinct<br/>Ball<br/>{⍺∘≈⍵}</th><br />
<br />
<tr><br />
<td>&nbsp;├──L──┤<br/>&nbsp;├──R──┤&nbsp;</td><br />
<td>&nbsp;L0 L1≡R0 R1&nbsp;</td><br />
<td>&nbsp;L=≈R&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 6<_pom/>4&nbsp;</td><br />
<td>&nbsp;&nbsp;0&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──L──┤<br/>&nbsp;├──R─┤&nbsp;</td><br />
<td>&nbsp;(L0=R0)∧L1&gt;R1&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 5<_pom/>3&nbsp;</td><br />
<td>&nbsp;&nbsp;1&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──L─┤<br/>&nbsp;├──R──┤&nbsp;</td><br />
<td>&nbsp;(L0=R0)∧L1&lt;R1&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 7<_pom/>5&nbsp;</td><br />
<td>&nbsp;¯1&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──L──┤<br/>&nbsp;&nbsp;├──R─┤&nbsp;</td><br />
<td>&nbsp;(L0&lt;R0)∧L1=R1&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 7<_pom/>3&nbsp;</td><br />
<td>&nbsp;&nbsp;2&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;&nbsp;├──L─┤<br/>&nbsp;├──R──┤&nbsp;</td><br />
<td>&nbsp;(L0&gt;R0)∧L1=R1&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 5<_pom/>5&nbsp;</td><br />
<td>&nbsp;¯2&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──L──┤<br/>&nbsp;&nbsp;├─R─┤&nbsp;</td><br />
<td>&nbsp;(L0&lt;R0)∧L1&gt;R1&nbsp;</td><br />
<td>&nbsp;L⊃≈R&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 6<_pom/>2&nbsp;</td><br />
<td>&nbsp;&nbsp;3&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;&nbsp;├─L─┤<br/>&nbsp;├──R──┤&nbsp;</td><br />
<td>&nbsp;(L0&gt;R0)∧L1&lt;R1&nbsp;</td><br />
<td>&nbsp;L⊂≈R&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 6<_pom/>6&nbsp;</td><br />
<td>&nbsp;¯3&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──L──┤<br/>&nbsp;&nbsp;├──R──┤&nbsp;</td><br />
<td>&nbsp;(L0&lt;R0)∧(L1&lt;R1)∧L1&gt;R0&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 8<_pom/>4&nbsp;</td><br />
<td>&nbsp;&nbsp;4&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;&nbsp;├──L──┤<br/>&nbsp;├──R──┤&nbsp;</td><br />
<td>&nbsp;(L0&gt;R0)∧(L1&gt;R1)∧L0&lt;R1&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 4<_pom/>4&nbsp;</td><br />
<td>&nbsp;¯4&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──L──┼──R──┤&nbsp;</td><br />
<td>&nbsp;L1=R0&nbsp;</td><br />
<td>&nbsp;(L≤≈R)&gt;L&lt;≈R&nbsp;</td><br />
<td>&nbsp;L=∀R&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 14<_pom/>4&nbsp;</td><br />
<td>&nbsp;&nbsp;5&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──R──┼──L──┤&nbsp;</td><br />
<td>&nbsp;L0=R1&nbsp;</td><br />
<td>&nbsp;(L≥≈R)&gt;L&gt;≈R&nbsp;</td><br />
<td>&nbsp;L=∃R&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 0<_pom/>2&nbsp;</td><br />
<td>&nbsp;¯5&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──L──┤&nbsp;├──R──┤&nbsp;</td><br />
<td>&nbsp;L1&lt;R0&nbsp;</td><br />
<td>&nbsp;L&lt;≈R&nbsp;</td><br />
<td>&nbsp;L&lt;∀R&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 17<_pom/>5&nbsp;</td><br />
<td>&nbsp;&nbsp;6&nbsp;</td><br />
</tr><br />
<br />
<tr><br />
<td>&nbsp;├──R──┤&nbsp;├──L──┤&nbsp;</td><br />
<td>&nbsp;L0&gt;R1&nbsp;</td><br />
<td>&nbsp;L&gt;≈R&nbsp;</td><br />
<td>&nbsp;L&gt;∃R&nbsp;</td><br />
<td>&nbsp;6<_pom/>4 0<_pom/>1&nbsp;</td><br />
<td>&nbsp;¯6&nbsp;</td><br />
</tr><br />
</table><br />
<br />
The above table can be interpreted as follows:<br />
<br />
<ul><br />
<li>The first column lists all possible '''Relative Positions''' two finite non-zero Radii (i.e., multi-valued) Balls may assume.</li><br />
<li>The second column lists the '''Endpoint Relationship''' that defines the corresponding '''Relative Position'''.</li><br />
<li>The third column lists a '''Defining Expression''' using the '''DoubleTilde''' operator that is TRUE for the corresponding '''Relative Position''' and FALSE for all of the other '''Relative Positions''' in different rows.</li><br />
<li>The fourth column lists a '''Defining Expression''' using the '''Always''' and '''Possibly''' operators [http://forum.nars2000.org/ball-arithmetic-t614.html#p1803 proposed] by David Rabenhorst.</li><br />
<li>The fifth column contains '''Sample Data''' that defines the corresponding '''Relative Position'''.</li><br />
<li>The sixth column gives the value of the '''Distinct Ball''' function <apll>{⍺∘≈⍵}</apll> when executed on the '''Sample Data'''.</li><br />
</ul><br />
<br />
Note the table is organized such that apart from the first row (whose '''Endpoint Relationship''' is Symmetric in <apll>L</apll> and <apll>R</apll>) the rows occur in six pairs where the '''Endpoint Relationship''' for each row in the pair can be obtained from the other by swapping <apll>L</apll> and <apll>R</apll>. The pairs of rows are ordered roughly by the amount of overlap between the two Balls.<br />
<br />
As you can see, we are missing '''Defining Expressions''' for several of the '''Relative Positions'''. I was hoping that this table would be filled in with more detail so it would serve as a measure of whether or not we had a complete set of functions/operators which could be used to tell apart all of the '''Relative Positions''' without having to resort to the '''Distinct Ball''' function <apll>{⍺∘≈⍵}</apll> constructed explicitly for this purpose. Please add to this table if you find a missing expression, or wish to propose whole new functions and/or operators.<br />
<br />
If you would like to try a '''Defining Expression''' on the '''Sample Data''', collect the data into a <apll>13</apll> by <apll>2</apll> matrix, put your '''Defining Expression''' into (say) an Anonymous Function and reduce the same data matrix along the last coordinate &mdash; if you have a successful function, you should see a <apll>13</apll>-element Boolean vector with a single one in it. For example,<br />
<br />
<apll><pre><br />
sd←6<_pom/>4,⍪6<_pom/>4 5<_pom/>3 7<_pom/>5 7<_pom/>3 5<_pom/>5 6<_pom/>2 6<_pom/>6 8<_pom/>4 4<_pom/>4 14<_pom/>4 0<_pom/>2 17<_pom/>5 0<_pom/>1<br />
{(⍺≤≈⍵)>⍺<≈⍵}/sd<br />
0 0 0 0 0 0 0 0 0 1 0 0 0 <br />
{(⍺≥≈⍵)>⍺>≈⍵}/sd<br />
0 0 0 0 0 0 0 0 0 0 1 0 0 <br />
{⍺<≈⍵}/sd<br />
0 0 0 0 0 0 0 0 0 0 0 1 0 <br />
{⍺>≈⍵}/sd<br />
0 0 0 0 0 0 0 0 0 0 0 0 1<br />
</pre></apll><br />
<br />
Finally, the following example shows that the '''Sample Data''' are all distinct:<br />
<br />
<apll><pre><br />
{⍺∘≈⍵}/sd<br />
0 1 ¯1 2 ¯2 3 ¯3 4 ¯4 5 ¯5 6 ¯6<br />
</pre></apll><br />
<br />
==Hypercomplex Ball Arithmetic==<br />
<br />
Ball Arithmetic also extends to all Hypercomplex numbers (Complex, Quaternion, and Octonion) such as <apll>1.2<_pom/><_i/>2.2</apll> which represents a Complex Ball Arithmetic number whose '''Real''' part is <apll>1.2<_pom/></apll> and whose '''Imaginary''' part is <apll>2.2<_pom/></apll>. Note that the display of that number (at <apll>53</apll> bits of precision)<br />
<br />
<apll><pre><br />
1.2<_pom/><_i/>2.2<br />
1.2<_pom/>2.2<_E/>¯16<_i/>2.2<_pom/>4.4<_E/>¯16<br />
</pre></apll><br />
<br />
demonstrates the inexactness of both floating point coefficients.<br />
<br />
==Small v. Large Radii==<br />
<br />
Ball Arithmetic works best when given small Radii, that is, small relative to the Midpoint. Calculations on large Radii numbers such as <apll>0<_i/>0.5<_pom/>0.5</apll> don't always produce useful results. For example,<br />
<br />
<apll><pre><br />
⎕PP←8 ⍝ To reduce fractional clutter<br />
x←0<_i/>0.5<_pom/>0.5<br />
√x<br />
0.4267767<_pom/>0.57<_i/>0<_pom/>1.4<br />
</pre></apll><br />
<br />
Unfortunately in this case, because the Radius is so large it overwhelms the Midpoint, as can be seen when we Square the Square Root:<br />
<br />
<apll><pre><br />
(√x)*2<br />
0.18213835<_pom/>2.8<_i/>0<_pom/>2.8<br />
x=(√x)*2<br />
0<br />
</pre></apll><br />
<br />
These calculations work better using smaller Radii, such as<br />
<br />
<apll><pre><br />
y←0<_i/>0.5<_pom/>0.5<_E/>¯30<br />
√y<br />
0.5<_pom/>2.5<_E/>¯31<_i/>0.5<_pom/>7.5<_E/>¯31<br />
(√y)*2<br />
0<_pom/>1<_E/>¯30<_i/>0.5<_pom/>1<_E/>¯30 <br />
y=(√y)*2<br />
1<br />
</pre></apll><br />
<br />
where Square Root now returns a meaningful result, and its Square returns the original value.<br />
<br />
==Mixed Notation==<br />
<br />
The notation for Ball Arithmetic may be combined with other Point Notations in many ways, such as<br />
<br />
<apll><pre><br />
1<_p/>1<_pom/><br />
3.141592653589793<_pom/>4.4<_E/>¯16 <br />
1<_x/>1<_pom/><br />
2.718281828459045<_pom/>4.5<_E/>¯16<br />
</pre></apll><br />
<br />
For more details about combining different forms of Point Notation, see [[Point_Notation|Point Notation]] and in particular the section on [[Point_Notation#Mixed_Notation|Mixed Notation]].<br />
<br />
==Implementation==<br />
<br />
===Datataypes===<br />
<br />
This feature adds four new datatypes to the language: one each for the four Division Algebras. Note that marking any one of the Hypercomplex coefficients as a Ball automatically marks them all as Balls.<br />
{|<br />
|-<br />
|Real||&nbsp;&nbsp;&nbsp;&nbsp;<apll>23<_pom/></apll> or <apll>1.2<_pom/></apll><br />
|-<br />
|Complex||&nbsp;&nbsp;&nbsp;&nbsp;<apll>23<_i/>1.2<_pom/></apll><br />
|-<br />
|Quaternion||&nbsp;&nbsp;&nbsp;&nbsp;<apll>23<_i/>1.2<_j/>0.5<_k/>¯3.14<_pom/></apll><br />
|-<br />
|Octonion||&nbsp;&nbsp;&nbsp;&nbsp;<apll>23<_i/>1.2<_j/>0.5<_k/>¯3.14<l/>¯3<_ij/>19<_jk/>¯3<_kl/>6<_pom/></apll><br />
|}<br />
<br />
===Primitive Functions===<br />
<br />
As described above, this feature adds two new monadic primitive functions '''Contract''' (<apll>≤R</apll>) and its inverse '''Distract''' (<apll>≥R</apll>), along with one new monadic primitive operator '''DoubleTilde''' <apll>f≈ R</apll> and <apll>L f≈ R</apll>.<br />
<br />
All primitive and system functions and operators are extended to work with Ball Arithmetic, so you can test out this feature on all algorithms, with the exception of trying to find the Factorial of a multiple-precision/Ball Arithmetic Hypercomplex number, in which case you are temporarily out of luck.<br />
<br />
==Workspace Version Number==<br />
<br />
For the moment, if you save a workspace which contains a Ball Arithmetic number in a variable, the workspace version number is <apll>0.03</apll>. Otherwise, the version number is <apll>0.02</apll>. Workspaces with Ball Arithmetic Numbers may not be loaded by an earlier version of the interpreter.<br />
<br />
==Pending Design Decisions==<br />
<br />
<ul><br />
<li>The direct comparison functions (<apll>&lt;≤=≥&gt;≠≡≢</apll>) and indirect ones (<apll>⍳⍸∊⍷⍒⍋</apll>) are currently implemented to compare the Midpoints of the arguments ignoring the Radius &mdash; this may change.</li><br />
<li>The Floor function and its related functions (Ceiling, Residue, GCD, LCM, and Encode) are currently implemented to execute on the Midpoints of the arguments ignoring the Radius &mdash; this may change.</li><br />
<li>We need new primitives to describe the different ways in which Balls can intersect/overlap, possibly through a new monadic operator (perhaps &#x2248;) on the existing direct and indirect comparison and Floor-related functions.</li><br />
<li>Certain primitives are defined on limited ranges, and sometimes multiple ranges where it might use different algorithms for different ranges (e.g. <apll>L!R</apll>). There are open questions about how to handle a Ball that spans two or more of these ranges as to how to calculate the result.</li><br />
<li>Infinity and NaN have not been given any special treatment as yet. The results are whatever ARB has chosen which we may need to override.</li><br />
</ul><br />
<br />
==Download==<br />
<br />
This feature is available as an Alpha release &mdash; it may be downloaded from the [http://www.nars2000.org/download/binaries/alpha/ Alpha] release directory.<br />
<br />
==Acknowledgements==<br />
<br />
<ul><br />
<li>The Arb team has contributed their Ball Arithmetic<ref name="BallArithmetic" /> code which made this feature possible.</li><br />
<li>David Rabenhorst has contributed many very useful ideas and many hours debugging the implementation.</li><br />
</ul><br />
<br />
==References==<br />
<br />
<references /></div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=Ball_Arithmetic&diff=3356Ball Arithmetic2018-10-10T20:57:13Z<p>Sudleyplace: /* Conversion Between Balls and Intervals */</p>
<hr />
<div>==Introduction==<br />
<br />
Ball<ref name="BallArithmetic">NARS2000 Wiki, [http://arblib.org Ball Arithmetic]</ref> and Interval Arithmetic<ref name="IntervalArithmetic">Wikipedia, [https://en.wikipedia.org/wiki/Interval_arithmetic Interval Arithmetic]</ref> both refer to the same idea of calculating with arbitrary precision inexact numbers &mdash; that is, with a range of floating point values instead of a single representative. This allows such numbers to reflect their inexactness explicitly.<br />
<br />
"The most common use is to keep track of and handle rounding errors directly during the calculation and of uncertainties in the knowledge of the exact values of physical and technical parameters. The latter often arise from measurement errors and tolerances for components or '''due to limits on computational accuracy'''. Interval arithmetic also helps find reliable and guaranteed solutions to equations and optimization problems."<ref name="IntervalArithmetic" /><br />
<br />
The difference between the two is in how each approach represents its values: Interval Arithmetic uses the two ends of the interval <apll>[a, b]</apll> whereas Ball Arithmetic uses a Ball with a Midpoint and Radius. Each has its advantages. Interval Arithmetic is implemented by several libraries such as MPFI<ref name="MPFI">[http://perso.ens-lyon.fr/nathalie.revol/software.html MPFI]</ref> and Ball Arithmetic is implemented by ARB<ref name="BallArithmetic" />.<br />
<br />
This feature uses the ARB<ref name="BallArithmetic" /> library to implement Ball Arithmetic.<br />
<br />
==Environment==<br />
<br />
In the examples below, unless otherwise specified, the precision of multi-precision floating-point numbers is set to <apll>53</apll> bits via <apll>⎕FPC←53</apll> which is the same precision as standard double-precision numbers. The Printing Precision is set to <apll>17</apll> digits via <apll>⎕PP←17</apll> so as to display the maximum number of significant digits at <apll>53</apll> bits of precision. The Comparison Tolerance is set via <apll>⎕CT←1<_E/>¯10</apll>.<br />
<br />
==Calculating With Ball Arithmetic==<br />
<br />
If you have ever entered an expression such as<br />
<br />
<apll><pre><br />
÷3<br />
0.3333333333333333<br />
</pre></apll><br />
<br />
undoubtedly, you are aware that the result is inexact. Moreover, as you incorporate into your code the many other functions that produce inexact numbers, you should be wondering "How does the accumulation of inexactness affect my results?".<br />
<br />
The answer to that question lies in the province of [https://en.wikipedia.org/wiki/Numerical_analysis Numerical Analysis] where it is described as "the study of algorithms that use numerical approximation". In general, applying the techniques of Numerical Analysis often involves time-consuming analysis. Fortunately, Ball Arithmetic is an easy to use alternative to that. That is, instead of analyzing the algorithm, run the algorithm with all calculations done with Ball Arithmetic.<br />
<br />
Here is the same expression in Ball Arithmetic (use Alt-‘q’ or Ctrl-‘q’, depending on your keyboard layout, to enter the <apll><_pom/></apll> symbol):<br />
<br />
<apll><pre><br />
÷3<_pom/><br />
0.3333333333333333<_pom/>5.6<_E/>¯17<br />
</pre></apll><br />
<br />
Essentially, each Ball Arithmetic number carries with it an explicit Radius that describes the interval which contains the true value. Because Ball Arithmetic data propagates throughout a calculation and is never demoted to a lower datatype, its advantage is that after each operation the resulting Ball reliably includes the true answer. Across an entire algorithm, the final result is a Ball that indicates explicitly how precise it is, thus eliminating the guesswork as to the effect on the algorithm of the inexactness of the input and any other inexact constants used.<br />
<br />
For example,<br />
<br />
<apll><pre><br />
sqrt←{⍺←= ⋄ {0.5×⍵+⍺÷⍵}⍣⍺⍨⍵} ⍝ Calculate square root using Newton's method<br />
√2<_pom/><br />
1.414213562373095<_pom/>2.2<_E/>¯16<br />
sqrt 2<_pom/><br />
1.414213562373095<_pom/>1.1<_E/>¯15 <br />
10 sqrt 2<_pom/><br />
1.414213562373095<_pom/>2.8<_E/>¯15 <br />
100 sqrt 2<_pom/><br />
1.414213562373095<_pom/>3.3<_E/>¯14 <br />
1000 sqrt 2<_pom/><br />
1.414213562373095<_pom/>3.3<_E/>¯13 <br />
10000 sqrt 2<_pom/><br />
1.414213562373095<_pom/>3.5<_E/>¯12<br />
</pre></apll><br />
<br />
As you can see, after a few iterations, the accuracy of the result doesn't improve. However, because it is an iterative algorithm, the precision worsens as the number of iterations increases. Only by using Ball Arithmetic can you see just how the precision of the result is affected.<br />
<br />
To demonstrate with an extreme example, consider the following function:<br />
<br />
<apll><pre><br />
f←{⍪⍵-3√(⍵*3)-⍵*2}<br />
f 10*3×⍳5<br />
0.33344450621439137<br />
0.3333334452472627 <br />
0.33333444595336914<br />
0.3348388671875 <br />
2.25<br />
</pre></apll><br />
<br />
Without knowing much about this ([https://en.wikipedia.org/wiki/Condition_number ill-conditioned]) algorithm, you have no reason to suspect these results. As it turns out, there's a mathematical proof that as the argument increases to infinity, the algorithm converges to <apll>÷3</apll>. Only when you calculate with Ball Arithmetic do you see that there is a problem:<br />
<br />
<apll><pre><br />
f 10*3×⍳5<_pom/><br />
0.3334445062153009<_pom/>2.2<_E/>¯12 <br />
0.3333334461785853<_pom/>4.3<_E/>¯9 <br />
0.333337664604187<_pom/>0.0000062<br />
0.3385009765625<_pom/>0.0085<br />
1.25<_pom/>5<br />
</pre></apll><br />
<br />
As you can see, the precision worsens quickly to the point where the result is meaningless. The last line even says that the answer lies somewhere between <apll>¯3.75</apll> and <apll>6.25</apll>. In other words, that answer is so '''imprecise''' as to be '''inaccurate'''! At higher powers of ten, the answers only worsen.<br />
<br />
The good news with Ball Arithmetic is that if you need greater precision, just increase the value of <apll>⎕FPC</apll>. For example,<br />
<br />
<apll><pre><br />
⎕FPC←128 ⋄ ⎕PP←40<br />
sqrt 2<_pom/><br />
1.41421356237309504880168872420969807857<_pom/>5.9<_E/>¯39<br />
</pre></apll><br />
<br />
In the case of an ill-conditioned algorithm, we just push the problem off a bit, but not very far &mdash; the problem is that the algorithm requires infinite precision:<br />
<br />
<apll><pre><br />
f 10*3×⍳10<_pom/><br />
0.333444506214021971364848444464298690637<_pom/>3.4<_E/>¯35<br />
0.333333444444506172880658466392407138179<_pom/>1.1<_E/>¯31<br />
0.333333333444444444506172839632668381652<_pom/>1.6<_E/>¯28<br />
0.333333333333444444444444547458328123363<_pom/>2.2<_E/>¯25<br />
0.333333333333333444444619474517508476812<_pom/>3.2<_E/>¯22<br />
0.333333333333333333552432522356445687706<_pom/>1.3<_E/>¯19<br />
0.333333333333333491771410805881714622956<_pom/>4.5<_E/>¯16<br />
0.333333333333417414223731611855328083038<_pom/>4.5<_E/>¯13<br />
0.33333333363771089352667331695556640625<_pom/>4.5<_E/>¯10 <br />
0.3333334587514400482177734375<_pom/>2.6<_E/>¯7<br />
</pre></apll><br />
<br />
While your floating point code might not be so ill-conditioned, the only way to be sure of its results is one of<br />
<br />
<ul><br />
<li>Hire a Numerical Analyst</li><br />
<li>Become a Numerical Analyst</li><br />
<li>Use Ball Arithmetic</li><br />
</ul><br />
<br />
==Ball Arithmetic Numbers==<br />
<br />
A Ball Arithmetic number consist of two parts: a Midpoint and Radius. The Midpoint value represents the middle of the Ball and the Radius represents the distance around the Ball of possible values. There is no way to tell which value in the Ball is the correct answer &mdash; you should assume that all values are potential candidates. <br />
<br />
The precision at which the Midpoint and Radius are stored depends upon the current value of <apll>⎕FPC</apll>. For example, the following display<br />
<br />
<apll><pre><br />
⎕FPC←53<br />
÷3<_pom/><br />
0.3333333333333333<_pom/>5.6<_E/>¯17<br />
</pre></apll><br />
<br />
indicates that the number <apll>÷3<_pom/></apll> has a Midpoint of <apll>0.3333333333333333</apll> at <apll>53</apll>-bit precision and a Radius of <apll>5.6<_E/>¯17</apll>. The Midpoint is stored as a variable precision number, and the Radius is stored as a low-precision number.<br />
<br />
Alternatively,<br />
<br />
<apll><pre><br />
⎕FPC←128 ⋄ ⎕PP←40<br />
÷3<_pom/><br />
0.333333333333333333333333333333333333332<_pom/>1.5<_E/>¯39<br />
</pre></apll><br />
<br />
shows the corresponding value at a higher precision and correspondingly narrower Radius.<br />
<br />
A Ball describes a range of '''variable-precision floating point numbers''', and so the expression <apll>23<_pom/>1</apll> represents the set of Real numbers between <apll>22</apll> and <apll>24</apll>, inclusive, '''not''' the three integers <apll>22</apll>, <apll>23</apll>, <apll>24</apll>.<br />
<br />
<p class="note" style=" background-color:lightcyan;">In general, suffix notation on Ball Arithmetic constants should be sufficient for '''almost all purposes'''. That is, the Radius is already correctly calculated for constants such as <apll>23<_pom/></apll> whose Radius is zero, and <apll>1.2<_pom/></apll> whose Radius at <apll>53</apll> bits of precision is on the order of <apll>2*¯53</apll> (because of the inexactness of the Midpoint <apll>1.2</apll>) which displays as <apll>1.2<_pom/>2.2<_E/>¯16</apll>. Although the input notation supports it, the need to override the default Radius should be '''quite rare'''.</p><br />
<br />
==New Functions and Operator==<br />
<br />
===Functions To Convert To And From Ball Arithmetic Numbers===<br />
<br />
A Ball Arithmetic constant number may be created through notation (as seen above). Otherwise, a Ball Arithmetic number also may be created from its constituent parts under program control with a new primitive function '''Contract''', and separated into its constituent parts with a new primitive function '''Distract'''.<br />
<br />
====Contract====<br />
<br />
'''Contract''' is a monadic function (<apll>≤R</apll>) whose right argument is a Real array. It may be used to create a Ball Arithmetic number from the one- or two-elements of its Midpoint and (optional) Radius. The Axis Operator may specify any length <apll>1</apll> or <apll>2</apll> coordinate along which the conversion takes place. It converts the first element along the specified dimension to the Midpoint of the result and (if present) the second element to its Radius. If the second element is not present (i.e., length <apll>1</apll> coordinate), the Radius used is calculated from the precision of the Midpoint.<br />
<br />
<apll><pre><br />
≤23<br />
23<br />
≤1.2<br />
1.2<_pom/>1.1<_E/>¯16<br />
≤1.3 1<_E/>¯20<br />
1.3<_pom/>1<_E/>¯20<br />
≤1r2 1<_E/>¯20<br />
0.5<_pom/>1<_E/>¯20<br />
≤○1<br />
3.141592653589793<_pom/>1.1<_E/>¯16 <br />
≤(○1) 1<_E/>¯20<br />
3.141592653589793<_pom/>1<_E/>¯20 <br />
</pre></apll><br />
<br />
====Distract====<br />
<br />
'''Distract''' is a monadic function (<apll>≥R</apll>) whose right argument is a Real array. It may be used to separate out a Ball Arithmetic's Midpoint and Radius into two distinct values. The Axis Operator may specify the place where the new length <apll>2</apll> coordinate is to be inserted. The pair of values along this new coordinate are the Midpoint and Radius of the corresponding number from the right argument. If the number can be represented exactly, the Radius is zero.<br />
<br />
<apll><pre><br />
⎕PP←10<br />
≥1.2<br />
1.2 1.1102230246251565<_E/>¯16<br />
≥1.2<_x/><br />
6<_r/>5 0<br />
≥1.2<_v/><br />
1.2 1.110223024625157<_E/>¯16<br />
≥1.2<_pom/><br />
1.2 2.220446049250313<_E/>¯16<br />
≥1.5<br />
1.5 0<br />
≥1.5<_x/><br />
3<_r/>2 0<br />
≥1.5<_v/><br />
1.5 1.110223024625157<_E/>¯16<br />
≥1.5<_pom/><br />
1.5 0<br />
a←(○1<_pom/>)×⍳4<br />
a,'|',≥a<br />
3.141592654<_pom/>4.4<_E/>¯16 | 3.141592654 4.440892148<_E/>¯16<br />
6.283185307<_pom/>8.9<_E/>¯16 | 6.283185307 8.881784296<_E/>¯16<br />
9.424777961<_pom/>1.3<_E/>¯15 | 9.424777961 1.332267643<_E/>¯15<br />
12.56637061<_pom/>1.8<_E/>¯15 | 12.56637061 1.776356859<_E/>¯15<br />
</pre></apll><br />
<br />
These numbers can be represented exactly:<br />
<br />
<apll><pre><br />
≥⍳4<_pom/><br />
1 0<br />
2 0<br />
3 0<br />
4 0<br />
≥[2]⍳4<_pom/><br />
1 0<br />
2 0<br />
3 0<br />
4 0<br />
≥[1]⍳4<_pom/><br />
1 2 3 4<br />
0 0 0 0<br />
</pre></apll><br />
<br />
====Identities====<br />
<br />
The Contract of the Distract of a number both along the same axis, returns the same number.<br />The Distract of the Contract of a number both along the same length two axis, returns the same number.<br />
<br />
===Operator To Provide Arbitrary Precision Specific Derived Functions===<br />
<br />
The DoubleTilde monadic operator (<apll>≈</apll>, Alt-'Q' or Alt-shift-'q') takes a primitive function as its left operand and produces an arbitrary-precision-specific derived function.<br />
<br />
This operator should be considered preliminary.<br />
<br />
====Conversion Between Balls and Intervals====<br />
<br />
At the moment, the monadic derived function is defined for two primitive functions.<br />
<br />
Because Ball Arithmetic has a close relationship with Interval Arithmetic, it may be desirable to convert between the two forms: Endpoint to Midpoint-Radius and its inverse. The resulting derived function is not scalar.<br />
<br />
For example,<br />
<br />
<apll><pre><br />
x←0<_pom/>∞ 1<_pom/>2<br />
≥≈x<br />
¯∞ ∞<br />
¯1 3<br />
≥[1]≈x<br />
¯∞ ¯1<br />
∞ 3<br />
≥[2]≈x<br />
¯∞ ∞<br />
¯1 3<br />
≤≈≥≈x<br />
0<_pom/>∞ 1<_pom/>2<br />
≤≈≥[2]≈x<br />
0<_pom/>∞ 1<_pom/>2<br />
≤[2]≈≥≈x<br />
0<_pom/>∞ 1<_pom/>2<br />
≤[2]≈≥[2]≈x<br />
0<_pom/>∞ 1<_pom/>2 <br />
≤[1]≈≥[1]≈x<br />
0<_pom/>∞ 1<_pom/>2 <br />
</pre></apll><br />
<br />
====Union and Intersection of Balls====<br />
<br />
At the moment, the dyadic derived function is defined for two primitive functions.<br />
<br />
Because Ball arithmetic numbers represent a range of floating point numbers, at times it is desirable to produce their Union or Intersection. The resulting derived function is scalar.<br />
<br />
For example,<br />
<br />
<apll><pre><br />
x←0.5<pom/>0.5 ⍝ The interval [0,1]<br />
x∪≈x+2 ⍝ The interval [0,1] ∪ [2,3] ←→ [0,3]<br />
1.5<pom/>1.5<br />
x∪≈x+1 ⍝ The interval [0,1] ∪ [1,2] ←→ [0,2]<br />
1<pom/>1 <br />
x∩≈x+1 ⍝ The interval [0,1] ∩ [1,2] ←→ [1,1]<br />
1<br />
</pre></apll><br />
<br />
If two Balls have no points in common, the result is a NaN (<apll>∅</apll>):<br />
<br />
<apll><pre><br />
x∩≈x+1.1 ⍝ The interval [0,1] ∩ [1.1,2.1] ←→ ∅<br />
∅<br />
</pre></apll><br />
<br />
====Comparison Functions====<br />
<br />
This might be the place to define new derived functions such as <apll>&lt;≈</apll> which can return a non-Boolean result so as to cover the more complicated relationship of one Ball with another with respect to overlap, etc.<br />
<br />
==Hypercomplex Ball Arithmetic==<br />
<br />
Ball Arithmetic also extends to all Hypercomplex numbers (Complex, Quaternion, and Octonion) such as <apll>1.2<_pom/><_i/>2.2</apll> which represents a Complex Ball Arithmetic number whose '''Real''' part is <apll>1.2<_pom/></apll> and whose '''Imaginary''' part is <apll>2.2<_pom/></apll>. Note that the display of that number (at <apll>53</apll> bits of precision)<br />
<br />
<apll><pre><br />
1.2<_pom/><_i/>2.2<br />
1.2<_pom/>2.2<_E/>¯16<_i/>2.2<_pom/>4.4<_E/>¯16<br />
</pre></apll><br />
<br />
demonstrates the inexactness of both floating point coefficients.<br />
<br />
==Invalid Results==<br />
<br />
Not all Balls are valid arguments to all primitive functions. Sometimes, the result cannot be expressed in a Ball, such as<br />
<br />
<apll><pre><br />
√0<_pom/>1<br />
∅<br />
</pre></apll><br />
<br />
To see why, split apart the argument into two parts: <apll>¯0.5<_pom/>0.5</apll> and <apll>0.5<_pom/>0.5</apll> and apply the Square Root function to the separate parts. This yields a result that consists of two quite disjoint Balls: the square root of the Ball <apll>¯0.5<_pom/>0.5</apll> is <apll>0<_i/>0.5<_pom/>0.5</apll>, whereas the square root of the Ball <apll>0.5<_pom/>0.5</apll> is <apll>0.5<_pom/>0.5</apll> . As the two parts of the result are orthogonal to each other, they cannot be expressed as a single Midpoint-Radius Ball, and so the result is a NaN (= Not-A-Number = <apll>∅</apll>).<br />
<br />
==Small v. Large Radii==<br />
<br />
Ball Arithmetic works best when given small Radii, that is, small relative to the Midpoint. Calculations on large Radii numbers such as <apll>0<_i/>0.5<_pom/>0.5</apll> don't always produce useful results. For example,<br />
<br />
<apll><pre><br />
⎕←x←0<_i/>0.5<_pom/>0.5*2<br />
¯0.25<_pom/>0.75<br />
</pre></apll><br />
<br />
which follows from the standard way of multiplying Complex numbers<ref name="CayleyDickson">[https://en.wikipedia.org/wiki/Cayley%E2%80%93Dickson_construction]</ref>. Unfortunately in this case, because the Radius is so large that it includes negative numbers on the low end, the Square Root of this particular Squared interval is not representable, that is, it is a NaN:<br />
<br />
<apll><pre><br />
√x<br />
0<_i/>∅<br />
</pre></apll><br />
<br />
These calculations work better using smaller Radii, such as<br />
<br />
<apll><pre><br />
⎕←y←0<_i/>0.5<_pom/>0.5<_E/>¯10*2<br />
¯0.25<_pom/>5<_E/>¯11<br />
√y<br />
0<_i/>0.5<_pom/>5<_E/>¯11<br />
</pre></apll><br />
<br />
where Square Root now returns a meaningful result.<br />
<br />
==Mixed Notation==<br />
<br />
The notation for Ball Arithmetic may be combined with other Point Notations in many ways, such as<br />
<br />
<apll><pre><br />
1<_p/>1<_pom/><br />
3.141592653589793<_pom/>8.9<_E/>¯16 <br />
1<_x/>1<_pom/><br />
2.718281828459045<_pom/>4.5<_E/>¯16<br />
</pre></apll><br />
<br />
For more details about combining different forms of Point Notation, see [[Point_Notation|Point Notation]] and in particular the section on [[Point_Notation#Mixed_Notation|Mixed Notation]].<br />
<br />
==Implementation==<br />
<br />
===Datataypes===<br />
<br />
This feature adds four new datatypes to the language: one each for the four Division Algebras. Note that marking any one of the Hypercomplex coefficients as a Ball automatically marks them all as Balls.<br />
{|<br />
|-<br />
|Real||&nbsp;&nbsp;&nbsp;&nbsp;<apll>23<_pom/></apll> or <apll>1.2<_pom/></apll><br />
|-<br />
|Complex||&nbsp;&nbsp;&nbsp;&nbsp;<apll>23<_i/>1.2<_pom/></apll><br />
|-<br />
|Quaternion||&nbsp;&nbsp;&nbsp;&nbsp;<apll>23<_i/>1.2<_j/>0.5<_k/>¯3.14<_pom/></apll><br />
|-<br />
|Octonion||&nbsp;&nbsp;&nbsp;&nbsp;<apll>23<_i/>1.2<_j/>0.5<_k/>¯3.14<l/>¯3<_ij/>19<_jk/>¯3<_kl/>6<_pom/></apll><br />
|}<br />
<br />
===Primitive Functions===<br />
<br />
As described above, this feature adds two new monadic primitive functions '''Contract''' (<apll>≤R</apll>) and its inverse '''Distract''' (<apll>≥R</apll>), along with one new monadic primitive operator '''DoubleTilde''' <apll>f≈ R</apll> and <apll>L f≈ R</apll>.<br />
<br />
All primitive and system functions and operators are extended to work with Ball Arithmetic, so you can test out this feature on all algorithms, with the exception of trying to find the Factorial of a multiple-precision/Ball Arithmetic Hypercomplex number, in which case you are temporarily out of luck.<br />
<br />
==Workspace Version Number==<br />
<br />
For the moment, if you save a workspace which contains a Ball Arithmetic number in a variable, the workspace version number is <apll>0.03</apll>. Otherwise, the version number is <apll>0.02</apll>. Workspaces with Ball Arithmetic Numbers may not be loaded by an earlier version of the interpreter.<br />
<br />
==Pending Design Decisions==<br />
<br />
<ul><br />
<li>The direct comparison functions (<apll>&lt;≤=≥&gt;≠≡≢</apll>) and indirect ones (<apll>⍳⍸∊⍷⍒⍋</apll>) are currently implemented to compare the Midpoints of the arguments ignoring the Radius &mdash; this may change.</li><br />
<li>The Floor function and its related functions (Ceiling, Residue, GCD, LCM, and Encode) are currently implemented to execute on the Midpoints of the arguments ignoring the Radius &mdash; this may change.</li><br />
<li>We need new primitives to describe the different ways in which Balls can intersect/overlap, possibly through a new monadic operator (perhaps &#x2248;) on the existing direct and indirect comparison and Floor-related functions.</li><br />
<li>Certain primitives are defined on limited ranges, and sometimes multiple ranges where it might use different algorithms for different ranges (e.g. <apll>L!R</apll>). There are open questions about how to handle a Ball that spans two or more of these ranges as to how to calculate the result.</li><br />
<li>Infinity and NaN have not been given any special treatment as yet. The results are whatever ARB has chosen which we may need to override.</li><br />
</ul><br />
<br />
==Download==<br />
<br />
This feature is available as an Alpha release &mdash; it may be downloaded from the [http://www.nars2000.org/download/binaries/alpha/ Alpha] release directory.<br />
<br />
==Acknowledgements==<br />
<br />
<ul><br />
<li>The Arb team has contributed their Ball Arithmetic<ref name="BallArithmetic" /> code which made this feature possible.</li><br />
<li>David Rabenhorst has contributed many very useful ideas and many hours debugging the implementation.</li><br />
</ul><br />
<br />
==References==<br />
<br />
<references /></div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=Ball_Arithmetic&diff=3354Ball Arithmetic2018-10-09T20:12:57Z<p>Sudleyplace: /* Union and Intersection of Balls */</p>
<hr />
<div>==Introduction==<br />
<br />
Ball<ref name="BallArithmetic">NARS2000 Wiki, [http://arblib.org Ball Arithmetic]</ref> and Interval Arithmetic<ref name="IntervalArithmetic">Wikipedia, [https://en.wikipedia.org/wiki/Interval_arithmetic Interval Arithmetic]</ref> both refer to the same idea of calculating with arbitrary precision inexact numbers &mdash; that is, with a range of floating point values instead of a single representative. This allows such numbers to reflect their inexactness explicitly.<br />
<br />
"The most common use is to keep track of and handle rounding errors directly during the calculation and of uncertainties in the knowledge of the exact values of physical and technical parameters. The latter often arise from measurement errors and tolerances for components or '''due to limits on computational accuracy'''. Interval arithmetic also helps find reliable and guaranteed solutions to equations and optimization problems."<ref name="IntervalArithmetic" /><br />
<br />
The difference between the two is in how each approach represents its values: Interval Arithmetic uses the two ends of the interval <apll>[a, b]</apll> whereas Ball Arithmetic uses a Ball with a Midpoint and Radius. Each has its advantages. Interval Arithmetic is implemented by several libraries such as MPFI<ref name="MPFI">[http://perso.ens-lyon.fr/nathalie.revol/software.html MPFI]</ref> and Ball Arithmetic is implemented by ARB<ref name="BallArithmetic" />.<br />
<br />
This feature uses the ARB<ref name="BallArithmetic" /> library to implement Ball Arithmetic.<br />
<br />
==Environment==<br />
<br />
In the examples below, unless otherwise specified, the precision of multi-precision floating-point numbers is set to <apll>53</apll> bits via <apll>⎕FPC←53</apll> which is the same precision as standard double-precision numbers. The Printing Precision is set to <apll>17</apll> digits via <apll>⎕PP←17</apll> so as to display the maximum number of significant digits at <apll>53</apll> bits of precision. The Comparison Tolerance is set via <apll>⎕CT←1<_E/>¯10</apll>.<br />
<br />
==Calculating With Ball Arithmetic==<br />
<br />
If you have ever entered an expression such as<br />
<br />
<apll><pre><br />
÷3<br />
0.3333333333333333<br />
</pre></apll><br />
<br />
undoubtedly, you are aware that the result is inexact. Moreover, as you incorporate into your code the many other functions that produce inexact numbers, you should be wondering "How does the accumulation of inexactness affect my results?".<br />
<br />
The answer to that question lies in the province of [https://en.wikipedia.org/wiki/Numerical_analysis Numerical Analysis] where it is described as "the study of algorithms that use numerical approximation". In general, applying the techniques of Numerical Analysis often involves time-consuming analysis. Fortunately, Ball Arithmetic is an easy to use alternative to that. That is, instead of analyzing the algorithm, run the algorithm with all calculations done with Ball Arithmetic.<br />
<br />
Here is the same expression in Ball Arithmetic (use Alt-‘q’ or Ctrl-‘q’, depending on your keyboard layout, to enter the <apll><_pom/></apll> symbol):<br />
<br />
<apll><pre><br />
÷3<_pom/><br />
0.3333333333333333<_pom/>5.6<_E/>¯17<br />
</pre></apll><br />
<br />
Essentially, each Ball Arithmetic number carries with it an explicit Radius that describes the interval which contains the true value. Because Ball Arithmetic data propagates throughout a calculation and is never demoted to a lower datatype, its advantage is that after each operation the resulting Ball reliably includes the true answer. Across an entire algorithm, the final result is a Ball that indicates explicitly how precise it is, thus eliminating the guesswork as to the effect on the algorithm of the inexactness of the input and any other inexact constants used.<br />
<br />
For example,<br />
<br />
<apll><pre><br />
sqrt←{⍺←= ⋄ {0.5×⍵+⍺÷⍵}⍣⍺⍨⍵} ⍝ Calculate square root using Newton's method<br />
√2<_pom/><br />
1.414213562373095<_pom/>2.2<_E/>¯16<br />
sqrt 2<_pom/><br />
1.414213562373095<_pom/>1.1<_E/>¯15 <br />
10 sqrt 2<_pom/><br />
1.414213562373095<_pom/>2.8<_E/>¯15 <br />
100 sqrt 2<_pom/><br />
1.414213562373095<_pom/>3.3<_E/>¯14 <br />
1000 sqrt 2<_pom/><br />
1.414213562373095<_pom/>3.3<_E/>¯13 <br />
10000 sqrt 2<_pom/><br />
1.414213562373095<_pom/>3.5<_E/>¯12<br />
</pre></apll><br />
<br />
As you can see, after a few iterations, the accuracy of the result doesn't improve. However, because it is an iterative algorithm, the precision worsens as the number of iterations increases. Only by using Ball Arithmetic can you see just how the precision of the result is affected.<br />
<br />
To demonstrate with an extreme example, consider the following function:<br />
<br />
<apll><pre><br />
f←{⍪⍵-3√(⍵*3)-⍵*2}<br />
f 10*3×⍳5<br />
0.33344450621439137<br />
0.3333334452472627 <br />
0.33333444595336914<br />
0.3348388671875 <br />
2.25<br />
</pre></apll><br />
<br />
Without knowing much about this ([https://en.wikipedia.org/wiki/Condition_number ill-conditioned]) algorithm, you have no reason to suspect these results. As it turns out, there's a mathematical proof that as the argument increases to infinity, the algorithm converges to <apll>÷3</apll>. Only when you calculate with Ball Arithmetic do you see that there is a problem:<br />
<br />
<apll><pre><br />
f 10*3×⍳5<_pom/><br />
0.3334445062153009<_pom/>2.2<_E/>¯12 <br />
0.3333334461785853<_pom/>4.3<_E/>¯9 <br />
0.333337664604187<_pom/>0.0000062<br />
0.3385009765625<_pom/>0.0085<br />
1.25<_pom/>5<br />
</pre></apll><br />
<br />
As you can see, the precision worsens quickly to the point where the result is meaningless. The last line even says that the answer lies somewhere between <apll>¯3.75</apll> and <apll>6.25</apll>. In other words, that answer is so '''imprecise''' as to be '''inaccurate'''! At higher powers of ten, the answers only worsen.<br />
<br />
The good news with Ball Arithmetic is that if you need greater precision, just increase the value of <apll>⎕FPC</apll>. For example,<br />
<br />
<apll><pre><br />
⎕FPC←128 ⋄ ⎕PP←40<br />
sqrt 2<_pom/><br />
1.41421356237309504880168872420969807857<_pom/>5.9<_E/>¯39<br />
</pre></apll><br />
<br />
In the case of an ill-conditioned algorithm, we just push the problem off a bit, but not very far &mdash; the problem is that the algorithm requires infinite precision:<br />
<br />
<apll><pre><br />
f 10*3×⍳10<_pom/><br />
0.333444506214021971364848444464298690637<_pom/>3.4<_E/>¯35<br />
0.333333444444506172880658466392407138179<_pom/>1.1<_E/>¯31<br />
0.333333333444444444506172839632668381652<_pom/>1.6<_E/>¯28<br />
0.333333333333444444444444547458328123363<_pom/>2.2<_E/>¯25<br />
0.333333333333333444444619474517508476812<_pom/>3.2<_E/>¯22<br />
0.333333333333333333552432522356445687706<_pom/>1.3<_E/>¯19<br />
0.333333333333333491771410805881714622956<_pom/>4.5<_E/>¯16<br />
0.333333333333417414223731611855328083038<_pom/>4.5<_E/>¯13<br />
0.33333333363771089352667331695556640625<_pom/>4.5<_E/>¯10 <br />
0.3333334587514400482177734375<_pom/>2.6<_E/>¯7<br />
</pre></apll><br />
<br />
While your floating point code might not be so ill-conditioned, the only way to be sure of its results is one of<br />
<br />
<ul><br />
<li>Hire a Numerical Analyst</li><br />
<li>Become a Numerical Analyst</li><br />
<li>Use Ball Arithmetic</li><br />
</ul><br />
<br />
==Ball Arithmetic Numbers==<br />
<br />
A Ball Arithmetic number consist of two parts: a Midpoint and Radius. The Midpoint value represents the middle of the Ball and the Radius represents the distance around the Ball of possible values. There is no way to tell which value in the Ball is the correct answer &mdash; you should assume that all values are potential candidates. <br />
<br />
The precision at which the Midpoint and Radius are stored depends upon the current value of <apll>⎕FPC</apll>. For example, the following display<br />
<br />
<apll><pre><br />
⎕FPC←53<br />
÷3<_pom/><br />
0.3333333333333333<_pom/>5.6<_E/>¯17<br />
</pre></apll><br />
<br />
indicates that the number <apll>÷3<_pom/></apll> has a Midpoint of <apll>0.3333333333333333</apll> at <apll>53</apll>-bit precision and a Radius of <apll>5.6<_E/>¯17</apll>. The Midpoint is stored as a variable precision number, and the Radius is stored as a low-precision number.<br />
<br />
Alternatively,<br />
<br />
<apll><pre><br />
⎕FPC←128 ⋄ ⎕PP←40<br />
÷3<_pom/><br />
0.333333333333333333333333333333333333332<_pom/>1.5<_E/>¯39<br />
</pre></apll><br />
<br />
shows the corresponding value at a higher precision and correspondingly narrower Radius.<br />
<br />
A Ball describes a range of '''variable-precision floating point numbers''', and so the expression <apll>23<_pom/>1</apll> represents the set of Real numbers between <apll>22</apll> and <apll>24</apll>, inclusive, '''not''' the three integers <apll>22</apll>, <apll>23</apll>, <apll>24</apll>.<br />
<br />
<p class="note" style=" background-color:lightcyan;">In general, suffix notation on Ball Arithmetic constants should be sufficient for '''almost all purposes'''. That is, the Radius is already correctly calculated for constants such as <apll>23<_pom/></apll> whose Radius is zero, and <apll>1.2<_pom/></apll> whose Radius at <apll>53</apll> bits of precision is on the order of <apll>2*¯53</apll> (because of the inexactness of the Midpoint <apll>1.2</apll>) which displays as <apll>1.2<_pom/>2.2<_E/>¯16</apll>. Although the input notation supports it, the need to override the default Radius should be '''quite rare'''.</p><br />
<br />
==New Functions and Operator==<br />
<br />
===Functions To Convert To And From Ball Arithmetic Numbers===<br />
<br />
A Ball Arithmetic constant number may be created through notation (as seen above). Otherwise, a Ball Arithmetic number also may be created from its constituent parts under program control with a new primitive function '''Contract''', and separated into its constituent parts with a new primitive function '''Distract'''.<br />
<br />
====Contract====<br />
<br />
'''Contract''' is a monadic function (<apll>≤R</apll>) whose right argument is a Real array. It may be used to create a Ball Arithmetic number from the one- or two-elements of its Midpoint and (optional) Radius. The Axis Operator may specify any length <apll>1</apll> or <apll>2</apll> coordinate along which the conversion takes place. It converts the first element along the specified dimension to the Midpoint of the result and (if present) the second element to its Radius. If the second element is not present (i.e., length <apll>1</apll> coordinate), the Radius used is calculated from the precision of the Midpoint.<br />
<br />
<apll><pre><br />
≤23<br />
23<br />
≤1.2<br />
1.2<_pom/>1.1<_E/>¯16<br />
≤1.3 1<_E/>¯20<br />
1.3<_pom/>1<_E/>¯20<br />
≤1r2 1<_E/>¯20<br />
0.5<_pom/>1<_E/>¯20<br />
≤○1<br />
3.141592653589793<_pom/>1.1<_E/>¯16 <br />
≤(○1) 1<_E/>¯20<br />
3.141592653589793<_pom/>1<_E/>¯20 <br />
</pre></apll><br />
<br />
====Distract====<br />
<br />
'''Distract''' is a monadic function (<apll>≥R</apll>) whose right argument is a Real array. It may be used to separate out a Ball Arithmetic's Midpoint and Radius into two distinct values. The Axis Operator may specify the place where the new length <apll>2</apll> coordinate is to be inserted. The pair of values along this new coordinate are the Midpoint and Radius of the corresponding number from the right argument. If the number can be represented exactly, the Radius is zero.<br />
<br />
<apll><pre><br />
⎕PP←10<br />
≥1.2<br />
1.2 1.1102230246251565<_E/>¯16<br />
≥1.2<_x/><br />
6<_r/>5 0<br />
≥1.2<_v/><br />
1.2 1.110223024625157<_E/>¯16<br />
≥1.2<_pom/><br />
1.2 2.220446049250313<_E/>¯16<br />
≥1.5<br />
1.5 0<br />
≥1.5<_x/><br />
3<_r/>2 0<br />
≥1.5<_v/><br />
1.5 1.110223024625157<_E/>¯16<br />
≥1.5<_pom/><br />
1.5 0<br />
a←(○1<_pom/>)×⍳4<br />
a,'|',≥a<br />
3.141592654<_pom/>4.4<_E/>¯16 | 3.141592654 4.440892148<_E/>¯16<br />
6.283185307<_pom/>8.9<_E/>¯16 | 6.283185307 8.881784296<_E/>¯16<br />
9.424777961<_pom/>1.3<_E/>¯15 | 9.424777961 1.332267643<_E/>¯15<br />
12.56637061<_pom/>1.8<_E/>¯15 | 12.56637061 1.776356859<_E/>¯15<br />
</pre></apll><br />
<br />
These numbers can be represented exactly:<br />
<br />
<apll><pre><br />
≥⍳4<_pom/><br />
1 0<br />
2 0<br />
3 0<br />
4 0<br />
≥[2]⍳4<_pom/><br />
1 0<br />
2 0<br />
3 0<br />
4 0<br />
≥[1]⍳4<_pom/><br />
1 2 3 4<br />
0 0 0 0<br />
</pre></apll><br />
<br />
====Identities====<br />
<br />
The Contract of the Distract of a number both along the same axis, returns the same number.<br />The Distract of the Contract of a number both along the same length two axis, returns the same number.<br />
<br />
===Operator To Provide Arbitrary Precision Specific Derived Functions===<br />
<br />
This operator should be considered preliminary.<br />
<br />
====Union and Intersection of Balls====<br />
<br />
The DoubleTilde monadic operator (<apll>≈</apll>, Alt-'Q' or Alt-shift-'q') takes a primitive function as its left operand and produces an arbitrary-precision-specific derived function. At the moment, it is defined for two primitive functions with more to come particularly with the comparison functions.<br />
<br />
Because Ball arithmetic numbers represent a range of floating point numbers, at times it is desirable to produce their Union or Intersection.<br />
<br />
For example,<br />
<br />
<apll><pre><br />
x←0.5<pom/>0.5 ⍝ The interval [0,1]<br />
x∪≈x+2 ⍝ The interval [0,1] ∪ [2,3] ←→ [0,3]<br />
1.5<pom/>1.5<br />
x∪≈x+1 ⍝ The interval [0,1] ∪ [1,2] ←→ [0,2]<br />
1<pom/>1 <br />
x∩≈x+1 ⍝ The interval [0,1] ∩ [1,2] ←→ [1,1]<br />
1<br />
</pre></apll><br />
<br />
If two Balls have no points in common, the result is a NaN (<apll>∅</apll>):<br />
<br />
<apll><pre><br />
x∩≈x+1.1 ⍝ The interval [0,1] ∩ [1.1,2.1] ←→ ∅<br />
∅<br />
</pre></apll><br />
<br />
====Comparison Functions====<br />
<br />
This might be the place to define new derived functions such as <apll>&lt;≈</apll> which can return a non-Boolean result so as to cover the more complicated relationship of one Ball with another with respect to overlap, etc.<br />
<br />
==Hypercomplex Ball Arithmetic==<br />
<br />
Ball Arithmetic also extends to all Hypercomplex numbers (Complex, Quaternion, and Octonion) such as <apll>1.2<_pom/><_i/>2.2</apll> which represents a Complex Ball Arithmetic number whose '''Real''' part is <apll>1.2<_pom/></apll> and whose '''Imaginary''' part is <apll>2.2<_pom/></apll>. Note that the display of that number (at <apll>53</apll> bits of precision)<br />
<br />
<apll><pre><br />
1.2<_pom/><_i/>2.2<br />
1.2<_pom/>2.2<_E/>¯16<_i/>2.2<_pom/>4.4<_E/>¯16<br />
</pre></apll><br />
<br />
demonstrates the inexactness of both floating point coefficients.<br />
<br />
==Invalid Results==<br />
<br />
Not all Balls are valid arguments to all primitive functions. Sometimes, the result cannot be expressed in a Ball, such as<br />
<br />
<apll><pre><br />
√0<_pom/>1<br />
∅<br />
</pre></apll><br />
<br />
To see why, split apart the argument into two parts: <apll>¯0.5<_pom/>0.5</apll> and <apll>0.5<_pom/>0.5</apll> and apply the Square Root function to the separate parts. This yields a result that consists of two quite disjoint Balls: the square root of the Ball <apll>¯0.5<_pom/>0.5</apll> is <apll>0<_i/>0.5<_pom/>0.5</apll>, whereas the square root of the Ball <apll>0.5<_pom/>0.5</apll> is <apll>0.5<_pom/>0.5</apll> . As the two parts of the result are orthogonal to each other, they cannot be expressed as a single Midpoint-Radius Ball, and so the result is a NaN (= Not-A-Number = <apll>∅</apll>).<br />
<br />
==Small v. Large Radii==<br />
<br />
Ball Arithmetic works best when given small Radii, that is, small relative to the Midpoint. Calculations on large Radii numbers such as <apll>0<_i/>0.5<_pom/>0.5</apll> don't always produce useful results. For example,<br />
<br />
<apll><pre><br />
⎕←x←0<_i/>0.5<_pom/>0.5*2<br />
¯0.25<_pom/>0.75<br />
</pre></apll><br />
<br />
which follows from the standard way of multiplying Complex numbers<ref name="CayleyDickson">[https://en.wikipedia.org/wiki/Cayley%E2%80%93Dickson_construction]</ref>. Unfortunately in this case, because the Radius is so large that it includes negative numbers on the low end, the Square Root of this particular Squared interval is not representable, that is, it is a NaN:<br />
<br />
<apll><pre><br />
√x<br />
0<_i/>∅<br />
</pre></apll><br />
<br />
These calculations work better using smaller Radii, such as<br />
<br />
<apll><pre><br />
⎕←y←0<_i/>0.5<_pom/>0.5<_E/>¯10*2<br />
¯0.25<_pom/>5<_E/>¯11<br />
√y<br />
0<_i/>0.5<_pom/>5<_E/>¯11<br />
</pre></apll><br />
<br />
where Square Root now returns a meaningful result.<br />
<br />
==Mixed Notation==<br />
<br />
The notation for Ball Arithmetic may be combined with other Point Notations in many ways, such as<br />
<br />
<apll><pre><br />
1<_p/>1<_pom/><br />
3.141592653589793<_pom/>8.9<_E/>¯16 <br />
1<_x/>1<_pom/><br />
2.718281828459045<_pom/>4.5<_E/>¯16<br />
</pre></apll><br />
<br />
For more details about combining different forms of Point Notation, see [[Point_Notation|Point Notation]] and in particular the section on [[Point_Notation#Mixed_Notation|Mixed Notation]].<br />
<br />
==Implementation==<br />
<br />
===Datataypes===<br />
<br />
This feature adds four new datatypes to the language: one each for the four Division Algebras. Note that marking any one of the Hypercomplex coefficients as a Ball automatically marks them all as Balls.<br />
{|<br />
|-<br />
|Real||&nbsp;&nbsp;&nbsp;&nbsp;<apll>23<_pom/></apll> or <apll>1.2<_pom/></apll><br />
|-<br />
|Complex||&nbsp;&nbsp;&nbsp;&nbsp;<apll>23<_i/>1.2<_pom/></apll><br />
|-<br />
|Quaternion||&nbsp;&nbsp;&nbsp;&nbsp;<apll>23<_i/>1.2<_j/>0.5<_k/>¯3.14<_pom/></apll><br />
|-<br />
|Octonion||&nbsp;&nbsp;&nbsp;&nbsp;<apll>23<_i/>1.2<_j/>0.5<_k/>¯3.14<l/>¯3<_ij/>19<_jk/>¯3<_kl/>6<_pom/></apll><br />
|}<br />
<br />
===Primitive Functions===<br />
<br />
As described above, this feature adds two new monadic primitive functions '''Contract''' (<apll>≤R</apll>) and its inverse '''Distract''' (<apll>≥R</apll>).<br />
<br />
All primitive and system functions and operators are extended to work with Ball Arithmetic, so you can test out this feature on all algorithms, with the exception of trying to find the Factorial of a multiple-precision/Ball Arithmetic Hypercomplex number, in which case you are temporarily out of luck.<br />
<br />
==Workspace Version Number==<br />
<br />
For the moment, if you save a workspace which contains a Ball Arithmetic number in a variable, the workspace version number is <apll>0.03</apll>. Otherwise, the version number is <apll>0.02</apll>. Workspaces with Ball Arithmetic Numbers may not be loaded by an earlier version of the interpreter.<br />
<br />
==Pending Design Decisions==<br />
<br />
<ul><br />
<li>The direct comparison functions (<apll>&lt;≤=≥&gt;≠≡≢</apll>) and indirect ones (<apll>⍳⍸∊⍷⍒⍋</apll>) are currently implemented to compare the Midpoints of the arguments ignoring the Radius &mdash; this may change.</li><br />
<li>The Floor function and its related functions (Ceiling, Residue, GCD, LCM, and Encode) are currently implemented to execute on the Midpoints of the arguments ignoring the Radius &mdash; this may change.</li><br />
<li>We need new primitives to describe the different ways in which Balls can intersect/overlap, possibly through a new monadic operator (perhaps &#x2248;) on the existing direct and indirect comparison and Floor-related functions.</li><br />
<li>Certain primitives are defined on limited ranges, and sometimes multiple ranges where it might use different algorithms for different ranges (e.g. <apll>L!R</apll>). There are open questions about how to handle a Ball that spans two or more of these ranges as to how to calculate the result.</li><br />
<li>Infinity and NaN have not been given any special treatment as yet. The results are whatever ARB has chosen which we may need to override.</li><br />
</ul><br />
<br />
==Download==<br />
<br />
This feature is available as an Alpha release &mdash; it may be downloaded from the [http://www.nars2000.org/download/binaries/alpha/ Alpha] release directory.<br />
<br />
==Acknowledgements==<br />
<br />
The Arb team has contributed their Ball Arithmetic<ref name="BallArithmetic" /> code which made this feature possible.<br />
<br />
==References==<br />
<br />
<references /></div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=Ball_Arithmetic&diff=3353Ball Arithmetic2018-09-29T15:38:46Z<p>Sudleyplace: /* Pending Design Decisions */</p>
<hr />
<div>==Introduction==<br />
<br />
Ball<ref name="BallArithmetic">NARS2000 Wiki, [http://arblib.org Ball Arithmetic]</ref> and Interval Arithmetic<ref name="IntervalArithmetic">Wikipedia, [https://en.wikipedia.org/wiki/Interval_arithmetic Interval Arithmetic]</ref> both refer to the same idea of calculating with arbitrary precision inexact numbers &mdash; that is, with a range of floating point values instead of a single representative. This allows such numbers to reflect their inexactness explicitly.<br />
<br />
"The most common use is to keep track of and handle rounding errors directly during the calculation and of uncertainties in the knowledge of the exact values of physical and technical parameters. The latter often arise from measurement errors and tolerances for components or '''due to limits on computational accuracy'''. Interval arithmetic also helps find reliable and guaranteed solutions to equations and optimization problems."<ref name="IntervalArithmetic" /><br />
<br />
The difference between the two is in how each approach represents its values: Interval Arithmetic uses the two ends of the interval <apll>[a, b]</apll> whereas Ball Arithmetic uses a Ball with a Midpoint and Radius. Each has its advantages. Interval Arithmetic is implemented by several libraries such as MPFI<ref name="MPFI">[http://perso.ens-lyon.fr/nathalie.revol/software.html MPFI]</ref> and Ball Arithmetic is implemented by ARB<ref name="BallArithmetic" />.<br />
<br />
This feature uses the ARB<ref name="BallArithmetic" /> library to implement Ball Arithmetic.<br />
<br />
==Environment==<br />
<br />
In the examples below, unless otherwise specified, the precision of multi-precision floating-point numbers is set to <apll>53</apll> bits via <apll>⎕FPC←53</apll> which is the same precision as standard double-precision numbers. The Printing Precision is set to <apll>17</apll> digits via <apll>⎕PP←17</apll> so as to display the maximum number of significant digits at <apll>53</apll> bits of precision. The Comparison Tolerance is set via <apll>⎕CT←1<_E/>¯10</apll>.<br />
<br />
==Calculating With Ball Arithmetic==<br />
<br />
If you have ever entered an expression such as<br />
<br />
<apll><pre><br />
÷3<br />
0.3333333333333333<br />
</pre></apll><br />
<br />
undoubtedly, you are aware that the result is inexact. Moreover, as you incorporate into your code the many other functions that produce inexact numbers, you should be wondering "How does the accumulation of inexactness affect my results?".<br />
<br />
The answer to that question lies in the province of [https://en.wikipedia.org/wiki/Numerical_analysis Numerical Analysis] where it is described as "the study of algorithms that use numerical approximation". In general, applying the techniques of Numerical Analysis often involves time-consuming analysis. Fortunately, Ball Arithmetic is an easy to use alternative to that. That is, instead of analyzing the algorithm, run the algorithm with all calculations done with Ball Arithmetic.<br />
<br />
Here is the same expression in Ball Arithmetic (use Alt-‘q’ or Ctrl-‘q’, depending on your keyboard layout, to enter the <apll><_pom/></apll> symbol):<br />
<br />
<apll><pre><br />
÷3<_pom/><br />
0.3333333333333333<_pom/>5.6<_E/>¯17<br />
</pre></apll><br />
<br />
Essentially, each Ball Arithmetic number carries with it an explicit Radius that describes the interval which contains the true value. Because Ball Arithmetic data propagates throughout a calculation and is never demoted to a lower datatype, its advantage is that after each operation the resulting Ball reliably includes the true answer. Across an entire algorithm, the final result is a Ball that indicates explicitly how precise it is, thus eliminating the guesswork as to the effect on the algorithm of the inexactness of the input and any other inexact constants used.<br />
<br />
For example,<br />
<br />
<apll><pre><br />
sqrt←{⍺←= ⋄ {0.5×⍵+⍺÷⍵}⍣⍺⍨⍵} ⍝ Calculate square root using Newton's method<br />
√2<_pom/><br />
1.414213562373095<_pom/>2.2<_E/>¯16<br />
sqrt 2<_pom/><br />
1.414213562373095<_pom/>1.1<_E/>¯15 <br />
10 sqrt 2<_pom/><br />
1.414213562373095<_pom/>2.8<_E/>¯15 <br />
100 sqrt 2<_pom/><br />
1.414213562373095<_pom/>3.3<_E/>¯14 <br />
1000 sqrt 2<_pom/><br />
1.414213562373095<_pom/>3.3<_E/>¯13 <br />
10000 sqrt 2<_pom/><br />
1.414213562373095<_pom/>3.5<_E/>¯12<br />
</pre></apll><br />
<br />
As you can see, after a few iterations, the accuracy of the result doesn't improve. However, because it is an iterative algorithm, the precision worsens as the number of iterations increases. Only by using Ball Arithmetic can you see just how the precision of the result is affected.<br />
<br />
To demonstrate with an extreme example, consider the following function:<br />
<br />
<apll><pre><br />
f←{⍪⍵-3√(⍵*3)-⍵*2}<br />
f 10*3×⍳5<br />
0.33344450621439137<br />
0.3333334452472627 <br />
0.33333444595336914<br />
0.3348388671875 <br />
2.25<br />
</pre></apll><br />
<br />
Without knowing much about this ([https://en.wikipedia.org/wiki/Condition_number ill-conditioned]) algorithm, you have no reason to suspect these results. As it turns out, there's a mathematical proof that as the argument increases to infinity, the algorithm converges to <apll>÷3</apll>. Only when you calculate with Ball Arithmetic do you see that there is a problem:<br />
<br />
<apll><pre><br />
f 10*3×⍳5<_pom/><br />
0.3334445062153009<_pom/>2.2<_E/>¯12 <br />
0.3333334461785853<_pom/>4.3<_E/>¯9 <br />
0.333337664604187<_pom/>0.0000062<br />
0.3385009765625<_pom/>0.0085<br />
1.25<_pom/>5<br />
</pre></apll><br />
<br />
As you can see, the precision worsens quickly to the point where the result is meaningless. The last line even says that the answer lies somewhere between <apll>¯3.75</apll> and <apll>6.25</apll>. In other words, that answer is so '''imprecise''' as to be '''inaccurate'''! At higher powers of ten, the answers only worsen.<br />
<br />
The good news with Ball Arithmetic is that if you need greater precision, just increase the value of <apll>⎕FPC</apll>. For example,<br />
<br />
<apll><pre><br />
⎕FPC←128 ⋄ ⎕PP←40<br />
sqrt 2<_pom/><br />
1.41421356237309504880168872420969807857<_pom/>5.9<_E/>¯39<br />
</pre></apll><br />
<br />
In the case of an ill-conditioned algorithm, we just push the problem off a bit, but not very far &mdash; the problem is that the algorithm requires infinite precision:<br />
<br />
<apll><pre><br />
f 10*3×⍳10<_pom/><br />
0.333444506214021971364848444464298690637<_pom/>3.4<_E/>¯35<br />
0.333333444444506172880658466392407138179<_pom/>1.1<_E/>¯31<br />
0.333333333444444444506172839632668381652<_pom/>1.6<_E/>¯28<br />
0.333333333333444444444444547458328123363<_pom/>2.2<_E/>¯25<br />
0.333333333333333444444619474517508476812<_pom/>3.2<_E/>¯22<br />
0.333333333333333333552432522356445687706<_pom/>1.3<_E/>¯19<br />
0.333333333333333491771410805881714622956<_pom/>4.5<_E/>¯16<br />
0.333333333333417414223731611855328083038<_pom/>4.5<_E/>¯13<br />
0.33333333363771089352667331695556640625<_pom/>4.5<_E/>¯10 <br />
0.3333334587514400482177734375<_pom/>2.6<_E/>¯7<br />
</pre></apll><br />
<br />
While your floating point code might not be so ill-conditioned, the only way to be sure of its results is one of<br />
<br />
<ul><br />
<li>Hire a Numerical Analyst</li><br />
<li>Become a Numerical Analyst</li><br />
<li>Use Ball Arithmetic</li><br />
</ul><br />
<br />
==Ball Arithmetic Numbers==<br />
<br />
A Ball Arithmetic number consist of two parts: a Midpoint and Radius. The Midpoint value represents the middle of the Ball and the Radius represents the distance around the Ball of possible values. There is no way to tell which value in the Ball is the correct answer &mdash; you should assume that all values are potential candidates. <br />
<br />
The precision at which the Midpoint and Radius are stored depends upon the current value of <apll>⎕FPC</apll>. For example, the following display<br />
<br />
<apll><pre><br />
⎕FPC←53<br />
÷3<_pom/><br />
0.3333333333333333<_pom/>5.6<_E/>¯17<br />
</pre></apll><br />
<br />
indicates that the number <apll>÷3<_pom/></apll> has a Midpoint of <apll>0.3333333333333333</apll> at <apll>53</apll>-bit precision and a Radius of <apll>5.6<_E/>¯17</apll>. The Midpoint is stored as a variable precision number, and the Radius is stored as a low-precision number.<br />
<br />
Alternatively,<br />
<br />
<apll><pre><br />
⎕FPC←128 ⋄ ⎕PP←40<br />
÷3<_pom/><br />
0.333333333333333333333333333333333333332<_pom/>1.5<_E/>¯39<br />
</pre></apll><br />
<br />
shows the corresponding value at a higher precision and correspondingly narrower Radius.<br />
<br />
A Ball describes a range of '''variable-precision floating point numbers''', and so the expression <apll>23<_pom/>1</apll> represents the set of Real numbers between <apll>22</apll> and <apll>24</apll>, inclusive, '''not''' the three integers <apll>22</apll>, <apll>23</apll>, <apll>24</apll>.<br />
<br />
<p class="note" style=" background-color:lightcyan;">In general, suffix notation on Ball Arithmetic constants should be sufficient for '''almost all purposes'''. That is, the Radius is already correctly calculated for constants such as <apll>23<_pom/></apll> whose Radius is zero, and <apll>1.2<_pom/></apll> whose Radius at <apll>53</apll> bits of precision is on the order of <apll>2*¯53</apll> (because of the inexactness of the Midpoint <apll>1.2</apll>) which displays as <apll>1.2<_pom/>2.2<_E/>¯16</apll>. Although the input notation supports it, the need to override the default Radius should be '''quite rare'''.</p><br />
<br />
==New Functions and Operator==<br />
<br />
===Functions To Convert To And From Ball Arithmetic Numbers===<br />
<br />
A Ball Arithmetic constant number may be created through notation (as seen above). Otherwise, a Ball Arithmetic number also may be created from its constituent parts under program control with a new primitive function '''Contract''', and separated into its constituent parts with a new primitive function '''Distract'''.<br />
<br />
====Contract====<br />
<br />
'''Contract''' is a monadic function (<apll>≤R</apll>) whose right argument is a Real array. It may be used to create a Ball Arithmetic number from the one- or two-elements of its Midpoint and (optional) Radius. The Axis Operator may specify any length <apll>1</apll> or <apll>2</apll> coordinate along which the conversion takes place. It converts the first element along the specified dimension to the Midpoint of the result and (if present) the second element to its Radius. If the second element is not present (i.e., length <apll>1</apll> coordinate), the Radius used is calculated from the precision of the Midpoint.<br />
<br />
<apll><pre><br />
≤23<br />
23<br />
≤1.2<br />
1.2<_pom/>1.1<_E/>¯16<br />
≤1.3 1<_E/>¯20<br />
1.3<_pom/>1<_E/>¯20<br />
≤1r2 1<_E/>¯20<br />
0.5<_pom/>1<_E/>¯20<br />
≤○1<br />
3.141592653589793<_pom/>1.1<_E/>¯16 <br />
≤(○1) 1<_E/>¯20<br />
3.141592653589793<_pom/>1<_E/>¯20 <br />
</pre></apll><br />
<br />
====Distract====<br />
<br />
'''Distract''' is a monadic function (<apll>≥R</apll>) whose right argument is a Real array. It may be used to separate out a Ball Arithmetic's Midpoint and Radius into two distinct values. The Axis Operator may specify the place where the new length <apll>2</apll> coordinate is to be inserted. The pair of values along this new coordinate are the Midpoint and Radius of the corresponding number from the right argument. If the number can be represented exactly, the Radius is zero.<br />
<br />
<apll><pre><br />
⎕PP←10<br />
≥1.2<br />
1.2 1.1102230246251565<_E/>¯16<br />
≥1.2<_x/><br />
6<_r/>5 0<br />
≥1.2<_v/><br />
1.2 1.110223024625157<_E/>¯16<br />
≥1.2<_pom/><br />
1.2 2.220446049250313<_E/>¯16<br />
≥1.5<br />
1.5 0<br />
≥1.5<_x/><br />
3<_r/>2 0<br />
≥1.5<_v/><br />
1.5 1.110223024625157<_E/>¯16<br />
≥1.5<_pom/><br />
1.5 0<br />
a←(○1<_pom/>)×⍳4<br />
a,'|',≥a<br />
3.141592654<_pom/>4.4<_E/>¯16 | 3.141592654 4.440892148<_E/>¯16<br />
6.283185307<_pom/>8.9<_E/>¯16 | 6.283185307 8.881784296<_E/>¯16<br />
9.424777961<_pom/>1.3<_E/>¯15 | 9.424777961 1.332267643<_E/>¯15<br />
12.56637061<_pom/>1.8<_E/>¯15 | 12.56637061 1.776356859<_E/>¯15<br />
</pre></apll><br />
<br />
These numbers can be represented exactly:<br />
<br />
<apll><pre><br />
≥⍳4<_pom/><br />
1 0<br />
2 0<br />
3 0<br />
4 0<br />
≥[2]⍳4<_pom/><br />
1 0<br />
2 0<br />
3 0<br />
4 0<br />
≥[1]⍳4<_pom/><br />
1 2 3 4<br />
0 0 0 0<br />
</pre></apll><br />
<br />
====Identities====<br />
<br />
The Contract of the Distract of a number both along the same axis, returns the same number.<br />The Distract of the Contract of a number both along the same length two axis, returns the same number.<br />
<br />
===Operator To Provide Arbitrary Precision Specific Derived Functions===<br />
<br />
This operator should be considered preliminary.<br />
<br />
====Union and Intersection of Balls====<br />
<br />
The DoubleTilde monadic operator (<apll>≈</apll>, Alt-'Q' or Alt-shift-'q') takes a primitive function as its right operand and produces an arbitrary-precision-specific derived function. At the moment, it is defined for two primitive functions with more to come particularly with the comparison functions.<br />
<br />
Because Ball arithmetic numbers represent a range of floating point numbers, at times it is desirable to produce their Union or Intersection.<br />
<br />
For example,<br />
<br />
<apll><pre><br />
x←0.5<pom/>0.5 ⍝ The interval [0,1]<br />
x∪≈x+2 ⍝ The interval [0,1] ∪ [2,3] ←→ [0,3]<br />
1.5<pom/>1.5<br />
x∪≈x+1 ⍝ The interval [0,1] ∪ [1,2] ←→ [0,2]<br />
1<pom/>1 <br />
x∩≈x+1 ⍝ The interval [0,1] ∩ [1,2] ←→ [1,1]<br />
1<br />
</pre></apll><br />
<br />
If two Balls have no points in common, the result is a NaN (<apll>∅</apll>):<br />
<br />
<apll><pre><br />
x∩≈x+1.1 ⍝ The interval [0,1] ∩ [1.1,2.1] ←→ ∅<br />
∅<br />
</pre></apll><br />
<br />
====Comparison Functions====<br />
<br />
This might be the place to define new derived functions such as <apll>&lt;≈</apll> which can return a non-Boolean result so as to cover the more complicated relationship of one Ball with another with respect to overlap, etc.<br />
<br />
==Hypercomplex Ball Arithmetic==<br />
<br />
Ball Arithmetic also extends to all Hypercomplex numbers (Complex, Quaternion, and Octonion) such as <apll>1.2<_pom/><_i/>2.2</apll> which represents a Complex Ball Arithmetic number whose '''Real''' part is <apll>1.2<_pom/></apll> and whose '''Imaginary''' part is <apll>2.2<_pom/></apll>. Note that the display of that number (at <apll>53</apll> bits of precision)<br />
<br />
<apll><pre><br />
1.2<_pom/><_i/>2.2<br />
1.2<_pom/>2.2<_E/>¯16<_i/>2.2<_pom/>4.4<_E/>¯16<br />
</pre></apll><br />
<br />
demonstrates the inexactness of both floating point coefficients.<br />
<br />
==Invalid Results==<br />
<br />
Not all Balls are valid arguments to all primitive functions. Sometimes, the result cannot be expressed in a Ball, such as<br />
<br />
<apll><pre><br />
√0<_pom/>1<br />
∅<br />
</pre></apll><br />
<br />
To see why, split apart the argument into two parts: <apll>¯0.5<_pom/>0.5</apll> and <apll>0.5<_pom/>0.5</apll> and apply the Square Root function to the separate parts. This yields a result that consists of two quite disjoint Balls: the square root of the Ball <apll>¯0.5<_pom/>0.5</apll> is <apll>0<_i/>0.5<_pom/>0.5</apll>, whereas the square root of the Ball <apll>0.5<_pom/>0.5</apll> is <apll>0.5<_pom/>0.5</apll> . As the two parts of the result are orthogonal to each other, they cannot be expressed as a single Midpoint-Radius Ball, and so the result is a NaN (= Not-A-Number = <apll>∅</apll>).<br />
<br />
==Small v. Large Radii==<br />
<br />
Ball Arithmetic works best when given small Radii, that is, small relative to the Midpoint. Calculations on large Radii numbers such as <apll>0<_i/>0.5<_pom/>0.5</apll> don't always produce useful results. For example,<br />
<br />
<apll><pre><br />
⎕←x←0<_i/>0.5<_pom/>0.5*2<br />
¯0.25<_pom/>0.75<br />
</pre></apll><br />
<br />
which follows from the standard way of multiplying Complex numbers<ref name="CayleyDickson">[https://en.wikipedia.org/wiki/Cayley%E2%80%93Dickson_construction]</ref>. Unfortunately in this case, because the Radius is so large that it includes negative numbers on the low end, the Square Root of this particular Squared interval is not representable, that is, it is a NaN:<br />
<br />
<apll><pre><br />
√x<br />
0<_i/>∅<br />
</pre></apll><br />
<br />
These calculations work better using smaller Radii, such as<br />
<br />
<apll><pre><br />
⎕←y←0<_i/>0.5<_pom/>0.5<_E/>¯10*2<br />
¯0.25<_pom/>5<_E/>¯11<br />
√y<br />
0<_i/>0.5<_pom/>5<_E/>¯11<br />
</pre></apll><br />
<br />
where Square Root now returns a meaningful result.<br />
<br />
==Mixed Notation==<br />
<br />
The notation for Ball Arithmetic may be combined with other Point Notations in many ways, such as<br />
<br />
<apll><pre><br />
1<_p/>1<_pom/><br />
3.141592653589793<_pom/>8.9<_E/>¯16 <br />
1<_x/>1<_pom/><br />
2.718281828459045<_pom/>4.5<_E/>¯16<br />
</pre></apll><br />
<br />
For more details about combining different forms of Point Notation, see [[Point_Notation|Point Notation]] and in particular the section on [[Point_Notation#Mixed_Notation|Mixed Notation]].<br />
<br />
==Implementation==<br />
<br />
===Datataypes===<br />
<br />
This feature adds four new datatypes to the language: one each for the four Division Algebras. Note that marking any one of the Hypercomplex coefficients as a Ball automatically marks them all as Balls.<br />
{|<br />
|-<br />
|Real||&nbsp;&nbsp;&nbsp;&nbsp;<apll>23<_pom/></apll> or <apll>1.2<_pom/></apll><br />
|-<br />
|Complex||&nbsp;&nbsp;&nbsp;&nbsp;<apll>23<_i/>1.2<_pom/></apll><br />
|-<br />
|Quaternion||&nbsp;&nbsp;&nbsp;&nbsp;<apll>23<_i/>1.2<_j/>0.5<_k/>¯3.14<_pom/></apll><br />
|-<br />
|Octonion||&nbsp;&nbsp;&nbsp;&nbsp;<apll>23<_i/>1.2<_j/>0.5<_k/>¯3.14<l/>¯3<_ij/>19<_jk/>¯3<_kl/>6<_pom/></apll><br />
|}<br />
<br />
===Primitive Functions===<br />
<br />
As described above, this feature adds two new monadic primitive functions '''Contract''' (<apll>≤R</apll>) and its inverse '''Distract''' (<apll>≥R</apll>).<br />
<br />
All primitive and system functions and operators are extended to work with Ball Arithmetic, so you can test out this feature on all algorithms, with the exception of trying to find the Factorial of a multiple-precision/Ball Arithmetic Hypercomplex number, in which case you are temporarily out of luck.<br />
<br />
==Workspace Version Number==<br />
<br />
For the moment, if you save a workspace which contains a Ball Arithmetic number in a variable, the workspace version number is <apll>0.03</apll>. Otherwise, the version number is <apll>0.02</apll>. Workspaces with Ball Arithmetic Numbers may not be loaded by an earlier version of the interpreter.<br />
<br />
==Pending Design Decisions==<br />
<br />
<ul><br />
<li>The direct comparison functions (<apll>&lt;≤=≥&gt;≠≡≢</apll>) and indirect ones (<apll>⍳⍸∊⍷⍒⍋</apll>) are currently implemented to compare the Midpoints of the arguments ignoring the Radius &mdash; this may change.</li><br />
<li>The Floor function and its related functions (Ceiling, Residue, GCD, LCM, and Encode) are currently implemented to execute on the Midpoints of the arguments ignoring the Radius &mdash; this may change.</li><br />
<li>We need new primitives to describe the different ways in which Balls can intersect/overlap, possibly through a new monadic operator (perhaps &#x2248;) on the existing direct and indirect comparison and Floor-related functions.</li><br />
<li>Certain primitives are defined on limited ranges, and sometimes multiple ranges where it might use different algorithms for different ranges (e.g. <apll>L!R</apll>). There are open questions about how to handle a Ball that spans two or more of these ranges as to how to calculate the result.</li><br />
<li>Infinity and NaN have not been given any special treatment as yet. The results are whatever ARB has chosen which we may need to override.</li><br />
</ul><br />
<br />
==Download==<br />
<br />
This feature is available as an Alpha release &mdash; it may be downloaded from the [http://www.nars2000.org/download/binaries/alpha/ Alpha] release directory.<br />
<br />
==Acknowledgements==<br />
<br />
The Arb team has contributed their Ball Arithmetic<ref name="BallArithmetic" /> code which made this feature possible.<br />
<br />
==References==<br />
<br />
<references /></div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=Point_Notation&diff=3292Point Notation2018-08-05T00:05:59Z<p>Sudleyplace: /* Base Point Notation */</p>
<hr />
<div>== Overview ==<br />
<br />
<table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td valign="baseline"><b>Base Point Notation</b>:</td><br />
<td></td><br />
<td></td><br />
<td>e.g., <apll>16<pn>b</pn>10FFFF</apll>as a shorthand for <apll>16⊥1 0 15 15 15 15 15</apll>.</td><br />
</tr><br />
<tr><br />
<td valign="baseline"><b>Euler Point Notation</b>:</td> <br />
<td></td><br />
<td></td><br />
<td>e.g., <apll>2<pn>x</pn>3</apll> as a shorthand for <apll>2∙e<sup>3</sup></apll> or <apll>2×(*1)*3</apll>.</td><br />
</tr><br />
<tr><br />
<td valign="baseline"><b>Pi Point Notation</b>:</td><br />
<td></td><br />
<td></td><br />
<td>e.g., <apll>2<pn>p</pn>3</apll> as a shorthand for <apll>2∙&pi;<sup>3</sup></apll> or <apll>2×(○1)*3</apll>.</td><br />
</tr><br />
<tr><br />
<td valign="baseline"><b>Gamma Point Notation</b>:</td><br />
<td></td><br />
<td></td><br />
<td>e.g., <apll>2<pn>g</pn>3</apll> as a shorthand for <apll>2∙&gamma;<sup>3</sup></apll> where <apll>&gamma;</apll> is the [https://en.wikipedia.org/wiki/Euler%E2%80%93Mascheroni_constant Euler-Mascheroni Constant].</td><br />
</tr><br />
<tr><br />
<td valign="baseline"><b>Hypercomplex Point Notation</b>:</td><br />
<td></td><br />
<td></td><br />
<td>e.g., <apll>2<hc>J</hc>3</apll> or <apll>2<hc>i</hc>3</apll> as a shorthand for <apll>2+3×√¯1</apll>, or <apll>2<hc>ad</hc>3</apll> (Angle in Degrees), <apll>2<hc>ar</hc>3</apll> (Angle in Radians), or <apll>2<hc>au</hc>3</apll> (Angle in Unit Normalized) all for Complex numbers, or <apll>1<hc>i</hc>2<hc>j</hc>3<hc>k</hc>4</apll> for a Quaternion number, or <apll>1<hc>i</hc>2<hc>j</hc>3<hc>k</hc>4<hc>l</hc>5<hc>ij</hc>6<hc>jk</hc>7<hc>kl</hc>8</apll> for an Octonion number.</td><br />
</tr><br />
<tr><br />
<td valign="baseline"><b>Ball Arithmetic Point Notation</b>:</td><br />
<td></td><br />
<td></td><br />
<td valign="baseline">e.g., <apll>2.3<pn>±</pn>1<pn>E</pn>¯9</apll> to indicate a Ball with a Midpoint of <apll>2.3</apll> and a Radius of <apll>1<pn>E</pn>¯9</apll>. Also, <apll>2.3<pn>±</pn></apll> is a shorthand for <apll>2.3<pn>±</pn>0</apll>.<br />
</tr><br />
<tr><br />
<td valign="baseline"><b>Rational Point Notation</b>:</td><br />
<td></td><br />
<td></td><br />
<td valign="baseline">e.g., <apll>2<pn>r</pn>3</apll> as a shorthand for <apll>2{divide}3</apll> as an infinite precision rational number, or <apll>123<pn>x</pn></apll> as a means of representing <apll>123</apll> as an infinite precision integer &mdash; the suffix <apll><pn>x</pn></apll> is actually a shorthand for <apll><pn>r</pn>1</apll>, that is, infinite precision integers are actually represented as rational numbers with a denominator of <apll>1</apll>.</td><br />
</tr><br />
<tr><br />
<td valign="baseline"><b>Variable-Precision Floating Point Notation</b>:</td><br />
<td></td><br />
<td></td><br />
<td valign="baseline">e.g., <apll>2.3<pn>v</pn></apll> as a shorthand for <apll>2.3</apll> as a variable-precision floating point number, or <apll>123<pn>v</pn></apll> as a means of representing <apll>123</apll> as a VFP number whose fractional part is zero.</td><br />
</tr><br />
<tr><br />
<td valign="baseline"><b>Exponential Point Notation</b>:</td><br />
<td></td><br />
<td></td><br />
<td>e.g., <apll>2<pn>e</pn>3</apll> or <apll>2<pn>E</pn>3</apll> as a shorthand for <apll>2&#8729;10<sup>3</sup></apll> or <apll>2×10*3</apll>.</td><br />
</tr><br />
<tr><br />
<td valign="baseline"><b>Decimal Point Notation</b>:</td><br />
<td></td><br />
<td></td><br />
<td>e.g., <apll>2.5</apll> as a shorthand for <apll>2&frac12;</apll> or <apll>2+5÷10</apll>.</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<tr><br />
<td><b>Base</b>, <b>Euler</b>, <b>Pi</b>, <b>Gamma</b>, and <b>Rational</b> Point Notations are extensions to the familiar <b>Decimal</b> Point Notation as well as <b>Exponential</b> Point or Scientific Notation methods of entering numeric constants. Thanks to the designers of J for these clever [http://www.jsoftware.com/help/dictionary/dcons.htm ideas].</td><br />
</tr><br />
</table><br />
<br /><br />
<br />
== Base Point Notation ==<br />
<br />
This notation makes it easy to enter numeric constants in an arbitrary base.<br />
<br />
The number to the left of the <apll><bn/></apll> is the base of the number system for the characters to the right of the <apll><pn>b</pn></apll>. The base may be represented in several ways including integers, <b>Exponential</b>, <b>Decimal</b>, <b>Euler</b>, <b>Pi</b>, <b>Gamma</b>, <b>Hypercomplex</b>, <b>Rational</b>, and <b>Variable Precision Floating</b> Point Notation, but not <b>Base</b> Point Notation.<br />
<br />
For example, <apll>1<E/>3<bn/>111</apll> is the same as <apll>1000<bn/>111</apll>.<br />
<br />
Note that the base may also be negative as in <apll>¯1<bn/>0z</apll>, fractional as in <apll>0.1<bn/>1234</apll>, or Hypercomplex as in <apll>0<pn>J</pn>1<bn/>321</apll>.<br />
<br />
The characters to the right of the <apll><pn>b</pn></apll> may range from <b>0-9</b> or <b>a-z</b> where the latter range is a way of representing numbers from <b>10-35</b> in a single character. The uppercase letters (<b>A-Z</b>) have the same values as the corresponding lowercase case letters and may be used instead of or intermixed with them.<br />
<br />
For example, <apll>10<bn/>zzZz</apll> is the same as <apll>10⊥35 35 35 35</apll>, and <apll>1<pn>r</pn>2<bn/>111</apll> is the same as <apll>0.5<bn/>111</apll> except for precision &mdash; the former is Multiple-Precision and the latter is Fixed.<br />
<br />
A decimal point may appear anywhere in the characters to the right of the <apll><bn/></apll> to indicate that the characters to its right represent the fractional part of the number in the given base.<br />
<br />
Finally, the characters to the right of the <apll><bn/></apll> may start with a negative sign (as in <apll>2<bn/>¯101 ←→ ¯5</apll>) which negates the entire result.<br />
<br />
For example, <apll>2<bn/>111.111</apll> is <apll>(6⍴1)+.×2*2..¯3</apll> which is <apll>7.875</apll>.<br />
<br />
== Euler Point Notation ==<br />
<br />
This notation allows you to enter numeric constants that are in the form of the product of a multiplier and <apll>e</apll> (&cong; 2.718281828459045... &mdash; base of the natural logarithms) raised to an exponent, that is, <apll>Me<sup>E</sup></apll> or <apll>M×(*1)*E</apll>. The numbers to the left (multiplier) and right (exponent) of the <apll><pn>x</pn></apll> may be represented in several ways including integers, <b>Decimal</b>, <b>Exponential</b>, <b>Hypercomplex</b>, <b>Rational</b>, or <b>Variable Precision Floating</b> Point Notation, but not <b>Base</b>, <b>Euler</b>, <b>Pi</b>, or <b>Gamma</b> Point Notation.<br />
<br />
For example, <apll>1<pn>e</pn>2<pn>x</pn>1.1</apll> is the same as <apll>100<pn>x</pn>1.1</apll>, and <apll>1<pn>r</pn>2<pn>x</pn>1.1<pn>e</pn>2</apll> is the same as <apll>0.5<pn>x</pn>110</apll>.<br />
<br />
Both the multiplier and exponent may be negative and/or fractional as in <apll>¯1<pn>e</pn>2<pn>x</pn>¯3.3</apll>.<br />
<br />
== Pi Point Notation ==<br />
<br />
This notation allows you to enter numeric constants that are in the form of the product of a multiplier and <apll>&pi;</apll> (&cong; 3.141592653589793... &mdash; ratio of a circle's circumference and diameter) raised to an exponent, that is, <apll>M&pi;<sup>E</sup></apll> or <apll>M×(○1)*E</apll>. The numbers to the left (multiplier) and right (exponent) of the <apll><pn>p</pn></apll> may be represented in several ways including integers, <b>Decimal</b>, <b>Exponential</b>, <b>Hypercomplex</b>, <b>Rational</b>, or <b>Variable Precision Floating</b> Point Notation, but not <b>Base</b>, <b>Euler</b>, <b>Pi</b>, or <b>Gamma</b> Point Notation.<br />
<br />
For example, <apll>1<pn>e</pn>2<pn>p</pn>1.1</apll> is the same as <apll>100<pn>p</pn>1.1</apll>, and <apll>1<pn>r</pn>2<pn>p</pn>1.1<pn>e</pn>2</apll> is the same as <apll>0.5<pn>p</pn>110</apll>.<br />
<br />
Both the multiplier and exponent may be negative and/or fractional as in <apll>{overbar}1<pn>e</pn>2<pn>p</pn>{overbar}3.3</apll>.<br />
<br />
== Gamma Point Notation ==<br />
<br />
This notation allows you to enter numeric constants that are in the form of the product of a multiplier and <apll>&gamma;</apll> (&cong; 0.5772156649015329... &mdash; limiting difference between the harmonic series and the natural logarithm) raised to an exponent, that is, <apll>M&gamma;<sup>E</sup></apll> or <apll>M×&gamma;*E</apll>. The numbers to the left (multiplier) and right (exponent) of the <apll><pn>g</pn></apll> may be represented in several ways including integers, <b>Decimal</b>, <b>Exponential</b>, <b>Rational</b>, or <b>Variable Precision Floating</b> Point Notation, but not <b>Base</b>, <b>Euler</b>, <b>Pi</b>, or <b>Gamma</b> Point Notation.<br />
<br />
For example, <apll>1<pn>e</pn>2<pn>g</pn>1.1</apll> is the same as <apll>100<pn>g</pn>1.1</apll>, and <apll>1<pn>r</pn>2<pn>g</pn>1.1e2</apll> is the same as <apll>0.5<pn>g</pn>110</apll>.<br />
<br />
Both the multiplier and exponent may be negative and/or fractional as in <apll>{overbar}1<pn>e</pn>2<pn>g</pn>{overbar}3.3</apll>.<br />
<br />
== Hypercomplex Point Notation ==<br />
<br />
This notation allows you to enter Complex, Quaternion, and Octonion numbers in various forms such as a combination of a Real part followed by one or more Hypercomplex units (2nd, 4th, or 8th root of <apll>¯1</apll>) times the corresponding coefficient. For more details, see [http://www.sudleyplace.com/APL/Hypercomplex%20Notation%20in%20APL.pdf Hypercomplex Notation in APL].<br />
<br />
== Ball Arithmetic Point Notation ==<br />
<br />
This notation allows you to enter '''Ball Arithmetic''' point values. A Ball consists of a '''Midpoint''' and a '''Radius'''. The two values are separated by a plus-or-minus sign (<apll><pn>±</pn></apll>) as in <apll>2.3<pn>±</pn>1<pn>E</pn>¯9</apll>. If the Radius is zero, it may be omitted.<br />
<br />
Ball Arithmetic numbers may also be used as a lefthand part of <b>Base</b>, and any part of <b>Euler</b>, <b>Pi</b>, <b>Gamma</b>, or <b>Hypercomplex</b> Point Notations. For more information, see [[Ball Arithmetic]].<br />
<br />
== Rational Point Notation ==<br />
<br />
This notation allows you to enter fractions as rational numbers and have them be retained as rational numbers. Rational numbers (using the <apll><pn>r</pn></apll> infix separator only, not the <apll><pn>x</pn></apll> suffix) may also be used as a lefthand part of <b>Base</b>, and either part of <b>Euler</b>, <b>Pi</b>, or <b>Gamma</b> Point Notations. For more information, see [[Rational and VFP Numbers|Rational Numbers]]. This notation also accepts strings that contain '''Decimal''' and/or '''Exponential''' point notation such as <apll>0.5<pn>x</pn></apll>, <apll>0.5<pn>r</pn>3</apll>, <apll>1<pn>E</pn>¯3<pn>r</pn>1.5</apll>, etc. and represents them as a Rational number.<br />
<br />
== Variable-Precision Floating Point Notation ==<br />
<br />
This notation allows you to enter '''Decimal''' and '''Exponential''' point values as variable-precision floating point numbers. For example, <apll>2.3<pn>v</pn></apll> or <apll>2<pn>E</pn>¯3<pn>v</pn></apll>.<br />
<br />
In this form, the bits of precision of the number is specified by the value of <apll>⎕FPC</apll> at the time the number is fixed. Alternatively, the suffix <apll><pn>v</pn></apll> may be followed by an unsigned integer (<apll>≥53</apll>) to specify the number of bits of precision of the number, overriding the value of <apll>⎕FPC</apll>. For example <apll>2.3<pn>v</pn>64</apll> is a shorthand for <apll>2.3</apll> as a VFP number with <apll>64</apll> bits of precision.<br />
<br />
VFP numbers (using the <apll><pn>v</pn></apll> suffix) may also be used as a lefthand part of <b>Base</b>, and either part of <b>Euler</b>, <b>Pi</b>, or <b>Gamma</b> Point Notations. For more information, see [[Rational and VFP Numbers|Variable-precision Floating Point (VFP) Numbers]].<br />
<br />
== Exponential Point Notation ==<br />
<br />
This familiar notation (sometimes called scientific notation) allows you to enter numeric constants that are in the form of the product of a multiplier and a (possibly negative) power of 10. Exponential numbers (using either the <apll><pn>e</pn></apll> or <apll><pn>E</pn></apll> infix separator) may also be used as a lefthand par of <b>Base</b>, and either part of <b>Euler</b>, <b>Pi</b>, or <b>Gamma</b>, <b>Hypercomplex</b> Point Notations.<br />
<br />
For example, <apll>¯1.1<pn>e</pn>2</apll> is the same as <apll>¯110.0</apll>, and <apll>1.1<pn>E</pn>¯6</apll> is the same as <apll>0.0000011</apll>.<br />
<br />
== Decimal Point Notation ==<br />
<br />
This basic notation allows you to enter a decimal value with an integer part and fractional part separated by a period (<apll>.</apll>) as in <apll>2.3</apll> with an optional leading high minus sign (<apll>¯2.3</apll>) if the number is negative.<br />
<br />
== Mixed Notation ==<br />
<br />
The above notations may be combined in a single '''Point Notation String''' with the restrictions discussed above, a summary of which follows:<br />
<ul><br />
<li>The right part of '''Base''' Point Notation may '''not''' contain any of the above Point Notations except for <b>Decimal</b>.</li><br />
<li>The left part of '''Base''' Point Notation may contain any of the above Point Notations except itself.</li><br />
<li>'''Decimal''', '''Exponential''', '''Rational''', '''Variable Precision''', '''Ball''', and '''Hypercomplex''' Point Notations may appear in either or both parts of '''Euler''', '''Pi''', or '''Gamma''' Point Notations.</li><br />
<li>No two of '''Euler''', '''Pi''', or '''Gamma''' Point Notations may appear in the same Point Notation String.</li><br />
</ul><br />
<br />
In terms of '''Binding Strength''', the Notation with the highest binding strength is '''Decimal'''. That is, '''Decimal''' Point Notation numbers are constructed first. From highest to lowest binding strength, the sequence is as follows:<br />
<br />
<ul><br />
<li>7. Decimal<br />
<li>6. Exponential<br />
<li>5. Rational, Variable Precision Floating Point<br />
<li>4. Ball Arithmetic<br />
<li>3. Hypercomplex<br />
<li>2. Euler, Pi, Gamma<br />
<li>1. Base<br />
</ul><br />
<br />
Notations with the same binding strength may not be mixed (e.g., <apll>1<pn>r</pn>2<pn>v</pn></apll> is an error). Otherwise, any notation may incorporate notations with a higher binding strength but may not incorporate notations with an equal or lower binding strength.<br />
<br />
This latter case need not signal an error, but instead it might produce a different interpretation. For example,<br />
<br />
<apll>1<pn>r</pn>2<pn>p</pn>1<hc>J</hc>3</apll> is interpreted as <apll>1<pn>r</pn>2×(○1<pn>x</pn>)*1<hc>J</hc>3</apll> not as <apll>1<pn>r</pn>2<pn>p</pn>1+0<hc>J</hc>3</apll> because '''Rational''' and '''Hypercomplex''' Point Notations are constructed before '''Pi''' Point Notation is.<br />
<br />
{{Language Toolbar}}<br />
[[Category:Mouse Group Notations]]</div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=Point_Notation&diff=3291Point Notation2018-08-04T21:16:53Z<p>Sudleyplace: /* Decimal Point Notation */</p>
<hr />
<div>== Overview ==<br />
<br />
<table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td valign="baseline"><b>Base Point Notation</b>:</td><br />
<td></td><br />
<td></td><br />
<td>e.g., <apll>16<pn>b</pn>10FFFF</apll>as a shorthand for <apll>16⊥1 0 15 15 15 15 15</apll>.</td><br />
</tr><br />
<tr><br />
<td valign="baseline"><b>Euler Point Notation</b>:</td> <br />
<td></td><br />
<td></td><br />
<td>e.g., <apll>2<pn>x</pn>3</apll> as a shorthand for <apll>2∙e<sup>3</sup></apll> or <apll>2×(*1)*3</apll>.</td><br />
</tr><br />
<tr><br />
<td valign="baseline"><b>Pi Point Notation</b>:</td><br />
<td></td><br />
<td></td><br />
<td>e.g., <apll>2<pn>p</pn>3</apll> as a shorthand for <apll>2∙&pi;<sup>3</sup></apll> or <apll>2×(○1)*3</apll>.</td><br />
</tr><br />
<tr><br />
<td valign="baseline"><b>Gamma Point Notation</b>:</td><br />
<td></td><br />
<td></td><br />
<td>e.g., <apll>2<pn>g</pn>3</apll> as a shorthand for <apll>2∙&gamma;<sup>3</sup></apll> where <apll>&gamma;</apll> is the [https://en.wikipedia.org/wiki/Euler%E2%80%93Mascheroni_constant Euler-Mascheroni Constant].</td><br />
</tr><br />
<tr><br />
<td valign="baseline"><b>Hypercomplex Point Notation</b>:</td><br />
<td></td><br />
<td></td><br />
<td>e.g., <apll>2<hc>J</hc>3</apll> or <apll>2<hc>i</hc>3</apll> as a shorthand for <apll>2+3×√¯1</apll>, or <apll>2<hc>ad</hc>3</apll> (Angle in Degrees), <apll>2<hc>ar</hc>3</apll> (Angle in Radians), or <apll>2<hc>au</hc>3</apll> (Angle in Unit Normalized) all for Complex numbers, or <apll>1<hc>i</hc>2<hc>j</hc>3<hc>k</hc>4</apll> for a Quaternion number, or <apll>1<hc>i</hc>2<hc>j</hc>3<hc>k</hc>4<hc>l</hc>5<hc>ij</hc>6<hc>jk</hc>7<hc>kl</hc>8</apll> for an Octonion number.</td><br />
</tr><br />
<tr><br />
<td valign="baseline"><b>Ball Arithmetic Point Notation</b>:</td><br />
<td></td><br />
<td></td><br />
<td valign="baseline">e.g., <apll>2.3<pn>±</pn>1<pn>E</pn>¯9</apll> to indicate a Ball with a Midpoint of <apll>2.3</apll> and a Radius of <apll>1<pn>E</pn>¯9</apll>. Also, <apll>2.3<pn>±</pn></apll> is a shorthand for <apll>2.3<pn>±</pn>0</apll>.<br />
</tr><br />
<tr><br />
<td valign="baseline"><b>Rational Point Notation</b>:</td><br />
<td></td><br />
<td></td><br />
<td valign="baseline">e.g., <apll>2<pn>r</pn>3</apll> as a shorthand for <apll>2{divide}3</apll> as an infinite precision rational number, or <apll>123<pn>x</pn></apll> as a means of representing <apll>123</apll> as an infinite precision integer &mdash; the suffix <apll><pn>x</pn></apll> is actually a shorthand for <apll><pn>r</pn>1</apll>, that is, infinite precision integers are actually represented as rational numbers with a denominator of <apll>1</apll>.</td><br />
</tr><br />
<tr><br />
<td valign="baseline"><b>Variable-Precision Floating Point Notation</b>:</td><br />
<td></td><br />
<td></td><br />
<td valign="baseline">e.g., <apll>2.3<pn>v</pn></apll> as a shorthand for <apll>2.3</apll> as a variable-precision floating point number, or <apll>123<pn>v</pn></apll> as a means of representing <apll>123</apll> as a VFP number whose fractional part is zero.</td><br />
</tr><br />
<tr><br />
<td valign="baseline"><b>Exponential Point Notation</b>:</td><br />
<td></td><br />
<td></td><br />
<td>e.g., <apll>2<pn>e</pn>3</apll> or <apll>2<pn>E</pn>3</apll> as a shorthand for <apll>2&#8729;10<sup>3</sup></apll> or <apll>2×10*3</apll>.</td><br />
</tr><br />
<tr><br />
<td valign="baseline"><b>Decimal Point Notation</b>:</td><br />
<td></td><br />
<td></td><br />
<td>e.g., <apll>2.5</apll> as a shorthand for <apll>2&frac12;</apll> or <apll>2+5÷10</apll>.</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<tr><br />
<td><b>Base</b>, <b>Euler</b>, <b>Pi</b>, <b>Gamma</b>, and <b>Rational</b> Point Notations are extensions to the familiar <b>Decimal</b> Point Notation as well as <b>Exponential</b> Point or Scientific Notation methods of entering numeric constants. Thanks to the designers of J for these clever [http://www.jsoftware.com/help/dictionary/dcons.htm ideas].</td><br />
</tr><br />
</table><br />
<br /><br />
<br />
== Base Point Notation ==<br />
<br />
This notation makes it easy to enter numeric constants in an arbitrary base.<br />
<br />
The number to the left of the <apll><pn>b</pn></apll> is the base of the number system for the characters to the right of the <apll><pn>b</pn></apll>. The base may be represented in several ways including integers, <b>Exponential</b>, <b>Decimal</b>, <b>Euler</b>, <b>Pi</b>, <b>Gamma</b>, <b>Hypercomplex</b>, <b>Rational</b>, and <b>Variable Precision Floating</b> Point Notation, but not <b>Base</b> Point Notation.<br />
<br />
For example, <apll>1<pn>e</pn>3<pn>b</pn>111</apll> is the same as <apll>1000<pn>b</pn>111</apll>.<br />
<br />
Note that the base may also be negative as in <apll>¯1<pn>b</pn>0z</apll>, fractional as in <apll>0.1<pn>b</pn>1234</apll>, or Hypercomplex as in <apll>0<pn>J</pn>1<pn>b</pn>321</apll>.<br />
<br />
The characters to the right of the <apll><pn>b</pn></apll> may range from <b>0-9</b> or <b>a-z</b> where the latter range is a way of representing numbers from <b>10-35</b> in a single character. The uppercase letters (<b>A-Z</b>) have the same values as the corresponding lowercase case letters and may be used instead of or intermixed with them.<br />
<br />
For example, <apll>10<pn>b</pn>zzZz</apll> is the same as <apll>10⊥35 35 35 35</apll>, and <apll>1<pn>r</pn>2<pn>b</pn>111</apll> is the same as <apll>0.5<pn>b</pn>111</apll> except for precision &mdash; the former is Multiple-Precision and the latter is Fixed.<br />
<br />
A decimal point may appear anywhere in the characters to the right of the <apll><pn>b</pn></apll> to indicate that the characters to its right represent the fractional part of the number in the given base.<br />
<br />
For example, <apll>2<pn>b</pn>111.111</apll> is <apll>(6⍴1)+.×2*2..¯3</apll> which is <apll>7.875</apll>.<br />
<br />
== Euler Point Notation ==<br />
<br />
This notation allows you to enter numeric constants that are in the form of the product of a multiplier and <apll>e</apll> (&cong; 2.718281828459045... &mdash; base of the natural logarithms) raised to an exponent, that is, <apll>Me<sup>E</sup></apll> or <apll>M×(*1)*E</apll>. The numbers to the left (multiplier) and right (exponent) of the <apll><pn>x</pn></apll> may be represented in several ways including integers, <b>Decimal</b>, <b>Exponential</b>, <b>Hypercomplex</b>, <b>Rational</b>, or <b>Variable Precision Floating</b> Point Notation, but not <b>Base</b>, <b>Euler</b>, <b>Pi</b>, or <b>Gamma</b> Point Notation.<br />
<br />
For example, <apll>1<pn>e</pn>2<pn>x</pn>1.1</apll> is the same as <apll>100<pn>x</pn>1.1</apll>, and <apll>1<pn>r</pn>2<pn>x</pn>1.1<pn>e</pn>2</apll> is the same as <apll>0.5<pn>x</pn>110</apll>.<br />
<br />
Both the multiplier and exponent may be negative and/or fractional as in <apll>¯1<pn>e</pn>2<pn>x</pn>¯3.3</apll>.<br />
<br />
== Pi Point Notation ==<br />
<br />
This notation allows you to enter numeric constants that are in the form of the product of a multiplier and <apll>&pi;</apll> (&cong; 3.141592653589793... &mdash; ratio of a circle's circumference and diameter) raised to an exponent, that is, <apll>M&pi;<sup>E</sup></apll> or <apll>M×(○1)*E</apll>. The numbers to the left (multiplier) and right (exponent) of the <apll><pn>p</pn></apll> may be represented in several ways including integers, <b>Decimal</b>, <b>Exponential</b>, <b>Hypercomplex</b>, <b>Rational</b>, or <b>Variable Precision Floating</b> Point Notation, but not <b>Base</b>, <b>Euler</b>, <b>Pi</b>, or <b>Gamma</b> Point Notation.<br />
<br />
For example, <apll>1<pn>e</pn>2<pn>p</pn>1.1</apll> is the same as <apll>100<pn>p</pn>1.1</apll>, and <apll>1<pn>r</pn>2<pn>p</pn>1.1<pn>e</pn>2</apll> is the same as <apll>0.5<pn>p</pn>110</apll>.<br />
<br />
Both the multiplier and exponent may be negative and/or fractional as in <apll>{overbar}1<pn>e</pn>2<pn>p</pn>{overbar}3.3</apll>.<br />
<br />
== Gamma Point Notation ==<br />
<br />
This notation allows you to enter numeric constants that are in the form of the product of a multiplier and <apll>&gamma;</apll> (&cong; 0.5772156649015329... &mdash; limiting difference between the harmonic series and the natural logarithm) raised to an exponent, that is, <apll>M&gamma;<sup>E</sup></apll> or <apll>M×&gamma;*E</apll>. The numbers to the left (multiplier) and right (exponent) of the <apll><pn>g</pn></apll> may be represented in several ways including integers, <b>Decimal</b>, <b>Exponential</b>, <b>Rational</b>, or <b>Variable Precision Floating</b> Point Notation, but not <b>Base</b>, <b>Euler</b>, <b>Pi</b>, or <b>Gamma</b> Point Notation.<br />
<br />
For example, <apll>1<pn>e</pn>2<pn>g</pn>1.1</apll> is the same as <apll>100<pn>g</pn>1.1</apll>, and <apll>1<pn>r</pn>2<pn>g</pn>1.1e2</apll> is the same as <apll>0.5<pn>g</pn>110</apll>.<br />
<br />
Both the multiplier and exponent may be negative and/or fractional as in <apll>{overbar}1<pn>e</pn>2<pn>g</pn>{overbar}3.3</apll>.<br />
<br />
== Hypercomplex Point Notation ==<br />
<br />
This notation allows you to enter Complex, Quaternion, and Octonion numbers in various forms such as a combination of a Real part followed by one or more Hypercomplex units (2nd, 4th, or 8th root of <apll>¯1</apll>) times the corresponding coefficient. For more details, see [http://www.sudleyplace.com/APL/Hypercomplex%20Notation%20in%20APL.pdf Hypercomplex Notation in APL].<br />
<br />
== Ball Arithmetic Point Notation ==<br />
<br />
This notation allows you to enter '''Ball Arithmetic''' point values. A Ball consists of a '''Midpoint''' and a '''Radius'''. The two values are separated by a plus-or-minus sign (<apll><pn>±</pn></apll>) as in <apll>2.3<pn>±</pn>1<pn>E</pn>¯9</apll>. If the Radius is zero, it may be omitted.<br />
<br />
Ball Arithmetic numbers may also be used as a lefthand part of <b>Base</b>, and any part of <b>Euler</b>, <b>Pi</b>, <b>Gamma</b>, or <b>Hypercomplex</b> Point Notations. For more information, see [[Ball Arithmetic]].<br />
<br />
== Rational Point Notation ==<br />
<br />
This notation allows you to enter fractions as rational numbers and have them be retained as rational numbers. Rational numbers (using the <apll><pn>r</pn></apll> infix separator only, not the <apll><pn>x</pn></apll> suffix) may also be used as a lefthand part of <b>Base</b>, and either part of <b>Euler</b>, <b>Pi</b>, or <b>Gamma</b> Point Notations. For more information, see [[Rational and VFP Numbers|Rational Numbers]]. This notation also accepts strings that contain '''Decimal''' and/or '''Exponential''' point notation such as <apll>0.5<pn>x</pn></apll>, <apll>0.5<pn>r</pn>3</apll>, <apll>1<pn>E</pn>¯3<pn>r</pn>1.5</apll>, etc. and represents them as a Rational number.<br />
<br />
== Variable-Precision Floating Point Notation ==<br />
<br />
This notation allows you to enter '''Decimal''' and '''Exponential''' point values as variable-precision floating point numbers. For example, <apll>2.3<pn>v</pn></apll> or <apll>2<pn>E</pn>¯3<pn>v</pn></apll>.<br />
<br />
In this form, the bits of precision of the number is specified by the value of <apll>⎕FPC</apll> at the time the number is fixed. Alternatively, the suffix <apll><pn>v</pn></apll> may be followed by an unsigned integer (<apll>≥53</apll>) to specify the number of bits of precision of the number, overriding the value of <apll>⎕FPC</apll>. For example <apll>2.3<pn>v</pn>64</apll> is a shorthand for <apll>2.3</apll> as a VFP number with <apll>64</apll> bits of precision.<br />
<br />
VFP numbers (using the <apll><pn>v</pn></apll> suffix) may also be used as a lefthand part of <b>Base</b>, and either part of <b>Euler</b>, <b>Pi</b>, or <b>Gamma</b> Point Notations. For more information, see [[Rational and VFP Numbers|Variable-precision Floating Point (VFP) Numbers]].<br />
<br />
== Exponential Point Notation ==<br />
<br />
This familiar notation (sometimes called scientific notation) allows you to enter numeric constants that are in the form of the product of a multiplier and a (possibly negative) power of 10. Exponential numbers (using either the <apll><pn>e</pn></apll> or <apll><pn>E</pn></apll> infix separator) may also be used as a lefthand par of <b>Base</b>, and either part of <b>Euler</b>, <b>Pi</b>, or <b>Gamma</b>, <b>Hypercomplex</b> Point Notations.<br />
<br />
For example, <apll>¯1.1<pn>e</pn>2</apll> is the same as <apll>¯110.0</apll>, and <apll>1.1<pn>E</pn>¯6</apll> is the same as <apll>0.0000011</apll>.<br />
<br />
== Decimal Point Notation ==<br />
<br />
This basic notation allows you to enter a decimal value with an integer part and fractional part separated by a period (<apll>.</apll>) as in <apll>2.3</apll> with an optional leading high minus sign (<apll>¯2.3</apll>) if the number is negative.<br />
<br />
== Mixed Notation ==<br />
<br />
The above notations may be combined in a single '''Point Notation String''' with the restrictions discussed above, a summary of which follows:<br />
<ul><br />
<li>The right part of '''Base''' Point Notation may '''not''' contain any of the above Point Notations except for <b>Decimal</b>.</li><br />
<li>The left part of '''Base''' Point Notation may contain any of the above Point Notations except itself.</li><br />
<li>'''Decimal''', '''Exponential''', '''Rational''', '''Variable Precision''', '''Ball''', and '''Hypercomplex''' Point Notations may appear in either or both parts of '''Euler''', '''Pi''', or '''Gamma''' Point Notations.</li><br />
<li>No two of '''Euler''', '''Pi''', or '''Gamma''' Point Notations may appear in the same Point Notation String.</li><br />
</ul><br />
<br />
In terms of '''Binding Strength''', the Notation with the highest binding strength is '''Decimal'''. That is, '''Decimal''' Point Notation numbers are constructed first. From highest to lowest binding strength, the sequence is as follows:<br />
<br />
<ul><br />
<li>7. Decimal<br />
<li>6. Exponential<br />
<li>5. Rational, Variable Precision Floating Point<br />
<li>4. Ball Arithmetic<br />
<li>3. Hypercomplex<br />
<li>2. Euler, Pi, Gamma<br />
<li>1. Base<br />
</ul><br />
<br />
Notations with the same binding strength may not be mixed (e.g., <apll>1<pn>r</pn>2<pn>v</pn></apll> is an error). Otherwise, any notation may incorporate notations with a higher binding strength but may not incorporate notations with an equal or lower binding strength.<br />
<br />
This latter case need not signal an error, but instead it might produce a different interpretation. For example,<br />
<br />
<apll>1<pn>r</pn>2<pn>p</pn>1<hc>J</hc>3</apll> is interpreted as <apll>1<pn>r</pn>2×(○1<pn>x</pn>)*1<hc>J</hc>3</apll> not as <apll>1<pn>r</pn>2<pn>p</pn>1+0<hc>J</hc>3</apll> because '''Rational''' and '''Hypercomplex''' Point Notations are constructed before '''Pi''' Point Notation is.<br />
<br />
{{Language Toolbar}}<br />
[[Category:Mouse Group Notations]]</div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=System_Variable_FEATURE&diff=3271System Variable FEATURE2018-08-02T10:04:08Z<p>Sudleyplace: </p>
<hr />
<div><h1><aplxx>⎕FEATURE</aplxx> - Feature Control</h1><br />
{{BoxStart|<apll>Z←⎕FEATURE</apll><br />
| returns the current value of the Feature Control vector}}<br />
{{BoxEnd|<apll>Z</apll> is an integer vector whose elements each control a separate experimental Feature of the system.}}<br />
<br /><br />
{| border="1" cellpadding="5" cellspacing="0" rules="none" summary=""<br />
|| <apll>⎕FEATURE←R</apll> || sets all of the values of the Feature Control Vector to <apll>R</apll>.<br />
|-<br />
| valign="top" |<apll>⎕FEAURE←⍬</apll> || sets all of the values of the Feature Control vector to their system default state.<br />
|-<br />
|| <apll>⎕FEATURE[L]←R</apll> || sets the value(s) of the Feature Control vector indexed by <apll>L</apll> to <apll>R</apll> &mdash; a <apll>1</apll> in <apll>R</apll> enables the feature, <apll>0</apll> disables it.<br />
|-<br />
|}<br />
<br />
<br />
This system variable allows the user to enable or disable certain experimental features &mdash; the initial setting is for all such features to be disabled. The features controlled are as follows:<br />
<br />
{| border="1" cellpadding="5" cellspacing="0" rules="all" summary=""<br />
||<apll>[1]</apll> || Allow negative indices<br />
|-<br />
||<apll>[2]</apll> || Allow <apll>¯0</apll><br />
|-<br />
||<apll>[3]</apll> || User Hurwitz's Floor function instead of McDonnell's<br />
|-<br />
||<apll>[4]</apll> || Allow NaNs (NaN = Not-a-Number)<br />
|-<br />
||<apll>[5]</apll> || Use APL2's definition of Inner Product<br />
|}<br />
<br />
For example,<br />
<ul><br />
<li>With the first feature enabled, in origin-1, the index <apll>1</apll> refers to the first element in a vector and <apll>0</apll> refers to the last element:<br />
<br />
<apll><pre><br />
⎕FEATURE[1]←1<br />
a←'abcdef'<br />
a[0 1 2]<br />
fab<br />
a[¯2 ¯1 0 1 2]<br />
defab<br />
⍳¯3<br />
¯2 ¯1 0<br />
</pre></apll><br />
<br />
When enabled, the first feature affects all contexts sensitive to the Index Origin, such as the <apll>L</apll> in &nbsp; <apll>R[L]</apll>, &nbsp; <apll>R[L]←A</apll>, &nbsp; <apll>R[L]f←A</apll>, &nbsp; <apll>L⌷R</apll>, &nbsp; <apll>L⍉R</apll>, &nbsp; and &nbsp; <apll>L⊃R</apll>.<br /><br /></li><br />
<br />
<li>With the second feature disabled and then enabled:<br />
<br />
<apll><pre><br />
⎕FEATURE[2]←0<br />
÷∞ ¯∞<br />
0 0 <br />
÷÷∞ ¯∞<br />
∞ ∞<br />
⎕FEATURE[2]←1<br />
÷∞ ¯∞<br />
0 ¯0 <br />
÷÷∞ ¯∞<br />
∞ ¯∞<br />
</pre></apll><br />
<br />
Because <apll>¯0</apll> can not stored as a 64-bit Integer, this feature has a drawback of occasionally forcing a type promotion from Integer to Floating Point. For example, if <apll>R</apll> is an Integer array with <apll>0∊R</apll>, then an expression such as <apll>-R</apll> can no longer be stored as an Integer array, and must be promoted to Floating Point.<br />
<br /></li><br />
<br />
<li>With the third feature disabled and then enabled:<br />
<br />
<apll><pre><br />
a←0.5<hc>J</hc>¯0.5<br />
⎕FEATURE[3]←0 ⋄ ⌊a<br />
1<hc>J</hc>¯1 <br />
⎕FEATURE[3]←1 ⋄ ⌊a<br />
0<hc>J</hc>0<br />
</pre></apll><br />
<br />
The industry standard definition of the Floor function on Complex numbers is McDonnell's. However, McDonnell's Floor function isn't defined on Quaternions, but Hurwitz's is:<br />
<br />
<apll><pre><br />
a←<1 3 5 7÷2<br />
⎕FEATURE[3]←0 ⋄ ⌊a<br />
DOMAIN ERROR<br />
⎕FEATURE[3]←0 ⋄ ⌊a<br />
∧<br />
⎕FEATURE[3]←1 ⋄ ⌊a<br />
0<hc>i</hc>1<hc>j</hc>2<hc>k</hc>3</pre></apll><br />
<br />
The two Floor functions return the same result for all Real numbers; they differ only on certain Complex numbers.<br />
<br />
The setting of this feature affects not only the result of the Floor function but also all other primitive functions directly or<br />
indirectly sensitive to the Floor function including Ceiling (<apll>⌈R</apll>), Residue (<apll>L|R</apll>), Greatest Common Divisor (<apll>L∨R</apll>), and Least Common Multiple (<apll>L∧R</apll>).<br />
<br />
For more details on this topic, see [http://www.sudleyplace.com/APL/Hypercomplex%20GCD%20in%20APL.pdf Hypercomplex GCD in APL].<br /><br /></li><br />
<br />
<li>With the fourth feature disabled and then enabled:<br />
<br />
<apll><pre><br />
⎕FEATURE[4]←0<br />
0*0<hc>J</hc>1<br />
DOMAIN ERROR<br />
0*0<hc>J</hc>1<br />
∧<br />
⎕FEATURE[4]←1<br />
0*0<hc>J</hc>1<br />
∅<hc>J</hc>∅</pre></apll><br />
<br />
A NaN is a special value supported by Fixed- and Multiple-precision arithmetic "representing an undefined or unrepresentable value, especially in floating-point calculations. Systematic use of NaNs was introduced by the [https://en.wikipedia.org/wiki/IEEE_floating_point IEEE 754] floating-point standard in 1985, along with the representation of other non-finite quantities like infinities"<sup>1</sup>.<br />
<br />
<br /></li><br />
<br />
<li>With the fifth feature disabled and then enabled:<br />
<br />
<apll><pre><br />
a←3 6⍴'Queue EschewAchoo '<br />
a<br />
Queue <br />
Eschew<br />
Achoo <br />
⎕FEATURE[5]←0<br />
a+.∊'aeiou'<br />
LENGTH ERROR<br />
a+.∊'aeiou'<br />
∧<br />
⎕FEATURE[5]←1<br />
a+.∊'aeiou'<br />
4 1 2 <br />
</pre></apll><br />
<br /></li><br />
</ul><br />
<br />
<h2>References</h2><br />
<br />
<sup>1</sup> [https://en.wikipedia.org/wiki/NaN Wikipedia NaN]<br />
<br />
{{System Variables}}<br />
{{Article footer}}<br />
{{stub}}</div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=Indexing&diff=3257Indexing2018-06-30T18:11:23Z<p>Sudleyplace: </p>
<hr />
<div><table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td valign="top"><apll>Z←R[L]</apll>, &nbsp;&nbsp; <apll>R[L]←A</apll>, &nbsp;&nbsp; and &nbsp;&nbsp; <apll>R[L]<i>f</i>←A</apll></td><br />
<td></td><br />
<td></td><br />
<td>are all extended to allow both <b>Reach</b> and <b>Scatter</b> indexing.</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<tr><br />
<td><apll>L</apll> is a nested array of integer scalars and/or vectors, suitable for indexing <apll>R</apll>.</td><br />
</tr><br />
<tr><br />
<td><apll>R</apll> is an arbitrary array.</td><br />
</tr><br />
<tr><br />
<td><apll>A</apll> is an arbitrary array.</td><br />
</tr><br />
<tr><br />
<td><apll><i>f</i></apll> is an arbitrary function.</td><br />
</tr><br />
<tr><br />
<td><table border="0" cellpadding="0" cellspacing="0" summary=""><br />
<tr><br />
<td><b>Reach Indexing</b>:&nbsp;&nbsp;</td><br />
<td>If <apll>L⊃R</apll> is valid, it is equivalent to <apll>⊃R[⊂L]</apll>, and</td><br />
</tr><br />
<tr><br />
<td></td><br />
<td>if <apll>L⊃¨⊂R</apll> is valid, it is equivalent to <apll>R[L]</apll></td><br />
</tr><br />
<tr><br />
<td><b>Scatter Indexing</b>:&nbsp;&nbsp;</td><br />
<td>If <apll>L⌷R</apll> is valid, it is equivalent to <apll>R[⊃∘.,/L]</apll>, and</td><br />
<tr><br />
<td></td><br />
<td>if <apll>L⌷¨⊂R</apll> is valid, it is equivalent to <apll>⊂¨R[⊂¨L]</apll></td><br />
</tr> <br />
</table><br />
</tr><br />
<tr><br />
<td>Both Reach and Scatter indexing may appear together within a single instance of <apll>R[L]</apll>, &nbsp;&nbsp; <apll>R[L]←A</apll>, &nbsp;&nbsp; and &nbsp;&nbsp; <apll>R[L]<i>f</i>←A</apll></td><br />
</tr><br />
<tr><br />
<td>These functions are sensitive to <apll>⎕IO</apll>.</td><br />
</tr><br />
</table><br />
<br /><br />
<p>For example, in origin-1</p><br />
<br />
<apll><pre><br />
V←'123'(⊂4 5)<br />
V[1 (2 ⍬ 1)]<br />
123 4<br />
M←2 2⍴(10 20) (30 40 'abc') 50 60<br />
M[(1 1)((1 2) 3)]<br />
10 20 abc</pre></apll><br />
<table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td valign="top"><apll>Z←R[L]</apll>, &nbsp;&nbsp; <apll>R[L]←A</apll>, &nbsp;&nbsp; <apll>R[L]<i>f</i>←A</apll>, &nbsp;&nbsp; <apll>L⌷[X] R</apll>, &nbsp;&nbsp; <apll>L⍉R</apll>, &nbsp;&nbsp; and &nbsp;&nbsp; <apll>L⊃R</apll></td><br />
<td></td><br />
<td></td><br />
<td>are all extended to allow negative values in <apll>L</apll>.</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<tr><br />
<td>For all but transpose, <apll>L</apll> is a nested array of integer scalars and/or vectors, suitable for indexing <apll>R</apll>; for transpose, <apll>L</apll> is an integer scalar or vector of integers, suitable for transposing <apll>R</apll>.</td><br />
</tr><br />
<tr><br />
<td>That is, if the largest allowed value for <apll>L</apll> is <apll>N</apll>, then the previous allowable range of values was <apll>⎕IO</apll> to <apll>N</apll>, inclusive. Now, the allowable range of values is <apll>1 ¯1[1]-N</apll> to <apll>N</apll>, inclusive. For example, &nbsp;&nbsp; <apll>A</apll>, &nbsp;&nbsp; <apll>A[⍳⍴A]</apll>, &nbsp;&nbsp; <apll>A[⍳-⍴A]</apll>, &nbsp;&nbsp; and even &nbsp;&nbsp; <apll>A[⍳¯1 1[?(⍴⍴A)⍴2]×⍴A]</apll> &nbsp;&nbsp; are all identical for any array <apll>A</apll> in either origin.<br />Also, &nbsp;&nbsp; <apll>A</apll>, &nbsp;&nbsp; <apll>(⍳⍴⍴A)⍉A</apll>, &nbsp;&nbsp; and &nbsp;&nbsp; <apll>(⍳-⍴⍴A)⍉A</apll> &nbsp;&nbsp; are all identical for any array <apll>A</apll> in either origin.</td><br />
</tr><br />
<tr><br />
<td><apll>R</apll> is an arbitrary array.</td><br />
</tr><br />
<tr><br />
<td><apll>A</apll> is an arbitrary array.</td><br />
</tr><br />
<tr><br />
<td>These functions are sensitive to <apll>⎕IO</apll>. Negative indexing is available only when the first element of <apll>⎕FEATURE</apll> is set to <apll>1</apll>.</td><br />
</tr><br />
</table><br />
<br /><br />
<p>For example, in origin-1</p><br />
<br />
<apll><pre><br />
⎕FEATURE[1]←1<br />
V←'123'(⊂4 5)<br />
V[¯1 (0 ⍬ ¯1)]<br />
123 4</pre></apll></div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=System_Command_ERASE&diff=3231System Command ERASE2018-04-17T16:56:46Z<p>Sudleyplace: </p>
<hr />
<div>The <apll>)ERASE</apll> command ''erases'' or ''deletes'' the named function(s) or variable(s) in the current workspace. The workspace is not changed on disk unless you )SAVE the workspace. Once a variable or function is <apll>)ERASE</apll>d it is no longer defined. Attempting to erase a non-existent function or variable returns an error message. <apll>)ERASE</apll> with no arguments has no effect; to erase everything in the workspace, use the [[System Command Clear|)CLEAR]] command to start a fresh, clear workspace.<br />
==Example==<br />
<apll><pre><br />
)vars <br />
a0 q <br />
pi←3.1415926 <br />
)fns <br />
function function2 <br />
)vars <br />
a0 pi q <br />
⎕vr 'function' <br />
∇ function <br />
[1] "this is a function" <br />
[2] <br />
∇ 2013 3 13 11 5 38 975 (UTC) <br />
⎕vr "function2" <br />
∇ function2 <br />
[1] 'This is another function' <br />
[2] <br />
∇ 2013 3 13 11 6 0 350 (UTC)<br />
)fns <br />
function function2 <br />
)vars <br />
a0 pi q <br />
)ERASE function2 pi <br />
)fns <br />
function <br />
)vars <br />
a0 q <br />
)ERASE q f <br />
NOT ERASED: f <br />
)vars <br />
a0 <br />
</pre></apll> <br />
<br><br>'''See also: [[System_Function_EX|Quad EX or ⎕EX]]'''<br />
<br><br><br />
{{Commands}}<br />
{{article footer}}</div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=System_Command_ERASE&diff=3230System Command ERASE2018-04-17T15:40:06Z<p>Sudleyplace: </p>
<hr />
<div>The ''')ERASE''' command ''erases'' or ''deletes'' the named function(s) or variable(s) in the current workspace. The workspace is not changed on disk unless you )SAVE the workspace. Once a variable or function is )ERASEd it is no longer defined. Attempting to erase a non-existent function or variable returns an error message. ''')ERASE''' with no arguments has no effect; to erase everything in the workspace, use the [[System Command Clear|)CLEAR]] command to start a fresh, clear workspace.<br />
==Example==<br />
<apll><pre><br />
)vars <br />
a0 q <br />
pi←3.1415926 <br />
)fns <br />
function function2 <br />
)vars <br />
a0 pi q <br />
⎕vr 'function' <br />
∇ function <br />
[1] "this is a function" <br />
[2] <br />
∇ 2013 3 13 11 5 38 975 (UTC) <br />
⎕vr "function2" <br />
∇ function2 <br />
[1] 'This is another function' <br />
[2] <br />
∇ 2013 3 13 11 6 0 350 (UTC)<br />
)fns <br />
function function2 <br />
)vars <br />
a0 pi q <br />
)ERASE function2 pi <br />
)fns <br />
function <br />
)vars <br />
a0 q <br />
)ERASE q f <br />
NOT ERASED: f <br />
)vars <br />
a0 <br />
</pre></apll> <br />
<br><br>'''See also: [[System_Function_EX|Quad EX or ⎕EX]]'''<br />
<br><br><br />
{{Commands}}<br />
{{article footer}}</div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=System_Command_EDIT&diff=3229System Command EDIT2018-04-17T15:31:35Z<p>Sudleyplace: </p>
<hr />
<div>The <apll>)EDIT</apll> command is used to edit an APL function. There are several forms:<br />
<apll><pre><br />
)EDIT<br />
</pre></apll><br />
and<br />
<apll><pre><br />
)EDIT function<br />
</pre></apll><br />
(or) <br />
<apll><pre><br />
)EDIT result←leftarg function rightarg;local1 local2<br />
</pre></apll><br />
where ''function'' is the name of the function to edit. If the function exists, an edit window will be opened and the function will be shown in the window. If the function does not exist, a new edit window will open with an empty function other than the function name on line 0.<br />
<br />
Function names, like variables, are case sensitive. '''PI''', '''Pi''', '''pI''', and '''pi''' are four different identifiers.<br />
<br />
If <apll>)EDIT</apll> is used with no function name specified, a new edit window will open and a blank line 0 will be presented to allow you to enter the function header. The function header can be typed in this window on line 0 (without using the prefix del (<apll>∇</apll>) symbol.) Note that to close the edit window, you type Control-E, '''do not''' place the <apll>∇</apll> symbol on the function header or use it to attempt to close the function by placing it on the last line of the function; the function editor will raise a syntax error and refuse to save the function with a warning of a SYNTAX ERROR if a <apll>∇</apll> appears in the function header; having a <apll>∇</apll> within the function results in a recursive call to the function when it is executed.<br />
<br />
The <apll>)EDIT</apll> command is treated exactly as the <apll>∇</apll> symbol, a <apll>∇</apll> used alone opens a blank window to edit a new function, <apll>∇</apll> followed by the name of a function opens a window containing the existing function for editing, or opens a new window to define the contents of the function.<br />
<br />
A new function may be defined via the <apll>)EDIT</apll> function or the <apll>∇</apll> symbol, so that<br />
<br />
<apll><pre><br />
)EDIT z←function5 r;⎕IO<br />
</pre></apll><br />
or<br />
<apll><pre><br />
∇ z←function5 r;⎕IO<br />
</pre></apll><br />
<br />
are identical. Note that arguments are ignored on the <apll>)EDIT</apll> or <apll>∇</apll> symbol if the function is already defined; if you want to change the function header of an already defined function, you must edit it directly.<br />
<br />
<br />
{{Commands}}<br />
{{Article footer}}</div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=System_Variable_FEATURE&diff=3228System Variable FEATURE2018-04-17T15:08:12Z<p>Sudleyplace: </p>
<hr />
<div><h1><aplxx>⎕FEATURE</aplxx> - Feature Control</h1><br />
{{BoxStart|<apll>Z←⎕FEATURE</apll><br />
| returns the current value of the Feature Control vector}}<br />
{{BoxEnd|<apll>Z</apll> is an integer vector whose elements each control a separate experimental Feature of the system.}}<br />
<br /><br />
{| border="1" cellpadding="5" cellspacing="0" rules="none" summary=""<br />
|| <apll>⎕FEATURE←R</apll> || sets all of the values of the Feature Control Vector to <apll>R</apll>.<br />
|-<br />
| valign="top" |<apll>⎕FEAURE←⍬</apll> || sets all of the values of the Feature Control vector to their system default state.<br />
|-<br />
|| <apll>⎕FEATURE[L]←R</apll> || sets the value(s) of the Feature Control vector indexed by <apll>L</apll> to <apll>R</apll> &mdash; a <apll>1</apll> in <apll>R</apll> enables the feature, <apll>0</apll> disables it.<br />
|-<br />
|}<br />
<br />
<br />
This system variable allows the user to enable or disable certain experimental features &mdash; the initial setting is for all such features to be disabled. The features controlled are as follows:<br />
<br />
{| border="1" cellpadding="5" cellspacing="0" rules="all" summary=""<br />
||<apll>[1]</apll> || Allow negative indices<br />
|-<br />
||<apll>[2]</apll> || Allow <apll>¯0</apll><br />
|-<br />
||<apll>[3]</apll> || User Hurwitz's Floor function instead of McDonnell's<br />
|-<br />
||<apll>[4]</apll> || Allow NaNs (NaN = Not-a-Number)<br />
|-<br />
|}<br />
<br />
For example,<br />
<ul><br />
<li>With the first feature enabled, in origin-1, the index <apll>1</apll> refers to the first element in a vector and <apll>0</apll> refers to the last element:<br />
<br />
<apll><pre><br />
⎕FEATURE[1]←1<br />
a←'abcdef'<br />
a[0 1 2]<br />
fab<br />
a[¯2 ¯1 0 1 2]<br />
defab<br />
⍳¯3<br />
¯2 ¯1 0<br />
</pre></apll><br />
<br />
When enabled, the first feature affects all contexts sensitive to the Index Origin, such as the <apll>L</apll> in &nbsp; <apll>R[L]</apll>, &nbsp; <apll>R[L]←A</apll>, &nbsp; <apll>R[L]f←A</apll>, &nbsp; <apll>L⌷R</apll>, &nbsp; <apll>L⍉R</apll>, &nbsp; and &nbsp; <apll>L⊃R</apll>.<br /><br /></li><br />
<br />
<li>With the second feature disabled and then enabled:<br />
<br />
<apll><pre><br />
⎕FEATURE[2]←0<br />
÷∞ ¯∞<br />
0 0 <br />
÷÷∞ ¯∞<br />
∞ ∞<br />
⎕FEATURE[2]←1<br />
÷∞ ¯∞<br />
0 ¯0 <br />
÷÷∞ ¯∞<br />
∞ ¯∞<br />
</pre></apll><br />
<br />
Because <apll>¯0</apll> can not stored as a 64-bit Integer, this feature has a drawback of occasionally forcing a type promotion from Integer to Floating Point. For example, if <apll>R</apll> is an Integer array with <apll>0∊R</apll>, then an expression such as <apll>-R</apll> can no longer be stored as an Integer array, and must be promoted to Floating Point.<br />
<br /></li><br />
<br />
<li>With the third feature disabled and then enabled:<br />
<br />
<apll><pre><br />
a←0.5<hc>J</hc>¯0.5<br />
⎕FEATURE[3]←0 ⋄ ⌊a<br />
1<hc>J</hc>¯1 <br />
⎕FEATURE[3]←1 ⋄ ⌊a<br />
0<hc>J</hc>0<br />
</pre></apll><br />
<br />
The industry standard definition of the Floor function on Complex numbers is McDonnell's. However, McDonnell's Floor function isn't defined on Quaternions, but Hurwitz's is:<br />
<br />
<apll><pre><br />
a←<1 3 5 7÷2<br />
⎕FEATURE[3]←0 ⋄ ⌊a<br />
DOMAIN ERROR<br />
⎕FEATURE[3]←0 ⋄ ⌊a<br />
∧<br />
⎕FEATURE[3]←1 ⋄ ⌊a<br />
0<hc>i</hc>1<hc>j</hc>2<hc>k</hc>3</pre></apll><br />
<br />
The two Floor functions return the same result for all Real numbers; they differ only on certain Complex numbers.<br />
<br />
The setting of this feature affects not only the result of the Floor function but also all other primitive functions directly or<br />
indirectly sensitive to the Floor function including Ceiling (<apll>⌈R</apll>), Residue (<apll>L|R</apll>), Greatest Common Divisor (<apll>L∨R</apll>), and Least Common Multiple (<apll>L∧R</apll>).<br />
<br />
For more details on this topic, see [http://www.sudleyplace.com/APL/Hypercomplex%20GCD%20in%20APL.pdf Hypercomplex GCD in APL].<br /><br /></li><br />
<br />
<li>With the fourth feature disabled and then enabled:<br />
<br />
<apll><pre><br />
⎕FEATURE[4]←0<br />
0*0<hc>J</hc>1<br />
DOMAIN ERROR<br />
0*0<hc>J</hc>1<br />
∧<br />
⎕FEATURE[4]←1<br />
0*0<hc>J</hc>1<br />
∅<hc>J</hc>∅</pre></apll><br />
<br />
A NaN is a special value supported by Fixed- and Multiple-precision arithmetic "representing an undefined or unrepresentable value, especially in floating-point calculations. Systematic use of NaNs was introduced by the [https://en.wikipedia.org/wiki/IEEE_floating_point IEEE 754] floating-point standard in 1985, along with the representation of other non-finite quantities like infinities"<sup>1</sup>.<br />
<br />
<br /></li><br />
</ul><br />
<br />
<h2>References</h2><br />
<br />
<sup>1</sup> [https://en.wikipedia.org/wiki/NaN Wikipedia NaN]<br />
<br />
{{System Variables}}<br />
{{Article footer}}<br />
{{stub}}</div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=System_Variable_IC&diff=3225System Variable IC2018-04-16T20:36:04Z<p>Sudleyplace: </p>
<hr />
<div><h1><aplxx>⎕IC</aplxx> - Indeterminate Control</h1><br />
{{BoxStart|<apll>Z←⎕IC</apll><br />
| returns the current value of the Indeterminate Control vector.}}<br />
{{BoxEnd|<apll>Z</apll> is an integer vector whose elements each control a separate aspect of how indeterminates are handled by the system.}}<br />
<br /><br />
{| border="1" cellpadding="5" cellspacing="0" rules="none" summary=""<br />
|| <apll>⎕IC←R</apll> || sets all of the values of the Indeterminate Control Vector to <apll>R</apll>.<br />
|-<br />
| valign="top" |<apll>⎕IC←⍬</apll> || sets all of the values of the Indeterminate Control vector to their system default state.<br />
|-<br />
|| <apll>⎕IC[L]←R</apll> || sets the value(s) of the Indeterminate Control vector indexed by <apll>L</apll> to <apll>R</apll>.<br />
|-<br />
|}<br />
<br /><br />
<p>This experimental feature attempts to collect together in one place control of various infinite and indeterminate calculations such as <apll>÷0</appl>, <apll>0÷0</apll>, and friends. The values of this multi-element vector each control a different calculation. In particular,</p><br />
<br />
<table border="0" cellpadding="5" cellspacing="0 rules="rows" summary=""><br />
<tr><br />
<th valign="top"><apll>⎕IC</apll> Index<br />(origin-0)</th><br />
<th valign="top">Indeterminate<br />or Infinite Calculation</th><br />
<th valign="top">Default<br />Result</th><br />
</tr><br />
<tr><br />
<td align="center">0</td><br />
<td align="center"><apll>÷0</apll> or <apll>L÷0</apll> for <apll>L≠0</apll></td><br />
<td align="center"><apll>∞</apll></td><br />
</tr><br />
<br />
<tr><br />
<td align="center">1</td><br />
<td align="center"><apll>⍟0</apll></td><br />
<td align="center"><apll>¯∞</apll></td><br />
</tr><br />
<br />
<tr><br />
<td align="center">2</td><br />
<td align="center"><apll>!R</apll> for integer <apll>R&lt;0</apll></td><br />
<td align="center"><apll>DOMAIN ERROR</apll></td><br />
</tr><br />
<br />
<tr><br />
<td align="center">3</td><br />
<td align="center"><apll>0×∞</apll> or <apll>∞×0</apll></td><br />
<td align="center"><apll>DOMAIN ERROR</apll></td><br />
</tr><br />
<br />
<tr><br />
<td align="center">4</td><br />
<td align="center"><apll>0ׯ∞</apll> or <apll>¯∞×0</apll></td><br />
<td align="center"><apll>DOMAIN ERROR</apll></td><br />
</tr><br />
<br />
<tr><br />
<td align="center">5</td><br />
<td align="center"><apll>0÷0</apll></td><br />
<td align="center"><apll>1</apll></td><br />
</tr><br />
<br />
<tr><br />
<td align="center">6</td><br />
<td align="center"><apll>∞÷∞</apll> (same sign)</td><br />
<td align="center"><apll>DOMAIN ERROR</apll></td><br />
</tr><br />
<br />
<tr><br />
<td align="center">7</td><br />
<td align="center"><apll>∞÷∞</apll> (different sign)</td><br />
<td align="center"><apll>DOMAIN ERROR</apll></td><br />
</tr><br />
<br />
<tr><br />
<td align="center">8</td><br />
<td align="center"><apll>∞-∞</apll> (same sign)</td><br />
<td align="center"><apll>DOMAIN ERROR</apll></td><br />
</tr><br />
<br />
<tr><br />
<td align="center">9</td><br />
<td align="center"><apll>L|∞</apll> for <apll>L&gt;0</apll></td><br />
<td align="center"><apll>DOMAIN ERROR</apll></td><br />
</tr><br />
<br />
<tr><br />
<td align="center">10</td><br />
<td align="center"><apll>L|¯∞</apll> for <apll>L&gt;0</apll></td><br />
<td align="center"><apll>DOMAIN ERROR</apll></td><br />
</tr><br />
<br />
<tr><br />
<td align="center">11</td><br />
<td align="center"><apll>L|∞</apll> for <apll>L&lt;0</apll></td><br />
<td align="center"><apll>DOMAIN ERROR</apll></td><br />
</tr><br />
<br />
<tr><br />
<td align="center">12</td><br />
<td align="center"><apll>L|¯∞</apll> for <apll>L&lt;0</apll></td><br />
<td align="center"><apll>DOMAIN ERROR</apll></td><br />
</tr><br />
<br />
<tr><br />
<td align="center">13</td><br />
<td align="center"><apll>¯∞|R</apll> for <apll>R&gt;0</apll></td><br />
<td align="center"><apll>¯∞</apll></td><br />
</tr><br />
<br />
<tr><br />
<td align="center">14</td><br />
<td align="center"><apll>∞|R</apll> for <apll>R&lt;0</apll></td><br />
<td align="center"><apll>∞</apll></td><br />
</tr><br />
<br />
<tr><br />
<td align="center">15</td><br />
<td align="center"><apll>0*0</apll></td><br />
<td align="center"><apll>1</apll></td><br />
</tr><br />
<br />
<tr><br />
<td align="center">16</td><br />
<td align="center"><apll>L*∞</apll> for <apll>L≤¯1</apll></td><br />
<td align="center"><apll>DOMAIN ERROR</apll></td><br />
</tr><br />
<br />
<tr><br />
<td align="center">17</td><br />
<td align="center"><apll>0*∞</apll></td><br />
<td align="center"><apll>0</apll></td><br />
</tr><br />
<br />
<tr><br />
<td align="center">18</td><br />
<td align="center"><apll>0*¯∞</apll></td><br />
<td align="center"><apll>∞</apll></td><br />
</tr><br />
<br />
<tr><br />
<td align="center">19</td><br />
<td align="center"><apll>±∞*0</apll></td><br />
<td align="center"><apll>DOMAIN ERROR</apll></td><br />
</tr><br />
<br />
<tr><br />
<td align="center">20</td><br />
<td align="center"><apll>L*R</apll> for <apll>L&lt;0</apll> and non-integer <apll>R</apll></td><br />
<td align="center"><apll>DOMAIN ERROR</apll></td><br />
</tr><br />
<br />
<tr><br />
<td align="center">21</td><br />
<td align="center"><apll>0⍟0</apll></td><br />
<td align="center"><apll>1</apll></td><br />
</tr><br />
<br />
<tr><br />
<td align="center">22</td><br />
<td align="center"><apll>0⍟1</apll></td><br />
<td align="center"><apll>DOMAIN ERROR</apll></td><br />
</tr><br />
<br />
<tr><br />
<td align="center">23</td><br />
<td align="center"><apll>1⍟0</apll></td><br />
<td align="center"><apll>DOMAIN ERROR</apll></td><br />
</tr><br />
<br />
<tr><br />
<td align="center">24</td><br />
<td align="center"><apll>1⍟1</apll></td><br />
<td align="center"><apll>1</apll></td><br />
</tr><br />
<br />
<tr><br />
<td align="center">25</td><br />
<td align="center"><apll>0∨±∞</apll> or <apll>±∞∨0</apll></td><br />
<td align="center"><apll>LEFT</apll></td><br />
</tr><br />
<br />
<tr><br />
<td align="center">26</td><br />
<td align="center"><apll>0∧±∞</apll> or <apll>±∞∧0</apll></td><br />
<td align="center"><apll>DOMAIN ERROR</apll></td><br />
</tr><br />
<br />
<tr><br />
<td align="center">27</td><br />
<td align="center"><apll>0⍟R</apll> for <apll>R≠0 1</apll></td><br />
<td align="center"><apll>DOMAIN ERROR</apll></td><br />
</tr><br />
<br />
<tr><br />
<td align="center">28</td><br />
<td align="center"><apll>L*¯∞</apll> for <apll>¯1 ≤ L < 0</apll></td><br />
<td align="center"><apll>DOMAIN ERROR</apll></td><br />
</tr><br />
<br />
</table><br />
<br />
<p>The values in each element of <apll>⎕IC</apll> control the result of the calculation as follows:</p><br />
<br />
<table border="0" cellpadding="5" cellspacing="0 rules="rows" summary=""><br />
<tr><br />
<th valign="top"><apll>⎕IC</apll> Value</th><br />
<th valign="top">Result</th><br />
</tr><br />
<br />
<tr><br />
<td align="center">¯1</td><br />
<td align="center"><apll>¯1</apll></td><br />
</tr><br />
<br />
<tr><br />
<td align="center">0</td><br />
<td align="center"><apll>0</apll></td><br />
</tr><br />
<br />
<tr><br />
<td align="center">1</td><br />
<td align="center"><apll>1</apll></td><br />
</tr><br />
<br />
<tr><br />
<td align="center">2</td><br />
<td align="center"><apll>DOMAIN ERROR</apll></td><br />
</tr><br />
<br />
<tr><br />
<td align="center">3</td><br />
<td align="center"><apll>∞</apll></td><br />
</tr><br />
<br />
<tr><br />
<td align="center">4</td><br />
<td align="center"><apll>¯∞</apll></td><br />
</tr><br />
<br />
<tr><br />
<td align="center">5</td><br />
<td align="center"><apll>NaN (∅)</apll></td><br />
</tr><br />
<br />
<tr><br />
<td align="center">6</td><br />
<td align="center"><apll>LEFT</apll></td><br />
</tr><br />
<br />
<tr><br />
<td align="center">7</td><br />
<td align="center"><apll>RIGHT</apll></td><br />
</tr><br />
</table><br />
<br />
<p>For example,</p><br />
<br />
<apll><pre><br />
⎕IO←0 <br />
⎕IC <br />
3 4 3 2 2 1 2 2 2 2 2 2 2 4 3 1 2 0 3 2 2 1 2 2 1 5 2 2 2 <br />
0÷0 <br />
1 <br />
⎕IC[5]←2 <br />
⎕IC <br />
3 4 3 2 2 2 2 2 2 2 2 2 2 4 3 1 2 0 3 2 2 1 2 2 1 5 2 2 2 <br />
0÷0 <br />
DOMAIN ERROR <br />
0÷0 <br />
∧ <br />
⎕IC←⍬ <br />
⎕IC <br />
3 4 3 2 2 1 2 2 2 2 2 2 2 4 3 1 2 0 3 2 2 1 2 2 1 5 2 2 2 <br />
</pre></apll><br />
<br />
To set all indeterminate results to <apll>DOMAIN ERROR</apll>, use <apll>⎕IC[]←2</apll>.<br />
<br />
==Incomplete List of Indeterminates==<br />
<br />
<p>There may be other indeterminates not covered by this feature. Please let us know if you think there are other cases that should be included.</p><br />
<br />
{{System Variables}}<br />
{{Article footer}}</div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=Variant&diff=3224Variant2018-04-16T19:16:54Z<p>Sudleyplace: </p>
<hr />
<div><table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td valign="top"><apll>Z←f⍠B R</apll> &nbsp;&nbsp; or &nbsp;&nbsp; <apll>Z←L f⍠B R</apll></td><br />
<td></td><br />
<td></td><br />
<td>evaluates <apll>f R</apll> or <apll>L f R</apll> in the context described by <apll>B</apll>.</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<tr><br />
<td><apll>L</apll> and <apll>R</apll> are arbitrary arrays conformable with <apll>f</apll>, and <apll>B</apll> is a simple scalar, simple or heterogeneous vector, or nested vector.</td><br />
</tr><br />
<tr><br />
<td><apll>f</apll> is an arbitrary function.</td><br />
</tr><br />
</table><br />
<br />
==Introduction==<br />
<br />
<p>The dyadic Variant operator creates a version of the function <apll>f</apll> with a set of properties bound and localized to it as specified by the array right operand. For example, <apll>⍳⍠0</apll> is a version of <apll>⍳</apll> that executes in origin-0 independent of the current value of <apll>⎕IO</apll>.</p><br />
<br />
<p>The array right operand to the operator may take several different forms depending upon the function left operand. In the general case, for any kind of function left operand, the right operand may specify a single property in the form of <apll>Key Val</apll>, or multiple properties in the form of <apll>(Key1 Val1) (Key2 Val2)</apll><b>&#8230;</b>, or if the left operand is a primitive function, a shorthand notation may be used as in <apll>Val</apll> or <apll>Val1 Val2</apll> <b>&#8230;</b>.</p><br />
<br />
<p>In the general case, the keys specify a property such as Index Origin as <apll>'IO'</apll> or Comparison Tolerance as <apll>'CT'</apll>, and the value part specifies a value appropriate to the property specified in the matching key. At the moment, the keys that may be used are <apll>'CT'</apll>, <apll>'DT'</apll>, <apll>'FPC'</apll>, <apll>'IO'</apll>, <apll>'LR'</apll>, and <apll>'PP'</apll> which stand for the corresponding system variable. Note that for the Variants of <apll>L×R</apll> and <apll>⌹R</apll> there are no corresponding system variables as yet.</p><br />
<br />
<p>For example:</p><br />
<br />
<apll><pre><br />
1 2 (3+1e¯9)&nbsp; 3⍳⍠(('IO' 0) ('CT' 1e¯10)) 3<br />
3<br />
1 2 (3+1e¯10) 3⍳⍠(('IO' 0) ('CT' 1e¯10)) 3<br />
2<br />
⍳⍠('IO' 0) 3 <br />
0 1 2 <br />
⍳⍠('IO' 1) 3 <br />
1 2 3<br />
⍳⍠('IO' 0) ⍠('IO' 1) 3 <br />
0 1 2 <br />
⍳⍠('IO' 1) ⍠('IO' 0) 3 <br />
1 2 3</pre></apll><br />
<br />
<p>Note that in the last two examples, the lefthand (innermost) value of <apll>⎕IO</apll> takes precedence.</p><br />
<br />
<p>If the left operand is a primitive function, the following shorthands may be used:</p><br />
<br />
<table border="1" cellpadding="5" cellspacing="0" rules="all" summary=""><br />
<tr><br />
<th width="20%">Function or<br />Operator</th><br />
<th width="5%">Right<br />Arg<br />Type</th><br />
<th width="75%">Meaning</th><br />
</tr><br />
<br />
<tr><br />
<td rowspan="2"><apll>⍳R</apll> and <apll>L⍳R</apll></td><br />
<td><i>N</i></td><br />
<td><apll>⎕IO←</apll><i>N</i></td><br />
</tr><br />
<br />
<tr><br />
<td><i>N1&nbsp;N2</i></td><br />
<td><apll>⎕IO←</apll><i>N1</i> and <apll>⎕CT←</apll><i>N2</i></td><br />
</tr><br />
<br />
<tr><br />
<td><apll>L⌷R</apll>, <apll>L⍉R</apll>, <apll>⍋R</apll>, <apll>L⍋R</apll>, <apll>⍒R</apll>, <apll>L⍒R</apll>,<br /><apll>L⊃R</apll>, <apll>⍸R</apll>, <apll>LπR</apll>, <apll>a‼R</apll></td><br />
<td><i>N</i></td><br />
<td><apll>⎕IO←</apll><i>N</i></td><br />
</tr><br />
<br />
<tr><br />
<td><apll>⍕R</apll> and <apll>L⍕R</apll></td><br />
<td><i>N</i></td><br />
<td><apll>⎕PP←</apll><i>N</i></td><br />
</tr><br />
<br />
<tr><br />
<td><apll><apll>L&lt;R</apll>, <apll>L≤R</apll>, <apll>L=R</apll>, <apll>L≠R</apll>, <apll>L≥R</apll>, <apll>L&gt;R</apll>,<br /><br />
<apll>L∊R</apll>, <apll>L≡R</apll>, <apll>L≢R</apll>, <apll>L∪R</apll>, <apll>L∩R</apll>,<br /><br />
<apll>L⊆R</apll>, <apll>L⊇R</apll>, <apll>L§R</apll>, <apll>L~R</apll>, <apll>L⍷R</apll>,<br /><br />
<apll>⌊R</apll>, <apll>⌈R</apll>, <apll>∪R</apll></td><br />
<td><i>N</i></td><br />
<td><apll>⎕CT←</apll><i>N</i></td><br />
</tr><br />
<br />
<tr><br />
<td rowspan="4"><apll>L|R</apll>, <apll>f⌻R</apll>, <apll>L f⌻R</apll>, <apll>∘⌻R</apll></td><br />
<td><i>N</i></td><br />
<td><apll>⎕CT←</apll><i>N</i></td><br />
</tr><br />
<br />
<tr><br />
<td><i>C</i></td><br />
<td><apll>⎕LR←</apll><i>C</i></td><br />
</tr><br />
<br />
<tr><br />
<td><i>N C</i><br />
<td><apll>⎕CT←</apll><i>N</i> and <apll>⎕LR←</apll><i>C</i></td><br />
</tr><br />
<br />
<tr><br />
<td><i>C N</i><br />
<td><apll>⎕CT←</apll><i>N</i> and <apll>⎕LR←</apll><i>C</i></td><br />
</tr><br />
<br />
<tr><br />
<td rowspan="4"><apll>?R</apll> and <apll>L?R</apll></td><br />
<td><i>N</i></td><br />
<td><apll>⎕IO←</apll><i>N</i></td><br />
</tr><br />
<br />
<tr><br />
<td><i>C</i></td><br />
<td><apll>⎕DT←</apll><i>C</i></td><br />
</tr><br />
<br />
<tr><br />
<td><i>N C</i><br />
<td><apll>⎕IO←</apll><i>N</i> and <apll>⎕DT←</apll><i>C</i></td><br />
</tr><br />
<br />
<tr><br />
<td><i>C N</i><br />
<td><apll>⎕IO←</apll><i>N</i> and <apll>⎕DT←</apll><i>C</i></td><br />
</tr><br />
<br />
<tr><br />
<td rowspan="2"><apll>!R</apll> ([https://en.wikipedia.org/wiki/Pochhammer_k-symbol Pochhammer k-symbol])</td><br />
<td><i>N</i></td><br />
<td>Rising (<i>N</i> &gt; 0) and Falling (<i>N</i> &lt; 0) factorial of length <apll>|</apll><i>N</i>, stepping by <apll>1</apll> in the direction of <i>N</i></td><br />
</tr><br />
<br />
<tr><br />
<td><i>N1&nbsp;N2</i></td><br />
<td>Rising (<i>N1</i> &gt; 0) and Falling (<i>N1</i> &lt; 0) factorial of length <apll>|</apll><i>N1</i>, stepping by <apll>|</apll><i>N2</i> in the direction of <i>N1</i></td><br />
</tr><br />
<br />
<tr><br />
<td><apll>⍎R</apll></td><br />
<td><i>N</i></td><br />
<td><apll>⎕FPC←</apll><i>N</i></td><br />
</tr><br />
<br />
<tr><br />
<td><apll>L÷R</apll>, <apll>L∨R</apll>, <apll>L∧R</apll>, <apll>L○R</apll>, <apll>L⊤R</apll></td><br />
<td><i>C</i></td><br />
<td><apll>⎕LR←</apll><i>C</i></td><br />
</tr><br />
<br />
<tr><br />
<td><apll>L×R</apll></td><br />
<td><i>C</i></td><br />
<td>where <i>C</i> may be either <apll>'i'</apll> or <apll>'e'</apll> for <b>I</b>nterior or <b>E</b>xterior product where the former calculates <apll>(((L×R)+R×L)÷2</apll> and the latter calculates <apll>(((L×R)-R×L)÷2</apll> and <apll>L</apll> and <apll>R</apll> are non-commutative (Quaternion or Octonion) numbers &mdash; for commutative numbers, both products are trivial.</td><br />
</tr><br />
<br />
<tr><br />
<td><apll>⌹R</apll></td><br />
<td><i>N</i></td><br />
<td>where <i>N</i> may be <apll>1</apll>, <apll>2</apll>, <apll>3</apll>, or <apll>4</apll>. <apll>R</apll> must be a square simple Real numeric matrix. If <i>N</i> is <apll>1</apll>, the result is a Complex floating point vector of the [https://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors Eigenvalues] of <apll>R</apll>. If <i>N</i> is 2, the result is a Complex floating point matrix of the [https://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors Eigenvectors] of <apll>R</apll>, one per column. If <i>N</i> is <apll>3</apll>, the result is a two-element nested vector with a Complex vector of the Eigenvalues in the first element and a Complex matrix of the Eigenvectors in the second. If <i>N</i> is <apll>4</apll>, the result is a three-element nested vector with a Complex vector of the Eigenvalues in the first element, a Complex matrix of the Eigenvectors in the second, and a Real matrix of the Schur vectors in the third.</td><br />
</tr><br />
</table><br />
<br /><br />
<br />
==Rising and Falling Factorials==<br />
<br />
<p>A falling factorial is like a normal factorial except that it subtracts the step value (by default <apll>1</apll> unless overridden) from the original number for a fixed # of iterations. That is, <apll>!6</apll> successively decrements <apll>6</apll> by <apll>1</apll> and multiplies the numbers <apll>6 5 4 3 2 1</apll> to get <apll>720</apll>. A falling factorial starting with <apll>6</apll> of length (say) <apll>3</apll> multiplies <apll>6 5 4</apll> to get <apll>120</apll>.<br />
</p><br />
<br />
<p>A rising factorial is like a falling factorial except it adds the step value (by default <apll>1</apll> unless overridden) instead of subtracting it. A rising factorial starting with <apll>6</apll> of length (say) <apll>3</apll> multiplies <apll>6 7 8</apll> to get <apll>336</apll>.<br />
</p><br />
<br />
<p>Here are some examples of the falling factorial</p><br />
<br />
<apll><pre><br />
!6 <br />
720 <br />
(!⍠¯6)6 ⍝ ×/6 5 4 3 2 1 <br />
720 <br />
(!⍠¯5)6 ⍝ ×/6 5 4 3 2 <br />
720 <br />
(!⍠¯4)6 ⍝ ×/6 5 4 3 <br />
360 <br />
(!⍠¯3)6 ⍝ ×/6 5 4 <br />
120 <br />
(!⍠¯2)6 ⍝ ×/6 5<br />
30 <br />
(!⍠¯1)6 ⍝ ×/6 <br />
6 <br />
(!⍠¯0)6 ⍝ ×/⍬ <br />
1 <br />
</pre></apll><br />
<br />
<p>and now falling by <apll>2</apll></p><br />
<br />
<apll><pre><br />
(!⍠¯6 2)6 ⍝ ×/6 4 2 0 ¯2 ¯4 <br />
0 <br />
(!⍠¯5 2)6 ⍝ ×/6 4 2 0 ¯2 <br />
0 <br />
(!⍠¯4 2)6 ⍝ ×/6 4 2 0 <br />
0 <br />
(!⍠¯3 2)6 ⍝ ×/6 4 2 <br />
48 <br />
(!⍠¯2 2)6 ⍝ ×/6 4 <br />
24 <br />
(!⍠¯1 2)6 ⍝ ×/6 <br />
6 <br />
(!⍠¯0 2)6 ⍝ ×/⍬ <br />
1 <br />
</pre></apll><br />
<br />
<p>and here are some examples of the rising factorial</p><br />
<br />
<apll><pre><br />
(!⍠6)6 ⍝ ×/6 7 8 9 10 11 <br />
332640 <br />
(!⍠5)6 ⍝ ×/6 7 8 9 10 <br />
30240 <br />
(!⍠4)6 ⍝ ×/6 7 8 9 <br />
3024 <br />
(!⍠3)6 ⍝ ×/6 7 8 <br />
336 <br />
(!⍠2)6 ⍝ ×/6 7<br />
42<br />
(!⍠1)6 ⍝ ×/6<br />
6<br />
(!⍠0)6 ⍝ ×/⍬<br />
1 <br />
</pre></apll><br />
<br />
<p>and now rising by <apll>2</apll></p><br />
<br />
<apll><pre><br />
(!⍠6 2)6 ⍝ ×/6 8 10 12 14 16 <br />
1290240 <br />
(!⍠5 2)6 ⍝ ×/6 8 10 12 14 <br />
80640 <br />
(!⍠4 2)6 ⍝ ×/6 8 10 12 <br />
5760 <br />
(!⍠3 2)6 ⍝ ×/6 8 10 <br />
480 <br />
(!⍠2 2)6 ⍝ ×/6 8 <br />
48 <br />
(!⍠1 2)6 ⍝ ×/6 <br />
6 <br />
(!⍠0 2)6 ⍝ ×/⍬ <br />
1 <br />
</pre></apll><br />
<br />
==Identities==<br />
<br />
<table border="1" cellpadding="5" cellspacing="5" rules="none" summary=""><br />
<tr><br />
<td><apll>(!⍠N)R</apll></td><br />
<td><apll>&nbsp; ←→ &nbsp;</apll></td><br />
<td><apll>(!⍠(N 1))R</apll></td><br />
</tr><br />
<br />
<tr><br />
<td><apll>(!⍠(N 0))R</apll></td><br />
<td><apll>&nbsp; ←→ &nbsp;</apll></td><br />
<td><apll>R*N</apll></td><br />
</tr><br />
<br />
<tr><br />
<td><apll>(!⍠(N1,N2))R</apll></td><br />
<td><apll>&nbsp; ←→ &nbsp;</apll></td><br />
<td><apll>(!⍠(N1,|N2))R</apll></td><br />
<td>&nbsp;&nbsp;(the sign of <apll>N2</apll> is ignored)</td><br />
</tr><br />
</table><br />
<br />
<br />
==Eigenvalues and Eigenvectors==<br />
<br />
These [https://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors concepts] from Linear Algebra and Matrix Theory define the characteristic values and vectors of the linear transformation represented by a matrix. Every square simple Real numeric matrix has Eigenvalues and Eigenvectors. To calculate these objects, use the Variant operator with a left operand of the Domino function and a right operand of an integer scalar according to the following table:<br />
<br />
<br />
{| border="1" cellpadding="5" cellspacing="5" rules="all" summary="" style=""border:1px solid black;"<br />
|<apll>Z←(⌹⍠1) R</apll>||<apll>Z</apll> is a Complex floating point vector of the Eigenvalues of <apll>R</apll><br />
|-<br />
|<apll>Z←(⌹⍠2) R</apll>||<apll>Z</apll> is a Complex floating point matrix of the Eigenvectors of <apll>R</apll>, one per column<br />
|-<br />
|<apll>Z←(⌹⍠3) R</apll>||<apll>Z</apll> is a two-element nested vector with a Complex floating point vector of the Eigenvalues in the first element and a Complex floating point matrix of the Eigenvectors in the second<br />
|-<br />
|<apll>Z←(⌹⍠4) R</apll>||<apll>Z</apll> is a three-element nested vector with a Complex floating point vector of the Eigenvalues in the first element, a Complex floating point matrix of the Eigenvectors in the second, and a Real matrix of the Schur vectors in the third<br />
|}<br />
<br />
<br />
For example, Eigenvalues and Eigenvectors can be used to calculate the factorial of a matrix:<br />
<br />
<apll><pre><br />
&ensp; M←2 2⍴1 3 2 1<br />
&ensp; M<br />
&ensp; 1 3<br />
&ensp; 2 1<br />
&ensp; MatFact←{(Eval Evec)←(⌹⍠3) ⍵<br />
<span style="color:blue;">➥</span>⋄ Diag←∘⌻!Eval ⍝ Factorial of Eigenvalues on diagonal<br />
<span style="color:blue;">➥</span>⋄ Evec+.×Diag+.×⌹Evec}<br />
&ensp; MatFact M<br />
&ensp; 3.6274 8.8423<br />
&ensp; 5.8949 3.6274<br />
</pre></apll><br />
<br />
Note that if we delete the Shriek function in <apll>MatFact</apll>, the result is the original matrix argument.<br />
<br />
In turn, the function <apll>MatFact</apll> can be used to calculate the Factorial of a HyperComplex number:<br />
<br />
<apll><pre><br />
&ensp; HyperFact←{M←∘⌻⍵ ⍝ Matrix representation of a HyperComplex number<br />
<span style="color:blue;">➥</span>⋄ ⎕IO←1 ⋄ <9○1⌷[2] MatFact M ⍝ Factorial ...<br />
<span style="color:blue;">➥</span>}<br />
&ensp; HyperFact 1i2<br />
&ensp; 0.11229J0.32361<br />
&ensp; !1i2<br />
&ensp; 0.11229J0.32361<br />
</pre></apll><br />
<br />
where the latter expression uses the Gnu Scientific Library Complex number routines to calculate the Factorial of a Complex number.<br />
<br />
In a similar manner, using the appropriate <apll>4×4</apll> matrix representation of a Quaternion, its Factorial can be calculated which is the algorithm used in the implementation:<br />
<br />
<apll><pre><br />
&ensp; HyperFact <⍳4<br />
&ensp; 0.0060975i¯0.0010787j¯0.001618k¯0.0021573<br />
&ensp; !<⍳4<br />
&ensp; 0.0060975i¯0.0010787j¯0.001618k¯0.0021573<br />
</pre></apll><br />
<br />
{{Language Toolbar}}</div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=System_Variable_IO&diff=3221System Variable IO2018-04-16T17:50:45Z<p>Sudleyplace: </p>
<hr />
<div><h1><aplxx>⎕IO</aplxx> - Index Origin</h1><br />
{{BoxStart|<apll>Z←⎕IO</apll><br />
| returns the current value of the Index Origin. }}<br />
{{BoxEnd|<apll>Z</apll> is an integer scalar containing the current value of <apll>⎕IO</apll>. This is the lowest value of an array subscript, and is either <apll>1</apll> or <apll>0</apll>.}}<br/><br />
<br />
{| border="1" cellpadding="5" cellspacing="0" rules="none" summary=""<br />
|| <apll>⎕IO←0</apll> || sets the lowest subscript of an array to <apll>0</apll><br />
|-<br />
| valign="top" |<apll>⎕IO←1</apll> || sets the lowest subscript of an array to <apll>1</apll><br />
|-<br />
|}<br />
<br /><br />
<apll>⎕IO</apll> determines the lowest subscript for arrays. The default is <apll>1</apll>, but can be changed to <apll>0</apll>. If an attempt is made to set <apll>⎕IO</apll> to a value higher than <apll>1</apll>, it is set to <apll>1</apll>. If an attempt is made to set <apll>⎕IO</apll> to a value lower than <apll>0</apll>, it is set to <apll>0</apll>. Setting <apll>⎕IO</apll> to anything other than a number causes a <apll>DOMAIN ERROR</apll>. <br />
<br />
<apll><pre><br />
⎕IO ⍝ default ⎕IO is 1 in a clear workspace<br />
1<br />
⍳5 ⍝ iota 5<br />
1 2 3 4 5 <br />
<br />
⎕IO←0 ⍝ Set index origin ⎕IO to 0 <br />
<br />
⍳5 ⍝ iota 5 again but compare the results just below to just above<br />
0 1 2 3 4<br />
</pre></apll><br />
<br />
{{System Variables}}<br />
{{Article footer}}</div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=Rational_and_VFP_Numbers&diff=3188Rational and VFP Numbers2018-04-16T00:57:05Z<p>Sudleyplace: </p>
<hr />
<div>===Introduction===<br />
<br />
<p><b>Rational numbers</b> complement the existing 64-bit integer datatype to provide infinite precision (or <apll>WS FULL</apll>) at the cost of some performance. Similarly, <b>Variable-precision Floating Point</b> (VFP) numbers complement the existing 64-bit floating point (IEEE-754) datatype to provide more precision (as much as the user cares to specify) again with some cost in performance.</p><br />
<br />
<p>There is no separate datatype for infinite precision Integers. Instead, they are represented as a special case of rational numbers. In the discussion below, the phrase <b>rational integer</b> means a rational number whose denominator is one.</p><br />
<br />
<p class="note">Throughout this discussion the similarity between integer and rational numbers as well as floating point and VFP numbers will become apparent.</p><br />
<br />
===Rationale===<br />
<br />
<p>Simply put: precision. If the 53 bits of precision in the floating point result of, say, <apll>2÷3</apll> is not enough, you now have two more choices: one as an exact number, and one as a binary floating point number with as much precision as you care to specify.</p><br />
<br />
<p>For example,</p><br />
<br />
<apll><pre><br />
⎕PP←60 ⋄ ⎕FPC←512 <br />
2÷3 <br />
0.6666666666666666 <br />
2÷3<pn>x</pn><br />
2<pn>r</pn>3 <br />
2÷3<pn>v</pn><br />
0.666666666666666666666666666666666666666666666666666666666667 <br />
2*200 <br />
1.6069380442589903<pn>E</pn>60 <br />
2*200<pn>x</pn> <br />
1606938044258990275541962092341162602522202993782792835301376 <br />
○1 <br />
3.141592653589793 <br />
○1<pn>v</pn> <br />
3.14159265358979323846264338327950288419716939937510582097494</pre></apll><br />
<br />
===Constants===<br />
<br />
<p>Rational constants may be entered by suffixing an integer constant with an <apll><pn>x</pn></apll> (for a rational integer) or separating the numerator and denominator with an <apll><pn>r</pn></apll> (for a rational number) as follows:</p><br />
<br />
* <apll>123<pn>x</pn></apll> for the constant <apll>123</apll> (the suffix <apll><pn>x</pn></apll> is but a shorthand for <apll><pn>r</pn>1</apll>)<br />
* <apll>123<pn>r</pn>4567</apll> for the constant <apll>123÷4567</apll><br />
<br />
<p>VFP constants may be entered by suffixing the integer or floating point constant with a <apll><pn>v</pn></apll> as follows:</p><br />
<br />
* <apll>123<pn>v</pn></apll> for the constant <apll>123</apll><br />
* <apll>123.4567<pn>v</pn></apll> for the constant <apll>123.4567</apll><br />
* <apll>123.4567e3<pn>v</pn></apll> for the constant <apll>123.4567<pn>E</pn>3</apll><br />
<br />
<p>The above formats for constants (except for the suffix <apll><pn>x</pn></apll>) may be used in other constants such as <apll>1<pn>r</pn>4<pn>p</pn>2</apll> to generate a shorter and more accurate value for <apll>π<sup>2</sup>/4</apll> than, say, <apll>((○1)*2)÷4</apll>.</p><br />
<br />
===Precision===<br />
<br />
<p>Rational numbers have <b>infinite precision</b>. They are stored with a separate numerator and denominator, both of which are exact numbers in the sense that their size (and hence precision) grows limited only by the available workspace.</p><br />
<br />
<p>VFP numbers have <b>user-controlled variable precision</b>, and each number may have a different precision. The default precision at startup is controlled by the value of the system variable <apll>⎕FPC</apll>. The system default of this value is <apll>128</apll> in units of bits of precision of the mantissa (the digits) of the number, not counting the exponent (which is of fixed size). The current precision may be changed as needed by assigning a new value to the system variable. All newly created VFP numbers will have the new precision – the precision of VFP numbers already present in the workspace does not change.</p><br />
<br />
<p>Generally, precision is set once for a particular application and unchanged thereafter. Although not recommended, it is possible to mix VFP numbers of different precisions in a single array – presumably you <b>really</b> know what you are doing. The system function <apll>0 ⎕DR</apll> may be used to display an array's precision(s).</p><br />
<br />
===Datatype Propagation===<br />
<br />
<p>Generally, the datatype of constants propagates through a calculation. That is, if you start with a rational number and don't calculate with irrational or transcendental functions, you'll end up with a rational result, and if you start with a VFP number, you'll end up with a VFP result.</p><br />
<br />
<p>An example from the programming problems site [http://projecteuler.net/ ProjectEuler.net] illustrates this point. [http://projecteuler.net/problem=48 Problem #48] asks what are the low-order ten digits of the sum of the first thousand instances of N<sup>N</sup>?</p><br />
<br />
<p>The obvious expression <apll>¯10↑⍕+/*⍨⍳1000</apll>, at first sight, seems to solve the problem until you realize that it quickly runs afoul of the limited precision of 64-bit integer and floating point numbers. Clearly, this is a problem for the infinite precision of rational integers.</p><br />
<br />
<p>As <apll>⍳1000</apll> generates the first thousand integers as an integer datatype (actually an Arithmetic Progression Array), <apll>⍳1000<pn>x</pn></apll> generates the same values as rational integers. Next, <apll>*⍨⍳1000<pn>x</pn></apll> generates the first thousand instances of N<sup>N</sup> as exact rational integers, and unlike its integer counterpart, there is no overflow to floating point, just an increase in precision (as well as space used in the workspace). Then, <apll>+/*⍨⍳1000<pn>x</pn></apll> sums them into a single 3001-digit rational integer, and finally <apll>¯10↑⍕+/*⍨⍳1000<pn>x</pn></apll> converts the large integer to characters and extracts the low-order ten digits &mdash; <apll>9110846700</apll> &mdash; all in a small number of milliseconds.</p><br />
<br />
<p>Note how we started with an obvious expression that failed because of its limited precision, and made a single change to suffix the constant <apll>1000</apll> with an <apll><pn>x</pn></apll> to convert it to a rational integer which then propagates through the calculation with infinite precision to yield the correct result.</p><br />
<br />
===Display===<br />
<br />
<p>Rational integers are displayed as an integer with no special adornment; rational non-integers are displayed as a numerator and denominator separated by an <apll><pn>r</pn></apll> as in <apll>34<pn>r</pn>9</apll>. As with the integer datatype, the numerator and denominator of a rational number are displayed exactly, unaffected by the current setting for Printing Precision (<apll>⎕PP</apll>).</p><br />
<br /><br />
<apll><pre><br />
!40 <br />
8.159152832478977<pn>E</pn>47 <br />
!40<pn>x</pn><br />
815915283247897734345611269596115894272000000000 <br />
+\÷⍳10<pn>x</pn><br />
1 3<pn>r</pn>2 11<pn>r</pn>6 25<pn>r</pn>12 137<pn>r</pn>60 49<pn>r</pn>20 363<pn>r</pn>140 761<pn>r</pn>280 7129<pn>r</pn>2520 7381<pn>r</pn>2520 <br />
</pre></apll><br />
<br />
<p>VFP numbers are displayed as decimal numbers to the precision inherent in the number or <apll>⎕PP</apll>, whichever is smaller, just as floating point numbers are displayed. For example,</p><br />
<br />
<apll><pre><br />
⎕PP←100 <br />
⎕FPC←64 <br />
○1 <br />
3.141592653589793 <br />
○1<pn>x</pn><br />
3.14159265358979323851<br />
⎕FPC←128 <br />
○1<pn>x</pn><br />
3.141592653589793238462643383279502884195</pre></apll> <br />
<br />
<p>where both of the above displays were limited by the precision of the number, not <apll>⎕PP</apll>.</p><br />
<br />
<p>However, the first of the following displays <b>is</b> limited by <apll>⎕PP</apll>:</p><br />
<br />
<apll><pre><br />
⎕FPC←128 <br />
⎕PP←20 <br />
!40<pn>v</pn><br />
81591528324789773435____________________________ <br />
⎕PP←80 <br />
!40<pn>v</pn><br />
8159152832478977343456112695961158942720________</pre></apll> <br />
<br />
<p>In the last display, the current setting of Printing Precision is large enough, but the current setting of the Floating Point Control (<apll>⎕FPC</apll>) whose value is in bits is too small, so the display is truncated.</p><br />
<br />
===Formatted Display===<br />
<br />
<p>The system function <apll>⎕FMT</apll> has been enhanced to allow formatting of rational numbers via the (new) <apll>R</apll>-format specifier. For example,</p><br />
<br />
<apll><pre><br />
'R4.2' ⎕FMT ∘.÷⍨⍳6<pn>x</pn><br />
1 1<pn>r</pn>2 1<pn>r</pn>3 1<pn>r</pn>4 1<pn>r</pn>5 1<pn>r</pn>6<br />
2 1 2<pn>r</pn>3 1<pn>r</pn>2 2<pn>r</pn>5 1<pn>r</pn>3<br />
3 3<pn>r</pn>2 1 3<pn>r</pn>4 3<pn>r</pn>5 1<pn>r</pn>2<br />
4 2 4<pn>r</pn>3 1 4<pn>r</pn>5 2<pn>r</pn>3<br />
5 5<pn>r</pn>2 5<pn>r</pn>3 5<pn>r</pn>4 1 5<pn>r</pn>6<br />
6 3 2 3<pn>r</pn>2 6<pn>r</pn>5 1 </pre></apll><br />
<br />
<p>Moreover, the Symbol Substitution (<apll>S&lt;…&gt;</apll>) feature of <apll>⎕FMT</apll> allows you to substitute a different symbol for the default <apll><pn>r</pn></apll> used to separate the numerator and denominator of a rational number, as in</p><br />
<br />
<apll><pre><br />
'S&lt;r/&gt;R4.2' ⎕FMT ∘.÷⍨⍳6<pn>x</pn><br />
1 1/2 1/3 1/4 1/5 1/6 <br /><br />
2 1 2/3 1/2 2/5 1/3 <br /><br />
3 3/2 1 3/4 3/5 1/2 <br /><br />
4 2 4/3 1 4/5 2/3 <br /><br />
5 5/2 5/3 5/4 1 5/6 <br /><br />
6 3 2 3/2 6/5 1 </pre></apll><br />
<br />
===Datatype Promotion===<br />
<br />
<p>For the most part, rational numbers beget rational numbers and VFP numbers beget VFP numbers. However, when irrational, transcendental, and certain other functions are used, rational numbers beget VFP numbers. For example,</p><br />
<br />
<apll><pre><br />
*1 <br />
2.718281828459045 <br />
*1<pn>x</pn><br />
2.718281828459045235360287471352662497759</pre></apll> <br />
<br />
<p>where the datatype of the two results are floating point and VFP, respectively. That is, in a manner similar to how some primitive functions with integer arguments may return floating point results when a rational number is used as an argument to a primitive function that can't return a result with infinite precision, it returns a VFP number.</p><br />
<br />
<p class="note">The reason irrational, transcendental, and certain other functions on rational numbers do not return rational numbers is that, by definition, the result of such a function is, in general, not representable as a rational number; instead, VFP numbers are better suited to represent irrational results where the end user may control exactly how much precision is desired in an obviously inexact number.</p><br />
<br />
<p>Two special functions are the prime decomposition (<apll>πR</apll>)/number theoretic (<apll>LπR</apll>) functions. In these cases, fractional or VFP right arguments are converted to integers or rational integers, respectively, which is the datatype of the result except for <apll>0πR</apll> (Primality Test) which always returns a Boolean result regardless of the type of <apll>R</apll>.</p><br />
<br />
<p>Ignoring purely structural functions, the list of functions that produce VFP numbers given rational numbers is as follows:</p><br />
<br />
* Power: <apll>*R</apll> and <apll>L*R</apll> (except when <apll>R</apll> is a 32-bit integer, in which case the result is a rational number)<br />
* Logarithm: <apll>⍟R</apll> and <apll>L⍟R</apll><br />
* Pi Times and Circle functions: <apll>○R</apll> and <apll>L○R</apll><br />
* Root: <apll>√R</apll> and <apll>L√R</apll><br />
* Factorial and Binomial: <apll>!R</apll> and <apll>L!R</apll> (except when the arguments are rational integers, in which case the result is a rational integer)<br />
<br />
<p>Beyond the ones mentioned above, the list of functions that <b>don't</b> produce a rational or VFP result given those argument(s) is as follows:</p><br />
<br />
* Depth: <apll>≡</apll> (Integer)<br />
* Dyadic Comparison: <apll>= ≠ < ≤ ≥ > ≡ ≢</apll> (Boolean)<br />
* Nand and Nor: <apll>⍲ ⍱</apll> (Boolean)<br />
* Grade Up/Down: <apll>⍋ ⍒</apll> (Integer)<br />
* Index Of: <apll>⍳</apll> (Integer)<br />
* Member Of: <apll>∊</apll> (Boolean)<br />
* Find: <apll>⍷</apll> (Boolean)<br />
* Subset and Superset: <apll>⊆ ⊇</apll> (Boolean)<br />
* Format: <apll>⍕</apll> (Character)<br />
<br />
<p>Otherwise, rational argument(s) produce rational result(s) and VFP argument(s) produce VFP result(s).</p><br />
<br />
===Datatype Demotion===<br />
<br />
<p>It is common in APL implementations to demote datatypes where appropriate. For example, the constant <apll>1.0</apll> might actually be represented as an integer or even Boolean datatype. The idea is there is no loss of precision and the storage is typically smaller which might lead to a more efficient algorithm when next used, so why not?</p><br />
<br />
<p class="note">With rational and VFP numbers those reasons no longer apply. While the constant <apll>1<pn>x</pn></apll> might have the same precision as the constant <apll>1.0</apll>, the difference in latent precision between the two is vast. In fact, in order for datatype propagation of rational and VFP numbers to work at all, we must be careful <b>not</b> to demote them automatically to a smaller datatype. Otherwise, it would require an intolerable degree of analysis on the part of the programmer to ensure that the desired datatype (rational or VFP) remains in effect throughout a calculation.</p><br />
<br />
===Conversions===<br />
<br />
<p>To convert manually from one datatype to another, use the system function <apll>⎕DC</apll> to convert any numeric datatype</p><br />
<br />
* To 64-bit Integer, use <apll>'i' ⎕DC R</apll><br />
* To 64-bit Floating Point, use <apll>'f' ⎕DC R</apll><br />
* To Multiple Precision Integer/Rational, use <apll>'r' ⎕DC R</apll><br />
* To Multiple Precision Floating point, use <apll>'v' ⎕DC R</apll><br />
<br />
===Comparisons===<br />
<br />
<ul><li><p>Comparisons between two rational numbers or a rational number and any other integer is exact &mdash; just as they are between integers.</p></li><br />
<br />
<li><p>Comparisons between a rational number and a floating point number convert both arguments to VFP numbers and compare the two as below.</p></li><br />
<br />
<li><p>Comparisons between a VFP number and any other number is sensitive to the current setting of Comparison Tolerance (<apll>⎕CT</apll>) &mdash; just as they are between floating point numbers.</p></li><br />
<br />
</ul><br />
<br />
<p>That is, comparisons continue the analogy between integers and rationals as well as floats and VFPs.</p><br />
<br />
===Integer Tolerance===<br />
<br />
<p>Both rational and VFP numbers may be used where the system ordinarily requires an integer (such axis coordinates, indexing, left argument to structural primitives, etc.) just as the system tolerates floating point numbers in those contexts if they are sufficiently near an integer. In all cases, the system attempts to convert the non-integer to an integer using the fixed system comparison tolerance (at the moment, <apll>3<pn>E</pn>¯15</apll>).</p><br />
<br />
===Infinities===<br />
<br />
<p>Support for <apll>±∞</apll> has been extended to rational and VFP numbers in the same manner as it applies to 64-bit integers and 64-bit floats. That is, the same cases covered by the system variable <apll>⎕IC</apll> (Indeterminate Control) also apply to infinite rational and VFP numbers. Moreover, infinite numeric constants may be entered, for example, as</p><br />
<br />
* <apll>∞<pn>x</pn></apll><br />
* <apll>∞<pn>r</pn>1</apll><br />
* <apll>∞<pn>v</pn></apll><br />
* <apll>∞<pn>v</pn>0</apll><br />
<br />
<p>Also constants such as <apll>2<pn>r</pn>∞</apll> resolve to <apll>0<pn>x</pn></apll>.</p><br />
<br />
===New And/Or Different Behavior===<br />
<br />
<ul><br />
<li><p>Both roll (<apll>?R</apll>) and deal (<apll>L?R</apll>) on rational integers use a built-in random number generator so as to use the entire range of rational integers – this algorithm uses its own internal seeds that are much more complicated than the simple integer seed that is <apll>⎕RL</apll> (Random Link). Thus <apll>⎕RL</apll> is unchanged by these functions on rationals.</p><br />
<br />
<p>For example, if you need <b>really</b> large random numbers</p><br />
<br />
<apll><pre><br />
?10*60<pn>x</pn><br />
370857192605742854709703007683731949504799559659692534573173</pre></apll><br />
</li><br />
<li><p>Matrix inverse (<apll>⌹R</apll>) and matrix division (<apll>L⌹R</apll>) on rational or VFP arguments each have two limitations above and beyond that of normal conformability:</p><br />
<ul><br />
<li><p>for a square right argument that it be non-singular, and</p></li><br />
<li><p>for an overdetermined (<apll>&gt;/⍴R</apll>) right argument that the symmetric matrix <apll>(⍉R)+.×R</apll> be non-singular.</p></li><br />
</ul><br />
<p>These limitations are due to the algorithm ([http://en.wikipedia.org/wiki/Gauss%E2%80%93Jordan_elimination Gauss-Jordan Elimination]) used to implement Matrix Inverse/Divide on rational and VFP numbers.</p><br />
<br />
<p>Integer and floating point arguments are not subject to these limitations because they use a more general algorithm ([http://en.wikipedia.org/wiki/Singular_value_decomposition Singular Value Decomposition]) that produces a unique result even for singular arguments (e.g., <apll>⌹5 3⍴0</apll>).</p></li><br />
</ul><br />
<br />
===Conclusions===<br />
<br />
<p>The new datatypes offer several benefits:</p><br />
<br />
* They extend the precision of existing integer and floating point datatypes to a much greater level.<br />
* As integer blows up to floating point, rational blows up to VFP, providing a natural parallel progression for irrational and transcendental primitive functions.<br />
* There is a close similarity between integer and rational numbers as well as floating point and VFP numbers.<br />
* Datatype propagation without demotion allows one to code an algorithm in either of the new types easily and without the need for detailed analysis of the datatype in intermediate results.<br />
* All primitives extend naturally to encompass the new types as numbers.<br />
* The notation for constants builds on existing point notation formats.<br />
<br />
===Acknowledgments===<br />
<br />
<p>The designers of J are thanked for having the foresight to include [http://www.jsoftware.com/help/dictionary/dictg.htm rational numbers] as a separate datatype.</p><br />
<br />
<p>The following LGPL libraries have been used to provide support for these datatypes:</p><br />
<br />
* MPIR (Multiple Precision Integers and Rationals) at [http://www.mpir.org mpir.org].<br />
* MPFR (Multiple Precision Floating-Point Reliable Library ) at [http://www.mpfr.org mpfr.org].<br />
<br />
===References===<br />
<br />
<p>For a PDF version of this page, view it [http://www.sudleyplace.com/APL/Rational%20&%20Variable-Precision%20FP.pdf here].</p></div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=APA&diff=3187APA2018-04-16T00:20:39Z<p>Sudleyplace: </p>
<hr />
<div><p>So as to more efficiently represent this commonly occurring array, a new datatype &mdash; '''Arithmetic Progression Arrays''' ('''APAs''') &mdash; are created by the [[Index Generator]] function and may be reshaped arbitrarily (as long as no replication occurs) and still retain the datatype.</p><br />
<br />
<p>For example, <apll>2 3 4⍴⍳24</apll> has a very compact storage consisting of the array shape (<apll>2 3 4</apll>), the starting offset (<apll>⎕IO</apll>) and multiplier (<apll>1</apll>), plus the normal array overhead (which includes the number of elements (<apll>24</apll>)), for a total of <apll>96</apll> bytes. This datatype is also used to store reshaped Boolean or integer scalars, as in <apll>1e6⍴12</apll> or <apll>1e6/12</apll> both of which use <apll>80</apll> bytes (<apll>16</apll> bytes less than the preceding example because it has two fewer shape elements at eight bytes per).</p><br />
<br />
<p>Within the implementation, this datatype is used to avoid treating elided coordinates for indexing (as in <apll>M[;1]</apll>) as a special case by substituting an APA for the elided coordinate (as in <apll>M[⍳(⍴M)[1];1]</apll>).</p></div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=Infinity&diff=3186Infinity2018-04-16T00:15:49Z<p>Sudleyplace: </p>
<hr />
<div><p>The two infinities are now valid values to be used as the upper and lower numeric limits. The infinity symbol (<apll>∞</apll>) is entered from the keyboard using the key combination '''Alt-f'''. The other infinity is obtained from the positive form by preceding it with a negative symbol (<apll>¯∞</apll>).</p> <br />
<br />
<p>For example,</p><br />
<br />
<apll><pre><br />
⌊/⍬<br />
∞<br />
⌈/⍬<br />
¯∞<br />
9*999<br />
∞<br />
÷0<br />
∞<br />
÷¯∞ ∞<br />
0 0<br />
('&lt;',a),a⍪a∘.&lt;a←¯∞ 0 ∞<br />
&lt; ¯∞ 0 ∞<br />
¯∞ 0 1 1<br />
0 0 0 1<br />
∞ 0 0 0<br />
</pre></apll><br />
<br />
<p>Also, see the description of the system variable [[System Variable IC|<apll>⎕IC</apll>]] (Indeterminate Control) for a way to control how infinity along with other indeterminates are handled.<br />
<br />
<br />
{{Language Toolbar}}<br />
[[Category:Mouse Group 12]]</div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=Variant&diff=3185Variant2018-04-16T00:12:58Z<p>Sudleyplace: </p>
<hr />
<div><table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td valign="top"><apll>Z←f⍠B R</apll> or <apll>Z←L f⍠B R</apll></td><br />
<td></td><br />
<td></td><br />
<td>evaluates <apll>f R</apll> or <apll>L f R</apll> in the context described by <apll>B</apll>.</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<tr><br />
<td><apll>L</apll> and <apll>R</apll> are arbitrary arrays conformable with <apll>f</apll>, and <apll>B</apll> is a simple scalar, simple or heterogeneous vector, or nested vector.</td><br />
</tr><br />
<tr><br />
<td><apll>f</apll> is a function.</td><br />
</tr><br />
</table><br />
<br />
==Introduction==<br />
<br />
<p>The dyadic Variant operator creates a version of the function <apll>f</apll> with a set of properties bound to it as specified by the array right operand. For example, <apll>⍳⍠0</apll> is a version of <apll>⍳</apll> that executes in origin-0 independent of the current value of <apll>⎕IO</apll>.</p><br />
<br />
<p>The array right operand to the operator may take several different forms depending upon the function left operand. In the general case, for any kind of function left operand, the right operand may specify a single property in the form of <apll>Key Val</apll>, or multiple properties in the form of <apll>(Key1 Val1) (Key2 Val2)</apll><b>&#8230;</b>, or if the left operand is a primitive function, a shorthand notation may be used as in <apll>Val</apll> or <apll>Val1 Val2</apll> <b>&#8230;</b>.</p><br />
<br />
<p>In the general case, the keys specify a property such as Index Origin as <apll>'IO'</apll> or Comparison Tolerance as <apll>'CT'</apll>, and the value part specifies a value appropriate to the property specified in the matching key. At the moment, the keys that may be used are <apll>'CT'</apll>, <apll>'DT'</apll>, <apll>'FPC'</apll>, <apll>'IO'</apll>, <apll>'LR'</apll>, and <apll>'PP'</apll> which stand for the corresponding system variable. Note that for the Variants of <apll>L×R</apll> and <apll>⌹R</apll> there are no corresponding system variables as yet.</p><br />
<br />
<p>For example:</p><br />
<br />
<apll><pre><br />
1 2 (3+1e¯9)&nbsp; 3⍳⍠(('IO' 0) ('CT' 1e¯10)) 3<br />
3<br />
1 2 (3+1e¯10) 3⍳⍠(('IO' 0) ('CT' 1e¯10)) 3<br />
2<br />
⍳⍠('IO' 0) 3 <br />
0 1 2 <br />
⍳⍠('IO' 1) 3 <br />
1 2 3<br />
⍳⍠('IO' 0) ⍠('IO' 1) 3 <br />
0 1 2 <br />
⍳⍠('IO' 1) ⍠('IO' 0) 3 <br />
1 2 3</pre></apll><br />
<br />
<p>Note that in the last two examples, the lefthand (innermost) value of <apll>⎕IO</apll> takes precedence.</p><br />
<br />
<p>If the left operand is a primitive function, the following shorthands may be used:</p><br />
<br />
<table border="1" cellpadding="5" cellspacing="0" rules="all" summary=""><br />
<tr><br />
<th width="20%">Function or<br />Operator</th><br />
<th width="5%">Right<br />Arg<br />Type</th><br />
<th width="75%">Meaning</th><br />
</tr><br />
<br />
<tr><br />
<td rowspan="2"><apll>⍳R</apll> and <apll>L⍳R</apll></td><br />
<td><i>N</i></td><br />
<td><apll>⎕IO←</apll><i>N</i></td><br />
</tr><br />
<br />
<tr><br />
<td><i>N1&nbsp;N2</i></td><br />
<td><apll>⎕IO←</apll><i>N1</i> and <apll>⎕CT←</apll><i>N2</i></td><br />
</tr><br />
<br />
<tr><br />
<td><apll>L⌷R</apll>, <apll>L⍉R</apll>, <apll>⍋R</apll>, <apll>L⍋R</apll>, <apll>⍒R</apll>, <apll>L⍒R</apll>,<br /><apll>L⊃R</apll>, <apll>⍸R</apll>, <apll>LπR</apll>, <apll>a‼R</apll></td><br />
<td><i>N</i></td><br />
<td><apll>⎕IO←</apll><i>N</i></td><br />
</tr><br />
<br />
<tr><br />
<td><apll>⍕R</apll> and <apll>L⍕R</apll></td><br />
<td><i>N</i></td><br />
<td><apll>⎕PP←</apll><i>N</i></td><br />
</tr><br />
<br />
<tr><br />
<td><apll><apll>L&lt;R</apll>, <apll>L≤R</apll>, <apll>L=R</apll>, <apll>L≠R</apll>, <apll>L≥R</apll>, <apll>L&gt;R</apll>,<br /><br />
<apll>L∊R</apll>, <apll>L≡R</apll>, <apll>L≢R</apll>, <apll>L∪R</apll>, <apll>L∩R</apll>,<br /><br />
<apll>L⊆R</apll>, <apll>L⊇R</apll>, <apll>L§R</apll>, <apll>L~R</apll>, <apll>L⍷R</apll>,<br /><br />
<apll>⌊R</apll>, <apll>⌈R</apll>, <apll>∪R</apll></td><br />
<td><i>N</i></td><br />
<td><apll>⎕CT←</apll><i>N</i></td><br />
</tr><br />
<br />
<tr><br />
<td rowspan="4"><apll>L|R</apll>, <apll>f⌻R</apll>, <apll>L f⌻R</apll>, <apll>∘⌻R</apll></td><br />
<td><i>N</i></td><br />
<td><apll>⎕CT←</apll><i>N</i></td><br />
</tr><br />
<br />
<tr><br />
<td><i>C</i></td><br />
<td><apll>⎕LR←</apll><i>C</i></td><br />
</tr><br />
<br />
<tr><br />
<td><i>N C</i><br />
<td><apll>⎕CT←</apll><i>N</i> and <apll>⎕LR←</apll><i>C</i></td><br />
</tr><br />
<br />
<tr><br />
<td><i>C N</i><br />
<td><apll>⎕CT←</apll><i>N</i> and <apll>⎕LR←</apll><i>C</i></td><br />
</tr><br />
<br />
<tr><br />
<td rowspan="4"><apll>?R</apll> and <apll>L?R</apll></td><br />
<td><i>N</i></td><br />
<td><apll>⎕IO←</apll><i>N</i></td><br />
</tr><br />
<br />
<tr><br />
<td><i>C</i></td><br />
<td><apll>⎕DT←</apll><i>C</i></td><br />
</tr><br />
<br />
<tr><br />
<td><i>N C</i><br />
<td><apll>⎕IO←</apll><i>N</i> and <apll>⎕DT←</apll><i>C</i></td><br />
</tr><br />
<br />
<tr><br />
<td><i>C N</i><br />
<td><apll>⎕IO←</apll><i>N</i> and <apll>⎕DT←</apll><i>C</i></td><br />
</tr><br />
<br />
<tr><br />
<td rowspan="2"><apll>!R</apll> ([https://en.wikipedia.org/wiki/Pochhammer_k-symbol Pochhammer k-symbol])</td><br />
<td><i>N</i></td><br />
<td>Rising (<i>N</i> &gt; 0) and Falling (<i>N</i> &lt; 0) factorial of length <apll>|</apll><i>N</i>, stepping by <apll>1</apll> in the direction of <i>N</i></td><br />
</tr><br />
<br />
<tr><br />
<td><i>N1&nbsp;N2</i></td><br />
<td>Rising (<i>N1</i> &gt; 0) and Falling (<i>N1</i> &lt; 0) factorial of length <apll>|</apll><i>N1</i>, stepping by <apll>|</apll><i>N2</i> in the direction of <i>N1</i></td><br />
</tr><br />
<br />
<tr><br />
<td><apll>⍎R</apll></td><br />
<td><i>N</i></td><br />
<td><apll>⎕FPC←</apll><i>N</i></td><br />
</tr><br />
<br />
<tr><br />
<td><apll>L÷R</apll>, <apll>L∨R</apll>, <apll>L∧R</apll>, <apll>L○R</apll>, <apll>L⊤R</apll></td><br />
<td><i>C</i></td><br />
<td><apll>⎕LR←</apll><i>C</i></td><br />
</tr><br />
<br />
<tr><br />
<td><apll>L×R</apll></td><br />
<td><i>C</i></td><br />
<td>where <i>C</i> may be either <apll>'i'</apll> or <apll>'e'</apll> for <b>I</b>nterior or <b>E</b>xterior product where the former calculates <apll>(((L×R)+R×L)÷2</apll> and the latter calculates <apll>(((L×R)-R×L)÷2</apll> and <apll>L</apll> and <apll>R</apll> are non-commutative (Quaternion or Octonion) numbers &mdash; for commutative numbers, both products are trivial.</td><br />
</tr><br />
<br />
<tr><br />
<td><apll>⌹R</apll></td><br />
<td><i>N</i></td><br />
<td>where <i>N</i> may be <apll>1</apll>, <apll>2</apll>, <apll>3</apll>, or <apll>4</apll>. <apll>R</apll> must be a square simple Real numeric matrix. If <i>N</i> is <apll>1</apll>, the result is a Complex floating point vector of the [https://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors Eigenvalues] of <apll>R</apll>. If <i>N</i> is 2, the result is a Complex floating point matrix of the [https://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors Eigenvectors] of <apll>R</apll>, one per column. If <i>N</i> is <apll>3</apll>, the result is a two-element nested vector with a Complex vector of the Eigenvalues in the first element and a Complex matrix of the Eigenvectors in the second. If <i>N</i> is <apll>4</apll>, the result is a three-element nested vector with a Complex vector of the Eigenvalues in the first element, a Complex matrix of the Eigenvectors in the second, and a Real matrix of the Schur vectors in the third.</td><br />
</tr><br />
</table><br />
<br /><br />
<br />
==Rising and Falling Factorials==<br />
<br />
<p>A falling factorial is like a normal factorial except that it subtracts the step value (by default <apll>1</apll> unless overridden) from the original number for a fixed # of iterations. That is, <apll>!6</apll> successively decrements <apll>6</apll> by <apll>1</apll> and multiplies the numbers <apll>6 5 4 3 2 1</apll> to get <apll>720</apll>. A falling factorial starting with <apll>6</apll> of length (say) <apll>3</apll> multiplies <apll>6 5 4</apll> to get <apll>120</apll>.<br />
</p><br />
<br />
<p>A rising factorial is like a falling factorial except it adds the step value (by default <apll>1</apll> unless overridden) instead of subtracting it. A rising factorial starting with <apll>6</apll> of length (say) <apll>3</apll> multiplies <apll>6 7 8</apll> to get <apll>336</apll>.<br />
</p><br />
<br />
<p>Here are some examples of the falling factorial</p><br />
<br />
<apll><pre><br />
!6 <br />
720 <br />
(!⍠¯6)6 ⍝ ×/6 5 4 3 2 1 <br />
720 <br />
(!⍠¯5)6 ⍝ ×/6 5 4 3 2 <br />
720 <br />
(!⍠¯4)6 ⍝ ×/6 5 4 3 <br />
360 <br />
(!⍠¯3)6 ⍝ ×/6 5 4 <br />
120 <br />
(!⍠¯2)6 ⍝ ×/6 5<br />
30 <br />
(!⍠¯1)6 ⍝ ×/6 <br />
6 <br />
(!⍠¯0)6 ⍝ ×/⍬ <br />
1 <br />
</pre></apll><br />
<br />
<p>and now falling by <apll>2</apll></p><br />
<br />
<apll><pre><br />
(!⍠¯6 2)6 ⍝ ×/6 4 2 0 ¯2 ¯4 <br />
0 <br />
(!⍠¯5 2)6 ⍝ ×/6 4 2 0 ¯2 <br />
0 <br />
(!⍠¯4 2)6 ⍝ ×/6 4 2 0 <br />
0 <br />
(!⍠¯3 2)6 ⍝ ×/6 4 2 <br />
48 <br />
(!⍠¯2 2)6 ⍝ ×/6 4 <br />
24 <br />
(!⍠¯1 2)6 ⍝ ×/6 <br />
6 <br />
(!⍠¯0 2)6 ⍝ ×/⍬ <br />
1 <br />
</pre></apll><br />
<br />
<p>and here are some examples of the rising factorial</p><br />
<br />
<apll><pre><br />
(!⍠6)6 ⍝ ×/6 7 8 9 10 11 <br />
332640 <br />
(!⍠5)6 ⍝ ×/6 7 8 9 10 <br />
30240 <br />
(!⍠4)6 ⍝ ×/6 7 8 9 <br />
3024 <br />
(!⍠3)6 ⍝ ×/6 7 8 <br />
336 <br />
(!⍠2)6 ⍝ ×/6 7<br />
42<br />
(!⍠1)6 ⍝ ×/6<br />
6<br />
(!⍠0)6 ⍝ ×/⍬<br />
1 <br />
</pre></apll><br />
<br />
<p>and now rising by <apll>2</apll></p><br />
<br />
<apll><pre><br />
(!⍠6 2)6 ⍝ ×/6 8 10 12 14 16 <br />
1290240 <br />
(!⍠5 2)6 ⍝ ×/6 8 10 12 14 <br />
80640 <br />
(!⍠4 2)6 ⍝ ×/6 8 10 12 <br />
5760 <br />
(!⍠3 2)6 ⍝ ×/6 8 10 <br />
480 <br />
(!⍠2 2)6 ⍝ ×/6 8 <br />
48 <br />
(!⍠1 2)6 ⍝ ×/6 <br />
6 <br />
(!⍠0 2)6 ⍝ ×/⍬ <br />
1 <br />
</pre></apll><br />
<br />
==Identities==<br />
<br />
<table border="1" cellpadding="5" cellspacing="5" rules="none" summary=""><br />
<tr><br />
<td><apll>(!⍠N)R</apll></td><br />
<td><apll>&nbsp; ←→ &nbsp;</apll></td><br />
<td><apll>(!⍠(N 1))R</apll></td><br />
</tr><br />
<br />
<tr><br />
<td><apll>(!⍠(N 0))R</apll></td><br />
<td><apll>&nbsp; ←→ &nbsp;</apll></td><br />
<td><apll>R*N</apll></td><br />
</tr><br />
<br />
<tr><br />
<td><apll>(!⍠(N1,N2))R</apll></td><br />
<td><apll>&nbsp; ←→ &nbsp;</apll></td><br />
<td><apll>(!⍠(N1,|N2))R</apll></td><br />
<td>&nbsp;&nbsp;(the sign of <apll>N2</apll> is ignored)</td><br />
</tr><br />
</table><br />
<br />
<br />
==Eigenvalues and Eigenvectors==<br />
<br />
These [https://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors concepts] from Linear Algebra and Matrix Theory define the characteristic values and vectors of the linear transformation represented by a matrix. Every square simple Real numeric matrix has Eigenvalues and Eigenvectors. To calculate these objects, use the Variant operator with a left operand of the Domino function and a right operand of an integer scalar according to the following table:<br />
<br />
<br />
{| border="1" cellpadding="5" cellspacing="5" rules="all" summary="" style=""border:1px solid black;"<br />
|<apll>Z←(⌹⍠1) R</apll>||<apll>Z</apll> is a Complex floating point vector of the Eigenvalues of <apll>R</apll><br />
|-<br />
|<apll>Z←(⌹⍠2) R</apll>||<apll>Z</apll> is a Complex floating point matrix of the Eigenvectors of <apll>R</apll>, one per column<br />
|-<br />
|<apll>Z←(⌹⍠3) R</apll>||<apll>Z</apll> is a two-element nested vector with a Complex floating point vector of the Eigenvalues in the first element and a Complex floating point matrix of the Eigenvectors in the second<br />
|-<br />
|<apll>Z←(⌹⍠4) R</apll>||<apll>Z</apll> is a three-element nested vector with a Complex floating point vector of the Eigenvalues in the first element, a Complex floating point matrix of the Eigenvectors in the second, and a Real matrix of the Schur vectors in the third<br />
|}<br />
<br />
<br />
For example, Eigenvalues and Eigenvectors can be used to calculate the factorial of a matrix:<br />
<br />
<apll><pre><br />
&ensp; M←2 2⍴1 3 2 1<br />
&ensp; M<br />
&ensp; 1 3<br />
&ensp; 2 1<br />
&ensp; MatFact←{(Eval Evec)←(⌹⍠3) ⍵<br />
<span style="color:blue;">➥</span>⋄ Diag←∘⌻!Eval ⍝ Factorial of Eigenvalues on diagonal<br />
<span style="color:blue;">➥</span>⋄ Evec+.×Diag+.×⌹Evec}<br />
&ensp; MatFact M<br />
&ensp; 3.6274 8.8423<br />
&ensp; 5.8949 3.6274<br />
</pre></apll><br />
<br />
Note that if we delete the Shriek function in <apll>MatFact</apll>, the result is the original matrix argument.<br />
<br />
In turn, the function <apll>MatFact</apll> can be used to calculate the Factorial of a HyperComplex number:<br />
<br />
<apll><pre><br />
&ensp; HyperFact←{M←∘⌻⍵ ⍝ Matrix representation of a HyperComplex number<br />
<span style="color:blue;">➥</span>⋄ ⎕IO←1 ⋄ <9○1⌷[2] MatFact M ⍝ Factorial ...<br />
<span style="color:blue;">➥</span>}<br />
&ensp; HyperFact 1i2<br />
&ensp; 0.11229J0.32361<br />
&ensp; !1i2<br />
&ensp; 0.11229J0.32361<br />
</pre></apll><br />
<br />
where the latter expression uses the Gnu Scientific Library Complex number routines to calculate the Factorial of a Complex number.<br />
<br />
In a similar manner, using the appropriate <apll>4×4</apll> matrix representation of a Quaternion, its Factorial can be calculated which is the algorithm used in the implementation:<br />
<br />
<apll><pre><br />
&ensp; HyperFact <⍳4<br />
&ensp; 0.0060975i¯0.0010787j¯0.001618k¯0.0021573<br />
&ensp; !<⍳4<br />
&ensp; 0.0060975i¯0.0010787j¯0.001618k¯0.0021573<br />
</pre></apll><br />
<br />
{{Language Toolbar}}</div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=Rank/Atop&diff=3184Rank/Atop2018-04-16T00:03:26Z<p>Sudleyplace: </p>
<hr />
<div>==Monadic Derived Function==<br />
<br />
<table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td valign="top"><apll>Z←(<i>f</i>⍤[X] Y) R</apll></td><br />
<td></td><br />
<td></td><br />
<td>Applies the monadic function <apll><i>f</i></apll> to the rank-<apll><i>r</i></apll> cells of <apll>R</apll>, where <apll><i>r</i></apll> is defined by <apll>Y</apll> and restores the cells to the result as per <apll>X</apll>.</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<tr><br />
<td><apll>R</apll> is an arbitrary array, <apll><i>f</i></apll> is an arbitrary monadic function, <apll>X</apll> is an origin-sensitive integer scalar or vector, and <apll>Y</apll> is an integer scalar or vector.</td><br />
</tr><br />
<tr><br />
<td>If <apll>1&lt;⍴⍴Y</apll>, signal a <apll>RANK ERROR</apll>.</td><br />
</tr><br />
<tr><br />
<td>If <apll>1=⍴⍴Y</apll> and <apll>~(⍴Y)∊1 2 3</apll>, signal a <apll>LENGTH ERROR</apll>.</td><br />
</tr><br />
<tr><br />
<td><apll>Y</apll> is a scalar or one-, two-, or three-element integer vector that describes the cell size of the arguments. When it is a three-element vector, the first element specifies the cell size of the right argument when the derived function is called monadically; the second and third elements specify the left and right argument cell sizes when the derived function is called dyadically. When it is a two-element vector, the two values are used for the left and right arguments cell sizes when the derived function is called dyadically; if the derived function is called monadically, the cell size is the second value of the two. When it is a scalar or one-element vector, the single value is used for all three cell sizes. Moreover, the value of <apll>Y</apll> for the monadic derived function case may be positive or negative with an absolute value no larger than <apll>⍴⍴R</apll>. In this case (first element only), the above rules may be summarized by setting <apll>Y</apll> to the one-element integer vector <apll>(-⍴⍴R)⌈(⍴⍴R)⌊1↑⌽3⍴⌽Y</apll>.</td><br />
</tr><br />
<tr><br />
<td>The cells from <apll>R</apll> are of rank <apll>|Y</apll>.</td><br />
</tr><br />
<tr><br />
<td>If <apll>Y</apll> is positive, the cells from <apll>R</apll> are taken from the right end of the shape vector; if negative, the cells are taken from the left end of the shape vector. In particular, <apll>CR←(-Y)↑⍴R</apll> is the shape of the righthand cells, and <apll>FR←(-Y)↓⍴R</apll> is the shape of the righthand frame.</td><br />
</tr><br />
<tr><br />
<td>Loop through the frame applying <apll><i>f</i></apll> to the shape <apll>CR</apll> cells from <apll>R</apll>.</td><br />
</tr><br />
<tr><br />
<td>The result <apll>Z</apll> is the <b>conforming</b> disclose of the above (see below).</td><br />
</tr><br />
</table><br />
<br /><br />
<p>The monadic derived function of this dyadic operator is partially implemented by calling the following internal magic function:</p><br />
<br />
<apll><pre><br />
∇ Z←(LO #MonRank Y) R;YR<br />
[1] YR←(1↑⌽3⍴⌽Y)⌊⍴⍴R<br />
[2] if 0>YR ⋄ YR←0⌈YR+⍴⍴R ⋄ :end<br />
[3] Z←LO¨⊂[(-YR)↑⍳⍴⍴R] R ⋄ →0<br />
[4] ⎕PRO:YR←(1↑⌽3⍴⌽Y)⌊⍴⍴R<br />
[5] :if 0>YR ⋄ YR←0⌈YR+⍴⍴R ⋄ :end<br />
[6] Z←⊃LO¨¨⊂[(-YR)↑⍳⍴⍴R]¨0⍴⊂R<br />
∇</pre></apll><br />
<br />
See the discussion below for details on the final processing of the result of this magic function.<br />
<br />
<br /><br />
<br /><br />
<br />
==Dyadic Derived Function==<br />
<br />
<table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td valign="top"><apll>Z←L (<i>f</i>⍤[X] Y) R</apll></td><br />
<td></td><br />
<td></td><br />
<td>Applies the dyadic function <apll><i>f</i></apll> between the rank-<apll><i>l</i></apll> cells of <apll>L</apll> and the rank-<apll><i>r</i></apll> cells of <apll>R</apll> and restores the cells to the result as per <apll>X</apll>, where <apll><i>l</i></apll> and <apll><i>r</i></apll> are defined by <apll>Y</apll>.</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<tr><br />
<td><apll>L</apll> and <apll>R</apll> are arbitrary arrays, <apll><i>f</i></apll> is an arbitrary dyadic function, <apll>X</apll> is an origin-sensitive integer scalar or vector, and <apll>Y</apll> is an integer scalar or vector.</td><br />
</tr><br />
<tr><br />
<td>If <apll>1&lt;⍴⍴Y</apll>, signal a <apll>RANK ERROR</apll>.</td><br />
</tr><br />
<tr><br />
<td>If <apll>1=⍴⍴Y</apll> and <apll>~(⍴Y)∊1 2 3</apll>, signal a <apll>LENGTH ERROR</apll>.</td><br />
</tr><br />
<tr><br />
<td><apll>Y</apll> is a scalar or one-, two-, or three-element integer vector that describes the cell size of the arguments. When it is a three-element vector, the first element specifies the cell size of the right argument when the derived function is called monadically; the second and third elements specify the left and right argument cell sizes when the derived function is called dyadically. When it is a two-element vector, the two values are used for the left and right arguments cell sizes when the derived function is called dyadically; if the derived function is called monadically, the cell size is the second value of the two. When it is a scalar or one-element vector, the single value is used for all three cell sizes. <br />
<br />
Moreover, the values of <apll>Y</apll> for the dyadic derived function case may be positive or negative with an absolute value no larger than <apll>(⍴⍴L),⍴⍴R</apll>. In this case (second and third elements only), the above rules may be summarized by setting <apll>Y</apll> to the two-element integer vector <apll>(-(⍴⍴L),⍴⍴R)⌈((⍴⍴L),⍴⍴R)⌊1↓⌽3⍴⌽Y</apll>.</td><br />
</tr><br />
<tr><br />
<td>The cells from <apll>L</apll> are of rank <apll>|1↑Y</apll>; the cells from <apll>R</apll> are of rank <apll>|1↓Y</apll>.</td><br />
</tr><br />
<tr><br />
<td>If <apll>1↑Y</apll> is positive, the cells from <apll>L</apll> are taken from the right end of the shape vector; if negative, the cells are taken from the left end of the shape vector. In particular, <apll>CL←(-1↑Y)↑⍴L</apll> is the shape of the lefthand cells, and <apll>FL←(-1↑Y)↓⍴L</apll> is the shape of the lefthand frame.</td><br />
</tr><br />
<tr><br />
<td>If <apll>1↓Y</apll> is positive, the cells from <apll>R</apll> are taken from the right end of the shape vector; if negative, the cells are taken from the left end of the shape vector. In particular, <apll>CR←(-1↓Y)↑⍴R</apll> is the shape of the righthand cells, and <apll>FR←(-1↓Y)↓⍴R</apll> is the shape of the righthand frame.</td><br />
</tr><br />
<tr><br />
<td>If <apll>FL</apll> and <apll>FR</apll> are both non-empty and <apll>(⍴FL)≠⍴FR</apll>, signal a <apll>RANK ERROR</apll>; if the shapes of <apll>FL</apll> and <apll>FR</apll> are the same, but their values differ, signal a <apll>LENGTH ERROR</apll>.</td><br />
</tr><br />
<tr><br />
<td>Loop through the frames (scalar extending as necessary) applying <apll><i>f</i></apll> between the shape <apll>CL</apll> cells from <apll>L</apll> and the shape <apll>CR</apll> cells from <apll>R</apll>.</td><br />
</tr><br />
<tr><br />
<td>The result <apll>Z</apll> is the <b>conforming</b> disclose of the above (see below).</td><br />
</tr><br />
</table><br />
<br /><br />
<p>The dyadic derived function of this dyadic operator is partially implemented by calling the following internal magic function:</p><br />
<br />
<apll><pre><br />
∇ Z←L (LO #DydRank Y) R;YL;YR<br />
[1] (YL YR)←(1↓⌽3⍴⌽Y)⌊(⍴⍴L),⍴⍴R<br />
[2] :if 0>YL ⋄ YL←0⌈YL+⍴⍴L ⋄ :end<br />
[3] :if 0>YR ⋄ YR←0⌈YR+⍴⍴R ⋄ :end<br />
[4] Z←(⊂[(-YL)↑⍳⍴⍴L] L) LO¨⊂[(-YR)↑⍳⍴⍴R] R ⋄ →0<br />
[5] ⎕PRO:(YL YR)←(1↓⌽3⍴⌽Y)⌊(⍴⍴L),⍴⍴R<br />
[6] :if 0>YL ⋄ YL←0⌈YL+⍴⍴L ⋄ :end<br />
[7] :if 0>YR ⋄ YR←0⌈YR+⍴⍴R ⋄ :end<br />
[8] Z←⊃(⊂[(-YL)↑⍳⍴⍴L]¨0⍴⊂L) LO¨¨⊂[(-YR)↑⍳⍴⍴R]¨0⍴⊂R<br />
∇</pre></apll><br />
<br />
If the axis operator <apll>[X]</apll> is present on the rank operator, it is used in the final stage to disclose with axis (<apll>⊃[X]</apll>) the <apll>#Conform</apll> result to produce the final result <apll>Z</apll>. If the axis operator is not present, the final result <apll>Z</apll> is the disclose without axis (<apll>⊃</apll>) of the <apll>#Conform</apll> result.<br />
<br />
For example, the rank operator can emulate laminate between the following two vectors to produce the first result, but not the second without help from the axis operator:<br />
<br />
<apll><pre><br />
L←'abcdef' {diamond} R←⍳⍴L<br />
L ,⍤0 R a.k.a. L,[1.5] R<br />
a 1<br />
b 2<br />
c 3<br />
d 4<br />
e 5<br />
f 6<br />
L ,⍤[1] 0 R a.k.a. L,[0.5] R<br />
a b c d e f<br />
1 2 3 4 5 6</pre></apll><br />
<br />
== Acknowledgments ==<br />
<br />
The APL functions shown above were originally based upon those found in the paper J. Philip Benkhard, "[http://portal.acm.org/citation.cfm?id=114058&dl=GUIDE&coll=GUIDE&CFID=98347615&CFTOKEN=27795431 Extending structure, type, and expression in APL2]", ACM SIGAPL APL Quote Quad, v.21 n.4, p.20-38, Aug. 1991, but later was modified to reflect the definition of the Rank operator in the ISO-IEC 13751 Extended APL Standard.</div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=Multisets&diff=3183Multisets2018-04-15T23:56:46Z<p>Sudleyplace: </p>
<hr />
<div>== Introduction ==<br />
<br />
For decades the several set symbols have languished on APL keyboards either unused or underused. Sometimes the vendor has assigned no dyadic function to that symbol and sometimes the assigned function isn't very useful. All vendors have implemented Set Difference (<apll>L~R</apll>), one has implemented Set Union (<apll>L∪R</apll>) and Set Intersection (<apll>L∩R</apll>), and, up to now, no APL vendor has implemented the missing fourth function.<br />
<br />
Part of the reason the so-called set functions in APL are in an odd state is that they are defined on sets, but implemented on non-sets.<br />
<br />
From Wikipedia, “in computer science, a set is an abstract data structure that can store certain values, without any particular order, and no repeated values. It is a computer implementation of the mathematical concept of a finite set”.<br />
<br />
However, APL implementations of the set functions don't enforce the “no repeated value” requirement. Moreover, allowing repeated values is quite useful giving rise to useful idioms such as <apll>L~' '</apll> to remove all blanks from a vector.<br />
<br />
Interestingly, sets with repeated values have a long history in mathematics and are known as multisets. The usual set functions have identical counterparts as multiset functions with the same definitions except the multiset version takes into account the multiplicity of the unique values.<br />
<br />
'''Multisets''' in an APL context are scalars or vectors of arbitrary items with various operations defined on them (monadically), but mostly between them (dyadically).<br />
<br />
More formally, if <apll>L</apll> and <apll>R</apll> are multisets and the function <apll>m(x,M)</apll> returns the multiplicity of element <apll>x</apll> in the multiset <apll>M</apll>, then<br />
<br />
* The Union of multisets is the multiset whose unique elements are the unique elements of <apll>L,R</apll> where the multiplicity of element <apll>x</apll> in the result is the larger of <apll>m(x,L)</apll> and <apll>m(x,R)</apll>,<br />
* The Intersection of multisets is the multiset similar to Union, but with larger replaced by smaller, and<br />
* The Difference (also called Asymmetric Difference and Relative Complement) of multisets is similar to Union and Intersection, but where the multiplicity calculation is <apll>max(0,m(x,L)-m(x,R))</apll>, that is if element <apll>x</apll> is in the result if it occurs more in <apll>L</apll> than in <apll>R</apll>, and it occurs with the multiplicity of the difference of the left and right multiplicities.<br />
<br />
For multisets with no repeated elements, the multiset function and the corresponding set function produce the same results.<br />
<br />
== Notation ==<br />
<br />
There are a dozen or so APL primitive functions we'd like to define on Multisets. One way to do this is to come up with a dozen new symbols to represent those Multiset functions; another is to define a single '''Multiset Operator''' that can be applied to the APL primitives which is the approach taken here, and that symbol is (<apll>⍦</apll>) which can be typed with <b>Alt-'m'</b>, a keystroke previously used for the stile symbol (<apll>|</apll>) which was duplicated elsewhere on the keyboard. This operator is different from previous operators in APL in that it applies to a select set of primitive functions, but not system functions nor derived functions. It does, however, apply to user-defined functions via the System Label <apll>⎕MS</apll>. In that sense it's more like an [http://jsoftware.com/help/dictionary/dict1.htm inflection] such as how J uses <apll>.</apll> and <apll>:</apll>. Nonetheless, it is a (monadic) operator in the full mathematical (and APL) sense of it taking a function as an operand and returning a (derived) function.<br />
<br />
== Examples ==<br />
<br />
A common example of a multiset is the decomposition of an integer into its prime factors, each of which may occur multiple times. For example, <apll>600</apll> may be factored into the multiset <apll>L←2 2 2 3 5 5</apll>, and <apll>2100</apll> into <apll>R←2 2 3 5 5 7</apll>.<br />
<br />
Two useful properties of a multiset are the '''Underlying Set of Unique Elements''' (obtained via the usual <apll>∪R</apll>) along with their '''Multiplicities''' (obtained via the derived function <apll>∪⍦R</apll>), where the latter may be defined as <apll>¯2-/⍸1,(2≠/R[⍋R⍳R]),1</apll>.<br />
<br />
For the two multisets above the two properties are<br />
{|<br />
|-<br />
|<apll>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(∪L),[0.5] ∪⍦L</apll><br />
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
|<apll>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(∪R),[0.5] ∪⍦R</apll><br />
|-<br />
|<apll> 2 3 5</apll><br />
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
|<apll> 2 3 5 7</apll><br />
|-<br />
|<apll> 3 1 2</apll><br />
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
|<apll> 2 1 2 1</apll><br />
|}<br />
<br />
The values (but not the order) of the original multiset may be reconstructed from <apll>∊(∪⍦R)⍴¨∪R</apll>. That is, <apll>R≡⍦∊(∪⍦R)⍴¨∪R</apll>, but not necessarily <apll>R≡∊(∪⍦R)⍴¨∪R</apll>.<br />
<br />
Two common operations performed between multisets are '''Union''' and '''Intersection'''.<br />
<br />
'''Multiset Union''' on <apll>L</apll> and <apll>R</apll> is defined as the Multiset whose underlying set is the set union of the underlying sets of <apll>L</apll> and <apll>R</apll>, and whose multiplicities are the larger of the multiplicities of the corresponding elements of <apll>L</apll> and <apll>R</apll>.<br />
<br />
For <apll>L←2 2 2 3 5 5</apll> and <apll>R←2 2 3 5 5 7</apll> the Multiset Union is <apll>2 2 2 3 5 5 7</apll>. Note that, for example, there are three <apll>2</apll>s in the result because that is the larger of the number of <apll>2</apll>s in <apll>L</apll> (3) and <apll>R</apll> (2).<br />
<br />
'''Multiset Intersection''' on <apll>L</apll> and <apll>R</apll> is defined the same as for '''Multiset Union''' except that the smaller of the multiplicities is taken instead of the larger. For the two Multisets above, the Multiset Intersection is <apll>2 2 3 5 5</apll> where there are two <apll>2</apll>s in the result because that's the smaller of the number of <apll>2</apll>s in <apll>L</apll> (3) and <apll>R</apll> (2), and there are no <apll>7</apll>s in the result because that's the smaller of the number of <apll>7</apll>s in <apll>L</apll> (0) and <apll>R</apll> (1).<br />
<br />
Interestingly, in the context of prime factorization, Multiset Union is the direct analog of '''Least Common Multiple''' and Multiset Intersection is '''Greatest Common Divisor'''. For the two Multisets above,<br />
<br />
<apll>L∪⍦R ←→ 2 2 2 3 5 5 7</apll> and<br /><apll>L∩⍦R ←→ 2 2 3 5 5</apll><br />
<br />
The Least Common Multiple of two original numbers <apll>×/L ←→ 600</apll> and <apll>×/R ←→ 2100</apll> is<br />
<br />
<apll><pre><br />
(×/L)∧×/R<br />
4200<br />
×/L∪⍦R<br />
4200</pre></apll><br />
<br />
and the Greatest Common Divisor is<br />
<br />
<apll><pre><br />
(×/L)∨×/R<br />
300<br />
×/L∩⍦R<br />
300</pre></apll><br />
<br />
Moreover, using <apll>P←2 2 2 3 3 5 7</apll> and <apll>Q←2 2 3 5</apll> where as in this case <apll>P</apll> is a superset of <apll>Q</apll> (that is, <apll>P⊇Q</apll>) then '''Multiset Asymmetric Difference''' is the direct analog of integer division. That is,<br />
<br />
<apll><pre><br />
P~⍦Q<br />
2 3 7<br />
×/P~⍦Q<br />
42<br />
(×/P)÷×/Q<br />
42</pre></apll><br />
<br />
Other examples illustrate the distinction between the multiset and non-multiset functions<br />
<br />
<apll><pre><br />
'mississippi'~'miss'<br />
pp<br />
'mississippi'~⍦'miss'<br />
issippi</pre></apll><br />
<br />
== Subscripts ==<br />
<br />
One way to understand Multisets and the operations performed on them is to view them with equal elements having unique subscripts. That is, for the Multisets <apll>2 2 2 3 5 5</apll> and <apll>2 2 3 5 5 7</apll>, write them as<br />
{|<br />
|-<br />
|<apll>2</apll><sub>1</sub><br />
|<apll>2</apll><sub>2</sub><br />
|<apll>2</apll><sub>3</sub><br />
|<apll>3</apll><sub>1</sub><br />
|<apll>5</apll><sub>1</sub><br />
|<apll>5</apll><sub>2</sub><br />
|<br />
|<br />
|and<br />
|-<br />
|<apll>2</apll><sub>1</sub><br />
|<apll>2</apll><sub>2</sub><br />
|<br />
|<apll>3</apll><sub>1</sub><br />
|<apll>5</apll><sub>1</sub><br />
|<apll>5</apll><sub>2</sub><br />
|<apll>7</apll><sub>1</sub><br />
|}<br />
Now Multiset Union reduces to simple union where only one copy of like elements is kept, and similarly for Multiset Intersection and Multiset Asymmetric Difference. That is, <br />
{|<br />
|-<br />
|<apll>L</apll><br />
|&nbsp;<br />
|<apll>←</apll><br />
|&nbsp;<br />
|<apll>2</apll><sub>1</sub><br />
|<apll>2</apll><sub>2</sub><br />
|<apll>2</apll><sub>3</sub><br />
|<apll>3</apll><sub>1</sub><br />
|<apll>5</apll><sub>1</sub><br />
|<apll>5</apll><sub>2</sub><br />
|-<br />
|<apll>R</apll><br />
|&nbsp;<br />
|<apll>←</apll><br />
|&nbsp;<br />
|<apll>2</apll><sub>1</sub><br />
|<apll>2</apll><sub>2</sub><br />
|<br />
|<apll>3</apll><sub>1</sub><br />
|<apll>5</apll><sub>1</sub><br />
|<apll>5</apll><sub>2</sub><br />
|<apll>7</apll><sub>1</sub><br />
|-<br />
|<apll>L∪⍦R</apll><br />
|&nbsp;<br />
|<apll>←→</apll><br />
|&nbsp;<br />
|<apll>2</apll><sub>1</sub><br />
|<apll>2</apll><sub>2</sub><br />
|<apll>2</apll><sub>3</sub><br />
|<apll>3</apll><sub>1</sub><br />
|<apll>5</apll><sub>1</sub><br />
|<apll>5</apll><sub>2</sub><br />
|<apll>7</apll><sub>1</sub><br />
|-<br />
|<apll>L∩⍦R</apll><br />
|&nbsp;<br />
|<apll>←→</apll><br />
|&nbsp;<br />
|<apll>2</apll><sub>1</sub><br />
|<apll>2</apll><sub>2</sub><br />
|<br />
|<apll>3</apll><sub>1</sub><br />
|<apll>5</apll><sub>1</sub><br />
|<apll>5</apll><sub>2</sub><br />
|-<br />
|<apll>L~⍦R</apll><br />
|&nbsp;<br />
|<apll>←→</apll><br />
|&nbsp;<br />
|<br />
|<br />
|<apll>2</apll><sub>3</sub><br />
|}<br />
<br />
== Missing Function ==<br />
<br />
To see if we have covered all of the possible set/multiset results, look at the usual Venn diagram for two sets – all seven results (excluding the empty set) appear as follows:<br />
<br />
{|<br />
|-<br />
|<apll>L∪R</apll><br />
|&nbsp;&nbsp;&nbsp;<br />
|[[image:Venn123.png|40px]]<br />
|&nbsp;&nbsp;&nbsp;<br />
|Union<br />
|&nbsp;&nbsp;&nbsp;<br />
|<apll>L,R~L</apll><br />
|-<br />
|<apll>L∩R</apll><br />
|&nbsp;&nbsp;&nbsp;<br />
|[[image:Venn2.png|40px]]<br />
|&nbsp;&nbsp;&nbsp;<br />
|Intersection<br />
|&nbsp;&nbsp;&nbsp;<br />
|<apll>L~L~R</apll><br />
|-<br />
|<apll>L~R</apll><br />
|&nbsp;&nbsp;&nbsp;<br />
|[[image:Venn1.png|40px]]<br />
|&nbsp;&nbsp;&nbsp;<br />
|Asymmetric Difference Left<br />
|&nbsp;&nbsp;&nbsp;<br />
|<apll>L~R</apll><br />
|-<br />
|<apll>R~L</apll><br />
|&nbsp;&nbsp;&nbsp;<br />
|[[image:Venn3.png|40px]]<br />
|&nbsp;&nbsp;&nbsp;<br />
|Asymmetric Difference Right<br />
|&nbsp;&nbsp;&nbsp;<br />
|<apll>R~L</apll><br />
|-<br />
|<apll>L</apll><br />
|&nbsp;&nbsp;&nbsp;<br />
|[[image:Venn12.png|40px]]<br />
|&nbsp;&nbsp;&nbsp;<br />
|Left<br />
|&nbsp;&nbsp;&nbsp;<br />
|<apll>L</apll><br />
|-<br />
|<apll>R</apll><br />
|&nbsp;&nbsp;&nbsp;<br />
|[[image:Venn23.png|40px]]<br />
|&nbsp;&nbsp;&nbsp;<br />
|Right<br />
|&nbsp;&nbsp;&nbsp;<br />
|<apll>R</apll><br />
|-<br />
|<apll>L∆R</apll><br />
|&nbsp;&nbsp;&nbsp;<br />
|[[image:Venn13.png|40px]]<br />
|&nbsp;&nbsp;&nbsp;<br />
|Symmetric Difference<br />
|&nbsp;&nbsp;&nbsp;<br />
|<apll>(L~R)∪R~L ←→ (L~R),R~L</apll><br />
|}<br />
<br />
The last diagram shows the missing function along with its name and effect. The mathematical symbol for this function is delta (<apll>∆</apll>), however because old APL programs use this symbol as another alphabetic character, we use the Section symbol (<apll>§</apll>, <b>Alt-'S'</b>) instead.<br />
<br />
== Multiset Derived Functions ==<br />
<br />
The APL functions defined on Multisets are as follows:<br />
<table summary=""><br />
<tr><br />
<td><apll>L∪⍦R</apll></td> <td>&nbsp;&nbsp;&nbsp;</td> <td>Multiset Union</td><br />
</tr><br />
<tr><br />
<td><apll>L∩⍦R</apll></td> <td>&nbsp;&nbsp;&nbsp;</td> <td>Multiset Intersection</td><br />
</tr><br />
<tr><br />
<td><apll>L~⍦R</apll></td> <td>&nbsp;&nbsp;&nbsp;</td> <td>Multiset Asymmetric Difference</td><br />
</tr><br />
<tr><br />
<td><apll>L§⍦R</apll></td> <td>&nbsp;&nbsp;&nbsp;</td> <td>Multiset Symmetric Difference</td><br />
</tr><br />
<tr><br />
<td><apll>L⍳⍦R</apll></td> <td>&nbsp;&nbsp;&nbsp;</td> <td>Multiset Index Of</td><br />
</tr><br />
<tr><br />
<td><apll>L∊⍦R</apll></td> <td>&nbsp;&nbsp;&nbsp;</td> <td>Multiset Member Of</td><br />
</tr><br />
<tr><br />
<td><apll>L≡⍦R</apll></td> <td>&nbsp;&nbsp;&nbsp;</td> <td>Multiset Match</td><br />
</tr><br />
<tr><br />
<td><apll>L≢⍦R</apll></td> <td>&nbsp;&nbsp;&nbsp;</td> <td>Multiset Mismatch (same as <apll>~L≡⍦R</apll>)</td><br />
</tr><br />
<tr><br />
<td><apll>L⊂⍦R</apll></td> <td>&nbsp;&nbsp;&nbsp;</td> <td>Multiset Proper Subset Of</td><br />
</tr><br />
<tr><br />
<td><apll>L⊆⍦R</apll></td> <td>&nbsp;&nbsp;&nbsp;</td> <td>Multiset Subset Of</td><br />
</tr><br />
<tr><br />
<td><apll>L⊃⍦R</apll></td> <td>&nbsp;&nbsp;&nbsp;</td> <td>Multiset Proper Superset Of</td><br />
</tr><br />
<tr><br />
<td><apll>L⊇⍦R</apll></td> <td>&nbsp;&nbsp;&nbsp;</td> <td>Multiset Superset Of</td><br />
</tr><br />
<tr><br />
<td><apll>&nbsp;∪⍦R</apll></td> <td>&nbsp;&nbsp;&nbsp;</td> <td>Multiset Multiplicities (<apll>⍴∪⍦R ←→ ⍴∪R</apll>)</td><br />
</tr><br />
</table><br />
== Multiset Member Of and Index Of ==<br />
<br />
The key to understanding the meaning of the Multiset Operator as it is applied to the above APL primitive functions is Multiset Member Of (<apll>∊⍦</apll>), so we'll investigate that first.<br />
<br />
Using the subscript approach above the definition is straightforward, <br />
{|<br />
|-<br />
|<apll>L</apll><br />
|&nbsp;<br />
|<apll>←</apll><br />
|&nbsp;<br />
|<apll>2</apll><sub>1</sub><br />
|<apll>2</apll><sub>2</sub><br />
|<apll>2</apll><sub>3</sub><br />
|<apll>3</apll><sub>1</sub><br />
|<apll>5</apll><sub>1</sub><br />
|<apll>5</apll><sub>2</sub><br />
|-<br />
|<apll>R</apll><br />
|&nbsp;<br />
|<apll>←</apll><br />
|&nbsp;<br />
|<apll>2</apll><sub>1</sub><br />
|<apll>2</apll><sub>2</sub><br />
|<br />
|<apll>3</apll><sub>1</sub><br />
|<apll>5</apll><sub>1</sub><br />
|<apll>5</apll><sub>2</sub><br />
|<apll>7</apll><sub>1</sub><br />
|-<br />
|<apll>L∊⍦R</apll><br />
|&nbsp;<br />
|<apll>←→</apll><br />
|&nbsp;<br />
|<apll>1</apll><br />
|<apll>1</apll><br />
|<apll>0</apll><br />
|<apll>1</apll><br />
|<apll>1</apll><br />
|<apll>1</apll><br />
|}<br />
again, matching like elements with like elements between the two arguments.<br />
<br />
We'll use this definition many times over in defining how the Multiset Operator applies to various APL primitive functions.<br />
<br />
In a similar manner, Multiset Index Of can be understood best by writing the two arguments with subscripts. For a more detailed coverage of this see [http://www.sudleyplace.com/APL/AnatomyOfAnIdiom.ahtml Anatomy of An Idiom].<br />
<br />
== Multiset Match ==<br />
<br />
This derived function is a convenient way to determine whether or not two multisets are identical up to but not including order, as in these anagrams:<br />
<br />
<apll><pre><br />
'dynamo'≡⍦'monday'<br />
1<br />
'pepsicola'≡⍦'episcopal'<br />
1<br />
'the morse code'≡⍦'here come dots'<br />
1</pre></apll><br />
<br />
== APL Definitions ==<br />
<br />
Each of the above dyadic Multiset functions has a simple analog in a non-Multiset context:<br />
<br />
<table summary=""><br />
<tr><br />
<td style="font-weight: bold;" valign="bottom">Function<br /><apll>&nbsp;&nbsp;<i>f</i></apll></td><br />
<td style="font-weight: bold;" valign="bottom">&nbsp;&nbsp;&nbsp;</td><br />
<td style="font-weight: bold;" valign="bottom">Non-Multiset<br />Definition<br /><apll>L <i>f</i> R</apll></td><br />
<td style="font-weight: bold;" valign="bottom">&nbsp;&nbsp;&nbsp;</td><br />
<td style="font-weight: bold;" valign="bottom">Multiset<br />Definition<br /><apll>L <i>f</i>⍦ R</apll></td><br />
</tr><br />
<tr><br />
<td colspan="5"><hr /></td><br />
</tr><br />
<tr><br />
<td><apll>&nbsp;&nbsp;∪</apll></td> <td>&nbsp;&nbsp;&nbsp;</td> <td><apll>L,R~L</apll></td> <td>&nbsp;&nbsp;&nbsp;</td> <td><apll>L,R~⍦L</apll></td><br />
</tr><br />
<tr><br />
<td><apll>&nbsp;&nbsp;∩</apll></td> <td>&nbsp;&nbsp;&nbsp;</td> <td><apll>(L∊R)/L</apll></td> <td>&nbsp;&nbsp;&nbsp;</td> <td><apll>(L∊⍦R)/L</apll></td><br />
</tr><br />
<tr><br />
<td><apll>&nbsp;&nbsp;~</apll></td> <td>&nbsp;&nbsp;&nbsp;</td> <td><apll>(~L∊R)/L</apll></td> <td>&nbsp;&nbsp;&nbsp;</td> <td><apll>(~L∊⍦R)/L</apll></td><br />
</tr><br />
<tr><br />
<td><apll>&nbsp;&nbsp;§</apll></td> <td>&nbsp;&nbsp;&nbsp;</td> <td><apll>(L~R),R~L</apll></td> <td>&nbsp;&nbsp;&nbsp;</td> <td><apll>(L~⍦R),R~⍦L</apll></td><br />
</tr><br />
<tr><br />
<td><apll>&nbsp;&nbsp;⍳</apll></td> <td>&nbsp;&nbsp;&nbsp;</td> <td><apll>L⍳R</apll></td> <td>&nbsp;&nbsp;&nbsp;</td> <td><apll>L⍳⍦R</apll></td><br />
</tr><br />
<tr><br />
<td><apll>&nbsp;&nbsp;∊</apll></td> <td>&nbsp;&nbsp;&nbsp;</td> <td><apll>L∊R</apll></td> <td>&nbsp;&nbsp;&nbsp;</td> <td><apll>L∊⍦R</apll></td><br />
</tr><br />
<tr><br />
<td><apll>&nbsp;&nbsp;≡</apll></td> <td>&nbsp;&nbsp;&nbsp;</td> <td><apll>((≢L)≡≢R)∧∧/L∊R</apll></td> <td>&nbsp;&nbsp;&nbsp;</td> <td><apll>((≢L)≡≢R)∧∧/L∊⍦R</apll></td><br />
</tr><br />
<tr><br />
<td><apll>&nbsp;&nbsp;≢</apll></td> <td>&nbsp;&nbsp;&nbsp;</td> <td><apll>~L≡R</apll></td> <td>&nbsp;&nbsp;&nbsp;</td> <td><apll>~L≡⍦R</apll></td><br />
</tr><br />
<tr><br />
<td><apll>&nbsp;&nbsp;⊂</apll></td> <td>&nbsp;&nbsp;&nbsp;</td> <td><apll>(L⊆R)∧L≢R</apll> &dagger;</td> <td>&nbsp;&nbsp;&nbsp;</td> <td><apll>(L⊆⍦R)∧L≢⍦R</apll></td><br />
</tr><br />
<tr><br />
<td><apll>&nbsp;&nbsp;⊆</apll></td> <td>&nbsp;&nbsp;&nbsp;</td> <td><apll>∧/L∊R</apll></td> <td>&nbsp;&nbsp;&nbsp;</td> <td><apll>∧/L∊⍦R</apll></td><br />
</tr><br />
<tr><br />
<td><apll>&nbsp;&nbsp;⊃</apll></td> <td>&nbsp;&nbsp;&nbsp;</td> <td><apll>(R⊆L)∧R≢L</apll> &dagger;</td> <td>&nbsp;&nbsp;&nbsp;</td> <td><apll>(R⊆⍦L)∧R≢⍦L</apll></td><br />
</tr><br />
<tr><br />
<td><apll>&nbsp;&nbsp;⊇</apll></td> <td>&nbsp;&nbsp;&nbsp;</td> <td><apll>∧/R∊L</apll></td> <td>&nbsp;&nbsp;&nbsp;</td> <td><apll>∧/R∊⍦L</apll></td><br />
</tr><br />
</table><br />
&dagger; = This is the meaning this function would have as a set function if it didn't have another meaning in a non-Multiset context.<br />
<br />
Note that in every case the Multiset definition may be obtained from the non-Multiset definition by introducing the Multiset Operator at the appropriate place(s). Beyond the above explanations for Multiset Member Of and Multiset Index Of, all of the other Multiset definitions can be reduced to the definition of Multiset Member Of.<br />
<br />
Moreover, Multiset Union, Intersection, and Symmetric Difference are all symmetric up to order. That is,<br />
<br />
{|<br />
|-<br />
|<apll>(L∪⍦R)≡⍦R∪⍦L</apll><br />
|-<br />
|<apll>(L∩⍦R)≡⍦R∩⍦L</apll><br />
|-<br />
|<apll>(L~⍦R)≡⍦R~⍦L</apll><br />
|}<br />
<br />
== Acknowledgments ==<br />
<br />
The idea of defining Multisets in an APL context is due to Patrick Parks of APL2000, Inc.</div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=Determinant_Operator&diff=3182Determinant Operator2018-04-15T23:51:06Z<p>Sudleyplace: </p>
<hr />
<div><table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td valign="top"><apll>Z←f.g R</apll></td><br />
<td></td><br />
<td></td><br />
<td>returns the generalized determinant of <apll>R</apll>.</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<tr><br />
<td><apll>R</apll> is a numeric scalar, vector, or matrix.</td><br />
</tr><br />
<tr><br />
<td><apll>f</apll> and <apll>g</apll> are functions.</td><br />
</tr><br />
</table><br />
<br />
<p>The determinant of a matrix is a value associated with it whose interpretation depends upon the purpose of the matrix. For example, where the matrix represents the coefficients in a system of linear equations, a non-zero determinant indicates that the system has a unique solution, and a zero determinant indicates that the system has either no solutions or many solutions. For the original source document that introduced this operator, see [http://www.jsoftware.com/papers/satn42.htm Determinant-Like Functions Produced by the Dot Operator].</p><br />
<br />
<p>There are many formulas that many be used to calculate the value of the determinant, one of which (from Wikipedia, due to [https://en.wikipedia.org/wiki/Leibniz_formula_for_determinants Leibniz]) is particularly suited to our purposes:</p><br />
<br />
[[image:LeibnizFormula.png]]<br />
<br />
<p>for an ''n''×''n'' matrix, where sgn is the [https://en.wikipedia.org/wiki/Even_and_odd_permutations sign function] of [https://en.wikipedia.org/wiki/Permutation permutation]s in the [https://en.wikipedia.org/wiki/Permutation_group permutation group] ''S''<sub>''n''</sub>, which returns +1 and −1 for [https://en.wikipedia.org/wiki/Even_and_odd_permutations even and odd permutations], respectively. The latter sum of positive or negative quantities is actually an alternating sum (<apll>-/</apll> in APL) and the righthand part is a product of terms (<apll>×/</apll> in APL), hence this formula may be described as an alternating sum of products. This means that the usual determinant of a matrix is obtained via <apll>-.×</apll>. Moreover, the [https://en.wikipedia.org/wiki/Permanent permanent] of a matrix uses <apll>+.×</apll>.</p><br />
<br />
<h2>Examples</h2><br />
<br />
<apll><pre><br />
⎕←a←?4 4⍴10<br />
1 8 1 8<br />
5 1 7 2<br />
6 3 9 4<br />
4 9 8 8<br />
-.×a<br />
26<br />
+.×a<br />
18886</pre></apll><br />
<br />
<h2>Alternate Derived Functions</h2><br />
<br />
<p>The Leibniz formula nicely allows us to substitute other functions for (<apll>-</apll>) and (<apll>×</apll>) to obtain alternate derived functions in order to solve different problems, while <b>still using the same basic algorithm</b>.</p><br />
<br />
<p>One such alternate derived function is <apll>⌊.+</apll> which finds the [https://en.wikipedia.org/wiki/Assignment_problem lowest cost assignment] of agents (rows) to tasks (columns) where each agent is assigned one and only one task. For example,</p><br />
<br />
<apll><pre><br />
⌊.+a<br />
10</pre></apll><br />
<br />
<p>This result means that there is a minimal assignment of choices of an entry from each column and each row that sums to <apll>10</apll>, a result easily seen using another pair of operands to the Determinant Operator so as to display the actual choices:</p><br />
<br />
<apll><pre><br />
{(+/⍺)<+/⍵:⍺ ⋄ ⍵}.,a<br />
4 3 1 2</pre></apll><br />
<br />
<p>That is, a minimal set of choices is the <apll>4</apll> in column <apll>1</apll>, the <apll>3</apll> in column <apll>2</apll>, the <apll>1</apll> in column <apll>3</apll>, and the <apll>2</apll> in column <apll>4</apll>, which, by construction, are all in different rows.</p><br />
<br />
<p>Moreover, just as <apll>-.×</apll> uses an optimized algorithm ([http://www.gnu.org/software/gsl/manual/html_node/LU-Decomposition.html#LU-Decomposition LU Decomposition]), so does <apll>⌊.+</apll> ([https://github.com/maandree/hungarian-algorithm-n3/blob/master/hungarian.c Kuhn's Hungarian Algorithm]) as well as <apll>⌈.+</apll> and <apll>{(+/⍺)<+/⍵:⍺ ⋄ ⍵}</apll>, along with a number of variations of the latter anonymous function (e.g. <apll>{(+/⍺)>+/⍵:⍺ ⋄ ⍵}</apll>, <apll>{(+/⍺)<+/⍵:⍵ ⋄ ⍺}</apll>, etc.). Consequently, all of the above derived functions return results very quickly for reasonably large arguments. For example, <apll>⌊.+</apll> on a random <apll>50</apll> by <apll>50</apll> matrix takes only a few milliseconds.</p><br />
<br />
<p>Another variant of the lowest cost assignment is <apll>⌊.×</apll> and <apll>⌈.×</apll>. Rather than treat these expressions specially, they can be resolved via the identities <apll>⌊.×R ←→ *⌊.+⍟R</apll> and <apll>⌈.×R ←→ *⌈.+⍟R</apll>.<br />
<br />
<h2>References</h2><br />
<br />
<ol><br />
<li>[http://www.jsoftware.com/papers/satn42.htm Determinant-Like Functions Produced by the Dot Operator], SATN-42 (Sharp APL Technical Notes), 1982-04-01, by K.E. Iverson</li><br />
<li>[https://en.wikipedia.org/wiki/Leibniz_formula_for_determinants Leibniz Formula], from Wikipedia</li><br />
<li>[https://en.wikipedia.org/wiki/Permanent Permanent], from Wikipedia</li><br />
<li>[https://en.wikipedia.org/wiki/Assignment_problem Assignment Problem], from Wikipedia</li><br />
</ol></div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=Convolution&diff=3181Convolution2018-04-15T23:48:29Z<p>Sudleyplace: </p>
<hr />
<div><table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td valign="top"><apll>Z←L f⍡g R</apll></td><br />
<td></td><br />
<td></td><br />
<td>returns the [https://en.wikipedia.org/wiki/Convolution convolution] (moving window inner product) of <apll>L</apll> vs. <apll>R</apll>.</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<tr><br />
<td><apll>L</apll> and <apll>R</apll> are vectors; scalars are promoted to one-element vectors.</td><br />
</tr><br />
<tr><br />
<td><apll>f</apll> and <apll>g</apll> are functions.</td><br />
</tr><br />
<br />
<tr><br />
<td><apll>Z</apll> is a vector whose shape is <apll>(⍴L)+(⍴R)-1</apll>.<br />
</tr><br />
</table><br />
<br />
<p>The result is obtained by dragging the <b>reverse</b> of the shorter argument through all positions of the longer argument (as in a moving window) and performing an <apll>f.g</apll> inner product between the two, including leading and trailing prefixes. For example,</p><br />
<br />
<apll>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;L←1 3 2 1 ⋄ R←2 1 ⋄ L+⍡×R</apll><br /><br />
<table border="0" cellpadding="0" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><apll>2</apll></td><br />
<td><apll>1 2</apll></td><br />
<td><apll> 1 2</apll></td><br />
<td><apll> 1 2</apll></td><br />
<td><apll> 1</apll></td><br />
<td>&nbsp;&nbsp;&nbsp;multiply the rows together</td><br />
</tr><br />
<tr><br />
<td><apll>1 3 2 1 </apll></td><br />
<td><apll>1 3 2 1 </apll></td><br />
<td><apll>1 3 2 1 </apll></td><br />
<td><apll>1 3 2 1 </apll></td><br />
<td><apll>1 3 2 1</apll></td><br />
</tr><br />
<tr><br />
<td colspan="5"><hr size="6" /></td><br />
</tr><br />
<tr><br />
<td><apll>2</apll></td><br />
<td><apll>1 6</apll></td><br />
<td><apll> 3 4</apll></td><br />
<td><apll> 2 2</apll></td><br />
<td><apll> 1</apll></td><br />
<td>&nbsp;&nbsp;&nbsp;add the products</td><br />
</tr><br />
</table><br />
<apll> L+⍡×R<br />
2 7 7 4 1</apll><br />
<br />
<p>Interestingly, this algorithm solves a diverse set of problems such as [https://en.wikipedia.org/wiki/Weighted_moving_average#Weighted_moving_average weighted moving average] (used to remove pixelization from a digital image), polynomial multiplication, and overlapping string searching.</p><br />
<br />
<p>Polynomial multiplication is illustrated in the above example using the functions <apll>+</apll> and <apll>×</apll>. Overlapping string searching uses the functions <apll>∧</apll> and <apll>=</apll> as in</p><br />
<br />
<apll><pre><br />
L←'abababc' ⋄ R←'aba'<br />
(0⌈¯1+(⍴L)⌊⍴R)↓L∧⍡=⌽R<br />
1 0 1 0 0 0 0</pre></apll><br />
<br />
where we need to drop leading elements of the convolution result to remove the leading prefix comparisons.</div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=Compose&diff=3180Compose2018-04-15T23:44:35Z<p>Sudleyplace: </p>
<hr />
<div>In the following descriptions, <apll><i>f</i></apll> and <apll><i>g</i></apll> represent functions and <apll><i>a</i></apll> and <apll><i>b</i></apll> represent variables.<br />
<br />
* The form <apll><i>f</i>∘<i>g</i></apll> may be used both monadically and dyadically.<br />
:<br />
:Monadic: <apll>Z←<i>f</i>∘<i>g</i>R</apll> is identical to <apll>Z←<i>f</i><i>g</i>R</apll>.<br />
:<br />
:Dyadic: <apll>Z←L<i>f</i>∘<i>g</i>R</apll> is identical to <apll>Z←L<i>f</i><i>g</i>R</apll>.<br />
<br />
* The form <apll><i>f</i>∘b</apll> may be used monadically only.<br />
:<br />
:Monadic: <apll>Z←(<i>f</i>∘<i>b</i>) R</apll> is identical to <apll>Z←R <i>f b</i></apll>.<br />
:Note that parentheses are required around the function to avoid interpreting <apll><i>b</i> R</apll> as a strand.<br />
<br />
* The form <apll><i>a</i>∘<i>g</i></apll> may be used monadically only.<br />
:<br />
:Monadic: <apll>Z←<i>a</i>∘<i>g</i>R</apll> is identical to <apll>Z←<i>a g</i> R</apll>.<br />
<br />
* The derived function from the form <apll><i>a</i>∘<i>b</i></apll> always signals a <apll>SYNTAX ERROR</apll>.<br />
<br />
Compose can be useful for function assignment (but enclosing parentheses are necessary).<br />
<br />
For example<br />
<br />
<apll><pre><br />
p1←(1∘+¯2∘π) ⍝ 1 more than the Nth prime number<br />
p1 ⍳9<br />
3 4 6 8 12 14 18 20 24<br />
</pre></apll></div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=Commute-Duplicate&diff=3179Commute-Duplicate2018-04-15T23:41:24Z<p>Sudleyplace: </p>
<hr />
<div><table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td valign="top">Duplicate: <apll>Z←f⍨ R</apll></td><br />
<td></td><br />
<td>&nbsp;&nbsp;&nbsp;&nbsp;</td><br />
<td>returns <apll>R f R</apll>.</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td valign="top">Commute: <apll>Z←L f⍨ R</apll></td><br />
<td></td><br />
<td></td><br />
<td>returns <apll>R f L</apll>.</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<br />
<tr><br />
<td><apll>L</apll> and <apll>R</apll> are arrays.</td><br />
</tr><br />
<br />
<tr><br />
<td><apll>f</apll> is a function.</td><br />
</tr><br />
</table><br />
<br />
<p>For example:</p><br />
<br />
<apll><pre><br />
×⍨⍳5 ⍝ squares<br />
1 4 9 16 25<br />
∘.=⍨⍳4 ⍝ Identity matrix<br />
1 0 0 0<br />
0 1 0 0<br />
0 0 1 0<br />
0 0 0 1<br />
</pre></apll><br />
<br />
<apll><pre><br />
2*⍨⍳5 ⍝ squares<br />
1 4 9 16 25<br />
√+/2*⍨6 2⍴3 4, 5 12, 8 15, 7 24, 20 21, 12 35 ⍝ Pythagorean hypotenuses<br />
5 13 17 25 29 37<br />
</pre></apll></div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=Axis&diff=3178Axis2018-04-15T23:38:02Z<p>Sudleyplace: </p>
<hr />
<div>* The Axis operator is allowed with all primitive scalar dyadic functions (e.g., <apll>1 2+[1] 2 3⍴R</apll>) and some scalar monadic functions (e.g., <apll>&lt;[1] 2 3⍴R</apll>)<br />
* The Axis operator is allowed with some primitive operators (e.g., <apll>L←'abcdef' ⋄ R←⍳⍴L ⋄ L ,⍤[1] 0 R ←→ L,[0.5] R</apll>)<br />
* The Axis operator to primitive scalar dyadic functions may transpose coordinates (e.g., <apll>(2 3⍴L)+[1 2] 2 3 4⍴R ←→ (⍉2 3⍴L)+[2 1] 2 3 4⍴R</apll>)<br />
* The Axis operator to Ravel may transpose coordinates (e.g., <apll>,[2 1] R</apll> and <apll>,[1 2] R</apll> are both valid but, in general, have the same values in different order)<br />
* The Axis operator is allowed on the dyadic derived function from the Each operator (e.g., <apll>(2 3⍴L)⍴¨[1 2] 2 3 4⍴R</apll>)<br />
* The Axis operator is allowed on user-defined functions/operators (e.g., <apll>FOO[2 3] R</apll> by specifying it in the function header, as in <apll>∇ Z←FOO[X] R</apll>)<br />
* If the first element of <apll>⎕FEATURE</apll> is a <apll>1</apll>, the Axis operator values may be negative. That is, if the largest allowed value is <apll>N</apll>, then the allowable range for axis operator values is <apll>1 ¯1[1]-N</apll> to <apll>N</apll>, inclusive.</div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=Without&diff=3177Without2018-04-15T23:25:29Z<p>Sudleyplace: </p>
<hr />
<div><table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td valign="top"><apll>Z←L~R</apll></td><br />
<td></td><br />
<td></td><br />
<td>returns a subset of <apll>L</apll> consisting of those elements in <apll>L</apll> which do not occur in <apll>R</apll>.</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<tr><br />
<td><apll>L</apll> is a scalar or vector, else signal <apll>RANK ERROR</apll>.</td><br />
</tr><br />
<tr><br />
<td><apll>R</apll> is an arbitrary array.</td><br />
</tr><br />
<tr><br />
<td><apll>Z</apll> is a vector identical to <apll>(~L∊R)/L</apll>.</td><br />
</tr><br />
<tr><br />
<td>The result is sensitive to <apll>⎕CT</apll>.</td><br />
</tr><br />
</table><br />
<br /><br />
<p>This feature is implemented by an internal magic function:</p><br />
<br />
<apll><pre><br />
∇ Z←L #DydTilde R<br />
[1] Z←(~L∊R)/L<br />
∇</pre></apll></div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=Tally&diff=3176Tally2018-04-15T23:23:23Z<p>Sudleyplace: </p>
<hr />
<div><table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td valign="top"><apll>Z←≢R</apll></td><br />
<td></td><br />
<td></td><br />
<td>returns an integer scalar identical to <apll>⍬⍴(⍴R),1</apll>.</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<tr><br />
<td><apll>R</apll> is an arbitrary array.</td><br />
</tr><br />
<tr><br />
<td><apll>Z</apll> is an integer scalar whose value is the number of items along the first coordinate of <apll>R</apll>.</td><br />
</tr><br />
</table><br />
<br /><br />
<p>For example,</p><br />
<br />
<apll><pre><br />
≢⍬<br />
0<br />
≢23<br />
1<br />
≢,23<br />
1<br />
≢2 3 4⍴5 6<br />
2</pre></apll><br />
<br />
<p>This symbol was suggested by the language designers of Dyalog APL.</p></div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=Sets&diff=3175Sets2018-04-15T23:21:59Z<p>Sudleyplace: </p>
<hr />
<div><table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td valign="top"><apll>Z←L§R</apll></td><br />
<td></td><br />
<td></td><br />
<td>returns a vector consisting of the elements of <apll>L</apll> that are not in <apll>R</apll>.</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<br />
<tr><br />
<td><apll>L</apll> is a scalar or one-element vector.</td><br />
</tr><br />
<br />
<tr><br />
<td><apll>R</apll> is a scalar or one-element vector.</td><br />
</tr><br />
<br />
<tr><br />
<td><apll>Z</apll> is the vector result equivalent to <apll>(L~R),R~L</apll>.</td><br />
</tr><br />
</table><br />
<br /><br />
<br />
<table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td valign="top"><apll>Z←L⊆R</apll></td><br />
<td></td><br />
<td></td><br />
<td>returns a Boolean scalar indicating whether or not <apll>L</apll> is a subset of <apll>R</apll>.</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<br />
<tr><br />
<td><apll>L</apll> is a scalar or one-element vector.</td><br />
</tr><br />
<br />
<tr><br />
<td><apll>R</apll> is a scalar or one-element vector.</td><br />
</tr><br />
<br />
<tr><br />
<td><apll>Z</apll> is the Boolean scalar result equivalent to <apll>∧/L∊R</apll> as well as <apll>R⊇L</apll>.</td><br />
</tr><br />
</table><br />
<br /><br />
<br />
<table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td valign="top"><apll>Z←L⊇R</apll></td><br />
<td></td><br />
<td></td><br />
<td>returns a Boolean scalar indicating whether or not <apll>L</apll> is a superset of <apll>R</apll>.</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<br />
<tr><br />
<td><apll>L</apll> is a scalar or one-element vector.</td><br />
</tr><br />
<br />
<tr><br />
<td><apll>R</apll> is a scalar or one-element vector.</td><br />
</tr><br />
<br />
<tr><br />
<td><apll>Z</apll> is the Boolean scalar result equivalent to <apll>∧/R∊L</apll> as well as <apll>R⊆L</apll>.</td><br />
</tr><br />
</table><br />
<br /><br />
<br />
<p>These functions behave differently when invoked via the [[Multisets|Multiset Operator]] which takes into account multiplicities.</p><br />
<br />
<p>For example,</p><br />
<br />
<apll><pre><br />
'miasma'§'sis'<br />
mama<br />
'miasma'§⍦'sis' ⍝ Using the Multiset form<br />
mamas<br />
'immiss'⊆'mississippi'<br />
1<br />
'immiss'⊆⍦'mississippi' ⍝ Using the Multiset form<br />
0 ⍝ because the # m's doesn't match<br />
</pre></apll></div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=Sequence&diff=3174Sequence2018-04-15T23:18:46Z<p>Sudleyplace: </p>
<hr />
<div><table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td valign="top"><apll>Z←L..R</apll></td><br />
<td></td><br />
<td></td><br />
<td>returns an array consisting of the numeric sequence of values between <apll>L</apll> and <apll>R</apll>.</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<tr><br />
<td><apll>L</apll> is a numeric or nested scalar or one- or two-element vector consisting of starting value(s) and optional step value(s) (default is <apll>1</apll>) for the sequence.</td><br />
</tr><br />
<tr><br />
<td><apll>R</apll> is a numeric or nested scalar or one-element vector consisting of ending value(s) for the sequence.</td><br />
</tr><br />
<tr><br />
<td><apll>Z</apll> is an array whose values represent the sequence of values between <apll>L</apll> and <apll>R</apll>.</td><br />
</tr><br />
</table><br />
<br /><br />
<br />
<p>For example</p><br />
<br />
<apll><pre><br />
3..10 Start and end values<br />
3 4 5 6 7 8 9 10<br />
3 2..10 Start, step, and end values<br />
3 5 7 9<br />
(⊂3 4)..6 Two start values, so the result is two-dimensional and nested<br />
3 4 3 5 3 6 <br />
4 4 4 5 4 6 <br />
5 4 5 5 5 6 <br />
6 4 6 5 6 6 <br />
3..⊂5 6 Two ending values, so the result is two-dimensional and nested<br />
3 3 3 4 3 5 3 6 <br />
4 3 4 4 4 5 4 6 <br />
5 3 5 4 5 5 5 6 <br />
</pre></apll><br />
<br />
<p>The starting value(s) may be greater than the ending values in which case the sequence is in descending order. The sign of the optional step value is ignored.</p><br />
<br />
<apll><pre><br />
(6 7)2..2<br />
6 7 6 5 6 3<br />
4 7 4 5 4 3<br />
2 7 2 5 2 3<br />
</pre></apll><br />
<br />
<p>This primitive was suggested by John Scholes of Dyalog, Ltd.</p></div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=Root&diff=3173Root2018-04-15T23:12:45Z<p>Sudleyplace: </p>
<hr />
<div><table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td valign="top"><apll>Z←√R</apll></td><br />
<td></td><br />
<td></td><br />
<td>returns the square root of each of the elements in <apll>R</apll>.</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<tr><br />
<td><apll>R</apll> is a numeric array.</td><br />
</tr><br />
<tr><br />
<td><apll>Z</apll> is a floating point array whose values are the square root of the elements of <apll>R</apll>.</td><br />
</tr><br />
</table><br />
<br /><br />
<table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td valign="top"><apll>Z←L√R</apll> &nbsp;&nbsp; or &nbsp;&nbsp; <apll>Z←L√[X] R</apll></td><br />
<td></td><br />
<td></td><br />
<td>returns the <apll>L</apll><sup>th</sup> root of each of the elements in <apll>R</apll>.</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<tr><br />
<td><apll>L</apll> and <apll>R</apll> are numeric arrays.</td><br />
</tr><br />
<tr><br />
<td><apll>Z</apll> is a floating point array whose values are the <apll>L</apll><sup>th</sup> root of the elements of <apll>R</apll>.</td><br />
</tr><br />
</table><br />
<br /><br />
<br />
<p>For example,</p><br />
<br />
<apll><pre><br />
√⍳4<br />
1 1.414213562 1.732050808 2<br />
(3√⍳4)*3<br />
1 2 3 4</pre></apll><br />
<br />
<br />
{{Language Toolbar}}</div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=Rho&diff=3172Rho2018-04-15T23:11:28Z<p>Sudleyplace: </p>
<hr />
<div>__NOTOC__<br />
<br />
{{Article header<br />
|sym={rho}<br />
|def=Shape or Reshape<br />
|ks=ALT+r<br />
|char=9076 or x2374<br />
|kb=APLKB-Rho.png|kb2=}}<br />
<br />
Note: This is ALT+r; ALT+SHIFT+R will generate the symbol [[Symbol Root|root]] ({root}).<br />
<br />
Rho may be used as a [[monadic]] or [[dyadic]] operator, depending on the functionality desired. Used monadically with the argument to the right returns the '''shape''' of the argument. Used dyadically, the argument on the left is used to '''reshape''' the argument on the right.<br />
<br />
==Shape - Monadic {rho}==<br />
<big>Symbol '''{rho}''' when used '''monadically''' (no left argument) returns the '''shape of {rho}'s right argument''', i.e. the size or dimensions of a scalar, string, vector, array or matrix. Shape returns null for a scalar or a single character, it returns 0 for a null string, the length of a string of at least two characters, the number of elements of an array or vector, and the number of elements of a matrix.</big><br />
<apll><pre><br />
⍴ 1 2 3 4 5 6 ⍝ Rho in the case of vectors represents a Count(# elements) function<br />
6<br />
⍴'abcdefg' ⍝ Similarly with text strings(vector of chars), Rho represents a Count function<br />
7<br />
⍴ 1 ⍝ For a scalar right argument, Rho generates a null vector.<br />
<br />
⍴⍴ 1 ⍝ The shape of the shape(⍴⍴) of a scalar (because the shape of a scalar is a null) - generates zero.<br />
0<br />
⍴ 'a' ⍝ Ditto for {numbers, integers, letters}, etc. - for scalar right arguments: Rho also generates a null vector.<br />
<br />
⍴⍴ 'a'<br />
0<br />
⍴, 4.581 ⍝ Rho for a raveled(, or comma used) scalar(real num 4.581) - again correctly represents a Count(# elements) function<br />
1<br />
<br />
2 3⍴⍳6 ⍝ Dyadic call for demonstration purposes(see below for dyadic calls to {rho}): result = 2 rows and 3 cols matrix of integers(1..6)<br />
1 2 3<br />
4 5 6<br />
<br />
⍴2 3⍴⍳6 ⍝ Monadic LEFTMOST shape {rho} yields: matrix has 2 rows and 3 cols; equivalent to ⍴(2 3⍴⍳6) which has parentheses added for clarity<br />
2 3<br />
<br />
⍴⍴(2 3⍴⍳6) ⍝ Monadic LEFTMOST shape-shape or {rho}{rho} generates the RANK of the 2 row, 3 col matrix which = 2 (matrix) <br />
2<br />
⍴⍴(⍳6) ⍝ Monadic leftmost {rho}{rho} generates the RANK of the vector = 1 (vector)<br />
1<br />
</pre></apll><br />
<br />
==Reshape - Dyadic {rho}==<br />
<big>'''{rho}''''s Left Argument(L) output-reshapes {rho}'s Right Argument(R).</big><br />
<table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td valign="top"><apll>Z←L⍴R</apll></td><br />
<td></td><br />
<td></td><br />
<td>dyadic '''{rho}''' returns an array of shape <apll>L</apll> whose items are taken from <apll>R</apll> in row major order, repeated as necessary.</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<tr><br />
<td><apll>L</apll> is a scalar or vector of non-negative integers, and <apll>R</apll> is an arbitrary array.</td><br />
</tr><br />
<tr><br />
<td>If the right argument is empty, the result consists of <apll>×/⍴L</apll> copies of the fill item of <apll>R</apll>.<br />
</tr><br />
</table><br />
<br /><br />
<p>For example, in origin <apll>1</apll> (where <apll>⎕IO=1</apll>)</p><br />
<br />
<apll><pre><br />
2 3⍴⍳6<br />
1 2 3<br />
4 5 6<br />
2 3⍴⍳0<br />
0 0 0<br />
0 0 0</pre></apll><br />
<br />
<p>The idea for the latter enhancement was taken from Dyalog APL.</p><br />
<br />
{{article footer}}<br />
[[Category:Monadic Operators]]<br />
[[Category:Dyadic Operators]]<br />
<br />
==See Also==<br />
<br />
{{Language Toolbar}}<br />
[[Category:Mouse Group 8|R]]<br />
[[Category:Symbols|R]]</div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=Primes&diff=3171Primes2018-04-15T23:07:53Z<p>Sudleyplace: </p>
<hr />
<div><table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td valign="top"><apll>Z←πR</apll></td><br />
<td></td><br />
<td></td><br />
<td>returns an integer vector consisting of the prime factors of <apll>R</apll>.</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<tr><br />
<td><apll>R</apll> is a scalar or one-element vector consisting of a positive integer to be factored.</td><br />
</tr><br />
<tr><br />
<td><apll>Z</apll> is an integer vector whose values are the prime factors of <apll>R</apll>.</td><br />
</tr><br />
</table><br />
<br /><br />
<br />
<p>For example,</p><br />
<br />
<apll><pre><br />
π120<br />
2 2 2 3 5<br />
<br />
×/⎕←π⎕←¯1+2*62<br />
4611686018427387903<br />
3 715827883 2147483647<br />
4611686018427387903<br />
<br />
π¯1+2*61<br />
2305843009213693951<br />
<br />
⍴π1<br />
0</pre></apll><br />
<br />
<br />
<br />
<br />
<table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td valign="top"><apll>Z←LπR</apll></td><br />
<td></td><br />
<td></td><br />
<td>returns an array whose values depend upon which number-theoretic function chosen by <apll>L</apll> is applied to <apll>R</apll>.</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<tr><br />
<td><apll>L</apll> is an integer scalar whose meaning is as follows<br />
<table border="0" cellpadding="1" cellspacing="0" rules="none" summary="" style="margin-left: 20px;"><br />
<tr><br />
<td><apll>¯2</apll></td><br />
<td>&nbsp;&nbsp;Rth prime function</td><br />
</tr><br />
<br />
<tr><br />
<td><apll>¯1</apll></td><br />
<td>&nbsp;&nbsp;Previous prime function</td><br />
</tr><br />
<br />
<tr><br />
<td><apll>&nbsp;0</apll></td><br />
<td>&nbsp;&nbsp;Primality test function</td><br />
</tr><br />
<br />
<tr><br />
<td><apll>&nbsp;1</apll></td><br />
<td>&nbsp;&nbsp;Next prime function</td><br />
</tr><br />
<br />
<tr><br />
<td><apll>&nbsp;2</apll></td><br />
<td>&nbsp;&nbsp;Number of primes function</td><br />
</tr><br />
<br />
<tr><br />
<td><apll>10</apll></td><br />
<td>&nbsp;&nbsp;Divisor count function</td><br />
</tr><br />
<br />
<tr><br />
<td><apll>11</apll></td><br />
<td>&nbsp;&nbsp;Divisor sum function</td><br />
</tr><br />
<br />
<tr><br />
<td><apll>12</apll></td><br />
<td>&nbsp;&nbsp;Möbius function function</td><br />
</tr><br />
<br />
<tr><br />
<td><apll>13</apll></td><br />
<td>&nbsp;&nbsp;Euler totient function</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<tr><br />
<td><apll>R</apll> is an array consisting of positive integers to which one of the above functions is applied, element by element.</td><br />
</tr><br />
<tr><br />
<td><apll>Z</apll> is an integer array of the same shape as <apll>R</apll>.</td><br />
</tr><br />
</table><br />
<br /><br />
<br />
== Rth Prime Function ==<br />
<br />
<p>The Rth prime function (<apll>¯2πR</apll>) returns the <apll>R</apll><sup>th</sup> prime where <apll>2</apll> is the first prime. This function is sensitive to the index origin.</p><br />
<br />
<p>For example, how many primes are less then or equal to <apll>1000003</apll>?</p><br />
<br />
<apll><pre><br />
¯2π1000003<br />
15485927</pre></apll><br />
<br />
== Previous Prime Function ==<br />
<br />
<p>The previous prime function (<apll>¯1πR</apll>) returns the prime that immediately precedes <apll>R</apll>.</p><br />
<br />
<p>For example, what is the prime that immediately precedes <apll>1000000</apll>?</p><br />
<br />
<apll><pre><br />
¯1π1000000<br />
999983</pre></apll><br />
<br />
== Primality Test ==<br />
<br />
<p>The primality test function (<apll>0πR</apll>) returns a <apll>1</apll> if <apll>R</apll> is a prime and <apll>0</apll> if not.</p><br />
<br />
<p>For example, is <apll>1000003</apll> a prime?</p><br />
<br />
<apll><pre><br />
0π1000003<br />
1</pre></apll><br />
<br />
<p>List the primes up to 100</p><br />
<br />
<apll><pre><br />
⍸0π⍳100<br />
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97</pre></apll><br />
<br />
== Next Prime Function ==<br />
<br />
<p>The next prime function (<apll>1πR</apll>) returns the prime that immediately follows <apll>R</apll>.</p><br />
<br />
<p>For example, what is the next prime after <apll>1000000</apll>?</p><br />
<br />
<apll><pre><br />
1π1000000<br />
1000003</pre></apll><br />
<br />
== Number Of Primes Function ==<br />
<br />
<p>The number of primes function (<apll>2πR</apll>) returns number of primes less than or equal to <apll>R</apll>.</p><br />
<br />
<p>For example, what is the <apll>15485927</apll>th prime?</p><br />
<br />
<apll><pre><br />
2π15485927<br />
1000003</pre></apll><br />
<br />
== Divisor Count Function ==<br />
<br />
<p>The divisor count function (<apll>10πR</apll>) returns the number of divisors of a number. It is the same as <apll>×/1+∪⍦πR</apll> where <apll>πR</apll> returns the prime factors of <apll>R</apll> and <apll>∪⍦</apll> counts the number of occurrences of unique elements (in this case, the exponent vector of the unique primes). A divisor then consists of the product of zero or more of the unique primes which is why <apll>×/1+</apll> counts them.</p><br />
<br />
== Divisor Sum Function ==<br />
<br />
<p>The divisor sum function (<apll>11πR</apll>) returns the sum of the divisors of a number. It is the same as <apll>×/(¯1+(∪f)*1+∪⍦f)÷¯1+∪f←πR</apll><sup>1</sup>. This function is used to recognize [http://en.wikipedia.org/wiki/Deficient_number deficient], [http://en.wikipedia.org/wiki/Perfect_number perfect], and [http://en.wikipedia.org/wiki/Abundant_number abundant] numbers.</p><br />
<br />
== Möbius Function ==<br />
<br />
<p>The [http://en.wikipedia.org/wiki/M%C3%B6bius_function Möbius function] (<apll>12πR</apll>) returns information about the square free properties of <apll>R</apll>. If <apll>R</apll> is [http://en.wikipedia.org/wiki/Square-free_integer square free], the function returns <apll>1</apll> if <apll>R</apll> has an even number of prime factors, and <apll>¯1</apll> if it has an odd number of prime factors. If the argument is not square free, the function returns <apll>0</apll>. It is used in the [http://en.wikipedia.org/wiki/M%C3%B6bius_inversion_formula Möbius Inversion Formula] to invert general arithmetic functions.</p><br />
<br />
== Totient Function ==<br />
<br />
<p>The totient function (<apll>13πR</apll>) (also called [http://en.wikipedia.org/wiki/Euler_phi Euler's Totient Function]) returns the number of positive integers less than or equal to <apll>R</apll> that are relatively prime to it (i.e., having no common positive factors other than 1).<br />
</p><br />
<br />
== Examples ==<br />
<br />
<p>Add together the first 100 primes:</p><br />
<br />
<p>The Rth prime function (<apll>¯2πR</apll>) gives the value of the Rth prime, as in</p><br />
<br />
<apll><pre><br />
¯2π100<br />
541</pre></apll><br />
<br />
<p>The Index function (<apll>⍳R</apll>) produces a vector of integers of length <apll>R</apll>, as in</p><br />
<br />
<apll><pre><br />
⍳¯2π100<br />
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ... 541</pre></apll><br />
<br />
<p>The Primality Test function (<apll>0πR</apll>) returns a <apll>1</apll> if the corresponding element in <apll>R</apll> is a prime, <apll>0</apll> otherwise, as in</p><br />
<br />
<apll><pre><br />
0π⍳¯2π100<br />
0 1 1 0 1 0 1 0 0 0 1 0 1 0 0 0 1 0 1 0 0 0 1 ... 1</pre></apll><br />
<br />
<p>The Indices function (<apll>⍸R</apll>) converts the argument <apll>R</apll> to indices (equivalent to <apll>(,R)/⍳×/⍴R</apll>), as in</p><br />
<br />
<apll><pre><br />
⍸0π⍳¯2π100<br />
2 3 5 7 11 13 17 19 23 29 31 37 41 43 ... 541</pre></apll><br />
<br />
<p>Finally, those numbers may be added together using plus reduction (<apll>+/</apll>), as in</p><br />
<br />
<apll><pre><br />
+/⍸0π⍳¯2π100<br />
24133</pre></apll><br />
<br />
== Notes ==<br />
<br />
<sup>1</sup> [https://en.wikipedia.org/wiki/Divisor_function Formula for sum of divisors]</div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=Mismatch&diff=3170Mismatch2018-04-15T22:58:36Z<p>Sudleyplace: </p>
<hr />
<div>__NOTOC__<br />
<h1> {mismatch} &mdash; Tally &mdash; or Multiset Not Identical &mdash; Keystroke ALT+@ or ALT+SHIFT+2 &mdash; Character 8802</h1><br />
<br />
[[File:APLKB-Mismatch.png]]<br />
==Usage==<br />
<br />
<table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td valign="top"><apll>Z←L≢R</apll></td><br />
<td></td><br />
<td></td><br />
<td>returns a Boolean scalar identical to <apll>~L≡R</apll>.</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<tr><br />
<td><apll>L</apll> and <apll>R</apll> are both arbitrary arrays.</td><br />
</tr><br />
<tr><br />
<td><apll>Z</apll> is a Boolean scalar whose value is <apll>1</apll> if the two arguments differ in any respect be it depth, rank, shape or value, and <apll>0</apll> otherwise.</td><br />
</tr><br />
</table><br />
<br />
==Example==<br />
<br />
<p>For example, in origin-1</p><br />
<br />
<apll><pre><br />
''≢⍬<br />
1<br />
1 2 3≢⍳3<br />
0</pre></apll><br />
<br />
<br />
{{Article footer}}<br />
{{Symbol footer|4|M}}<br />
[[Category:Boolean Functions]]<br />
[[Category:Dyadic Functions]]</div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=Matrix_Inverse/Divide&diff=3169Matrix Inverse/Divide2018-04-15T22:56:55Z<p>Sudleyplace: </p>
<hr />
<div><table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td valign="top"><apll>Z←⌹R</apll></td><br />
<td></td><br />
<td></td><br />
<td>returns the inverse of the right argument.</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<tr><br />
<td><apll>R</apll> is a numeric scalar, vector or matrix; otherwise signal a <apll>RANK ERROR</apll>. If <apll>R</apll> is a matrix, <apll>≥/⍴R</apll> must be true; otherwise signal a <apll>LENGTH ERROR</apll>.</td><br />
</tr><br />
<tr><br />
<td><apll>Z</apll> is a numeric array of rank <apll>⍴⍴R</apll>, and shape <apll>⌽⍴R</apll>.</td><br />
</tr><br />
</table><br />
<br /><br />
<p>This feature implements matrix inversion on integer or floating point arguments using [http://www.gnu.org/software/gsl/manual/html_node/Singular-Value-Decomposition.html Singular Value Decomposition]. In particular, this means that any numeric array meeting the rank and shape requirements above is invertible.</p><br />
<br />
<p>Matrix inverse (<apll>⌹R</apll>) and matrix division (<apll>L⌹R</apll>) on Rational or VFP arguments each have two limitations above and beyond that of normal conformability:</p><br />
<ul><br />
<li><p>for a square right argument that it be non-singular, and</p></li><br />
<li><p>for an overdetermined (<apll>&gt;/⍴R</apll>) right argument that the symmetric matrix <apll>(⍉R)+.×R</apll> be non-singular.</p></li><br />
</ul><br />
<p>These limitations are due to the algorithm ([http://en.wikipedia.org/wiki/Gauss%E2%80%93Jordan_elimination Gauss-Jordan Elimination]) used to implement Matrix Inverse/Divide on Rational and VFP numbers.</p><br />
<br />
<p>For example,</p><br />
<br />
<apll><pre><br />
⌹3 3{rho}0<br />
0 0 0<br />
0 0 0<br />
0 0 0<br />
⌹3 3⍴1 2 3 4<br />
¯0.1944444444 0.2777777778 0.02777777778<br />
0.05555555556 ¯0.2222222222 0.2777777778<br />
0.3611111111 0.05555555556 ¯0.1944444444<br />
⌹3 3⍴1 2 3 4<pn>x</pn><br />
¯7<pn>r</pn>36 5<pn>r</pn>18 1<pn>r</pn>36<br />
1<pn>r</pn>18 ¯2<pn>r</pn>9 5<pn>r</pn>18<br />
13<pn>r</pn>36 1<pn>r</pn>18 ¯7<pn>r</pn>36<br />
</pre></apll><br />
<br />
<br />
<table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td valign="top"><apll>Z←L⌹R</apll></td><br />
<td></td><br />
<td></td><br />
<td>returns the quotient of the left and right arguments. This quotient can be interpreted in various ways, such as the least squares solution of the system of linear equations determined by arguments.</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<tr><br />
<td><apll>L</apll> is a numeric scalar, vector or matrix; otherwise signal a <apll>RANK ERROR</apll>.</td><br />
</tr><br />
<tr><br />
<td><apll>R</apll> is a numeric scalar, vector or matrix; otherwise signal a <apll>RANK ERROR</apll>.</td><br />
</tr><br />
<tr><br />
<td>If either <apll>L</apll> or <apll>R</apll> is a scalar or vector, it is coerced to a matrix by <apll>(L R)←⍪{each}L R</apll>. After this coercion, if the two matrices have a different number of rows, signal a <apll>LENGTH ERROR</apll>.</td><br />
</tr><br />
<tr><br />
<td><apll>Z</apll> is a numeric array. Before the above coercion of <apll>L</apll> and <apll>R</apll>, the rank of <apll>Z</apll> is <apll>¯2+2⌈(⍴⍴L)+⍴⍴R</apll>, and the shape is <apll>(1↓⍴R),1↓⍴L</apll>.</td><br />
</tr><br />
</table><br />
<br /><br />
<p>This feature implements matrix division on integers and floating point arguments using [http://www.gnu.org/software/gsl/manual/html_node/Singular-Value-Decomposition.html Singular Value Decomposition]. In particular, this means that any two numeric arrays meeting the rank and shape requirements above are divisible.</p><br />
<br />
<p>As noted above, Matrix Division on Rational or VFP arguments uses a different algorithm and has slightly more restrictive conformability requirements.</p><br />
<br />
<p>For example,</p><br />
<br />
<apll><pre><br />
a←3 3⍴0<br />
a⌹a<br />
0 0 0<br />
0 0 0<br />
0 0 0<br />
1 2 3⌹3 3⍴1 2 3 4<br />
0.4444444444 0.4444444444 ¯0.1111111111<br />
1 2 3⌹3 3⍴1 2 3 4<pn>x</pn><br />
4<pn>r</pn>9 4<pn>r</pn>9 ¯1<pn>r</pn>9</pre></apll><br />
<br />
<hr width=35%><br><br />
<br />
<big>For several more everyday problem-solving examples using Matrix Inverse see also '''[[Symbol_Domino|Domino Symbol ⌹]]'''.</big><br />
<br />
<br><hr width=35%><br />
<br />
{{Language Toolbar}}</div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=Indices&diff=3168Indices2018-04-15T22:49:10Z<p>Sudleyplace: </p>
<hr />
<div><table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td valign="top"><apll>Z←⍸R</apll></td><br />
<td></td><br />
<td></td><br />
<td>returns a simple integer vector or nested vector of integer vectors identical to <apll>(,R)/,⍳⍴R</apll>.</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<tr><br />
<td><apll>R</apll> is a simple array of non-negative integers.</td><br />
</tr><br />
<tr><br />
<td>For vector <apll>R</apll>, <apll>Z</apll> is an integer vector. For all other ranks of <apll>R</apll>, <apll>Z</apll> is a nested vector of integer vectors. In both case the length of <apll>Z</apll> is <apll>+/,R</apll>.</td><br />
</tr><br />
<tr><br />
<td>For scalars or vectors, the result is equivalent to <apll>R/⍳⍴R</apll> which encapsulates a very common idiom in one symbol.</td><br />
</tr><br />
<tr><br />
<td>For higher rank arrays, the result extends to produce a nested vector of vectors of the indices of all the positive integer elements of <apll>R</apll> replicated as per the corresponding value in <apll>R</apll>.</td><br />
</tr><br />
<tr><br />
<td>This function is sensitive to <apll>⎕IO</apll>.</td><br />
</tr><br />
</table><br />
<br /><br />
<p>For example, in origin-0</p><br />
<br />
<apll><pre><br />
⍸,3<br />
0 0 0<br />
⍬⍬⍬≡⍸3 ⍝ for scalar S, ⍸S ←→ S⍴⊂⍬ as per the definition R/⍳⍴R<br />
1<br />
⍬≡⍸⍬<br />
1<br />
⍸1 0 1 1 1 0 1<br />
0 2 3 4 6<br />
⍸'Now is the time'=' '<br />
3 6 10<br />
⍸2 3 4<br />
0 0 1 1 1 2 2 2 2<br />
⍸⎕←2 3⍴⍳4<br />
0 1 2<br />
3 0 1<br />
0 1 0 2 0 2 1 0 1 0 1 0 1 2<br />
⍸1 2 3⍴⍳4<br />
0 0 1 0 0 2 0 0 2 0 1 0 0 1 0 0 1 0 0 1 2<br />
<br />
∇ Z←(Txt Rep) txtrep Z;a<br />
[1] ⍝ Replace Txt in Z with Rep.<br />
[2] :Assert 2=⍴⍴Z ⋄ :Assert (⍴Txt)≡⍴Rep<br />
[3] a←⍸Txt⍷Z<br />
[4] Z[⊃⊃¨,¨/¨a+⊂0(0..¯1+⍴Txt)]←((⍴a),⍴Rep)⍴Rep<br />
∇<br />
'Now' 'Who' txtrep 4 13⍴'Now is the time...'<br />
Who is the ti<br />
me...Who is t<br />
he time...Who<br />
is the time.</pre></apll></div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=Indexing&diff=3167Indexing2018-04-15T22:41:25Z<p>Sudleyplace: </p>
<hr />
<div><table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td valign="top"><apll>Z←R[L]</apll>, <apll>R[L]←A</apll>, and <apll>R[L]<i>f</i>←A</apll></td><br />
<td></td><br />
<td></td><br />
<td>are all extended to allow both <b>Reach</b> and <b>Scatter</b> indexing.</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<tr><br />
<td><apll>L</apll> is a nested array of integer scalars and/or vectors, suitable for indexing <apll>R</apll>.</td><br />
</tr><br />
<tr><br />
<td><apll>R</apll> is an arbitrary array.</td><br />
</tr><br />
<tr><br />
<td><apll>A</apll> is an arbitrary array.</td><br />
</tr><br />
<tr><br />
<td><table border="0" cellpadding="0" cellspacing="0" summary=""><br />
<tr><br />
<td><b>Reach Indexing</b>:&nbsp;&nbsp;</td><br />
<td>If <apll>L⊃R</apll> is valid, it is equivalent to <apll>⊃R[⊂L]</apll>, and</td><br />
</tr><br />
<tr><br />
<td></td><br />
<td>if <apll>L⊃¨⊂R</apll> is valid, it is equivalent to <apll>R[L]</apll></td><br />
</tr><br />
<tr><br />
<td><b>Scatter Indexing</b>:&nbsp;&nbsp;</td><br />
<td>If <apll>L⌷R</apll> is valid, it is equivalent to <apll>R[⊃∘.,/L]</apll>, and</td><br />
<tr><br />
<td></td><br />
<td>if <apll>L⌷¨⊂R</apll> is valid, it is equivalent to <apll>⊂¨R[⊂¨L]</apll></td><br />
</tr> <br />
</table><br />
</tr><br />
<tr><br />
<td>Both Reach and Scatter indexing may appear together within a single instance of <apll>R[L]</apll>, <apll>R[L]←A</apll>, and <apll>R[L]<i>f</i>←A</apll></td><br />
</tr><br />
<tr><br />
<td>These functions are sensitive to <apll>⎕IO</apll>.</td><br />
</tr><br />
</table><br />
<br /><br />
<p>For example, in origin-1</p><br />
<br />
<apll><pre><br />
V←'123'(⊂4 5)<br />
V[1 (2 ⍬ 1)]<br />
123 4<br />
M←2 2⍴(10 20) (30 40 'abc') 50 60<br />
M[(1 1)((1 2) 3)]<br />
10 20 abc</pre></apll><br />
<table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td valign="top"><apll>Z←R[L]</apll>, <apll>R[L]←A</apll>, <apll>R[L]<i>f</i>←A</apll>, <apll>L⌷R</apll>, <apll>L⍉R</apll>, and <apll>L⊃R</apll></td><br />
<td></td><br />
<td></td><br />
<td>are all extended to allow negative values in <apll>L</apll>.</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<tr><br />
<td>For all but transpose, <apll>L</apll> is a nested array of integer scalars and/or vectors, suitable for indexing <apll>R</apll>; for transpose, <apll>L</apll> is an integer scalar or vector of integers, suitable for transposing <apll>R</apll>.</td><br />
</tr><br />
<tr><br />
<td>That is, if the largest allowed value for <apll>L</apll> is <apll>N</apll>, then the previous allowable range of values was <apll>⎕IO</apll> to <apll>N</apll>, inclusive. Now, the allowable range of values is <apll>1 ¯1[1]-N</apll> to <apll>N</apll>, inclusive. For example, <apll>A</apll>, <apll>A[⍳⍴A]</apll>, <apll>A[⍳-⍴A]</apll>, and even <apll>A[⍳¯1 1[?(⍴⍴A)⍴2]×⍴A]</apll> are all identical for any array <apll>A</apll> in either origin.<br />Also, <apll>A</apll>, <apll>(⍳⍴⍴A)⍉A</apll>, and <apll>(⍳-⍴⍴A)⍉A</apll> are all identical for any array <apll>A</apll> in either origin.</td><br />
</tr><br />
<tr><br />
<td><apll>R</apll> is an arbitrary array.</td><br />
</tr><br />
<tr><br />
<td><apll>A</apll> is an arbitrary array.</td><br />
</tr><br />
<tr><br />
<td>These functions are sensitive to <apll>⎕IO</apll>. Negative indexing is available only when the first element of <apll>⎕FEATURE</apll> is set to <apll>1</apll>.</td><br />
</tr><br />
</table><br />
<br /><br />
<p>For example, in origin-1</p><br />
<br />
<apll><pre><br />
⎕FEATURE[1]←1<br />
V←'123'(⊂4 5)<br />
V[¯1 (0 ⍬ ¯1)]<br />
123 4</pre></apll></div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=Index_Of&diff=3166Index Of2018-04-15T22:33:33Z<p>Sudleyplace: </p>
<hr />
<div><table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td valign="top"><apll>Z←L⍳R</apll></td><br />
<td></td><br />
<td></td><br />
<td>returns a nested array of indices suitable to indexing <apll>L</apll>.</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<tr><br />
<td><apll>L</apll> is an array of rank not equal 1.</td><br />
</tr><br />
<tr><br />
<td><apll>R</apll> is an arbitrary array.</td><br />
</tr><br />
<tr><br />
<td><apll>Z</apll> is a nested array of shape <apll>⍴R</apll> whose items are each integer vectors of length <apll>⍴⍴L</apll>, suitable for use as indices to <apll>L</apll>, except for where the item in <apll>R</apll> is not found in <apll>L</apll>, in which case the corresponding item in <apll>Z</apll> is <apll>⎕IO+⍴L</apll>.</td><br />
</tr><br />
<tr><br />
<td>This feature extends dyadic iota to non-vector left arguments.</td><br />
</tr><br />
<tr><br />
<td>This function is sensitive to <apll>⎕IO</apll> and <apll>⎕CT</apll>.</td><br />
</tr><br />
</table><br />
<br /><br />
<p>For example, in origin-1</p><br />
<br />
<apll><pre><br />
M←2 3⍴'abcdef'<br />
M⍳'afg'<br />
1 1 2 3 3 4<br />
M[M⍳'af']<br />
af<br />
L←2 ⋄ ⎕FMT L⍳⍳3<br />
┌3──────────┐<br />
│┌0┐ ┌0┐ ┌0┐│<br />
││0│ │0│ │0││<br />
│└~┘ └~┘ └~┘2<br />
└∊──────────┘</pre></apll><br />
<br />
<p>Note that this extension preserves the identity <apll>R≡L[L⍳R]</apll> for all <apll>R⊆L</apll>.</p><br />
<br />
<p>This extension is implemented via an internal magic function:</p><br />
<br />
<apll><pre><br />
∇ Z←L #DydIota R;⎕IO;O<br />
[1] O←⎕IO ⋄ ⎕IO←0<br />
[2] Z←⊂[0] O+(1+⍴L)⊤(¯1↓,(1+⍴L)↑L)⍳R<br />
∇</pre></apll></div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=Find&diff=3165Find2018-04-15T22:28:57Z<p>Sudleyplace: </p>
<hr />
<div><table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td valign="top"><apll>Z←L⍷R</apll></td><br />
<td></td><br />
<td></td><br />
<td>finds the matches of <apll>L</apll> in <apll>R</apll>.</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<tr><br />
<td><apll>L</apll> and <apll>R</apll> are arbitrary arrays of any rank, shape, or datatype.<br />
But to be useful,<br />
<ul><br />
<li>the rank of <apll>L</apll> should not be more than the rank of <apll>R</apll></li><br />
<li>the shape of <apll>L</apll> padded with enough leading <apll>1</apll>s to equal the rank of <apll>R</apll> should be less than or equal to the shape of <apll>R</apll></li><br />
<li>both arguments should have the same type (either both character or both numeric)</li><br />
</ul><br />
otherwise the result is all zero.</td><br />
</tr><br />
<tr><br />
<td><apll>Z</apll> is a Boolean array of the same rank and shape as <apll>R</apll> where each <apll>1</apll> represents the upper left corner of a place in <apll>R</apll> of a match with <apll>L</apll>.<br />
</td><br />
</tr><br />
</table><br />
<br />
<br />
If <apll>L</apll> is a scalar, then <apll>L⍷R ←→ R∊L</apll>.<br />
<br />
If <apll>L</apll> is not a scalar, then it represents a contiguous pattern,<br />
which may or may not be found in one or more places in <apll>R</apll>.<br />
<br />
If the arguments are numeric, then the result is sensitive to <apll>⎕CT</apll>.<br />
<br />
For example:<br />
<br />
<apll><pre><br />
R←3 8⍴'thirteenfourteenfifteen '<br />
R<br />
thirteen<br />
fourteen<br />
fifteen<br />
't'⍷R<br />
1 0 0 0 1 0 0 0<br />
0 0 0 0 1 0 0 0<br />
0 0 0 1 0 0 0 0<br />
'teen'⍷R<br />
0 0 0 0 1 0 0 0<br />
0 0 0 0 1 0 0 0<br />
0 0 0 1 0 0 0 0<br />
(2 4⍴'teen')⍷R<br />
0 0 0 0 1 0 0 0<br />
0 0 0 0 0 0 0 0<br />
0 0 0 0 0 0 0 0<br />
</pre></apll></div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=Dilate&diff=3163Dilate2018-04-15T21:13:58Z<p>Sudleyplace: </p>
<hr />
<div><table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td valign="top"><apll>Z←&gt;R</apll> &nbsp;&nbsp; or &nbsp;&nbsp; <apll>Z←&gt;[X] R</apll></td><br />
<td></td><br />
<td></td><br />
<td>extracts from <apll>R</apll> its Hypercomplex coefficients.</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<tr><br />
<td><apll>X</apll> is an optional numeric singleton axis with <apll>X∊⍳1+⍴⍴R</apll>. If <apll>[X]</apll> is omitted, the operation applies to the last axis plus one.</td><br />
</tr><br />
<tr><br />
<td><apll>R</apll> is an arbitrary Real or Hypercomplex numeric array &mdash; otherwise, <apll>DOMAIN ERROR</apll>.</td><br />
</tr><br />
<tr><br />
<td><apll>Z</apll> is the corresponding array of Real numbers of shape <apll>((=R),⍴R)[⍋⍋X≠⍳1+⍴⍴R]</apll> where <apll>=R</apll> is the Hypercomplex dimension of <apll>R</apll> as in <apll>(=R)∊1 2 4 8</apll>.</td><br />
</tr><br />
</table><br />
<br /><br />
<p>For example,</p><br />
<br />
<apll><pre><br />
⍴⎕←&gt;23<br />
23<br />
1<br />
⍴⎕←&gt;[1] 23<br />
23<br />
1<br />
⍴⎕←&gt;2 2⍴⍳4<br />
1<br />
2<br />
<br />
3<br />
4<br />
2 2 1<br />
⍴⎕←&gt;2 2⍴1<hc>J</hc>2 3<hc>J</hc>4 4<hc>J</hc>3 2<hc>J</hc>1<br />
1 2<br />
3 4<br />
<br />
4 3<br />
2 1<br />
2 2 2<br />
⍴⎕←>[1] 2 2⍴1<hc>J</hc>2 3<hc>J</hc>4 4<hc>J</hc>3 2<hc>J</hc>1<br />
1 3<br />
4 2<br />
<br />
2 4<br />
3 1<br />
2 2 2<br />
⍴⎕←&gt;2 2⍴1<hc>i</hc>2<hc>j</hc>3<hc>k</hc>4 5<hc>i</hc>6<hc>j</hc>7<hc>k</hc>8 8<hc>i</hc>7<hc>j</hc>6<hc>k</hc>5 4<hc>i</hc>3<hc>j</hc>2<hc>k</hc>1<br />
1 2 3 4<br />
5 6 7 8<br />
<br />
8 7 6 5<br />
4 3 2 1<br />
2 2 4 <br />
⍴⎕←&gt;2 2⍴1<hc>i</hc>2<hc>j</hc>3<hc>k</hc>4<hc>l</hc>5<hc>ij</hc>6<hc>jk</hc>7<hc>kl</hc>8 9<hc>i</hc>10<hc>j</hc>11<hc>k</hc>12<hc>l</hc>13<hc>ij</hc>14<hc>jk</hc>15<hc>kl</hc>16 16<hc>i</hc>15<hc>j</hc>14<hc>k</hc>13<hc>l</hc>12<hc>ij</hc>11<hc>jk</hc>10<hc>kl</hc>9 8<hc>i</hc>7<hc>j</hc>6<hc>k</hc>5<hc>l</hc>4<hc>ij</hc>3<hc>jk</hc>2<hc>kl</hc>1<br />
1 2 3 4 5 6 7 8<br />
9 10 11 12 13 14 15 16<br />
<br />
16 15 14 13 12 11 10 9<br />
8 7 6 5 4 3 2 1<br />
2 2 8<br />
</pre></apll><br />
<br />
==Identities==<br />
<br />
<apll> R ←→ &lt; &gt; R</apll> &nbsp;&nbsp;for all <apll>R</apll> (see [[Condense]] for the definition of monadic Left Caret)<br /><br />
<apll> R ←→ &lt;[X] &gt;[X] R</apll> &nbsp;&nbsp;for all <apll>R</apll><br /><br />
<apll> R ←→ &gt; &lt; R</apll> &nbsp;&nbsp;for all <apll>R</apll> with <apll>(¯1↑⍴ R)∊1 2 4 8</apll><br /><br />
<apll>1/R ←→ &gt; &lt; R</apll> &nbsp;&nbsp;for all <apll>R</apll> with <apll>(¯1↑⍴1/R)∊1 2 4 8</apll><br /><br />
<apll> R ←→ &gt;[X] &lt;[X] R</apll> &nbsp;&nbsp;for all non-scalar <apll>R</apll> with <apll>(⍴R)[X]∊1 2 4 8</apll><br />
<br />
== Acknowledgements==<br />
<br />
<p>This symbol and its name were suggested by David A. Rabenhorst.</p></div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=Array_Lookup&diff=3162Array Lookup2018-04-15T20:16:18Z<p>Sudleyplace: </p>
<hr />
<div><table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td valign="top"><apll>Z←L⍸R</apll></td><br />
<td></td><br />
<td></td><br />
<td>returns a simple integer vector identical to <apll>(⊂⍤¯1 L)⍳⊂⍤(¯1+⍴⍴L) R</apll>.</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<tr><br />
<td><apll>L</apll> and <apll>R</apll> are arbitrary arrays.</td><br />
</tr><br />
<tr><br />
<td><apll>Z</apll> is an array of rank <apll>0⌈1+(⍴⍴R)-⍴⍴L</apll> and shape <apll>(1-⍴⍴L)↓⍴R</apll>.</td><br />
</tr><br />
<tr><br />
<td>For matrices, the result is equivalent to <apll>(⊂[2] L)⍳⊂[2] R</apll> (lookup the rows of one array in another) which encapsulates a common idiom in one symbol.</td><br />
</tr><br />
<tr><br />
<td>For higher rank arrays, the arguments are enclosed to become vectors of subarrays and then the usual lookup produces the final result.</td><br />
</tr><br />
<tr><br />
<td>This function is sensitive to both <apll>⎕IO</apll> and <apll>⎕CT</apll>.</td><br />
</tr><br />
</table><br />
<br /><br />
<p>For example, in origin-1</p><br />
<br />
<apll><pre><br />
⎕←L←6 4⍴'DinaDickJohnJaneSue Mary<br />
Dina<br />
Dick<br />
John<br />
Jane<br />
Sue <br />
Mary<br />
⎕←R←3 4⍴'JaneBob Sue '<br /><br />
Jane<br />
Bob <br />
Sue <br />
L⍸R<br />
4 7 5</pre></apll><br />
<br />
<p>This function was suggested by the language designers of Dyalog APL.</p></div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=Anonymous_Functions/Operators/Hyperators&diff=3161Anonymous Functions/Operators/Hyperators2018-04-15T20:13:51Z<p>Sudleyplace: </p>
<hr />
<div>Anonymous functions and operators (AFOs) are a one- or multi-line grouping of one or more statements all enclosed in braces such as <apll>{(+⌿⍵)÷≢⍵}</apll>. This syntax is useful for one- or multi-line functions and operators to complement the existing definition types of [[User-Defined_Functions/Operators|user-defined]]: <apll>∇ Z←avg R</apll>, [[Trains|trains]]: <apll>(+⌿ ÷ ≢)</apll>, and derived: <apll>,∘⍋∘⍋∘,</apll>.<br />
<br />
These objects may be named as in <apll>avg←{(+⌿⍵)÷≢⍵}</apll>, and named or unnamed may be used in place of any APL function (primitive, operator operand, derived, train, user-defined) including within another AFO.<br />
<br />
== Function Arguments ==<br />
<br />
To define an anonymous function, use <apll>⍺</apll> as the (optional) left argument, <apll>∇</apll> as the name of the anonymous function (for [[#Recursion|recursion]]), and <apll>⍵</apll> as the name of the right argument. For example,<br />
<br />
<apll><pre><br />
3 5{√+/⍺ ⍵*2}4 12 ⍝ Pythagorean theorem<br />
5 13<br />
{s←(+/⍵)÷2 ⋄ √×/s-0,⍵}3 4 5 ⍝ Heron's formula for triangle area<br />
6</pre></apll><br />
<br />
== Operator Operands ==<br />
<br />
To define an anonymous operator, use the above special names along with <apll>⍺⍺</apll> as the name of the left operand, <apll>∇∇</apll> as the name of the operator (for [[#Recursion|recursion]]), and <apll>⍵⍵</apll> as the name of the (optional) right operand. If neither <apll>⍺⍺</apll> nor <apll>⍵⍵</apll> appears as a token between the braces and outside of character constants, then the object is a function, not an operator. For example,<br />
<br />
<table cellpadding="0" cellspacing="0" style="border-collapse: separate; border-spacing: 5em 0px;"><br />
<br />
<tr><br />
<td colspan="7"><br />
<apll>f←{∘.⍺⍺⍨⍳⍵}</apll><br />
</td><br />
</tr><br />
<br />
<tr><br />
<td><br />
<apll> =f 4<br />
1 0 0 0<br />
0 1 0 0<br />
0 0 1 0<br />
0 0 0 1</apll><br />
</td><br />
<br />
<td><br />
<apll> ⌈f 4<br />
1 2 3 4<br />
2 2 3 4<br />
3 3 3 4<br />
4 4 4 4</apll><br />
</td><br />
<br />
<td><br />
<apll> *f 4<br />
1 1 1 1<br />
2 4 8 16<br />
3 9 27 81<br />
4 16 64 256</apll><br />
</td><br />
<br />
<td><br />
<apll> ≤f 4<br />
1 1 1 1<br />
0 1 1 1<br />
0 0 1 1<br />
0 0 0 1</apll><br />
</td><br />
</tr><br />
</table><br />
<br />
== Ambivalent AFOs ==<br />
<br />
User-defined functions/operators allow you to specify in their headers that the left argument is optional by enclosing it in braces, as in <apll>∇ Z←{L} foo R</apll>, and to test for the presence or absence of the optional argument using <apll>0=⎕NC 'L'</apll>.<br />
<br />
This behavior is also available to AFOs by including a statement that assigns a value to <apll>⍺</apll>. If <apll>⍺</apll> does not have a value when that statement is encountered, the statement is executed; otherwise, that entire statement is ignored including any side effects. This behavior obviates the need to use <apll>0=⎕NC '⍺'</apll> to test for a value in <apll>⍺</apll>. It also means that as a consequence of this rule, regardless of how the AFO is called, any second or subsequent statements that assign a value to <apll>⍺</apll> are always ignored.<br />
<br />
For example,<br />
<br />
<apll><pre><br />
f←{⍺←2 ⋄ ⍺√⍵}<br />
f 16<br />
4<br />
3 f 27<br />
3<br />
f←{⎕←⍺←⍵ ⋄ (⍳⍺)∘.⍺⍺⍳⍵}<br />
⌊f 4<br />
4<br />
1 1 1 1<br />
1 2 2 2<br />
1 2 3 3<br />
1 2 3 4<br />
3⌊f 4<br />
1 1 1 1<br />
1 2 2 2<br />
1 2 3 3<br />
f←{⎕←⍺←9 ⋄ ⎕←⍺←0 ⋄ ⍺+⍵}<br />
4 f 12 ⍝ Both assignments of ⍺ ignored<br />
16<br />
f 12 ⍝ Second assignment of ⍺ ignored<br />
9<br />
21</pre></apll><br />
<br />
== Valences ==<br />
<br />
An AFO may be<br />
<br />
* Ambivalent (must be called with either one or two arguments),<br />
* Dyadic (must be called with two arguments),<br />
* Monadic (must be called with one argument), or<br />
* Niladic (must be called with no arguments),<br />
<br />
depending upon which of the special symbols are present in its definition.<br />
<br />
Disregarding special symbols inside of character constants and/or comments<br />
<br />
* For anonymous functions (and operators):<br />
** If <apll>⍺←</apll> appears as a sequence of tokens, then the (derived) function is ambivalent,<br />
** Otherwise, if <apll>⍺</apll> appears as a token, the (derived) function is dyadic,<br />
** Otherwise, if <apll>⍵</apll> appears as a token, the (derived) function is monadic,<br />
** Otherwise, if neither <apll>⍺</apll> nor <apll>⍵</apll> appears as a token, the (derived) function is niladic.<br />
* For anonymous operators only:<br />
** If <apll>⍵⍵</apll> appears as a token, the operator is dyadic (must be called with two operands &mdash; left and right),<br />
** Otherwise, if <apll>⍺⍺</apll> appears as a token, the operator is monadic (must be called with one operand &mdash; left only).<br />
<br />
For example,<br />
<br />
<apll><pre><br />
{⍵}2<br />
2<br />
1{⍵}2<br />
VALENCE ERROR<br />
1{⍵}2<br />
^<br />
1{⍺+⍵}2<br />
3<br />
{⍺+⍵}2<br />
VALENCE ERROR<br />
{⍺+⍵}2<br />
∧<br />
{⍺←2 ⋄ ⍺+⍵}2&nbsp;&nbsp;⍝ Ambivalent function, monadic with default left argument 2<br />
4<br />
3{⍺←2 ⋄ ⍺+⍵}2&nbsp;⍝ Ambivalent function, dyadic with left argument 3<br />
5<br />
{⍳3} ⍝ A three-element simple vector<br />
1 2 3<br />
{⍳3}23 ⍝ A two-element nested vector<br />
1 2 3 23<br />
12{⍳3}23 ⍝ A three-element nested vector<br />
12 1 2 3 23<br />
3{∘.=⍨⍳⍺⍺} ⍝ A niladic derived function from a monadic operator<br />
1 0 0<br />
0 1 0<br />
0 0 1</pre></apll><br />
<br />
== Multi-Line AFOs ==<br />
<br />
An AFO may be defined on multiple lines (just like User-Defined Functions/Operators) by first naming it (e.g. <apll>h←{s←(+/⍵)÷2 ⋄ √×/s-0,⍵}</apll>), and then editing it in the usual way (e.g., <apll>∇h</apll>). For more details, see [[Function_Editing|Function Editing]].<br />
<br />
== Guards ==<br />
<br />
[http://en.wikipedia.org/wiki/Guard_%28computer_science%29 Guards] are used to test for a condition and execute a statement or not depending upon the value of the conditional expression. This behavior is identical to the [[Control_Structures|control structure]]<br />
<br />
<apll>:if Cond ⋄ CondStmt ⋄ :return ⋄ :end</apll><br />
<br />
Guards appear as a Boolean-valued APL expression (<apll>Cond</apll>) followed by a colon, followed by a single APL statement (<apll>CondStmt</apll>) as in<br />
<br />
<apll>{... ⋄ Cond:CondStmt ⋄ ....}</apll><br />
<br />
which executes <apll>CondStmt</apll> and terminates the AFO if and only if <apll>Cond</apll> evaluates to TRUE (<apll>1</apll>).<br />
<br />
For example,<br />
<br />
<apll>{... ⋄ 0∊⍴⍵:'empty right argument' ⋄ ....}</apll><br />
<br />
As many guard statements may appear in an AFO as desired. They are executed in turn until one of them evaluates to TRUE, at which time the statement following the colon is executed and the function terminates with any result of that conditional statement as the result of the AFO.<br />
<br />
If <apll>Cond</apll> does not evaluate to a Boolean-valued scalar or one-element vector, a <apll>RANK</apll>, <apll>LENGTH</apll>, or <apll>DOMAIN ERROR</apll> is signalled, as appropriate.<br />
<br />
If the rightmost statement is executed and it is a guard statement whose <apll>Cond</apll> evaluates to FALSE (<apll>0</apll>), the AFO terminates with no value; if the result of that AFO is assigned, a <apll>VALUE ERROR</apll> is signalled.<br />
<br />
== Shy Results ==<br />
<br />
A "shy" result is any result that doesn't automatically display its value, a simple example of which is <apll>L←⍳3</apll>: the result is <apll>⍳3</apll> (as evidenced by the extension to <apll>3+L←⍳3</apll>), but because it has been assigned to a name, the result doesn't automatically display. Other ways to produce a shy result are to use the [[Sink]] syntax <apll>←⍳3</apll>, or to call a [[User-Defined_Functions/Operators#Shy|user-defined function]] that declares in its header that the result is shy as in <apll>∇ {Z}←foo R</apll>.<br />
<br />
A shy result propagates up the chain of results just as it does through the Execute primitive. That is, if the last statement executed has a shy result, the result of Execute is shy, too.<br />
<br />
Typically, <apll>⎕←</apll> is used to expose a shy result.<br />
<br />
AFOs also may have shy results by virtue of the final result being<br />
* [[Sink|Sinked]],<br />
* Assigned to a name, or<br />
* From a shy user-defined function.<br />
<br />
For example,<br />
<br />
<apll><pre><br />
{←⍳3}<br />
⎕←{←⍳3}<br />
1 2 3<br />
{L←⍳3}<br />
⎕←{L←⍳3}<br />
1 2 3</pre></apll><br />
<br />
Ordinarily, a shy result doesn't terminate the AFO, as in<br />
<br />
<apll><pre><br />
{←⍳3 ⋄ 'abc'}<br />
abc</pre></apll><br />
<br />
To force termination, precede the assignment with a guard as in<br />
<br />
<apll>{⍵=0:←'Zero' ⋄ ⍵>0:←'Positive' ⋄ ←'Negative'} R</apll><br />
<br />
which terminates with a shy result in all three cases.<br />
<br />
== Localization ==<br />
<br />
Unlike user-defined functions, in AFOs all names to which an assignment is made are automatically localized. As a result, a direct assignment inside an AFO cannot affect the value of a name defined higher up in the execution chain '''unless''' it is made via a user-defined function or the Execute primitive as in<br />
<br />
<apll><pre><br />
L←⍳9 ⋄ {L←"abc" ⋄ ⍵}23<br />
23<br />
L<br />
1 2 3 4 5 6 7 8 9<br />
L←⍳9 ⋄ {⍎'L←"abc"' ⋄ ⍵}23<br />
23<br />
L<br />
abc</pre></apll><br />
<br />
== Scoping ==<br />
<br />
When calls to user-defined functions are nested, a reference to a name by an inner function is resolved by looking up the chain of nested functions for the nearest level at which that name is localized. Looked at from a different perspective, when a name is localized to a function, its scope consists of all functions called by that function. This is called '''dynamic scoping'''.<br />
<br />
AFOs use a different mechanism where names referenced by an AFO are resolved by the context in which the AFO is defined, not where it is used. This is called '''lexical scoping''' or '''static scoping'''.<br />
<br />
In other words, to paraphrase [http://en.wikipedia.org/wiki/Scope_%28computer_science%29#Lexical_scoping_and_dynamic_scoping Wikipedia], "This means that if function <apll>f</apll> invokes function <apll>g</apll> that is defined outside the context of <apll>f</apll>, then under lexical scoping, function <apll>g</apll> does not have access to <apll>f</apll>'s local variables (since the definition of <apll>g</apll> is not inside the definition of <apll>f</apll>), while under dynamic scoping, function <apll>g</apll> does have access to <apll>f</apll>'s local variables (since the invocation of <apll>g</apll> is inside the invocation of <apll>f</apll>)".<br />
<br />
For example,<br />
<br />
<apll><pre><br />
∇ foo;f g a<br />
[1] a←'static'<br />
[2] ←⎕fx 'f R;a' 'a←"dynamic"' 'g R'<br />
[3] ←⎕fx 'g R' '"scope ←→ ",a'<br />
[4] f 'a'<br />
∇<br />
<br />
foo<br />
scope ←→ dynamic<br />
{a←'static' ⋄ f←{a←'dynamic' ⋄ g ⍵} ⋄ g←{'scope ←→ ',a ⋄ ⍵} ⋄ f 'a'}<br />
scope ←→ static<br />
</pre></apll><br />
<br />
== Recursion ==<br />
<br />
AFOs may be called recursively, but because they might be unnamed (i.e., anonymous), the <apll>∇</apll> symbol is used to name the AFO.<br />
<br />
For example, with anonymous functions,<br />
<br />
<apll><pre><br />
⍝ Fibonacci sequence algorithm<br />
f←{⍺←10 ⋄ ⍺=1:⍵ ⋄ (⍺-1)∇⍵,+/¯2↑⍵}<br />
f 1<br />
1 1 2 3 5 8 13 21 34 55<br />
;20 f 1<br />
1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765<br />
⍝ Euclidean algorithm for Greatest Common Divisor<br />
12 {⍺=0:|⍵ ⋄ (⍵|⍺)∇⍺} 8<br />
4</pre></apll><br />
<br />
With anonymous operators, <apll>∇</apll> references the derived function with its operand(s) already bound, and <apll>∇∇</apll> references the operator itself with its operand(s) yet to be bound. That is, for monadic anonymous operators <apll>∇ ←→ ⍺⍺∇∇</apll>, and for dyadic anonymous operators <apll>∇ ←→ ⍺⍺∇∇⍵⍵</apll>.<br />
<br />
For example, with anonymous operators,<br />
<br />
<apll><pre><br />
⍝ Generalized definition of vector reduction<br />
f←{0=⍴⍵:⍺⍺/0⍴⍵ ⋄ 1=⍴⍵:⊂↑⍵ ⋄ ⊂(↑⍵)⍺⍺ ⊃∇1↓⍵}<br />
+f⍳4<br />
10<br />
×f⍳4<br />
24<br />
+f(1 2)(3 4)<br />
4 6</pre></apll><br />
<br />
A more advanced example of recursion of an anonymous operator is [http://en.wikipedia.org/wiki/Hyperoperation hyperoperation] expressed below as a monadic operator where its operand <apll>N</apll> indexes successively more powerful functions as derived functions:<br />
* <apll>N=0</apll> is the successor function (i.e., adds <apll>1</apll> to <apll>⍵</apll>),<br />
* <apll>N=1</apll> is the addition function of <apll>⍺</apll> to <apll>⍵</apll>, i.e. the successor function on <apll>⍺</apll> repeated <apll>⍵</apll> times &mdash; <apll>⍺+⍵</apll>,<br />
* <apll>N=2</apll> is the multiplication function of <apll>⍺</apll> by <apll>⍵</apll>, i.e. the addition function on <apll>⍺</apll> repeated <apll>⍵</apll> times &mdash; <apll>+/⍵⍴a ←→ ⍺×⍵</apll>,<br />
* <apll>N=3</apll> is the exponentiation function of <apll>⍺</apll> to the power <apll>⍵</apll>, i.e. the multiplication function on <apll>⍺</apll> repeated <apll>⍵</apll> times &mdash; <apll>×/⍵⍴a ←→ ⍺*⍵</apll>,<br />
* <apll>N=4</apll> is the [http://en.wikipedia.org/wiki/Tetration tetration] function (related to the [http://en.wikipedia.org/wiki/Ackermann_function Ackermann-Péter] function), i.e. the exponentiation function on <apll>⍺</apll> repeated <apll>⍵</apll> times &mdash; <apll>*/⍵⍴⍺</apll>,<br />
* <apll>N=5</apll> is the [http://en.wikipedia.org/wiki/Pentation pentation] function, i.e. the tetration function on <apll>⍺</apll> repeated <apll>⍵</apll> times,<br />
* etc.<br />
written on multiple lines using [[Function_Editing|Line Continuations]] for clarity:<br />
<br />
<apll><pre><br />
ho←{⍺⍺=0 :⍵+1<br />
<span style="color:blue;">➥</span>&nbsp;⋄ (⍺⍺=1)∧⍵=0:⍺<br />
<span style="color:blue;">➥</span>&nbsp;⋄ (⍺⍺=2)∧⍵=0:0<br />
<span style="color:blue;">➥</span>&nbsp;⋄ (⍺⍺≥3)∧⍵=0:1<br />
<span style="color:blue;">➥</span>&nbsp;⋄ ⍺ ((⍺⍺-1)∇∇) ⍺∇⍵-1}<br />
<br />
2 (0 ho) 5 ⍝ Successor: 1+5 (left argument ignored)<br />
6<br />
2 (1 ho) 5 ⍝ Addition: 2+5<br />
7<br />
2 (2 ho) 5 ⍝ Multiplication: 2×5<br />
10<br />
2 (3 ho) 5 ⍝ Exponentiation: 2*5<br />
32<br />
2 (4 ho) 5 ⍝ Tetration: */5⍴2<br />
200352993040684646497907235156025575044782547556975141926501697371089405955...</pre></apll><br />
<br />
If we could compute <apll>2<pn>x</pn> (4 ho) 5<pn>x</pn></apll> in a reasonable amount of time, it would return a number with 19,729 digits (= <apll>⍴⍕*/5⍴2<pn>x</pn></apll>)!<br />
<br />
'''N.B.:''' Both of the <apll>∇</apll> and <apll>∇∇</apll> names may be used in user-defined functions, where they have the same meaning as they do in AFOs.<br />
<br />
== Termination ==<br />
<br />
Normally, the statements within the braces execute one by one from left to right, just as in the Execute primitive. Execution of the AFO terminates on the first occurrence of one of the following:<br />
<br />
* A [[#Guards|Guard]] with a TRUE condition,<br />
* A non-[[#Shy Results|Shy]] value to display, or<br />
* The rightmost statement.<br />
<br />
== Restrictions ==<br />
<br />
* Assignments to any of the special names (<apll>∇</apll>, <apll>⍵</apll>, <apll>⍺⍺</apll>, <apll>∇∇</apll>, <apll>⍵⍵</apll>) except for <apll>⍺</apll> are not allowed; they signal a <apll>SYNTAX ERROR</apll>.<br />
* Assignments to <apll>⍺</apll> within a guard statement are not allowed; they signal a <apll>SYNTAX ERROR</apll>.<br />
* None of the special names may be erased, via <apll>⎕EX</apll> or otherwise.<br />
* Goto statements are not allowed; they signal a <apll>SYNTAX ERROR</apll>.<br />
* Control structures (e.g., <apll>:if ... ⋄ ... ⋄ :end</apll>) are not allowed; they signal a <apll>SYNTAX ERROR</apll>.<br />
* Line labels except for [[System_Labels|System Labels]] are not allowed.<br />
<br />
== Acknowledgements ==<br />
<br />
This design of this feature was copied (with minor changes) from the same feature designed and implemented by John Scholes and other folks at Dyalog, Inc.</div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=Trains&diff=3160Trains2018-04-15T19:32:30Z<p>Sudleyplace: </p>
<hr />
<div><table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td><apll>Z←&nbsp;&nbsp;(f g) R</apll></td><br />
<td></td><br />
<td></td><br />
<td>is called a '''Monadic Hook''' &mdash; <apll>Z ≡ R f g R</apll></td><br />
</tr><br />
<tr><br />
<td><apll>Z←L (f g) R</apll></td><br />
<td></td><br />
<td></td><br />
<td>is called a '''Dyadic Hook''' &mdash; <apll>Z ≡ L f g R</apll></td><br />
</tr><br />
<tr><br />
<td><apll>Z←&nbsp;&nbsp;(f g h) R</apll></td><br />
<td></td><br />
<td></td><br />
<td>is called a '''Monadic Fork''' &mdash; <apll>Z ≡ (f R) g h R</apll></td><br />
</tr><br />
<tr><br />
<td><apll>Z←L (f g h) R</apll></td><br />
<td></td><br />
<td></td><br />
<td>is called a '''Dyadic Fork''' &mdash; <apll>Z ≡ (L f R) g L h R</apll></td><br />
</tr><br />
<tr><br />
<td><apll>Z←&nbsp;&nbsp;(f g h ...) R</apll><br /><apll>Z←L (f g h ...) R</apll></td><br />
<td></td><br />
<td></td><br />
<td>is also defined for longer Trains</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<tr><br />
<td><apll>L</apll> and <apll>R</apll> are arbitrary arrays, <apll>f</apll>, <apll>g</apll>, <apll>h</apll>, etc, are arbitrary functions of any type: primitive, user-defined, system, anonymous, and/or derived.</td><br />
</tr><br />
</table><br />
<br /><br />
<p>This clever idea from the designers of J is called [http://www.jsoftware.com/help/dictionary/dictf.htm Trains] where a parenthesized sequence of functions (which normally would signal a SYNTAX ERROR) can be interpreted as per the above descriptions. Very nicely, they fit into and extend the spectrum of function definition syntax from user-defined to dynamic to trains to operator expressions. They are another and very interesting form of functional programming.</p><br />
<br />
<p>Note that the spacing between functions is for visual purposes only &mdash; it has no effect on the interpretation.</p><br />
<br />
<p>For example,</p><br />
<br />
<apll> (,⍎)'2+3'</apll><br /><br />
<apll>←→ '2+3',⍎'2+3'</apll><br /><br />
<apll>←→ '2+3',5</apll><br /><br />
<apll>2+3 5</apll><br /><br />
<br />
<apll> avg{is}(+⌿ ÷ ≢)</apll> defines a function that computes the average of a numeric vector.<br /><br />
<apll> avg 1 2 3 4</apll><br /><br />
<apll>←→ (+⌿ ÷ ≢) 1 2 3 4</apll><br /><br />
<apll>←→ (+⌿1 2 3 4) ÷ ≢1 2 3 4</apll><br /><br />
<apll>←→ 10 ÷ 4</apll><br /><br />
<apll>2.5</apll><br />
<br />
<p>Longer Trains are defined as follows:</p><br />
<br />
<apll> (e f g h) ←→ (e (f g h))</apll><br /><br />
<apll>(d e f g h) ←→ (d e (f g h))</apll><br /><br />
<br />
and in general<br />
<br />
{|border="0"<br />
|Even length: || <apll>(a b c ...) ←→ (a (b c ...))</apll><br />
|-<br />
|Odd length: || <apll>(a b c ...) ←→ (a b (c ...))</apll><br />
|}<br />
<br />
<p>For more applications of this concept, see the [http://www.jsoftware.com/help/learning/09.htm discussion] in the '''Learning J''' manual.</p><br />
<br />
<p>There is also a series of [[Train_Tables|tables]] of common function expressions and their corresponding Train.</p></div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=Language_Features&diff=3159Language Features2018-04-15T19:26:45Z<p>Sudleyplace: /* Datatypes */</p>
<hr />
<div>At the moment, the following sections describe only those language features that are '''New''' or '''Enhanced''' relative to the Extended APL Standard, or that deserve special comment.<br />
<br />
==Syntax==<br />
* [[Strand Assignment]]: <apll>(A<sub>1</sub> A<sub>2</sub> ... A<sub>n</sub>)←R</apll><br />
* [[Modify Assignment]]: <apll>A<i>f</i>←R</apll><br />
* [[Modify Strand Assignment]]: <apll>(A<sub>1</sub> A<sub>2</sub> ... A<sub>n</sub>)<i>f</i>←R</apll><br />
* [[Function/Operator Assignment]]: <apll>A←<i>f</i></apll>, &nbsp;&nbsp;<apll>A←<i>op1</i></apll>, &nbsp;&nbsp;<apll>A←<i>op2</i></apll><br />
<!-- * [[Selective Assignment]]: e.g., <apll>(1 1⍉M)←0</apll> --><br />
* [[Sink]]: <apll>←R</apll><br />
* [[Point Notation]]: <br />
** '''Base''' &mdash; <apll>16<pn>b</pn>10FFFF</apll> is a shorthand for <apll>16⊥1 0 15 15 15 15</apll> and <apll>10<pn>b</pn>45<pn>v</pn></apll> is a shorthand for <apll>10⊥4 5 31</apll><br />
** '''Euler''' &mdash; <apll>2<pn>x</pn>3</apll> is a shorthand for <apll>2e<sup>3</sup></apll> or <apll>2×(*1)*3</apll> where <apll>e</apll> is [https://en.wikipedia.org/wiki/E_(mathematical_constant) Euler's Number] (2.718281828459045...)<br />
** '''Pi''' &mdash; <apll>2<pn>p</pn>3</apll> is a shorthand for <apll>2&pi;<sup>3</sup></apll> or <apll>2×(○1)*3</apll> where <apll>&pi;</apll> is [https://en.wikipedia.org/wiki/Pi Archimedes' constant] (3.141592653589793...)<br />
** '''Gamma''' &mdash; <apll>2<pn>g</pn>3</apll> is a shorthand for <apll>2&gamma;<sup>3</sup></apll> where <apll>&gamma;</apll> is [https://en.wikipedia.org/wiki/Euler%E2%80%93Mascheroni_constant Euler-Mascheroni's Constant] (0.5772156649015329...)<br />
** '''Hypercomplex''' &mdash; <apll>2<hc>J</hc>3</apll>, <apll>2<hc>i</hc>3</apll> (both equal to <apll>2+3×√¯1</apll>), <apll>2<hc>ad</hc>3</apll> (Angle in Degrees), <apll>2<hc>ar</hc>3</apll> (Angle in Radians), or <apll>2<hc>au</hc>3</apll> (Angle in Unit Normalized) for a Complex number, <apll>1<hc>i</hc>2<hc>j</hc>3<hc>k</hc>4</apll> for a Quaternion number, and <apll>1<hc>i</hc>2<hc>j</hc>3<hc>k</hc>4<hc>l</hc>5<hc>ij</hc>6<hc>jk</hc>7<hc>kl</hc>8</apll> for an Octonion number.<br />
** '''Rational''' &mdash; <apll>2<pn>r</pn>3</apll> is a shorthand for <apll>2÷3</apll> as a Multiple-Precision Integer/Rational number.<br />
** '''Variable-Precision Floating''' &mdash; <apll>2.3<pn>v</pn></apll> is a shorthand for <apll>2.3</apll> as a Multiple-Precision Floating Point number.<br />
* [[Trains]]: e.g., <apll>avg←(+⌿ ÷ ≢)</apll> applies the functions to its argument(s) in a particular way (in this case, to compute the average of a numeric scalar or vector).<br />
* [[Anonymous Functions/Operators]]: multi-line grouping of one or more statements all enclosed in braces such as <apll>{(+⌿⍵)÷≢⍵}</apll>.<br />
<br />
==Primitive functions==<br />
* [[Array Lookup]]: <apll>L⍸R</apll><br />
* [[Condense]]: <apll>&lt;[X] R</apll><br />
* [[Dilate]]: <apll>&gt;[X] R</apll><br />
* [[Expand]]: <apll>L\[X] R</apll><br />
* [[Find]]: <apll>L⍷R</apll><br />
* [[Index Generator]]: <apll>⍳R</apll><br />
* [[Index Of]]: <apll>L⍳R</apll><br />
* [[Indexing]]: <apll>R[L]</apll>, &nbsp;&nbsp;<apll>R[L]←A</apll>, &nbsp;&nbsp;<apll>R[L]<i>f</i>←A</apll>, &nbsp;&nbsp;<apll>L⌷R</apll>, &nbsp;&nbsp;<apll>L⍉R</apll>, &nbsp;&nbsp; <apll>L⊃R</apll><br />
* [[Indices]]: <apll>⍸R</apll><br />
* [[Matrix Inverse/Divide]]: <apll>⌹R</apll>, &nbsp;&nbsp;<apll>L⌹R</apll><br />
* [[Mismatch]]: <apll>L≢R</apll><br />
* [[Partitioned Enclose]]: <apll>L⊂[X] R</apll><br />
* [[Primes]]: <apll>πR</apll> and <apll>LπR</apll><br />
* [[Reshape]]: <apll>L⍴R</apll><br />
* [[Root]]: <apll>√R</apll> and <apll>L√[X] R</apll><br />
* [[Sequence]]: <apll>L..R</apll><br />
* [[Sets]]: <apll>L§R</apll>, <apll>L⊆R</apll>, <apll>L⊇R</apll><br />
* [[Tally]]: <apll>≢R</apll><br />
* [[Without]]: <apll>L~R</apll><br />
<br />
==Primitive operators==<br />
* [[Axis]]: <apll><i>f</i>[<i>X</i>]</apll>, <apll><i>f op1</i>[<i>X</i>]</apll>, <apll><i>f op2</i>[<i>X</i>]g</apll><br />
* [[Combinatorial]]: <apll><i>a</i>‼R</apll> &nbsp;&nbsp; (monadic derived function)<br />
* [[Commute-Duplicate|Commute]]: <apll>L <i>f</i>⍨ R ←→ R <i>f</i> L</apll> &nbsp;&nbsp;&nbsp; (dyadic derived function)<br />
* [[Composition]]: <apll><i>f</i>⍥<i>g</i></apll><br />
* [[Compose]]: <apll><i>f</i>∘<i>g</i></apll>, &nbsp;&nbsp;<apll><i>f</i>∘R</apll>, &nbsp;&nbsp;<apll>L∘<i>g</i></apll><br />
* [[Convolution]]: <apll><i>f</i>⍡<i>g</i></apll> &nbsp;&nbsp;&nbsp; (dyadic derived function)<br />
* [[Determinant Operator|Determinant]]: <apll><i>f</i>.<i>g</i></apll> &nbsp;&nbsp;&nbsp; (monadic derived function)<br />
* [[Commute-Duplicate|Duplicate]]: <apll><i>f</i>⍨ R ←→ R <i>f</i> R</apll> &nbsp;&nbsp;&nbsp; (monadic derived function)<br />
* [[Matrix]]: <apll><i>f</i>⌻R</apll>, <apll>L <i>f</i>⌻R</apll>, <apll>∘⌻R</apll><br />
* [[Multisets]]: <apll><i>f</i>⍦</apll><br />
* [[Null]]: <apll><i>f</i>⊙</apll><br />
* [[Rank]]: <apll><i>f</i>⍤[<i>X</i>] Y</apll><br />
* [[Variant]]: <apll><i>f</i>⍠V</apll><br />
<br />
==Datatypes==<br />
* [[Infinity]]: <apll>∞</apll> and <apll>¯∞</apll><br />
* [[APA|Arithmetic Progression Arrays]]: <apll>2 3 4⍴⍳24</apll><br />
* [[Unicode|Unicode Characters]]<br />
* [[Array Predicates]]<br />
* [[Rational and VFP Numbers|Rational Numbers]]: <apll>1<pn>r</pn>3</apll> and <apll>12345<pn>x</pn></apll><br />
* [[Rational and VFP Numbers|Variable-precision Floating Point (VFP) Numbers]]: <apll>1.234<pn>v</pn></apll> and <apll>12<pn>v</pn></apll><br />
* Complex Numbers: <apll>1<hc>J</hc>2</apll> or <apll>3.4<hc>i</hc>5</apll> or <apll>2<hc>ad</hc>90</apll> or <apll>2<hc>ar</hc>2.1</apll> or <apll>2<hc>au</hc>0.5</apll><br />
* Quaternion Numbers: <apll>1<hc>i</hc>2<hc>j</hc>3<hc>k</hc>4</apll><br />
* Octonion Numbers: <apll>1<hc>i</hc>2<hc>j</hc>3<hc>k</hc>4<hc>l</hc>5<hc>ij</hc>6<hc>jk</hc>7<hc>kl</hc>8</apll><br />
<br />
==System Commands==<br />
{{:System Commands}}<br />
<br />
==System Variables and Functions==<br />
{{System Variables}}</div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=Language_Features&diff=3158Language Features2018-04-15T19:24:18Z<p>Sudleyplace: /* Syntax */</p>
<hr />
<div>At the moment, the following sections describe only those language features that are '''New''' or '''Enhanced''' relative to the Extended APL Standard, or that deserve special comment.<br />
<br />
==Syntax==<br />
* [[Strand Assignment]]: <apll>(A<sub>1</sub> A<sub>2</sub> ... A<sub>n</sub>)←R</apll><br />
* [[Modify Assignment]]: <apll>A<i>f</i>←R</apll><br />
* [[Modify Strand Assignment]]: <apll>(A<sub>1</sub> A<sub>2</sub> ... A<sub>n</sub>)<i>f</i>←R</apll><br />
* [[Function/Operator Assignment]]: <apll>A←<i>f</i></apll>, &nbsp;&nbsp;<apll>A←<i>op1</i></apll>, &nbsp;&nbsp;<apll>A←<i>op2</i></apll><br />
<!-- * [[Selective Assignment]]: e.g., <apll>(1 1⍉M)←0</apll> --><br />
* [[Sink]]: <apll>←R</apll><br />
* [[Point Notation]]: <br />
** '''Base''' &mdash; <apll>16<pn>b</pn>10FFFF</apll> is a shorthand for <apll>16⊥1 0 15 15 15 15</apll> and <apll>10<pn>b</pn>45<pn>v</pn></apll> is a shorthand for <apll>10⊥4 5 31</apll><br />
** '''Euler''' &mdash; <apll>2<pn>x</pn>3</apll> is a shorthand for <apll>2e<sup>3</sup></apll> or <apll>2×(*1)*3</apll> where <apll>e</apll> is [https://en.wikipedia.org/wiki/E_(mathematical_constant) Euler's Number] (2.718281828459045...)<br />
** '''Pi''' &mdash; <apll>2<pn>p</pn>3</apll> is a shorthand for <apll>2&pi;<sup>3</sup></apll> or <apll>2×(○1)*3</apll> where <apll>&pi;</apll> is [https://en.wikipedia.org/wiki/Pi Archimedes' constant] (3.141592653589793...)<br />
** '''Gamma''' &mdash; <apll>2<pn>g</pn>3</apll> is a shorthand for <apll>2&gamma;<sup>3</sup></apll> where <apll>&gamma;</apll> is [https://en.wikipedia.org/wiki/Euler%E2%80%93Mascheroni_constant Euler-Mascheroni's Constant] (0.5772156649015329...)<br />
** '''Hypercomplex''' &mdash; <apll>2<hc>J</hc>3</apll>, <apll>2<hc>i</hc>3</apll> (both equal to <apll>2+3×√¯1</apll>), <apll>2<hc>ad</hc>3</apll> (Angle in Degrees), <apll>2<hc>ar</hc>3</apll> (Angle in Radians), or <apll>2<hc>au</hc>3</apll> (Angle in Unit Normalized) for a Complex number, <apll>1<hc>i</hc>2<hc>j</hc>3<hc>k</hc>4</apll> for a Quaternion number, and <apll>1<hc>i</hc>2<hc>j</hc>3<hc>k</hc>4<hc>l</hc>5<hc>ij</hc>6<hc>jk</hc>7<hc>kl</hc>8</apll> for an Octonion number.<br />
** '''Rational''' &mdash; <apll>2<pn>r</pn>3</apll> is a shorthand for <apll>2÷3</apll> as a Multiple-Precision Integer/Rational number.<br />
** '''Variable-Precision Floating''' &mdash; <apll>2.3<pn>v</pn></apll> is a shorthand for <apll>2.3</apll> as a Multiple-Precision Floating Point number.<br />
* [[Trains]]: e.g., <apll>avg←(+⌿ ÷ ≢)</apll> applies the functions to its argument(s) in a particular way (in this case, to compute the average of a numeric scalar or vector).<br />
* [[Anonymous Functions/Operators]]: multi-line grouping of one or more statements all enclosed in braces such as <apll>{(+⌿⍵)÷≢⍵}</apll>.<br />
<br />
==Primitive functions==<br />
* [[Array Lookup]]: <apll>L⍸R</apll><br />
* [[Condense]]: <apll>&lt;[X] R</apll><br />
* [[Dilate]]: <apll>&gt;[X] R</apll><br />
* [[Expand]]: <apll>L\[X] R</apll><br />
* [[Find]]: <apll>L⍷R</apll><br />
* [[Index Generator]]: <apll>⍳R</apll><br />
* [[Index Of]]: <apll>L⍳R</apll><br />
* [[Indexing]]: <apll>R[L]</apll>, &nbsp;&nbsp;<apll>R[L]←A</apll>, &nbsp;&nbsp;<apll>R[L]<i>f</i>←A</apll>, &nbsp;&nbsp;<apll>L⌷R</apll>, &nbsp;&nbsp;<apll>L⍉R</apll>, &nbsp;&nbsp; <apll>L⊃R</apll><br />
* [[Indices]]: <apll>⍸R</apll><br />
* [[Matrix Inverse/Divide]]: <apll>⌹R</apll>, &nbsp;&nbsp;<apll>L⌹R</apll><br />
* [[Mismatch]]: <apll>L≢R</apll><br />
* [[Partitioned Enclose]]: <apll>L⊂[X] R</apll><br />
* [[Primes]]: <apll>πR</apll> and <apll>LπR</apll><br />
* [[Reshape]]: <apll>L⍴R</apll><br />
* [[Root]]: <apll>√R</apll> and <apll>L√[X] R</apll><br />
* [[Sequence]]: <apll>L..R</apll><br />
* [[Sets]]: <apll>L§R</apll>, <apll>L⊆R</apll>, <apll>L⊇R</apll><br />
* [[Tally]]: <apll>≢R</apll><br />
* [[Without]]: <apll>L~R</apll><br />
<br />
==Primitive operators==<br />
* [[Axis]]: <apll><i>f</i>[<i>X</i>]</apll>, <apll><i>f op1</i>[<i>X</i>]</apll>, <apll><i>f op2</i>[<i>X</i>]g</apll><br />
* [[Combinatorial]]: <apll><i>a</i>‼R</apll> &nbsp;&nbsp; (monadic derived function)<br />
* [[Commute-Duplicate|Commute]]: <apll>L <i>f</i>⍨ R ←→ R <i>f</i> L</apll> &nbsp;&nbsp;&nbsp; (dyadic derived function)<br />
* [[Composition]]: <apll><i>f</i>⍥<i>g</i></apll><br />
* [[Compose]]: <apll><i>f</i>∘<i>g</i></apll>, &nbsp;&nbsp;<apll><i>f</i>∘R</apll>, &nbsp;&nbsp;<apll>L∘<i>g</i></apll><br />
* [[Convolution]]: <apll><i>f</i>⍡<i>g</i></apll> &nbsp;&nbsp;&nbsp; (dyadic derived function)<br />
* [[Determinant Operator|Determinant]]: <apll><i>f</i>.<i>g</i></apll> &nbsp;&nbsp;&nbsp; (monadic derived function)<br />
* [[Commute-Duplicate|Duplicate]]: <apll><i>f</i>⍨ R ←→ R <i>f</i> R</apll> &nbsp;&nbsp;&nbsp; (monadic derived function)<br />
* [[Matrix]]: <apll><i>f</i>⌻R</apll>, <apll>L <i>f</i>⌻R</apll>, <apll>∘⌻R</apll><br />
* [[Multisets]]: <apll><i>f</i>⍦</apll><br />
* [[Null]]: <apll><i>f</i>⊙</apll><br />
* [[Rank]]: <apll><i>f</i>⍤[<i>X</i>] Y</apll><br />
* [[Variant]]: <apll><i>f</i>⍠V</apll><br />
<br />
==Datatypes==<br />
* [[Infinity]]: <apll>∞</apll> and <apll>¯∞</apll><br />
* [[APA|Arithmetic Progression Arrays]]: <apll>2 3 4⍴⍳24</apll><br />
* [[Unicode|Unicode Characters]]<br />
* [[Array Predicates]]<br />
* [[Rational and VFP Numbers|Rational Numbers]]: <apll>1<pn>r</pn>3</apll> and <apll>12345<pn>x</pn></apll><br />
* [[Rational and VFP Numbers|Variable-precision Floating Point (VFP) Numbers]]: <apll>1.234<pn>v</pn></apll> and <apll>12<pn>v</pn></apll><br />
* Complex Numbers: <apll>1<pn>J</pn>2</apll> or <apll>3.4<pn>i</pn>5</apll> or <apll>2<pn>ad</pn>90</apll> or <apll>2<pn>ar</pn>2.1</apll> or <apll>2<pn>au</pn>0.5</apll><br />
* Quaternion Numbers: <apll>1<pn>i</pn>2<pn>j</pn>3<pn>k</pn>4</apll><br />
* Octonion Numbers: <apll>1<pn>i</pn>2<pn>j</pn>3<pn>k</pn>4<pn>l</pn>5<pn>ij</pn>6<pn>jk</pn>7<pn>kl</pn>8</apll><br />
<br />
==System Commands==<br />
{{:System Commands}}<br />
<br />
==System Variables and Functions==<br />
{{System Variables}}</div>Sudleyplacehttp://wiki.nars2000.org/index.php?title=Point_Notation&diff=3157Point Notation2018-04-15T19:21:30Z<p>Sudleyplace: /* Mixed Notation */</p>
<hr />
<div>== Overview ==<br />
<br />
<table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td valign="baseline"><b>Base Point Notation</b>:</td><br />
<td></td><br />
<td></td><br />
<td>e.g., <apll>16<pn>b</pn>10FFFF</apll>as a shorthand for <apll>16⊥1 0 15 15 15 15 15</apll>.</td><br />
</tr><br />
<tr><br />
<td valign="baseline"><b>Euler Point Notation</b>:</td> <br />
<td></td><br />
<td></td><br />
<td>e.g., <apll>2<pn>x</pn>3</apll> as a shorthand for <apll>2∙e<sup>3</sup></apll> or <apll>2×(*1)*3</apll>.</td><br />
</tr><br />
<tr><br />
<td valign="baseline"><b>Pi Point Notation</b>:</td><br />
<td></td><br />
<td></td><br />
<td>e.g., <apll>2<pn>p</pn>3</apll> as a shorthand for <apll>2∙&pi;<sup>3</sup></apll> or <apll>2×(○1)*3</apll>.</td><br />
</tr><br />
<tr><br />
<td valign="baseline"><b>Gamma Point Notation</b>:</td><br />
<td></td><br />
<td></td><br />
<td>e.g., <apll>2<pn>g</pn>3</apll> as a shorthand for <apll>2∙&gamma;<sup>3</sup></apll> where <apll>&gamma;</apll> is the [https://en.wikipedia.org/wiki/Euler%E2%80%93Mascheroni_constant Euler-Mascheroni Constant].</td><br />
</tr><br />
<tr><br />
<td valign="baseline"><b>Hypercomplex Point Notation</b>:</td><br />
<td></td><br />
<td></td><br />
<td>e.g., <apll>2<hc>J</hc>3</apll> or <apll>2<hc>i</hc>3</apll> as a shorthand for <apll>2+3×√¯1</apll>, or <apll>2<hc>ad</hc>3</apll> (Angle in Degrees), <apll>2<hc>ar</hc>3</apll> (Angle in Radians), or <apll>2<hc>au</hc>3</apll> (Angle in Unit Normalized) all for Complex numbers, or <apll>1<hc>i</hc>2<hc>j</hc>3<hc>k</hc>4</apll> for a Quaternion number, or <apll>1<hc>i</hc>2<hc>j</hc>3<hc>k</hc>4<hc>l</hc>5<hc>ij</hc>6<hc>jk</hc>7<hc>kl</hc>8</apll> for an Octonion number.</td><br />
</tr><br />
<tr><br />
<td valign="baseline"><b>Rational Point Notation</b>:</td><br />
<td></td><br />
<td></td><br />
<td valign="baseline">e.g., <apll>2<pn>r</pn>3</apll> as a shorthand for <apll>2{divide}3</apll> as an infinite precision rational number, or <apll>123<pn>x</pn></apll> as a means of representing <apll>123</apll> as an infinite precision integer &mdash; the suffix <apll><pn>x</pn></apll> is actually a shorthand for <apll><pn>r</pn>1</apll>, that is, infinite precision integers are actually represented as rational numbers with a denominator of <apll>1</apll>.</td><br />
</tr><br />
<tr><br />
<td valign="baseline"><b>Variable-Precision Floating Point Notation</b>:</td><br />
<td></td><br />
<td></td><br />
<td valign="baseline">e.g., <apll>2.3<pn>v</pn></apll> as a shorthand for <apll>2.3</apll> as a variable-precision floating point number, or <apll>123<pn>v</pn></apll> as a means of representing <apll>123</apll> as a VFP number whose fractional part is zero.</td><br />
</tr><br />
<tr><br />
<td valign="baseline"><b>Decimal Point Notation</b>:</td><br />
<td></td><br />
<td></td><br />
<td>e.g., <apll>2.5</apll> as a shorthand for <apll>2&frac12;</apll> or <apll>2+5÷10</apll>.</td><br />
</tr><br />
<tr><br />
<td valign="baseline"><b>Exponential Point Notation</b>:</td><br />
<td></td><br />
<td></td><br />
<td>e.g., <apll>2<pn>e</pn>3</apll> or <apll>2<pn>E</pn>3</apll> as a shorthand for <apll>2&#8729;10<sup>3</sup></apll> or <apll>2×10*3</apll>.</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<tr><br />
<td><b>Base</b>, <b>Euler</b>, <b>Pi</b>, <b>Gamma</b>, and <b>Rational</b> Point Notations are extensions to the familiar <b>Decimal</b> Point Notation as well as <b>Exponential</b> Point or Scientific Notation methods of entering numeric constants. Thanks to the designers of J for these clever [http://www.jsoftware.com/help/dictionary/dcons.htm ideas].</td><br />
</tr><br />
</table><br />
<br /><br />
<br />
== Base Point Notation ==<br />
<br />
This notation makes it easy to enter numeric constants in an arbitrary base.<br />
<br />
The number to the left of the <apll><pn>b</pn></apll> is the base of the number system for the characters to the right of the <apll><pn>b</pn></apll>. The base may be represented in several ways including integers, <b>Exponential</b>, <b>Decimal</b>, <b>Euler</b>, <b>Pi</b>, <b>Gamma</b>, <b>Hypercomplex</b>, <b>Rational</b>, and <b>Variable Precision Floating</b> Point Notation, but not <b>Base</b> Point Notation.<br />
<br />
For example, <apll>1<pn>e</pn>3<pn>b</pn>111</apll> is the same as <apll>1000<pn>b</pn>111</apll>.<br />
<br />
Note that the base may also be negative as in <apll>¯1<pn>b</pn>0z</apll>, fractional as in <apll>0.1<pn>b</pn>1234</apll>, or Hypercomplex as in <apll>0<pn>J</pn>1<pn>b</pn>321</apll>.<br />
<br />
The characters to the right of the <apll><pn>b</pn></apll> may range from <b>0-9</b> or <b>a-z</b> where the latter range is a way of representing numbers from <b>10-35</b> in a single character. The uppercase letters (<b>A-Z</b>) have the same values as the corresponding lowercase case letters and may be used instead of or intermixed with them.<br />
<br />
For example, <apll>10<pn>b</pn>zzZz</apll> is the same as <apll>10⊥35 35 35 35</apll>, and <apll>1<pn>r</pn>2<pn>b</pn>111</apll> is the same as <apll>0.5<pn>b</pn>111</apll> except for precision &mdash; the former is Multiple-Precision and the latter is Fixed.<br />
<br />
A decimal point may appear anywhere in the characters to the right of the <apll><pn>b</pn></apll> to indicate that the characters to its right represent the fractional part of the number in the given base.<br />
<br />
For example, <apll>2<pn>b</pn>111.111</apll> is <apll>(6⍴1)+.×2*2..¯3</apll> which is <apll>7.875</apll>.<br />
<br />
== Euler Point Notation ==<br />
<br />
This notation allows you to enter numeric constants that are in the form of the product of a multiplier and <apll>e</apll> (&cong; 2.718281828459045... &mdash; base of the natural logarithms) raised to an exponent, that is, <apll>Me<sup>E</sup></apll> or <apll>M×(*1)*E</apll>. The numbers to the left (multiplier) and right (exponent) of the <apll><pn>x</pn></apll> may be represented in several ways including integers, <b>Decimal</b>, <b>Exponential</b>, <b>Hypercomplex</b>, <b>Rational</b>, or <b>Variable Precision Floating</b> Point Notation, but not <b>Base</b>, <b>Euler</b>, <b>Pi</b>, or <b>Gamma</b> Point Notation.<br />
<br />
For example, <apll>1<pn>e</pn>2<pn>x</pn>1.1</apll> is the same as <apll>100<pn>x</pn>1.1</apll>, and <apll>1<pn>r</pn>2<pn>x</pn>1.1<pn>e</pn>2</apll> is the same as <apll>0.5<pn>x</pn>110</apll>.<br />
<br />
Both the multiplier and exponent may be negative and/or fractional as in <apll>{overbar}1<pn>e</pn>2<pn>x</pn>{overbar}3.3</apll>.<br />
<br />
== Pi Point Notation ==<br />
<br />
This notation allows you to enter numeric constants that are in the form of the product of a multiplier and <apll>&pi;</apll> (&cong; 3.141592653589793... &mdash; ratio of a circle's circumference and diameter) raised to an exponent, that is, <apll>M&pi;<sup>E</sup></apll> or <apll>M×(○1)*E</apll>. The numbers to the left (multiplier) and right (exponent) of the <apll><pn>p</pn></apll> may be represented in several ways including integers, <b>Decimal</b>, <b>Exponential</b>, <b>Hypercomplex</b>, <b>Rational</b>, or <b>Variable Precision Floating</b> Point Notation, but not <b>Base</b>, <b>Euler</b>, <b>Pi</b>, or <b>Gamma</b> Point Notation.<br />
<br />
For example, <apll>1<pn>e</pn>2<pn>p</pn>1.1</apll> is the same as <apll>100<pn>p</pn>1.1</apll>, and <apll>1<pn>r</pn>2<pn>p</pn>1.1<pn>e</pn>2</apll> is the same as <apll>0.5<pn>p</pn>110</apll>.<br />
<br />
Both the multiplier and exponent may be negative and/or fractional as in <apll>{overbar}1<pn>e</pn>2<pn>p</pn>{overbar}3.3</apll>.<br />
<br />
== Gamma Point Notation ==<br />
<br />
This notation allows you to enter numeric constants that are in the form of the product of a multiplier and <apll>&gamma;</apll> (&cong; 0.5772156649015329... &mdash; limiting difference between the harmonic series and the natural logarithm) raised to an exponent, that is, <apll>M&gamma;<sup>E</sup></apll> or <apll>M×&gamma;*E</apll>. The numbers to the left (multiplier) and right (exponent) of the <apll><pn>g</pn></apll> may be represented in several ways including integers, <b>Decimal</b>, <b>Exponential</b>, <b>Rational</b>, or <b>Variable Precision Floating</b> Point Notation, but not <b>Base</b>, <b>Euler</b>, <b>Pi</b>, or <b>Gamma</b> Point Notation.<br />
<br />
For example, <apll>1<pn>e</pn>2<pn>g</pn>1.1</apll> is the same as <apll>100<pn>g</pn>1.1</apll>, and <apll>1<pn>r</pn>2<pn>g</pn>1.1e2</apll> is the same as <apll>0.5<pn>g</pn>110</apll>.<br />
<br />
Both the multiplier and exponent may be negative and/or fractional as in <apll>{overbar}1<pn>e</pn>2<pn>g</pn>{overbar}3.3</apll>.<br />
<br />
== Rational Point Notation ==<br />
<br />
This notation allows you to enter fractions as rational numbers and have them be retained as rational numbers. Rational numbers (using the <apll><pn>r</pn></apll> infix separator only, not the <apll><pn>x</pn></apll> suffix) may also be used as a lefthand argument to <b>Base</b>, and either argument to <b>Euler</b>, <b>Pi</b>, or <b>Gamma</b> Point Notations. For more information, see [[Rational and VFP Numbers|Rational Numbers]]. This notation also accepts strings that contain '''Decimal''' and/or '''Exponential''' point notation such as <apll>0.5<pn>x</pn></apll>, <apll>0.5<pn>r</pn>3</apll>, <apll>1<pn>E</pn>¯3<pn>r</pn>1.5</apll>, etc. and represents them as a Rational number.<br />
<br />
== Hypercomplex Point Notation ==<br />
<br />
This notation allows you to enter Complex, Quaternion, and Octonion numbers in various forms such as a combination of a Real part followed by one or more Hypercomplex units (2nd, 4th, or 8th root of <apll>¯1</apll>) times the corresponding coefficient. For more details, see [http://www.sudleyplace.com/APL/Hypercomplex%20Notation%20in%20APL.pdf Hypercomplex Notation in APL].<br />
<br />
== Variable-Precision Floating Point Notation ==<br />
<br />
This notation allows you to enter '''Decimal''' and '''Exponential''' point values as variable-precision floating point numbers. For example, <apll>2.3<pn>v</pn></apll> or <apll>2E¯3<pn>v</pn></apll>.<br />
<br />
In this form, the bits of precision of the number is specified by the value of <apll>⎕FPC</apll> at the time the number is fixed. Alternatively, the suffix <apll><pn>v</pn></apll> may be followed by an unsigned integer (<apll>≥53</apll>) to specify the number of bits of precision of the number, overriding the value of <apll>⎕FPC</apll>. For example <apll>2.3<pn>v</pn>64</apll> is a shorthand for <apll>2.3</apll> as a VFP number with <apll>64</apll> bits of precision.<br />
<br />
VFP numbers (using the <apll><pn>v</pn></apll> suffix) may also be used as a lefthand argument to <b>Base</b>, and either argument to <b>Euler</b>, <b>Pi</b>, or <b>Gamma</b> Point Notations. For more information, see [[Rational and VFP Numbers|Variable-precision Floating Point (VFP) Numbers]].<br />
<br />
== Exponential Point Notation ==<br />
<br />
This familiar notation (sometimes called scientific notation) allows you to enter numeric constants that are in the form of the product of a multiplier and a (possibly negative) power of 10. Exponential numbers (using either the <apll><pn>e</pn></apll> or <apll><pn>E</pn></apll> infix separator) may also be used as a lefthand argument to <b>Base</b>, and either argument to <b>Euler</b>, <b>Pi</b>, or <b>Gamma</b>, <b>Hypercomplex</b> Point Notations.<br />
<br />
For example, <apll>¯1.1<pn>e</pn>2</apll> is the same as <apll>¯110.0</apll>, and <apll>1.1<pn>E</pn>¯6</apll> is the same as <apll>0.0000011</apll>.<br />
<br />
== Mixed Notation ==<br />
<br />
The above notations may be combined in a single '''Point Notation String''' with the restrictions discussed above, a summary of which follows:<br />
<ul><br />
<li>The right element of '''Base''' Point Notation may '''not''' contain any of the above Point Notations except for <b>Decimal</b>.</li><br />
<li>The left element of '''Base''' Point Notation may contain any of the above Point Notations except itself.</li><br />
<li>'''Rational''', '''Variable Precision''', '''Hypercomplex''', and '''Exponential''' Point Notations may appear in either or both arguments to '''Euler''', '''Pi''', or '''Gamma''' Point Notations.</li><br />
<li>No Point Notation may appear with itself in the same Point Notation String.</li><br />
<li>No two of '''Euler''', '''Pi''', or '''Gamma''' Point Notations may appear in the same Point Notation String.</li><br />
</ul><br />
<br />
In terms of '''Binding Strength''', the Notation with the highest binding strength is '''Decimal'''. That is, '''Decimal''' Point Notation numbers are constructed first. From highest to lowest binding strength, the sequence is as follows:<br />
<br />
<ul><br />
<li>6. Decimal<br />
<li>5. Exponential<br />
<li>4. Rational, Variable Precision Floating Point<br />
<li>3. Hypercomplex<br />
<li>2. Euler, Pi, Gamma<br />
<li>1. Base<br />
</ul><br />
<br />
Notations with the same binding strength may not be mixed (e.g., <apll>1<pn>r</pn>2<pn>v</pn></apll> is an error). Otherwise, any notation may incorporate notations with a higher binding strength but may not incorporate notations with an equal or lower binding strength.<br />
<br />
This latter case need not signal an error, but instead it might produce a different interpretation. For example,<br />
<br />
<apll>1<pn>r</pn>2<pn>p</pn>1<hc>J</hc>3</apll> is interpreted as <apll>1<pn>r</pn>2×(○1<pn>x</pn>)*1<hc>J</hc>3</apll> not as <apll>1<pn>r</pn>2<pn>p</pn>1+0<hc>J</hc>3</apll> because '''Rational''' and '''Hypercomplex''' Point Notations are constructed before '''Pi''' Point Notation is.<br />
<br />
{{Language Toolbar}}<br />
[[Category:Mouse Group Notations]]</div>Sudleyplace