
(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 6 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
(let* ((t_1 (- x (/ y z))))
(if (<= z -7.2e+117)
t_1
(if (<= z 9.6e+139)
(fma (/ (* z 2.0) (fma z (* z -2.0) (* y t))) y x)
t_1))))
double code(double x, double y, double z, double t) {
double t_1 = x - (y / z);
double tmp;
if (z <= -7.2e+117) {
tmp = t_1;
} else if (z <= 9.6e+139) {
tmp = fma(((z * 2.0) / fma(z, (z * -2.0), (y * t))), y, x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(x - Float64(y / z)) tmp = 0.0 if (z <= -7.2e+117) tmp = t_1; elseif (z <= 9.6e+139) tmp = fma(Float64(Float64(z * 2.0) / fma(z, Float64(z * -2.0), Float64(y * t))), y, x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -7.2e+117], t$95$1, If[LessEqual[z, 9.6e+139], N[(N[(N[(z * 2.0), $MachinePrecision] / N[(z * N[(z * -2.0), $MachinePrecision] + N[(y * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * y + x), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x - \frac{y}{z}\\
\mathbf{if}\;z \leq -7.2 \cdot 10^{+117}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 9.6 \cdot 10^{+139}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z \cdot 2}{\mathsf{fma}\left(z, z \cdot -2, y \cdot t\right)}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -7.20000000000000025e117 or 9.60000000000000032e139 < z Initial program 56.5%
Taylor expanded in y around 0
mul-1-negN/A
sub-negN/A
--lowering--.f64N/A
/-lowering-/.f6496.3
Simplified96.3%
if -7.20000000000000025e117 < z < 9.60000000000000032e139Initial program 90.5%
sub-negN/A
+-commutativeN/A
div-invN/A
distribute-lft-neg-inN/A
associate-*l*N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
associate-*l*N/A
accelerator-lowering-fma.f64N/A
Applied egg-rr95.3%
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
associate-*l/N/A
neg-mul-1N/A
*-commutativeN/A
/-lowering-/.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
metadata-evalN/A
*-lowering-*.f64N/A
+-commutativeN/A
associate-*l*N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6495.3
Applied egg-rr95.3%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- x (/ y z))))
(if (<= z -6.2e+117)
t_1
(if (<= z 2.22e+139)
(fma (/ z (fma y t (* -2.0 (* z z)))) (* y 2.0) x)
t_1))))
double code(double x, double y, double z, double t) {
double t_1 = x - (y / z);
double tmp;
if (z <= -6.2e+117) {
tmp = t_1;
} else if (z <= 2.22e+139) {
tmp = fma((z / fma(y, t, (-2.0 * (z * z)))), (y * 2.0), x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(x - Float64(y / z)) tmp = 0.0 if (z <= -6.2e+117) tmp = t_1; elseif (z <= 2.22e+139) tmp = fma(Float64(z / fma(y, t, Float64(-2.0 * Float64(z * z)))), Float64(y * 2.0), x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -6.2e+117], t$95$1, If[LessEqual[z, 2.22e+139], N[(N[(z / N[(y * t + N[(-2.0 * N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(y * 2.0), $MachinePrecision] + x), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x - \frac{y}{z}\\
\mathbf{if}\;z \leq -6.2 \cdot 10^{+117}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 2.22 \cdot 10^{+139}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{\mathsf{fma}\left(y, t, -2 \cdot \left(z \cdot z\right)\right)}, y \cdot 2, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -6.1999999999999995e117 or 2.22000000000000001e139 < z Initial program 56.5%
Taylor expanded in y around 0
mul-1-negN/A
sub-negN/A
--lowering--.f64N/A
/-lowering-/.f6496.3
Simplified96.3%
if -6.1999999999999995e117 < z < 2.22000000000000001e139Initial program 90.5%
sub-negN/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
distribute-lft-neg-inN/A
accelerator-lowering-fma.f64N/A
Applied egg-rr95.3%
Final simplification95.6%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- x (/ y z))))
(if (<= z -1.6e+25)
t_1
(if (<= z 10200000000000.0) (fma (/ z t) 2.0 x) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = x - (y / z);
double tmp;
if (z <= -1.6e+25) {
tmp = t_1;
} else if (z <= 10200000000000.0) {
tmp = fma((z / t), 2.0, x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(x - Float64(y / z)) tmp = 0.0 if (z <= -1.6e+25) tmp = t_1; elseif (z <= 10200000000000.0) tmp = fma(Float64(z / t), 2.0, x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.6e+25], t$95$1, If[LessEqual[z, 10200000000000.0], N[(N[(z / t), $MachinePrecision] * 2.0 + x), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x - \frac{y}{z}\\
\mathbf{if}\;z \leq -1.6 \cdot 10^{+25}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 10200000000000:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, 2, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -1.6e25 or 1.02e13 < z Initial program 66.8%
Taylor expanded in y around 0
mul-1-negN/A
sub-negN/A
--lowering--.f64N/A
/-lowering-/.f6489.8
Simplified89.8%
if -1.6e25 < z < 1.02e13Initial program 93.9%
Taylor expanded in y around inf
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
associate-*r/N/A
*-commutativeN/A
associate-*r/N/A
metadata-evalN/A
associate-*r/N/A
accelerator-lowering-fma.f64N/A
associate-*r/N/A
metadata-evalN/A
/-lowering-/.f6485.1
Simplified85.1%
clear-numN/A
metadata-evalN/A
associate-*r/N/A
div-invN/A
times-fracN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6485.2
Applied egg-rr85.2%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (- x (/ y z)))) (if (<= z -1.85e+28) t_1 (if (<= z 5.8e+24) (fma z (/ 2.0 t) x) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = x - (y / z);
double tmp;
if (z <= -1.85e+28) {
tmp = t_1;
} else if (z <= 5.8e+24) {
tmp = fma(z, (2.0 / t), x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(x - Float64(y / z)) tmp = 0.0 if (z <= -1.85e+28) tmp = t_1; elseif (z <= 5.8e+24) tmp = fma(z, Float64(2.0 / t), x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.85e+28], t$95$1, If[LessEqual[z, 5.8e+24], N[(z * N[(2.0 / t), $MachinePrecision] + x), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x - \frac{y}{z}\\
\mathbf{if}\;z \leq -1.85 \cdot 10^{+28}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 5.8 \cdot 10^{+24}:\\
\;\;\;\;\mathsf{fma}\left(z, \frac{2}{t}, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -1.85e28 or 5.79999999999999958e24 < z Initial program 66.8%
Taylor expanded in y around 0
mul-1-negN/A
sub-negN/A
--lowering--.f64N/A
/-lowering-/.f6489.8
Simplified89.8%
if -1.85e28 < z < 5.79999999999999958e24Initial program 93.9%
Taylor expanded in y around inf
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
associate-*r/N/A
*-commutativeN/A
associate-*r/N/A
metadata-evalN/A
associate-*r/N/A
accelerator-lowering-fma.f64N/A
associate-*r/N/A
metadata-evalN/A
/-lowering-/.f6485.1
Simplified85.1%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (- x (/ y z)))) (if (<= z -210000.0) t_1 (if (<= z 1.7e-61) x t_1))))
double code(double x, double y, double z, double t) {
double t_1 = x - (y / z);
double tmp;
if (z <= -210000.0) {
tmp = t_1;
} else if (z <= 1.7e-61) {
tmp = x;
} else {
tmp = t_1;
}
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) :: t_1
real(8) :: tmp
t_1 = x - (y / z)
if (z <= (-210000.0d0)) then
tmp = t_1
else if (z <= 1.7d-61) then
tmp = x
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = x - (y / z);
double tmp;
if (z <= -210000.0) {
tmp = t_1;
} else if (z <= 1.7e-61) {
tmp = x;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = x - (y / z) tmp = 0 if z <= -210000.0: tmp = t_1 elif z <= 1.7e-61: tmp = x else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(x - Float64(y / z)) tmp = 0.0 if (z <= -210000.0) tmp = t_1; elseif (z <= 1.7e-61) tmp = x; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = x - (y / z); tmp = 0.0; if (z <= -210000.0) tmp = t_1; elseif (z <= 1.7e-61) tmp = x; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -210000.0], t$95$1, If[LessEqual[z, 1.7e-61], x, t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x - \frac{y}{z}\\
\mathbf{if}\;z \leq -210000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 1.7 \cdot 10^{-61}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -2.1e5 or 1.6999999999999999e-61 < z Initial program 71.1%
Taylor expanded in y around 0
mul-1-negN/A
sub-negN/A
--lowering--.f64N/A
/-lowering-/.f6484.8
Simplified84.8%
if -2.1e5 < z < 1.6999999999999999e-61Initial program 92.6%
Taylor expanded in x around inf
Simplified73.6%
(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 79.0%
Taylor expanded in x around inf
Simplified69.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 2024195
(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)))))