
(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 6 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}
(FPCore (x) :precision binary64 (/ (/ 2.0 (+ x -1.0)) (- -1.0 x)))
double code(double x) {
return (2.0 / (x + -1.0)) / (-1.0 - x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (2.0d0 / (x + (-1.0d0))) / ((-1.0d0) - x)
end function
public static double code(double x) {
return (2.0 / (x + -1.0)) / (-1.0 - x);
}
def code(x): return (2.0 / (x + -1.0)) / (-1.0 - x)
function code(x) return Float64(Float64(2.0 / Float64(x + -1.0)) / Float64(-1.0 - x)) end
function tmp = code(x) tmp = (2.0 / (x + -1.0)) / (-1.0 - x); end
code[x_] := N[(N[(2.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision] / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{2}{x + -1}}{-1 - x}
\end{array}
Initial program 79.9%
sub-neg79.9%
+-commutative79.9%
distribute-neg-frac79.9%
metadata-eval79.9%
metadata-eval79.9%
metadata-eval79.9%
associate-/r*79.9%
metadata-eval79.9%
neg-mul-179.9%
sub0-neg79.9%
associate-+l-79.9%
neg-sub079.9%
metadata-eval79.9%
metadata-eval79.9%
metadata-eval79.9%
associate-/r*79.9%
metadata-eval79.9%
neg-mul-179.9%
distribute-neg-in79.9%
sub-neg79.9%
distribute-neg-frac79.9%
neg-mul-179.9%
Simplified79.9%
frac-sub80.4%
*-rgt-identity80.4%
metadata-eval80.4%
div-inv80.4%
associate-/r*80.4%
*-un-lft-identity80.4%
metadata-eval80.4%
div-inv80.4%
associate--l-83.1%
div-inv83.1%
metadata-eval83.1%
*-rgt-identity83.1%
div-inv83.1%
metadata-eval83.1%
*-rgt-identity83.1%
Applied egg-rr83.1%
div-sub83.1%
sub-neg83.1%
Applied egg-rr83.1%
distribute-neg-frac83.1%
+-commutative83.1%
associate--r-99.9%
+-inverses99.9%
metadata-eval99.9%
metadata-eval99.9%
count-299.9%
associate-*r/99.9%
metadata-eval99.9%
metadata-eval99.9%
associate-/r*99.9%
neg-mul-199.9%
neg-sub099.9%
associate--r-99.9%
metadata-eval99.9%
+-commutative99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x) :precision binary64 (if (<= x 0.76) 2.0 (/ (/ -2.0 x) (+ x -1.0))))
double code(double x) {
double tmp;
if (x <= 0.76) {
tmp = 2.0;
} else {
tmp = (-2.0 / x) / (x + -1.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.76d0) then
tmp = 2.0d0
else
tmp = ((-2.0d0) / x) / (x + (-1.0d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.76) {
tmp = 2.0;
} else {
tmp = (-2.0 / x) / (x + -1.0);
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.76: tmp = 2.0 else: tmp = (-2.0 / x) / (x + -1.0) return tmp
function code(x) tmp = 0.0 if (x <= 0.76) tmp = 2.0; else tmp = Float64(Float64(-2.0 / x) / Float64(x + -1.0)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.76) tmp = 2.0; else tmp = (-2.0 / x) / (x + -1.0); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.76], 2.0, N[(N[(-2.0 / x), $MachinePrecision] / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.76:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{-2}{x}}{x + -1}\\
\end{array}
\end{array}
if x < 0.76000000000000001Initial program 84.6%
sub-neg84.6%
+-commutative84.6%
distribute-neg-frac84.6%
metadata-eval84.6%
metadata-eval84.6%
metadata-eval84.6%
associate-/r*84.6%
metadata-eval84.6%
neg-mul-184.6%
sub0-neg84.6%
associate-+l-84.6%
neg-sub084.6%
metadata-eval84.6%
metadata-eval84.6%
metadata-eval84.6%
associate-/r*84.6%
metadata-eval84.6%
neg-mul-184.6%
distribute-neg-in84.6%
sub-neg84.6%
distribute-neg-frac84.6%
neg-mul-184.6%
Simplified84.6%
Taylor expanded in x around 0 67.2%
if 0.76000000000000001 < x Initial program 61.7%
sub-neg61.7%
+-commutative61.7%
distribute-neg-frac61.7%
metadata-eval61.7%
metadata-eval61.7%
metadata-eval61.7%
associate-/r*61.7%
metadata-eval61.7%
neg-mul-161.7%
sub0-neg61.7%
associate-+l-61.7%
neg-sub061.7%
metadata-eval61.7%
metadata-eval61.7%
metadata-eval61.7%
associate-/r*61.7%
metadata-eval61.7%
neg-mul-161.7%
distribute-neg-in61.7%
sub-neg61.7%
distribute-neg-frac61.7%
neg-mul-161.7%
Simplified61.7%
sub-neg61.7%
distribute-neg-frac61.7%
metadata-eval61.7%
Applied egg-rr61.7%
*-rgt-identity61.7%
cancel-sign-sub61.7%
distribute-neg-frac61.7%
metadata-eval61.7%
*-inverses61.7%
associate-/r*7.7%
distribute-lft-neg-in7.7%
distribute-rgt-neg-in7.7%
*-commutative7.7%
*-commutative7.7%
*-inverses7.7%
times-frac61.6%
div-sub63.3%
Simplified99.8%
associate-/r*99.8%
div-inv99.6%
Applied egg-rr99.6%
un-div-inv99.8%
Applied egg-rr99.8%
Taylor expanded in x around inf 98.6%
Final simplification73.6%
(FPCore (x) :precision binary64 (if (<= x 1.0) 2.0 (/ 2.0 (- -1.0 x))))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 2.0;
} else {
tmp = 2.0 / (-1.0 - x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.0d0) then
tmp = 2.0d0
else
tmp = 2.0d0 / ((-1.0d0) - x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 2.0;
} else {
tmp = 2.0 / (-1.0 - x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.0: tmp = 2.0 else: tmp = 2.0 / (-1.0 - x) return tmp
function code(x) tmp = 0.0 if (x <= 1.0) tmp = 2.0; else tmp = Float64(2.0 / Float64(-1.0 - x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.0) tmp = 2.0; else tmp = 2.0 / (-1.0 - x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.0], 2.0, N[(2.0 / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{-1 - x}\\
\end{array}
\end{array}
if x < 1Initial program 84.6%
sub-neg84.6%
+-commutative84.6%
distribute-neg-frac84.6%
metadata-eval84.6%
metadata-eval84.6%
metadata-eval84.6%
associate-/r*84.6%
metadata-eval84.6%
neg-mul-184.6%
sub0-neg84.6%
associate-+l-84.6%
neg-sub084.6%
metadata-eval84.6%
metadata-eval84.6%
metadata-eval84.6%
associate-/r*84.6%
metadata-eval84.6%
neg-mul-184.6%
distribute-neg-in84.6%
sub-neg84.6%
distribute-neg-frac84.6%
neg-mul-184.6%
Simplified84.6%
Taylor expanded in x around 0 67.2%
if 1 < x Initial program 61.7%
sub-neg61.7%
+-commutative61.7%
distribute-neg-frac61.7%
metadata-eval61.7%
metadata-eval61.7%
metadata-eval61.7%
associate-/r*61.7%
metadata-eval61.7%
neg-mul-161.7%
sub0-neg61.7%
associate-+l-61.7%
neg-sub061.7%
metadata-eval61.7%
metadata-eval61.7%
metadata-eval61.7%
associate-/r*61.7%
metadata-eval61.7%
neg-mul-161.7%
distribute-neg-in61.7%
sub-neg61.7%
distribute-neg-frac61.7%
neg-mul-161.7%
Simplified61.7%
frac-sub63.3%
*-rgt-identity63.3%
metadata-eval63.3%
div-inv63.3%
associate-/r*63.3%
*-un-lft-identity63.3%
metadata-eval63.3%
div-inv63.3%
associate--l-68.8%
div-inv68.8%
metadata-eval68.8%
*-rgt-identity68.8%
div-inv68.8%
metadata-eval68.8%
*-rgt-identity68.8%
Applied egg-rr68.8%
Taylor expanded in x around 0 4.9%
add-sqr-sqrt4.9%
sqrt-unprod58.7%
frac-times58.7%
metadata-eval58.7%
metadata-eval58.7%
frac-times58.7%
sqrt-unprod0.0%
add-sqr-sqrt6.8%
expm1-log1p-u6.8%
expm1-udef59.9%
Applied egg-rr59.9%
expm1-def6.8%
expm1-log1p6.8%
Simplified6.8%
Final simplification54.9%
(FPCore (x) :precision binary64 (/ 2.0 (* (+ x -1.0) (- -1.0 x))))
double code(double x) {
return 2.0 / ((x + -1.0) * (-1.0 - x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0 / ((x + (-1.0d0)) * ((-1.0d0) - x))
end function
public static double code(double x) {
return 2.0 / ((x + -1.0) * (-1.0 - x));
}
def code(x): return 2.0 / ((x + -1.0) * (-1.0 - x))
function code(x) return Float64(2.0 / Float64(Float64(x + -1.0) * Float64(-1.0 - x))) end
function tmp = code(x) tmp = 2.0 / ((x + -1.0) * (-1.0 - x)); end
code[x_] := N[(2.0 / N[(N[(x + -1.0), $MachinePrecision] * N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{\left(x + -1\right) \cdot \left(-1 - x\right)}
\end{array}
Initial program 79.9%
sub-neg79.9%
+-commutative79.9%
distribute-neg-frac79.9%
metadata-eval79.9%
metadata-eval79.9%
metadata-eval79.9%
associate-/r*79.9%
metadata-eval79.9%
neg-mul-179.9%
sub0-neg79.9%
associate-+l-79.9%
neg-sub079.9%
metadata-eval79.9%
metadata-eval79.9%
metadata-eval79.9%
associate-/r*79.9%
metadata-eval79.9%
neg-mul-179.9%
distribute-neg-in79.9%
sub-neg79.9%
distribute-neg-frac79.9%
neg-mul-179.9%
Simplified79.9%
sub-neg79.9%
distribute-neg-frac79.9%
metadata-eval79.9%
Applied egg-rr79.9%
*-rgt-identity79.9%
cancel-sign-sub79.9%
distribute-neg-frac79.9%
metadata-eval79.9%
*-inverses79.9%
associate-/r*57.4%
distribute-lft-neg-in57.4%
distribute-rgt-neg-in57.4%
*-commutative57.4%
*-commutative57.4%
*-inverses57.4%
times-frac79.9%
div-sub80.4%
Simplified99.5%
Final simplification99.5%
(FPCore (x) :precision binary64 (if (<= x 1.0) 2.0 (/ -2.0 x)))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 2.0;
} else {
tmp = -2.0 / x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.0d0) then
tmp = 2.0d0
else
tmp = (-2.0d0) / x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 2.0;
} else {
tmp = -2.0 / x;
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.0: tmp = 2.0 else: tmp = -2.0 / x return tmp
function code(x) tmp = 0.0 if (x <= 1.0) tmp = 2.0; else tmp = Float64(-2.0 / x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.0) tmp = 2.0; else tmp = -2.0 / x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.0], 2.0, N[(-2.0 / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;\frac{-2}{x}\\
\end{array}
\end{array}
if x < 1Initial program 84.6%
sub-neg84.6%
+-commutative84.6%
distribute-neg-frac84.6%
metadata-eval84.6%
metadata-eval84.6%
metadata-eval84.6%
associate-/r*84.6%
metadata-eval84.6%
neg-mul-184.6%
sub0-neg84.6%
associate-+l-84.6%
neg-sub084.6%
metadata-eval84.6%
metadata-eval84.6%
metadata-eval84.6%
associate-/r*84.6%
metadata-eval84.6%
neg-mul-184.6%
distribute-neg-in84.6%
sub-neg84.6%
distribute-neg-frac84.6%
neg-mul-184.6%
Simplified84.6%
Taylor expanded in x around 0 67.2%
if 1 < x Initial program 61.7%
sub-neg61.7%
+-commutative61.7%
distribute-neg-frac61.7%
metadata-eval61.7%
metadata-eval61.7%
metadata-eval61.7%
associate-/r*61.7%
metadata-eval61.7%
neg-mul-161.7%
sub0-neg61.7%
associate-+l-61.7%
neg-sub061.7%
metadata-eval61.7%
metadata-eval61.7%
metadata-eval61.7%
associate-/r*61.7%
metadata-eval61.7%
neg-mul-161.7%
distribute-neg-in61.7%
sub-neg61.7%
distribute-neg-frac61.7%
neg-mul-161.7%
Simplified61.7%
frac-sub63.3%
*-rgt-identity63.3%
metadata-eval63.3%
div-inv63.3%
associate-/r*63.3%
*-un-lft-identity63.3%
metadata-eval63.3%
div-inv63.3%
associate--l-68.8%
div-inv68.8%
metadata-eval68.8%
*-rgt-identity68.8%
div-inv68.8%
metadata-eval68.8%
*-rgt-identity68.8%
Applied egg-rr68.8%
Taylor expanded in x around 0 4.9%
add-sqr-sqrt4.9%
sqrt-unprod58.7%
frac-times58.7%
metadata-eval58.7%
metadata-eval58.7%
frac-times58.7%
sqrt-unprod0.0%
add-sqr-sqrt6.8%
expm1-log1p-u6.8%
expm1-udef59.9%
Applied egg-rr59.9%
expm1-def6.8%
expm1-log1p6.8%
Simplified6.8%
Taylor expanded in x around inf 6.8%
Final simplification54.9%
(FPCore (x) :precision binary64 2.0)
double code(double x) {
return 2.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0
end function
public static double code(double x) {
return 2.0;
}
def code(x): return 2.0
function code(x) return 2.0 end
function tmp = code(x) tmp = 2.0; end
code[x_] := 2.0
\begin{array}{l}
\\
2
\end{array}
Initial program 79.9%
sub-neg79.9%
+-commutative79.9%
distribute-neg-frac79.9%
metadata-eval79.9%
metadata-eval79.9%
metadata-eval79.9%
associate-/r*79.9%
metadata-eval79.9%
neg-mul-179.9%
sub0-neg79.9%
associate-+l-79.9%
neg-sub079.9%
metadata-eval79.9%
metadata-eval79.9%
metadata-eval79.9%
associate-/r*79.9%
metadata-eval79.9%
neg-mul-179.9%
distribute-neg-in79.9%
sub-neg79.9%
distribute-neg-frac79.9%
neg-mul-179.9%
Simplified79.9%
Taylor expanded in x around 0 54.1%
Final simplification54.1%
herbie shell --seed 2024019
(FPCore (x)
:name "Asymptote A"
:precision binary64
(- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))