
(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 y) (- (* y (/ t z)) (* 2.0 z)))))
double code(double x, double y, double z, double t) {
return x + ((2.0 * y) / ((y * (t / z)) - (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 + ((2.0d0 * y) / ((y * (t / z)) - (2.0d0 * z)))
end function
public static double code(double x, double y, double z, double t) {
return x + ((2.0 * y) / ((y * (t / z)) - (2.0 * z)));
}
def code(x, y, z, t): return x + ((2.0 * y) / ((y * (t / z)) - (2.0 * z)))
function code(x, y, z, t) return Float64(x + Float64(Float64(2.0 * y) / Float64(Float64(y * Float64(t / z)) - Float64(2.0 * z)))) end
function tmp = code(x, y, z, t) tmp = x + ((2.0 * y) / ((y * (t / z)) - (2.0 * z))); end
code[x_, y_, z_, t_] := N[(x + N[(N[(2.0 * y), $MachinePrecision] / N[(N[(y * N[(t / z), $MachinePrecision]), $MachinePrecision] - N[(2.0 * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{2 \cdot y}{y \cdot \frac{t}{z} - 2 \cdot z}
\end{array}
Initial program 82.3%
Simplified90.0%
clear-num89.8%
un-div-inv89.8%
*-commutative89.8%
*-commutative89.8%
associate-*l*89.8%
pow289.8%
Applied egg-rr89.8%
Taylor expanded in z around 0 95.6%
+-commutative95.6%
*-commutative95.6%
neg-mul-195.6%
unsub-neg95.6%
*-commutative95.6%
associate-/l*98.4%
Simplified98.4%
Final simplification98.4%
(FPCore (x y z t) :precision binary64 (if (or (<= z -5.2e-24) (not (<= z 1.2e-7))) (- x (/ y z)) (- x (/ -2.0 (/ t z)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -5.2e-24) || !(z <= 1.2e-7)) {
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 <= (-5.2d-24)) .or. (.not. (z <= 1.2d-7))) 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 <= -5.2e-24) || !(z <= 1.2e-7)) {
tmp = x - (y / z);
} else {
tmp = x - (-2.0 / (t / z));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -5.2e-24) or not (z <= 1.2e-7): tmp = x - (y / z) else: tmp = x - (-2.0 / (t / z)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -5.2e-24) || !(z <= 1.2e-7)) 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 <= -5.2e-24) || ~((z <= 1.2e-7))) 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, -5.2e-24], N[Not[LessEqual[z, 1.2e-7]], $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 -5.2 \cdot 10^{-24} \lor \neg \left(z \leq 1.2 \cdot 10^{-7}\right):\\
\;\;\;\;x - \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{-2}{\frac{t}{z}}\\
\end{array}
\end{array}
if z < -5.2e-24 or 1.19999999999999989e-7 < z Initial program 75.8%
Simplified87.9%
Taylor expanded in y around 0 86.3%
if -5.2e-24 < z < 1.19999999999999989e-7Initial program 89.0%
Simplified92.1%
clear-num91.7%
un-div-inv91.8%
*-commutative91.8%
*-commutative91.8%
associate-*l*91.8%
pow291.8%
Applied egg-rr91.8%
Taylor expanded in z around 0 79.1%
associate-*r*79.1%
neg-mul-179.1%
*-commutative79.1%
Simplified79.1%
frac-2neg79.1%
div-inv79.1%
distribute-neg-frac279.1%
distribute-rgt-neg-out79.1%
frac-2neg79.1%
add-sqr-sqrt40.1%
times-frac42.9%
add-sqr-sqrt21.3%
sqrt-unprod31.3%
sqr-neg31.3%
sqrt-unprod16.8%
add-sqr-sqrt35.2%
times-frac32.1%
add-sqr-sqrt64.6%
clear-num64.6%
distribute-lft-neg-in64.6%
clear-num64.6%
Applied egg-rr80.6%
neg-sub080.6%
associate-*r*80.6%
associate-*r/82.4%
associate-*r/86.4%
/-rgt-identity86.4%
associate-/r/86.3%
associate-/r*79.1%
*-commutative79.1%
associate-/r*81.1%
associate-/r/81.1%
/-rgt-identity81.1%
associate-*l/75.8%
associate-/r/81.8%
associate-/r*84.9%
times-frac87.9%
*-inverses87.9%
*-rgt-identity87.9%
distribute-neg-frac87.9%
metadata-eval87.9%
Simplified87.9%
Final simplification87.0%
(FPCore (x y z t) :precision binary64 (if (or (<= z -2.8e-26) (not (<= z 0.0022))) (- x (/ y z)) (- x (/ (* z -2.0) t))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2.8e-26) || !(z <= 0.0022)) {
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 <= (-2.8d-26)) .or. (.not. (z <= 0.0022d0))) 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 <= -2.8e-26) || !(z <= 0.0022)) {
tmp = x - (y / z);
} else {
tmp = x - ((z * -2.0) / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -2.8e-26) or not (z <= 0.0022): tmp = x - (y / z) else: tmp = x - ((z * -2.0) / t) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -2.8e-26) || !(z <= 0.0022)) 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 <= -2.8e-26) || ~((z <= 0.0022))) 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, -2.8e-26], N[Not[LessEqual[z, 0.0022]], $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 -2.8 \cdot 10^{-26} \lor \neg \left(z \leq 0.0022\right):\\
\;\;\;\;x - \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{z \cdot -2}{t}\\
\end{array}
\end{array}
if z < -2.8000000000000001e-26 or 0.00220000000000000013 < z Initial program 75.8%
Simplified87.9%
Taylor expanded in y around 0 86.3%
if -2.8000000000000001e-26 < z < 0.00220000000000000013Initial program 89.0%
Simplified92.1%
Taylor expanded in y around inf 87.9%
*-commutative87.9%
associate-*l/87.9%
Simplified87.9%
Final simplification87.1%
(FPCore (x y z t) :precision binary64 (if (<= t -8.1e-19) x (if (<= t 5.2e-92) (- x (/ y z)) x)))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= -8.1e-19) {
tmp = x;
} else if (t <= 5.2e-92) {
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 (t <= (-8.1d-19)) then
tmp = x
else if (t <= 5.2d-92) 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 (t <= -8.1e-19) {
tmp = x;
} else if (t <= 5.2e-92) {
tmp = x - (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= -8.1e-19: tmp = x elif t <= 5.2e-92: tmp = x - (y / z) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= -8.1e-19) tmp = x; elseif (t <= 5.2e-92) 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 (t <= -8.1e-19) tmp = x; elseif (t <= 5.2e-92) tmp = x - (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, -8.1e-19], x, If[LessEqual[t, 5.2e-92], N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -8.1 \cdot 10^{-19}:\\
\;\;\;\;x\\
\mathbf{elif}\;t \leq 5.2 \cdot 10^{-92}:\\
\;\;\;\;x - \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if t < -8.10000000000000023e-19 or 5.2e-92 < t Initial program 84.2%
Simplified92.0%
Taylor expanded in x around inf 83.6%
if -8.10000000000000023e-19 < t < 5.2e-92Initial program 79.6%
Simplified87.0%
Taylor expanded in y around 0 75.9%
Final simplification80.5%
(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.3%
Simplified90.0%
Taylor expanded in x around inf 76.0%
Final simplification76.0%
(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 2024043
(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)))))