
(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 7 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(-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 76.9%
sub-neg76.9%
+-commutative76.9%
distribute-neg-frac276.9%
neg-sub076.9%
associate-+l-76.9%
neg-sub076.9%
remove-double-neg76.9%
distribute-neg-in76.9%
sub-neg76.9%
distribute-neg-frac276.9%
sub-neg76.9%
+-commutative76.9%
unsub-neg76.9%
sub-neg76.9%
+-commutative76.9%
unsub-neg76.9%
metadata-eval76.9%
Simplified76.9%
sub-neg76.9%
distribute-neg-frac76.9%
metadata-eval76.9%
Applied egg-rr76.9%
Simplified98.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 85.4%
sub-neg85.4%
+-commutative85.4%
distribute-neg-frac285.4%
neg-sub085.4%
associate-+l-85.4%
neg-sub085.4%
remove-double-neg85.4%
distribute-neg-in85.4%
sub-neg85.4%
distribute-neg-frac285.4%
sub-neg85.4%
+-commutative85.4%
unsub-neg85.4%
sub-neg85.4%
+-commutative85.4%
unsub-neg85.4%
metadata-eval85.4%
Simplified85.4%
Taylor expanded in x around 0 65.5%
if 1 < x Initial program 56.1%
sub-neg56.1%
+-commutative56.1%
distribute-neg-frac256.1%
neg-sub056.1%
associate-+l-56.1%
neg-sub056.1%
remove-double-neg56.1%
distribute-neg-in56.1%
sub-neg56.1%
distribute-neg-frac256.1%
sub-neg56.1%
+-commutative56.1%
unsub-neg56.1%
sub-neg56.1%
+-commutative56.1%
unsub-neg56.1%
metadata-eval56.1%
Simplified56.1%
frac-sub56.6%
*-rgt-identity56.6%
metadata-eval56.6%
div-inv56.6%
associate-/r*56.6%
metadata-eval56.6%
div-inv56.6%
*-un-lft-identity56.6%
associate--l-62.3%
div-inv62.3%
metadata-eval62.3%
*-rgt-identity62.3%
div-inv62.3%
metadata-eval62.3%
*-rgt-identity62.3%
Applied egg-rr62.3%
Taylor expanded in x around inf 97.3%
(FPCore (x) :precision binary64 (if (<= x 0.78) 2.0 (/ -2.0 (* x (+ x -1.0)))))
double code(double x) {
double tmp;
if (x <= 0.78) {
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.78d0) 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.78) {
tmp = 2.0;
} else {
tmp = -2.0 / (x * (x + -1.0));
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.78: tmp = 2.0 else: tmp = -2.0 / (x * (x + -1.0)) return tmp
function code(x) tmp = 0.0 if (x <= 0.78) 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.78) tmp = 2.0; else tmp = -2.0 / (x * (x + -1.0)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.78], 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.78:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;\frac{-2}{x \cdot \left(x + -1\right)}\\
\end{array}
\end{array}
if x < 0.78000000000000003Initial program 85.4%
sub-neg85.4%
+-commutative85.4%
distribute-neg-frac285.4%
neg-sub085.4%
associate-+l-85.4%
neg-sub085.4%
remove-double-neg85.4%
distribute-neg-in85.4%
sub-neg85.4%
distribute-neg-frac285.4%
sub-neg85.4%
+-commutative85.4%
unsub-neg85.4%
sub-neg85.4%
+-commutative85.4%
unsub-neg85.4%
metadata-eval85.4%
Simplified85.4%
Taylor expanded in x around 0 65.5%
if 0.78000000000000003 < x Initial program 56.1%
sub-neg56.1%
+-commutative56.1%
distribute-neg-frac256.1%
neg-sub056.1%
associate-+l-56.1%
neg-sub056.1%
remove-double-neg56.1%
distribute-neg-in56.1%
sub-neg56.1%
distribute-neg-frac256.1%
sub-neg56.1%
+-commutative56.1%
unsub-neg56.1%
sub-neg56.1%
+-commutative56.1%
unsub-neg56.1%
metadata-eval56.1%
Simplified56.1%
sub-neg56.1%
distribute-neg-frac56.1%
metadata-eval56.1%
Applied egg-rr56.1%
Simplified97.2%
Taylor expanded in x around inf 94.6%
(FPCore (x) :precision binary64 (if (<= x 1.0) 2.0 (/ -2.0 (+ x 1.0))))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 2.0;
} else {
tmp = -2.0 / (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 + 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 + 1.0);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.0: tmp = 2.0 else: tmp = -2.0 / (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 + 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 + 1.0); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.0], 2.0, N[(-2.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;\frac{-2}{x + 1}\\
\end{array}
\end{array}
if x < 1Initial program 85.4%
sub-neg85.4%
+-commutative85.4%
distribute-neg-frac285.4%
neg-sub085.4%
associate-+l-85.4%
neg-sub085.4%
remove-double-neg85.4%
distribute-neg-in85.4%
sub-neg85.4%
distribute-neg-frac285.4%
sub-neg85.4%
+-commutative85.4%
unsub-neg85.4%
sub-neg85.4%
+-commutative85.4%
unsub-neg85.4%
metadata-eval85.4%
Simplified85.4%
Taylor expanded in x around 0 65.5%
if 1 < x Initial program 56.1%
sub-neg56.1%
+-commutative56.1%
distribute-neg-frac256.1%
neg-sub056.1%
associate-+l-56.1%
neg-sub056.1%
remove-double-neg56.1%
distribute-neg-in56.1%
sub-neg56.1%
distribute-neg-frac256.1%
sub-neg56.1%
+-commutative56.1%
unsub-neg56.1%
sub-neg56.1%
+-commutative56.1%
unsub-neg56.1%
metadata-eval56.1%
Simplified56.1%
frac-sub56.6%
*-rgt-identity56.6%
metadata-eval56.6%
div-inv56.6%
associate-/r*56.6%
metadata-eval56.6%
div-inv56.6%
*-un-lft-identity56.6%
associate--l-62.3%
div-inv62.3%
metadata-eval62.3%
*-rgt-identity62.3%
div-inv62.3%
metadata-eval62.3%
*-rgt-identity62.3%
Applied egg-rr62.3%
Taylor expanded in x around 0 4.9%
Applied egg-rr7.0%
*-lft-identity7.0%
Simplified7.0%
(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 85.4%
sub-neg85.4%
+-commutative85.4%
distribute-neg-frac285.4%
neg-sub085.4%
associate-+l-85.4%
neg-sub085.4%
remove-double-neg85.4%
distribute-neg-in85.4%
sub-neg85.4%
distribute-neg-frac285.4%
sub-neg85.4%
+-commutative85.4%
unsub-neg85.4%
sub-neg85.4%
+-commutative85.4%
unsub-neg85.4%
metadata-eval85.4%
Simplified85.4%
Taylor expanded in x around 0 65.5%
if 1 < x Initial program 56.1%
sub-neg56.1%
+-commutative56.1%
distribute-neg-frac256.1%
neg-sub056.1%
associate-+l-56.1%
neg-sub056.1%
remove-double-neg56.1%
distribute-neg-in56.1%
sub-neg56.1%
distribute-neg-frac256.1%
sub-neg56.1%
+-commutative56.1%
unsub-neg56.1%
sub-neg56.1%
+-commutative56.1%
unsub-neg56.1%
metadata-eval56.1%
Simplified56.1%
frac-sub56.6%
*-rgt-identity56.6%
metadata-eval56.6%
div-inv56.6%
associate-/r*56.6%
metadata-eval56.6%
div-inv56.6%
*-un-lft-identity56.6%
associate--l-62.3%
div-inv62.3%
metadata-eval62.3%
*-rgt-identity62.3%
div-inv62.3%
metadata-eval62.3%
*-rgt-identity62.3%
Applied egg-rr62.3%
Taylor expanded in x around inf 97.3%
Taylor expanded in x around 0 7.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 76.9%
sub-neg76.9%
+-commutative76.9%
distribute-neg-frac276.9%
neg-sub076.9%
associate-+l-76.9%
neg-sub076.9%
remove-double-neg76.9%
distribute-neg-in76.9%
sub-neg76.9%
distribute-neg-frac276.9%
sub-neg76.9%
+-commutative76.9%
unsub-neg76.9%
sub-neg76.9%
+-commutative76.9%
unsub-neg76.9%
metadata-eval76.9%
Simplified76.9%
Taylor expanded in x around 0 47.4%
(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 76.9%
sub-neg76.9%
+-commutative76.9%
distribute-neg-frac276.9%
neg-sub076.9%
associate-+l-76.9%
neg-sub076.9%
remove-double-neg76.9%
distribute-neg-in76.9%
sub-neg76.9%
distribute-neg-frac276.9%
sub-neg76.9%
+-commutative76.9%
unsub-neg76.9%
sub-neg76.9%
+-commutative76.9%
unsub-neg76.9%
metadata-eval76.9%
Simplified76.9%
Taylor expanded in x around 0 46.8%
Taylor expanded in x around inf 10.2%
herbie shell --seed 2024135
(FPCore (x)
:name "Asymptote A"
:precision binary64
(- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))