
(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 (- 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(Float64(2.0 * 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[(N[(2.0 * z), $MachinePrecision] / y), $MachinePrecision] - N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \frac{2}{\frac{2 \cdot z}{y} - \frac{t}{z}}
\end{array}
Initial program 83.2%
associate-/l*87.5%
associate-*l*87.5%
Simplified87.5%
Taylor expanded in z around 0 94.4%
+-commutative94.4%
*-commutative94.4%
mul-1-neg94.4%
associate-*r/96.2%
sub-neg96.2%
*-commutative96.2%
associate-*l/94.4%
associate-*r/98.1%
Simplified98.1%
Taylor expanded in y around 0 94.4%
associate-/l*96.4%
Simplified96.4%
expm1-log1p-u88.8%
expm1-udef75.3%
*-commutative75.3%
*-un-lft-identity75.3%
times-frac75.3%
metadata-eval75.3%
*-commutative75.3%
div-inv75.4%
clear-num75.4%
Applied egg-rr75.4%
expm1-def88.8%
expm1-log1p96.2%
associate-*r/96.2%
associate-/l*96.1%
div-sub96.1%
associate-*r/94.3%
associate-*l/98.0%
associate-/l*99.9%
*-inverses99.9%
/-rgt-identity99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z t) :precision binary64 (if (or (<= z -46000000.0) (not (<= z 2.2e+24))) (- x (/ y z)) (+ x (/ 2.0 (/ t z)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -46000000.0) || !(z <= 2.2e+24)) {
tmp = x - (y / z);
} else {
tmp = x + (2.0 / (t / z));
}
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 <= (-46000000.0d0)) .or. (.not. (z <= 2.2d+24))) then
tmp = x - (y / z)
else
tmp = x + (2.0d0 / (t / z))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -46000000.0) || !(z <= 2.2e+24)) {
tmp = x - (y / z);
} else {
tmp = x + (2.0 / (t / z));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -46000000.0) or not (z <= 2.2e+24): tmp = x - (y / z) else: tmp = x + (2.0 / (t / z)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -46000000.0) || !(z <= 2.2e+24)) tmp = Float64(x - Float64(y / z)); else tmp = Float64(x + Float64(2.0 / Float64(t / z))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -46000000.0) || ~((z <= 2.2e+24))) tmp = x - (y / z); else tmp = x + (2.0 / (t / z)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -46000000.0], N[Not[LessEqual[z, 2.2e+24]], $MachinePrecision]], N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision], N[(x + N[(2.0 / N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -46000000 \lor \neg \left(z \leq 2.2 \cdot 10^{+24}\right):\\
\;\;\;\;x - \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{2}{\frac{t}{z}}\\
\end{array}
\end{array}
if z < -4.6e7 or 2.20000000000000002e24 < z Initial program 70.8%
associate-/l*79.7%
associate-*l*79.7%
Simplified79.7%
Taylor expanded in y around 0 91.0%
if -4.6e7 < z < 2.20000000000000002e24Initial program 95.6%
associate-/l*95.3%
associate-*l*95.3%
Simplified95.3%
Taylor expanded in y around inf 87.7%
associate-*r/87.7%
Simplified87.7%
sub-neg87.7%
associate-/l*87.6%
distribute-neg-frac87.6%
metadata-eval87.6%
Applied egg-rr87.6%
Final simplification89.3%
(FPCore (x y z t) :precision binary64 (if (or (<= z -2100000000.0) (not (<= z 3.8e+24))) (- x (/ y z)) (- x (/ (* z -2.0) t))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2100000000.0) || !(z <= 3.8e+24)) {
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 <= (-2100000000.0d0)) .or. (.not. (z <= 3.8d+24))) 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 <= -2100000000.0) || !(z <= 3.8e+24)) {
tmp = x - (y / z);
} else {
tmp = x - ((z * -2.0) / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -2100000000.0) or not (z <= 3.8e+24): tmp = x - (y / z) else: tmp = x - ((z * -2.0) / t) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -2100000000.0) || !(z <= 3.8e+24)) 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 <= -2100000000.0) || ~((z <= 3.8e+24))) 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, -2100000000.0], N[Not[LessEqual[z, 3.8e+24]], $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 -2100000000 \lor \neg \left(z \leq 3.8 \cdot 10^{+24}\right):\\
\;\;\;\;x - \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{z \cdot -2}{t}\\
\end{array}
\end{array}
if z < -2.1e9 or 3.80000000000000015e24 < z Initial program 70.8%
associate-/l*79.7%
associate-*l*79.7%
Simplified79.7%
Taylor expanded in y around 0 91.0%
if -2.1e9 < z < 3.80000000000000015e24Initial program 95.6%
associate-/l*95.3%
associate-*l*95.3%
Simplified95.3%
Taylor expanded in y around inf 87.7%
associate-*r/87.7%
Simplified87.7%
Final simplification89.4%
(FPCore (x y z t) :precision binary64 (if (or (<= z -4e+35) (not (<= z 7.4e-26))) (- x (/ y z)) x))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -4e+35) || !(z <= 7.4e-26)) {
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 <= (-4d+35)) .or. (.not. (z <= 7.4d-26))) 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 <= -4e+35) || !(z <= 7.4e-26)) {
tmp = x - (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -4e+35) or not (z <= 7.4e-26): tmp = x - (y / z) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -4e+35) || !(z <= 7.4e-26)) 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 <= -4e+35) || ~((z <= 7.4e-26))) tmp = x - (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -4e+35], N[Not[LessEqual[z, 7.4e-26]], $MachinePrecision]], N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4 \cdot 10^{+35} \lor \neg \left(z \leq 7.4 \cdot 10^{-26}\right):\\
\;\;\;\;x - \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -3.9999999999999999e35 or 7.3999999999999997e-26 < z Initial program 71.0%
associate-/l*79.9%
associate-*l*79.9%
Simplified79.9%
Taylor expanded in y around 0 90.4%
if -3.9999999999999999e35 < z < 7.3999999999999997e-26Initial program 95.6%
associate-/l*95.3%
associate-*l*95.3%
Simplified95.3%
Taylor expanded in y around 0 45.0%
Taylor expanded in x around inf 76.5%
Final simplification83.5%
(FPCore (x y z t) :precision binary64 (if (<= x -1.95e-239) x (if (<= x 9.2e-209) (/ (- y) z) x)))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -1.95e-239) {
tmp = x;
} else if (x <= 9.2e-209) {
tmp = -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 (x <= (-1.95d-239)) then
tmp = x
else if (x <= 9.2d-209) then
tmp = -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 (x <= -1.95e-239) {
tmp = x;
} else if (x <= 9.2e-209) {
tmp = -y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -1.95e-239: tmp = x elif x <= 9.2e-209: tmp = -y / z else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -1.95e-239) tmp = x; elseif (x <= 9.2e-209) tmp = Float64(Float64(-y) / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= -1.95e-239) tmp = x; elseif (x <= 9.2e-209) tmp = -y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -1.95e-239], x, If[LessEqual[x, 9.2e-209], N[((-y) / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.95 \cdot 10^{-239}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 9.2 \cdot 10^{-209}:\\
\;\;\;\;\frac{-y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -1.95e-239 or 9.1999999999999999e-209 < x Initial program 85.5%
associate-/l*91.4%
associate-*l*91.4%
Simplified91.4%
Taylor expanded in y around 0 68.3%
Taylor expanded in x around inf 81.3%
if -1.95e-239 < x < 9.1999999999999999e-209Initial program 71.4%
associate-/l*67.7%
associate-*l*67.7%
Simplified67.7%
Taylor expanded in y around 0 65.5%
Taylor expanded in x around 0 51.6%
mul-1-neg51.6%
distribute-neg-frac51.6%
Simplified51.6%
Final simplification76.4%
(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 83.2%
associate-/l*87.5%
associate-*l*87.5%
Simplified87.5%
Taylor expanded in y around 0 67.8%
Taylor expanded in x around inf 72.4%
Final simplification72.4%
(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 2024017
(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)))))