
(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) (- (* t (/ y z)) (* z 2.0)))))
double code(double x, double y, double z, double t) {
return x + ((y * 2.0) / ((t * (y / z)) - (z * 2.0)));
}
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) / ((t * (y / z)) - (z * 2.0d0)))
end function
public static double code(double x, double y, double z, double t) {
return x + ((y * 2.0) / ((t * (y / z)) - (z * 2.0)));
}
def code(x, y, z, t): return x + ((y * 2.0) / ((t * (y / z)) - (z * 2.0)))
function code(x, y, z, t) return Float64(x + Float64(Float64(y * 2.0) / Float64(Float64(t * Float64(y / z)) - Float64(z * 2.0)))) end
function tmp = code(x, y, z, t) tmp = x + ((y * 2.0) / ((t * (y / z)) - (z * 2.0))); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y * 2.0), $MachinePrecision] / N[(N[(t * N[(y / z), $MachinePrecision]), $MachinePrecision] - N[(z * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y \cdot 2}{t \cdot \frac{y}{z} - z \cdot 2}
\end{array}
Initial program 85.3%
Simplified92.3%
clear-num92.3%
un-div-inv92.4%
*-commutative92.4%
*-commutative92.4%
associate-*l*92.4%
pow292.4%
Applied egg-rr92.4%
Taylor expanded in y around 0 96.9%
+-commutative96.9%
mul-1-neg96.9%
*-commutative96.9%
associate-*r/98.8%
unsub-neg98.8%
*-commutative98.8%
associate-*r/96.9%
*-commutative96.9%
associate-/l*97.3%
Simplified97.3%
Final simplification97.3%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- x (/ y z))) (t_2 (- x (/ (* z -2.0) t))))
(if (<= z -1e+18)
t_1
(if (<= z 5.3e-77)
t_2
(if (<= z 2.8e+31) x (if (<= z 1.05e+60) t_2 t_1))))))
double code(double x, double y, double z, double t) {
double t_1 = x - (y / z);
double t_2 = x - ((z * -2.0) / t);
double tmp;
if (z <= -1e+18) {
tmp = t_1;
} else if (z <= 5.3e-77) {
tmp = t_2;
} else if (z <= 2.8e+31) {
tmp = x;
} else if (z <= 1.05e+60) {
tmp = t_2;
} 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) :: t_2
real(8) :: tmp
t_1 = x - (y / z)
t_2 = x - ((z * (-2.0d0)) / t)
if (z <= (-1d+18)) then
tmp = t_1
else if (z <= 5.3d-77) then
tmp = t_2
else if (z <= 2.8d+31) then
tmp = x
else if (z <= 1.05d+60) then
tmp = t_2
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 t_2 = x - ((z * -2.0) / t);
double tmp;
if (z <= -1e+18) {
tmp = t_1;
} else if (z <= 5.3e-77) {
tmp = t_2;
} else if (z <= 2.8e+31) {
tmp = x;
} else if (z <= 1.05e+60) {
tmp = t_2;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = x - (y / z) t_2 = x - ((z * -2.0) / t) tmp = 0 if z <= -1e+18: tmp = t_1 elif z <= 5.3e-77: tmp = t_2 elif z <= 2.8e+31: tmp = x elif z <= 1.05e+60: tmp = t_2 else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(x - Float64(y / z)) t_2 = Float64(x - Float64(Float64(z * -2.0) / t)) tmp = 0.0 if (z <= -1e+18) tmp = t_1; elseif (z <= 5.3e-77) tmp = t_2; elseif (z <= 2.8e+31) tmp = x; elseif (z <= 1.05e+60) tmp = t_2; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = x - (y / z); t_2 = x - ((z * -2.0) / t); tmp = 0.0; if (z <= -1e+18) tmp = t_1; elseif (z <= 5.3e-77) tmp = t_2; elseif (z <= 2.8e+31) tmp = x; elseif (z <= 1.05e+60) tmp = t_2; 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]}, Block[{t$95$2 = N[(x - N[(N[(z * -2.0), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1e+18], t$95$1, If[LessEqual[z, 5.3e-77], t$95$2, If[LessEqual[z, 2.8e+31], x, If[LessEqual[z, 1.05e+60], t$95$2, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x - \frac{y}{z}\\
t_2 := x - \frac{z \cdot -2}{t}\\
\mathbf{if}\;z \leq -1 \cdot 10^{+18}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 5.3 \cdot 10^{-77}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;z \leq 2.8 \cdot 10^{+31}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.05 \cdot 10^{+60}:\\
\;\;\;\;t\_2\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -1e18 or 1.0500000000000001e60 < z Initial program 74.1%
Simplified89.1%
Taylor expanded in y around 0 93.1%
if -1e18 < z < 5.30000000000000015e-77 or 2.80000000000000017e31 < z < 1.0500000000000001e60Initial program 92.9%
Simplified93.7%
Taylor expanded in y around inf 93.4%
associate-*r/93.4%
*-commutative93.4%
Simplified93.4%
if 5.30000000000000015e-77 < z < 2.80000000000000017e31Initial program 96.0%
Simplified99.9%
Taylor expanded in x around inf 87.5%
(FPCore (x y z t) :precision binary64 (if (or (<= z -8.5e+21) (not (<= z 4.3e+60))) (- x (/ y z)) x))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -8.5e+21) || !(z <= 4.3e+60)) {
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 <= (-8.5d+21)) .or. (.not. (z <= 4.3d+60))) 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 <= -8.5e+21) || !(z <= 4.3e+60)) {
tmp = x - (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -8.5e+21) or not (z <= 4.3e+60): tmp = x - (y / z) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -8.5e+21) || !(z <= 4.3e+60)) 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 <= -8.5e+21) || ~((z <= 4.3e+60))) tmp = x - (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -8.5e+21], N[Not[LessEqual[z, 4.3e+60]], $MachinePrecision]], N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.5 \cdot 10^{+21} \lor \neg \left(z \leq 4.3 \cdot 10^{+60}\right):\\
\;\;\;\;x - \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -8.5e21 or 4.29999999999999971e60 < z Initial program 73.6%
Simplified88.9%
Taylor expanded in y around 0 93.9%
if -8.5e21 < z < 4.29999999999999971e60Initial program 93.5%
Simplified94.8%
Taylor expanded in x around inf 79.5%
Final simplification85.4%
(FPCore (x y z t) :precision binary64 (+ x (* y (/ 2.0 (- (/ (* y t) z) (* z 2.0))))))
double code(double x, double y, double z, double t) {
return x + (y * (2.0 / (((y * t) / z) - (z * 2.0))));
}
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) - (z * 2.0d0))))
end function
public static double code(double x, double y, double z, double t) {
return x + (y * (2.0 / (((y * t) / z) - (z * 2.0))));
}
def code(x, y, z, t): return x + (y * (2.0 / (((y * t) / z) - (z * 2.0))))
function code(x, y, z, t) return Float64(x + Float64(y * Float64(2.0 / Float64(Float64(Float64(y * t) / z) - Float64(z * 2.0))))) end
function tmp = code(x, y, z, t) tmp = x + (y * (2.0 / (((y * t) / z) - (z * 2.0)))); end
code[x_, y_, z_, t_] := N[(x + N[(y * N[(2.0 / N[(N[(N[(y * t), $MachinePrecision] / z), $MachinePrecision] - N[(z * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \frac{2}{\frac{y \cdot t}{z} - z \cdot 2}
\end{array}
Initial program 85.3%
Simplified92.3%
clear-num92.3%
un-div-inv92.4%
*-commutative92.4%
*-commutative92.4%
associate-*l*92.4%
pow292.4%
Applied egg-rr92.4%
Taylor expanded in y around 0 96.9%
+-commutative96.9%
mul-1-neg96.9%
*-commutative96.9%
associate-*r/98.8%
unsub-neg98.8%
*-commutative98.8%
associate-*r/96.9%
*-commutative96.9%
associate-/l*97.3%
Simplified97.3%
associate-/l*97.3%
*-commutative97.3%
fma-neg97.3%
*-commutative97.3%
distribute-rgt-neg-in97.3%
Applied egg-rr97.3%
associate-*r/97.3%
*-commutative97.3%
associate-*r/97.2%
fma-define97.2%
*-commutative97.2%
cancel-sign-sub-inv97.2%
*-commutative97.2%
associate-*r/96.9%
*-commutative96.9%
Simplified96.9%
Final simplification96.9%
(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 85.3%
Simplified92.3%
Taylor expanded in x around inf 80.3%
(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 2024096
(FPCore (x y z t)
:name "Numeric.AD.Rank1.Halley:findZero from ad-4.2.4"
:precision binary64
:alt
(- x (/ 1.0 (- (/ z y) (/ (/ t 2.0) z))))
(- x (/ (* (* y 2.0) z) (- (* (* z 2.0) z) (* y t)))))