
(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) (* y (- (/ t z) (/ (* 2.0 z) y))))))
double code(double x, double y, double z, double t) {
return x + ((y * 2.0) / (y * ((t / z) - ((2.0 * z) / y))));
}
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) / (y * ((t / z) - ((2.0d0 * z) / y))))
end function
public static double code(double x, double y, double z, double t) {
return x + ((y * 2.0) / (y * ((t / z) - ((2.0 * z) / y))));
}
def code(x, y, z, t): return x + ((y * 2.0) / (y * ((t / z) - ((2.0 * z) / y))))
function code(x, y, z, t) return Float64(x + Float64(Float64(y * 2.0) / Float64(y * Float64(Float64(t / z) - Float64(Float64(2.0 * z) / y))))) end
function tmp = code(x, y, z, t) tmp = x + ((y * 2.0) / (y * ((t / z) - ((2.0 * z) / y)))); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y * 2.0), $MachinePrecision] / N[(y * N[(N[(t / z), $MachinePrecision] - N[(N[(2.0 * z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y \cdot 2}{y \cdot \left(\frac{t}{z} - \frac{2 \cdot z}{y}\right)}
\end{array}
Initial program 80.6%
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
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6488.0%
Applied egg-rr88.0%
Taylor expanded in y around inf
+-commutativeN/A
associate-*r/N/A
metadata-evalN/A
distribute-lft-neg-inN/A
distribute-frac-negN/A
associate-*r/N/A
mul-1-negN/A
distribute-neg-inN/A
*-lowering-*.f64N/A
distribute-neg-inN/A
associate-*r/N/A
distribute-frac-negN/A
distribute-lft-neg-inN/A
metadata-evalN/A
associate-*r/N/A
unsub-negN/A
--lowering--.f64N/A
associate-*r/N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
/-lowering-/.f6497.7%
Simplified97.7%
Final simplification97.7%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- x (/ y z))))
(if (<= z -8500000000.0)
t_1
(if (<= z 1.8e-6) (- 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 <= -8500000000.0) {
tmp = t_1;
} else if (z <= 1.8e-6) {
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 <= (-8500000000.0d0)) then
tmp = t_1
else if (z <= 1.8d-6) 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 <= -8500000000.0) {
tmp = t_1;
} else if (z <= 1.8e-6) {
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 <= -8500000000.0: tmp = t_1 elif z <= 1.8e-6: 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 <= -8500000000.0) tmp = t_1; elseif (z <= 1.8e-6) 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 <= -8500000000.0) tmp = t_1; elseif (z <= 1.8e-6) 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, -8500000000.0], t$95$1, If[LessEqual[z, 1.8e-6], 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 -8500000000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 1.8 \cdot 10^{-6}:\\
\;\;\;\;x - \frac{z \cdot -2}{t}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -8.5e9 or 1.79999999999999992e-6 < z Initial program 71.8%
Taylor expanded in y around 0
mul-1-negN/A
sub-negN/A
--lowering--.f64N/A
/-lowering-/.f6493.4%
Simplified93.4%
if -8.5e9 < z < 1.79999999999999992e-6Initial program 90.7%
Taylor expanded in y around inf
--lowering--.f64N/A
associate-*r/N/A
/-lowering-/.f64N/A
*-lowering-*.f6494.3%
Simplified94.3%
Final simplification93.8%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (- x (/ y z)))) (if (<= z -1700000000000.0) t_1 (if (<= z 7e-40) x t_1))))
double code(double x, double y, double z, double t) {
double t_1 = x - (y / z);
double tmp;
if (z <= -1700000000000.0) {
tmp = t_1;
} else if (z <= 7e-40) {
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 <= (-1700000000000.0d0)) then
tmp = t_1
else if (z <= 7d-40) 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 <= -1700000000000.0) {
tmp = t_1;
} else if (z <= 7e-40) {
tmp = x;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = x - (y / z) tmp = 0 if z <= -1700000000000.0: tmp = t_1 elif z <= 7e-40: 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 <= -1700000000000.0) tmp = t_1; elseif (z <= 7e-40) 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 <= -1700000000000.0) tmp = t_1; elseif (z <= 7e-40) 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, -1700000000000.0], t$95$1, If[LessEqual[z, 7e-40], x, t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x - \frac{y}{z}\\
\mathbf{if}\;z \leq -1700000000000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 7 \cdot 10^{-40}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -1.7e12 or 7.0000000000000003e-40 < z Initial program 73.2%
Taylor expanded in y around 0
mul-1-negN/A
sub-negN/A
--lowering--.f64N/A
/-lowering-/.f6491.7%
Simplified91.7%
if -1.7e12 < z < 7.0000000000000003e-40Initial program 90.2%
Taylor expanded in x around inf
Simplified78.1%
(FPCore (x y z t) :precision binary64 (+ x (/ (* y 2.0) (- (/ (* y t) z) (* 2.0 z)))))
double code(double x, double y, double z, double t) {
return x + ((y * 2.0) / (((y * t) / z) - (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 + ((y * 2.0d0) / (((y * t) / z) - (2.0d0 * z)))
end function
public static double code(double x, double y, double z, double t) {
return x + ((y * 2.0) / (((y * t) / z) - (2.0 * z)));
}
def code(x, y, z, t): return x + ((y * 2.0) / (((y * t) / z) - (2.0 * z)))
function code(x, y, z, t) return Float64(x + Float64(Float64(y * 2.0) / Float64(Float64(Float64(y * t) / z) - Float64(2.0 * z)))) end
function tmp = code(x, y, z, t) tmp = x + ((y * 2.0) / (((y * t) / z) - (2.0 * z))); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y * 2.0), $MachinePrecision] / N[(N[(N[(y * t), $MachinePrecision] / z), $MachinePrecision] - N[(2.0 * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y \cdot 2}{\frac{y \cdot t}{z} - 2 \cdot z}
\end{array}
Initial program 80.6%
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
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6488.0%
Applied egg-rr88.0%
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
*-commutativeN/A
*-lowering-*.f6495.2%
Simplified95.2%
Final simplification95.2%
(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 80.6%
Taylor expanded in x around inf
Simplified75.2%
(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 2024150
(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)))))