
(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}
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (/ (/ -2.0 (+ 1.0 x)) (+ x -1.0)))
x = abs(x);
double code(double x) {
return (-2.0 / (1.0 + x)) / (x + -1.0);
}
NOTE: x should be positive before calling this function
real(8) function code(x)
real(8), intent (in) :: x
code = ((-2.0d0) / (1.0d0 + x)) / (x + (-1.0d0))
end function
x = Math.abs(x);
public static double code(double x) {
return (-2.0 / (1.0 + x)) / (x + -1.0);
}
x = abs(x) def code(x): return (-2.0 / (1.0 + x)) / (x + -1.0)
x = abs(x) function code(x) return Float64(Float64(-2.0 / Float64(1.0 + x)) / Float64(x + -1.0)) end
x = abs(x) function tmp = code(x) tmp = (-2.0 / (1.0 + x)) / (x + -1.0); end
NOTE: x should be positive before calling this function code[x_] := N[(N[(-2.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x = |x|\\
\\
\frac{\frac{-2}{1 + x}}{x + -1}
\end{array}
Initial program 79.0%
frac-sub79.4%
associate-/r*79.4%
*-un-lft-identity79.4%
*-rgt-identity79.4%
associate--l-79.4%
+-commutative79.4%
+-commutative79.4%
sub-neg79.4%
metadata-eval79.4%
Applied egg-rr79.4%
Taylor expanded in x around 0 99.9%
Final simplification99.9%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 1.55) (+ (- 1.0 x) (/ -1.0 (+ x -1.0))) (/ (/ (- 2.0) x) x)))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 1.55) {
tmp = (1.0 - x) + (-1.0 / (x + -1.0));
} else {
tmp = (-2.0 / x) / x;
}
return tmp;
}
NOTE: x should be positive before calling this function
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.55d0) then
tmp = (1.0d0 - x) + ((-1.0d0) / (x + (-1.0d0)))
else
tmp = (-2.0d0 / x) / x
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x) {
double tmp;
if (x <= 1.55) {
tmp = (1.0 - x) + (-1.0 / (x + -1.0));
} else {
tmp = (-2.0 / x) / x;
}
return tmp;
}
x = abs(x) def code(x): tmp = 0 if x <= 1.55: tmp = (1.0 - x) + (-1.0 / (x + -1.0)) else: tmp = (-2.0 / x) / x return tmp
x = abs(x) function code(x) tmp = 0.0 if (x <= 1.55) tmp = Float64(Float64(1.0 - x) + Float64(-1.0 / Float64(x + -1.0))); else tmp = Float64(Float64(Float64(-2.0) / x) / x); end return tmp end
x = abs(x) function tmp_2 = code(x) tmp = 0.0; if (x <= 1.55) tmp = (1.0 - x) + (-1.0 / (x + -1.0)); else tmp = (-2.0 / x) / x; end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_] := If[LessEqual[x, 1.55], N[(N[(1.0 - x), $MachinePrecision] + N[(-1.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-2.0) / x), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.55:\\
\;\;\;\;\left(1 - x\right) + \frac{-1}{x + -1}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{-2}{x}}{x}\\
\end{array}
\end{array}
if x < 1.55000000000000004Initial program 84.4%
Taylor expanded in x around 0 68.8%
neg-mul-168.8%
unsub-neg68.8%
Simplified68.8%
if 1.55000000000000004 < x Initial program 56.1%
Taylor expanded in x around inf 96.9%
unpow296.9%
Simplified96.9%
associate-/r*98.4%
div-inv98.2%
Applied egg-rr98.2%
un-div-inv98.4%
frac-2neg98.4%
frac-2neg98.4%
metadata-eval98.4%
add-sqr-sqrt0.0%
sqrt-unprod51.5%
sqr-neg51.5%
sqrt-unprod51.4%
add-sqr-sqrt51.4%
add-sqr-sqrt0.0%
sqrt-unprod96.8%
sqr-neg96.8%
sqrt-unprod98.1%
add-sqr-sqrt98.4%
Applied egg-rr98.4%
Final simplification74.5%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 1.0) 2.0 (/ (/ (- 2.0) x) x)))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 2.0;
} else {
tmp = (-2.0 / x) / x;
}
return tmp;
}
NOTE: x should be positive before calling this function
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) / x
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 2.0;
} else {
tmp = (-2.0 / x) / x;
}
return tmp;
}
x = abs(x) def code(x): tmp = 0 if x <= 1.0: tmp = 2.0 else: tmp = (-2.0 / x) / x return tmp
x = abs(x) function code(x) tmp = 0.0 if (x <= 1.0) tmp = 2.0; else tmp = Float64(Float64(Float64(-2.0) / x) / x); end return tmp end
x = abs(x) function tmp_2 = code(x) tmp = 0.0; if (x <= 1.0) tmp = 2.0; else tmp = (-2.0 / x) / x; end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_] := If[LessEqual[x, 1.0], 2.0, N[(N[((-2.0) / x), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{-2}{x}}{x}\\
\end{array}
\end{array}
if x < 1Initial program 84.3%
Taylor expanded in x around 0 69.3%
if 1 < x Initial program 56.9%
Taylor expanded in x around inf 95.3%
unpow295.3%
Simplified95.3%
associate-/r*96.8%
div-inv96.7%
Applied egg-rr96.7%
un-div-inv96.8%
frac-2neg96.8%
frac-2neg96.8%
metadata-eval96.8%
add-sqr-sqrt0.0%
sqrt-unprod50.5%
sqr-neg50.5%
sqrt-unprod50.4%
add-sqr-sqrt50.4%
add-sqr-sqrt0.0%
sqrt-unprod95.3%
sqr-neg95.3%
sqrt-unprod96.5%
add-sqr-sqrt96.8%
Applied egg-rr96.8%
Final simplification74.7%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 1.0) 2.0 (/ -2.0 (* x x))))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 2.0;
} else {
tmp = -2.0 / (x * x);
}
return tmp;
}
NOTE: x should be positive before calling this function
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 * x)
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 2.0;
} else {
tmp = -2.0 / (x * x);
}
return tmp;
}
x = abs(x) def code(x): tmp = 0 if x <= 1.0: tmp = 2.0 else: tmp = -2.0 / (x * x) return tmp
x = abs(x) function code(x) tmp = 0.0 if (x <= 1.0) tmp = 2.0; else tmp = Float64(-2.0 / Float64(x * x)); end return tmp end
x = abs(x) function tmp_2 = code(x) tmp = 0.0; if (x <= 1.0) tmp = 2.0; else tmp = -2.0 / (x * x); end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_] := If[LessEqual[x, 1.0], 2.0, N[(-2.0 / N[(x * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;\frac{-2}{x \cdot x}\\
\end{array}
\end{array}
if x < 1Initial program 84.3%
Taylor expanded in x around 0 69.3%
if 1 < x Initial program 56.9%
Taylor expanded in x around inf 95.3%
unpow295.3%
Simplified95.3%
Final simplification74.4%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 2.0)
x = abs(x);
double code(double x) {
return 2.0;
}
NOTE: x should be positive before calling this function
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0
end function
x = Math.abs(x);
public static double code(double x) {
return 2.0;
}
x = abs(x) def code(x): return 2.0
x = abs(x) function code(x) return 2.0 end
x = abs(x) function tmp = code(x) tmp = 2.0; end
NOTE: x should be positive before calling this function code[x_] := 2.0
\begin{array}{l}
x = |x|\\
\\
2
\end{array}
Initial program 79.0%
Taylor expanded in x around 0 56.3%
Final simplification56.3%
herbie shell --seed 2023224
(FPCore (x)
:name "Asymptote A"
:precision binary64
(- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))