
(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 6 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)) (* x (- x -1.0))))
double code(double x) {
return (-1.0 + (x - x)) / (x * (x - -1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((-1.0d0) + (x - x)) / (x * (x - (-1.0d0)))
end function
public static double code(double x) {
return (-1.0 + (x - x)) / (x * (x - -1.0));
}
def code(x): return (-1.0 + (x - x)) / (x * (x - -1.0))
function code(x) return Float64(Float64(-1.0 + Float64(x - x)) / Float64(x * Float64(x - -1.0))) end
function tmp = code(x) tmp = (-1.0 + (x - x)) / (x * (x - -1.0)); end
code[x_] := N[(N[(-1.0 + N[(x - x), $MachinePrecision]), $MachinePrecision] / N[(x * N[(x - -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-1 + \left(x - x\right)}{x \cdot \left(x - -1\right)}
\end{array}
Initial program 76.7%
frac-2neg76.7%
frac-2neg76.7%
frac-sub77.1%
distribute-rgt-neg-in77.1%
distribute-lft-neg-in77.1%
metadata-eval77.1%
metadata-eval77.1%
*-un-lft-identity77.1%
cancel-sign-sub77.1%
distribute-rgt-neg-in77.1%
*-rgt-identity77.1%
neg-sub077.1%
+-commutative77.1%
associate--r+77.1%
metadata-eval77.1%
*-commutative77.1%
neg-sub077.1%
+-commutative77.1%
associate--r+77.1%
metadata-eval77.1%
Applied egg-rr77.1%
associate-+r-77.1%
+-commutative77.1%
associate--l+99.9%
distribute-lft-neg-out99.9%
distribute-rgt-neg-in99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x) :precision binary64 (if (or (<= x -1.0) (not (<= x 3.8e+61))) (+ (/ 1.0 x) (/ -1.0 x)) (+ (- 1.0 x) (/ -1.0 x))))
double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 3.8e+61)) {
tmp = (1.0 / x) + (-1.0 / x);
} else {
tmp = (1.0 - x) + (-1.0 / x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-1.0d0)) .or. (.not. (x <= 3.8d+61))) then
tmp = (1.0d0 / x) + ((-1.0d0) / x)
else
tmp = (1.0d0 - x) + ((-1.0d0) / x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 3.8e+61)) {
tmp = (1.0 / x) + (-1.0 / x);
} else {
tmp = (1.0 - x) + (-1.0 / x);
}
return tmp;
}
def code(x): tmp = 0 if (x <= -1.0) or not (x <= 3.8e+61): tmp = (1.0 / x) + (-1.0 / x) else: tmp = (1.0 - x) + (-1.0 / x) return tmp
function code(x) tmp = 0.0 if ((x <= -1.0) || !(x <= 3.8e+61)) tmp = Float64(Float64(1.0 / x) + Float64(-1.0 / x)); else tmp = Float64(Float64(1.0 - x) + Float64(-1.0 / x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -1.0) || ~((x <= 3.8e+61))) tmp = (1.0 / x) + (-1.0 / x); else tmp = (1.0 - x) + (-1.0 / x); end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 3.8e+61]], $MachinePrecision]], N[(N[(1.0 / x), $MachinePrecision] + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 - x), $MachinePrecision] + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 3.8 \cdot 10^{+61}\right):\\
\;\;\;\;\frac{1}{x} + \frac{-1}{x}\\
\mathbf{else}:\\
\;\;\;\;\left(1 - x\right) + \frac{-1}{x}\\
\end{array}
\end{array}
if x < -1 or 3.79999999999999995e61 < x Initial program 56.6%
Taylor expanded in x around inf 55.0%
if -1 < x < 3.79999999999999995e61Initial program 91.6%
Taylor expanded in x around 0 90.0%
mul-1-neg90.0%
sub-neg90.0%
Simplified90.0%
Final simplification75.1%
(FPCore (x) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.55))) (/ -1.0 (* x (+ -1.0 x))) (+ (- 1.0 x) (/ -1.0 x))))
double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 1.55)) {
tmp = -1.0 / (x * (-1.0 + x));
} else {
tmp = (1.0 - x) + (-1.0 / x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-1.0d0)) .or. (.not. (x <= 1.55d0))) then
tmp = (-1.0d0) / (x * ((-1.0d0) + x))
else
tmp = (1.0d0 - x) + ((-1.0d0) / x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 1.55)) {
tmp = -1.0 / (x * (-1.0 + x));
} else {
tmp = (1.0 - x) + (-1.0 / x);
}
return tmp;
}
def code(x): tmp = 0 if (x <= -1.0) or not (x <= 1.55): tmp = -1.0 / (x * (-1.0 + x)) else: tmp = (1.0 - x) + (-1.0 / x) return tmp
function code(x) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.55)) tmp = Float64(-1.0 / Float64(x * Float64(-1.0 + x))); else tmp = Float64(Float64(1.0 - x) + Float64(-1.0 / x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -1.0) || ~((x <= 1.55))) tmp = -1.0 / (x * (-1.0 + x)); else tmp = (1.0 - x) + (-1.0 / x); end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 1.55]], $MachinePrecision]], N[(-1.0 / N[(x * N[(-1.0 + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 - x), $MachinePrecision] + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1.55\right):\\
\;\;\;\;\frac{-1}{x \cdot \left(-1 + x\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(1 - x\right) + \frac{-1}{x}\\
\end{array}
\end{array}
if x < -1 or 1.55000000000000004 < x Initial program 52.0%
frac-sub52.7%
*-commutative52.7%
associate-/r*52.7%
*-un-lft-identity52.7%
*-rgt-identity52.7%
sub-neg52.7%
neg-sub052.7%
+-commutative52.7%
associate--r+52.7%
metadata-eval52.7%
+-commutative52.7%
Applied egg-rr52.7%
Taylor expanded in x around 0 99.8%
div-inv99.5%
add-sqr-sqrt48.8%
associate-*l*48.9%
add-sqr-sqrt48.9%
sqrt-unprod48.9%
frac-times48.9%
metadata-eval48.9%
associate-/l/48.9%
un-div-inv48.9%
sqrt-unprod0.0%
add-sqr-sqrt0.0%
inv-pow0.0%
sqrt-pow10.0%
metadata-eval0.0%
*-commutative0.0%
Applied egg-rr49.2%
*-commutative49.2%
associate-*l*49.3%
associate-*l/49.3%
pow-sqr97.3%
metadata-eval97.3%
unpow-197.3%
neg-mul-197.3%
distribute-neg-frac97.3%
metadata-eval97.3%
associate-/l/97.4%
*-commutative97.4%
Simplified97.4%
if -1 < x < 1.55000000000000004Initial program 100.0%
Taylor expanded in x around 0 99.4%
mul-1-neg99.4%
sub-neg99.4%
Simplified99.4%
Final simplification98.4%
(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 76.7%
frac-sub77.1%
*-commutative77.1%
associate-/r*77.1%
*-un-lft-identity77.1%
*-rgt-identity77.1%
sub-neg77.1%
neg-sub077.1%
+-commutative77.1%
associate--r+77.1%
metadata-eval77.1%
+-commutative77.1%
Applied egg-rr77.1%
Taylor expanded in x around 0 99.9%
Final simplification99.9%
(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 76.7%
Taylor expanded in x around 0 53.5%
Final simplification53.5%
(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 76.7%
frac-2neg76.7%
frac-2neg76.7%
frac-sub77.1%
distribute-rgt-neg-in77.1%
distribute-lft-neg-in77.1%
metadata-eval77.1%
metadata-eval77.1%
*-un-lft-identity77.1%
cancel-sign-sub77.1%
distribute-rgt-neg-in77.1%
*-rgt-identity77.1%
neg-sub077.1%
+-commutative77.1%
associate--r+77.1%
metadata-eval77.1%
*-commutative77.1%
neg-sub077.1%
+-commutative77.1%
associate--r+77.1%
metadata-eval77.1%
Applied egg-rr77.1%
associate-+r-77.1%
+-commutative77.1%
associate--l+99.9%
distribute-lft-neg-out99.9%
distribute-rgt-neg-in99.9%
Simplified99.9%
Applied egg-rr1.1%
associate-*l/1.1%
associate-*r/1.1%
associate-/l/1.1%
mul-1-neg1.1%
rem-square-sqrt2.9%
+-commutative2.9%
Simplified2.9%
Taylor expanded in x around inf 3.9%
Final simplification3.9%
herbie shell --seed 2023301
(FPCore (x)
:name "2frac (problem 3.3.1)"
:precision binary64
(- (/ 1.0 (+ x 1.0)) (/ 1.0 x)))