
(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 (- (/ z (/ y 2.0)) (/ t z)))))
double code(double x, double y, double z, double t) {
return x - (2.0 / ((z / (y / 2.0)) - (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 / ((z / (y / 2.0d0)) - (t / z)))
end function
public static double code(double x, double y, double z, double t) {
return x - (2.0 / ((z / (y / 2.0)) - (t / z)));
}
def code(x, y, z, t): return x - (2.0 / ((z / (y / 2.0)) - (t / z)))
function code(x, y, z, t) return Float64(x - Float64(2.0 / Float64(Float64(z / Float64(y / 2.0)) - Float64(t / z)))) end
function tmp = code(x, y, z, t) tmp = x - (2.0 / ((z / (y / 2.0)) - (t / z))); end
code[x_, y_, z_, t_] := N[(x - N[(2.0 / N[(N[(z / N[(y / 2.0), $MachinePrecision]), $MachinePrecision] - N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \frac{2}{\frac{z}{\frac{y}{2}} - \frac{t}{z}}
\end{array}
Initial program 81.0%
remove-double-neg81.0%
neg-mul-181.0%
*-commutative81.0%
*-commutative81.0%
neg-mul-181.0%
remove-double-neg81.0%
associate-/l*89.4%
associate-*l*89.4%
Simplified89.4%
Taylor expanded in z around 0 97.7%
+-commutative97.7%
mul-1-neg97.7%
associate-*r/96.2%
*-commutative96.2%
associate-/r/98.9%
unsub-neg98.9%
*-commutative98.9%
associate-/r/96.2%
*-commutative96.2%
Simplified96.2%
clear-num96.2%
inv-pow96.2%
*-un-lft-identity96.2%
*-commutative96.2%
times-frac96.2%
metadata-eval96.2%
*-commutative96.2%
Applied egg-rr96.2%
unpow-196.2%
*-commutative96.2%
associate-*l/97.7%
associate-*r/98.8%
*-commutative98.8%
Simplified98.8%
expm1-log1p-u89.0%
expm1-udef77.4%
associate-/r*77.4%
metadata-eval77.4%
div-inv77.4%
clear-num77.4%
*-commutative77.4%
Applied egg-rr77.4%
expm1-def89.1%
expm1-log1p98.9%
associate-*r/98.9%
associate-/l*98.8%
div-sub98.8%
associate-*l/99.9%
*-inverses99.9%
*-lft-identity99.9%
*-commutative99.9%
associate-/l*99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z t)
:precision binary64
(if (or (<= z -1.6e+64)
(not
(or (<= z -28000000.0) (and (not (<= z -9e-78)) (<= z 1.35e+37)))))
(- x (/ y z))
(+ x (* z (/ 2.0 t)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -1.6e+64) || !((z <= -28000000.0) || (!(z <= -9e-78) && (z <= 1.35e+37)))) {
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.6d+64)) .or. (.not. (z <= (-28000000.0d0)) .or. (.not. (z <= (-9d-78))) .and. (z <= 1.35d+37))) 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.6e+64) || !((z <= -28000000.0) || (!(z <= -9e-78) && (z <= 1.35e+37)))) {
tmp = x - (y / z);
} else {
tmp = x + (z * (2.0 / t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -1.6e+64) or not ((z <= -28000000.0) or (not (z <= -9e-78) and (z <= 1.35e+37))): 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.6e+64) || !((z <= -28000000.0) || (!(z <= -9e-78) && (z <= 1.35e+37)))) 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 <= -1.6e+64) || ~(((z <= -28000000.0) || (~((z <= -9e-78)) && (z <= 1.35e+37))))) 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.6e+64], N[Not[Or[LessEqual[z, -28000000.0], And[N[Not[LessEqual[z, -9e-78]], $MachinePrecision], LessEqual[z, 1.35e+37]]]], $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 -1.6 \cdot 10^{+64} \lor \neg \left(z \leq -28000000 \lor \neg \left(z \leq -9 \cdot 10^{-78}\right) \land z \leq 1.35 \cdot 10^{+37}\right):\\
\;\;\;\;x - \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x + z \cdot \frac{2}{t}\\
\end{array}
\end{array}
if z < -1.60000000000000009e64 or -2.8e7 < z < -9e-78 or 1.34999999999999993e37 < z Initial program 68.6%
sub-neg68.6%
associate-/l*85.0%
distribute-neg-frac85.0%
distribute-lft-neg-out85.0%
associate-/r/85.0%
distribute-lft-neg-out85.0%
distribute-rgt-neg-in85.0%
metadata-eval85.0%
*-commutative85.0%
associate-*l*85.0%
fma-neg85.0%
Simplified85.0%
Taylor expanded in y around 0 94.4%
mul-1-neg94.4%
sub-neg94.4%
Simplified94.4%
if -1.60000000000000009e64 < z < -2.8e7 or -9e-78 < z < 1.34999999999999993e37Initial program 93.1%
sub-neg93.1%
associate-/l*93.7%
distribute-neg-frac93.7%
distribute-lft-neg-out93.7%
associate-/r/95.2%
distribute-lft-neg-out95.2%
distribute-rgt-neg-in95.2%
metadata-eval95.2%
*-commutative95.2%
associate-*l*95.2%
fma-neg95.2%
Simplified95.2%
Taylor expanded in y around inf 89.4%
Final simplification91.9%
(FPCore (x y z t)
:precision binary64
(if (or (<= z -3.4e+64)
(not
(or (<= z -50000000.0) (and (not (<= z -9e-78)) (<= z 1.8e+42)))))
(- x (/ y z))
(- x (* (/ z t) -2.0))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -3.4e+64) || !((z <= -50000000.0) || (!(z <= -9e-78) && (z <= 1.8e+42)))) {
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 <= (-3.4d+64)) .or. (.not. (z <= (-50000000.0d0)) .or. (.not. (z <= (-9d-78))) .and. (z <= 1.8d+42))) 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 <= -3.4e+64) || !((z <= -50000000.0) || (!(z <= -9e-78) && (z <= 1.8e+42)))) {
tmp = x - (y / z);
} else {
tmp = x - ((z / t) * -2.0);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -3.4e+64) or not ((z <= -50000000.0) or (not (z <= -9e-78) and (z <= 1.8e+42))): tmp = x - (y / z) else: tmp = x - ((z / t) * -2.0) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -3.4e+64) || !((z <= -50000000.0) || (!(z <= -9e-78) && (z <= 1.8e+42)))) 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 <= -3.4e+64) || ~(((z <= -50000000.0) || (~((z <= -9e-78)) && (z <= 1.8e+42))))) 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, -3.4e+64], N[Not[Or[LessEqual[z, -50000000.0], And[N[Not[LessEqual[z, -9e-78]], $MachinePrecision], LessEqual[z, 1.8e+42]]]], $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 -3.4 \cdot 10^{+64} \lor \neg \left(z \leq -50000000 \lor \neg \left(z \leq -9 \cdot 10^{-78}\right) \land z \leq 1.8 \cdot 10^{+42}\right):\\
\;\;\;\;x - \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{z}{t} \cdot -2\\
\end{array}
\end{array}
if z < -3.4000000000000002e64 or -5e7 < z < -9e-78 or 1.8e42 < z Initial program 68.6%
sub-neg68.6%
associate-/l*85.0%
distribute-neg-frac85.0%
distribute-lft-neg-out85.0%
associate-/r/85.0%
distribute-lft-neg-out85.0%
distribute-rgt-neg-in85.0%
metadata-eval85.0%
*-commutative85.0%
associate-*l*85.0%
fma-neg85.0%
Simplified85.0%
Taylor expanded in y around 0 94.4%
mul-1-neg94.4%
sub-neg94.4%
Simplified94.4%
if -3.4000000000000002e64 < z < -5e7 or -9e-78 < z < 1.8e42Initial program 93.1%
remove-double-neg93.1%
neg-mul-193.1%
*-commutative93.1%
*-commutative93.1%
neg-mul-193.1%
remove-double-neg93.1%
associate-/l*93.7%
associate-*l*93.7%
Simplified93.7%
Taylor expanded in y around inf 89.5%
*-commutative89.5%
Simplified89.5%
Final simplification91.9%
(FPCore (x y z t) :precision binary64 (if (or (<= z -9e-78) (not (<= z 5.4e+45))) (- x (/ y z)) x))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -9e-78) || !(z <= 5.4e+45)) {
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 <= (-9d-78)) .or. (.not. (z <= 5.4d+45))) 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 <= -9e-78) || !(z <= 5.4e+45)) {
tmp = x - (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -9e-78) or not (z <= 5.4e+45): tmp = x - (y / z) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -9e-78) || !(z <= 5.4e+45)) 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 <= -9e-78) || ~((z <= 5.4e+45))) tmp = x - (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -9e-78], N[Not[LessEqual[z, 5.4e+45]], $MachinePrecision]], N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9 \cdot 10^{-78} \lor \neg \left(z \leq 5.4 \cdot 10^{+45}\right):\\
\;\;\;\;x - \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -9e-78 or 5.39999999999999968e45 < z Initial program 70.5%
sub-neg70.5%
associate-/l*85.9%
distribute-neg-frac85.9%
distribute-lft-neg-out85.9%
associate-/r/85.9%
distribute-lft-neg-out85.9%
distribute-rgt-neg-in85.9%
metadata-eval85.9%
*-commutative85.9%
associate-*l*85.9%
fma-neg85.9%
Simplified85.9%
Taylor expanded in y around 0 90.3%
mul-1-neg90.3%
sub-neg90.3%
Simplified90.3%
if -9e-78 < z < 5.39999999999999968e45Initial program 93.9%
sub-neg93.9%
associate-/l*93.7%
distribute-neg-frac93.7%
distribute-lft-neg-out93.7%
associate-/r/95.4%
distribute-lft-neg-out95.4%
distribute-rgt-neg-in95.4%
metadata-eval95.4%
*-commutative95.4%
associate-*l*95.4%
fma-neg95.4%
Simplified95.4%
Taylor expanded in x around inf 77.2%
Final simplification84.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 81.0%
sub-neg81.0%
associate-/l*89.4%
distribute-neg-frac89.4%
distribute-lft-neg-out89.4%
associate-/r/90.2%
distribute-lft-neg-out90.2%
distribute-rgt-neg-in90.2%
metadata-eval90.2%
*-commutative90.2%
associate-*l*90.2%
fma-neg90.2%
Simplified90.2%
Taylor expanded in x around inf 75.1%
Final simplification75.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 2023334
(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)))))