
(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) x)))
double code(double x) {
return 2.0 / (pow(x, 3.0) - x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0 / ((x ** 3.0d0) - x)
end function
public static double code(double x) {
return 2.0 / (Math.pow(x, 3.0) - x);
}
def code(x): return 2.0 / (math.pow(x, 3.0) - x)
function code(x) return Float64(2.0 / Float64((x ^ 3.0) - x)) end
function tmp = code(x) tmp = 2.0 / ((x ^ 3.0) - x); end
code[x_] := N[(2.0 / N[(N[Power[x, 3.0], $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{{x}^{3} - x}
\end{array}
Initial program 69.2%
sub-neg69.2%
distribute-neg-frac69.2%
metadata-eval69.2%
metadata-eval69.2%
metadata-eval69.2%
associate-/r*69.2%
metadata-eval69.2%
neg-mul-169.2%
+-commutative69.2%
associate-+l+69.2%
+-commutative69.2%
neg-mul-169.2%
metadata-eval69.2%
associate-/r*69.2%
metadata-eval69.2%
metadata-eval69.2%
+-commutative69.2%
+-commutative69.2%
sub-neg69.2%
metadata-eval69.2%
Simplified69.2%
+-commutative69.2%
frac-add21.0%
frac-add20.6%
*-un-lft-identity20.6%
*-rgt-identity20.6%
+-commutative20.6%
+-commutative20.6%
+-commutative20.6%
+-commutative20.6%
Applied egg-rr20.6%
Taylor expanded in x around 0 99.6%
expm1-log1p-u99.6%
expm1-udef68.8%
*-commutative68.8%
metadata-eval68.8%
sub-neg68.8%
difference-of-sqr-168.8%
distribute-rgt-out--68.8%
unpow368.8%
*-un-lft-identity68.8%
Applied egg-rr68.8%
expm1-def99.7%
expm1-log1p99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (x) :precision binary64 (/ 2.0 (* x (* (+ x 1.0) (+ x -1.0)))))
double code(double x) {
return 2.0 / (x * ((x + 1.0) * (x + -1.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0 / (x * ((x + 1.0d0) * (x + (-1.0d0))))
end function
public static double code(double x) {
return 2.0 / (x * ((x + 1.0) * (x + -1.0)));
}
def code(x): return 2.0 / (x * ((x + 1.0) * (x + -1.0)))
function code(x) return Float64(2.0 / Float64(x * Float64(Float64(x + 1.0) * Float64(x + -1.0)))) end
function tmp = code(x) tmp = 2.0 / (x * ((x + 1.0) * (x + -1.0))); end
code[x_] := N[(2.0 / N[(x * N[(N[(x + 1.0), $MachinePrecision] * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{x \cdot \left(\left(x + 1\right) \cdot \left(x + -1\right)\right)}
\end{array}
Initial program 69.2%
sub-neg69.2%
distribute-neg-frac69.2%
metadata-eval69.2%
metadata-eval69.2%
metadata-eval69.2%
associate-/r*69.2%
metadata-eval69.2%
neg-mul-169.2%
+-commutative69.2%
associate-+l+69.2%
+-commutative69.2%
neg-mul-169.2%
metadata-eval69.2%
associate-/r*69.2%
metadata-eval69.2%
metadata-eval69.2%
+-commutative69.2%
+-commutative69.2%
sub-neg69.2%
metadata-eval69.2%
Simplified69.2%
+-commutative69.2%
frac-add21.0%
frac-add20.6%
*-un-lft-identity20.6%
*-rgt-identity20.6%
+-commutative20.6%
+-commutative20.6%
+-commutative20.6%
+-commutative20.6%
Applied egg-rr20.6%
Taylor expanded in x around 0 99.6%
Final simplification99.6%
(FPCore (x) :precision binary64 (/ 2.0 (* (+ x 1.0) (* x (+ x -1.0)))))
double code(double x) {
return 2.0 / ((x + 1.0) * (x * (x + -1.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0 / ((x + 1.0d0) * (x * (x + (-1.0d0))))
end function
public static double code(double x) {
return 2.0 / ((x + 1.0) * (x * (x + -1.0)));
}
def code(x): return 2.0 / ((x + 1.0) * (x * (x + -1.0)))
function code(x) return Float64(2.0 / Float64(Float64(x + 1.0) * Float64(x * Float64(x + -1.0)))) end
function tmp = code(x) tmp = 2.0 / ((x + 1.0) * (x * (x + -1.0))); end
code[x_] := N[(2.0 / N[(N[(x + 1.0), $MachinePrecision] * N[(x * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{\left(x + 1\right) \cdot \left(x \cdot \left(x + -1\right)\right)}
\end{array}
Initial program 69.2%
sub-neg69.2%
distribute-neg-frac69.2%
metadata-eval69.2%
metadata-eval69.2%
metadata-eval69.2%
associate-/r*69.2%
metadata-eval69.2%
neg-mul-169.2%
+-commutative69.2%
associate-+l+69.2%
+-commutative69.2%
neg-mul-169.2%
metadata-eval69.2%
associate-/r*69.2%
metadata-eval69.2%
metadata-eval69.2%
+-commutative69.2%
+-commutative69.2%
sub-neg69.2%
metadata-eval69.2%
Simplified69.2%
+-commutative69.2%
frac-add21.0%
frac-add20.6%
*-un-lft-identity20.6%
*-rgt-identity20.6%
+-commutative20.6%
+-commutative20.6%
+-commutative20.6%
+-commutative20.6%
Applied egg-rr20.6%
Taylor expanded in x around 0 99.6%
expm1-log1p-u48.9%
expm1-udef48.9%
associate-*l*48.9%
+-commutative48.9%
Applied egg-rr48.9%
expm1-def48.9%
expm1-log1p99.6%
+-commutative99.6%
*-commutative99.6%
Simplified99.6%
Final simplification99.6%
(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 69.2%
sub-neg69.2%
distribute-neg-frac69.2%
metadata-eval69.2%
metadata-eval69.2%
metadata-eval69.2%
associate-/r*69.2%
metadata-eval69.2%
neg-mul-169.2%
+-commutative69.2%
associate-+l+69.2%
+-commutative69.2%
neg-mul-169.2%
metadata-eval69.2%
associate-/r*69.2%
metadata-eval69.2%
metadata-eval69.2%
+-commutative69.2%
+-commutative69.2%
sub-neg69.2%
metadata-eval69.2%
Simplified69.2%
Taylor expanded in x around inf 67.2%
Final simplification67.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 69.2%
sub-neg69.2%
distribute-neg-frac69.2%
metadata-eval69.2%
metadata-eval69.2%
metadata-eval69.2%
associate-/r*69.2%
metadata-eval69.2%
neg-mul-169.2%
+-commutative69.2%
associate-+l+69.2%
+-commutative69.2%
neg-mul-169.2%
metadata-eval69.2%
associate-/r*69.2%
metadata-eval69.2%
metadata-eval69.2%
+-commutative69.2%
+-commutative69.2%
sub-neg69.2%
metadata-eval69.2%
Simplified69.2%
Taylor expanded in x around 0 4.9%
Final simplification4.9%
(FPCore (x) :precision binary64 -9.0)
double code(double x) {
return -9.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = -9.0d0
end function
public static double code(double x) {
return -9.0;
}
def code(x): return -9.0
function code(x) return -9.0 end
function tmp = code(x) tmp = -9.0; end
code[x_] := -9.0
\begin{array}{l}
\\
-9
\end{array}
Initial program 69.2%
sub-neg69.2%
distribute-neg-frac69.2%
metadata-eval69.2%
metadata-eval69.2%
metadata-eval69.2%
associate-/r*69.2%
metadata-eval69.2%
neg-mul-169.2%
+-commutative69.2%
associate-+l+69.2%
+-commutative69.2%
neg-mul-169.2%
metadata-eval69.2%
associate-/r*69.2%
metadata-eval69.2%
metadata-eval69.2%
+-commutative69.2%
+-commutative69.2%
sub-neg69.2%
metadata-eval69.2%
Simplified69.2%
frac-add21.0%
div-inv16.5%
*-un-lft-identity16.5%
*-rgt-identity16.5%
+-commutative16.5%
+-commutative16.5%
metadata-eval16.5%
frac-times19.0%
clear-num19.0%
frac-times16.5%
metadata-eval16.5%
+-commutative16.5%
/-rgt-identity16.5%
Applied egg-rr16.5%
associate-*r/21.0%
*-rgt-identity21.0%
associate-+l+21.0%
+-commutative21.0%
associate-+r+21.0%
metadata-eval21.0%
*-commutative21.0%
Simplified21.0%
Applied egg-rr0.0%
Simplified3.4%
Final simplification3.4%
(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 69.2%
associate-+l-69.2%
sub-neg69.2%
+-commutative69.2%
neg-sub069.2%
associate-+l-69.2%
neg-sub069.2%
distribute-neg-frac69.2%
metadata-eval69.2%
sub-neg69.2%
metadata-eval69.2%
Simplified69.2%
clear-num69.2%
frac-2neg69.2%
metadata-eval69.2%
frac-add21.1%
*-un-lft-identity21.1%
+-commutative21.1%
distribute-neg-in21.1%
metadata-eval21.1%
sub-neg21.1%
div-inv21.1%
metadata-eval21.1%
div-inv21.1%
metadata-eval21.1%
+-commutative21.1%
distribute-neg-in21.1%
metadata-eval21.1%
sub-neg21.1%
Applied egg-rr21.1%
associate-+l-21.1%
*-commutative21.1%
associate-*r*21.1%
neg-mul-121.1%
cancel-sign-sub21.1%
+-commutative21.1%
*-commutative21.1%
distribute-lft1-in21.1%
metadata-eval21.1%
metadata-eval21.1%
*-commutative21.1%
metadata-eval21.1%
associate-*l*21.1%
Simplified21.1%
Taylor expanded in x around 0 3.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 2024020
(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))))