| Alternative 1 | |
|---|---|
| Accuracy | 97.7% |
| Cost | 7625 |

(FPCore (x y z t) :precision binary64 (- (* x x) (* (* y 4.0) (- (* z z) t))))
(FPCore (x y z t) :precision binary64 (if (or (<= (* y 4.0) -2e+132) (not (<= (* y 4.0) 1e-113))) (fma x x (* (- (* z z) t) (* y -4.0))) (- (* x x) (* 4.0 (- (* z (* y z)) (* y t))))))
double code(double x, double y, double z, double t) {
return (x * x) - ((y * 4.0) * ((z * z) - t));
}
double code(double x, double y, double z, double t) {
double tmp;
if (((y * 4.0) <= -2e+132) || !((y * 4.0) <= 1e-113)) {
tmp = fma(x, x, (((z * z) - t) * (y * -4.0)));
} else {
tmp = (x * x) - (4.0 * ((z * (y * z)) - (y * t)));
}
return tmp;
}
function code(x, y, z, t) return Float64(Float64(x * x) - Float64(Float64(y * 4.0) * Float64(Float64(z * z) - t))) end
function code(x, y, z, t) tmp = 0.0 if ((Float64(y * 4.0) <= -2e+132) || !(Float64(y * 4.0) <= 1e-113)) tmp = fma(x, x, Float64(Float64(Float64(z * z) - t) * Float64(y * -4.0))); else tmp = Float64(Float64(x * x) - Float64(4.0 * Float64(Float64(z * Float64(y * z)) - Float64(y * t)))); end return tmp end
code[x_, y_, z_, t_] := N[(N[(x * x), $MachinePrecision] - N[(N[(y * 4.0), $MachinePrecision] * N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := If[Or[LessEqual[N[(y * 4.0), $MachinePrecision], -2e+132], N[Not[LessEqual[N[(y * 4.0), $MachinePrecision], 1e-113]], $MachinePrecision]], N[(x * x + N[(N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision] * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] - N[(4.0 * N[(N[(z * N[(y * z), $MachinePrecision]), $MachinePrecision] - N[(y * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)
\begin{array}{l}
\mathbf{if}\;y \cdot 4 \leq -2 \cdot 10^{+132} \lor \neg \left(y \cdot 4 \leq 10^{-113}\right):\\
\;\;\;\;\mathsf{fma}\left(x, x, \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x - 4 \cdot \left(z \cdot \left(y \cdot z\right) - y \cdot t\right)\\
\end{array}
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
| Original | 91.0% |
|---|---|
| Target | 91.0% |
| Herbie | 97.7% |
if (*.f64 y 4) < -1.99999999999999998e132 or 9.99999999999999979e-114 < (*.f64 y 4) Initial program 91.8%
Simplified97.5%
[Start]91.8% | \[ x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)
\] |
|---|---|
fma-neg [=>]97.5% | \[ \color{blue}{\mathsf{fma}\left(x, x, -\left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)\right)}
\] |
*-commutative [=>]97.5% | \[ \mathsf{fma}\left(x, x, -\color{blue}{\left(z \cdot z - t\right) \cdot \left(y \cdot 4\right)}\right)
\] |
distribute-rgt-neg-in [=>]97.5% | \[ \mathsf{fma}\left(x, x, \color{blue}{\left(z \cdot z - t\right) \cdot \left(-y \cdot 4\right)}\right)
\] |
distribute-rgt-neg-in [=>]97.5% | \[ \mathsf{fma}\left(x, x, \left(z \cdot z - t\right) \cdot \color{blue}{\left(y \cdot \left(-4\right)\right)}\right)
\] |
metadata-eval [=>]97.5% | \[ \mathsf{fma}\left(x, x, \left(z \cdot z - t\right) \cdot \left(y \cdot \color{blue}{-4}\right)\right)
\] |
if -1.99999999999999998e132 < (*.f64 y 4) < 9.99999999999999979e-114Initial program 86.4%
Applied egg-rr86.4%
[Start]86.4% | \[ x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)
\] |
|---|---|
sub-neg [=>]86.4% | \[ x \cdot x - \left(y \cdot 4\right) \cdot \color{blue}{\left(z \cdot z + \left(-t\right)\right)}
\] |
distribute-rgt-in [=>]86.4% | \[ x \cdot x - \color{blue}{\left(\left(z \cdot z\right) \cdot \left(y \cdot 4\right) + \left(-t\right) \cdot \left(y \cdot 4\right)\right)}
\] |
Applied egg-rr99.2%
[Start]86.4% | \[ x \cdot x - \left(\left(z \cdot z\right) \cdot \left(y \cdot 4\right) + \left(-t\right) \cdot \left(y \cdot 4\right)\right)
\] |
|---|---|
distribute-rgt-out [=>]86.4% | \[ x \cdot x - \color{blue}{\left(y \cdot 4\right) \cdot \left(z \cdot z + \left(-t\right)\right)}
\] |
unsub-neg [=>]86.4% | \[ x \cdot x - \left(y \cdot 4\right) \cdot \color{blue}{\left(z \cdot z - t\right)}
\] |
add-sqr-sqrt [=>]48.6% | \[ x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - \color{blue}{\sqrt{t} \cdot \sqrt{t}}\right)
\] |
sqrt-unprod [=>]62.0% | \[ x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - \color{blue}{\sqrt{t \cdot t}}\right)
\] |
sqr-neg [<=]62.0% | \[ x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - \sqrt{\color{blue}{\left(-t\right) \cdot \left(-t\right)}}\right)
\] |
sqrt-unprod [<=]24.4% | \[ x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - \color{blue}{\sqrt{-t} \cdot \sqrt{-t}}\right)
\] |
add-sqr-sqrt [<=]57.2% | \[ x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - \color{blue}{\left(-t\right)}\right)
\] |
distribute-rgt-out-- [<=]57.2% | \[ x \cdot x - \color{blue}{\left(\left(z \cdot z\right) \cdot \left(y \cdot 4\right) - \left(-t\right) \cdot \left(y \cdot 4\right)\right)}
\] |
associate-*r* [=>]57.2% | \[ x \cdot x - \left(\color{blue}{\left(\left(z \cdot z\right) \cdot y\right) \cdot 4} - \left(-t\right) \cdot \left(y \cdot 4\right)\right)
\] |
*-commutative [<=]57.2% | \[ x \cdot x - \left(\color{blue}{\left(y \cdot \left(z \cdot z\right)\right)} \cdot 4 - \left(-t\right) \cdot \left(y \cdot 4\right)\right)
\] |
associate-*r* [=>]57.2% | \[ x \cdot x - \left(\left(y \cdot \left(z \cdot z\right)\right) \cdot 4 - \color{blue}{\left(\left(-t\right) \cdot y\right) \cdot 4}\right)
\] |
distribute-rgt-out-- [=>]57.2% | \[ x \cdot x - \color{blue}{4 \cdot \left(y \cdot \left(z \cdot z\right) - \left(-t\right) \cdot y\right)}
\] |
*-commutative [=>]57.2% | \[ x \cdot x - 4 \cdot \left(\color{blue}{\left(z \cdot z\right) \cdot y} - \left(-t\right) \cdot y\right)
\] |
associate-*l* [=>]70.0% | \[ x \cdot x - 4 \cdot \left(\color{blue}{z \cdot \left(z \cdot y\right)} - \left(-t\right) \cdot y\right)
\] |
*-commutative [=>]70.0% | \[ x \cdot x - 4 \cdot \left(z \cdot \left(z \cdot y\right) - \color{blue}{y \cdot \left(-t\right)}\right)
\] |
add-sqr-sqrt [=>]28.0% | \[ x \cdot x - 4 \cdot \left(z \cdot \left(z \cdot y\right) - y \cdot \color{blue}{\left(\sqrt{-t} \cdot \sqrt{-t}\right)}\right)
\] |
sqrt-unprod [=>]72.7% | \[ x \cdot x - 4 \cdot \left(z \cdot \left(z \cdot y\right) - y \cdot \color{blue}{\sqrt{\left(-t\right) \cdot \left(-t\right)}}\right)
\] |
sqr-neg [=>]72.7% | \[ x \cdot x - 4 \cdot \left(z \cdot \left(z \cdot y\right) - y \cdot \sqrt{\color{blue}{t \cdot t}}\right)
\] |
sqrt-unprod [<=]57.8% | \[ x \cdot x - 4 \cdot \left(z \cdot \left(z \cdot y\right) - y \cdot \color{blue}{\left(\sqrt{t} \cdot \sqrt{t}\right)}\right)
\] |
add-sqr-sqrt [<=]99.2% | \[ x \cdot x - 4 \cdot \left(z \cdot \left(z \cdot y\right) - y \cdot \color{blue}{t}\right)
\] |
Final simplification98.4%
| Alternative 1 | |
|---|---|
| Accuracy | 97.7% |
| Cost | 7625 |
| Alternative 2 | |
|---|---|
| Accuracy | 56.9% |
| Cost | 1240 |
| Alternative 3 | |
|---|---|
| Accuracy | 58.4% |
| Cost | 1240 |
| Alternative 4 | |
|---|---|
| Accuracy | 86.4% |
| Cost | 1096 |
| Alternative 5 | |
|---|---|
| Accuracy | 95.6% |
| Cost | 1092 |
| Alternative 6 | |
|---|---|
| Accuracy | 79.5% |
| Cost | 840 |
| Alternative 7 | |
|---|---|
| Accuracy | 58.3% |
| Cost | 584 |
| Alternative 8 | |
|---|---|
| Accuracy | 41.9% |
| Cost | 192 |
herbie shell --seed 2023263
(FPCore (x y z t)
:name "Graphics.Rasterific.Shading:$sradialGradientWithFocusShader from Rasterific-0.6.1, B"
:precision binary64
:herbie-target
(- (* x x) (* 4.0 (* y (- (* z z) t))))
(- (* x x) (* (* y 4.0) (- (* z z) t))))