
(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 78.6%
sub-neg78.6%
+-commutative78.6%
distribute-neg-frac78.6%
metadata-eval78.6%
metadata-eval78.6%
metadata-eval78.6%
associate-/r*78.6%
metadata-eval78.6%
neg-mul-178.6%
sub0-neg78.6%
associate-+l-78.6%
neg-sub078.6%
metadata-eval78.6%
metadata-eval78.6%
metadata-eval78.6%
associate-/r*78.6%
metadata-eval78.6%
neg-mul-178.6%
distribute-neg-in78.6%
sub-neg78.6%
distribute-neg-frac78.6%
neg-mul-178.6%
Simplified78.6%
frac-sub79.2%
*-rgt-identity79.2%
metadata-eval79.2%
div-inv79.2%
associate-/r*79.2%
*-un-lft-identity79.2%
metadata-eval79.2%
div-inv79.2%
associate--l-82.1%
div-inv82.1%
metadata-eval82.1%
*-rgt-identity82.1%
div-inv82.1%
metadata-eval82.1%
*-rgt-identity82.1%
Applied egg-rr82.1%
frac-2neg82.1%
div-inv82.0%
distribute-neg-frac82.0%
associate--r+79.2%
associate--r-79.2%
sub-neg79.2%
neg-mul-179.2%
distribute-neg-in79.2%
metadata-eval79.2%
*-commutative79.2%
sub-neg79.2%
*-commutative79.2%
neg-mul-179.2%
Applied egg-rr79.2%
associate-*r/79.2%
*-rgt-identity79.2%
associate-+l-79.2%
associate--l-82.1%
+-commutative82.1%
associate--r-99.9%
+-inverses99.9%
metadata-eval99.9%
metadata-eval99.9%
metadata-eval99.9%
sub-neg99.9%
remove-double-neg99.9%
+-commutative99.9%
Simplified99.9%
Final simplification99.9%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= x_m 1.0) 2.0 (/ 2.0 (* x_m (- -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 / (x_m * (-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 / (x_m * ((-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 / (x_m * (-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 / (x_m * (-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(x_m * 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 / (x_m * (-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[(x$95$m * N[(-1.0 - x$95$m), $MachinePrecision]), $MachinePrecision]), $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 \cdot \left(-1 - x_m\right)}\\
\end{array}
\end{array}
if x < 1Initial program 85.8%
sub-neg85.8%
+-commutative85.8%
distribute-neg-frac85.8%
metadata-eval85.8%
metadata-eval85.8%
metadata-eval85.8%
associate-/r*85.8%
metadata-eval85.8%
neg-mul-185.8%
sub0-neg85.8%
associate-+l-85.8%
neg-sub085.8%
metadata-eval85.8%
metadata-eval85.8%
metadata-eval85.8%
associate-/r*85.8%
metadata-eval85.8%
neg-mul-185.8%
distribute-neg-in85.8%
sub-neg85.8%
distribute-neg-frac85.8%
neg-mul-185.8%
Simplified85.8%
Taylor expanded in x around 0 69.9%
if 1 < x Initial program 55.1%
sub-neg55.1%
+-commutative55.1%
distribute-neg-frac55.1%
metadata-eval55.1%
metadata-eval55.1%
metadata-eval55.1%
associate-/r*55.1%
metadata-eval55.1%
neg-mul-155.1%
sub0-neg55.1%
associate-+l-55.1%
neg-sub055.1%
metadata-eval55.1%
metadata-eval55.1%
metadata-eval55.1%
associate-/r*55.1%
metadata-eval55.1%
neg-mul-155.1%
distribute-neg-in55.1%
sub-neg55.1%
distribute-neg-frac55.1%
neg-mul-155.1%
Simplified55.1%
frac-sub56.5%
*-rgt-identity56.5%
metadata-eval56.5%
div-inv56.5%
associate-/r*56.6%
*-un-lft-identity56.6%
metadata-eval56.6%
div-inv56.6%
associate--l-62.6%
div-inv62.6%
metadata-eval62.6%
*-rgt-identity62.6%
div-inv62.6%
metadata-eval62.6%
*-rgt-identity62.6%
Applied egg-rr62.6%
Taylor expanded in x around inf 96.1%
expm1-log1p-u96.1%
expm1-udef51.7%
associate-/l/51.7%
associate-/r*51.7%
Applied egg-rr51.7%
expm1-def96.1%
expm1-log1p96.1%
associate-/l/95.2%
Simplified95.2%
Final simplification75.8%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= x_m 1.0) 2.0 (/ (/ 2.0 x_m) (- -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 / x_m) / (-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 / x_m) / ((-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 / x_m) / (-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 / x_m) / (-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(Float64(2.0 / x_m) / 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 / x_m) / (-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[(N[(2.0 / x$95$m), $MachinePrecision] / 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{\frac{2}{x_m}}{-1 - x_m}\\
\end{array}
\end{array}
if x < 1Initial program 85.8%
sub-neg85.8%
+-commutative85.8%
distribute-neg-frac85.8%
metadata-eval85.8%
metadata-eval85.8%
metadata-eval85.8%
associate-/r*85.8%
metadata-eval85.8%
neg-mul-185.8%
sub0-neg85.8%
associate-+l-85.8%
neg-sub085.8%
metadata-eval85.8%
metadata-eval85.8%
metadata-eval85.8%
associate-/r*85.8%
metadata-eval85.8%
neg-mul-185.8%
distribute-neg-in85.8%
sub-neg85.8%
distribute-neg-frac85.8%
neg-mul-185.8%
Simplified85.8%
Taylor expanded in x around 0 69.9%
if 1 < x Initial program 55.1%
sub-neg55.1%
+-commutative55.1%
distribute-neg-frac55.1%
metadata-eval55.1%
metadata-eval55.1%
metadata-eval55.1%
associate-/r*55.1%
metadata-eval55.1%
neg-mul-155.1%
sub0-neg55.1%
associate-+l-55.1%
neg-sub055.1%
metadata-eval55.1%
metadata-eval55.1%
metadata-eval55.1%
associate-/r*55.1%
metadata-eval55.1%
neg-mul-155.1%
distribute-neg-in55.1%
sub-neg55.1%
distribute-neg-frac55.1%
neg-mul-155.1%
Simplified55.1%
frac-sub56.5%
*-rgt-identity56.5%
metadata-eval56.5%
div-inv56.5%
associate-/r*56.6%
*-un-lft-identity56.6%
metadata-eval56.6%
div-inv56.6%
associate--l-62.6%
div-inv62.6%
metadata-eval62.6%
*-rgt-identity62.6%
div-inv62.6%
metadata-eval62.6%
*-rgt-identity62.6%
Applied egg-rr62.6%
Taylor expanded in x around inf 96.1%
Final simplification76.0%
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 78.6%
sub-neg78.6%
+-commutative78.6%
distribute-neg-frac78.6%
metadata-eval78.6%
metadata-eval78.6%
metadata-eval78.6%
associate-/r*78.6%
metadata-eval78.6%
neg-mul-178.6%
sub0-neg78.6%
associate-+l-78.6%
neg-sub078.6%
metadata-eval78.6%
metadata-eval78.6%
metadata-eval78.6%
associate-/r*78.6%
metadata-eval78.6%
neg-mul-178.6%
distribute-neg-in78.6%
sub-neg78.6%
distribute-neg-frac78.6%
neg-mul-178.6%
Simplified78.6%
sub-neg78.6%
distribute-neg-frac78.6%
metadata-eval78.6%
Applied egg-rr78.6%
*-rgt-identity78.6%
cancel-sign-sub78.6%
distribute-neg-frac78.6%
metadata-eval78.6%
*-inverses78.6%
associate-/r*57.9%
distribute-lft-neg-in57.9%
distribute-rgt-neg-in57.9%
*-commutative57.9%
*-commutative57.9%
*-inverses57.9%
times-frac78.6%
div-sub79.2%
Simplified99.1%
Final simplification99.1%
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 85.8%
sub-neg85.8%
+-commutative85.8%
distribute-neg-frac85.8%
metadata-eval85.8%
metadata-eval85.8%
metadata-eval85.8%
associate-/r*85.8%
metadata-eval85.8%
neg-mul-185.8%
sub0-neg85.8%
associate-+l-85.8%
neg-sub085.8%
metadata-eval85.8%
metadata-eval85.8%
metadata-eval85.8%
associate-/r*85.8%
metadata-eval85.8%
neg-mul-185.8%
distribute-neg-in85.8%
sub-neg85.8%
distribute-neg-frac85.8%
neg-mul-185.8%
Simplified85.8%
Taylor expanded in x around 0 69.9%
if 1 < x Initial program 55.1%
sub-neg55.1%
+-commutative55.1%
distribute-neg-frac55.1%
metadata-eval55.1%
metadata-eval55.1%
metadata-eval55.1%
associate-/r*55.1%
metadata-eval55.1%
neg-mul-155.1%
sub0-neg55.1%
associate-+l-55.1%
neg-sub055.1%
metadata-eval55.1%
metadata-eval55.1%
metadata-eval55.1%
associate-/r*55.1%
metadata-eval55.1%
neg-mul-155.1%
distribute-neg-in55.1%
sub-neg55.1%
distribute-neg-frac55.1%
neg-mul-155.1%
Simplified55.1%
frac-sub56.5%
*-rgt-identity56.5%
metadata-eval56.5%
div-inv56.5%
associate-/r*56.6%
*-un-lft-identity56.6%
metadata-eval56.6%
div-inv56.6%
associate--l-62.6%
div-inv62.6%
metadata-eval62.6%
*-rgt-identity62.6%
div-inv62.6%
metadata-eval62.6%
*-rgt-identity62.6%
Applied egg-rr62.6%
Taylor expanded in x around inf 96.1%
Taylor expanded in x around 0 7.0%
Final simplification55.2%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 1.0)
x_m = fabs(x);
double code(double x_m) {
return 1.0;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = 1.0d0
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return 1.0;
}
x_m = math.fabs(x) def code(x_m): return 1.0
x_m = abs(x) function code(x_m) return 1.0 end
x_m = abs(x); function tmp = code(x_m) tmp = 1.0; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := 1.0
\begin{array}{l}
x_m = \left|x\right|
\\
1
\end{array}
Initial program 78.6%
sub-neg78.6%
+-commutative78.6%
distribute-neg-frac78.6%
metadata-eval78.6%
metadata-eval78.6%
metadata-eval78.6%
associate-/r*78.6%
metadata-eval78.6%
neg-mul-178.6%
sub0-neg78.6%
associate-+l-78.6%
neg-sub078.6%
metadata-eval78.6%
metadata-eval78.6%
metadata-eval78.6%
associate-/r*78.6%
metadata-eval78.6%
neg-mul-178.6%
distribute-neg-in78.6%
sub-neg78.6%
distribute-neg-frac78.6%
neg-mul-178.6%
Simplified78.6%
Taylor expanded in x around 0 53.2%
Taylor expanded in x around inf 11.2%
Final simplification11.2%
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 78.6%
sub-neg78.6%
+-commutative78.6%
distribute-neg-frac78.6%
metadata-eval78.6%
metadata-eval78.6%
metadata-eval78.6%
associate-/r*78.6%
metadata-eval78.6%
neg-mul-178.6%
sub0-neg78.6%
associate-+l-78.6%
neg-sub078.6%
metadata-eval78.6%
metadata-eval78.6%
metadata-eval78.6%
associate-/r*78.6%
metadata-eval78.6%
neg-mul-178.6%
distribute-neg-in78.6%
sub-neg78.6%
distribute-neg-frac78.6%
neg-mul-178.6%
Simplified78.6%
Taylor expanded in x around 0 54.1%
Final simplification54.1%
herbie shell --seed 2024017
(FPCore (x)
:name "Asymptote A"
:precision binary64
(- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))