\[\begin{array}{l}
[z, t] = \mathsf{sort}([z, t])\\
\\
\begin{array}{l}
t_1 := x \cdot y - z \cdot t\\
\mathbf{if}\;t_1 \leq -\infty \lor \neg \left(t_1 \leq 10^{+269}\right):\\
\;\;\;\;y \cdot \frac{x}{a} - z \cdot \frac{t}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{t_1}{a}\\
\end{array}
\end{array}
\]
(FPCore (x y z t a) :precision binary64 (/ (- (* x y) (* z t)) a))
↓
NOTE: z and t should be sorted in increasing order before calling this function.
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (- (* x y) (* z t))))
(if (or (<= t_1 (- INFINITY)) (not (<= t_1 1e+269)))
(- (* y (/ x a)) (* z (/ t a)))
(/ t_1 a))))
double code(double x, double y, double z, double t, double a) {
return ((x * y) - (z * t)) / a;
}
The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.
Herbie found 7 alternatives:
Alternative
Accuracy
Speedup
Accuracy vs Speed
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.
\[ y \cdot \frac{x}{a} - \color{blue}{\frac{t}{\frac{a}{z}}}
\]
associate-/r/ [=>]95.3%
\[ y \cdot \frac{x}{a} - \color{blue}{\frac{t}{a} \cdot z}
\]
if -inf.0 < (-.f64 (*.f64 x y) (*.f64 z t)) < 1e269
Initial program 99.6%
\[\frac{x \cdot y - z \cdot t}{a}
\]
Recombined 2 regimes into one program.
Final simplification98.5%
\[\leadsto \begin{array}{l}
\mathbf{if}\;x \cdot y - z \cdot t \leq -\infty \lor \neg \left(x \cdot y - z \cdot t \leq 10^{+269}\right):\\
\;\;\;\;y \cdot \frac{x}{a} - z \cdot \frac{t}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot y - z \cdot t}{a}\\
\end{array}
\]
Alternatives
Alternative 1
Accuracy
97.0%
Cost
1737
\[\begin{array}{l}
t_1 := x \cdot y - z \cdot t\\
\mathbf{if}\;t_1 \leq -\infty \lor \neg \left(t_1 \leq 10^{+269}\right):\\
\;\;\;\;y \cdot \frac{x}{a} - z \cdot \frac{t}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{t_1}{a}\\
\end{array}
\]
herbie shell --seed 2023167
(FPCore (x y z t a)
:name "Data.Colour.Matrix:inverse from colour-2.3.3, B"
:precision binary64
:herbie-target
(if (< z -2.468684968699548e+170) (- (* (/ y a) x) (* (/ t a) z)) (if (< z 6.309831121978371e-71) (/ (- (* x y) (* z t)) a) (- (* (/ y a) x) (* (/ t a) z))))
(/ (- (* x y) (* z t)) a))