
(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 (+ 1.0 x)) (/ -1.0 x)))
double code(double x) {
return (1.0 / (1.0 + x)) * (-1.0 / x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / (1.0d0 + x)) * ((-1.0d0) / x)
end function
public static double code(double x) {
return (1.0 / (1.0 + x)) * (-1.0 / x);
}
def code(x): return (1.0 / (1.0 + x)) * (-1.0 / x)
function code(x) return Float64(Float64(1.0 / Float64(1.0 + x)) * Float64(-1.0 / x)) end
function tmp = code(x) tmp = (1.0 / (1.0 + x)) * (-1.0 / x); end
code[x_] := N[(N[(1.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] * N[(-1.0 / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{1 + x} \cdot \frac{-1}{x}
\end{array}
Initial program 75.8%
clear-num75.8%
frac-sub76.3%
*-un-lft-identity76.3%
div-inv76.3%
metadata-eval76.3%
*-rgt-identity76.3%
*-rgt-identity76.3%
+-commutative76.3%
*-commutative76.3%
div-inv76.3%
metadata-eval76.3%
*-rgt-identity76.3%
+-commutative76.3%
Applied egg-rr76.3%
Taylor expanded in x around 0 99.3%
clear-num99.3%
inv-pow99.3%
*-commutative99.3%
associate-/l*99.3%
unpow-prod-down99.8%
inv-pow99.8%
+-commutative99.8%
inv-pow99.8%
clear-num99.8%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (* (/ -1.0 x) (/ 1.0 x)) (+ (/ -1.0 x) (- 1.0 x))))
double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
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.0d0))) 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.0)) {
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.0): 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.0)) 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 <= 1.0))) 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.0]], $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 1\right):\\
\;\;\;\;\frac{-1}{x} \cdot \frac{1}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{x} + \left(1 - x\right)\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 50.5%
clear-num50.5%
frac-sub51.5%
*-un-lft-identity51.5%
div-inv51.5%
metadata-eval51.5%
*-rgt-identity51.5%
*-rgt-identity51.5%
+-commutative51.5%
*-commutative51.5%
div-inv51.5%
metadata-eval51.5%
*-rgt-identity51.5%
+-commutative51.5%
Applied egg-rr51.5%
Taylor expanded in x around 0 98.6%
clear-num98.6%
inv-pow98.6%
*-commutative98.6%
associate-/l*98.6%
unpow-prod-down99.6%
inv-pow99.6%
+-commutative99.6%
inv-pow99.6%
clear-num99.6%
Applied egg-rr99.6%
Taylor expanded in x around inf 99.4%
if -1 < x < 1Initial program 100.0%
Taylor expanded in x around 0 99.8%
neg-mul-199.8%
unsub-neg99.8%
Simplified99.8%
Final simplification99.6%
(FPCore (x) :precision binary64 (if (or (<= x -1.0) (not (<= x 0.75))) (* (/ -1.0 x) (/ 1.0 x)) (/ (+ x -1.0) x)))
double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 0.75)) {
tmp = (-1.0 / x) * (1.0 / x);
} else {
tmp = (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 <= 0.75d0))) then
tmp = ((-1.0d0) / x) * (1.0d0 / x)
else
tmp = (x + (-1.0d0)) / x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 0.75)) {
tmp = (-1.0 / x) * (1.0 / x);
} else {
tmp = (x + -1.0) / x;
}
return tmp;
}
def code(x): tmp = 0 if (x <= -1.0) or not (x <= 0.75): tmp = (-1.0 / x) * (1.0 / x) else: tmp = (x + -1.0) / x return tmp
function code(x) tmp = 0.0 if ((x <= -1.0) || !(x <= 0.75)) tmp = Float64(Float64(-1.0 / x) * Float64(1.0 / x)); else tmp = Float64(Float64(x + -1.0) / x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -1.0) || ~((x <= 0.75))) tmp = (-1.0 / x) * (1.0 / x); else tmp = (x + -1.0) / x; end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 0.75]], $MachinePrecision]], N[(N[(-1.0 / x), $MachinePrecision] * N[(1.0 / x), $MachinePrecision]), $MachinePrecision], N[(N[(x + -1.0), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 0.75\right):\\
\;\;\;\;\frac{-1}{x} \cdot \frac{1}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{x + -1}{x}\\
\end{array}
\end{array}
if x < -1 or 0.75 < x Initial program 50.5%
clear-num50.5%
frac-sub51.5%
*-un-lft-identity51.5%
div-inv51.5%
metadata-eval51.5%
*-rgt-identity51.5%
*-rgt-identity51.5%
+-commutative51.5%
*-commutative51.5%
div-inv51.5%
metadata-eval51.5%
*-rgt-identity51.5%
+-commutative51.5%
Applied egg-rr51.5%
Taylor expanded in x around 0 98.6%
clear-num98.6%
inv-pow98.6%
*-commutative98.6%
associate-/l*98.6%
unpow-prod-down99.6%
inv-pow99.6%
+-commutative99.6%
inv-pow99.6%
clear-num99.6%
Applied egg-rr99.6%
Taylor expanded in x around inf 99.4%
if -1 < x < 0.75Initial program 100.0%
Taylor expanded in x around 0 99.3%
Final simplification99.4%
(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}
Initial program 75.8%
clear-num75.8%
frac-sub76.3%
*-un-lft-identity76.3%
div-inv76.3%
metadata-eval76.3%
*-rgt-identity76.3%
*-rgt-identity76.3%
+-commutative76.3%
*-commutative76.3%
div-inv76.3%
metadata-eval76.3%
*-rgt-identity76.3%
+-commutative76.3%
Applied egg-rr76.3%
Taylor expanded in x around 0 99.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 75.8%
Taylor expanded in x around 0 52.2%
(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 75.8%
Taylor expanded in x around 0 52.2%
Taylor expanded in x around inf 3.1%
herbie shell --seed 2024105
(FPCore (x)
:name "2frac (problem 3.3.1)"
:precision binary64
(- (/ 1.0 (+ x 1.0)) (/ 1.0 x)))