
(FPCore (x) :precision binary64 (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))
double code(double x) {
return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((1.0d0 / (x + 1.0d0)) - (2.0d0 / x)) + (1.0d0 / (x - 1.0d0))
end function
public static double code(double x) {
return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0));
}
def code(x): return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0))
function code(x) return Float64(Float64(Float64(1.0 / Float64(x + 1.0)) - Float64(2.0 / x)) + Float64(1.0 / Float64(x - 1.0))) end
function tmp = code(x) tmp = ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0)); end
code[x_] := N[(N[(N[(1.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(2.0 / x), $MachinePrecision]), $MachinePrecision] + N[(1.0 / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))
double code(double x) {
return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((1.0d0 / (x + 1.0d0)) - (2.0d0 / x)) + (1.0d0 / (x - 1.0d0))
end function
public static double code(double x) {
return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0));
}
def code(x): return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0))
function code(x) return Float64(Float64(Float64(1.0 / Float64(x + 1.0)) - Float64(2.0 / x)) + Float64(1.0 / Float64(x - 1.0))) end
function tmp = code(x) tmp = ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0)); end
code[x_] := N[(N[(N[(1.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(2.0 / x), $MachinePrecision]), $MachinePrecision] + N[(1.0 / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\end{array}
(FPCore (x) :precision binary64 (* (fma 2.0 (pow x -2.0) (fma 2.0 (pow x -4.0) 2.0)) (pow x -3.0)))
double code(double x) {
return fma(2.0, pow(x, -2.0), fma(2.0, pow(x, -4.0), 2.0)) * pow(x, -3.0);
}
function code(x) return Float64(fma(2.0, (x ^ -2.0), fma(2.0, (x ^ -4.0), 2.0)) * (x ^ -3.0)) end
code[x_] := N[(N[(2.0 * N[Power[x, -2.0], $MachinePrecision] + N[(2.0 * N[Power[x, -4.0], $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision] * N[Power[x, -3.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(2, {x}^{-2}, \mathsf{fma}\left(2, {x}^{-4}, 2\right)\right) \cdot {x}^{-3}
\end{array}
Initial program 70.6%
+-commutative70.6%
associate-+r-70.5%
sub-neg70.5%
remove-double-neg70.5%
neg-sub070.5%
associate-+l-70.5%
neg-sub070.5%
distribute-neg-frac270.5%
distribute-frac-neg270.5%
associate-+r+70.6%
+-commutative70.6%
remove-double-neg70.6%
distribute-neg-frac270.6%
sub0-neg70.6%
associate-+l-70.6%
neg-sub070.6%
Simplified70.6%
Taylor expanded in x around inf 98.6%
associate-+r+98.6%
+-commutative98.6%
associate-+l+98.6%
associate-*r/98.6%
metadata-eval98.6%
Simplified98.6%
div-inv98.6%
div-inv98.6%
fma-define98.6%
pow-flip98.6%
metadata-eval98.6%
+-commutative98.6%
div-inv98.6%
fma-define98.6%
pow-flip98.6%
metadata-eval98.6%
pow-flip99.7%
metadata-eval99.7%
Applied egg-rr99.7%
Final simplification99.7%
(FPCore (x) :precision binary64 (* 2.0 (pow x -3.0)))
double code(double x) {
return 2.0 * pow(x, -3.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0 * (x ** (-3.0d0))
end function
public static double code(double x) {
return 2.0 * Math.pow(x, -3.0);
}
def code(x): return 2.0 * math.pow(x, -3.0)
function code(x) return Float64(2.0 * (x ^ -3.0)) end
function tmp = code(x) tmp = 2.0 * (x ^ -3.0); end
code[x_] := N[(2.0 * N[Power[x, -3.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot {x}^{-3}
\end{array}
Initial program 70.6%
+-commutative70.6%
associate-+r-70.5%
sub-neg70.5%
remove-double-neg70.5%
neg-sub070.5%
associate-+l-70.5%
neg-sub070.5%
distribute-neg-frac270.5%
distribute-frac-neg270.5%
associate-+r+70.6%
+-commutative70.6%
remove-double-neg70.6%
distribute-neg-frac270.6%
sub0-neg70.6%
associate-+l-70.6%
neg-sub070.6%
Simplified70.6%
Taylor expanded in x around inf 97.9%
div-inv97.9%
pow-flip99.0%
metadata-eval99.0%
Applied egg-rr99.0%
Final simplification99.0%
(FPCore (x)
:precision binary64
(let* ((t_0 (* (- 1.0 x) (+ x 1.0))))
(if (<= (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (+ x -1.0))) 5e-25)
(/ (/ (/ 1.0 x) (+ x -1.0)) x)
(/ (- (* -2.0 t_0) (* x (+ x x))) (* x t_0)))))
double code(double x) {
double t_0 = (1.0 - x) * (x + 1.0);
double tmp;
if ((((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x + -1.0))) <= 5e-25) {
tmp = ((1.0 / x) / (x + -1.0)) / x;
} else {
tmp = ((-2.0 * t_0) - (x * (x + x))) / (x * t_0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = (1.0d0 - x) * (x + 1.0d0)
if ((((1.0d0 / (x + 1.0d0)) - (2.0d0 / x)) + (1.0d0 / (x + (-1.0d0)))) <= 5d-25) then
tmp = ((1.0d0 / x) / (x + (-1.0d0))) / x
else
tmp = (((-2.0d0) * t_0) - (x * (x + x))) / (x * t_0)
end if
code = tmp
end function
public static double code(double x) {
double t_0 = (1.0 - x) * (x + 1.0);
double tmp;
if ((((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x + -1.0))) <= 5e-25) {
tmp = ((1.0 / x) / (x + -1.0)) / x;
} else {
tmp = ((-2.0 * t_0) - (x * (x + x))) / (x * t_0);
}
return tmp;
}
def code(x): t_0 = (1.0 - x) * (x + 1.0) tmp = 0 if (((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x + -1.0))) <= 5e-25: tmp = ((1.0 / x) / (x + -1.0)) / x else: tmp = ((-2.0 * t_0) - (x * (x + x))) / (x * t_0) return tmp
function code(x) t_0 = Float64(Float64(1.0 - x) * Float64(x + 1.0)) tmp = 0.0 if (Float64(Float64(Float64(1.0 / Float64(x + 1.0)) - Float64(2.0 / x)) + Float64(1.0 / Float64(x + -1.0))) <= 5e-25) tmp = Float64(Float64(Float64(1.0 / x) / Float64(x + -1.0)) / x); else tmp = Float64(Float64(Float64(-2.0 * t_0) - Float64(x * Float64(x + x))) / Float64(x * t_0)); end return tmp end
function tmp_2 = code(x) t_0 = (1.0 - x) * (x + 1.0); tmp = 0.0; if ((((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x + -1.0))) <= 5e-25) tmp = ((1.0 / x) / (x + -1.0)) / x; else tmp = ((-2.0 * t_0) - (x * (x + x))) / (x * t_0); end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(N[(1.0 - x), $MachinePrecision] * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(N[(1.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(2.0 / x), $MachinePrecision]), $MachinePrecision] + N[(1.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e-25], N[(N[(N[(1.0 / x), $MachinePrecision] / N[(x + -1.0), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], N[(N[(N[(-2.0 * t$95$0), $MachinePrecision] - N[(x * N[(x + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x * t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - x\right) \cdot \left(x + 1\right)\\
\mathbf{if}\;\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x + -1} \leq 5 \cdot 10^{-25}:\\
\;\;\;\;\frac{\frac{\frac{1}{x}}{x + -1}}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{-2 \cdot t\_0 - x \cdot \left(x + x\right)}{x \cdot t\_0}\\
\end{array}
\end{array}
if (+.f64 (-.f64 (/.f64 #s(literal 1 binary64) (+.f64 x #s(literal 1 binary64))) (/.f64 #s(literal 2 binary64) x)) (/.f64 #s(literal 1 binary64) (-.f64 x #s(literal 1 binary64)))) < 4.99999999999999962e-25Initial program 70.7%
+-commutative70.7%
associate-+r-70.6%
sub-neg70.6%
remove-double-neg70.6%
neg-sub070.6%
associate-+l-70.6%
neg-sub070.6%
distribute-neg-frac270.6%
distribute-frac-neg270.6%
associate-+r+70.7%
+-commutative70.7%
remove-double-neg70.7%
distribute-neg-frac270.7%
sub0-neg70.7%
associate-+l-70.7%
neg-sub070.7%
Simplified70.7%
Taylor expanded in x around inf 70.4%
associate-*r/70.4%
neg-mul-170.4%
distribute-neg-in70.4%
metadata-eval70.4%
distribute-neg-frac70.4%
metadata-eval70.4%
Simplified70.4%
frac-2neg70.4%
div-inv70.5%
+-commutative70.5%
add-sqr-sqrt35.0%
sqrt-unprod70.6%
frac-times70.6%
metadata-eval70.6%
metadata-eval70.6%
frac-times70.6%
sqrt-prod35.6%
add-sqr-sqrt70.4%
metadata-eval70.4%
frac-2neg70.4%
add-sqr-sqrt17.6%
sqrt-unprod16.2%
frac-times13.1%
metadata-eval13.1%
metadata-eval13.1%
frac-times16.2%
sqrt-prod3.2%
add-sqr-sqrt6.3%
Applied egg-rr6.3%
add-sqr-sqrt6.3%
sqrt-unprod6.3%
sqr-neg6.3%
sqrt-unprod0.0%
add-sqr-sqrt70.4%
cancel-sign-sub70.4%
un-div-inv70.4%
frac-sub70.4%
Applied egg-rr70.5%
associate-/r*70.5%
Simplified74.4%
if 4.99999999999999962e-25 < (+.f64 (-.f64 (/.f64 #s(literal 1 binary64) (+.f64 x #s(literal 1 binary64))) (/.f64 #s(literal 2 binary64) x)) (/.f64 #s(literal 1 binary64) (-.f64 x #s(literal 1 binary64)))) Initial program 66.7%
+-commutative66.7%
associate-+r-66.2%
sub-neg66.2%
remove-double-neg66.2%
neg-sub066.2%
associate-+l-66.2%
neg-sub066.2%
distribute-neg-frac266.2%
distribute-frac-neg266.2%
associate-+r+66.7%
+-commutative66.7%
remove-double-neg66.7%
distribute-neg-frac266.7%
sub0-neg66.7%
associate-+l-66.7%
neg-sub066.7%
Simplified66.7%
+-commutative66.7%
associate-+l-66.2%
Applied egg-rr66.2%
frac-sub65.7%
frac-sub99.5%
*-un-lft-identity99.5%
metadata-eval99.5%
div-inv99.5%
associate--l+99.5%
div-inv99.5%
metadata-eval99.5%
*-rgt-identity99.5%
Applied egg-rr99.5%
Simplified99.5%
Final simplification74.9%
(FPCore (x) :precision binary64 (+ (/ 1.0 (+ x -1.0)) (/ -1.0 x)))
double code(double x) {
return (1.0 / (x + -1.0)) + (-1.0 / x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / (x + (-1.0d0))) + ((-1.0d0) / x)
end function
public static double code(double x) {
return (1.0 / (x + -1.0)) + (-1.0 / x);
}
def code(x): return (1.0 / (x + -1.0)) + (-1.0 / x)
function code(x) return Float64(Float64(1.0 / Float64(x + -1.0)) + Float64(-1.0 / x)) end
function tmp = code(x) tmp = (1.0 / (x + -1.0)) + (-1.0 / x); end
code[x_] := N[(N[(1.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision] + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x + -1} + \frac{-1}{x}
\end{array}
Initial program 70.6%
+-commutative70.6%
associate-+r-70.5%
sub-neg70.5%
remove-double-neg70.5%
neg-sub070.5%
associate-+l-70.5%
neg-sub070.5%
distribute-neg-frac270.5%
distribute-frac-neg270.5%
associate-+r+70.6%
+-commutative70.6%
remove-double-neg70.6%
distribute-neg-frac270.6%
sub0-neg70.6%
associate-+l-70.6%
neg-sub070.6%
Simplified70.6%
Taylor expanded in x around inf 69.3%
Final simplification69.3%
(FPCore (x) :precision binary64 (/ (/ (/ 1.0 x) (+ x -1.0)) x))
double code(double x) {
return ((1.0 / x) / (x + -1.0)) / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((1.0d0 / x) / (x + (-1.0d0))) / x
end function
public static double code(double x) {
return ((1.0 / x) / (x + -1.0)) / x;
}
def code(x): return ((1.0 / x) / (x + -1.0)) / x
function code(x) return Float64(Float64(Float64(1.0 / x) / Float64(x + -1.0)) / x) end
function tmp = code(x) tmp = ((1.0 / x) / (x + -1.0)) / x; end
code[x_] := N[(N[(N[(1.0 / x), $MachinePrecision] / N[(x + -1.0), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{\frac{1}{x}}{x + -1}}{x}
\end{array}
Initial program 70.6%
+-commutative70.6%
associate-+r-70.5%
sub-neg70.5%
remove-double-neg70.5%
neg-sub070.5%
associate-+l-70.5%
neg-sub070.5%
distribute-neg-frac270.5%
distribute-frac-neg270.5%
associate-+r+70.6%
+-commutative70.6%
remove-double-neg70.6%
distribute-neg-frac270.6%
sub0-neg70.6%
associate-+l-70.6%
neg-sub070.6%
Simplified70.6%
Taylor expanded in x around inf 69.4%
associate-*r/69.4%
neg-mul-169.4%
distribute-neg-in69.4%
metadata-eval69.4%
distribute-neg-frac69.4%
metadata-eval69.4%
Simplified69.4%
frac-2neg69.4%
div-inv69.5%
+-commutative69.5%
add-sqr-sqrt34.3%
sqrt-unprod69.5%
frac-times69.5%
metadata-eval69.5%
metadata-eval69.5%
frac-times69.5%
sqrt-prod35.2%
add-sqr-sqrt69.3%
metadata-eval69.3%
frac-2neg69.3%
add-sqr-sqrt17.2%
sqrt-unprod16.1%
frac-times13.1%
metadata-eval13.1%
metadata-eval13.1%
frac-times16.1%
sqrt-prod3.4%
add-sqr-sqrt6.5%
Applied egg-rr6.5%
add-sqr-sqrt6.5%
sqrt-unprod6.5%
sqr-neg6.5%
sqrt-unprod0.0%
add-sqr-sqrt69.3%
cancel-sign-sub69.3%
un-div-inv69.3%
frac-sub69.3%
Applied egg-rr69.5%
associate-/r*69.5%
Simplified73.4%
Final simplification73.4%
(FPCore (x) :precision binary64 (+ -1.0 (+ 1.0 (/ -2.0 x))))
double code(double x) {
return -1.0 + (1.0 + (-2.0 / x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-1.0d0) + (1.0d0 + ((-2.0d0) / x))
end function
public static double code(double x) {
return -1.0 + (1.0 + (-2.0 / x));
}
def code(x): return -1.0 + (1.0 + (-2.0 / x))
function code(x) return Float64(-1.0 + Float64(1.0 + Float64(-2.0 / x))) end
function tmp = code(x) tmp = -1.0 + (1.0 + (-2.0 / x)); end
code[x_] := N[(-1.0 + N[(1.0 + N[(-2.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-1 + \left(1 + \frac{-2}{x}\right)
\end{array}
Initial program 70.6%
+-commutative70.6%
associate-+r-70.5%
sub-neg70.5%
remove-double-neg70.5%
neg-sub070.5%
associate-+l-70.5%
neg-sub070.5%
distribute-neg-frac270.5%
distribute-frac-neg270.5%
associate-+r+70.6%
+-commutative70.6%
remove-double-neg70.6%
distribute-neg-frac270.6%
sub0-neg70.6%
associate-+l-70.6%
neg-sub070.6%
Simplified70.6%
Taylor expanded in x around 0 3.5%
div-sub3.5%
sub-neg3.5%
*-inverses3.5%
metadata-eval3.5%
distribute-neg-frac3.5%
remove-double-neg3.5%
Simplified3.5%
Taylor expanded in x around 0 68.9%
Final simplification68.9%
(FPCore (x) :precision binary64 (- (/ -2.0 x) (/ -2.0 x)))
double code(double x) {
return (-2.0 / x) - (-2.0 / x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((-2.0d0) / x) - ((-2.0d0) / x)
end function
public static double code(double x) {
return (-2.0 / x) - (-2.0 / x);
}
def code(x): return (-2.0 / x) - (-2.0 / x)
function code(x) return Float64(Float64(-2.0 / x) - Float64(-2.0 / x)) end
function tmp = code(x) tmp = (-2.0 / x) - (-2.0 / x); end
code[x_] := N[(N[(-2.0 / x), $MachinePrecision] - N[(-2.0 / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-2}{x} - \frac{-2}{x}
\end{array}
Initial program 70.6%
+-commutative70.6%
associate-+r-70.5%
sub-neg70.5%
remove-double-neg70.5%
neg-sub070.5%
associate-+l-70.5%
neg-sub070.5%
distribute-neg-frac270.5%
distribute-frac-neg270.5%
associate-+r+70.6%
+-commutative70.6%
remove-double-neg70.6%
distribute-neg-frac270.6%
sub0-neg70.6%
associate-+l-70.6%
neg-sub070.6%
Simplified70.6%
+-commutative70.6%
associate-+l-70.5%
Applied egg-rr70.5%
frac-sub19.0%
div-inv19.8%
*-un-lft-identity19.8%
metadata-eval19.8%
div-inv19.8%
associate--l+19.7%
div-inv19.7%
metadata-eval19.7%
*-rgt-identity19.7%
Applied egg-rr19.7%
associate--r-19.8%
metadata-eval19.8%
*-commutative19.8%
Simplified19.8%
Taylor expanded in x around inf 69.0%
Final simplification69.0%
(FPCore (x) :precision binary64 (/ -2.0 x))
double code(double x) {
return -2.0 / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-2.0d0) / x
end function
public static double code(double x) {
return -2.0 / x;
}
def code(x): return -2.0 / x
function code(x) return Float64(-2.0 / x) end
function tmp = code(x) tmp = -2.0 / x; end
code[x_] := N[(-2.0 / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{-2}{x}
\end{array}
Initial program 70.6%
+-commutative70.6%
associate-+r-70.5%
sub-neg70.5%
remove-double-neg70.5%
neg-sub070.5%
associate-+l-70.5%
neg-sub070.5%
distribute-neg-frac270.5%
distribute-frac-neg270.5%
associate-+r+70.6%
+-commutative70.6%
remove-double-neg70.6%
distribute-neg-frac270.6%
sub0-neg70.6%
associate-+l-70.6%
neg-sub070.6%
Simplified70.6%
Taylor expanded in x around 0 5.1%
Final simplification5.1%
(FPCore (x) :precision binary64 (/ -1.0 x))
double code(double x) {
return -1.0 / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-1.0d0) / x
end function
public static double code(double x) {
return -1.0 / x;
}
def code(x): return -1.0 / x
function code(x) return Float64(-1.0 / x) end
function tmp = code(x) tmp = -1.0 / x; end
code[x_] := N[(-1.0 / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{-1}{x}
\end{array}
Initial program 70.6%
+-commutative70.6%
associate-+r-70.5%
sub-neg70.5%
remove-double-neg70.5%
neg-sub070.5%
associate-+l-70.5%
neg-sub070.5%
distribute-neg-frac270.5%
distribute-frac-neg270.5%
associate-+r+70.6%
+-commutative70.6%
remove-double-neg70.6%
distribute-neg-frac270.6%
sub0-neg70.6%
associate-+l-70.6%
neg-sub070.6%
Simplified70.6%
Taylor expanded in x around 0 3.5%
div-sub3.5%
sub-neg3.5%
*-inverses3.5%
metadata-eval3.5%
distribute-neg-frac3.5%
remove-double-neg3.5%
Simplified3.5%
Taylor expanded in x around inf 3.5%
Taylor expanded in x around 0 5.2%
Final simplification5.2%
(FPCore (x) :precision binary64 (/ 2.0 x))
double code(double x) {
return 2.0 / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0 / x
end function
public static double code(double x) {
return 2.0 / x;
}
def code(x): return 2.0 / x
function code(x) return Float64(2.0 / x) end
function tmp = code(x) tmp = 2.0 / x; end
code[x_] := N[(2.0 / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{x}
\end{array}
Initial program 70.6%
+-commutative70.6%
associate-+r-70.5%
sub-neg70.5%
remove-double-neg70.5%
neg-sub070.5%
associate-+l-70.5%
neg-sub070.5%
distribute-neg-frac270.5%
distribute-frac-neg270.5%
associate-+r+70.6%
+-commutative70.6%
remove-double-neg70.6%
distribute-neg-frac270.6%
sub0-neg70.6%
associate-+l-70.6%
neg-sub070.6%
Simplified70.6%
Taylor expanded in x around inf 69.4%
associate-*r/69.4%
neg-mul-169.4%
distribute-neg-in69.4%
metadata-eval69.4%
distribute-neg-frac69.4%
metadata-eval69.4%
Simplified69.4%
frac-2neg69.4%
div-inv69.5%
+-commutative69.5%
add-sqr-sqrt34.3%
sqrt-unprod69.5%
frac-times69.5%
metadata-eval69.5%
metadata-eval69.5%
frac-times69.5%
sqrt-prod35.2%
add-sqr-sqrt69.3%
metadata-eval69.3%
frac-2neg69.3%
add-sqr-sqrt17.2%
sqrt-unprod16.1%
frac-times13.1%
metadata-eval13.1%
metadata-eval13.1%
frac-times16.1%
sqrt-prod3.4%
add-sqr-sqrt6.5%
Applied egg-rr6.5%
Taylor expanded in x around inf 6.5%
Final simplification6.5%
(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 70.6%
+-commutative70.6%
associate-+r-70.5%
sub-neg70.5%
remove-double-neg70.5%
neg-sub070.5%
associate-+l-70.5%
neg-sub070.5%
distribute-neg-frac270.5%
distribute-frac-neg270.5%
associate-+r+70.6%
+-commutative70.6%
remove-double-neg70.6%
distribute-neg-frac270.6%
sub0-neg70.6%
associate-+l-70.6%
neg-sub070.6%
Simplified70.6%
Taylor expanded in x around 0 3.5%
div-sub3.5%
sub-neg3.5%
*-inverses3.5%
metadata-eval3.5%
distribute-neg-frac3.5%
remove-double-neg3.5%
Simplified3.5%
Taylor expanded in x around inf 3.5%
Final simplification3.5%
(FPCore (x) :precision binary64 (/ 2.0 (* x (- (* x x) 1.0))))
double code(double x) {
return 2.0 / (x * ((x * x) - 1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0 / (x * ((x * x) - 1.0d0))
end function
public static double code(double x) {
return 2.0 / (x * ((x * x) - 1.0));
}
def code(x): return 2.0 / (x * ((x * x) - 1.0))
function code(x) return Float64(2.0 / Float64(x * Float64(Float64(x * x) - 1.0))) end
function tmp = code(x) tmp = 2.0 / (x * ((x * x) - 1.0)); end
code[x_] := N[(2.0 / N[(x * N[(N[(x * x), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{x \cdot \left(x \cdot x - 1\right)}
\end{array}
herbie shell --seed 2024079
(FPCore (x)
:name "3frac (problem 3.3.3)"
:precision binary64
:pre (> (fabs x) 1.0)
:alt
(/ 2.0 (* x (- (* x x) 1.0)))
(+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))