
(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 (/ (* y 2.0) (- (* 2.0 z) (/ y (/ z t))))))
double code(double x, double y, double z, double t) {
return x - ((y * 2.0) / ((2.0 * z) - (y / (z / 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) / ((2.0d0 * z) - (y / (z / t))))
end function
public static double code(double x, double y, double z, double t) {
return x - ((y * 2.0) / ((2.0 * z) - (y / (z / t))));
}
def code(x, y, z, t): return x - ((y * 2.0) / ((2.0 * z) - (y / (z / t))))
function code(x, y, z, t) return Float64(x - Float64(Float64(y * 2.0) / Float64(Float64(2.0 * z) - Float64(y / Float64(z / t))))) end
function tmp = code(x, y, z, t) tmp = x - ((y * 2.0) / ((2.0 * z) - (y / (z / t)))); end
code[x_, y_, z_, t_] := N[(x - N[(N[(y * 2.0), $MachinePrecision] / N[(N[(2.0 * z), $MachinePrecision] - N[(y / N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \frac{y \cdot 2}{2 \cdot z - \frac{y}{\frac{z}{t}}}
\end{array}
Initial program 82.4%
sub-neg82.4%
neg-mul-182.4%
*-commutative82.4%
cancel-sign-sub82.4%
*-commutative82.4%
mul-1-neg82.4%
remove-double-neg82.4%
associate-/l*90.4%
*-commutative90.4%
*-commutative90.4%
*-commutative90.4%
*-commutative90.4%
Simplified90.4%
Taylor expanded in z around 0 95.2%
associate-*l/99.2%
*-commutative99.2%
mul-1-neg99.2%
*-commutative99.2%
+-commutative99.2%
sub-neg99.2%
Simplified99.2%
clear-num99.2%
div-inv99.2%
Applied egg-rr99.2%
Final simplification99.2%
(FPCore (x y z t) :precision binary64 (- x (/ (* y 2.0) (- (* 2.0 z) (* y (/ t z))))))
double code(double x, double y, double z, double t) {
return x - ((y * 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 - ((y * 2.0d0) / ((2.0d0 * z) - (y * (t / z))))
end function
public static double code(double x, double y, double z, double t) {
return x - ((y * 2.0) / ((2.0 * z) - (y * (t / z))));
}
def code(x, y, z, t): return x - ((y * 2.0) / ((2.0 * z) - (y * (t / z))))
function code(x, y, z, t) return Float64(x - Float64(Float64(y * 2.0) / Float64(Float64(2.0 * z) - Float64(y * Float64(t / z))))) end
function tmp = code(x, y, z, t) tmp = x - ((y * 2.0) / ((2.0 * z) - (y * (t / z)))); end
code[x_, y_, z_, t_] := N[(x - N[(N[(y * 2.0), $MachinePrecision] / N[(N[(2.0 * z), $MachinePrecision] - N[(y * N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \frac{y \cdot 2}{2 \cdot z - y \cdot \frac{t}{z}}
\end{array}
Initial program 82.4%
sub-neg82.4%
neg-mul-182.4%
*-commutative82.4%
cancel-sign-sub82.4%
*-commutative82.4%
mul-1-neg82.4%
remove-double-neg82.4%
associate-/l*90.4%
*-commutative90.4%
*-commutative90.4%
*-commutative90.4%
*-commutative90.4%
Simplified90.4%
Taylor expanded in z around 0 95.2%
associate-*l/99.2%
*-commutative99.2%
mul-1-neg99.2%
*-commutative99.2%
+-commutative99.2%
sub-neg99.2%
Simplified99.2%
Final simplification99.2%
(FPCore (x y z t) :precision binary64 (if (or (<= z -3e+33) (not (<= z 0.000105))) (- x (/ y z)) (- x (* z (/ -2.0 t)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -3e+33) || !(z <= 0.000105)) {
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 <= (-3d+33)) .or. (.not. (z <= 0.000105d0))) 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 <= -3e+33) || !(z <= 0.000105)) {
tmp = x - (y / z);
} else {
tmp = x - (z * (-2.0 / t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -3e+33) or not (z <= 0.000105): tmp = x - (y / z) else: tmp = x - (z * (-2.0 / t)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -3e+33) || !(z <= 0.000105)) 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 <= -3e+33) || ~((z <= 0.000105))) 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, -3e+33], N[Not[LessEqual[z, 0.000105]], $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 -3 \cdot 10^{+33} \lor \neg \left(z \leq 0.000105\right):\\
\;\;\;\;x - \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - z \cdot \frac{-2}{t}\\
\end{array}
\end{array}
if z < -2.99999999999999984e33 or 1.05e-4 < z Initial program 71.2%
sub-neg71.2%
neg-mul-171.2%
*-commutative71.2%
cancel-sign-sub71.2%
*-commutative71.2%
mul-1-neg71.2%
remove-double-neg71.2%
associate-/l*87.4%
*-commutative87.4%
*-commutative87.4%
*-commutative87.4%
*-commutative87.4%
Simplified87.4%
Taylor expanded in y around 0 92.4%
if -2.99999999999999984e33 < z < 1.05e-4Initial program 91.0%
sub-neg91.0%
neg-mul-191.0%
*-commutative91.0%
cancel-sign-sub91.0%
*-commutative91.0%
mul-1-neg91.0%
remove-double-neg91.0%
associate-/l*92.8%
*-commutative92.8%
*-commutative92.8%
*-commutative92.8%
*-commutative92.8%
Simplified92.8%
Taylor expanded in z around 0 84.7%
*-commutative84.7%
mul-1-neg84.7%
*-commutative84.7%
distribute-rgt-neg-out84.7%
Simplified84.7%
div-inv84.1%
*-commutative84.1%
clear-num84.1%
associate-/r*89.1%
add-sqr-sqrt42.8%
sqrt-unprod59.7%
sqr-neg59.7%
sqrt-unprod32.2%
add-sqr-sqrt64.3%
associate-/l/63.5%
add-sqr-sqrt32.1%
sqrt-unprod48.4%
sqr-neg48.4%
sqrt-unprod40.5%
add-sqr-sqrt84.1%
distribute-lft-neg-in84.1%
distribute-rgt-neg-in84.1%
metadata-eval84.1%
Applied egg-rr84.1%
associate-*l/84.2%
Applied egg-rr84.2%
Taylor expanded in z around 0 91.2%
*-commutative91.2%
metadata-eval91.2%
times-frac91.2%
associate-*r/91.1%
*-commutative91.1%
associate-/r*91.1%
metadata-eval91.1%
Simplified91.1%
Final simplification91.6%
(FPCore (x y z t) :precision binary64 (if (or (<= z -1.02e+32) (not (<= z 2.25e-6))) (- x (/ y z)) (- x (/ (* z -2.0) t))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -1.02e+32) || !(z <= 2.25e-6)) {
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 <= (-1.02d+32)) .or. (.not. (z <= 2.25d-6))) 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 <= -1.02e+32) || !(z <= 2.25e-6)) {
tmp = x - (y / z);
} else {
tmp = x - ((z * -2.0) / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -1.02e+32) or not (z <= 2.25e-6): tmp = x - (y / z) else: tmp = x - ((z * -2.0) / t) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -1.02e+32) || !(z <= 2.25e-6)) tmp = Float64(x - Float64(y / z)); else tmp = Float64(x - Float64(Float64(z * -2.0) / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -1.02e+32) || ~((z <= 2.25e-6))) 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, -1.02e+32], N[Not[LessEqual[z, 2.25e-6]], $MachinePrecision]], N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision], N[(x - N[(N[(z * -2.0), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.02 \cdot 10^{+32} \lor \neg \left(z \leq 2.25 \cdot 10^{-6}\right):\\
\;\;\;\;x - \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{z \cdot -2}{t}\\
\end{array}
\end{array}
if z < -1.0199999999999999e32 or 2.25000000000000006e-6 < z Initial program 71.2%
sub-neg71.2%
neg-mul-171.2%
*-commutative71.2%
cancel-sign-sub71.2%
*-commutative71.2%
mul-1-neg71.2%
remove-double-neg71.2%
associate-/l*87.4%
*-commutative87.4%
*-commutative87.4%
*-commutative87.4%
*-commutative87.4%
Simplified87.4%
Taylor expanded in y around 0 92.4%
if -1.0199999999999999e32 < z < 2.25000000000000006e-6Initial program 91.0%
sub-neg91.0%
neg-mul-191.0%
*-commutative91.0%
cancel-sign-sub91.0%
*-commutative91.0%
mul-1-neg91.0%
remove-double-neg91.0%
associate-/l*92.8%
*-commutative92.8%
*-commutative92.8%
*-commutative92.8%
*-commutative92.8%
Simplified92.8%
Taylor expanded in y around inf 91.2%
associate-*r/91.2%
*-commutative91.2%
Simplified91.2%
Final simplification91.7%
(FPCore (x y z t) :precision binary64 (- x (/ y z)))
double code(double x, double y, double z, double t) {
return x - (y / 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 - (y / z)
end function
public static double code(double x, double y, double z, double t) {
return x - (y / z);
}
def code(x, y, z, t): return x - (y / z)
function code(x, y, z, t) return Float64(x - Float64(y / z)) end
function tmp = code(x, y, z, t) tmp = x - (y / z); end
code[x_, y_, z_, t_] := N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \frac{y}{z}
\end{array}
Initial program 82.4%
sub-neg82.4%
neg-mul-182.4%
*-commutative82.4%
cancel-sign-sub82.4%
*-commutative82.4%
mul-1-neg82.4%
remove-double-neg82.4%
associate-/l*90.4%
*-commutative90.4%
*-commutative90.4%
*-commutative90.4%
*-commutative90.4%
Simplified90.4%
Taylor expanded in y around 0 55.6%
Final simplification55.6%
(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 2023326
(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)))))