
(FPCore (x y z t) :precision binary64 (- x (/ (* (* y 2.0) z) (- (* (* z 2.0) z) (* y t)))))
double code(double x, double y, double z, double t) {
return x - (((y * 2.0) * z) / (((z * 2.0) * z) - (y * t)));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x - (((y * 2.0d0) * z) / (((z * 2.0d0) * z) - (y * t)))
end function
public static double code(double x, double y, double z, double t) {
return x - (((y * 2.0) * z) / (((z * 2.0) * z) - (y * t)));
}
def code(x, y, z, t): return x - (((y * 2.0) * z) / (((z * 2.0) * z) - (y * t)))
function code(x, y, z, t) return Float64(x - Float64(Float64(Float64(y * 2.0) * z) / Float64(Float64(Float64(z * 2.0) * z) - Float64(y * t)))) end
function tmp = code(x, y, z, t) tmp = x - (((y * 2.0) * z) / (((z * 2.0) * z) - (y * t))); end
code[x_, y_, z_, t_] := N[(x - N[(N[(N[(y * 2.0), $MachinePrecision] * z), $MachinePrecision] / N[(N[(N[(z * 2.0), $MachinePrecision] * z), $MachinePrecision] - N[(y * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \frac{\left(y \cdot 2\right) \cdot z}{\left(z \cdot 2\right) \cdot z - y \cdot t}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (- x (/ (* (* y 2.0) z) (- (* (* z 2.0) z) (* y t)))))
double code(double x, double y, double z, double t) {
return x - (((y * 2.0) * z) / (((z * 2.0) * z) - (y * t)));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x - (((y * 2.0d0) * z) / (((z * 2.0d0) * z) - (y * t)))
end function
public static double code(double x, double y, double z, double t) {
return x - (((y * 2.0) * z) / (((z * 2.0) * z) - (y * t)));
}
def code(x, y, z, t): return x - (((y * 2.0) * z) / (((z * 2.0) * z) - (y * t)))
function code(x, y, z, t) return Float64(x - Float64(Float64(Float64(y * 2.0) * z) / Float64(Float64(Float64(z * 2.0) * z) - Float64(y * t)))) end
function tmp = code(x, y, z, t) tmp = x - (((y * 2.0) * z) / (((z * 2.0) * z) - (y * t))); end
code[x_, y_, z_, t_] := N[(x - N[(N[(N[(y * 2.0), $MachinePrecision] * z), $MachinePrecision] / N[(N[(N[(z * 2.0), $MachinePrecision] * z), $MachinePrecision] - N[(y * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \frac{\left(y \cdot 2\right) \cdot z}{\left(z \cdot 2\right) \cdot z - y \cdot t}
\end{array}
(FPCore (x y z t) :precision binary64 (if (<= (/ (* (* y 2.0) z) (- (* z (* 2.0 z)) (* y t))) INFINITY) (fma (/ y (fma z (* z -2.0) (* y t))) (* 2.0 z) x) (- x (/ y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((((y * 2.0) * z) / ((z * (2.0 * z)) - (y * t))) <= ((double) INFINITY)) {
tmp = fma((y / fma(z, (z * -2.0), (y * t))), (2.0 * z), x);
} else {
tmp = x - (y / z);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(Float64(Float64(y * 2.0) * z) / Float64(Float64(z * Float64(2.0 * z)) - Float64(y * t))) <= Inf) tmp = fma(Float64(y / fma(z, Float64(z * -2.0), Float64(y * t))), Float64(2.0 * z), x); else tmp = Float64(x - Float64(y / z)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(N[(N[(y * 2.0), $MachinePrecision] * z), $MachinePrecision] / N[(N[(z * N[(2.0 * z), $MachinePrecision]), $MachinePrecision] - N[(y * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(N[(y / N[(z * N[(z * -2.0), $MachinePrecision] + N[(y * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(2.0 * z), $MachinePrecision] + x), $MachinePrecision], N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\left(y \cdot 2\right) \cdot z}{z \cdot \left(2 \cdot z\right) - y \cdot t} \leq \infty:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{\mathsf{fma}\left(z, z \cdot -2, y \cdot t\right)}, 2 \cdot z, x\right)\\
\mathbf{else}:\\
\;\;\;\;x - \frac{y}{z}\\
\end{array}
\end{array}
if (/.f64 (*.f64 (*.f64 y #s(literal 2 binary64)) z) (-.f64 (*.f64 (*.f64 z #s(literal 2 binary64)) z) (*.f64 y t))) < +inf.0Initial program 94.5%
sub-negN/A
+-commutativeN/A
distribute-neg-frac2N/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
Applied egg-rr97.7%
*-commutativeN/A
metadata-evalN/A
distribute-lft-neg-inN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
+-commutativeN/A
associate-*l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
distribute-lft-neg-inN/A
metadata-evalN/A
*-lowering-*.f6497.7
Applied egg-rr97.7%
if +inf.0 < (/.f64 (*.f64 (*.f64 y #s(literal 2 binary64)) z) (-.f64 (*.f64 (*.f64 z #s(literal 2 binary64)) z) (*.f64 y t))) Initial program 0.0%
Taylor expanded in y around 0
mul-1-negN/A
sub-negN/A
--lowering--.f64N/A
/-lowering-/.f6482.0
Simplified82.0%
Final simplification95.8%
(FPCore (x y z t) :precision binary64 (if (<= (/ (* (* y 2.0) z) (- (* z (* 2.0 z)) (* y t))) INFINITY) (fma (* 2.0 z) (/ y (fma y t (* -2.0 (* z z)))) x) (- x (/ y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((((y * 2.0) * z) / ((z * (2.0 * z)) - (y * t))) <= ((double) INFINITY)) {
tmp = fma((2.0 * z), (y / fma(y, t, (-2.0 * (z * z)))), x);
} else {
tmp = x - (y / z);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(Float64(Float64(y * 2.0) * z) / Float64(Float64(z * Float64(2.0 * z)) - Float64(y * t))) <= Inf) tmp = fma(Float64(2.0 * z), Float64(y / fma(y, t, Float64(-2.0 * Float64(z * z)))), x); else tmp = Float64(x - Float64(y / z)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(N[(N[(y * 2.0), $MachinePrecision] * z), $MachinePrecision] / N[(N[(z * N[(2.0 * z), $MachinePrecision]), $MachinePrecision] - N[(y * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(N[(2.0 * z), $MachinePrecision] * N[(y / N[(y * t + N[(-2.0 * N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\left(y \cdot 2\right) \cdot z}{z \cdot \left(2 \cdot z\right) - y \cdot t} \leq \infty:\\
\;\;\;\;\mathsf{fma}\left(2 \cdot z, \frac{y}{\mathsf{fma}\left(y, t, -2 \cdot \left(z \cdot z\right)\right)}, x\right)\\
\mathbf{else}:\\
\;\;\;\;x - \frac{y}{z}\\
\end{array}
\end{array}
if (/.f64 (*.f64 (*.f64 y #s(literal 2 binary64)) z) (-.f64 (*.f64 (*.f64 z #s(literal 2 binary64)) z) (*.f64 y t))) < +inf.0Initial program 94.5%
sub-negN/A
+-commutativeN/A
distribute-neg-frac2N/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
Applied egg-rr97.7%
if +inf.0 < (/.f64 (*.f64 (*.f64 y #s(literal 2 binary64)) z) (-.f64 (*.f64 (*.f64 z #s(literal 2 binary64)) z) (*.f64 y t))) Initial program 0.0%
Taylor expanded in y around 0
mul-1-negN/A
sub-negN/A
--lowering--.f64N/A
/-lowering-/.f6482.0
Simplified82.0%
Final simplification95.8%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (- x (/ y z)))) (if (<= z -3.2e-18) t_1 (if (<= z 1.75e-65) (fma (/ z t) 2.0 x) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = x - (y / z);
double tmp;
if (z <= -3.2e-18) {
tmp = t_1;
} else if (z <= 1.75e-65) {
tmp = fma((z / t), 2.0, x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(x - Float64(y / z)) tmp = 0.0 if (z <= -3.2e-18) tmp = t_1; elseif (z <= 1.75e-65) tmp = fma(Float64(z / t), 2.0, x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -3.2e-18], t$95$1, If[LessEqual[z, 1.75e-65], N[(N[(z / t), $MachinePrecision] * 2.0 + x), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x - \frac{y}{z}\\
\mathbf{if}\;z \leq -3.2 \cdot 10^{-18}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 1.75 \cdot 10^{-65}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, 2, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -3.1999999999999999e-18 or 1.75000000000000002e-65 < z Initial program 77.8%
Taylor expanded in y around 0
mul-1-negN/A
sub-negN/A
--lowering--.f64N/A
/-lowering-/.f6491.8
Simplified91.8%
if -3.1999999999999999e-18 < z < 1.75000000000000002e-65Initial program 88.2%
Taylor expanded in y around inf
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
associate-*r/N/A
*-commutativeN/A
associate-*r/N/A
metadata-evalN/A
associate-*r/N/A
accelerator-lowering-fma.f64N/A
associate-*r/N/A
metadata-evalN/A
/-lowering-/.f6495.9
Simplified95.9%
clear-numN/A
associate-*r/N/A
div-invN/A
times-fracN/A
metadata-evalN/A
metadata-evalN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6496.0
Applied egg-rr96.0%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (- x (/ y z)))) (if (<= z -1.1e-17) t_1 (if (<= z 1.4e-65) (fma z (/ 2.0 t) x) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = x - (y / z);
double tmp;
if (z <= -1.1e-17) {
tmp = t_1;
} else if (z <= 1.4e-65) {
tmp = fma(z, (2.0 / t), x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(x - Float64(y / z)) tmp = 0.0 if (z <= -1.1e-17) tmp = t_1; elseif (z <= 1.4e-65) tmp = fma(z, Float64(2.0 / t), x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.1e-17], t$95$1, If[LessEqual[z, 1.4e-65], N[(z * N[(2.0 / t), $MachinePrecision] + x), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x - \frac{y}{z}\\
\mathbf{if}\;z \leq -1.1 \cdot 10^{-17}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 1.4 \cdot 10^{-65}:\\
\;\;\;\;\mathsf{fma}\left(z, \frac{2}{t}, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -1.1e-17 or 1.4e-65 < z Initial program 77.8%
Taylor expanded in y around 0
mul-1-negN/A
sub-negN/A
--lowering--.f64N/A
/-lowering-/.f6491.8
Simplified91.8%
if -1.1e-17 < z < 1.4e-65Initial program 88.2%
Taylor expanded in y around inf
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
associate-*r/N/A
*-commutativeN/A
associate-*r/N/A
metadata-evalN/A
associate-*r/N/A
accelerator-lowering-fma.f64N/A
associate-*r/N/A
metadata-evalN/A
/-lowering-/.f6495.9
Simplified95.9%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (- x (/ y z)))) (if (<= z -1.08e-17) t_1 (if (<= z 4.8e-65) x t_1))))
double code(double x, double y, double z, double t) {
double t_1 = x - (y / z);
double tmp;
if (z <= -1.08e-17) {
tmp = t_1;
} else if (z <= 4.8e-65) {
tmp = x;
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: tmp
t_1 = x - (y / z)
if (z <= (-1.08d-17)) then
tmp = t_1
else if (z <= 4.8d-65) then
tmp = x
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = x - (y / z);
double tmp;
if (z <= -1.08e-17) {
tmp = t_1;
} else if (z <= 4.8e-65) {
tmp = x;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = x - (y / z) tmp = 0 if z <= -1.08e-17: tmp = t_1 elif z <= 4.8e-65: tmp = x else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(x - Float64(y / z)) tmp = 0.0 if (z <= -1.08e-17) tmp = t_1; elseif (z <= 4.8e-65) tmp = x; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = x - (y / z); tmp = 0.0; if (z <= -1.08e-17) tmp = t_1; elseif (z <= 4.8e-65) tmp = x; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.08e-17], t$95$1, If[LessEqual[z, 4.8e-65], x, t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x - \frac{y}{z}\\
\mathbf{if}\;z \leq -1.08 \cdot 10^{-17}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 4.8 \cdot 10^{-65}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -1.07999999999999995e-17 or 4.8000000000000003e-65 < z Initial program 77.8%
Taylor expanded in y around 0
mul-1-negN/A
sub-negN/A
--lowering--.f64N/A
/-lowering-/.f6491.8
Simplified91.8%
if -1.07999999999999995e-17 < z < 4.8000000000000003e-65Initial program 88.2%
Taylor expanded in x around inf
Simplified80.3%
(FPCore (x y z t) :precision binary64 x)
double code(double x, double y, double z, double t) {
return x;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x
end function
public static double code(double x, double y, double z, double t) {
return x;
}
def code(x, y, z, t): return x
function code(x, y, z, t) return x end
function tmp = code(x, y, z, t) tmp = x; end
code[x_, y_, z_, t_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 82.7%
Taylor expanded in x around inf
Simplified77.9%
(FPCore (x y z t) :precision binary64 (- x (/ 1.0 (- (/ z y) (/ (/ t 2.0) z)))))
double code(double x, double y, double z, double t) {
return x - (1.0 / ((z / y) - ((t / 2.0) / z)));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x - (1.0d0 / ((z / y) - ((t / 2.0d0) / z)))
end function
public static double code(double x, double y, double z, double t) {
return x - (1.0 / ((z / y) - ((t / 2.0) / z)));
}
def code(x, y, z, t): return x - (1.0 / ((z / y) - ((t / 2.0) / z)))
function code(x, y, z, t) return Float64(x - Float64(1.0 / Float64(Float64(z / y) - Float64(Float64(t / 2.0) / z)))) end
function tmp = code(x, y, z, t) tmp = x - (1.0 / ((z / y) - ((t / 2.0) / z))); end
code[x_, y_, z_, t_] := N[(x - N[(1.0 / N[(N[(z / y), $MachinePrecision] - N[(N[(t / 2.0), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \frac{1}{\frac{z}{y} - \frac{\frac{t}{2}}{z}}
\end{array}
herbie shell --seed 2024199
(FPCore (x y z t)
:name "Numeric.AD.Rank1.Halley:findZero from ad-4.2.4"
:precision binary64
:alt
(! :herbie-platform default (- x (/ 1 (- (/ z y) (/ (/ t 2) z)))))
(- x (/ (* (* y 2.0) z) (- (* (* z 2.0) z) (* y t)))))