
(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 8 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)) (+ x 1.0)))
double code(double x) {
return (-2.0 / (x + -1.0)) / (x + 1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((-2.0d0) / (x + (-1.0d0))) / (x + 1.0d0)
end function
public static double code(double x) {
return (-2.0 / (x + -1.0)) / (x + 1.0);
}
def code(x): return (-2.0 / (x + -1.0)) / (x + 1.0)
function code(x) return Float64(Float64(-2.0 / Float64(x + -1.0)) / Float64(x + 1.0)) end
function tmp = code(x) tmp = (-2.0 / (x + -1.0)) / (x + 1.0); end
code[x_] := N[(N[(-2.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{-2}{x + -1}}{x + 1}
\end{array}
Initial program 84.6%
sub-neg84.6%
+-commutative84.6%
distribute-neg-frac284.6%
neg-sub084.6%
associate-+l-84.6%
neg-sub084.6%
remove-double-neg84.6%
distribute-neg-in84.6%
sub-neg84.6%
distribute-neg-frac284.6%
sub-neg84.6%
+-commutative84.6%
unsub-neg84.6%
sub-neg84.6%
+-commutative84.6%
unsub-neg84.6%
metadata-eval84.6%
Simplified84.6%
sub-neg84.6%
distribute-neg-frac84.6%
metadata-eval84.6%
Applied egg-rr84.6%
Simplified99.3%
associate-/r*99.9%
div-inv99.8%
+-commutative99.8%
Applied egg-rr99.8%
associate-*l/99.9%
un-div-inv99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x) :precision binary64 (if (<= x 0.76) 2.0 (/ (/ 2.0 x) (- 1.0 x))))
double code(double x) {
double tmp;
if (x <= 0.76) {
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 <= 0.76d0) 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 <= 0.76) {
tmp = 2.0;
} else {
tmp = (2.0 / x) / (1.0 - x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.76: tmp = 2.0 else: tmp = (2.0 / x) / (1.0 - x) return tmp
function code(x) tmp = 0.0 if (x <= 0.76) 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 <= 0.76) tmp = 2.0; else tmp = (2.0 / x) / (1.0 - x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.76], 2.0, N[(N[(2.0 / x), $MachinePrecision] / N[(1.0 - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.76:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{2}{x}}{1 - x}\\
\end{array}
\end{array}
if x < 0.76000000000000001Initial program 89.4%
sub-neg89.4%
+-commutative89.4%
distribute-neg-frac289.4%
neg-sub089.4%
associate-+l-89.4%
neg-sub089.4%
remove-double-neg89.4%
distribute-neg-in89.4%
sub-neg89.4%
distribute-neg-frac289.4%
sub-neg89.4%
+-commutative89.4%
unsub-neg89.4%
sub-neg89.4%
+-commutative89.4%
unsub-neg89.4%
metadata-eval89.4%
Simplified89.4%
Taylor expanded in x around 0 69.5%
if 0.76000000000000001 < x Initial program 64.9%
sub-neg64.9%
+-commutative64.9%
distribute-neg-frac264.9%
neg-sub064.9%
associate-+l-64.9%
neg-sub064.9%
remove-double-neg64.9%
distribute-neg-in64.9%
sub-neg64.9%
distribute-neg-frac264.9%
sub-neg64.9%
+-commutative64.9%
unsub-neg64.9%
sub-neg64.9%
+-commutative64.9%
unsub-neg64.9%
metadata-eval64.9%
Simplified64.9%
sub-neg64.9%
distribute-neg-frac64.9%
metadata-eval64.9%
Applied egg-rr64.9%
Simplified97.6%
Taylor expanded in x around inf 95.8%
div-inv95.8%
frac-2neg95.8%
metadata-eval95.8%
distribute-rgt-neg-in95.8%
+-commutative95.8%
distribute-neg-in95.8%
metadata-eval95.8%
sub-neg95.8%
Applied egg-rr95.8%
associate-*r/95.8%
metadata-eval95.8%
associate-/r*97.9%
Simplified97.9%
(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 89.4%
sub-neg89.4%
+-commutative89.4%
distribute-neg-frac289.4%
neg-sub089.4%
associate-+l-89.4%
neg-sub089.4%
remove-double-neg89.4%
distribute-neg-in89.4%
sub-neg89.4%
distribute-neg-frac289.4%
sub-neg89.4%
+-commutative89.4%
unsub-neg89.4%
sub-neg89.4%
+-commutative89.4%
unsub-neg89.4%
metadata-eval89.4%
Simplified89.4%
Taylor expanded in x around 0 69.5%
if 1 < x Initial program 64.9%
sub-neg64.9%
+-commutative64.9%
distribute-neg-frac264.9%
neg-sub064.9%
associate-+l-64.9%
neg-sub064.9%
remove-double-neg64.9%
distribute-neg-in64.9%
sub-neg64.9%
distribute-neg-frac264.9%
sub-neg64.9%
+-commutative64.9%
unsub-neg64.9%
sub-neg64.9%
+-commutative64.9%
unsub-neg64.9%
metadata-eval64.9%
Simplified64.9%
frac-sub67.5%
*-rgt-identity67.5%
metadata-eval67.5%
div-inv67.5%
associate-/r*67.6%
metadata-eval67.6%
div-inv67.6%
*-un-lft-identity67.6%
associate--l-72.1%
div-inv72.1%
metadata-eval72.1%
*-rgt-identity72.1%
div-inv72.1%
metadata-eval72.1%
*-rgt-identity72.1%
Applied egg-rr72.1%
Taylor expanded in x around inf 97.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(-2.0 / Float64(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[(-2.0 / N[(x * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.76:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;\frac{-2}{x \cdot \left(x + -1\right)}\\
\end{array}
\end{array}
if x < 0.76000000000000001Initial program 89.4%
sub-neg89.4%
+-commutative89.4%
distribute-neg-frac289.4%
neg-sub089.4%
associate-+l-89.4%
neg-sub089.4%
remove-double-neg89.4%
distribute-neg-in89.4%
sub-neg89.4%
distribute-neg-frac289.4%
sub-neg89.4%
+-commutative89.4%
unsub-neg89.4%
sub-neg89.4%
+-commutative89.4%
unsub-neg89.4%
metadata-eval89.4%
Simplified89.4%
Taylor expanded in x around 0 69.5%
if 0.76000000000000001 < x Initial program 64.9%
sub-neg64.9%
+-commutative64.9%
distribute-neg-frac264.9%
neg-sub064.9%
associate-+l-64.9%
neg-sub064.9%
remove-double-neg64.9%
distribute-neg-in64.9%
sub-neg64.9%
distribute-neg-frac264.9%
sub-neg64.9%
+-commutative64.9%
unsub-neg64.9%
sub-neg64.9%
+-commutative64.9%
unsub-neg64.9%
metadata-eval64.9%
Simplified64.9%
sub-neg64.9%
distribute-neg-frac64.9%
metadata-eval64.9%
Applied egg-rr64.9%
Simplified97.6%
Taylor expanded in x around inf 95.8%
(FPCore (x) :precision binary64 (/ -2.0 (* (+ x -1.0) (+ x 1.0))))
double code(double x) {
return -2.0 / ((x + -1.0) * (x + 1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-2.0d0) / ((x + (-1.0d0)) * (x + 1.0d0))
end function
public static double code(double x) {
return -2.0 / ((x + -1.0) * (x + 1.0));
}
def code(x): return -2.0 / ((x + -1.0) * (x + 1.0))
function code(x) return Float64(-2.0 / Float64(Float64(x + -1.0) * Float64(x + 1.0))) end
function tmp = code(x) tmp = -2.0 / ((x + -1.0) * (x + 1.0)); end
code[x_] := N[(-2.0 / N[(N[(x + -1.0), $MachinePrecision] * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-2}{\left(x + -1\right) \cdot \left(x + 1\right)}
\end{array}
Initial program 84.6%
sub-neg84.6%
+-commutative84.6%
distribute-neg-frac284.6%
neg-sub084.6%
associate-+l-84.6%
neg-sub084.6%
remove-double-neg84.6%
distribute-neg-in84.6%
sub-neg84.6%
distribute-neg-frac284.6%
sub-neg84.6%
+-commutative84.6%
unsub-neg84.6%
sub-neg84.6%
+-commutative84.6%
unsub-neg84.6%
metadata-eval84.6%
Simplified84.6%
sub-neg84.6%
distribute-neg-frac84.6%
metadata-eval84.6%
Applied egg-rr84.6%
Simplified99.3%
Final simplification99.3%
(FPCore (x) :precision binary64 (/ -2.0 (- -1.0 x)))
double code(double x) {
return -2.0 / (-1.0 - x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-2.0d0) / ((-1.0d0) - x)
end function
public static double code(double x) {
return -2.0 / (-1.0 - x);
}
def code(x): return -2.0 / (-1.0 - x)
function code(x) return Float64(-2.0 / Float64(-1.0 - x)) end
function tmp = code(x) tmp = -2.0 / (-1.0 - x); end
code[x_] := N[(-2.0 / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-2}{-1 - x}
\end{array}
Initial program 84.6%
sub-neg84.6%
+-commutative84.6%
distribute-neg-frac284.6%
neg-sub084.6%
associate-+l-84.6%
neg-sub084.6%
remove-double-neg84.6%
distribute-neg-in84.6%
sub-neg84.6%
distribute-neg-frac284.6%
sub-neg84.6%
+-commutative84.6%
unsub-neg84.6%
sub-neg84.6%
+-commutative84.6%
unsub-neg84.6%
metadata-eval84.6%
Simplified84.6%
frac-sub85.3%
*-rgt-identity85.3%
metadata-eval85.3%
div-inv85.3%
associate-/r*85.3%
metadata-eval85.3%
div-inv85.3%
*-un-lft-identity85.3%
associate--l-87.4%
div-inv87.4%
metadata-eval87.4%
*-rgt-identity87.4%
div-inv87.4%
metadata-eval87.4%
*-rgt-identity87.4%
Applied egg-rr87.4%
Taylor expanded in x around 0 57.5%
(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 84.6%
sub-neg84.6%
+-commutative84.6%
distribute-neg-frac284.6%
neg-sub084.6%
associate-+l-84.6%
neg-sub084.6%
remove-double-neg84.6%
distribute-neg-in84.6%
sub-neg84.6%
distribute-neg-frac284.6%
sub-neg84.6%
+-commutative84.6%
unsub-neg84.6%
sub-neg84.6%
+-commutative84.6%
unsub-neg84.6%
metadata-eval84.6%
Simplified84.6%
Taylor expanded in x around 0 56.5%
(FPCore (x) :precision binary64 1.0)
double code(double x) {
return 1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0
end function
public static double code(double x) {
return 1.0;
}
def code(x): return 1.0
function code(x) return 1.0 end
function tmp = code(x) tmp = 1.0; end
code[x_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 84.6%
sub-neg84.6%
+-commutative84.6%
distribute-neg-frac284.6%
neg-sub084.6%
associate-+l-84.6%
neg-sub084.6%
remove-double-neg84.6%
distribute-neg-in84.6%
sub-neg84.6%
distribute-neg-frac284.6%
sub-neg84.6%
+-commutative84.6%
unsub-neg84.6%
sub-neg84.6%
+-commutative84.6%
unsub-neg84.6%
metadata-eval84.6%
Simplified84.6%
Taylor expanded in x around 0 55.9%
Taylor expanded in x around inf 11.7%
herbie shell --seed 2024123
(FPCore (x)
:name "Asymptote A"
:precision binary64
(- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))