
(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}
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (let* ((t_0 (* (* y 4.0) z))) (if (<= t_0 5e-166) (- (* x x) t_0) (* z (- (/ (* x x) z) (* y 4.0))))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = (y * 4.0) * z;
double tmp;
if (t_0 <= 5e-166) {
tmp = (x * x) - t_0;
} else {
tmp = z * (((x * x) / z) - (y * 4.0));
}
return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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 <= 5d-166) then
tmp = (x * x) - t_0
else
tmp = z * (((x * x) / z) - (y * 4.0d0))
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double t_0 = (y * 4.0) * z;
double tmp;
if (t_0 <= 5e-166) {
tmp = (x * x) - t_0;
} else {
tmp = z * (((x * x) / z) - (y * 4.0));
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = (y * 4.0) * z tmp = 0 if t_0 <= 5e-166: tmp = (x * x) - t_0 else: tmp = z * (((x * x) / z) - (y * 4.0)) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(Float64(y * 4.0) * z) tmp = 0.0 if (t_0 <= 5e-166) tmp = Float64(Float64(x * x) - t_0); else tmp = Float64(z * Float64(Float64(Float64(x * x) / z) - Float64(y * 4.0))); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = (y * 4.0) * z;
tmp = 0.0;
if (t_0 <= 5e-166)
tmp = (x * x) - t_0;
else
tmp = z * (((x * x) / z) - (y * 4.0));
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y * 4.0), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[t$95$0, 5e-166], N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision], N[(z * N[(N[(N[(x * x), $MachinePrecision] / z), $MachinePrecision] - N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := \left(y \cdot 4\right) \cdot z\\
\mathbf{if}\;t\_0 \leq 5 \cdot 10^{-166}:\\
\;\;\;\;x \cdot x - t\_0\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(\frac{x \cdot x}{z} - y \cdot 4\right)\\
\end{array}
\end{array}
if (*.f64 (*.f64 y #s(literal 4 binary64)) z) < 5e-166Initial program 100.0%
if 5e-166 < (*.f64 (*.f64 y #s(literal 4 binary64)) z) Initial program 94.5%
Taylor expanded in z around inf 100.0%
unpow2100.0%
Applied egg-rr100.0%
Final simplification100.0%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* x x) 2.1e+277) (- (* x x) (* (* y 4.0) z)) (* x x)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((x * x) <= 2.1e+277) {
tmp = (x * x) - ((y * 4.0) * z);
} else {
tmp = x * x;
}
return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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) <= 2.1d+277) then
tmp = (x * x) - ((y * 4.0d0) * z)
else
tmp = x * x
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((x * x) <= 2.1e+277) {
tmp = (x * x) - ((y * 4.0) * z);
} else {
tmp = x * x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (x * x) <= 2.1e+277: tmp = (x * x) - ((y * 4.0) * z) else: tmp = x * x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(x * x) <= 2.1e+277) tmp = Float64(Float64(x * x) - Float64(Float64(y * 4.0) * z)); else tmp = Float64(x * x); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((x * x) <= 2.1e+277)
tmp = (x * x) - ((y * 4.0) * z);
else
tmp = x * x;
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[N[(x * x), $MachinePrecision], 2.1e+277], N[(N[(x * x), $MachinePrecision] - N[(N[(y * 4.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 2.1 \cdot 10^{+277}:\\
\;\;\;\;x \cdot x - \left(y \cdot 4\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 2.09999999999999999e277Initial program 100.0%
if 2.09999999999999999e277 < (*.f64 x x) Initial program 94.0%
Taylor expanded in x around inf 100.0%
unpow296.8%
Applied egg-rr100.0%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* x x) 7.5e-36) (* -4.0 (* y z)) (* x x)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((x * x) <= 7.5e-36) {
tmp = -4.0 * (y * z);
} else {
tmp = x * x;
}
return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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) <= 7.5d-36) then
tmp = (-4.0d0) * (y * z)
else
tmp = x * x
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((x * x) <= 7.5e-36) {
tmp = -4.0 * (y * z);
} else {
tmp = x * x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (x * x) <= 7.5e-36: tmp = -4.0 * (y * z) else: tmp = x * x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(x * x) <= 7.5e-36) tmp = Float64(-4.0 * Float64(y * z)); else tmp = Float64(x * x); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((x * x) <= 7.5e-36)
tmp = -4.0 * (y * z);
else
tmp = x * x;
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[N[(x * x), $MachinePrecision], 7.5e-36], N[(-4.0 * N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 7.5 \cdot 10^{-36}:\\
\;\;\;\;-4 \cdot \left(y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 7.49999999999999972e-36Initial program 100.0%
Taylor expanded in x around 0 86.2%
if 7.49999999999999972e-36 < (*.f64 x x) Initial program 96.4%
Taylor expanded in x around inf 88.9%
unpow287.9%
Applied egg-rr88.9%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (* x x))
assert(x < y && y < z);
double code(double x, double y, double z) {
return x * x;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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
assert x < y && y < z;
public static double code(double x, double y, double z) {
return x * x;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return x * x
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(x * x) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = x * x;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(x * x), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
x \cdot x
\end{array}
Initial program 98.0%
Taylor expanded in x around inf 58.1%
unpow293.4%
Applied egg-rr58.1%
herbie shell --seed 2024100
(FPCore (x y z)
:name "Graphics.Rasterific.QuadraticFormula:discriminant from Rasterific-0.6.1"
:precision binary64
(- (* x x) (* (* y 4.0) z)))