
(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 (fma (/ y (+ (* z -2.0) (* y (/ t z)))) 2.0 x))
double code(double x, double y, double z, double t) {
return fma((y / ((z * -2.0) + (y * (t / z)))), 2.0, x);
}
function code(x, y, z, t) return fma(Float64(y / Float64(Float64(z * -2.0) + Float64(y * Float64(t / z)))), 2.0, x) end
code[x_, y_, z_, t_] := N[(N[(y / N[(N[(z * -2.0), $MachinePrecision] + N[(y * N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 2.0 + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{y}{z \cdot -2 + y \cdot \frac{t}{z}}, 2, x\right)
\end{array}
Initial program 81.7%
sub-neg81.7%
+-commutative81.7%
distribute-neg-frac81.7%
distribute-rgt-neg-out81.7%
remove-double-neg81.7%
distribute-rgt-neg-in81.7%
distribute-lft-neg-out81.7%
distribute-lft-neg-out81.7%
associate-/l*92.6%
associate-*l/92.6%
fma-def92.6%
Simplified99.2%
Final simplification99.2%
(FPCore (x y z t) :precision binary64 (+ x (* (* y 2.0) (/ -1.0 (- (* z 2.0) (* y (/ t z)))))))
double code(double x, double y, double z, double t) {
return x + ((y * 2.0) * (-1.0 / ((z * 2.0) - (y * (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 + ((y * 2.0d0) * ((-1.0d0) / ((z * 2.0d0) - (y * (t / z)))))
end function
public static double code(double x, double y, double z, double t) {
return x + ((y * 2.0) * (-1.0 / ((z * 2.0) - (y * (t / z)))));
}
def code(x, y, z, t): return x + ((y * 2.0) * (-1.0 / ((z * 2.0) - (y * (t / z)))))
function code(x, y, z, t) return Float64(x + Float64(Float64(y * 2.0) * Float64(-1.0 / Float64(Float64(z * 2.0) - Float64(y * Float64(t / z)))))) end
function tmp = code(x, y, z, t) tmp = x + ((y * 2.0) * (-1.0 / ((z * 2.0) - (y * (t / z))))); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y * 2.0), $MachinePrecision] * N[(-1.0 / N[(N[(z * 2.0), $MachinePrecision] - N[(y * N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y \cdot 2\right) \cdot \frac{-1}{z \cdot 2 - y \cdot \frac{t}{z}}
\end{array}
Initial program 81.7%
associate-/l*92.6%
associate-*l*92.6%
Simplified92.6%
div-inv92.6%
Applied egg-rr92.6%
Taylor expanded in z around 0 96.5%
+-commutative96.5%
mul-1-neg96.5%
*-commutative96.5%
associate-*r/99.2%
unsub-neg99.2%
*-commutative99.2%
Simplified99.2%
Final simplification99.2%
(FPCore (x y z t) :precision binary64 (if (or (<= z -9e-6) (not (<= z 4.5e+29))) (- x (/ y z)) (+ x (* z (/ 2.0 t)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -9e-6) || !(z <= 4.5e+29)) {
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 <= (-9d-6)) .or. (.not. (z <= 4.5d+29))) 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 <= -9e-6) || !(z <= 4.5e+29)) {
tmp = x - (y / z);
} else {
tmp = x + (z * (2.0 / t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -9e-6) or not (z <= 4.5e+29): tmp = x - (y / z) else: tmp = x + (z * (2.0 / t)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -9e-6) || !(z <= 4.5e+29)) 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 <= -9e-6) || ~((z <= 4.5e+29))) 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, -9e-6], N[Not[LessEqual[z, 4.5e+29]], $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 -9 \cdot 10^{-6} \lor \neg \left(z \leq 4.5 \cdot 10^{+29}\right):\\
\;\;\;\;x - \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x + z \cdot \frac{2}{t}\\
\end{array}
\end{array}
if z < -9.00000000000000023e-6 or 4.5000000000000002e29 < z Initial program 72.7%
sub-neg72.7%
associate-/l*89.2%
distribute-neg-frac89.2%
distribute-lft-neg-out89.2%
associate-/r/89.2%
distribute-lft-neg-out89.2%
distribute-rgt-neg-in89.2%
metadata-eval89.2%
*-commutative89.2%
associate-*l*89.2%
fma-neg89.2%
Simplified89.2%
Taylor expanded in y around 0 93.7%
mul-1-neg93.7%
sub-neg93.7%
Simplified93.7%
if -9.00000000000000023e-6 < z < 4.5000000000000002e29Initial program 91.1%
sub-neg91.1%
associate-/l*96.2%
distribute-neg-frac96.2%
distribute-lft-neg-out96.2%
associate-/r/96.3%
distribute-lft-neg-out96.3%
distribute-rgt-neg-in96.3%
metadata-eval96.3%
*-commutative96.3%
associate-*l*96.3%
fma-neg96.3%
Simplified96.3%
Taylor expanded in y around inf 93.3%
Final simplification93.5%
(FPCore (x y z t) :precision binary64 (if (or (<= z -1.15e-5) (not (<= z 1.75e+30))) (- x (/ y z)) (- x (/ (* z -2.0) t))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -1.15e-5) || !(z <= 1.75e+30)) {
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.15d-5)) .or. (.not. (z <= 1.75d+30))) 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.15e-5) || !(z <= 1.75e+30)) {
tmp = x - (y / z);
} else {
tmp = x - ((z * -2.0) / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -1.15e-5) or not (z <= 1.75e+30): 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.15e-5) || !(z <= 1.75e+30)) 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 <= -1.15e-5) || ~((z <= 1.75e+30))) 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.15e-5], N[Not[LessEqual[z, 1.75e+30]], $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 -1.15 \cdot 10^{-5} \lor \neg \left(z \leq 1.75 \cdot 10^{+30}\right):\\
\;\;\;\;x - \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{z \cdot -2}{t}\\
\end{array}
\end{array}
if z < -1.15e-5 or 1.75000000000000011e30 < z Initial program 72.7%
sub-neg72.7%
associate-/l*89.2%
distribute-neg-frac89.2%
distribute-lft-neg-out89.2%
associate-/r/89.2%
distribute-lft-neg-out89.2%
distribute-rgt-neg-in89.2%
metadata-eval89.2%
*-commutative89.2%
associate-*l*89.2%
fma-neg89.2%
Simplified89.2%
Taylor expanded in y around 0 93.7%
mul-1-neg93.7%
sub-neg93.7%
Simplified93.7%
if -1.15e-5 < z < 1.75000000000000011e30Initial program 91.1%
associate-/l*96.2%
associate-*l*96.2%
Simplified96.2%
Taylor expanded in y around inf 93.4%
associate-*r/93.4%
*-commutative93.4%
Simplified93.4%
Final simplification93.6%
(FPCore (x y z t) :precision binary64 (if (or (<= z -6.5e+40) (not (<= z 5.8e+62))) (- x (/ y z)) x))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -6.5e+40) || !(z <= 5.8e+62)) {
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 <= (-6.5d+40)) .or. (.not. (z <= 5.8d+62))) 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 <= -6.5e+40) || !(z <= 5.8e+62)) {
tmp = x - (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -6.5e+40) or not (z <= 5.8e+62): tmp = x - (y / z) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -6.5e+40) || !(z <= 5.8e+62)) 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 <= -6.5e+40) || ~((z <= 5.8e+62))) tmp = x - (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -6.5e+40], N[Not[LessEqual[z, 5.8e+62]], $MachinePrecision]], N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.5 \cdot 10^{+40} \lor \neg \left(z \leq 5.8 \cdot 10^{+62}\right):\\
\;\;\;\;x - \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -6.5000000000000001e40 or 5.79999999999999968e62 < z Initial program 69.8%
sub-neg69.8%
associate-/l*87.7%
distribute-neg-frac87.7%
distribute-lft-neg-out87.7%
associate-/r/87.7%
distribute-lft-neg-out87.7%
distribute-rgt-neg-in87.7%
metadata-eval87.7%
*-commutative87.7%
associate-*l*87.7%
fma-neg87.7%
Simplified87.7%
Taylor expanded in y around 0 95.4%
mul-1-neg95.4%
sub-neg95.4%
Simplified95.4%
if -6.5000000000000001e40 < z < 5.79999999999999968e62Initial program 91.5%
sub-neg91.5%
associate-/l*96.7%
distribute-neg-frac96.7%
distribute-lft-neg-out96.7%
associate-/r/96.7%
distribute-lft-neg-out96.7%
distribute-rgt-neg-in96.7%
metadata-eval96.7%
*-commutative96.7%
associate-*l*96.7%
fma-neg96.7%
Simplified96.7%
Taylor expanded in x around inf 77.8%
Final simplification85.7%
(FPCore (x y z t) :precision binary64 (if (<= x -1e-166) x (if (<= x 1.45e-261) (* 2.0 (/ z t)) x)))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -1e-166) {
tmp = x;
} else if (x <= 1.45e-261) {
tmp = 2.0 * (z / 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 <= (-1d-166)) then
tmp = x
else if (x <= 1.45d-261) then
tmp = 2.0d0 * (z / 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 <= -1e-166) {
tmp = x;
} else if (x <= 1.45e-261) {
tmp = 2.0 * (z / t);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -1e-166: tmp = x elif x <= 1.45e-261: tmp = 2.0 * (z / t) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -1e-166) tmp = x; elseif (x <= 1.45e-261) tmp = Float64(2.0 * Float64(z / t)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= -1e-166) tmp = x; elseif (x <= 1.45e-261) tmp = 2.0 * (z / t); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -1e-166], x, If[LessEqual[x, 1.45e-261], N[(2.0 * N[(z / t), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \cdot 10^{-166}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1.45 \cdot 10^{-261}:\\
\;\;\;\;2 \cdot \frac{z}{t}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -1.00000000000000004e-166 or 1.44999999999999993e-261 < x Initial program 84.3%
sub-neg84.3%
associate-/l*94.3%
distribute-neg-frac94.3%
distribute-lft-neg-out94.3%
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 87.3%
if -1.00000000000000004e-166 < x < 1.44999999999999993e-261Initial program 60.6%
sub-neg60.6%
+-commutative60.6%
distribute-neg-frac60.6%
distribute-rgt-neg-out60.6%
remove-double-neg60.6%
distribute-rgt-neg-in60.6%
distribute-lft-neg-out60.6%
distribute-lft-neg-out60.6%
associate-/l*79.0%
associate-*l/79.0%
fma-def79.0%
Simplified92.8%
Taylor expanded in x around 0 66.6%
Taylor expanded in y around inf 58.7%
Final simplification84.1%
(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.7%
sub-neg81.7%
associate-/l*92.6%
distribute-neg-frac92.6%
distribute-lft-neg-out92.6%
associate-/r/92.6%
distribute-lft-neg-out92.6%
distribute-rgt-neg-in92.6%
metadata-eval92.6%
*-commutative92.6%
associate-*l*92.6%
fma-neg92.6%
Simplified92.6%
Taylor expanded in x around inf 80.1%
Final simplification80.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 2023275
(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)))))