
(FPCore (x y z) :precision binary64 (- (* x x) (* (* y 4.0) z)))
double code(double x, double y, double z) {
return (x * x) - ((y * 4.0) * z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * x) - ((y * 4.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * x) - ((y * 4.0) * z);
}
def code(x, y, z): return (x * x) - ((y * 4.0) * z)
function code(x, y, z) return Float64(Float64(x * x) - Float64(Float64(y * 4.0) * z)) end
function tmp = code(x, y, z) tmp = (x * x) - ((y * 4.0) * z); end
code[x_, y_, z_] := N[(N[(x * x), $MachinePrecision] - N[(N[(y * 4.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x - \left(y \cdot 4\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (- (* x x) (* (* y 4.0) z)))
double code(double x, double y, double z) {
return (x * x) - ((y * 4.0) * z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * x) - ((y * 4.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * x) - ((y * 4.0) * z);
}
def code(x, y, z): return (x * x) - ((y * 4.0) * z)
function code(x, y, z) return Float64(Float64(x * x) - Float64(Float64(y * 4.0) * z)) end
function tmp = code(x, y, z) tmp = (x * x) - ((y * 4.0) * z); end
code[x_, y_, z_] := N[(N[(x * x), $MachinePrecision] - N[(N[(y * 4.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x - \left(y \cdot 4\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (if (<= (* x x) 5e+283) (- (* x x) (* z (* y 4.0))) (pow x 2.0)))
double code(double x, double y, double z) {
double tmp;
if ((x * x) <= 5e+283) {
tmp = (x * x) - (z * (y * 4.0));
} else {
tmp = pow(x, 2.0);
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((x * x) <= 5d+283) then
tmp = (x * x) - (z * (y * 4.0d0))
else
tmp = x ** 2.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x * x) <= 5e+283) {
tmp = (x * x) - (z * (y * 4.0));
} else {
tmp = Math.pow(x, 2.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x * x) <= 5e+283: tmp = (x * x) - (z * (y * 4.0)) else: tmp = math.pow(x, 2.0) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(x * x) <= 5e+283) tmp = Float64(Float64(x * x) - Float64(z * Float64(y * 4.0))); else tmp = x ^ 2.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x * x) <= 5e+283) tmp = (x * x) - (z * (y * 4.0)); else tmp = x ^ 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(x * x), $MachinePrecision], 5e+283], N[(N[(x * x), $MachinePrecision] - N[(z * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Power[x, 2.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 5 \cdot 10^{+283}:\\
\;\;\;\;x \cdot x - z \cdot \left(y \cdot 4\right)\\
\mathbf{else}:\\
\;\;\;\;{x}^{2}\\
\end{array}
\end{array}
if (*.f64 x x) < 5.0000000000000004e283Initial program 100.0%
if 5.0000000000000004e283 < (*.f64 x x) Initial program 87.3%
Taylor expanded in x around inf 94.4%
Final simplification98.4%
(FPCore (x y z) :precision binary64 (fma x x (* y (* z -4.0))))
double code(double x, double y, double z) {
return fma(x, x, (y * (z * -4.0)));
}
function code(x, y, z) return fma(x, x, Float64(y * Float64(z * -4.0))) end
code[x_, y_, z_] := N[(x * x + N[(y * N[(z * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, x, y \cdot \left(z \cdot -4\right)\right)
\end{array}
Initial program 96.5%
fma-neg98.0%
associate-*l*98.0%
*-commutative98.0%
distribute-rgt-neg-in98.0%
distribute-rgt-neg-in98.0%
metadata-eval98.0%
Simplified98.0%
Final simplification98.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- (* x x) (* z (* y 4.0))))) (if (<= t_0 INFINITY) t_0 (* -4.0 (* y z)))))
double code(double x, double y, double z) {
double t_0 = (x * x) - (z * (y * 4.0));
double tmp;
if (t_0 <= ((double) INFINITY)) {
tmp = t_0;
} else {
tmp = -4.0 * (y * z);
}
return tmp;
}
public static double code(double x, double y, double z) {
double t_0 = (x * x) - (z * (y * 4.0));
double tmp;
if (t_0 <= Double.POSITIVE_INFINITY) {
tmp = t_0;
} else {
tmp = -4.0 * (y * z);
}
return tmp;
}
def code(x, y, z): t_0 = (x * x) - (z * (y * 4.0)) tmp = 0 if t_0 <= math.inf: tmp = t_0 else: tmp = -4.0 * (y * z) return tmp
function code(x, y, z) t_0 = Float64(Float64(x * x) - Float64(z * Float64(y * 4.0))) tmp = 0.0 if (t_0 <= Inf) tmp = t_0; else tmp = Float64(-4.0 * Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x * x) - (z * (y * 4.0)); tmp = 0.0; if (t_0 <= Inf) tmp = t_0; else tmp = -4.0 * (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * x), $MachinePrecision] - N[(z * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, Infinity], t$95$0, N[(-4.0 * N[(y * z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot x - z \cdot \left(y \cdot 4\right)\\
\mathbf{if}\;t\_0 \leq \infty:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;-4 \cdot \left(y \cdot z\right)\\
\end{array}
\end{array}
if (-.f64 (*.f64 x x) (*.f64 (*.f64 y 4) z)) < +inf.0Initial program 100.0%
if +inf.0 < (-.f64 (*.f64 x x) (*.f64 (*.f64 y 4) z)) Initial program 0.0%
Taylor expanded in x around 0 44.4%
Final simplification98.0%
(FPCore (x y z) :precision binary64 (* -4.0 (* y z)))
double code(double x, double y, double z) {
return -4.0 * (y * z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (-4.0d0) * (y * z)
end function
public static double code(double x, double y, double z) {
return -4.0 * (y * z);
}
def code(x, y, z): return -4.0 * (y * z)
function code(x, y, z) return Float64(-4.0 * Float64(y * z)) end
function tmp = code(x, y, z) tmp = -4.0 * (y * z); end
code[x_, y_, z_] := N[(-4.0 * N[(y * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-4 \cdot \left(y \cdot z\right)
\end{array}
Initial program 96.5%
Taylor expanded in x around 0 55.1%
Final simplification55.1%
(FPCore (x y z) :precision binary64 (* y (* z -4.0)))
double code(double x, double y, double z) {
return y * (z * -4.0);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y * (z * (-4.0d0))
end function
public static double code(double x, double y, double z) {
return y * (z * -4.0);
}
def code(x, y, z): return y * (z * -4.0)
function code(x, y, z) return Float64(y * Float64(z * -4.0)) end
function tmp = code(x, y, z) tmp = y * (z * -4.0); end
code[x_, y_, z_] := N[(y * N[(z * -4.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \left(z \cdot -4\right)
\end{array}
Initial program 96.5%
Taylor expanded in x around 0 55.1%
add-log-exp25.1%
*-un-lft-identity25.1%
log-prod25.1%
metadata-eval25.1%
add-log-exp55.1%
*-commutative55.1%
associate-*l*55.1%
Applied egg-rr55.1%
+-lft-identity55.1%
Simplified55.1%
Final simplification55.1%
herbie shell --seed 2024039
(FPCore (x y z)
:name "Graphics.Rasterific.QuadraticFormula:discriminant from Rasterific-0.6.1"
:precision binary64
(- (* x x) (* (* y 4.0) z)))