
(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 12 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 (* (+ 2.0 (/ 2.0 (* x x))) (pow x -3.0)))
double code(double x) {
return (2.0 + (2.0 / (x * x))) * pow(x, -3.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (2.0d0 + (2.0d0 / (x * x))) * (x ** (-3.0d0))
end function
public static double code(double x) {
return (2.0 + (2.0 / (x * x))) * Math.pow(x, -3.0);
}
def code(x): return (2.0 + (2.0 / (x * x))) * math.pow(x, -3.0)
function code(x) return Float64(Float64(2.0 + Float64(2.0 / Float64(x * x))) * (x ^ -3.0)) end
function tmp = code(x) tmp = (2.0 + (2.0 / (x * x))) * (x ^ -3.0); end
code[x_] := N[(N[(2.0 + N[(2.0 / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Power[x, -3.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(2 + \frac{2}{x \cdot x}\right) \cdot {x}^{-3}
\end{array}
Initial program 70.7%
Simplified70.7%
Taylor expanded in x around inf 98.8%
associate-*r/98.8%
metadata-eval98.8%
Simplified98.8%
div-inv98.8%
+-commutative98.8%
div-inv98.8%
fma-define98.8%
pow-flip98.8%
metadata-eval98.8%
pow-flip99.5%
metadata-eval99.5%
Applied egg-rr99.5%
metadata-eval99.5%
pow-flip99.5%
pow299.5%
fma-define99.5%
div-inv99.5%
pow299.5%
Applied egg-rr99.5%
unpow299.5%
Applied egg-rr99.5%
Final simplification99.5%
(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.7%
Simplified70.7%
Taylor expanded in x around inf 98.8%
associate-*r/98.8%
metadata-eval98.8%
Simplified98.8%
div-inv98.8%
+-commutative98.8%
div-inv98.8%
fma-define98.8%
pow-flip98.8%
metadata-eval98.8%
pow-flip99.5%
metadata-eval99.5%
Applied egg-rr99.5%
Taylor expanded in x around inf 99.1%
(FPCore (x) :precision binary64 (+ (/ 1.0 (+ x 1.0)) (+ (/ -2.0 x) (/ 1.0 (* x (- 1.0 (/ 1.0 x)))))))
double code(double x) {
return (1.0 / (x + 1.0)) + ((-2.0 / x) + (1.0 / (x * (1.0 - (1.0 / x)))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / (x + 1.0d0)) + (((-2.0d0) / x) + (1.0d0 / (x * (1.0d0 - (1.0d0 / x)))))
end function
public static double code(double x) {
return (1.0 / (x + 1.0)) + ((-2.0 / x) + (1.0 / (x * (1.0 - (1.0 / x)))));
}
def code(x): return (1.0 / (x + 1.0)) + ((-2.0 / x) + (1.0 / (x * (1.0 - (1.0 / x)))))
function code(x) return Float64(Float64(1.0 / Float64(x + 1.0)) + Float64(Float64(-2.0 / x) + Float64(1.0 / Float64(x * Float64(1.0 - Float64(1.0 / x)))))) end
function tmp = code(x) tmp = (1.0 / (x + 1.0)) + ((-2.0 / x) + (1.0 / (x * (1.0 - (1.0 / x))))); end
code[x_] := N[(N[(1.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] + N[(N[(-2.0 / x), $MachinePrecision] + N[(1.0 / N[(x * N[(1.0 - N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x + 1} + \left(\frac{-2}{x} + \frac{1}{x \cdot \left(1 - \frac{1}{x}\right)}\right)
\end{array}
Initial program 70.7%
Simplified70.7%
Taylor expanded in x around inf 70.7%
Final simplification70.7%
(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(1.0 / Float64(x + 1.0)) + Float64(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[(1.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] + N[(N[(-2.0 / x), $MachinePrecision] + N[(1.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x + 1} + \left(\frac{-2}{x} + \frac{1}{x + -1}\right)
\end{array}
Initial program 70.7%
Simplified70.7%
Final simplification70.7%
(FPCore (x) :precision binary64 (+ (/ 1.0 (+ x -1.0)) (- (/ 1.0 (+ x 1.0)) (/ 2.0 x))))
double code(double x) {
return (1.0 / (x + -1.0)) + ((1.0 / (x + 1.0)) - (2.0 / x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / (x + (-1.0d0))) + ((1.0d0 / (x + 1.0d0)) - (2.0d0 / x))
end function
public static double code(double x) {
return (1.0 / (x + -1.0)) + ((1.0 / (x + 1.0)) - (2.0 / x));
}
def code(x): return (1.0 / (x + -1.0)) + ((1.0 / (x + 1.0)) - (2.0 / x))
function code(x) return Float64(Float64(1.0 / Float64(x + -1.0)) + Float64(Float64(1.0 / Float64(x + 1.0)) - Float64(2.0 / x))) end
function tmp = code(x) tmp = (1.0 / (x + -1.0)) + ((1.0 / (x + 1.0)) - (2.0 / x)); end
code[x_] := N[(N[(1.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(2.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x + -1} + \left(\frac{1}{x + 1} - \frac{2}{x}\right)
\end{array}
Initial program 70.7%
Final simplification70.7%
(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 / x) * Float64(1.0 + Float64(Float64(1.0 / 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 / x), $MachinePrecision] * N[(1.0 + N[(N[(1.0 / x), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x} \cdot \left(1 + \left(\frac{1}{x} + -1\right)\right)
\end{array}
Initial program 70.7%
Simplified70.7%
Taylor expanded in x around inf 69.6%
Taylor expanded in x around inf 69.6%
+-commutative69.6%
div-inv69.6%
fma-define69.6%
sub-neg69.6%
metadata-eval69.6%
Applied egg-rr69.6%
fma-undefine69.6%
*-commutative69.6%
*-rgt-identity69.6%
distribute-lft-out69.6%
Simplified69.6%
Final simplification69.6%
(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.7%
+-commutative70.7%
associate-+r-70.7%
sub-neg70.7%
remove-double-neg70.7%
neg-sub070.7%
associate-+l-70.7%
neg-sub070.7%
distribute-neg-frac270.7%
distribute-frac-neg270.7%
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 69.8%
associate-*r/69.8%
neg-mul-169.8%
distribute-neg-in69.8%
metadata-eval69.8%
distribute-neg-frac69.8%
metadata-eval69.8%
Simplified69.8%
Taylor expanded in x around inf 69.6%
(FPCore (x) :precision binary64 (+ -1.0 (+ 1.0 (/ 1.0 x))))
double code(double x) {
return -1.0 + (1.0 + (1.0 / x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-1.0d0) + (1.0d0 + (1.0d0 / x))
end function
public static double code(double x) {
return -1.0 + (1.0 + (1.0 / x));
}
def code(x): return -1.0 + (1.0 + (1.0 / x))
function code(x) return Float64(-1.0 + Float64(1.0 + Float64(1.0 / x))) end
function tmp = code(x) tmp = -1.0 + (1.0 + (1.0 / x)); end
code[x_] := N[(-1.0 + N[(1.0 + N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-1 + \left(1 + \frac{1}{x}\right)
\end{array}
Initial program 70.7%
Simplified70.7%
Taylor expanded in x around inf 69.6%
Taylor expanded in x around 0 5.3%
div-inv5.3%
pow15.3%
metadata-eval5.3%
sqrt-pow157.5%
pow257.5%
sqr-neg57.5%
sqrt-unprod3.7%
add-sqr-sqrt6.6%
metadata-eval6.6%
frac-2neg6.6%
Applied egg-rr6.6%
associate-*r/6.6%
metadata-eval6.6%
Simplified6.6%
pow16.6%
metadata-eval6.6%
sqrt-pow157.4%
unpow257.4%
sqr-neg57.4%
sqrt-unprod3.0%
add-sqr-sqrt5.3%
expm1-log1p-u5.3%
metadata-eval5.3%
frac-2neg5.3%
log1p-define69.3%
+-commutative69.3%
expm1-undefine69.3%
add-exp-log69.3%
+-commutative69.3%
frac-2neg69.3%
metadata-eval69.3%
add-sqr-sqrt37.4%
sqrt-unprod69.5%
sqr-neg69.5%
sqrt-prod32.1%
add-sqr-sqrt69.8%
Applied egg-rr69.8%
Final simplification69.8%
(FPCore (x) :precision binary64 (- (/ 1.0 x) (/ 1.0 x)))
double code(double x) {
return (1.0 / x) - (1.0 / x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / x) - (1.0d0 / x)
end function
public static double code(double x) {
return (1.0 / x) - (1.0 / x);
}
def code(x): return (1.0 / x) - (1.0 / x)
function code(x) return Float64(Float64(1.0 / x) - Float64(1.0 / x)) end
function tmp = code(x) tmp = (1.0 / x) - (1.0 / x); end
code[x_] := N[(N[(1.0 / x), $MachinePrecision] - N[(1.0 / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x} - \frac{1}{x}
\end{array}
Initial program 70.7%
Simplified70.7%
Taylor expanded in x around inf 69.6%
Taylor expanded in x around inf 69.4%
Final simplification69.4%
(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.7%
Simplified70.7%
Taylor expanded in x around inf 69.6%
Taylor expanded in x around 0 5.3%
div-inv5.3%
pow15.3%
metadata-eval5.3%
sqrt-pow157.5%
pow257.5%
sqr-neg57.5%
sqrt-unprod3.7%
add-sqr-sqrt6.6%
metadata-eval6.6%
frac-2neg6.6%
Applied egg-rr6.6%
associate-*r/6.6%
metadata-eval6.6%
Simplified6.6%
(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.7%
Simplified70.7%
Taylor expanded in x around inf 69.6%
Taylor expanded in x around 0 5.3%
(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.7%
Simplified70.7%
Taylor expanded in x around 0 5.3%
(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 2024129
(FPCore (x)
:name "3frac (problem 3.3.3)"
:precision binary64
:pre (> (fabs x) 1.0)
:alt
(! :herbie-platform default (/ 2 (* x (- (* x x) 1))))
(+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))