
(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 (- (+ 1.0 (* x (- 1.0 x))) x)))
double code(double x) {
return 2.0 / ((1.0 + (x * (1.0 - x))) - x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0 / ((1.0d0 + (x * (1.0d0 - x))) - x)
end function
public static double code(double x) {
return 2.0 / ((1.0 + (x * (1.0 - x))) - x);
}
def code(x): return 2.0 / ((1.0 + (x * (1.0 - x))) - x)
function code(x) return Float64(2.0 / Float64(Float64(1.0 + Float64(x * Float64(1.0 - x))) - x)) end
function tmp = code(x) tmp = 2.0 / ((1.0 + (x * (1.0 - x))) - x); end
code[x_] := N[(2.0 / N[(N[(1.0 + N[(x * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{\left(1 + x \cdot \left(1 - x\right)\right) - x}
\end{array}
Initial program 74.8%
sub-neg74.8%
+-commutative74.8%
distribute-neg-frac274.8%
neg-sub074.8%
associate-+l-74.8%
neg-sub074.8%
remove-double-neg74.8%
distribute-neg-in74.8%
sub-neg74.8%
distribute-neg-frac274.8%
sub-neg74.8%
+-commutative74.8%
unsub-neg74.8%
sub-neg74.8%
+-commutative74.8%
unsub-neg74.8%
metadata-eval74.8%
Simplified74.8%
sub-neg74.8%
distribute-neg-frac74.8%
metadata-eval74.8%
Applied egg-rr74.8%
*-rgt-identity74.8%
fma-undefine74.8%
*-inverses74.8%
*-lft-identity74.8%
*-inverses74.8%
distribute-frac-neg74.8%
distribute-lft-neg-in74.8%
times-frac55.5%
distribute-lft-neg-out55.5%
distribute-rgt-neg-out55.5%
fma-neg55.5%
Simplified99.6%
distribute-rgt-in99.6%
*-un-lft-identity99.6%
associate-+r-99.6%
Applied egg-rr99.6%
Final simplification99.6%
(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 84.0%
sub-neg84.0%
+-commutative84.0%
distribute-neg-frac284.0%
neg-sub084.0%
associate-+l-84.0%
neg-sub084.0%
remove-double-neg84.0%
distribute-neg-in84.0%
sub-neg84.0%
distribute-neg-frac284.0%
sub-neg84.0%
+-commutative84.0%
unsub-neg84.0%
sub-neg84.0%
+-commutative84.0%
unsub-neg84.0%
metadata-eval84.0%
Simplified84.0%
Taylor expanded in x around 0 66.7%
if 1 < x Initial program 46.0%
sub-neg46.0%
+-commutative46.0%
distribute-neg-frac246.0%
neg-sub046.0%
associate-+l-46.0%
neg-sub046.0%
remove-double-neg46.0%
distribute-neg-in46.0%
sub-neg46.0%
distribute-neg-frac246.0%
sub-neg46.0%
+-commutative46.0%
unsub-neg46.0%
sub-neg46.0%
+-commutative46.0%
unsub-neg46.0%
metadata-eval46.0%
Simplified46.0%
frac-sub48.2%
*-rgt-identity48.2%
metadata-eval48.2%
div-inv48.2%
associate-/r*48.2%
*-un-lft-identity48.2%
metadata-eval48.2%
div-inv48.2%
associate--l-55.3%
div-inv55.3%
metadata-eval55.3%
*-rgt-identity55.3%
div-inv55.3%
metadata-eval55.3%
*-rgt-identity55.3%
Applied egg-rr55.3%
Taylor expanded in x around inf 98.1%
*-un-lft-identity98.1%
associate-/l/98.0%
Applied egg-rr98.0%
*-lft-identity98.0%
*-commutative98.0%
Simplified98.0%
Final simplification74.3%
(FPCore (x) :precision binary64 (if (<= x 1.0) (/ 2.0 (- (+ x 1.0) x)) (/ 2.0 (* x (- -1.0 x)))))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 2.0 / ((x + 1.0) - x);
} 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 / ((x + 1.0d0) - x)
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 / ((x + 1.0) - x);
} else {
tmp = 2.0 / (x * (-1.0 - x));
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.0: tmp = 2.0 / ((x + 1.0) - x) else: tmp = 2.0 / (x * (-1.0 - x)) return tmp
function code(x) tmp = 0.0 if (x <= 1.0) tmp = Float64(2.0 / Float64(Float64(x + 1.0) - x)); 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 / ((x + 1.0) - x); else tmp = 2.0 / (x * (-1.0 - x)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.0], N[(2.0 / N[(N[(x + 1.0), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision], N[(2.0 / N[(x * N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;\frac{2}{\left(x + 1\right) - x}\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{x \cdot \left(-1 - x\right)}\\
\end{array}
\end{array}
if x < 1Initial program 84.0%
sub-neg84.0%
+-commutative84.0%
distribute-neg-frac284.0%
neg-sub084.0%
associate-+l-84.0%
neg-sub084.0%
remove-double-neg84.0%
distribute-neg-in84.0%
sub-neg84.0%
distribute-neg-frac284.0%
sub-neg84.0%
+-commutative84.0%
unsub-neg84.0%
sub-neg84.0%
+-commutative84.0%
unsub-neg84.0%
metadata-eval84.0%
Simplified84.0%
sub-neg84.0%
distribute-neg-frac84.0%
metadata-eval84.0%
Applied egg-rr84.0%
*-rgt-identity84.0%
fma-undefine84.0%
*-inverses84.0%
*-lft-identity84.0%
*-inverses84.0%
distribute-frac-neg84.0%
distribute-lft-neg-in84.0%
times-frac70.4%
distribute-lft-neg-out70.4%
distribute-rgt-neg-out70.4%
fma-neg70.4%
Simplified99.6%
distribute-rgt-in99.6%
*-un-lft-identity99.6%
associate-+r-99.6%
Applied egg-rr99.6%
Taylor expanded in x around 0 66.3%
if 1 < x Initial program 46.0%
sub-neg46.0%
+-commutative46.0%
distribute-neg-frac246.0%
neg-sub046.0%
associate-+l-46.0%
neg-sub046.0%
remove-double-neg46.0%
distribute-neg-in46.0%
sub-neg46.0%
distribute-neg-frac246.0%
sub-neg46.0%
+-commutative46.0%
unsub-neg46.0%
sub-neg46.0%
+-commutative46.0%
unsub-neg46.0%
metadata-eval46.0%
Simplified46.0%
frac-sub48.2%
*-rgt-identity48.2%
metadata-eval48.2%
div-inv48.2%
associate-/r*48.2%
*-un-lft-identity48.2%
metadata-eval48.2%
div-inv48.2%
associate--l-55.3%
div-inv55.3%
metadata-eval55.3%
*-rgt-identity55.3%
div-inv55.3%
metadata-eval55.3%
*-rgt-identity55.3%
Applied egg-rr55.3%
Taylor expanded in x around inf 98.1%
*-un-lft-identity98.1%
associate-/l/98.0%
Applied egg-rr98.0%
*-lft-identity98.0%
*-commutative98.0%
Simplified98.0%
Final simplification74.0%
(FPCore (x) :precision binary64 (if (<= x 1.0) (/ 2.0 (- (+ x 1.0) x)) (/ (/ 2.0 x) (- -1.0 x))))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 2.0 / ((x + 1.0) - x);
} 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 / ((x + 1.0d0) - x)
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 / ((x + 1.0) - x);
} else {
tmp = (2.0 / x) / (-1.0 - x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.0: tmp = 2.0 / ((x + 1.0) - x) else: tmp = (2.0 / x) / (-1.0 - x) return tmp
function code(x) tmp = 0.0 if (x <= 1.0) tmp = Float64(2.0 / Float64(Float64(x + 1.0) - x)); 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 / ((x + 1.0) - x); else tmp = (2.0 / x) / (-1.0 - x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.0], N[(2.0 / N[(N[(x + 1.0), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 / x), $MachinePrecision] / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;\frac{2}{\left(x + 1\right) - x}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{2}{x}}{-1 - x}\\
\end{array}
\end{array}
if x < 1Initial program 84.0%
sub-neg84.0%
+-commutative84.0%
distribute-neg-frac284.0%
neg-sub084.0%
associate-+l-84.0%
neg-sub084.0%
remove-double-neg84.0%
distribute-neg-in84.0%
sub-neg84.0%
distribute-neg-frac284.0%
sub-neg84.0%
+-commutative84.0%
unsub-neg84.0%
sub-neg84.0%
+-commutative84.0%
unsub-neg84.0%
metadata-eval84.0%
Simplified84.0%
sub-neg84.0%
distribute-neg-frac84.0%
metadata-eval84.0%
Applied egg-rr84.0%
*-rgt-identity84.0%
fma-undefine84.0%
*-inverses84.0%
*-lft-identity84.0%
*-inverses84.0%
distribute-frac-neg84.0%
distribute-lft-neg-in84.0%
times-frac70.4%
distribute-lft-neg-out70.4%
distribute-rgt-neg-out70.4%
fma-neg70.4%
Simplified99.6%
distribute-rgt-in99.6%
*-un-lft-identity99.6%
associate-+r-99.6%
Applied egg-rr99.6%
Taylor expanded in x around 0 66.3%
if 1 < x Initial program 46.0%
sub-neg46.0%
+-commutative46.0%
distribute-neg-frac246.0%
neg-sub046.0%
associate-+l-46.0%
neg-sub046.0%
remove-double-neg46.0%
distribute-neg-in46.0%
sub-neg46.0%
distribute-neg-frac246.0%
sub-neg46.0%
+-commutative46.0%
unsub-neg46.0%
sub-neg46.0%
+-commutative46.0%
unsub-neg46.0%
metadata-eval46.0%
Simplified46.0%
frac-sub48.2%
*-rgt-identity48.2%
metadata-eval48.2%
div-inv48.2%
associate-/r*48.2%
*-un-lft-identity48.2%
metadata-eval48.2%
div-inv48.2%
associate--l-55.3%
div-inv55.3%
metadata-eval55.3%
*-rgt-identity55.3%
div-inv55.3%
metadata-eval55.3%
*-rgt-identity55.3%
Applied egg-rr55.3%
Taylor expanded in x around inf 98.1%
Final simplification74.0%
(FPCore (x) :precision binary64 (/ 2.0 (* (- 1.0 x) (+ x 1.0))))
double code(double x) {
return 2.0 / ((1.0 - x) * (x + 1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0 / ((1.0d0 - x) * (x + 1.0d0))
end function
public static double code(double x) {
return 2.0 / ((1.0 - x) * (x + 1.0));
}
def code(x): return 2.0 / ((1.0 - x) * (x + 1.0))
function code(x) return Float64(2.0 / Float64(Float64(1.0 - x) * Float64(x + 1.0))) end
function tmp = code(x) tmp = 2.0 / ((1.0 - x) * (x + 1.0)); end
code[x_] := N[(2.0 / N[(N[(1.0 - x), $MachinePrecision] * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{\left(1 - x\right) \cdot \left(x + 1\right)}
\end{array}
Initial program 74.8%
sub-neg74.8%
+-commutative74.8%
distribute-neg-frac274.8%
neg-sub074.8%
associate-+l-74.8%
neg-sub074.8%
remove-double-neg74.8%
distribute-neg-in74.8%
sub-neg74.8%
distribute-neg-frac274.8%
sub-neg74.8%
+-commutative74.8%
unsub-neg74.8%
sub-neg74.8%
+-commutative74.8%
unsub-neg74.8%
metadata-eval74.8%
Simplified74.8%
sub-neg74.8%
distribute-neg-frac74.8%
metadata-eval74.8%
Applied egg-rr74.8%
*-rgt-identity74.8%
fma-undefine74.8%
*-inverses74.8%
*-lft-identity74.8%
*-inverses74.8%
distribute-frac-neg74.8%
distribute-lft-neg-in74.8%
times-frac55.5%
distribute-lft-neg-out55.5%
distribute-rgt-neg-out55.5%
fma-neg55.5%
Simplified99.6%
Final simplification99.6%
(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.0%
sub-neg84.0%
+-commutative84.0%
distribute-neg-frac284.0%
neg-sub084.0%
associate-+l-84.0%
neg-sub084.0%
remove-double-neg84.0%
distribute-neg-in84.0%
sub-neg84.0%
distribute-neg-frac284.0%
sub-neg84.0%
+-commutative84.0%
unsub-neg84.0%
sub-neg84.0%
+-commutative84.0%
unsub-neg84.0%
metadata-eval84.0%
Simplified84.0%
Taylor expanded in x around 0 66.7%
if 1 < x Initial program 46.0%
sub-neg46.0%
+-commutative46.0%
distribute-neg-frac246.0%
neg-sub046.0%
associate-+l-46.0%
neg-sub046.0%
remove-double-neg46.0%
distribute-neg-in46.0%
sub-neg46.0%
distribute-neg-frac246.0%
sub-neg46.0%
+-commutative46.0%
unsub-neg46.0%
sub-neg46.0%
+-commutative46.0%
unsub-neg46.0%
metadata-eval46.0%
Simplified46.0%
flip--8.7%
metadata-eval8.7%
metadata-eval8.7%
associate-/r/8.7%
metadata-eval8.7%
pow28.7%
Applied egg-rr8.7%
associate-*l/8.6%
*-lft-identity8.6%
+-commutative8.6%
Simplified8.6%
Applied egg-rr0.0%
div-sub0.0%
unpow20.0%
+-inverses0.0%
metadata-eval0.0%
+-inverses0.0%
metadata-eval0.0%
metadata-eval0.0%
+-inverses43.5%
Simplified43.5%
Final simplification61.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.8%
sub-neg74.8%
+-commutative74.8%
distribute-neg-frac274.8%
neg-sub074.8%
associate-+l-74.8%
neg-sub074.8%
remove-double-neg74.8%
distribute-neg-in74.8%
sub-neg74.8%
distribute-neg-frac274.8%
sub-neg74.8%
+-commutative74.8%
unsub-neg74.8%
sub-neg74.8%
+-commutative74.8%
unsub-neg74.8%
metadata-eval74.8%
Simplified74.8%
flip--55.4%
metadata-eval55.4%
metadata-eval55.4%
associate-/r/55.3%
metadata-eval55.3%
pow255.3%
Applied egg-rr55.3%
associate-*l/55.3%
*-lft-identity55.3%
+-commutative55.3%
Simplified55.3%
Applied egg-rr1.6%
div-sub1.6%
unpow21.6%
+-inverses1.6%
metadata-eval1.6%
+-inverses1.6%
metadata-eval1.6%
metadata-eval1.6%
+-inverses23.9%
Simplified23.9%
Final simplification23.9%
herbie shell --seed 2024046
(FPCore (x)
:name "Asymptote A"
:precision binary64
(- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))