
(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 3 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 (- (/ z (/ y 2.0)) (/ t z)))))
double code(double x, double y, double z, double t) {
return x - (2.0 / ((z / (y / 2.0)) - (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 - (2.0d0 / ((z / (y / 2.0d0)) - (t / z)))
end function
public static double code(double x, double y, double z, double t) {
return x - (2.0 / ((z / (y / 2.0)) - (t / z)));
}
def code(x, y, z, t): return x - (2.0 / ((z / (y / 2.0)) - (t / z)))
function code(x, y, z, t) return Float64(x - Float64(2.0 / Float64(Float64(z / Float64(y / 2.0)) - Float64(t / z)))) end
function tmp = code(x, y, z, t) tmp = x - (2.0 / ((z / (y / 2.0)) - (t / z))); end
code[x_, y_, z_, t_] := N[(x - N[(2.0 / N[(N[(z / N[(y / 2.0), $MachinePrecision]), $MachinePrecision] - N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \frac{2}{\frac{z}{\frac{y}{2}} - \frac{t}{z}}
\end{array}
Initial program 83.1%
associate-/l*91.3%
associate-*l*91.3%
Simplified91.3%
Taylor expanded in z around 0 96.6%
+-commutative96.6%
mul-1-neg96.6%
*-commutative96.6%
associate-*r/98.8%
unsub-neg98.8%
*-commutative98.8%
associate-*r/96.6%
associate-*l/98.1%
*-commutative98.1%
Simplified98.1%
add-log-exp69.4%
*-un-lft-identity69.4%
log-prod69.4%
metadata-eval69.4%
add-log-exp98.1%
*-commutative98.1%
*-un-lft-identity98.1%
times-frac98.1%
metadata-eval98.1%
*-commutative98.1%
Applied egg-rr98.1%
+-lft-identity98.1%
associate-*r/98.1%
associate-/l*98.0%
div-sub98.0%
*-commutative98.0%
associate-/l*98.0%
associate-*r/96.5%
associate-*l/98.7%
associate-/l*99.9%
*-inverses99.9%
associate-/r*99.9%
*-rgt-identity99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z t) :precision binary64 (if (or (<= z -95.0) (not (<= z 2.3e+52))) (- x (/ y z)) (- x (* (/ z t) -2.0))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -95.0) || !(z <= 2.3e+52)) {
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 <= (-95.0d0)) .or. (.not. (z <= 2.3d+52))) 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 <= -95.0) || !(z <= 2.3e+52)) {
tmp = x - (y / z);
} else {
tmp = x - ((z / t) * -2.0);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -95.0) or not (z <= 2.3e+52): tmp = x - (y / z) else: tmp = x - ((z / t) * -2.0) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -95.0) || !(z <= 2.3e+52)) 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 <= -95.0) || ~((z <= 2.3e+52))) 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, -95.0], N[Not[LessEqual[z, 2.3e+52]], $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 -95 \lor \neg \left(z \leq 2.3 \cdot 10^{+52}\right):\\
\;\;\;\;x - \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{z}{t} \cdot -2\\
\end{array}
\end{array}
if z < -95 or 2.3e52 < z Initial program 69.3%
associate-/l*87.1%
associate-*l*87.1%
Simplified87.1%
Taylor expanded in y around 0 92.0%
if -95 < z < 2.3e52Initial program 93.8%
associate-/l*94.6%
associate-*l*94.6%
Simplified94.6%
Taylor expanded in y around inf 87.8%
*-commutative87.8%
Simplified87.8%
Final simplification89.6%
(FPCore (x y z t) :precision binary64 (- x (/ y z)))
double code(double x, double y, double z, double t) {
return x - (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 / z)
end function
public static double code(double x, double y, double z, double t) {
return x - (y / z);
}
def code(x, y, z, t): return x - (y / z)
function code(x, y, z, t) return Float64(x - Float64(y / z)) end
function tmp = code(x, y, z, t) tmp = x - (y / z); end
code[x_, y_, z_, t_] := N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \frac{y}{z}
\end{array}
Initial program 83.1%
associate-/l*91.3%
associate-*l*91.3%
Simplified91.3%
Taylor expanded in y around 0 59.8%
Final simplification59.8%
(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 2024041
(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)))))