
(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 (if (<= z 2e-135) (+ x (* z (/ 2.0 (- t (* z (/ 2.0 (/ y z))))))) (fma (/ y (+ (* z -2.0) (* t (/ y z)))) 2.0 x)))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 2e-135) {
tmp = x + (z * (2.0 / (t - (z * (2.0 / (y / z))))));
} else {
tmp = fma((y / ((z * -2.0) + (t * (y / z)))), 2.0, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (z <= 2e-135) tmp = Float64(x + Float64(z * Float64(2.0 / Float64(t - Float64(z * Float64(2.0 / Float64(y / z))))))); else tmp = fma(Float64(y / Float64(Float64(z * -2.0) + Float64(t * Float64(y / z)))), 2.0, x); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[z, 2e-135], N[(x + N[(z * N[(2.0 / N[(t - N[(z * N[(2.0 / N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y / N[(N[(z * -2.0), $MachinePrecision] + N[(t * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 2.0 + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 2 \cdot 10^{-135}:\\
\;\;\;\;x + z \cdot \frac{2}{t - z \cdot \frac{2}{\frac{y}{z}}}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{z \cdot -2 + t \cdot \frac{y}{z}}, 2, x\right)\\
\end{array}
\end{array}
if z < 2.0000000000000001e-135Initial program 84.0%
Simplified91.4%
*-commutative91.4%
clear-num91.0%
un-div-inv91.1%
frac-2neg91.1%
fma-udef91.1%
*-commutative91.1%
associate-*r*91.1%
fma-def91.1%
fma-neg91.1%
*-commutative91.1%
*-commutative91.1%
associate-*r*91.1%
Applied egg-rr91.1%
distribute-rgt-neg-in91.1%
metadata-eval91.1%
distribute-neg-frac91.1%
neg-sub091.0%
cancel-sign-sub-inv91.0%
*-commutative91.0%
+-commutative91.0%
associate--r+91.0%
neg-sub091.0%
distribute-rgt-neg-in91.0%
remove-double-neg91.0%
*-commutative91.0%
associate-*r*91.0%
*-commutative91.0%
*-commutative91.0%
Simplified91.0%
associate-/l*91.0%
div-inv90.9%
clear-num90.9%
*-commutative90.9%
div-sub91.0%
*-commutative91.0%
associate-/l*95.3%
*-inverses95.3%
/-rgt-identity95.3%
*-commutative95.3%
associate-/l*98.8%
un-div-inv98.7%
*-lft-identity98.7%
times-frac98.7%
/-rgt-identity98.7%
un-div-inv98.8%
Applied egg-rr98.8%
if 2.0000000000000001e-135 < z Initial program 77.3%
Simplified100.0%
Final simplification99.2%
(FPCore (x y z t) :precision binary64 (if (<= z 2e+136) (+ x (* z (/ 2.0 (- t (* z (/ 2.0 (/ y z))))))) (- x (/ y z))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 2e+136) {
tmp = x + (z * (2.0 / (t - (z * (2.0 / (y / z))))));
} else {
tmp = x - (y / 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 <= 2d+136) then
tmp = x + (z * (2.0d0 / (t - (z * (2.0d0 / (y / z))))))
else
tmp = x - (y / z)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= 2e+136) {
tmp = x + (z * (2.0 / (t - (z * (2.0 / (y / z))))));
} else {
tmp = x - (y / z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= 2e+136: tmp = x + (z * (2.0 / (t - (z * (2.0 / (y / z)))))) else: tmp = x - (y / z) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= 2e+136) tmp = Float64(x + Float64(z * Float64(2.0 / Float64(t - Float64(z * Float64(2.0 / Float64(y / z))))))); else tmp = Float64(x - Float64(y / z)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= 2e+136) tmp = x + (z * (2.0 / (t - (z * (2.0 / (y / z)))))); else tmp = x - (y / z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, 2e+136], N[(x + N[(z * N[(2.0 / N[(t - N[(z * N[(2.0 / N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 2 \cdot 10^{+136}:\\
\;\;\;\;x + z \cdot \frac{2}{t - z \cdot \frac{2}{\frac{y}{z}}}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{y}{z}\\
\end{array}
\end{array}
if z < 2.00000000000000012e136Initial program 85.6%
Simplified93.0%
*-commutative93.0%
clear-num92.6%
un-div-inv92.7%
frac-2neg92.7%
fma-udef92.7%
*-commutative92.7%
associate-*r*92.7%
fma-def92.7%
fma-neg92.7%
*-commutative92.7%
*-commutative92.7%
associate-*r*92.7%
Applied egg-rr92.7%
distribute-rgt-neg-in92.7%
metadata-eval92.7%
distribute-neg-frac92.7%
neg-sub092.6%
cancel-sign-sub-inv92.6%
*-commutative92.6%
+-commutative92.6%
associate--r+92.6%
neg-sub092.6%
distribute-rgt-neg-in92.6%
remove-double-neg92.6%
*-commutative92.6%
associate-*r*92.6%
*-commutative92.6%
*-commutative92.6%
Simplified92.6%
associate-/l*92.6%
div-inv92.5%
clear-num92.5%
*-commutative92.5%
div-sub92.6%
*-commutative92.6%
associate-/l*96.3%
*-inverses96.3%
/-rgt-identity96.3%
*-commutative96.3%
associate-/l*98.9%
un-div-inv98.9%
*-lft-identity98.9%
times-frac98.9%
/-rgt-identity98.9%
un-div-inv98.9%
Applied egg-rr98.9%
if 2.00000000000000012e136 < z Initial program 57.5%
Simplified78.7%
Taylor expanded in y around 0 100.0%
mul-1-neg100.0%
sub-neg100.0%
Simplified100.0%
Final simplification99.1%
(FPCore (x y z t) :precision binary64 (if (or (<= z -2.3e+39) (not (<= z 0.0105))) (- x (/ y z)) (- x (* -2.0 (/ z t)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2.3e+39) || !(z <= 0.0105)) {
tmp = x - (y / z);
} else {
tmp = x - (-2.0 * (z / 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.3d+39)) .or. (.not. (z <= 0.0105d0))) then
tmp = x - (y / z)
else
tmp = x - ((-2.0d0) * (z / t))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2.3e+39) || !(z <= 0.0105)) {
tmp = x - (y / z);
} else {
tmp = x - (-2.0 * (z / t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -2.3e+39) or not (z <= 0.0105): tmp = x - (y / z) else: tmp = x - (-2.0 * (z / t)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -2.3e+39) || !(z <= 0.0105)) tmp = Float64(x - Float64(y / z)); else tmp = Float64(x - Float64(-2.0 * Float64(z / t))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -2.3e+39) || ~((z <= 0.0105))) tmp = x - (y / z); else tmp = x - (-2.0 * (z / t)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -2.3e+39], N[Not[LessEqual[z, 0.0105]], $MachinePrecision]], N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision], N[(x - N[(-2.0 * N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.3 \cdot 10^{+39} \lor \neg \left(z \leq 0.0105\right):\\
\;\;\;\;x - \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - -2 \cdot \frac{z}{t}\\
\end{array}
\end{array}
if z < -2.30000000000000012e39 or 0.0105000000000000007 < z Initial program 69.7%
Simplified87.6%
Taylor expanded in y around 0 92.7%
mul-1-neg92.7%
sub-neg92.7%
Simplified92.7%
if -2.30000000000000012e39 < z < 0.0105000000000000007Initial program 90.1%
*-commutative90.1%
associate-*r/93.4%
remove-double-neg93.4%
distribute-lft-neg-out93.4%
distribute-lft-neg-out93.4%
distribute-rgt-neg-out93.4%
cancel-sign-sub-inv93.4%
*-commutative93.4%
cancel-sign-sub93.4%
distribute-lft-neg-in93.4%
Simplified92.2%
Taylor expanded in y around inf 86.0%
Final simplification88.8%
(FPCore (x y z t) :precision binary64 (if (or (<= z -2.15e+40) (not (<= z 1.8e+136))) (- x (/ y z)) x))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2.15e+40) || !(z <= 1.8e+136)) {
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 <= (-2.15d+40)) .or. (.not. (z <= 1.8d+136))) 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 <= -2.15e+40) || !(z <= 1.8e+136)) {
tmp = x - (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -2.15e+40) or not (z <= 1.8e+136): tmp = x - (y / z) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -2.15e+40) || !(z <= 1.8e+136)) 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 <= -2.15e+40) || ~((z <= 1.8e+136))) tmp = x - (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -2.15e+40], N[Not[LessEqual[z, 1.8e+136]], $MachinePrecision]], N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.15 \cdot 10^{+40} \lor \neg \left(z \leq 1.8 \cdot 10^{+136}\right):\\
\;\;\;\;x - \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.1500000000000001e40 or 1.80000000000000003e136 < z Initial program 65.5%
Simplified85.0%
Taylor expanded in y around 0 95.3%
mul-1-neg95.3%
sub-neg95.3%
Simplified95.3%
if -2.1500000000000001e40 < z < 1.80000000000000003e136Initial program 89.3%
Simplified93.8%
Taylor expanded in x around inf 80.9%
Final simplification85.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 81.7%
Simplified91.0%
Taylor expanded in x around inf 80.5%
Final simplification80.5%
(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 2023297
(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)))))