
(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 (* (- 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.5%
sub-neg74.5%
+-commutative74.5%
distribute-neg-frac274.5%
neg-sub074.5%
associate-+l-74.5%
neg-sub074.5%
remove-double-neg74.5%
distribute-neg-in74.5%
sub-neg74.5%
distribute-neg-frac274.5%
sub-neg74.5%
+-commutative74.5%
unsub-neg74.5%
sub-neg74.5%
+-commutative74.5%
unsub-neg74.5%
metadata-eval74.5%
Simplified74.5%
sub-neg74.5%
distribute-neg-frac74.5%
metadata-eval74.5%
Applied egg-rr74.5%
Simplified99.1%
Final simplification99.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(2.0 / Float64(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[(2.0 / N[(x * N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{x \cdot \left(-1 - x\right)}\\
\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 63.1%
if 1 < x Initial program 52.8%
sub-neg52.8%
+-commutative52.8%
distribute-neg-frac252.8%
neg-sub052.8%
associate-+l-52.8%
neg-sub052.8%
remove-double-neg52.8%
distribute-neg-in52.8%
sub-neg52.8%
distribute-neg-frac252.8%
sub-neg52.8%
+-commutative52.8%
unsub-neg52.8%
sub-neg52.8%
+-commutative52.8%
unsub-neg52.8%
metadata-eval52.8%
Simplified52.8%
frac-sub55.0%
*-rgt-identity55.0%
metadata-eval55.0%
div-inv55.0%
associate-/r*55.0%
metadata-eval55.0%
div-inv55.0%
*-un-lft-identity55.0%
associate--l-61.4%
div-inv61.4%
metadata-eval61.4%
*-rgt-identity61.4%
div-inv61.4%
metadata-eval61.4%
*-rgt-identity61.4%
Applied egg-rr61.4%
Taylor expanded in x around inf 96.7%
*-un-lft-identity96.7%
associate-/l/96.0%
*-commutative96.0%
Applied egg-rr96.0%
*-lft-identity96.0%
Simplified96.0%
Final simplification72.2%
(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 63.1%
if 1 < x Initial program 52.8%
sub-neg52.8%
+-commutative52.8%
distribute-neg-frac252.8%
neg-sub052.8%
associate-+l-52.8%
neg-sub052.8%
remove-double-neg52.8%
distribute-neg-in52.8%
sub-neg52.8%
distribute-neg-frac252.8%
sub-neg52.8%
+-commutative52.8%
unsub-neg52.8%
sub-neg52.8%
+-commutative52.8%
unsub-neg52.8%
metadata-eval52.8%
Simplified52.8%
frac-sub55.0%
*-rgt-identity55.0%
metadata-eval55.0%
div-inv55.0%
associate-/r*55.0%
metadata-eval55.0%
div-inv55.0%
*-un-lft-identity55.0%
associate--l-61.4%
div-inv61.4%
metadata-eval61.4%
*-rgt-identity61.4%
div-inv61.4%
metadata-eval61.4%
*-rgt-identity61.4%
Applied egg-rr61.4%
Taylor expanded in x around inf 96.7%
Final simplification72.4%
(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 63.1%
if 1 < x Initial program 52.8%
sub-neg52.8%
+-commutative52.8%
distribute-neg-frac252.8%
neg-sub052.8%
associate-+l-52.8%
neg-sub052.8%
remove-double-neg52.8%
distribute-neg-in52.8%
sub-neg52.8%
distribute-neg-frac252.8%
sub-neg52.8%
+-commutative52.8%
unsub-neg52.8%
sub-neg52.8%
+-commutative52.8%
unsub-neg52.8%
metadata-eval52.8%
Simplified52.8%
frac-sub55.0%
*-rgt-identity55.0%
metadata-eval55.0%
div-inv55.0%
associate-/r*55.0%
metadata-eval55.0%
div-inv55.0%
*-un-lft-identity55.0%
associate--l-61.4%
div-inv61.4%
metadata-eval61.4%
*-rgt-identity61.4%
div-inv61.4%
metadata-eval61.4%
*-rgt-identity61.4%
Applied egg-rr61.4%
Applied egg-rr48.2%
+-inverses48.2%
Simplified48.2%
Final simplification59.0%
(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 74.5%
sub-neg74.5%
+-commutative74.5%
distribute-neg-frac274.5%
neg-sub074.5%
associate-+l-74.5%
neg-sub074.5%
remove-double-neg74.5%
distribute-neg-in74.5%
sub-neg74.5%
distribute-neg-frac274.5%
sub-neg74.5%
+-commutative74.5%
unsub-neg74.5%
sub-neg74.5%
+-commutative74.5%
unsub-neg74.5%
metadata-eval74.5%
Simplified74.5%
sub-neg74.5%
distribute-neg-frac74.5%
metadata-eval74.5%
Applied egg-rr74.5%
Simplified99.1%
Applied egg-rr53.4%
Taylor expanded in x around 0 3.1%
Final simplification3.1%
(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.5%
sub-neg74.5%
+-commutative74.5%
distribute-neg-frac274.5%
neg-sub074.5%
associate-+l-74.5%
neg-sub074.5%
remove-double-neg74.5%
distribute-neg-in74.5%
sub-neg74.5%
distribute-neg-frac274.5%
sub-neg74.5%
+-commutative74.5%
unsub-neg74.5%
sub-neg74.5%
+-commutative74.5%
unsub-neg74.5%
metadata-eval74.5%
Simplified74.5%
frac-sub75.9%
*-rgt-identity75.9%
metadata-eval75.9%
div-inv75.9%
associate-/r*75.9%
metadata-eval75.9%
div-inv75.9%
*-un-lft-identity75.9%
associate--l-79.2%
div-inv79.2%
metadata-eval79.2%
*-rgt-identity79.2%
div-inv79.2%
metadata-eval79.2%
*-rgt-identity79.2%
Applied egg-rr79.2%
Applied egg-rr27.9%
+-inverses27.9%
Simplified27.9%
Final simplification27.9%
herbie shell --seed 2024075
(FPCore (x)
:name "Asymptote A"
:precision binary64
(- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))