
(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 (- x (/ (* y 2.0) (- (* 2.0 z) (/ (* y t) z)))))
double code(double x, double y, double z, double t) {
return x - ((y * 2.0) / ((2.0 * z) - ((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) / ((2.0d0 * z) - ((y * t) / z)))
end function
public static double code(double x, double y, double z, double t) {
return x - ((y * 2.0) / ((2.0 * z) - ((y * t) / z)));
}
def code(x, y, z, t): return x - ((y * 2.0) / ((2.0 * z) - ((y * t) / z)))
function code(x, y, z, t) return Float64(x - Float64(Float64(y * 2.0) / Float64(Float64(2.0 * z) - Float64(Float64(y * t) / z)))) end
function tmp = code(x, y, z, t) tmp = x - ((y * 2.0) / ((2.0 * z) - ((y * t) / z))); end
code[x_, y_, z_, t_] := N[(x - N[(N[(y * 2.0), $MachinePrecision] / N[(N[(2.0 * z), $MachinePrecision] - N[(N[(y * t), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \frac{y \cdot 2}{2 \cdot z - \frac{y \cdot t}{z}}
\end{array}
Initial program 81.4%
associate-/l*N/A
clear-numN/A
un-div-invN/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
--lowering--.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f6489.3%
Applied egg-rr89.3%
Taylor expanded in y around 0
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
--lowering--.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f6496.0%
Simplified96.0%
Final simplification96.0%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (- x (/ y z)))) (if (<= z -3.5e+91) t_1 (if (<= z 4.8e+49) (- x (/ (* z -2.0) t)) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = x - (y / z);
double tmp;
if (z <= -3.5e+91) {
tmp = t_1;
} else if (z <= 4.8e+49) {
tmp = x - ((z * -2.0) / t);
} 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 <= (-3.5d+91)) then
tmp = t_1
else if (z <= 4.8d+49) then
tmp = x - ((z * (-2.0d0)) / t)
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 <= -3.5e+91) {
tmp = t_1;
} else if (z <= 4.8e+49) {
tmp = x - ((z * -2.0) / t);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = x - (y / z) tmp = 0 if z <= -3.5e+91: tmp = t_1 elif z <= 4.8e+49: tmp = x - ((z * -2.0) / t) else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(x - Float64(y / z)) tmp = 0.0 if (z <= -3.5e+91) tmp = t_1; elseif (z <= 4.8e+49) tmp = Float64(x - Float64(Float64(z * -2.0) / t)); 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 <= -3.5e+91) tmp = t_1; elseif (z <= 4.8e+49) tmp = x - ((z * -2.0) / t); 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, -3.5e+91], t$95$1, If[LessEqual[z, 4.8e+49], N[(x - N[(N[(z * -2.0), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x - \frac{y}{z}\\
\mathbf{if}\;z \leq -3.5 \cdot 10^{+91}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 4.8 \cdot 10^{+49}:\\
\;\;\;\;x - \frac{z \cdot -2}{t}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -3.50000000000000001e91 or 4.8e49 < z Initial program 69.1%
Taylor expanded in y around 0
mul-1-negN/A
sub-negN/A
--lowering--.f64N/A
/-lowering-/.f6497.3%
Simplified97.3%
if -3.50000000000000001e91 < z < 4.8e49Initial program 89.7%
Taylor expanded in y around inf
associate-*r/N/A
/-lowering-/.f64N/A
*-lowering-*.f6487.1%
Simplified87.1%
Final simplification91.2%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (- x (/ y z)))) (if (<= z -3.5e+91) t_1 (if (<= z 4.8e+49) (- x (* z (/ -2.0 t))) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = x - (y / z);
double tmp;
if (z <= -3.5e+91) {
tmp = t_1;
} else if (z <= 4.8e+49) {
tmp = x - (z * (-2.0 / t));
} 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 <= (-3.5d+91)) then
tmp = t_1
else if (z <= 4.8d+49) then
tmp = x - (z * ((-2.0d0) / t))
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 <= -3.5e+91) {
tmp = t_1;
} else if (z <= 4.8e+49) {
tmp = x - (z * (-2.0 / t));
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = x - (y / z) tmp = 0 if z <= -3.5e+91: tmp = t_1 elif z <= 4.8e+49: tmp = x - (z * (-2.0 / t)) else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(x - Float64(y / z)) tmp = 0.0 if (z <= -3.5e+91) tmp = t_1; elseif (z <= 4.8e+49) tmp = Float64(x - Float64(z * Float64(-2.0 / t))); 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 <= -3.5e+91) tmp = t_1; elseif (z <= 4.8e+49) tmp = x - (z * (-2.0 / t)); 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, -3.5e+91], t$95$1, If[LessEqual[z, 4.8e+49], N[(x - N[(z * N[(-2.0 / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x - \frac{y}{z}\\
\mathbf{if}\;z \leq -3.5 \cdot 10^{+91}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 4.8 \cdot 10^{+49}:\\
\;\;\;\;x - z \cdot \frac{-2}{t}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -3.50000000000000001e91 or 4.8e49 < z Initial program 69.1%
Taylor expanded in y around 0
mul-1-negN/A
sub-negN/A
--lowering--.f64N/A
/-lowering-/.f6497.3%
Simplified97.3%
if -3.50000000000000001e91 < z < 4.8e49Initial program 89.7%
Taylor expanded in y around inf
associate-*r/N/A
/-lowering-/.f64N/A
*-lowering-*.f6487.1%
Simplified87.1%
*-commutativeN/A
associate-/l*N/A
*-lowering-*.f64N/A
/-lowering-/.f6487.0%
Applied egg-rr87.0%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (- x (/ y z)))) (if (<= z -6.5e+91) t_1 (if (<= z 3.1e+45) x t_1))))
double code(double x, double y, double z, double t) {
double t_1 = x - (y / z);
double tmp;
if (z <= -6.5e+91) {
tmp = t_1;
} else if (z <= 3.1e+45) {
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 <= (-6.5d+91)) then
tmp = t_1
else if (z <= 3.1d+45) 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 <= -6.5e+91) {
tmp = t_1;
} else if (z <= 3.1e+45) {
tmp = x;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = x - (y / z) tmp = 0 if z <= -6.5e+91: tmp = t_1 elif z <= 3.1e+45: 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 <= -6.5e+91) tmp = t_1; elseif (z <= 3.1e+45) 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 <= -6.5e+91) tmp = t_1; elseif (z <= 3.1e+45) 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, -6.5e+91], t$95$1, If[LessEqual[z, 3.1e+45], x, t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x - \frac{y}{z}\\
\mathbf{if}\;z \leq -6.5 \cdot 10^{+91}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 3.1 \cdot 10^{+45}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -6.4999999999999997e91 or 3.09999999999999988e45 < z Initial program 69.1%
Taylor expanded in y around 0
mul-1-negN/A
sub-negN/A
--lowering--.f64N/A
/-lowering-/.f6497.3%
Simplified97.3%
if -6.4999999999999997e91 < z < 3.09999999999999988e45Initial program 89.7%
Taylor expanded in x around inf
Simplified75.8%
(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.4%
Taylor expanded in x around inf
Simplified76.6%
(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 2024161
(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)))))