This commit adds the following to the RealFunctions protocol:
static func _relaxedAdd(_:Self, _:Self) -> Self
static func _relaxedMul(_:Self, _:Self) -> Self
These are equivalent to + and *, but have "relaxed semantics"; specifically, they license the compiler to reassociate them and to form FMA nodes, which are both significant optimizations that can easily make many common loops 8-10x faster. These transformation perturb results slightly, so they should not be enabled without care, but the results with the relaxed operations are--for most purposes--"just as good as" (and often better than) what strict operations produce. The main thing to beware of is that they are no longer portable; different compiler versions and different targets and optimization flags will result in different results.
They are underscored because they are not stable API. In particular:
- `RealFunctions` is not really the right protocol for these (and neither is `Real`). I need to do some thinking about where to attach them.
- Even if it were the right protocol, these are more like implementation hooks than the API I really want people to use (TBD).
- I like "relaxed" more than other commonly used idioms ("fast"), but I'm not sure it's the name I ultimately want.
In older toolchains, Float16 is marked unavailable on all mac targets; starting with the 5.4 toolchain, it is available starting in macOS 11.0 when targeting Apple Silicon.
These significantly improve on the state of the art for arguments close to the circle where the result vanishes, producing good componentwise relative accuracy as well as relative accuracy in the complex norm.
Also drops the argument parser dependency, which is desirable to avoid possible circular dependencies in the future with algorithms.
These are _mostly_ implementation hooks for Complex, but are generally useful, so I've made them public. Experimental, subject to renaming, especially mulAdd.
The most general version of the API is now defined on AA as:
```
public func isApproximatelyEqual<Magnitude>(
to other: Self,
absoluteTolerance: Magnitude,
relativeTolerance: Magnitude = 0,
norm: (Self) -> Magnitude
) -> Bool where Magnitude: FloatingPoint {
```
Note that AA does not have the magnitude property, so we can't default the norm in this setting. Therefore the following is kept on Numeric:
```
public func isApproximatelyEqual(
to other: Self,
absoluteTolerance: Magnitude,
relativeTolerance: Magnitude = 0
) -> Bool {
self.isApproximatelyEqual(
to: other,
absoluteTolerance: absoluteTolerance,
relativeTolerance: relativeTolerance,
norm: \.magnitude
)
}
```
to provide the operation with norm defaulted (note: it's not optional, because then this would call itself).
- Removed isApproximatelyEqual(to:), since that functionality already
exists via the default value of relativeTolerance.
- Added the ability to specify a norm to use in the expert-mode
operation, defaulting to using $0.magnitude.
- Respell as isApproximatelyEqual(to:), by analogy to isEqual(to:),
isLess(than:), etc.
- Refactor to eliminate the need for the Tolerance<Magnitude> type.
Now all we have is one overloaded function with three implementations.
This could be futher trimmed down to two versions by taking an
optional parameter instead, but that seems a little bit less clean.
I want to write some more documentation and examples here, but this is
enough to discuss and start review.