
(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 4 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) (- (* 2.0 z) (* t (/ y z))))))
double code(double x, double y, double z, double t) {
return x - ((y * 2.0) / ((2.0 * z) - (t * (y / 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 - ((y * 2.0d0) / ((2.0d0 * z) - (t * (y / z))))
end function
public static double code(double x, double y, double z, double t) {
return x - ((y * 2.0) / ((2.0 * z) - (t * (y / z))));
}
def code(x, y, z, t): return x - ((y * 2.0) / ((2.0 * z) - (t * (y / z))))
function code(x, y, z, t) return Float64(x - Float64(Float64(y * 2.0) / Float64(Float64(2.0 * z) - Float64(t * Float64(y / z))))) end
function tmp = code(x, y, z, t) tmp = x - ((y * 2.0) / ((2.0 * z) - (t * (y / z)))); end
code[x_, y_, z_, t_] := N[(x - N[(N[(y * 2.0), $MachinePrecision] / N[(N[(2.0 * z), $MachinePrecision] - N[(t * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \frac{y \cdot 2}{2 \cdot z - t \cdot \frac{y}{z}}
\end{array}
Initial program 83.3%
remove-double-neg83.3%
neg-mul-183.3%
*-commutative83.3%
*-commutative83.3%
neg-mul-183.3%
remove-double-neg83.3%
associate-/l*90.7%
associate-*l*90.7%
Simplified90.7%
Taylor expanded in z around 0 96.2%
+-commutative96.2%
mul-1-neg96.2%
associate-*r/98.0%
*-commutative98.0%
associate-/r/99.2%
unsub-neg99.2%
*-commutative99.2%
associate-/r/98.0%
*-commutative98.0%
Simplified98.0%
Final simplification98.0%
(FPCore (x y z t) :precision binary64 (if (or (<= z -4.8e+16) (not (<= z 1.8e+21))) (- x (/ y z)) (- x (* (/ z t) -2.0))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -4.8e+16) || !(z <= 1.8e+21)) {
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 <= (-4.8d+16)) .or. (.not. (z <= 1.8d+21))) 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 <= -4.8e+16) || !(z <= 1.8e+21)) {
tmp = x - (y / z);
} else {
tmp = x - ((z / t) * -2.0);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -4.8e+16) or not (z <= 1.8e+21): tmp = x - (y / z) else: tmp = x - ((z / t) * -2.0) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -4.8e+16) || !(z <= 1.8e+21)) 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 <= -4.8e+16) || ~((z <= 1.8e+21))) 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, -4.8e+16], N[Not[LessEqual[z, 1.8e+21]], $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 -4.8 \cdot 10^{+16} \lor \neg \left(z \leq 1.8 \cdot 10^{+21}\right):\\
\;\;\;\;x - \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{z}{t} \cdot -2\\
\end{array}
\end{array}
if z < -4.8e16 or 1.8e21 < z Initial program 74.1%
sub-neg74.1%
associate-/l*87.5%
distribute-neg-frac87.5%
distribute-lft-neg-out87.5%
associate-/r/87.5%
distribute-lft-neg-out87.5%
distribute-rgt-neg-in87.5%
metadata-eval87.5%
*-commutative87.5%
associate-*l*87.5%
fma-neg87.5%
Simplified87.5%
Taylor expanded in y around 0 90.6%
mul-1-neg90.6%
sub-neg90.6%
Simplified90.6%
if -4.8e16 < z < 1.8e21Initial program 91.4%
remove-double-neg91.4%
neg-mul-191.4%
*-commutative91.4%
*-commutative91.4%
neg-mul-191.4%
remove-double-neg91.4%
associate-/l*93.5%
associate-*l*93.5%
Simplified93.5%
Taylor expanded in y around inf 92.2%
*-commutative92.2%
Simplified92.2%
Final simplification91.5%
(FPCore (x y z t) :precision binary64 (if (or (<= z -6e-55) (not (<= z 8e+20))) (- x (/ y z)) x))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -6e-55) || !(z <= 8e+20)) {
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 <= (-6d-55)) .or. (.not. (z <= 8d+20))) 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 <= -6e-55) || !(z <= 8e+20)) {
tmp = x - (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -6e-55) or not (z <= 8e+20): tmp = x - (y / z) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -6e-55) || !(z <= 8e+20)) 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 <= -6e-55) || ~((z <= 8e+20))) tmp = x - (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -6e-55], N[Not[LessEqual[z, 8e+20]], $MachinePrecision]], N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6 \cdot 10^{-55} \lor \neg \left(z \leq 8 \cdot 10^{+20}\right):\\
\;\;\;\;x - \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -6.00000000000000033e-55 or 8e20 < z Initial program 76.8%
sub-neg76.8%
associate-/l*88.8%
distribute-neg-frac88.8%
distribute-lft-neg-out88.8%
associate-/r/88.8%
distribute-lft-neg-out88.8%
distribute-rgt-neg-in88.8%
metadata-eval88.8%
*-commutative88.8%
associate-*l*88.8%
fma-neg88.8%
Simplified88.8%
Taylor expanded in y around 0 88.1%
mul-1-neg88.1%
sub-neg88.1%
Simplified88.1%
if -6.00000000000000033e-55 < z < 8e20Initial program 90.4%
sub-neg90.4%
associate-/l*92.8%
distribute-neg-frac92.8%
distribute-lft-neg-out92.8%
associate-/r/94.3%
distribute-lft-neg-out94.3%
distribute-rgt-neg-in94.3%
metadata-eval94.3%
*-commutative94.3%
associate-*l*94.3%
fma-neg94.3%
Simplified94.3%
Taylor expanded in x around inf 71.1%
Final simplification79.9%
(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 83.3%
sub-neg83.3%
associate-/l*90.7%
distribute-neg-frac90.7%
distribute-lft-neg-out90.7%
associate-/r/91.4%
distribute-lft-neg-out91.4%
distribute-rgt-neg-in91.4%
metadata-eval91.4%
*-commutative91.4%
associate-*l*91.4%
fma-neg91.4%
Simplified91.4%
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 2023332
(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)))))