
(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) (+ x (* z (/ (* y 2.0) (- (* y t) (* 2.0 (pow z 2.0)))))) (- 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 = x + (z * ((y * 2.0) / ((y * t) - (2.0 * pow(z, 2.0)))));
} else {
tmp = x - (y / z);
}
return tmp;
}
public static double code(double x, double y, double z, double t) {
double tmp;
if ((((y * 2.0) * z) / ((z * (2.0 * z)) - (y * t))) <= Double.POSITIVE_INFINITY) {
tmp = x + (z * ((y * 2.0) / ((y * t) - (2.0 * Math.pow(z, 2.0)))));
} else {
tmp = x - (y / z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (((y * 2.0) * z) / ((z * (2.0 * z)) - (y * t))) <= math.inf: tmp = x + (z * ((y * 2.0) / ((y * t) - (2.0 * math.pow(z, 2.0))))) 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 = Float64(x + Float64(z * Float64(Float64(y * 2.0) / Float64(Float64(y * t) - Float64(2.0 * (z ^ 2.0)))))); else tmp = Float64(x - Float64(y / z)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((((y * 2.0) * z) / ((z * (2.0 * z)) - (y * t))) <= Inf) tmp = x + (z * ((y * 2.0) / ((y * t) - (2.0 * (z ^ 2.0))))); else tmp = x - (y / z); end tmp_2 = 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[(x + N[(z * N[(N[(y * 2.0), $MachinePrecision] / N[(N[(y * t), $MachinePrecision] - N[(2.0 * N[Power[z, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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:\\
\;\;\;\;x + z \cdot \frac{y \cdot 2}{y \cdot t - 2 \cdot {z}^{2}}\\
\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 95.2%
*-commutative95.2%
associate-/l*98.1%
*-commutative98.1%
associate-*l*98.1%
pow298.1%
Applied egg-rr98.1%
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 72.0%
Final simplification95.3%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (+ x (/ (* (* y 2.0) z) (- (* y t) (* z (* 2.0 z))))))) (if (<= t_1 1e+289) t_1 (- x (/ y z)))))
double code(double x, double y, double z, double t) {
double t_1 = x + (((y * 2.0) * z) / ((y * t) - (z * (2.0 * z))));
double tmp;
if (t_1 <= 1e+289) {
tmp = t_1;
} else {
tmp = x - (y / 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) :: t_1
real(8) :: tmp
t_1 = x + (((y * 2.0d0) * z) / ((y * t) - (z * (2.0d0 * z))))
if (t_1 <= 1d+289) then
tmp = t_1
else
tmp = x - (y / z)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = x + (((y * 2.0) * z) / ((y * t) - (z * (2.0 * z))));
double tmp;
if (t_1 <= 1e+289) {
tmp = t_1;
} else {
tmp = x - (y / z);
}
return tmp;
}
def code(x, y, z, t): t_1 = x + (((y * 2.0) * z) / ((y * t) - (z * (2.0 * z)))) tmp = 0 if t_1 <= 1e+289: tmp = t_1 else: tmp = x - (y / z) return tmp
function code(x, y, z, t) t_1 = Float64(x + Float64(Float64(Float64(y * 2.0) * z) / Float64(Float64(y * t) - Float64(z * Float64(2.0 * z))))) tmp = 0.0 if (t_1 <= 1e+289) tmp = t_1; else tmp = Float64(x - Float64(y / z)); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = x + (((y * 2.0) * z) / ((y * t) - (z * (2.0 * z)))); tmp = 0.0; if (t_1 <= 1e+289) tmp = t_1; else tmp = x - (y / z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x + N[(N[(N[(y * 2.0), $MachinePrecision] * z), $MachinePrecision] / N[(N[(y * t), $MachinePrecision] - N[(z * N[(2.0 * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, 1e+289], t$95$1, N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x + \frac{\left(y \cdot 2\right) \cdot z}{y \cdot t - z \cdot \left(2 \cdot z\right)}\\
\mathbf{if}\;t\_1 \leq 10^{+289}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;x - \frac{y}{z}\\
\end{array}
\end{array}
if (-.f64 x (/.f64 (*.f64 (*.f64 y #s(literal 2 binary64)) z) (-.f64 (*.f64 (*.f64 z #s(literal 2 binary64)) z) (*.f64 y t)))) < 1.0000000000000001e289Initial program 97.2%
if 1.0000000000000001e289 < (-.f64 x (/.f64 (*.f64 (*.f64 y #s(literal 2 binary64)) z) (-.f64 (*.f64 (*.f64 z #s(literal 2 binary64)) z) (*.f64 y t)))) Initial program 9.1%
Taylor expanded in y around 0 75.3%
Final simplification94.2%
(FPCore (x y z t)
:precision binary64
(if (or (<= x -4e-94)
(and (not (<= x -5.4e-108))
(or (<= x -3e-280) (not (<= x 1.45e-229)))))
x
(* 2.0 (/ z t))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -4e-94) || (!(x <= -5.4e-108) && ((x <= -3e-280) || !(x <= 1.45e-229)))) {
tmp = x;
} else {
tmp = 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 ((x <= (-4d-94)) .or. (.not. (x <= (-5.4d-108))) .and. (x <= (-3d-280)) .or. (.not. (x <= 1.45d-229))) then
tmp = x
else
tmp = 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 ((x <= -4e-94) || (!(x <= -5.4e-108) && ((x <= -3e-280) || !(x <= 1.45e-229)))) {
tmp = x;
} else {
tmp = 2.0 * (z / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= -4e-94) or (not (x <= -5.4e-108) and ((x <= -3e-280) or not (x <= 1.45e-229))): tmp = x else: tmp = 2.0 * (z / t) return tmp
function code(x, y, z, t) tmp = 0.0 if ((x <= -4e-94) || (!(x <= -5.4e-108) && ((x <= -3e-280) || !(x <= 1.45e-229)))) tmp = x; else tmp = Float64(2.0 * Float64(z / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x <= -4e-94) || (~((x <= -5.4e-108)) && ((x <= -3e-280) || ~((x <= 1.45e-229))))) tmp = x; else tmp = 2.0 * (z / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -4e-94], And[N[Not[LessEqual[x, -5.4e-108]], $MachinePrecision], Or[LessEqual[x, -3e-280], N[Not[LessEqual[x, 1.45e-229]], $MachinePrecision]]]], x, N[(2.0 * N[(z / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{-94} \lor \neg \left(x \leq -5.4 \cdot 10^{-108}\right) \land \left(x \leq -3 \cdot 10^{-280} \lor \neg \left(x \leq 1.45 \cdot 10^{-229}\right)\right):\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \frac{z}{t}\\
\end{array}
\end{array}
if x < -3.9999999999999998e-94 or -5.4000000000000001e-108 < x < -2.99999999999999987e-280 or 1.45e-229 < x Initial program 86.0%
Taylor expanded in x around inf 80.9%
if -3.9999999999999998e-94 < x < -5.4000000000000001e-108 or -2.99999999999999987e-280 < x < 1.45e-229Initial program 79.5%
Taylor expanded in y around inf 76.3%
Taylor expanded in x around 0 70.0%
Final simplification79.5%
(FPCore (x y z t) :precision binary64 (if (or (<= z -2.25e-11) (not (<= z 7.5e-57))) (- x (/ y z)) (- x (* (/ z t) -2.0))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2.25e-11) || !(z <= 7.5e-57)) {
tmp = x - (y / z);
} else {
tmp = x - ((z / t) * -2.0);
}
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 <= (-2.25d-11)) .or. (.not. (z <= 7.5d-57))) then
tmp = x - (y / z)
else
tmp = x - ((z / t) * (-2.0d0))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2.25e-11) || !(z <= 7.5e-57)) {
tmp = x - (y / z);
} else {
tmp = x - ((z / t) * -2.0);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -2.25e-11) or not (z <= 7.5e-57): tmp = x - (y / z) else: tmp = x - ((z / t) * -2.0) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -2.25e-11) || !(z <= 7.5e-57)) tmp = Float64(x - Float64(y / z)); else tmp = Float64(x - Float64(Float64(z / t) * -2.0)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -2.25e-11) || ~((z <= 7.5e-57))) tmp = x - (y / z); else tmp = x - ((z / t) * -2.0); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -2.25e-11], N[Not[LessEqual[z, 7.5e-57]], $MachinePrecision]], N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision], N[(x - N[(N[(z / t), $MachinePrecision] * -2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.25 \cdot 10^{-11} \lor \neg \left(z \leq 7.5 \cdot 10^{-57}\right):\\
\;\;\;\;x - \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{z}{t} \cdot -2\\
\end{array}
\end{array}
if z < -2.25e-11 or 7.49999999999999973e-57 < z Initial program 75.8%
Taylor expanded in y around 0 87.0%
if -2.25e-11 < z < 7.49999999999999973e-57Initial program 94.5%
Taylor expanded in y around inf 91.6%
Final simplification89.3%
(FPCore (x y z t) :precision binary64 (if (or (<= z -8.2e+15) (not (<= z 1.6e-22))) (- x (/ y z)) x))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -8.2e+15) || !(z <= 1.6e-22)) {
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 <= (-8.2d+15)) .or. (.not. (z <= 1.6d-22))) 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 <= -8.2e+15) || !(z <= 1.6e-22)) {
tmp = x - (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -8.2e+15) or not (z <= 1.6e-22): tmp = x - (y / z) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -8.2e+15) || !(z <= 1.6e-22)) 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 <= -8.2e+15) || ~((z <= 1.6e-22))) tmp = x - (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -8.2e+15], N[Not[LessEqual[z, 1.6e-22]], $MachinePrecision]], N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.2 \cdot 10^{+15} \lor \neg \left(z \leq 1.6 \cdot 10^{-22}\right):\\
\;\;\;\;x - \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -8.2e15 or 1.59999999999999994e-22 < z Initial program 74.4%
Taylor expanded in y around 0 89.0%
if -8.2e15 < z < 1.59999999999999994e-22Initial program 94.2%
Taylor expanded in x around inf 75.0%
Final simplification81.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 85.1%
Taylor expanded in x around inf 73.1%
(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 2024095
(FPCore (x y z t)
:name "Numeric.AD.Rank1.Halley:findZero from ad-4.2.4"
:precision binary64
:alt
(- x (/ 1.0 (- (/ z y) (/ (/ t 2.0) z))))
(- x (/ (* (* y 2.0) z) (- (* (* z 2.0) z) (* y t)))))