
(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 5 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 (* (- 1.0 x) (- -1.0 x))))
double code(double x) {
return -2.0 / ((1.0 - x) * (-1.0 - x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-2.0d0) / ((1.0d0 - x) * ((-1.0d0) - x))
end function
public static double code(double x) {
return -2.0 / ((1.0 - x) * (-1.0 - x));
}
def code(x): return -2.0 / ((1.0 - x) * (-1.0 - x))
function code(x) return Float64(-2.0 / Float64(Float64(1.0 - x) * Float64(-1.0 - x))) end
function tmp = code(x) tmp = -2.0 / ((1.0 - x) * (-1.0 - x)); end
code[x_] := N[(-2.0 / N[(N[(1.0 - x), $MachinePrecision] * N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-2}{\left(1 - x\right) \cdot \left(-1 - x\right)}
\end{array}
Initial program 74.6%
sub-neg74.6%
+-commutative74.6%
distribute-neg-frac274.6%
neg-sub074.6%
associate-+l-74.6%
neg-sub074.6%
remove-double-neg74.6%
distribute-neg-in74.6%
sub-neg74.6%
distribute-neg-frac274.6%
sub-neg74.6%
+-commutative74.6%
unsub-neg74.6%
sub-neg74.6%
+-commutative74.6%
unsub-neg74.6%
metadata-eval74.6%
Simplified74.6%
sub-neg74.6%
distribute-neg-frac74.6%
metadata-eval74.6%
Applied egg-rr74.6%
Simplified99.5%
Final simplification99.5%
(FPCore (x) :precision binary64 (if (<= x 0.75) 2.0 (/ -2.0 (* x (+ x -1.0)))))
double code(double x) {
double tmp;
if (x <= 0.75) {
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.75d0) 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.75) {
tmp = 2.0;
} else {
tmp = -2.0 / (x * (x + -1.0));
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.75: tmp = 2.0 else: tmp = -2.0 / (x * (x + -1.0)) return tmp
function code(x) tmp = 0.0 if (x <= 0.75) 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.75) tmp = 2.0; else tmp = -2.0 / (x * (x + -1.0)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.75], 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.75:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;\frac{-2}{x \cdot \left(x + -1\right)}\\
\end{array}
\end{array}
if x < 0.75Initial program 82.9%
sub-neg82.9%
+-commutative82.9%
distribute-neg-frac282.9%
neg-sub082.9%
associate-+l-82.9%
neg-sub082.9%
remove-double-neg82.9%
distribute-neg-in82.9%
sub-neg82.9%
distribute-neg-frac282.9%
sub-neg82.9%
+-commutative82.9%
unsub-neg82.9%
sub-neg82.9%
+-commutative82.9%
unsub-neg82.9%
metadata-eval82.9%
Simplified82.9%
Taylor expanded in x around 0 64.9%
if 0.75 < x Initial program 49.3%
sub-neg49.3%
+-commutative49.3%
distribute-neg-frac249.3%
neg-sub049.3%
associate-+l-49.3%
neg-sub049.3%
remove-double-neg49.3%
distribute-neg-in49.3%
sub-neg49.3%
distribute-neg-frac249.3%
sub-neg49.3%
+-commutative49.3%
unsub-neg49.3%
sub-neg49.3%
+-commutative49.3%
unsub-neg49.3%
metadata-eval49.3%
Simplified49.3%
sub-neg49.3%
distribute-neg-frac49.3%
metadata-eval49.3%
Applied egg-rr49.3%
Simplified99.7%
flip3--45.0%
associate-*r/34.4%
metadata-eval34.4%
metadata-eval34.4%
distribute-rgt-out34.4%
Applied egg-rr34.4%
associate-/l*45.0%
Simplified45.0%
Taylor expanded in x around inf 98.3%
neg-mul-198.3%
Simplified98.3%
Taylor expanded in x around 0 98.3%
Final simplification73.1%
(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 82.9%
sub-neg82.9%
+-commutative82.9%
distribute-neg-frac282.9%
neg-sub082.9%
associate-+l-82.9%
neg-sub082.9%
remove-double-neg82.9%
distribute-neg-in82.9%
sub-neg82.9%
distribute-neg-frac282.9%
sub-neg82.9%
+-commutative82.9%
unsub-neg82.9%
sub-neg82.9%
+-commutative82.9%
unsub-neg82.9%
metadata-eval82.9%
Simplified82.9%
Taylor expanded in x around 0 64.9%
if 1 < x Initial program 49.3%
sub-neg49.3%
+-commutative49.3%
distribute-neg-frac249.3%
neg-sub049.3%
associate-+l-49.3%
neg-sub049.3%
remove-double-neg49.3%
distribute-neg-in49.3%
sub-neg49.3%
distribute-neg-frac249.3%
sub-neg49.3%
+-commutative49.3%
unsub-neg49.3%
sub-neg49.3%
+-commutative49.3%
unsub-neg49.3%
metadata-eval49.3%
Simplified49.3%
frac-sub50.4%
*-rgt-identity50.4%
metadata-eval50.4%
div-inv50.4%
associate-/r*50.4%
metadata-eval50.4%
div-inv50.4%
*-un-lft-identity50.4%
associate--l-57.5%
div-inv57.5%
metadata-eval57.5%
*-rgt-identity57.5%
div-inv57.5%
metadata-eval57.5%
*-rgt-identity57.5%
Applied egg-rr57.5%
Taylor expanded in x around inf 98.3%
Final simplification73.1%
(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 82.9%
sub-neg82.9%
+-commutative82.9%
distribute-neg-frac282.9%
neg-sub082.9%
associate-+l-82.9%
neg-sub082.9%
remove-double-neg82.9%
distribute-neg-in82.9%
sub-neg82.9%
distribute-neg-frac282.9%
sub-neg82.9%
+-commutative82.9%
unsub-neg82.9%
sub-neg82.9%
+-commutative82.9%
unsub-neg82.9%
metadata-eval82.9%
Simplified82.9%
Taylor expanded in x around 0 64.9%
if 1 < x Initial program 49.3%
sub-neg49.3%
+-commutative49.3%
distribute-neg-frac249.3%
neg-sub049.3%
associate-+l-49.3%
neg-sub049.3%
remove-double-neg49.3%
distribute-neg-in49.3%
sub-neg49.3%
distribute-neg-frac249.3%
sub-neg49.3%
+-commutative49.3%
unsub-neg49.3%
sub-neg49.3%
+-commutative49.3%
unsub-neg49.3%
metadata-eval49.3%
Simplified49.3%
flip--8.1%
metadata-eval8.1%
metadata-eval8.1%
associate-/r/8.1%
metadata-eval8.1%
pow28.1%
Applied egg-rr8.1%
associate-*l/8.2%
*-lft-identity8.2%
+-commutative8.2%
Simplified8.2%
clear-num8.1%
metadata-eval8.1%
unpow28.1%
+-commutative8.1%
flip--49.3%
frac-sub50.4%
*-commutative50.4%
distribute-lft-out--50.4%
associate--r+57.5%
flip--54.3%
*-un-lft-identity54.3%
associate-/l/54.3%
Applied egg-rr0.0%
div-sub0.0%
unpow20.0%
+-inverses0.0%
metadata-eval0.0%
+-inverses0.0%
metadata-eval0.0%
metadata-eval0.0%
+-inverses47.0%
Simplified47.0%
Final simplification60.5%
(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 74.6%
sub-neg74.6%
+-commutative74.6%
distribute-neg-frac274.6%
neg-sub074.6%
associate-+l-74.6%
neg-sub074.6%
remove-double-neg74.6%
distribute-neg-in74.6%
sub-neg74.6%
distribute-neg-frac274.6%
sub-neg74.6%
+-commutative74.6%
unsub-neg74.6%
sub-neg74.6%
+-commutative74.6%
unsub-neg74.6%
metadata-eval74.6%
Simplified74.6%
flip--53.5%
metadata-eval53.5%
metadata-eval53.5%
associate-/r/53.4%
metadata-eval53.4%
pow253.4%
Applied egg-rr53.4%
associate-*l/53.6%
*-lft-identity53.6%
+-commutative53.6%
Simplified53.6%
clear-num53.5%
metadata-eval53.5%
unpow253.5%
+-commutative53.5%
flip--74.6%
frac-sub75.0%
*-commutative75.0%
distribute-lft-out--75.0%
associate--r+78.4%
flip--28.4%
*-un-lft-identity28.4%
associate-/l/28.4%
Applied egg-rr0.0%
div-sub0.0%
unpow20.0%
+-inverses0.0%
metadata-eval0.0%
+-inverses0.0%
metadata-eval0.0%
metadata-eval0.0%
+-inverses25.7%
Simplified25.7%
Final simplification25.7%
herbie shell --seed 2024074
(FPCore (x)
:name "Asymptote A"
:precision binary64
(- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))