
(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 5 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 (+ x (/ 2.0 (+ (* -2.0 (/ z y)) (/ t z)))))
double code(double x, double y, double z, double t) {
return x + (2.0 / ((-2.0 * (z / y)) + (t / 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 + (2.0d0 / (((-2.0d0) * (z / y)) + (t / z)))
end function
public static double code(double x, double y, double z, double t) {
return x + (2.0 / ((-2.0 * (z / y)) + (t / z)));
}
def code(x, y, z, t): return x + (2.0 / ((-2.0 * (z / y)) + (t / z)))
function code(x, y, z, t) return Float64(x + Float64(2.0 / Float64(Float64(-2.0 * Float64(z / y)) + Float64(t / z)))) end
function tmp = code(x, y, z, t) tmp = x + (2.0 / ((-2.0 * (z / y)) + (t / z))); end
code[x_, y_, z_, t_] := N[(x + N[(2.0 / N[(N[(-2.0 * N[(z / y), $MachinePrecision]), $MachinePrecision] + N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{2}{-2 \cdot \frac{z}{y} + \frac{t}{z}}
\end{array}
Initial program 85.2%
Simplified99.2%
Taylor expanded in x around 0 98.3%
clear-num98.1%
un-div-inv98.1%
fma-def98.1%
associate-/l*96.9%
Applied egg-rr96.9%
Taylor expanded in z around 0 99.8%
Final simplification99.8%
(FPCore (x y z t) :precision binary64 (if (or (<= z -11000.0) (not (<= z 3e+46))) (- x (/ y z)) (+ x (* z (/ 2.0 t)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -11000.0) || !(z <= 3e+46)) {
tmp = x - (y / z);
} else {
tmp = x + (z * (2.0 / t));
}
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) :: tmp
if ((z <= (-11000.0d0)) .or. (.not. (z <= 3d+46))) then
tmp = x - (y / z)
else
tmp = x + (z * (2.0d0 / t))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -11000.0) || !(z <= 3e+46)) {
tmp = x - (y / z);
} else {
tmp = x + (z * (2.0 / t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -11000.0) or not (z <= 3e+46): tmp = x - (y / z) else: tmp = x + (z * (2.0 / t)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -11000.0) || !(z <= 3e+46)) tmp = Float64(x - Float64(y / z)); else tmp = Float64(x + Float64(z * Float64(2.0 / t))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -11000.0) || ~((z <= 3e+46))) tmp = x - (y / z); else tmp = x + (z * (2.0 / t)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -11000.0], N[Not[LessEqual[z, 3e+46]], $MachinePrecision]], N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision], N[(x + N[(z * N[(2.0 / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -11000 \lor \neg \left(z \leq 3 \cdot 10^{+46}\right):\\
\;\;\;\;x - \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x + z \cdot \frac{2}{t}\\
\end{array}
\end{array}
if z < -11000 or 3.00000000000000023e46 < z Initial program 73.1%
sub-neg73.1%
associate-/l*84.4%
distribute-neg-frac84.4%
distribute-lft-neg-out84.4%
associate-/r/83.4%
distribute-lft-neg-out83.4%
distribute-rgt-neg-in83.4%
metadata-eval83.4%
*-commutative83.4%
associate-*l*83.4%
fma-neg83.4%
Simplified83.4%
Taylor expanded in y around 0 91.4%
mul-1-neg91.4%
sub-neg91.4%
Simplified91.4%
if -11000 < z < 3.00000000000000023e46Initial program 94.5%
sub-neg94.5%
associate-/l*95.3%
distribute-neg-frac95.3%
distribute-lft-neg-out95.3%
associate-/r/95.8%
distribute-lft-neg-out95.8%
distribute-rgt-neg-in95.8%
metadata-eval95.8%
*-commutative95.8%
associate-*l*95.8%
fma-neg95.8%
Simplified95.8%
Taylor expanded in y around inf 88.8%
Final simplification90.0%
(FPCore (x y z t) :precision binary64 (if (or (<= z -8100000.0) (not (<= z 1.1e+50))) (- x (/ y z)) (- x (* -2.0 (/ z t)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -8100000.0) || !(z <= 1.1e+50)) {
tmp = x - (y / z);
} else {
tmp = x - (-2.0 * (z / t));
}
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) :: tmp
if ((z <= (-8100000.0d0)) .or. (.not. (z <= 1.1d+50))) then
tmp = x - (y / z)
else
tmp = x - ((-2.0d0) * (z / t))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -8100000.0) || !(z <= 1.1e+50)) {
tmp = x - (y / z);
} else {
tmp = x - (-2.0 * (z / t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -8100000.0) or not (z <= 1.1e+50): tmp = x - (y / z) else: tmp = x - (-2.0 * (z / t)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -8100000.0) || !(z <= 1.1e+50)) tmp = Float64(x - Float64(y / z)); else tmp = Float64(x - Float64(-2.0 * Float64(z / t))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -8100000.0) || ~((z <= 1.1e+50))) tmp = x - (y / z); else tmp = x - (-2.0 * (z / t)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -8100000.0], N[Not[LessEqual[z, 1.1e+50]], $MachinePrecision]], N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision], N[(x - N[(-2.0 * N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8100000 \lor \neg \left(z \leq 1.1 \cdot 10^{+50}\right):\\
\;\;\;\;x - \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - -2 \cdot \frac{z}{t}\\
\end{array}
\end{array}
if z < -8.1e6 or 1.10000000000000008e50 < z Initial program 73.1%
sub-neg73.1%
associate-/l*84.4%
distribute-neg-frac84.4%
distribute-lft-neg-out84.4%
associate-/r/83.4%
distribute-lft-neg-out83.4%
distribute-rgt-neg-in83.4%
metadata-eval83.4%
*-commutative83.4%
associate-*l*83.4%
fma-neg83.4%
Simplified83.4%
Taylor expanded in y around 0 91.4%
mul-1-neg91.4%
sub-neg91.4%
Simplified91.4%
if -8.1e6 < z < 1.10000000000000008e50Initial program 94.5%
associate-/l*95.3%
associate-*l*95.3%
Simplified95.3%
Taylor expanded in y around inf 88.9%
*-commutative88.9%
Simplified88.9%
Final simplification90.0%
(FPCore (x y z t) :precision binary64 (if (or (<= z -400000000000.0) (not (<= z 0.0125))) (- x (/ y z)) x))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -400000000000.0) || !(z <= 0.0125)) {
tmp = x - (y / z);
} else {
tmp = x;
}
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) :: tmp
if ((z <= (-400000000000.0d0)) .or. (.not. (z <= 0.0125d0))) then
tmp = x - (y / z)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -400000000000.0) || !(z <= 0.0125)) {
tmp = x - (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -400000000000.0) or not (z <= 0.0125): tmp = x - (y / z) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -400000000000.0) || !(z <= 0.0125)) tmp = Float64(x - Float64(y / z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -400000000000.0) || ~((z <= 0.0125))) tmp = x - (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -400000000000.0], N[Not[LessEqual[z, 0.0125]], $MachinePrecision]], N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -400000000000 \lor \neg \left(z \leq 0.0125\right):\\
\;\;\;\;x - \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -4e11 or 0.012500000000000001 < z Initial program 74.9%
sub-neg74.9%
associate-/l*85.9%
distribute-neg-frac85.9%
distribute-lft-neg-out85.9%
associate-/r/84.9%
distribute-lft-neg-out84.9%
distribute-rgt-neg-in84.9%
metadata-eval84.9%
*-commutative84.9%
associate-*l*84.9%
fma-neg84.9%
Simplified84.9%
Taylor expanded in y around 0 86.2%
mul-1-neg86.2%
sub-neg86.2%
Simplified86.2%
if -4e11 < z < 0.012500000000000001Initial program 94.8%
sub-neg94.8%
associate-/l*94.9%
distribute-neg-frac94.9%
distribute-lft-neg-out94.9%
associate-/r/95.5%
distribute-lft-neg-out95.5%
distribute-rgt-neg-in95.5%
metadata-eval95.5%
*-commutative95.5%
associate-*l*95.5%
fma-neg95.5%
Simplified95.5%
Taylor expanded in x around inf 79.5%
Final simplification82.7%
(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 85.2%
sub-neg85.2%
associate-/l*90.6%
distribute-neg-frac90.6%
distribute-lft-neg-out90.6%
associate-/r/90.4%
distribute-lft-neg-out90.4%
distribute-rgt-neg-in90.4%
metadata-eval90.4%
*-commutative90.4%
associate-*l*90.4%
fma-neg90.4%
Simplified90.4%
Taylor expanded in x around inf 74.9%
Final simplification74.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 2024026
(FPCore (x y z t)
:name "Numeric.AD.Rank1.Halley:findZero from ad-4.2.4"
:precision binary64
:herbie-target
(- x (/ 1.0 (- (/ z y) (/ (/ t 2.0) z))))
(- x (/ (* (* y 2.0) z) (- (* (* z 2.0) z) (* y t)))))