
(FPCore (x) :precision binary64 (- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))
double code(double x) {
return (1.0 / (x + 1.0)) - (1.0 / (x - 1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / (x + 1.0d0)) - (1.0d0 / (x - 1.0d0))
end function
public static double code(double x) {
return (1.0 / (x + 1.0)) - (1.0 / (x - 1.0));
}
def code(x): return (1.0 / (x + 1.0)) - (1.0 / (x - 1.0))
function code(x) return Float64(Float64(1.0 / Float64(x + 1.0)) - Float64(1.0 / Float64(x - 1.0))) end
function tmp = code(x) tmp = (1.0 / (x + 1.0)) - (1.0 / (x - 1.0)); end
code[x_] := N[(N[(1.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(1.0 / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x + 1} - \frac{1}{x - 1}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))
double code(double x) {
return (1.0 / (x + 1.0)) - (1.0 / (x - 1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / (x + 1.0d0)) - (1.0d0 / (x - 1.0d0))
end function
public static double code(double x) {
return (1.0 / (x + 1.0)) - (1.0 / (x - 1.0));
}
def code(x): return (1.0 / (x + 1.0)) - (1.0 / (x - 1.0))
function code(x) return Float64(Float64(1.0 / Float64(x + 1.0)) - Float64(1.0 / Float64(x - 1.0))) end
function tmp = code(x) tmp = (1.0 / (x + 1.0)) - (1.0 / (x - 1.0)); end
code[x_] := N[(N[(1.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(1.0 / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x + 1} - \frac{1}{x - 1}
\end{array}
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (/ (/ -2.0 (- 1.0 x_m)) (- -1.0 x_m)))
x_m = fabs(x);
double code(double x_m) {
return (-2.0 / (1.0 - x_m)) / (-1.0 - x_m);
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = ((-2.0d0) / (1.0d0 - x_m)) / ((-1.0d0) - x_m)
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return (-2.0 / (1.0 - x_m)) / (-1.0 - x_m);
}
x_m = math.fabs(x) def code(x_m): return (-2.0 / (1.0 - x_m)) / (-1.0 - x_m)
x_m = abs(x) function code(x_m) return Float64(Float64(-2.0 / Float64(1.0 - x_m)) / Float64(-1.0 - x_m)) end
x_m = abs(x); function tmp = code(x_m) tmp = (-2.0 / (1.0 - x_m)) / (-1.0 - x_m); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(N[(-2.0 / N[(1.0 - x$95$m), $MachinePrecision]), $MachinePrecision] / N[(-1.0 - x$95$m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
\frac{\frac{-2}{1 - x\_m}}{-1 - x\_m}
\end{array}
Initial program 79.9%
sub-neg79.9%
+-commutative79.9%
distribute-neg-frac279.9%
neg-sub079.9%
associate-+l-79.9%
neg-sub079.9%
remove-double-neg79.9%
distribute-neg-in79.9%
sub-neg79.9%
distribute-neg-frac279.9%
sub-neg79.9%
+-commutative79.9%
unsub-neg79.9%
sub-neg79.9%
+-commutative79.9%
unsub-neg79.9%
metadata-eval79.9%
Simplified79.9%
frac-sub81.0%
*-rgt-identity81.0%
metadata-eval81.0%
div-inv81.0%
associate-/r*81.0%
metadata-eval81.0%
div-inv81.0%
*-un-lft-identity81.0%
associate--l-83.5%
div-inv83.5%
metadata-eval83.5%
*-rgt-identity83.5%
div-inv83.5%
metadata-eval83.5%
*-rgt-identity83.5%
Applied egg-rr83.5%
div-sub83.5%
sub-neg83.5%
frac-2neg83.5%
metadata-eval83.5%
flip--83.4%
metadata-eval83.4%
metadata-eval83.4%
+-commutative83.4%
distribute-neg-frac283.4%
mul-1-neg83.4%
+-commutative83.4%
distribute-lft-in83.4%
metadata-eval83.4%
neg-mul-183.4%
sub-neg83.4%
flip-+83.5%
+-commutative83.5%
Applied egg-rr83.5%
sub-neg83.5%
+-commutative83.5%
associate--r-99.9%
+-inverses99.9%
metadata-eval99.9%
*-rgt-identity99.9%
+-commutative99.9%
metadata-eval99.9%
associate--r-99.9%
neg-sub099.9%
distribute-frac-neg299.9%
distribute-neg-frac99.9%
metadata-eval99.9%
*-rgt-identity99.9%
metadata-eval99.9%
+-inverses99.9%
associate--r-83.5%
+-commutative83.5%
Simplified99.9%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= x_m 1.0) 2.0 (/ (/ 2.0 x_m) (- x_m))))
x_m = fabs(x);
double code(double x_m) {
double tmp;
if (x_m <= 1.0) {
tmp = 2.0;
} else {
tmp = (2.0 / x_m) / -x_m;
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
real(8) :: tmp
if (x_m <= 1.0d0) then
tmp = 2.0d0
else
tmp = (2.0d0 / x_m) / -x_m
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
double tmp;
if (x_m <= 1.0) {
tmp = 2.0;
} else {
tmp = (2.0 / x_m) / -x_m;
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if x_m <= 1.0: tmp = 2.0 else: tmp = (2.0 / x_m) / -x_m return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (x_m <= 1.0) tmp = 2.0; else tmp = Float64(Float64(2.0 / x_m) / Float64(-x_m)); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m) tmp = 0.0; if (x_m <= 1.0) tmp = 2.0; else tmp = (2.0 / x_m) / -x_m; end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[x$95$m, 1.0], 2.0, N[(N[(2.0 / x$95$m), $MachinePrecision] / (-x$95$m)), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 1:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{2}{x\_m}}{-x\_m}\\
\end{array}
\end{array}
if x < 1Initial program 89.1%
sub-neg89.1%
+-commutative89.1%
distribute-neg-frac289.1%
neg-sub089.1%
associate-+l-89.1%
neg-sub089.1%
remove-double-neg89.1%
distribute-neg-in89.1%
sub-neg89.1%
distribute-neg-frac289.1%
sub-neg89.1%
+-commutative89.1%
unsub-neg89.1%
sub-neg89.1%
+-commutative89.1%
unsub-neg89.1%
metadata-eval89.1%
Simplified89.1%
Taylor expanded in x around 0 72.7%
if 1 < x Initial program 53.0%
sub-neg53.0%
+-commutative53.0%
distribute-neg-frac253.0%
neg-sub053.0%
associate-+l-53.0%
neg-sub053.0%
remove-double-neg53.0%
distribute-neg-in53.0%
sub-neg53.0%
distribute-neg-frac253.0%
sub-neg53.0%
+-commutative53.0%
unsub-neg53.0%
sub-neg53.0%
+-commutative53.0%
unsub-neg53.0%
metadata-eval53.0%
Simplified53.0%
sub-neg53.0%
distribute-neg-frac53.0%
metadata-eval53.0%
Applied egg-rr53.0%
Simplified97.0%
Taylor expanded in x around inf 93.3%
div-inv93.3%
*-commutative93.3%
associate-/r*96.0%
Applied egg-rr96.0%
associate-/l/93.3%
associate-*r/93.3%
metadata-eval93.3%
metadata-eval93.3%
distribute-neg-frac93.3%
associate-/r*96.0%
distribute-neg-frac296.0%
+-commutative96.0%
distribute-neg-in96.0%
metadata-eval96.0%
sub-neg96.0%
Simplified96.0%
Taylor expanded in x around inf 96.9%
neg-mul-196.9%
Simplified96.9%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= x_m 1.0) 2.0 (/ -2.0 (+ 1.0 x_m))))
x_m = fabs(x);
double code(double x_m) {
double tmp;
if (x_m <= 1.0) {
tmp = 2.0;
} else {
tmp = -2.0 / (1.0 + x_m);
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
real(8) :: tmp
if (x_m <= 1.0d0) then
tmp = 2.0d0
else
tmp = (-2.0d0) / (1.0d0 + x_m)
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
double tmp;
if (x_m <= 1.0) {
tmp = 2.0;
} else {
tmp = -2.0 / (1.0 + x_m);
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if x_m <= 1.0: tmp = 2.0 else: tmp = -2.0 / (1.0 + x_m) return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (x_m <= 1.0) tmp = 2.0; else tmp = Float64(-2.0 / Float64(1.0 + x_m)); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m) tmp = 0.0; if (x_m <= 1.0) tmp = 2.0; else tmp = -2.0 / (1.0 + x_m); end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[x$95$m, 1.0], 2.0, N[(-2.0 / N[(1.0 + x$95$m), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 1:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;\frac{-2}{1 + x\_m}\\
\end{array}
\end{array}
if x < 1Initial program 89.1%
sub-neg89.1%
+-commutative89.1%
distribute-neg-frac289.1%
neg-sub089.1%
associate-+l-89.1%
neg-sub089.1%
remove-double-neg89.1%
distribute-neg-in89.1%
sub-neg89.1%
distribute-neg-frac289.1%
sub-neg89.1%
+-commutative89.1%
unsub-neg89.1%
sub-neg89.1%
+-commutative89.1%
unsub-neg89.1%
metadata-eval89.1%
Simplified89.1%
Taylor expanded in x around 0 72.7%
if 1 < x Initial program 53.0%
sub-neg53.0%
+-commutative53.0%
distribute-neg-frac253.0%
neg-sub053.0%
associate-+l-53.0%
neg-sub053.0%
remove-double-neg53.0%
distribute-neg-in53.0%
sub-neg53.0%
distribute-neg-frac253.0%
sub-neg53.0%
+-commutative53.0%
unsub-neg53.0%
sub-neg53.0%
+-commutative53.0%
unsub-neg53.0%
metadata-eval53.0%
Simplified53.0%
frac-sub55.2%
*-rgt-identity55.2%
metadata-eval55.2%
div-inv55.2%
associate-/r*55.3%
metadata-eval55.3%
div-inv55.3%
*-un-lft-identity55.3%
associate--l-61.1%
div-inv61.1%
metadata-eval61.1%
*-rgt-identity61.1%
div-inv61.1%
metadata-eval61.1%
*-rgt-identity61.1%
Applied egg-rr61.1%
Taylor expanded in x around 0 4.6%
add-sqr-sqrt4.6%
sqrt-unprod41.8%
frac-times46.4%
metadata-eval46.4%
metadata-eval46.4%
sub-neg46.4%
metadata-eval46.4%
distribute-neg-in46.4%
+-commutative46.4%
sub-neg46.4%
metadata-eval46.4%
distribute-neg-in46.4%
+-commutative46.4%
frac-times41.8%
metadata-eval41.8%
frac-2neg41.8%
metadata-eval41.8%
frac-2neg41.8%
sqrt-unprod0.0%
add-sqr-sqrt7.0%
div-inv7.0%
Applied egg-rr7.0%
exp-neg7.0%
log1p-undefine7.0%
rem-exp-log7.0%
associate-*r/7.0%
metadata-eval7.0%
+-commutative7.0%
Simplified7.0%
Final simplification56.0%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (/ (/ -2.0 (- -1.0 x_m)) (- 1.0 x_m)))
x_m = fabs(x);
double code(double x_m) {
return (-2.0 / (-1.0 - x_m)) / (1.0 - x_m);
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = ((-2.0d0) / ((-1.0d0) - x_m)) / (1.0d0 - x_m)
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return (-2.0 / (-1.0 - x_m)) / (1.0 - x_m);
}
x_m = math.fabs(x) def code(x_m): return (-2.0 / (-1.0 - x_m)) / (1.0 - x_m)
x_m = abs(x) function code(x_m) return Float64(Float64(-2.0 / Float64(-1.0 - x_m)) / Float64(1.0 - x_m)) end
x_m = abs(x); function tmp = code(x_m) tmp = (-2.0 / (-1.0 - x_m)) / (1.0 - x_m); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(N[(-2.0 / N[(-1.0 - x$95$m), $MachinePrecision]), $MachinePrecision] / N[(1.0 - x$95$m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
\frac{\frac{-2}{-1 - x\_m}}{1 - x\_m}
\end{array}
Initial program 79.9%
sub-neg79.9%
+-commutative79.9%
distribute-neg-frac279.9%
neg-sub079.9%
associate-+l-79.9%
neg-sub079.9%
remove-double-neg79.9%
distribute-neg-in79.9%
sub-neg79.9%
distribute-neg-frac279.9%
sub-neg79.9%
+-commutative79.9%
unsub-neg79.9%
sub-neg79.9%
+-commutative79.9%
unsub-neg79.9%
metadata-eval79.9%
Simplified79.9%
sub-neg79.9%
distribute-neg-frac79.9%
metadata-eval79.9%
Applied egg-rr79.9%
Simplified98.9%
associate-/r*99.9%
div-inv99.9%
Applied egg-rr99.9%
associate-*r/99.9%
frac-2neg99.9%
*-rgt-identity99.9%
frac-2neg99.9%
metadata-eval99.9%
+-commutative99.9%
distribute-neg-in99.9%
metadata-eval99.9%
sub-neg99.9%
distribute-frac-neg299.9%
metadata-eval99.9%
frac-2neg99.9%
+-commutative99.9%
distribute-neg-in99.9%
metadata-eval99.9%
sub-neg99.9%
Applied egg-rr99.9%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (/ -2.0 (* (+ 1.0 x_m) (+ x_m -1.0))))
x_m = fabs(x);
double code(double x_m) {
return -2.0 / ((1.0 + x_m) * (x_m + -1.0));
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = (-2.0d0) / ((1.0d0 + x_m) * (x_m + (-1.0d0)))
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return -2.0 / ((1.0 + x_m) * (x_m + -1.0));
}
x_m = math.fabs(x) def code(x_m): return -2.0 / ((1.0 + x_m) * (x_m + -1.0))
x_m = abs(x) function code(x_m) return Float64(-2.0 / Float64(Float64(1.0 + x_m) * Float64(x_m + -1.0))) end
x_m = abs(x); function tmp = code(x_m) tmp = -2.0 / ((1.0 + x_m) * (x_m + -1.0)); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(-2.0 / N[(N[(1.0 + x$95$m), $MachinePrecision] * N[(x$95$m + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
\frac{-2}{\left(1 + x\_m\right) \cdot \left(x\_m + -1\right)}
\end{array}
Initial program 79.9%
sub-neg79.9%
+-commutative79.9%
distribute-neg-frac279.9%
neg-sub079.9%
associate-+l-79.9%
neg-sub079.9%
remove-double-neg79.9%
distribute-neg-in79.9%
sub-neg79.9%
distribute-neg-frac279.9%
sub-neg79.9%
+-commutative79.9%
unsub-neg79.9%
sub-neg79.9%
+-commutative79.9%
unsub-neg79.9%
metadata-eval79.9%
Simplified79.9%
sub-neg79.9%
distribute-neg-frac79.9%
metadata-eval79.9%
Applied egg-rr79.9%
Simplified98.9%
Final simplification98.9%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= x_m 1.0) 2.0 (/ -2.0 x_m)))
x_m = fabs(x);
double code(double x_m) {
double tmp;
if (x_m <= 1.0) {
tmp = 2.0;
} else {
tmp = -2.0 / x_m;
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
real(8) :: tmp
if (x_m <= 1.0d0) then
tmp = 2.0d0
else
tmp = (-2.0d0) / x_m
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
double tmp;
if (x_m <= 1.0) {
tmp = 2.0;
} else {
tmp = -2.0 / x_m;
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if x_m <= 1.0: tmp = 2.0 else: tmp = -2.0 / x_m return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (x_m <= 1.0) tmp = 2.0; else tmp = Float64(-2.0 / x_m); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m) tmp = 0.0; if (x_m <= 1.0) tmp = 2.0; else tmp = -2.0 / x_m; end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[x$95$m, 1.0], 2.0, N[(-2.0 / x$95$m), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 1:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;\frac{-2}{x\_m}\\
\end{array}
\end{array}
if x < 1Initial program 89.1%
sub-neg89.1%
+-commutative89.1%
distribute-neg-frac289.1%
neg-sub089.1%
associate-+l-89.1%
neg-sub089.1%
remove-double-neg89.1%
distribute-neg-in89.1%
sub-neg89.1%
distribute-neg-frac289.1%
sub-neg89.1%
+-commutative89.1%
unsub-neg89.1%
sub-neg89.1%
+-commutative89.1%
unsub-neg89.1%
metadata-eval89.1%
Simplified89.1%
Taylor expanded in x around 0 72.7%
if 1 < x Initial program 53.0%
sub-neg53.0%
+-commutative53.0%
distribute-neg-frac253.0%
neg-sub053.0%
associate-+l-53.0%
neg-sub053.0%
remove-double-neg53.0%
distribute-neg-in53.0%
sub-neg53.0%
distribute-neg-frac253.0%
sub-neg53.0%
+-commutative53.0%
unsub-neg53.0%
sub-neg53.0%
+-commutative53.0%
unsub-neg53.0%
metadata-eval53.0%
Simplified53.0%
frac-sub55.2%
*-rgt-identity55.2%
metadata-eval55.2%
div-inv55.2%
associate-/r*55.3%
metadata-eval55.3%
div-inv55.3%
*-un-lft-identity55.3%
associate--l-61.1%
div-inv61.1%
metadata-eval61.1%
*-rgt-identity61.1%
div-inv61.1%
metadata-eval61.1%
*-rgt-identity61.1%
Applied egg-rr61.1%
Taylor expanded in x around inf 96.0%
Taylor expanded in x around 0 7.0%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 2.0)
x_m = fabs(x);
double code(double x_m) {
return 2.0;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = 2.0d0
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return 2.0;
}
x_m = math.fabs(x) def code(x_m): return 2.0
x_m = abs(x) function code(x_m) return 2.0 end
x_m = abs(x); function tmp = code(x_m) tmp = 2.0; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := 2.0
\begin{array}{l}
x_m = \left|x\right|
\\
2
\end{array}
Initial program 79.9%
sub-neg79.9%
+-commutative79.9%
distribute-neg-frac279.9%
neg-sub079.9%
associate-+l-79.9%
neg-sub079.9%
remove-double-neg79.9%
distribute-neg-in79.9%
sub-neg79.9%
distribute-neg-frac279.9%
sub-neg79.9%
+-commutative79.9%
unsub-neg79.9%
sub-neg79.9%
+-commutative79.9%
unsub-neg79.9%
metadata-eval79.9%
Simplified79.9%
Taylor expanded in x around 0 54.9%
herbie shell --seed 2024172
(FPCore (x)
:name "Asymptote A"
:precision binary64
(- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))