
(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 7 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 (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 68.6%
+-commutative68.6%
associate-+r-68.5%
sub-neg68.5%
remove-double-neg68.5%
neg-sub068.5%
associate-+l-68.5%
neg-sub068.5%
distribute-neg-frac268.5%
distribute-frac-neg268.5%
associate-+r+68.6%
+-commutative68.6%
remove-double-neg68.6%
distribute-neg-frac268.6%
sub0-neg68.6%
associate-+l-68.6%
neg-sub068.6%
Simplified68.6%
Taylor expanded in x around inf 98.4%
div-inv98.4%
pow-flip99.0%
metadata-eval99.0%
Applied egg-rr99.0%
(FPCore (x) :precision binary64 (* 2.0 (/ (/ (/ 1.0 x) x) x)))
double code(double x) {
return 2.0 * (((1.0 / x) / x) / x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0 * (((1.0d0 / x) / x) / x)
end function
public static double code(double x) {
return 2.0 * (((1.0 / x) / x) / x);
}
def code(x): return 2.0 * (((1.0 / x) / x) / x)
function code(x) return Float64(2.0 * Float64(Float64(Float64(1.0 / x) / x) / x)) end
function tmp = code(x) tmp = 2.0 * (((1.0 / x) / x) / x); end
code[x_] := N[(2.0 * N[(N[(N[(1.0 / x), $MachinePrecision] / x), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \frac{\frac{\frac{1}{x}}{x}}{x}
\end{array}
Initial program 68.6%
+-commutative68.6%
associate-+r-68.5%
sub-neg68.5%
remove-double-neg68.5%
neg-sub068.5%
associate-+l-68.5%
neg-sub068.5%
distribute-neg-frac268.5%
distribute-frac-neg268.5%
associate-+r+68.6%
+-commutative68.6%
remove-double-neg68.6%
distribute-neg-frac268.6%
sub0-neg68.6%
associate-+l-68.6%
neg-sub068.6%
Simplified68.6%
Taylor expanded in x around inf 98.4%
div-inv98.4%
pow-flip99.0%
metadata-eval99.0%
Applied egg-rr99.0%
metadata-eval99.0%
pow-pow98.7%
inv-pow98.7%
cube-mult98.7%
inv-pow98.7%
inv-pow98.7%
pow-prod-up98.8%
metadata-eval98.8%
Applied egg-rr98.8%
associate-*l/98.9%
*-lft-identity98.9%
Simplified98.9%
metadata-eval98.9%
pow-div98.9%
inv-pow98.9%
pow198.9%
Applied egg-rr98.9%
(FPCore (x) :precision binary64 (+ 1.0 (+ (/ 1.0 x) -1.0)))
double code(double x) {
return 1.0 + ((1.0 / x) + -1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 + ((1.0d0 / x) + (-1.0d0))
end function
public static double code(double x) {
return 1.0 + ((1.0 / x) + -1.0);
}
def code(x): return 1.0 + ((1.0 / x) + -1.0)
function code(x) return Float64(1.0 + Float64(Float64(1.0 / x) + -1.0)) end
function tmp = code(x) tmp = 1.0 + ((1.0 / x) + -1.0); end
code[x_] := N[(1.0 + N[(N[(1.0 / x), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + \left(\frac{1}{x} + -1\right)
\end{array}
Initial program 68.6%
+-commutative68.6%
associate-+r-68.5%
sub-neg68.5%
remove-double-neg68.5%
neg-sub068.5%
associate-+l-68.5%
neg-sub068.5%
distribute-neg-frac268.5%
distribute-frac-neg268.5%
associate-+r+68.6%
+-commutative68.6%
remove-double-neg68.6%
distribute-neg-frac268.6%
sub0-neg68.6%
associate-+l-68.6%
neg-sub068.6%
Simplified68.6%
Taylor expanded in x around inf 67.2%
Taylor expanded in x around 0 5.3%
expm1-log1p-u5.3%
expm1-undefine66.9%
log1p-undefine66.9%
metadata-eval66.9%
div-inv66.9%
mul-1-neg66.9%
distribute-neg-in66.9%
add-exp-log66.9%
distribute-neg-in66.9%
metadata-eval66.9%
mul-1-neg66.9%
div-inv66.9%
add-sqr-sqrt32.0%
sqrt-unprod67.2%
frac-times67.2%
metadata-eval67.2%
metadata-eval67.2%
frac-times67.2%
sqrt-unprod35.2%
add-sqr-sqrt67.4%
Applied egg-rr67.4%
associate--l+67.4%
sub-neg67.4%
metadata-eval67.4%
+-commutative67.4%
Simplified67.4%
Final simplification67.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 68.6%
+-commutative68.6%
associate-+r-68.5%
sub-neg68.5%
remove-double-neg68.5%
neg-sub068.5%
associate-+l-68.5%
neg-sub068.5%
distribute-neg-frac268.5%
distribute-frac-neg268.5%
associate-+r+68.6%
+-commutative68.6%
remove-double-neg68.6%
distribute-neg-frac268.6%
sub0-neg68.6%
associate-+l-68.6%
neg-sub068.6%
Simplified68.6%
Taylor expanded in x around inf 67.2%
+-commutative67.2%
clear-num67.2%
frac-2neg67.2%
metadata-eval67.2%
frac-add67.3%
Applied egg-rr52.4%
Taylor expanded in x around 0 6.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 68.6%
+-commutative68.6%
associate-+r-68.5%
sub-neg68.5%
remove-double-neg68.5%
neg-sub068.5%
associate-+l-68.5%
neg-sub068.5%
distribute-neg-frac268.5%
distribute-frac-neg268.5%
associate-+r+68.6%
+-commutative68.6%
remove-double-neg68.6%
distribute-neg-frac268.6%
sub0-neg68.6%
associate-+l-68.6%
neg-sub068.6%
Simplified68.6%
Taylor expanded in x around inf 67.2%
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 68.6%
+-commutative68.6%
associate-+r-68.5%
sub-neg68.5%
remove-double-neg68.5%
neg-sub068.5%
associate-+l-68.5%
neg-sub068.5%
distribute-neg-frac268.5%
distribute-frac-neg268.5%
associate-+r+68.6%
+-commutative68.6%
remove-double-neg68.6%
distribute-neg-frac268.6%
sub0-neg68.6%
associate-+l-68.6%
neg-sub068.6%
Simplified68.6%
Taylor expanded in x around 0 5.3%
(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 68.6%
+-commutative68.6%
associate-+r-68.5%
sub-neg68.5%
remove-double-neg68.5%
neg-sub068.5%
associate-+l-68.5%
neg-sub068.5%
distribute-neg-frac268.5%
distribute-frac-neg268.5%
associate-+r+68.6%
+-commutative68.6%
remove-double-neg68.6%
distribute-neg-frac268.6%
sub0-neg68.6%
associate-+l-68.6%
neg-sub068.6%
Simplified68.6%
Taylor expanded in x around 0 3.4%
Taylor expanded in x around inf 3.4%
(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 2024141
(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))))