
(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 9 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 (* (pow x -3.0) 2.0))
double code(double x) {
return pow(x, -3.0) * 2.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x ** (-3.0d0)) * 2.0d0
end function
public static double code(double x) {
return Math.pow(x, -3.0) * 2.0;
}
def code(x): return math.pow(x, -3.0) * 2.0
function code(x) return Float64((x ^ -3.0) * 2.0) end
function tmp = code(x) tmp = (x ^ -3.0) * 2.0; end
code[x_] := N[(N[Power[x, -3.0], $MachinePrecision] * 2.0), $MachinePrecision]
\begin{array}{l}
\\
{x}^{-3} \cdot 2
\end{array}
Initial program 72.9%
Taylor expanded in x around inf 98.8%
clear-num98.8%
associate-/r/98.8%
pow-flip99.1%
metadata-eval99.1%
Applied egg-rr99.1%
Final simplification99.1%
(FPCore (x) :precision binary64 (/ (- (/ 2.0 (* x x)) (/ 2.0 x)) (* x (- 1.0 x))))
double code(double x) {
return ((2.0 / (x * x)) - (2.0 / x)) / (x * (1.0 - x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((2.0d0 / (x * x)) - (2.0d0 / x)) / (x * (1.0d0 - x))
end function
public static double code(double x) {
return ((2.0 / (x * x)) - (2.0 / x)) / (x * (1.0 - x));
}
def code(x): return ((2.0 / (x * x)) - (2.0 / x)) / (x * (1.0 - x))
function code(x) return Float64(Float64(Float64(2.0 / Float64(x * x)) - Float64(2.0 / x)) / Float64(x * Float64(1.0 - x))) end
function tmp = code(x) tmp = ((2.0 / (x * x)) - (2.0 / x)) / (x * (1.0 - x)); end
code[x_] := N[(N[(N[(2.0 / N[(x * x), $MachinePrecision]), $MachinePrecision] - N[(2.0 / x), $MachinePrecision]), $MachinePrecision] / N[(x * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{2}{x \cdot x} - \frac{2}{x}}{x \cdot \left(1 - x\right)}
\end{array}
Initial program 72.9%
frac-sub16.7%
/-rgt-identity16.7%
*-un-lft-identity16.7%
/-rgt-identity16.7%
+-commutative16.7%
*-commutative16.7%
+-commutative16.7%
Applied egg-rr16.7%
associate-/l/72.9%
+-commutative72.9%
frac-2neg72.9%
metadata-eval72.9%
frac-add72.9%
Applied egg-rr72.9%
Taylor expanded in x around inf 98.9%
associate-*r/98.9%
metadata-eval98.9%
associate-*r/98.9%
metadata-eval98.9%
Simplified98.9%
unpow298.9%
Applied egg-rr98.9%
Final simplification98.9%
(FPCore (x) :precision binary64 (+ (/ -1.0 x) (/ 1.0 (+ x -1.0))))
double code(double x) {
return (-1.0 / x) + (1.0 / (x + -1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((-1.0d0) / x) + (1.0d0 / (x + (-1.0d0)))
end function
public static double code(double x) {
return (-1.0 / x) + (1.0 / (x + -1.0));
}
def code(x): return (-1.0 / x) + (1.0 / (x + -1.0))
function code(x) return Float64(Float64(-1.0 / x) + Float64(1.0 / Float64(x + -1.0))) end
function tmp = code(x) tmp = (-1.0 / x) + (1.0 / (x + -1.0)); end
code[x_] := N[(N[(-1.0 / x), $MachinePrecision] + N[(1.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-1}{x} + \frac{1}{x + -1}
\end{array}
Initial program 72.9%
Taylor expanded in x around inf 71.6%
Final simplification71.6%
(FPCore (x) :precision binary64 (/ (/ -2.0 x) (* x (- 1.0 x))))
double code(double x) {
return (-2.0 / x) / (x * (1.0 - x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((-2.0d0) / x) / (x * (1.0d0 - x))
end function
public static double code(double x) {
return (-2.0 / x) / (x * (1.0 - x));
}
def code(x): return (-2.0 / x) / (x * (1.0 - x))
function code(x) return Float64(Float64(-2.0 / x) / Float64(x * Float64(1.0 - x))) end
function tmp = code(x) tmp = (-2.0 / x) / (x * (1.0 - x)); end
code[x_] := N[(N[(-2.0 / x), $MachinePrecision] / N[(x * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{-2}{x}}{x \cdot \left(1 - x\right)}
\end{array}
Initial program 72.9%
frac-sub16.7%
/-rgt-identity16.7%
*-un-lft-identity16.7%
/-rgt-identity16.7%
+-commutative16.7%
*-commutative16.7%
+-commutative16.7%
Applied egg-rr16.7%
associate-/l/72.9%
+-commutative72.9%
frac-2neg72.9%
metadata-eval72.9%
frac-add72.9%
Applied egg-rr72.9%
Taylor expanded in x around inf 98.9%
associate-*r/98.9%
metadata-eval98.9%
associate-*r/98.9%
metadata-eval98.9%
Simplified98.9%
Taylor expanded in x around inf 98.2%
Final simplification98.2%
(FPCore (x) :precision binary64 (/ -2.0 (* x (- 1.0 x))))
double code(double x) {
return -2.0 / (x * (1.0 - x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-2.0d0) / (x * (1.0d0 - x))
end function
public static double code(double x) {
return -2.0 / (x * (1.0 - x));
}
def code(x): return -2.0 / (x * (1.0 - x))
function code(x) return Float64(-2.0 / Float64(x * Float64(1.0 - x))) end
function tmp = code(x) tmp = -2.0 / (x * (1.0 - x)); end
code[x_] := N[(-2.0 / N[(x * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-2}{x \cdot \left(1 - x\right)}
\end{array}
Initial program 72.9%
frac-sub16.7%
/-rgt-identity16.7%
*-un-lft-identity16.7%
/-rgt-identity16.7%
+-commutative16.7%
*-commutative16.7%
+-commutative16.7%
Applied egg-rr16.7%
associate-/l/72.9%
+-commutative72.9%
frac-2neg72.9%
metadata-eval72.9%
frac-add72.9%
Applied egg-rr72.9%
Taylor expanded in x around 0 58.9%
Final simplification58.9%
(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 72.9%
Taylor expanded in x around 0 5.3%
Final simplification5.3%
(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 72.9%
Taylor expanded in x around inf 71.6%
Taylor expanded in x around 0 5.3%
Final simplification5.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 72.9%
div-inv72.9%
cancel-sign-sub-inv72.9%
metadata-eval72.9%
div-inv72.9%
+-commutative72.9%
clear-num72.9%
frac-2neg72.9%
metadata-eval72.9%
frac-add16.7%
Applied egg-rr6.3%
*-commutative6.3%
associate-*r*6.3%
*-commutative6.3%
distribute-rgt-in6.3%
neg-mul-16.3%
*-rgt-identity6.3%
distribute-lft-in6.3%
distribute-lft-neg-in6.3%
associate-/r*6.3%
Simplified6.3%
Taylor expanded in x around 0 6.3%
Final simplification6.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 72.9%
Taylor expanded in x around 0 3.3%
associate-*r/3.3%
metadata-eval3.3%
Simplified3.3%
Taylor expanded in x around inf 3.3%
Final simplification3.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 2024011
(FPCore (x)
:name "3frac (problem 3.3.3)"
:precision binary64
:pre (> (fabs x) 1.0)
:herbie-target
(/ 2.0 (* x (- (* x x) 1.0)))
(+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))