
(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)) (- -1.0 x)))
double code(double x) {
return (2.0 / (x + -1.0)) / (-1.0 - x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (2.0d0 / (x + (-1.0d0))) / ((-1.0d0) - x)
end function
public static double code(double x) {
return (2.0 / (x + -1.0)) / (-1.0 - x);
}
def code(x): return (2.0 / (x + -1.0)) / (-1.0 - x)
function code(x) return Float64(Float64(2.0 / Float64(x + -1.0)) / Float64(-1.0 - x)) end
function tmp = code(x) tmp = (2.0 / (x + -1.0)) / (-1.0 - x); end
code[x_] := N[(N[(2.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision] / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{2}{x + -1}}{-1 - x}
\end{array}
Initial program 78.0%
sub-neg78.0%
+-commutative78.0%
distribute-neg-frac278.0%
neg-sub078.0%
associate-+l-78.0%
neg-sub078.0%
remove-double-neg78.0%
distribute-neg-in78.0%
sub-neg78.0%
distribute-neg-frac278.0%
sub-neg78.0%
+-commutative78.0%
unsub-neg78.0%
sub-neg78.0%
+-commutative78.0%
unsub-neg78.0%
metadata-eval78.0%
Simplified78.0%
frac-sub78.5%
*-rgt-identity78.5%
metadata-eval78.5%
div-inv78.5%
associate-/r*78.5%
metadata-eval78.5%
div-inv78.5%
*-un-lft-identity78.5%
associate--l-81.4%
div-inv81.4%
metadata-eval81.4%
*-rgt-identity81.4%
div-inv81.4%
metadata-eval81.4%
*-rgt-identity81.4%
Applied egg-rr81.4%
div-sub81.4%
sub-neg81.4%
Applied egg-rr81.4%
distribute-neg-frac81.4%
+-commutative81.4%
associate--r-99.9%
+-inverses99.9%
metadata-eval99.9%
metadata-eval99.9%
count-299.9%
associate-*r/99.9%
metadata-eval99.9%
metadata-eval99.9%
associate-/r*99.9%
neg-mul-199.9%
neg-sub099.9%
associate--r-99.9%
metadata-eval99.9%
+-commutative99.9%
Simplified99.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.7%
sub-neg85.7%
+-commutative85.7%
distribute-neg-frac285.7%
neg-sub085.7%
associate-+l-85.7%
neg-sub085.7%
remove-double-neg85.7%
distribute-neg-in85.7%
sub-neg85.7%
distribute-neg-frac285.7%
sub-neg85.7%
+-commutative85.7%
unsub-neg85.7%
sub-neg85.7%
+-commutative85.7%
unsub-neg85.7%
metadata-eval85.7%
Simplified85.7%
Taylor expanded in x around 0 67.7%
if 1 < x Initial program 57.2%
sub-neg57.2%
+-commutative57.2%
distribute-neg-frac257.2%
neg-sub057.2%
associate-+l-57.2%
neg-sub057.2%
remove-double-neg57.2%
distribute-neg-in57.2%
sub-neg57.2%
distribute-neg-frac257.2%
sub-neg57.2%
+-commutative57.2%
unsub-neg57.2%
sub-neg57.2%
+-commutative57.2%
unsub-neg57.2%
metadata-eval57.2%
Simplified57.2%
frac-sub57.7%
*-rgt-identity57.7%
metadata-eval57.7%
div-inv57.7%
associate-/r*57.7%
metadata-eval57.7%
div-inv57.7%
*-un-lft-identity57.7%
associate--l-63.3%
div-inv63.3%
metadata-eval63.3%
*-rgt-identity63.3%
div-inv63.3%
metadata-eval63.3%
*-rgt-identity63.3%
Applied egg-rr63.3%
Taylor expanded in x around inf 98.1%
(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 85.7%
sub-neg85.7%
+-commutative85.7%
distribute-neg-frac285.7%
neg-sub085.7%
associate-+l-85.7%
neg-sub085.7%
remove-double-neg85.7%
distribute-neg-in85.7%
sub-neg85.7%
distribute-neg-frac285.7%
sub-neg85.7%
+-commutative85.7%
unsub-neg85.7%
sub-neg85.7%
+-commutative85.7%
unsub-neg85.7%
metadata-eval85.7%
Simplified85.7%
Taylor expanded in x around 0 67.7%
if 0.75 < x Initial program 57.2%
sub-neg57.2%
+-commutative57.2%
distribute-neg-frac257.2%
neg-sub057.2%
associate-+l-57.2%
neg-sub057.2%
remove-double-neg57.2%
distribute-neg-in57.2%
sub-neg57.2%
distribute-neg-frac257.2%
sub-neg57.2%
+-commutative57.2%
unsub-neg57.2%
sub-neg57.2%
+-commutative57.2%
unsub-neg57.2%
metadata-eval57.2%
Simplified57.2%
frac-sub57.7%
*-rgt-identity57.7%
metadata-eval57.7%
div-inv57.7%
associate-/r*57.7%
metadata-eval57.7%
div-inv57.7%
*-un-lft-identity57.7%
associate--l-63.3%
div-inv63.3%
metadata-eval63.3%
*-rgt-identity63.3%
div-inv63.3%
metadata-eval63.3%
*-rgt-identity63.3%
Applied egg-rr63.3%
Taylor expanded in x around inf 98.1%
add-sqr-sqrt97.9%
associate-/l*97.8%
Applied egg-rr97.8%
associate-*r/97.9%
add-sqr-sqrt98.1%
frac-2neg98.1%
associate-/l/96.7%
metadata-eval96.7%
add-sqr-sqrt0.0%
sqrt-unprod54.2%
sqr-neg54.2%
sqrt-unprod54.2%
add-sqr-sqrt54.2%
sub-neg54.2%
add-sqr-sqrt0.0%
sqrt-unprod96.7%
sqr-neg96.7%
sqrt-unprod96.4%
add-sqr-sqrt96.7%
+-commutative96.7%
Applied egg-rr96.7%
Final simplification75.5%
(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 78.0%
sub-neg78.0%
+-commutative78.0%
distribute-neg-frac278.0%
neg-sub078.0%
associate-+l-78.0%
neg-sub078.0%
remove-double-neg78.0%
distribute-neg-in78.0%
sub-neg78.0%
distribute-neg-frac278.0%
sub-neg78.0%
+-commutative78.0%
unsub-neg78.0%
sub-neg78.0%
+-commutative78.0%
unsub-neg78.0%
metadata-eval78.0%
Simplified78.0%
sub-neg78.0%
distribute-neg-frac78.0%
metadata-eval78.0%
Applied egg-rr78.0%
Simplified99.4%
Final simplification99.4%
(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.7%
sub-neg85.7%
+-commutative85.7%
distribute-neg-frac285.7%
neg-sub085.7%
associate-+l-85.7%
neg-sub085.7%
remove-double-neg85.7%
distribute-neg-in85.7%
sub-neg85.7%
distribute-neg-frac285.7%
sub-neg85.7%
+-commutative85.7%
unsub-neg85.7%
sub-neg85.7%
+-commutative85.7%
unsub-neg85.7%
metadata-eval85.7%
Simplified85.7%
Taylor expanded in x around 0 67.7%
if 1 < x Initial program 57.2%
sub-neg57.2%
+-commutative57.2%
distribute-neg-frac257.2%
neg-sub057.2%
associate-+l-57.2%
neg-sub057.2%
remove-double-neg57.2%
distribute-neg-in57.2%
sub-neg57.2%
distribute-neg-frac257.2%
sub-neg57.2%
+-commutative57.2%
unsub-neg57.2%
sub-neg57.2%
+-commutative57.2%
unsub-neg57.2%
metadata-eval57.2%
Simplified57.2%
frac-sub57.7%
*-rgt-identity57.7%
metadata-eval57.7%
div-inv57.7%
associate-/r*57.7%
metadata-eval57.7%
div-inv57.7%
*-un-lft-identity57.7%
associate--l-63.3%
div-inv63.3%
metadata-eval63.3%
*-rgt-identity63.3%
div-inv63.3%
metadata-eval63.3%
*-rgt-identity63.3%
Applied egg-rr63.3%
Taylor expanded in x around inf 98.1%
Taylor expanded in x around 0 7.0%
(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 78.0%
sub-neg78.0%
+-commutative78.0%
distribute-neg-frac278.0%
neg-sub078.0%
associate-+l-78.0%
neg-sub078.0%
remove-double-neg78.0%
distribute-neg-in78.0%
sub-neg78.0%
distribute-neg-frac278.0%
sub-neg78.0%
+-commutative78.0%
unsub-neg78.0%
sub-neg78.0%
+-commutative78.0%
unsub-neg78.0%
metadata-eval78.0%
Simplified78.0%
frac-sub78.5%
*-rgt-identity78.5%
metadata-eval78.5%
div-inv78.5%
associate-/r*78.5%
metadata-eval78.5%
div-inv78.5%
*-un-lft-identity78.5%
associate--l-81.4%
div-inv81.4%
metadata-eval81.4%
*-rgt-identity81.4%
div-inv81.4%
metadata-eval81.4%
*-rgt-identity81.4%
Applied egg-rr81.4%
Taylor expanded in x around 0 51.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 78.0%
sub-neg78.0%
+-commutative78.0%
distribute-neg-frac278.0%
neg-sub078.0%
associate-+l-78.0%
neg-sub078.0%
remove-double-neg78.0%
distribute-neg-in78.0%
sub-neg78.0%
distribute-neg-frac278.0%
sub-neg78.0%
+-commutative78.0%
unsub-neg78.0%
sub-neg78.0%
+-commutative78.0%
unsub-neg78.0%
metadata-eval78.0%
Simplified78.0%
Taylor expanded in x around 0 50.2%
(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 78.0%
sub-neg78.0%
+-commutative78.0%
distribute-neg-frac278.0%
neg-sub078.0%
associate-+l-78.0%
neg-sub078.0%
remove-double-neg78.0%
distribute-neg-in78.0%
sub-neg78.0%
distribute-neg-frac278.0%
sub-neg78.0%
+-commutative78.0%
unsub-neg78.0%
sub-neg78.0%
+-commutative78.0%
unsub-neg78.0%
metadata-eval78.0%
Simplified78.0%
Taylor expanded in x around 0 49.8%
Taylor expanded in x around inf 10.7%
herbie shell --seed 2024101
(FPCore (x)
:name "Asymptote A"
:precision binary64
(- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))