| Alternative 1 | |
|---|---|
| Accuracy | 99.0% |
| Cost | 7108 |
\[\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 10^{+272}:\\
\;\;\;\;\mathsf{fma}\left(x, x, z \cdot \left(y \cdot -4\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\]

(FPCore (x y z) :precision binary64 (- (* x x) (* (* y 4.0) z)))
(FPCore (x y z) :precision binary64 (if (<= (* x x) 1e+272) (fma x x (* z (* y -4.0))) (* x x)))
double code(double x, double y, double z) {
return (x * x) - ((y * 4.0) * z);
}
double code(double x, double y, double z) {
double tmp;
if ((x * x) <= 1e+272) {
tmp = fma(x, x, (z * (y * -4.0)));
} else {
tmp = x * x;
}
return tmp;
}
function code(x, y, z) return Float64(Float64(x * x) - Float64(Float64(y * 4.0) * z)) end
function code(x, y, z) tmp = 0.0 if (Float64(x * x) <= 1e+272) tmp = fma(x, x, Float64(z * Float64(y * -4.0))); else tmp = Float64(x * x); end return tmp end
code[x_, y_, z_] := N[(N[(x * x), $MachinePrecision] - N[(N[(y * 4.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := If[LessEqual[N[(x * x), $MachinePrecision], 1e+272], N[(x * x + N[(z * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
x \cdot x - \left(y \cdot 4\right) \cdot z
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 10^{+272}:\\
\;\;\;\;\mathsf{fma}\left(x, x, z \cdot \left(y \cdot -4\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
if (*.f64 x x) < 1.0000000000000001e272Initial program 100.0%
Simplified100.0%
[Start]100.0% | \[ x \cdot x - \left(y \cdot 4\right) \cdot z
\] |
|---|---|
fma-neg [=>]100.0% | \[ \color{blue}{\mathsf{fma}\left(x, x, -\left(y \cdot 4\right) \cdot z\right)}
\] |
*-commutative [=>]100.0% | \[ \mathsf{fma}\left(x, x, -\color{blue}{z \cdot \left(y \cdot 4\right)}\right)
\] |
distribute-rgt-neg-in [=>]100.0% | \[ \mathsf{fma}\left(x, x, \color{blue}{z \cdot \left(-y \cdot 4\right)}\right)
\] |
distribute-rgt-neg-in [=>]100.0% | \[ \mathsf{fma}\left(x, x, z \cdot \color{blue}{\left(y \cdot \left(-4\right)\right)}\right)
\] |
metadata-eval [=>]100.0% | \[ \mathsf{fma}\left(x, x, z \cdot \left(y \cdot \color{blue}{-4}\right)\right)
\] |
if 1.0000000000000001e272 < (*.f64 x x) Initial program 91.1%
Taylor expanded in x around inf 100.0%
Simplified100.0%
[Start]100.0% | \[ {x}^{2}
\] |
|---|---|
unpow2 [=>]100.0% | \[ \color{blue}{x \cdot x}
\] |
Final simplification100.0%
| Alternative 1 | |
|---|---|
| Accuracy | 99.0% |
| Cost | 7108 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 6848 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.1% |
| Cost | 836 |
| Alternative 4 | |
|---|---|
| Accuracy | 85.0% |
| Cost | 580 |
| Alternative 5 | |
|---|---|
| Accuracy | 85.0% |
| Cost | 580 |
| Alternative 6 | |
|---|---|
| Accuracy | 52.7% |
| Cost | 192 |
herbie shell --seed 2023272
(FPCore (x y z)
:name "Graphics.Rasterific.QuadraticFormula:discriminant from Rasterific-0.6.1"
:precision binary64
(- (* x x) (* (* y 4.0) z)))