
(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 (let* ((t_0 (* z (* y 4.0)))) (if (<= t_0 5e+197) (- (* x x) t_0) (* z (- (* x (/ x z)) (* y 4.0))))))
double code(double x, double y, double z) {
double t_0 = z * (y * 4.0);
double tmp;
if (t_0 <= 5e+197) {
tmp = (x * x) - t_0;
} else {
tmp = z * ((x * (x / z)) - (y * 4.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) :: t_0
real(8) :: tmp
t_0 = z * (y * 4.0d0)
if (t_0 <= 5d+197) then
tmp = (x * x) - t_0
else
tmp = z * ((x * (x / z)) - (y * 4.0d0))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * (y * 4.0);
double tmp;
if (t_0 <= 5e+197) {
tmp = (x * x) - t_0;
} else {
tmp = z * ((x * (x / z)) - (y * 4.0));
}
return tmp;
}
def code(x, y, z): t_0 = z * (y * 4.0) tmp = 0 if t_0 <= 5e+197: tmp = (x * x) - t_0 else: tmp = z * ((x * (x / z)) - (y * 4.0)) return tmp
function code(x, y, z) t_0 = Float64(z * Float64(y * 4.0)) tmp = 0.0 if (t_0 <= 5e+197) tmp = Float64(Float64(x * x) - t_0); else tmp = Float64(z * Float64(Float64(x * Float64(x / z)) - Float64(y * 4.0))); end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * (y * 4.0); tmp = 0.0; if (t_0 <= 5e+197) tmp = (x * x) - t_0; else tmp = z * ((x * (x / z)) - (y * 4.0)); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 5e+197], N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision], N[(z * N[(N[(x * N[(x / z), $MachinePrecision]), $MachinePrecision] - N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(y \cdot 4\right)\\
\mathbf{if}\;t\_0 \leq 5 \cdot 10^{+197}:\\
\;\;\;\;x \cdot x - t\_0\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x \cdot \frac{x}{z} - y \cdot 4\right)\\
\end{array}
\end{array}
if (*.f64 (*.f64 y #s(literal 4 binary64)) z) < 5.00000000000000009e197Initial program 100.0%
if 5.00000000000000009e197 < (*.f64 (*.f64 y #s(literal 4 binary64)) z) Initial program 82.1%
Taylor expanded in z around inf 89.3%
unpow289.3%
associate-/l*100.0%
Applied egg-rr100.0%
Final simplification100.0%
(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 98.0%
fma-neg99.2%
associate-*l*99.2%
*-commutative99.2%
distribute-rgt-neg-in99.2%
distribute-rgt-neg-in99.2%
metadata-eval99.2%
Simplified99.2%
(FPCore (x y z)
:precision binary64
(if (or (<= (* x x) 9e-54)
(and (not (<= (* x x) 1.3e+169)) (<= (* x x) 6.8e+209)))
(* y (* z -4.0))
(* x x)))
double code(double x, double y, double z) {
double tmp;
if (((x * x) <= 9e-54) || (!((x * x) <= 1.3e+169) && ((x * x) <= 6.8e+209))) {
tmp = y * (z * -4.0);
} else {
tmp = x * x;
}
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) <= 9d-54) .or. (.not. ((x * x) <= 1.3d+169)) .and. ((x * x) <= 6.8d+209)) then
tmp = y * (z * (-4.0d0))
else
tmp = x * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (((x * x) <= 9e-54) || (!((x * x) <= 1.3e+169) && ((x * x) <= 6.8e+209))) {
tmp = y * (z * -4.0);
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((x * x) <= 9e-54) or (not ((x * x) <= 1.3e+169) and ((x * x) <= 6.8e+209)): tmp = y * (z * -4.0) else: tmp = x * x return tmp
function code(x, y, z) tmp = 0.0 if ((Float64(x * x) <= 9e-54) || (!(Float64(x * x) <= 1.3e+169) && (Float64(x * x) <= 6.8e+209))) tmp = Float64(y * Float64(z * -4.0)); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (((x * x) <= 9e-54) || (~(((x * x) <= 1.3e+169)) && ((x * x) <= 6.8e+209))) tmp = y * (z * -4.0); else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[N[(x * x), $MachinePrecision], 9e-54], And[N[Not[LessEqual[N[(x * x), $MachinePrecision], 1.3e+169]], $MachinePrecision], LessEqual[N[(x * x), $MachinePrecision], 6.8e+209]]], N[(y * N[(z * -4.0), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 9 \cdot 10^{-54} \lor \neg \left(x \cdot x \leq 1.3 \cdot 10^{+169}\right) \land x \cdot x \leq 6.8 \cdot 10^{+209}:\\
\;\;\;\;y \cdot \left(z \cdot -4\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 8.9999999999999997e-54 or 1.3e169 < (*.f64 x x) < 6.7999999999999993e209Initial program 100.0%
Taylor expanded in x around 0 92.1%
associate-*r*92.1%
*-commutative92.1%
associate-*r*92.1%
Simplified92.1%
if 8.9999999999999997e-54 < (*.f64 x x) < 1.3e169 or 6.7999999999999993e209 < (*.f64 x x) Initial program 96.4%
Taylor expanded in x around inf 80.2%
unpow280.2%
Applied egg-rr80.2%
Final simplification85.6%
(FPCore (x y z) :precision binary64 (- (* x x) (* z (* y 4.0))))
double code(double x, double y, double z) {
return (x * x) - (z * (y * 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 = (x * x) - (z * (y * 4.0d0))
end function
public static double code(double x, double y, double z) {
return (x * x) - (z * (y * 4.0));
}
def code(x, y, z): return (x * x) - (z * (y * 4.0))
function code(x, y, z) return Float64(Float64(x * x) - Float64(z * Float64(y * 4.0))) end
function tmp = code(x, y, z) tmp = (x * x) - (z * (y * 4.0)); end
code[x_, y_, z_] := N[(N[(x * x), $MachinePrecision] - N[(z * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x - z \cdot \left(y \cdot 4\right)
\end{array}
Initial program 98.0%
Final simplification98.0%
(FPCore (x y z) :precision binary64 (* x x))
double code(double x, double y, double z) {
return x * x;
}
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
end function
public static double code(double x, double y, double z) {
return x * x;
}
def code(x, y, z): return x * x
function code(x, y, z) return Float64(x * x) end
function tmp = code(x, y, z) tmp = x * x; end
code[x_, y_, z_] := N[(x * x), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x
\end{array}
Initial program 98.0%
Taylor expanded in x around inf 50.6%
unpow250.6%
Applied egg-rr50.6%
herbie shell --seed 2024111
(FPCore (x y z)
:name "Graphics.Rasterific.QuadraticFormula:discriminant from Rasterific-0.6.1"
:precision binary64
(- (* x x) (* (* y 4.0) z)))