
(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 4 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 (* (* y 4.0) z))) (if (<= t_0 4e+168) (- (* x x) t_0) (* y (+ (/ (* x x) y) (* -4.0 z))))))
double code(double x, double y, double z) {
double t_0 = (y * 4.0) * z;
double tmp;
if (t_0 <= 4e+168) {
tmp = (x * x) - t_0;
} else {
tmp = y * (((x * x) / y) + (-4.0 * z));
}
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 = (y * 4.0d0) * z
if (t_0 <= 4d+168) then
tmp = (x * x) - t_0
else
tmp = y * (((x * x) / y) + ((-4.0d0) * z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (y * 4.0) * z;
double tmp;
if (t_0 <= 4e+168) {
tmp = (x * x) - t_0;
} else {
tmp = y * (((x * x) / y) + (-4.0 * z));
}
return tmp;
}
def code(x, y, z): t_0 = (y * 4.0) * z tmp = 0 if t_0 <= 4e+168: tmp = (x * x) - t_0 else: tmp = y * (((x * x) / y) + (-4.0 * z)) return tmp
function code(x, y, z) t_0 = Float64(Float64(y * 4.0) * z) tmp = 0.0 if (t_0 <= 4e+168) tmp = Float64(Float64(x * x) - t_0); else tmp = Float64(y * Float64(Float64(Float64(x * x) / y) + Float64(-4.0 * z))); end return tmp end
function tmp_2 = code(x, y, z) t_0 = (y * 4.0) * z; tmp = 0.0; if (t_0 <= 4e+168) tmp = (x * x) - t_0; else tmp = y * (((x * x) / y) + (-4.0 * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y * 4.0), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[t$95$0, 4e+168], N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision], N[(y * N[(N[(N[(x * x), $MachinePrecision] / y), $MachinePrecision] + N[(-4.0 * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y \cdot 4\right) \cdot z\\
\mathbf{if}\;t\_0 \leq 4 \cdot 10^{+168}:\\
\;\;\;\;x \cdot x - t\_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(\frac{x \cdot x}{y} + -4 \cdot z\right)\\
\end{array}
\end{array}
if (*.f64 (*.f64 y #s(literal 4 binary64)) z) < 3.9999999999999997e168Initial program 100.0%
if 3.9999999999999997e168 < (*.f64 (*.f64 y #s(literal 4 binary64)) z) Initial program 80.6%
Applied egg-rr0
Taylor expanded in y around inf 0
Simplified0
(FPCore (x y z) :precision binary64 (if (<= (* x x) 1.42e+274) (- (* x x) (* (* y 4.0) z)) (* x x)))
double code(double x, double y, double z) {
double tmp;
if ((x * x) <= 1.42e+274) {
tmp = (x * x) - ((y * 4.0) * z);
} 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) <= 1.42d+274) then
tmp = (x * x) - ((y * 4.0d0) * z)
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) <= 1.42e+274) {
tmp = (x * x) - ((y * 4.0) * z);
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x * x) <= 1.42e+274: tmp = (x * x) - ((y * 4.0) * z) else: tmp = x * x return tmp
function code(x, y, z) tmp = 0.0 if (Float64(x * x) <= 1.42e+274) tmp = Float64(Float64(x * x) - Float64(Float64(y * 4.0) * z)); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x * x) <= 1.42e+274) tmp = (x * x) - ((y * 4.0) * z); else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(x * x), $MachinePrecision], 1.42e+274], N[(N[(x * x), $MachinePrecision] - N[(N[(y * 4.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 1.42 \cdot 10^{+274}:\\
\;\;\;\;x \cdot x - \left(y \cdot 4\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 1.42e274Initial program 100.0%
if 1.42e274 < (*.f64 x x) Initial program 91.9%
Taylor expanded in x around inf 0
Simplified0
(FPCore (x y z) :precision binary64 (if (<= (* x x) 165000.0) (* -4.0 (* y z)) (* x x)))
double code(double x, double y, double z) {
double tmp;
if ((x * x) <= 165000.0) {
tmp = -4.0 * (y * z);
} 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) <= 165000.0d0) then
tmp = (-4.0d0) * (y * z)
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) <= 165000.0) {
tmp = -4.0 * (y * z);
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x * x) <= 165000.0: tmp = -4.0 * (y * z) else: tmp = x * x return tmp
function code(x, y, z) tmp = 0.0 if (Float64(x * x) <= 165000.0) tmp = Float64(-4.0 * Float64(y * z)); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x * x) <= 165000.0) tmp = -4.0 * (y * z); else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(x * x), $MachinePrecision], 165000.0], N[(-4.0 * N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 165000:\\
\;\;\;\;-4 \cdot \left(y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 165000Initial program 100.0%
Taylor expanded in x around 0 0
Simplified0
if 165000 < (*.f64 x x) Initial program 95.6%
Taylor expanded in x around inf 0
Simplified0
(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 97.7%
Taylor expanded in x around inf 0
Simplified0
herbie shell --seed 2024110
(FPCore (x y z)
:name "Graphics.Rasterific.QuadraticFormula:discriminant from Rasterific-0.6.1"
:precision binary64
(- (* x x) (* (* y 4.0) z)))