
(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 (/ -1.0 (+ (* -0.5 (/ t z)) (/ z y)))))
double code(double x, double y, double z, double t) {
return x + (-1.0 / ((-0.5 * (t / z)) + (z / y)));
}
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) / (((-0.5d0) * (t / z)) + (z / y)))
end function
public static double code(double x, double y, double z, double t) {
return x + (-1.0 / ((-0.5 * (t / z)) + (z / y)));
}
def code(x, y, z, t): return x + (-1.0 / ((-0.5 * (t / z)) + (z / y)))
function code(x, y, z, t) return Float64(x + Float64(-1.0 / Float64(Float64(-0.5 * Float64(t / z)) + Float64(z / y)))) end
function tmp = code(x, y, z, t) tmp = x + (-1.0 / ((-0.5 * (t / z)) + (z / y))); end
code[x_, y_, z_, t_] := N[(x + N[(-1.0 / N[(N[(-0.5 * N[(t / z), $MachinePrecision]), $MachinePrecision] + N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{-1}{-0.5 \cdot \frac{t}{z} + \frac{z}{y}}
\end{array}
Initial program 82.5%
associate-/l*88.2%
associate-*l*88.2%
Simplified88.2%
Taylor expanded in z around 0 94.1%
+-commutative94.1%
mul-1-neg94.1%
*-commutative94.1%
associate-*r/98.1%
sub-neg98.1%
*-commutative98.1%
Simplified98.1%
clear-num97.9%
inv-pow97.9%
Applied egg-rr97.9%
unpow-197.9%
*-commutative97.9%
associate-/r/95.1%
Simplified95.1%
Taylor expanded in z around 0 99.7%
Final simplification99.7%
(FPCore (x y z t) :precision binary64 (if (or (<= z -4e-18) (not (<= z 2.4e-46))) (- x (/ y z)) (- x (/ (* z -2.0) t))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -4e-18) || !(z <= 2.4e-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 <= (-4d-18)) .or. (.not. (z <= 2.4d-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 <= -4e-18) || !(z <= 2.4e-46)) {
tmp = x - (y / z);
} else {
tmp = x - ((z * -2.0) / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -4e-18) or not (z <= 2.4e-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 <= -4e-18) || !(z <= 2.4e-46)) 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 <= -4e-18) || ~((z <= 2.4e-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, -4e-18], N[Not[LessEqual[z, 2.4e-46]], $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 -4 \cdot 10^{-18} \lor \neg \left(z \leq 2.4 \cdot 10^{-46}\right):\\
\;\;\;\;x - \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{z \cdot -2}{t}\\
\end{array}
\end{array}
if z < -4.0000000000000003e-18 or 2.40000000000000013e-46 < z Initial program 75.1%
associate-/l*86.2%
associate-*l*86.2%
Simplified86.2%
Taylor expanded in y around 0 89.3%
if -4.0000000000000003e-18 < z < 2.40000000000000013e-46Initial program 92.6%
associate-/l*91.0%
associate-*l*91.0%
Simplified91.0%
Taylor expanded in y around inf 94.8%
associate-*r/94.8%
*-commutative94.8%
Simplified94.8%
Final simplification91.6%
(FPCore (x y z t) :precision binary64 (if (or (<= z -3.3e-18) (not (<= z 7.2e-47))) (- x (/ y z)) x))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -3.3e-18) || !(z <= 7.2e-47)) {
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 <= (-3.3d-18)) .or. (.not. (z <= 7.2d-47))) 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 <= -3.3e-18) || !(z <= 7.2e-47)) {
tmp = x - (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -3.3e-18) or not (z <= 7.2e-47): tmp = x - (y / z) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -3.3e-18) || !(z <= 7.2e-47)) 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 <= -3.3e-18) || ~((z <= 7.2e-47))) tmp = x - (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -3.3e-18], N[Not[LessEqual[z, 7.2e-47]], $MachinePrecision]], N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.3 \cdot 10^{-18} \lor \neg \left(z \leq 7.2 \cdot 10^{-47}\right):\\
\;\;\;\;x - \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -3.3000000000000002e-18 or 7.19999999999999982e-47 < z Initial program 75.1%
associate-/l*86.2%
associate-*l*86.2%
Simplified86.2%
Taylor expanded in y around 0 89.3%
if -3.3000000000000002e-18 < z < 7.19999999999999982e-47Initial program 92.6%
associate-/l*91.0%
associate-*l*91.0%
Simplified91.0%
Taylor expanded in x around inf 70.2%
Final simplification81.3%
(FPCore (x y z t) :precision binary64 (if (<= x -1.8e-160) x (if (<= x 1.52e-229) (* z (/ 2.0 t)) x)))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -1.8e-160) {
tmp = x;
} else if (x <= 1.52e-229) {
tmp = z * (2.0 / t);
} 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.8d-160)) then
tmp = x
else if (x <= 1.52d-229) then
tmp = z * (2.0d0 / t)
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.8e-160) {
tmp = x;
} else if (x <= 1.52e-229) {
tmp = z * (2.0 / t);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -1.8e-160: tmp = x elif x <= 1.52e-229: tmp = z * (2.0 / t) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -1.8e-160) tmp = x; elseif (x <= 1.52e-229) tmp = Float64(z * Float64(2.0 / t)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= -1.8e-160) tmp = x; elseif (x <= 1.52e-229) tmp = z * (2.0 / t); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -1.8e-160], x, If[LessEqual[x, 1.52e-229], N[(z * N[(2.0 / t), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.8 \cdot 10^{-160}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1.52 \cdot 10^{-229}:\\
\;\;\;\;z \cdot \frac{2}{t}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -1.7999999999999999e-160 or 1.5199999999999999e-229 < x Initial program 85.8%
associate-/l*93.3%
associate-*l*93.3%
Simplified93.3%
Taylor expanded in x around inf 82.5%
if -1.7999999999999999e-160 < x < 1.5199999999999999e-229Initial program 69.6%
associate-/l*68.4%
associate-*l*68.4%
Simplified68.4%
Taylor expanded in y around inf 58.1%
associate-*r/58.1%
*-commutative58.1%
Simplified58.1%
Taylor expanded in x around 0 45.5%
associate-*r/45.5%
*-commutative45.5%
Simplified45.5%
Taylor expanded in z around 0 45.5%
associate-*r/45.5%
*-commutative45.5%
associate-*r/45.3%
Simplified45.3%
Final simplification74.8%
(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 82.5%
associate-/l*88.2%
associate-*l*88.2%
Simplified88.2%
Taylor expanded in x around inf 71.4%
Final simplification71.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 2023318
(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)))))