
(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 78.2%
sub-neg78.2%
+-commutative78.2%
distribute-neg-frac278.2%
neg-sub078.2%
associate-+l-78.2%
neg-sub078.2%
remove-double-neg78.2%
distribute-neg-in78.2%
sub-neg78.2%
distribute-neg-frac278.2%
sub-neg78.2%
+-commutative78.2%
unsub-neg78.2%
sub-neg78.2%
+-commutative78.2%
unsub-neg78.2%
metadata-eval78.2%
Simplified78.2%
frac-sub79.3%
*-rgt-identity79.3%
metadata-eval79.3%
div-inv79.3%
associate-/r*79.3%
*-un-lft-identity79.3%
metadata-eval79.3%
div-inv79.3%
associate--l-82.0%
div-inv82.0%
metadata-eval82.0%
*-rgt-identity82.0%
div-inv82.0%
metadata-eval82.0%
*-rgt-identity82.0%
Applied egg-rr82.0%
div-sub82.0%
sub-neg82.0%
frac-2neg82.0%
metadata-eval82.0%
flip--81.9%
metadata-eval81.9%
unpow281.9%
+-commutative81.9%
distribute-neg-frac281.9%
metadata-eval81.9%
unpow281.9%
+-commutative81.9%
distribute-neg-in81.9%
metadata-eval81.9%
sub-neg81.9%
flip-+82.0%
+-commutative82.0%
associate-+r-82.0%
+-commutative82.0%
associate--l+99.9%
Applied egg-rr99.9%
+-commutative99.9%
neg-sub099.9%
+-inverses99.9%
metadata-eval99.9%
associate-+l-99.9%
sub-neg99.9%
metadata-eval99.9%
distribute-neg-in99.9%
+-commutative99.9%
distribute-neg-frac299.9%
distribute-neg-frac99.9%
metadata-eval99.9%
metadata-eval99.9%
+-inverses99.9%
associate--r+82.0%
div-sub82.0%
associate-+l-79.3%
Simplified99.9%
Final simplification99.9%
(FPCore (x) :precision binary64 (if (<= x 2e+15) (/ 2.0 (* (- 1.0 x) (+ x 1.0))) (/ (/ 2.0 x) (- -1.0 x))))
double code(double x) {
double tmp;
if (x <= 2e+15) {
tmp = 2.0 / ((1.0 - x) * (x + 1.0));
} else {
tmp = (2.0 / x) / (-1.0 - x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 2d+15) then
tmp = 2.0d0 / ((1.0d0 - x) * (x + 1.0d0))
else
tmp = (2.0d0 / x) / ((-1.0d0) - x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 2e+15) {
tmp = 2.0 / ((1.0 - x) * (x + 1.0));
} else {
tmp = (2.0 / x) / (-1.0 - x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 2e+15: tmp = 2.0 / ((1.0 - x) * (x + 1.0)) else: tmp = (2.0 / x) / (-1.0 - x) return tmp
function code(x) tmp = 0.0 if (x <= 2e+15) tmp = Float64(2.0 / Float64(Float64(1.0 - x) * Float64(x + 1.0))); else tmp = Float64(Float64(2.0 / x) / Float64(-1.0 - x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 2e+15) tmp = 2.0 / ((1.0 - x) * (x + 1.0)); else tmp = (2.0 / x) / (-1.0 - x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 2e+15], N[(2.0 / N[(N[(1.0 - x), $MachinePrecision] * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 / x), $MachinePrecision] / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2 \cdot 10^{+15}:\\
\;\;\;\;\frac{2}{\left(1 - x\right) \cdot \left(x + 1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{2}{x}}{-1 - x}\\
\end{array}
\end{array}
if x < 2e15Initial program 84.2%
sub-neg84.2%
+-commutative84.2%
distribute-neg-frac284.2%
neg-sub084.2%
associate-+l-84.2%
neg-sub084.2%
remove-double-neg84.2%
distribute-neg-in84.2%
sub-neg84.2%
distribute-neg-frac284.2%
sub-neg84.2%
+-commutative84.2%
unsub-neg84.2%
sub-neg84.2%
+-commutative84.2%
unsub-neg84.2%
metadata-eval84.2%
Simplified84.2%
sub-neg84.2%
distribute-neg-frac84.2%
metadata-eval84.2%
Applied egg-rr84.2%
*-rgt-identity84.2%
fma-undefine84.2%
*-inverses84.2%
*-lft-identity84.2%
*-inverses84.2%
distribute-frac-neg84.2%
distribute-lft-neg-in84.2%
times-frac69.8%
distribute-lft-neg-out69.8%
distribute-rgt-neg-out69.8%
fma-neg69.8%
Simplified98.6%
if 2e15 < x Initial program 55.6%
sub-neg55.6%
+-commutative55.6%
distribute-neg-frac255.6%
neg-sub055.6%
associate-+l-55.6%
neg-sub055.6%
remove-double-neg55.6%
distribute-neg-in55.6%
sub-neg55.6%
distribute-neg-frac255.6%
sub-neg55.6%
+-commutative55.6%
unsub-neg55.6%
sub-neg55.6%
+-commutative55.6%
unsub-neg55.6%
metadata-eval55.6%
Simplified55.6%
frac-sub55.6%
*-rgt-identity55.6%
metadata-eval55.6%
div-inv55.6%
associate-/r*55.6%
*-un-lft-identity55.6%
metadata-eval55.6%
div-inv55.6%
associate--l-61.5%
div-inv61.5%
metadata-eval61.5%
*-rgt-identity61.5%
div-inv61.5%
metadata-eval61.5%
*-rgt-identity61.5%
Applied egg-rr61.5%
Taylor expanded in x around inf 99.8%
Final simplification98.8%
(FPCore (x) :precision binary64 (if (<= x 1.0) 2.0 (/ -2.0 (* x (+ x 1.0)))))
double code(double x) {
double tmp;
if (x <= 1.0) {
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 <= 1.0d0) 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 <= 1.0) {
tmp = 2.0;
} else {
tmp = -2.0 / (x * (x + 1.0));
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.0: tmp = 2.0 else: tmp = -2.0 / (x * (x + 1.0)) return tmp
function code(x) tmp = 0.0 if (x <= 1.0) tmp = 2.0; else tmp = Float64(-2.0 / Float64(x * Float64(x + 1.0))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.0) tmp = 2.0; else tmp = -2.0 / (x * (x + 1.0)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.0], 2.0, N[(-2.0 / N[(x * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;\frac{-2}{x \cdot \left(x + 1\right)}\\
\end{array}
\end{array}
if x < 1Initial program 84.8%
sub-neg84.8%
+-commutative84.8%
distribute-neg-frac284.8%
neg-sub084.8%
associate-+l-84.8%
neg-sub084.8%
remove-double-neg84.8%
distribute-neg-in84.8%
sub-neg84.8%
distribute-neg-frac284.8%
sub-neg84.8%
+-commutative84.8%
unsub-neg84.8%
sub-neg84.8%
+-commutative84.8%
unsub-neg84.8%
metadata-eval84.8%
Simplified84.8%
Taylor expanded in x around 0 67.3%
if 1 < x Initial program 55.5%
sub-neg55.5%
+-commutative55.5%
distribute-neg-frac255.5%
neg-sub055.5%
associate-+l-55.5%
neg-sub055.5%
remove-double-neg55.5%
distribute-neg-in55.5%
sub-neg55.5%
distribute-neg-frac255.5%
sub-neg55.5%
+-commutative55.5%
unsub-neg55.5%
sub-neg55.5%
+-commutative55.5%
unsub-neg55.5%
metadata-eval55.5%
Simplified55.5%
frac-sub58.7%
*-rgt-identity58.7%
metadata-eval58.7%
div-inv58.7%
associate-/r*58.7%
*-un-lft-identity58.7%
metadata-eval58.7%
div-inv58.7%
associate--l-64.2%
div-inv64.2%
metadata-eval64.2%
*-rgt-identity64.2%
div-inv64.2%
metadata-eval64.2%
*-rgt-identity64.2%
Applied egg-rr64.2%
Taylor expanded in x around inf 97.6%
*-un-lft-identity97.6%
frac-2neg97.6%
distribute-neg-frac97.6%
metadata-eval97.6%
flip--95.4%
+-commutative95.4%
distribute-neg-frac295.4%
metadata-eval95.4%
metadata-eval95.4%
+-commutative95.4%
distribute-neg-in95.4%
metadata-eval95.4%
sub-neg95.4%
flip-+97.6%
+-commutative97.6%
Applied egg-rr97.6%
*-lft-identity97.6%
associate-/l/95.4%
Simplified95.4%
Final simplification73.7%
(FPCore (x) :precision binary64 (if (<= x 1.0) 2.0 (/ (/ 2.0 x) (- -1.0 x))))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 2.0;
} else {
tmp = (2.0 / x) / (-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 / x) / ((-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 / x) / (-1.0 - x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.0: tmp = 2.0 else: tmp = (2.0 / x) / (-1.0 - x) return tmp
function code(x) tmp = 0.0 if (x <= 1.0) tmp = 2.0; else tmp = Float64(Float64(2.0 / x) / 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 / x) / (-1.0 - x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.0], 2.0, N[(N[(2.0 / x), $MachinePrecision] / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{2}{x}}{-1 - x}\\
\end{array}
\end{array}
if x < 1Initial program 84.8%
sub-neg84.8%
+-commutative84.8%
distribute-neg-frac284.8%
neg-sub084.8%
associate-+l-84.8%
neg-sub084.8%
remove-double-neg84.8%
distribute-neg-in84.8%
sub-neg84.8%
distribute-neg-frac284.8%
sub-neg84.8%
+-commutative84.8%
unsub-neg84.8%
sub-neg84.8%
+-commutative84.8%
unsub-neg84.8%
metadata-eval84.8%
Simplified84.8%
Taylor expanded in x around 0 67.3%
if 1 < x Initial program 55.5%
sub-neg55.5%
+-commutative55.5%
distribute-neg-frac255.5%
neg-sub055.5%
associate-+l-55.5%
neg-sub055.5%
remove-double-neg55.5%
distribute-neg-in55.5%
sub-neg55.5%
distribute-neg-frac255.5%
sub-neg55.5%
+-commutative55.5%
unsub-neg55.5%
sub-neg55.5%
+-commutative55.5%
unsub-neg55.5%
metadata-eval55.5%
Simplified55.5%
frac-sub58.7%
*-rgt-identity58.7%
metadata-eval58.7%
div-inv58.7%
associate-/r*58.7%
*-un-lft-identity58.7%
metadata-eval58.7%
div-inv58.7%
associate--l-64.2%
div-inv64.2%
metadata-eval64.2%
*-rgt-identity64.2%
div-inv64.2%
metadata-eval64.2%
*-rgt-identity64.2%
Applied egg-rr64.2%
Taylor expanded in x around inf 97.6%
Final simplification74.2%
(FPCore (x) :precision binary64 (if (<= x 1.0) 2.0 0.0))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 2.0;
} else {
tmp = 0.0;
}
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 = 0.0d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 2.0;
} else {
tmp = 0.0;
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.0: tmp = 2.0 else: tmp = 0.0 return tmp
function code(x) tmp = 0.0 if (x <= 1.0) tmp = 2.0; else tmp = 0.0; end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.0) tmp = 2.0; else tmp = 0.0; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.0], 2.0, 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if x < 1Initial program 84.8%
sub-neg84.8%
+-commutative84.8%
distribute-neg-frac284.8%
neg-sub084.8%
associate-+l-84.8%
neg-sub084.8%
remove-double-neg84.8%
distribute-neg-in84.8%
sub-neg84.8%
distribute-neg-frac284.8%
sub-neg84.8%
+-commutative84.8%
unsub-neg84.8%
sub-neg84.8%
+-commutative84.8%
unsub-neg84.8%
metadata-eval84.8%
Simplified84.8%
Taylor expanded in x around 0 67.3%
if 1 < x Initial program 55.5%
sub-neg55.5%
+-commutative55.5%
distribute-neg-frac255.5%
neg-sub055.5%
associate-+l-55.5%
neg-sub055.5%
remove-double-neg55.5%
distribute-neg-in55.5%
sub-neg55.5%
distribute-neg-frac255.5%
sub-neg55.5%
+-commutative55.5%
unsub-neg55.5%
sub-neg55.5%
+-commutative55.5%
unsub-neg55.5%
metadata-eval55.5%
Simplified55.5%
flip--9.7%
metadata-eval9.7%
metadata-eval9.7%
associate-/r/9.5%
metadata-eval9.5%
pow29.5%
Applied egg-rr9.5%
associate-*l/9.6%
*-lft-identity9.6%
+-commutative9.6%
Simplified9.6%
Applied egg-rr0.0%
div-sub0.0%
unpow20.0%
+-inverses0.0%
metadata-eval0.0%
+-inverses0.0%
metadata-eval0.0%
metadata-eval0.0%
+-inverses52.0%
Simplified52.0%
Final simplification63.8%
(FPCore (x) :precision binary64 0.0)
double code(double x) {
return 0.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.0d0
end function
public static double code(double x) {
return 0.0;
}
def code(x): return 0.0
function code(x) return 0.0 end
function tmp = code(x) tmp = 0.0; end
code[x_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 78.2%
sub-neg78.2%
+-commutative78.2%
distribute-neg-frac278.2%
neg-sub078.2%
associate-+l-78.2%
neg-sub078.2%
remove-double-neg78.2%
distribute-neg-in78.2%
sub-neg78.2%
distribute-neg-frac278.2%
sub-neg78.2%
+-commutative78.2%
unsub-neg78.2%
sub-neg78.2%
+-commutative78.2%
unsub-neg78.2%
metadata-eval78.2%
Simplified78.2%
flip--56.5%
metadata-eval56.5%
metadata-eval56.5%
associate-/r/56.4%
metadata-eval56.4%
pow256.4%
Applied egg-rr56.4%
associate-*l/56.5%
*-lft-identity56.5%
+-commutative56.5%
Simplified56.5%
Applied egg-rr1.6%
div-sub1.6%
unpow21.6%
+-inverses1.6%
metadata-eval1.6%
+-inverses1.6%
metadata-eval1.6%
metadata-eval1.6%
+-inverses26.3%
Simplified26.3%
Final simplification26.3%
herbie shell --seed 2024050
(FPCore (x)
:name "Asymptote A"
:precision binary64
(- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))