
(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 7 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 (/ (* y 2.0) (* y (- (/ t z) (/ (* 2.0 z) y))))))
double code(double x, double y, double z, double t) {
return x + ((y * 2.0) / (y * ((t / z) - ((2.0 * 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 + ((y * 2.0d0) / (y * ((t / z) - ((2.0d0 * z) / y))))
end function
public static double code(double x, double y, double z, double t) {
return x + ((y * 2.0) / (y * ((t / z) - ((2.0 * z) / y))));
}
def code(x, y, z, t): return x + ((y * 2.0) / (y * ((t / z) - ((2.0 * z) / y))))
function code(x, y, z, t) return Float64(x + Float64(Float64(y * 2.0) / Float64(y * Float64(Float64(t / z) - Float64(Float64(2.0 * z) / y))))) end
function tmp = code(x, y, z, t) tmp = x + ((y * 2.0) / (y * ((t / z) - ((2.0 * z) / y)))); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y * 2.0), $MachinePrecision] / N[(y * N[(N[(t / z), $MachinePrecision] - N[(N[(2.0 * z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y \cdot 2}{y \cdot \left(\frac{t}{z} - \frac{2 \cdot z}{y}\right)}
\end{array}
Initial program 82.1%
Simplified88.9%
clear-num88.9%
un-div-inv88.9%
associate-*r*88.9%
*-commutative88.9%
associate-*l*88.9%
pow288.9%
Applied egg-rr88.9%
Taylor expanded in y around inf 97.2%
+-commutative97.2%
mul-1-neg97.2%
unsub-neg97.2%
associate-*r/97.2%
*-commutative97.2%
Simplified97.2%
Final simplification97.2%
(FPCore (x y z t) :precision binary64 (if (or (<= z -1.6e-139) (not (<= z 1.55e-200))) (+ x (/ (* y 2.0) (- (/ (* y t) z) (* 2.0 z)))) (- x (/ (* z -2.0) t))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -1.6e-139) || !(z <= 1.55e-200)) {
tmp = x + ((y * 2.0) / (((y * t) / z) - (2.0 * 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-139)) .or. (.not. (z <= 1.55d-200))) then
tmp = x + ((y * 2.0d0) / (((y * t) / z) - (2.0d0 * 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-139) || !(z <= 1.55e-200)) {
tmp = x + ((y * 2.0) / (((y * t) / z) - (2.0 * z)));
} else {
tmp = x - ((z * -2.0) / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -1.6e-139) or not (z <= 1.55e-200): tmp = x + ((y * 2.0) / (((y * t) / z) - (2.0 * z))) else: tmp = x - ((z * -2.0) / t) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -1.6e-139) || !(z <= 1.55e-200)) tmp = Float64(x + Float64(Float64(y * 2.0) / Float64(Float64(Float64(y * t) / z) - Float64(2.0 * 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 <= -1.6e-139) || ~((z <= 1.55e-200))) tmp = x + ((y * 2.0) / (((y * t) / z) - (2.0 * z))); else tmp = x - ((z * -2.0) / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -1.6e-139], N[Not[LessEqual[z, 1.55e-200]], $MachinePrecision]], N[(x + N[(N[(y * 2.0), $MachinePrecision] / N[(N[(N[(y * t), $MachinePrecision] / z), $MachinePrecision] - N[(2.0 * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x - N[(N[(z * -2.0), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.6 \cdot 10^{-139} \lor \neg \left(z \leq 1.55 \cdot 10^{-200}\right):\\
\;\;\;\;x + \frac{y \cdot 2}{\frac{y \cdot t}{z} - 2 \cdot z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{z \cdot -2}{t}\\
\end{array}
\end{array}
if z < -1.6e-139 or 1.5499999999999999e-200 < z Initial program 82.5%
Simplified91.3%
clear-num91.3%
un-div-inv91.3%
associate-*r*91.3%
*-commutative91.3%
associate-*l*91.3%
pow291.3%
Applied egg-rr91.3%
Taylor expanded in y around 0 96.4%
+-commutative96.4%
mul-1-neg96.4%
*-commutative96.4%
associate-*r/97.9%
unsub-neg97.9%
*-commutative97.9%
associate-*r/96.4%
Simplified96.4%
if -1.6e-139 < z < 1.5499999999999999e-200Initial program 80.8%
Simplified80.4%
Taylor expanded in y around inf 98.5%
metadata-eval98.5%
cancel-sign-sub-inv98.5%
associate-*r/98.5%
*-commutative98.5%
Simplified98.5%
Final simplification97.0%
(FPCore (x y z t) :precision binary64 (if (or (<= z -21000.0) (not (<= z 3.8e+20))) (- x (/ y z)) (- x (/ (* z -2.0) t))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -21000.0) || !(z <= 3.8e+20)) {
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 <= (-21000.0d0)) .or. (.not. (z <= 3.8d+20))) 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 <= -21000.0) || !(z <= 3.8e+20)) {
tmp = x - (y / z);
} else {
tmp = x - ((z * -2.0) / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -21000.0) or not (z <= 3.8e+20): tmp = x - (y / z) else: tmp = x - ((z * -2.0) / t) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -21000.0) || !(z <= 3.8e+20)) 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 <= -21000.0) || ~((z <= 3.8e+20))) 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, -21000.0], N[Not[LessEqual[z, 3.8e+20]], $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 -21000 \lor \neg \left(z \leq 3.8 \cdot 10^{+20}\right):\\
\;\;\;\;x - \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{z \cdot -2}{t}\\
\end{array}
\end{array}
if z < -21000 or 3.8e20 < z Initial program 74.5%
Simplified86.4%
Taylor expanded in y around 0 89.5%
mul-1-neg89.5%
sub-neg89.5%
Simplified89.5%
if -21000 < z < 3.8e20Initial program 87.3%
Simplified90.1%
Taylor expanded in y around inf 90.0%
metadata-eval90.0%
cancel-sign-sub-inv90.0%
associate-*r/90.0%
*-commutative90.0%
Simplified90.0%
Final simplification89.8%
(FPCore (x y z t) :precision binary64 (if (or (<= z -11500.0) (not (<= z 3.8e+20))) (- x (/ y z)) (- x (* z (/ -2.0 t)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -11500.0) || !(z <= 3.8e+20)) {
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 <= (-11500.0d0)) .or. (.not. (z <= 3.8d+20))) 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 <= -11500.0) || !(z <= 3.8e+20)) {
tmp = x - (y / z);
} else {
tmp = x - (z * (-2.0 / t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -11500.0) or not (z <= 3.8e+20): tmp = x - (y / z) else: tmp = x - (z * (-2.0 / t)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -11500.0) || !(z <= 3.8e+20)) 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 <= -11500.0) || ~((z <= 3.8e+20))) 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, -11500.0], N[Not[LessEqual[z, 3.8e+20]], $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 -11500 \lor \neg \left(z \leq 3.8 \cdot 10^{+20}\right):\\
\;\;\;\;x - \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - z \cdot \frac{-2}{t}\\
\end{array}
\end{array}
if z < -11500 or 3.8e20 < z Initial program 74.5%
Simplified86.4%
Taylor expanded in y around 0 89.5%
mul-1-neg89.5%
sub-neg89.5%
Simplified89.5%
if -11500 < z < 3.8e20Initial program 87.3%
Simplified90.1%
Taylor expanded in y around inf 90.0%
metadata-eval90.0%
cancel-sign-sub-inv90.0%
associate-*r/90.0%
*-commutative90.0%
Simplified90.0%
associate-/l*90.0%
*-commutative90.0%
Applied egg-rr90.0%
Final simplification89.8%
(FPCore (x y z t) :precision binary64 (if (or (<= z -1.3e+15) (not (<= z 40000000.0))) (- x (/ y z)) x))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -1.3e+15) || !(z <= 40000000.0)) {
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 <= (-1.3d+15)) .or. (.not. (z <= 40000000.0d0))) 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 <= -1.3e+15) || !(z <= 40000000.0)) {
tmp = x - (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -1.3e+15) or not (z <= 40000000.0): tmp = x - (y / z) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -1.3e+15) || !(z <= 40000000.0)) 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 <= -1.3e+15) || ~((z <= 40000000.0))) tmp = x - (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -1.3e+15], N[Not[LessEqual[z, 40000000.0]], $MachinePrecision]], N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.3 \cdot 10^{+15} \lor \neg \left(z \leq 40000000\right):\\
\;\;\;\;x - \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.3e15 or 4e7 < z Initial program 73.8%
Simplified86.5%
Taylor expanded in y around 0 87.8%
mul-1-neg87.8%
sub-neg87.8%
Simplified87.8%
if -1.3e15 < z < 4e7Initial program 87.9%
Simplified90.1%
Taylor expanded in y around 0 72.4%
Final simplification78.8%
(FPCore (x y z t) :precision binary64 (if (<= x -2.7e-175) x (if (<= x 1.7e-247) (* z (/ 2.0 t)) x)))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -2.7e-175) {
tmp = x;
} else if (x <= 1.7e-247) {
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 <= (-2.7d-175)) then
tmp = x
else if (x <= 1.7d-247) 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 <= -2.7e-175) {
tmp = x;
} else if (x <= 1.7e-247) {
tmp = z * (2.0 / t);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -2.7e-175: tmp = x elif x <= 1.7e-247: tmp = z * (2.0 / t) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -2.7e-175) tmp = x; elseif (x <= 1.7e-247) 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 <= -2.7e-175) tmp = x; elseif (x <= 1.7e-247) tmp = z * (2.0 / t); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -2.7e-175], x, If[LessEqual[x, 1.7e-247], N[(z * N[(2.0 / t), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.7 \cdot 10^{-175}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1.7 \cdot 10^{-247}:\\
\;\;\;\;z \cdot \frac{2}{t}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -2.69999999999999999e-175 or 1.7000000000000001e-247 < x Initial program 85.0%
Simplified91.8%
Taylor expanded in y around 0 77.4%
if -2.69999999999999999e-175 < x < 1.7000000000000001e-247Initial program 59.9%
Simplified64.2%
Taylor expanded in y around inf 64.6%
metadata-eval64.6%
cancel-sign-sub-inv64.6%
associate-*r/64.6%
*-commutative64.6%
Simplified64.6%
clear-num64.4%
inv-pow64.4%
*-un-lft-identity64.4%
*-commutative64.4%
times-frac64.4%
metadata-eval64.4%
Applied egg-rr64.4%
unpow-164.4%
associate-*r/64.4%
Simplified64.4%
Taylor expanded in x around 0 49.6%
associate-*r/49.6%
associate-*l/49.4%
*-commutative49.4%
Simplified49.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 82.1%
Simplified88.6%
Taylor expanded in y around 0 70.7%
(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 2024123
(FPCore (x y z t)
:name "Numeric.AD.Rank1.Halley:findZero from ad-4.2.4"
:precision binary64
:alt
(! :herbie-platform default (- x (/ 1 (- (/ z y) (/ (/ t 2) z)))))
(- x (/ (* (* y 2.0) z) (- (* (* z 2.0) z) (* y t)))))