
(FPCore (x y) :precision binary64 (- x (/ y (+ 1.0 (/ (* x y) 2.0)))))
double code(double x, double y) {
return x - (y / (1.0 + ((x * y) / 2.0)));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x - (y / (1.0d0 + ((x * y) / 2.0d0)))
end function
public static double code(double x, double y) {
return x - (y / (1.0 + ((x * y) / 2.0)));
}
def code(x, y): return x - (y / (1.0 + ((x * y) / 2.0)))
function code(x, y) return Float64(x - Float64(y / Float64(1.0 + Float64(Float64(x * y) / 2.0)))) end
function tmp = code(x, y) tmp = x - (y / (1.0 + ((x * y) / 2.0))); end
code[x_, y_] := N[(x - N[(y / N[(1.0 + N[(N[(x * y), $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \frac{y}{1 + \frac{x \cdot y}{2}}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (- x (/ y (+ 1.0 (/ (* x y) 2.0)))))
double code(double x, double y) {
return x - (y / (1.0 + ((x * y) / 2.0)));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x - (y / (1.0d0 + ((x * y) / 2.0d0)))
end function
public static double code(double x, double y) {
return x - (y / (1.0 + ((x * y) / 2.0)));
}
def code(x, y): return x - (y / (1.0 + ((x * y) / 2.0)))
function code(x, y) return Float64(x - Float64(y / Float64(1.0 + Float64(Float64(x * y) / 2.0)))) end
function tmp = code(x, y) tmp = x - (y / (1.0 + ((x * y) / 2.0))); end
code[x_, y_] := N[(x - N[(y / N[(1.0 + N[(N[(x * y), $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \frac{y}{1 + \frac{x \cdot y}{2}}
\end{array}
(FPCore (x y) :precision binary64 (- x (/ y (+ 1.0 (/ y (/ 2.0 x))))))
double code(double x, double y) {
return x - (y / (1.0 + (y / (2.0 / x))));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x - (y / (1.0d0 + (y / (2.0d0 / x))))
end function
public static double code(double x, double y) {
return x - (y / (1.0 + (y / (2.0 / x))));
}
def code(x, y): return x - (y / (1.0 + (y / (2.0 / x))))
function code(x, y) return Float64(x - Float64(y / Float64(1.0 + Float64(y / Float64(2.0 / x))))) end
function tmp = code(x, y) tmp = x - (y / (1.0 + (y / (2.0 / x)))); end
code[x_, y_] := N[(x - N[(y / N[(1.0 + N[(y / N[(2.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \frac{y}{1 + \frac{y}{\frac{2}{x}}}
\end{array}
Initial program 99.8%
*-commutative99.8%
associate-/l*99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y) :precision binary64 (if (<= x -6e-8) x (if (<= x -3.1e-18) (/ -2.0 x) (if (<= x 1.58e-12) (- x y) x))))
double code(double x, double y) {
double tmp;
if (x <= -6e-8) {
tmp = x;
} else if (x <= -3.1e-18) {
tmp = -2.0 / x;
} else if (x <= 1.58e-12) {
tmp = x - y;
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-6d-8)) then
tmp = x
else if (x <= (-3.1d-18)) then
tmp = (-2.0d0) / x
else if (x <= 1.58d-12) then
tmp = x - y
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -6e-8) {
tmp = x;
} else if (x <= -3.1e-18) {
tmp = -2.0 / x;
} else if (x <= 1.58e-12) {
tmp = x - y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -6e-8: tmp = x elif x <= -3.1e-18: tmp = -2.0 / x elif x <= 1.58e-12: tmp = x - y else: tmp = x return tmp
function code(x, y) tmp = 0.0 if (x <= -6e-8) tmp = x; elseif (x <= -3.1e-18) tmp = Float64(-2.0 / x); elseif (x <= 1.58e-12) tmp = Float64(x - y); else tmp = x; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -6e-8) tmp = x; elseif (x <= -3.1e-18) tmp = -2.0 / x; elseif (x <= 1.58e-12) tmp = x - y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -6e-8], x, If[LessEqual[x, -3.1e-18], N[(-2.0 / x), $MachinePrecision], If[LessEqual[x, 1.58e-12], N[(x - y), $MachinePrecision], x]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6 \cdot 10^{-8}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq -3.1 \cdot 10^{-18}:\\
\;\;\;\;\frac{-2}{x}\\
\mathbf{elif}\;x \leq 1.58 \cdot 10^{-12}:\\
\;\;\;\;x - y\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -5.99999999999999946e-8 or 1.57999999999999993e-12 < x Initial program 99.8%
*-commutative99.8%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in x around inf 98.8%
if -5.99999999999999946e-8 < x < -3.10000000000000007e-18Initial program 99.6%
*-commutative99.6%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in y around inf 79.1%
Taylor expanded in x around 0 78.7%
if -3.10000000000000007e-18 < x < 1.57999999999999993e-12Initial program 99.9%
*-commutative99.9%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in y around 0 81.1%
Final simplification90.9%
(FPCore (x y) :precision binary64 (if (or (<= y -1.9e+70) (not (<= y 5.1e+104))) (- x (/ 2.0 x)) (- x y)))
double code(double x, double y) {
double tmp;
if ((y <= -1.9e+70) || !(y <= 5.1e+104)) {
tmp = x - (2.0 / x);
} else {
tmp = x - y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-1.9d+70)) .or. (.not. (y <= 5.1d+104))) then
tmp = x - (2.0d0 / x)
else
tmp = x - y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.9e+70) || !(y <= 5.1e+104)) {
tmp = x - (2.0 / x);
} else {
tmp = x - y;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.9e+70) or not (y <= 5.1e+104): tmp = x - (2.0 / x) else: tmp = x - y return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.9e+70) || !(y <= 5.1e+104)) tmp = Float64(x - Float64(2.0 / x)); else tmp = Float64(x - y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.9e+70) || ~((y <= 5.1e+104))) tmp = x - (2.0 / x); else tmp = x - y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.9e+70], N[Not[LessEqual[y, 5.1e+104]], $MachinePrecision]], N[(x - N[(2.0 / x), $MachinePrecision]), $MachinePrecision], N[(x - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.9 \cdot 10^{+70} \lor \neg \left(y \leq 5.1 \cdot 10^{+104}\right):\\
\;\;\;\;x - \frac{2}{x}\\
\mathbf{else}:\\
\;\;\;\;x - y\\
\end{array}
\end{array}
if y < -1.8999999999999999e70 or 5.1000000000000002e104 < y Initial program 99.5%
*-commutative99.5%
associate-/l*99.6%
Simplified99.6%
Taylor expanded in y around inf 83.7%
if -1.8999999999999999e70 < y < 5.1000000000000002e104Initial program 100.0%
*-commutative100.0%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in y around 0 96.9%
Final simplification92.1%
(FPCore (x y) :precision binary64 (if (<= x -1.4e-8) x (if (<= x 1.58e-12) (- x y) x)))
double code(double x, double y) {
double tmp;
if (x <= -1.4e-8) {
tmp = x;
} else if (x <= 1.58e-12) {
tmp = x - y;
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-1.4d-8)) then
tmp = x
else if (x <= 1.58d-12) then
tmp = x - y
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.4e-8) {
tmp = x;
} else if (x <= 1.58e-12) {
tmp = x - y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.4e-8: tmp = x elif x <= 1.58e-12: tmp = x - y else: tmp = x return tmp
function code(x, y) tmp = 0.0 if (x <= -1.4e-8) tmp = x; elseif (x <= 1.58e-12) tmp = Float64(x - y); else tmp = x; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.4e-8) tmp = x; elseif (x <= 1.58e-12) tmp = x - y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.4e-8], x, If[LessEqual[x, 1.58e-12], N[(x - y), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.4 \cdot 10^{-8}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1.58 \cdot 10^{-12}:\\
\;\;\;\;x - y\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -1.4e-8 or 1.57999999999999993e-12 < x Initial program 99.8%
*-commutative99.8%
associate-/l*99.7%
Simplified99.7%
Taylor expanded in x around inf 97.4%
if -1.4e-8 < x < 1.57999999999999993e-12Initial program 99.9%
*-commutative99.9%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in y around 0 78.5%
Final simplification89.2%
(FPCore (x y) :precision binary64 (if (<= x -7.8e-134) x (if (<= x 2e-113) (- y) x)))
double code(double x, double y) {
double tmp;
if (x <= -7.8e-134) {
tmp = x;
} else if (x <= 2e-113) {
tmp = -y;
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-7.8d-134)) then
tmp = x
else if (x <= 2d-113) then
tmp = -y
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -7.8e-134) {
tmp = x;
} else if (x <= 2e-113) {
tmp = -y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -7.8e-134: tmp = x elif x <= 2e-113: tmp = -y else: tmp = x return tmp
function code(x, y) tmp = 0.0 if (x <= -7.8e-134) tmp = x; elseif (x <= 2e-113) tmp = Float64(-y); else tmp = x; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -7.8e-134) tmp = x; elseif (x <= 2e-113) tmp = -y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -7.8e-134], x, If[LessEqual[x, 2e-113], (-y), x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.8 \cdot 10^{-134}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 2 \cdot 10^{-113}:\\
\;\;\;\;-y\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -7.8000000000000002e-134 or 1.99999999999999996e-113 < x Initial program 99.8%
*-commutative99.8%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in x around inf 84.7%
if -7.8000000000000002e-134 < x < 1.99999999999999996e-113Initial program 100.0%
*-commutative100.0%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in x around 0 80.5%
neg-mul-180.5%
Simplified80.5%
Final simplification83.6%
(FPCore (x y) :precision binary64 x)
double code(double x, double y) {
return x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x
end function
public static double code(double x, double y) {
return x;
}
def code(x, y): return x
function code(x, y) return x end
function tmp = code(x, y) tmp = x; end
code[x_, y_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 99.8%
*-commutative99.8%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in x around inf 64.9%
Final simplification64.9%
herbie shell --seed 2023279
(FPCore (x y)
:name "Data.Number.Erf:$cinvnormcdf from erf-2.0.0.0, B"
:precision binary64
(- x (/ y (+ 1.0 (/ (* x y) 2.0)))))