
(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}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(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}
(FPCore (x) :precision binary64 (/ (/ -1.0 x) (+ x 1.0)))
double code(double x) {
return (-1.0 / x) / (x + 1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((-1.0d0) / x) / (x + 1.0d0)
end function
public static double code(double x) {
return (-1.0 / x) / (x + 1.0);
}
def code(x): return (-1.0 / x) / (x + 1.0)
function code(x) return Float64(Float64(-1.0 / x) / Float64(x + 1.0)) end
function tmp = code(x) tmp = (-1.0 / x) / (x + 1.0); end
code[x_] := N[(N[(-1.0 / x), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{-1}{x}}{x + 1}
\end{array}
Initial program 78.1%
clear-num78.1%
frac-sub79.1%
*-un-lft-identity79.1%
div-inv79.1%
metadata-eval79.1%
*-rgt-identity79.1%
*-rgt-identity79.1%
+-commutative79.1%
*-commutative79.1%
div-inv79.1%
metadata-eval79.1%
*-rgt-identity79.1%
+-commutative79.1%
Applied egg-rr79.1%
*-un-lft-identity79.1%
associate-/l/79.1%
div-sub78.1%
*-inverses78.1%
sub-neg78.1%
+-commutative78.1%
metadata-eval78.1%
Applied egg-rr78.1%
*-lft-identity78.1%
metadata-eval78.1%
sub-neg78.1%
lft-mult-inverse75.3%
associate-*l/78.1%
*-lft-identity78.1%
div-sub79.1%
rem-square-sqrt24.1%
associate-*r/24.1%
associate-*l/24.1%
associate-*r/24.1%
associate-*l/24.1%
rem-square-sqrt79.1%
associate--r+99.9%
+-inverses99.9%
metadata-eval99.9%
Simplified99.9%
(FPCore (x) :precision binary64 (/ -1.0 (+ x (* x x))))
double code(double x) {
return -1.0 / (x + (x * x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-1.0d0) / (x + (x * x))
end function
public static double code(double x) {
return -1.0 / (x + (x * x));
}
def code(x): return -1.0 / (x + (x * x))
function code(x) return Float64(-1.0 / Float64(x + Float64(x * x))) end
function tmp = code(x) tmp = -1.0 / (x + (x * x)); end
code[x_] := N[(-1.0 / N[(x + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-1}{x + x \cdot x}
\end{array}
Initial program 78.1%
sub-neg78.1%
+-commutative78.1%
distribute-neg-frac78.1%
metadata-eval78.1%
Applied egg-rr78.1%
*-rgt-identity78.1%
cancel-sign-sub78.1%
distribute-neg-frac78.1%
metadata-eval78.1%
*-commutative78.1%
*-inverses78.1%
times-frac56.7%
*-rgt-identity56.7%
*-commutative56.7%
associate-/r*78.0%
div-sub78.1%
*-inverses78.1%
div-sub79.1%
associate-/r*79.1%
+-commutative79.1%
associate--r+99.7%
+-inverses99.7%
metadata-eval99.7%
distribute-lft-in99.7%
unpow299.7%
*-rgt-identity99.7%
Simplified99.7%
unpow299.7%
Applied egg-rr99.7%
(FPCore (x) :precision binary64 (+ (/ -1.0 x) 1.0))
double code(double x) {
return (-1.0 / x) + 1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((-1.0d0) / x) + 1.0d0
end function
public static double code(double x) {
return (-1.0 / x) + 1.0;
}
def code(x): return (-1.0 / x) + 1.0
function code(x) return Float64(Float64(-1.0 / x) + 1.0) end
function tmp = code(x) tmp = (-1.0 / x) + 1.0; end
code[x_] := N[(N[(-1.0 / x), $MachinePrecision] + 1.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{-1}{x} + 1
\end{array}
Initial program 78.1%
Taylor expanded in x around 0 54.0%
div-sub54.0%
*-inverses54.0%
metadata-eval54.0%
distribute-neg-frac54.0%
neg-sub054.0%
associate--r-54.0%
metadata-eval54.0%
Simplified54.0%
Final simplification54.0%
(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}
\\
1 - x
\end{array}
Initial program 78.1%
Taylor expanded in x around 0 53.9%
neg-mul-153.9%
sub-neg53.9%
Simplified53.9%
Taylor expanded in x around inf 2.7%
sub-neg2.7%
metadata-eval2.7%
distribute-lft-in2.7%
rgt-mult-inverse2.7%
*-commutative2.7%
neg-mul-12.7%
sub-neg2.7%
Simplified2.7%
(FPCore (x) :precision binary64 (/ (/ -1.0 x) (+ x 1.0)))
double code(double x) {
return (-1.0 / x) / (x + 1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((-1.0d0) / x) / (x + 1.0d0)
end function
public static double code(double x) {
return (-1.0 / x) / (x + 1.0);
}
def code(x): return (-1.0 / x) / (x + 1.0)
function code(x) return Float64(Float64(-1.0 / x) / Float64(x + 1.0)) end
function tmp = code(x) tmp = (-1.0 / x) / (x + 1.0); end
code[x_] := N[(N[(-1.0 / x), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{-1}{x}}{x + 1}
\end{array}
(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(1.0 / Float64(x * Float64(-1.0 - x))) end
function tmp = code(x) tmp = 1.0 / (x * (-1.0 - x)); end
code[x_] := N[(1.0 / N[(x * N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x \cdot \left(-1 - x\right)}
\end{array}
herbie shell --seed 2024179
(FPCore (x)
:name "2frac (problem 3.3.1)"
:precision binary64
:alt
(! :herbie-platform default (/ (/ -1 x) (+ x 1)))
:alt
(! :herbie-platform default (/ 1 (* x (- -1 x))))
(- (/ 1.0 (+ x 1.0)) (/ 1.0 x)))