
(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 10 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 (fma x x x)) (- 1.0 x)))
double code(double x) {
return (-2.0 / fma(x, x, x)) / (1.0 - x);
}
function code(x) return Float64(Float64(-2.0 / fma(x, x, x)) / Float64(1.0 - x)) end
code[x_] := N[(N[(-2.0 / N[(x * x + x), $MachinePrecision]), $MachinePrecision] / N[(1.0 - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{-2}{\mathsf{fma}\left(x, x, x\right)}}{1 - x}
\end{array}
Initial program 80.7%
remove-double-neg80.7%
sub-neg80.7%
sub-neg80.7%
distribute-neg-frac80.7%
metadata-eval80.7%
metadata-eval80.7%
metadata-eval80.7%
associate-/r*80.7%
metadata-eval80.7%
neg-mul-180.7%
associate--l+80.7%
+-commutative80.7%
distribute-neg-frac80.7%
metadata-eval80.7%
metadata-eval80.7%
metadata-eval80.7%
associate-/r*80.7%
metadata-eval80.7%
neg-mul-180.7%
sub0-neg80.7%
associate-+l-80.7%
neg-sub080.7%
Simplified80.7%
frac-sub55.5%
div-inv54.0%
*-rgt-identity54.0%
Applied egg-rr54.0%
associate-/r*57.4%
Simplified57.4%
associate-*r/80.7%
frac-add79.4%
*-un-lft-identity79.4%
div-inv80.7%
Applied egg-rr80.7%
Taylor expanded in x around 0 99.9%
div-inv99.9%
*-un-lft-identity99.9%
times-frac99.9%
metadata-eval99.9%
+-commutative99.9%
Applied egg-rr99.9%
associate-*r/99.9%
metadata-eval99.9%
distribute-lft-neg-in99.9%
associate-*r/99.9%
metadata-eval99.9%
distribute-neg-frac99.9%
metadata-eval99.9%
*-rgt-identity99.9%
times-frac99.8%
associate-*r/99.9%
*-rgt-identity99.9%
associate-/l/99.9%
distribute-lft1-in99.9%
fma-udef99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x)
:precision binary64
(if (<= x -0.65)
(+ (/ -1.0 x) (/ 1.0 (+ x 1.0)))
(if (<= x 1.0)
(+ (- 1.0 x) (+ (/ -2.0 x) (- -1.0 x)))
(+ (/ 1.0 x) (/ -1.0 x)))))
double code(double x) {
double tmp;
if (x <= -0.65) {
tmp = (-1.0 / x) + (1.0 / (x + 1.0));
} else if (x <= 1.0) {
tmp = (1.0 - x) + ((-2.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 <= (-0.65d0)) then
tmp = ((-1.0d0) / x) + (1.0d0 / (x + 1.0d0))
else if (x <= 1.0d0) then
tmp = (1.0d0 - x) + (((-2.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 <= -0.65) {
tmp = (-1.0 / x) + (1.0 / (x + 1.0));
} else if (x <= 1.0) {
tmp = (1.0 - x) + ((-2.0 / x) + (-1.0 - x));
} else {
tmp = (1.0 / x) + (-1.0 / x);
}
return tmp;
}
def code(x): tmp = 0 if x <= -0.65: tmp = (-1.0 / x) + (1.0 / (x + 1.0)) elif x <= 1.0: tmp = (1.0 - x) + ((-2.0 / x) + (-1.0 - x)) else: tmp = (1.0 / x) + (-1.0 / x) return tmp
function code(x) tmp = 0.0 if (x <= -0.65) tmp = Float64(Float64(-1.0 / x) + Float64(1.0 / Float64(x + 1.0))); elseif (x <= 1.0) tmp = Float64(Float64(1.0 - x) + Float64(Float64(-2.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 <= -0.65) tmp = (-1.0 / x) + (1.0 / (x + 1.0)); elseif (x <= 1.0) tmp = (1.0 - x) + ((-2.0 / x) + (-1.0 - x)); else tmp = (1.0 / x) + (-1.0 / x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -0.65], N[(N[(-1.0 / x), $MachinePrecision] + N[(1.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.0], N[(N[(1.0 - x), $MachinePrecision] + N[(N[(-2.0 / x), $MachinePrecision] + 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 -0.65:\\
\;\;\;\;\frac{-1}{x} + \frac{1}{x + 1}\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;\left(1 - x\right) + \left(\frac{-2}{x} + \left(-1 - x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x} + \frac{-1}{x}\\
\end{array}
\end{array}
if x < -0.650000000000000022Initial program 67.9%
remove-double-neg67.9%
sub-neg67.9%
sub-neg67.9%
distribute-neg-frac67.9%
metadata-eval67.9%
metadata-eval67.9%
metadata-eval67.9%
associate-/r*67.9%
metadata-eval67.9%
neg-mul-167.9%
associate--l+67.9%
+-commutative67.9%
distribute-neg-frac67.9%
metadata-eval67.9%
metadata-eval67.9%
metadata-eval67.9%
associate-/r*67.9%
metadata-eval67.9%
neg-mul-167.9%
sub0-neg67.9%
associate-+l-67.9%
neg-sub067.9%
Simplified67.9%
Taylor expanded in x around inf 66.8%
if -0.650000000000000022 < x < 1Initial program 100.0%
remove-double-neg100.0%
sub-neg100.0%
sub-neg100.0%
distribute-neg-frac100.0%
metadata-eval100.0%
metadata-eval100.0%
metadata-eval100.0%
associate-/r*100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate--l+100.0%
+-commutative100.0%
distribute-neg-frac100.0%
metadata-eval100.0%
metadata-eval100.0%
metadata-eval100.0%
associate-/r*100.0%
metadata-eval100.0%
neg-mul-1100.0%
sub0-neg100.0%
associate-+l-100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in x around 0 99.2%
+-commutative99.2%
Simplified99.2%
Taylor expanded in x around 0 99.3%
neg-mul-199.3%
sub-neg99.3%
Simplified99.3%
if 1 < x Initial program 61.8%
remove-double-neg61.8%
sub-neg61.8%
sub-neg61.8%
distribute-neg-frac61.8%
metadata-eval61.8%
metadata-eval61.8%
metadata-eval61.8%
associate-/r*61.8%
metadata-eval61.8%
neg-mul-161.8%
associate--l+61.8%
+-commutative61.8%
distribute-neg-frac61.8%
metadata-eval61.8%
metadata-eval61.8%
metadata-eval61.8%
associate-/r*61.8%
metadata-eval61.8%
neg-mul-161.8%
sub0-neg61.8%
associate-+l-61.8%
neg-sub061.8%
Simplified61.8%
Taylor expanded in x around inf 61.8%
Taylor expanded in x around inf 61.8%
Final simplification80.1%
(FPCore (x)
:precision binary64
(if (<= x -0.65)
(/ (- (+ x 1.0) x) (* x (- -1.0 x)))
(if (<= x 1.0)
(+ (- 1.0 x) (+ (/ -2.0 x) (- -1.0 x)))
(+ (/ 1.0 x) (/ -1.0 x)))))
double code(double x) {
double tmp;
if (x <= -0.65) {
tmp = ((x + 1.0) - x) / (x * (-1.0 - x));
} else if (x <= 1.0) {
tmp = (1.0 - x) + ((-2.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 <= (-0.65d0)) then
tmp = ((x + 1.0d0) - x) / (x * ((-1.0d0) - x))
else if (x <= 1.0d0) then
tmp = (1.0d0 - x) + (((-2.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 <= -0.65) {
tmp = ((x + 1.0) - x) / (x * (-1.0 - x));
} else if (x <= 1.0) {
tmp = (1.0 - x) + ((-2.0 / x) + (-1.0 - x));
} else {
tmp = (1.0 / x) + (-1.0 / x);
}
return tmp;
}
def code(x): tmp = 0 if x <= -0.65: tmp = ((x + 1.0) - x) / (x * (-1.0 - x)) elif x <= 1.0: tmp = (1.0 - x) + ((-2.0 / x) + (-1.0 - x)) else: tmp = (1.0 / x) + (-1.0 / x) return tmp
function code(x) tmp = 0.0 if (x <= -0.65) tmp = Float64(Float64(Float64(x + 1.0) - x) / Float64(x * Float64(-1.0 - x))); elseif (x <= 1.0) tmp = Float64(Float64(1.0 - x) + Float64(Float64(-2.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 <= -0.65) tmp = ((x + 1.0) - x) / (x * (-1.0 - x)); elseif (x <= 1.0) tmp = (1.0 - x) + ((-2.0 / x) + (-1.0 - x)); else tmp = (1.0 / x) + (-1.0 / x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -0.65], N[(N[(N[(x + 1.0), $MachinePrecision] - x), $MachinePrecision] / N[(x * N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.0], N[(N[(1.0 - x), $MachinePrecision] + N[(N[(-2.0 / x), $MachinePrecision] + 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 -0.65:\\
\;\;\;\;\frac{\left(x + 1\right) - x}{x \cdot \left(-1 - x\right)}\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;\left(1 - x\right) + \left(\frac{-2}{x} + \left(-1 - x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x} + \frac{-1}{x}\\
\end{array}
\end{array}
if x < -0.650000000000000022Initial program 67.9%
remove-double-neg67.9%
sub-neg67.9%
sub-neg67.9%
distribute-neg-frac67.9%
metadata-eval67.9%
metadata-eval67.9%
metadata-eval67.9%
associate-/r*67.9%
metadata-eval67.9%
neg-mul-167.9%
associate--l+67.9%
+-commutative67.9%
distribute-neg-frac67.9%
metadata-eval67.9%
metadata-eval67.9%
metadata-eval67.9%
associate-/r*67.9%
metadata-eval67.9%
neg-mul-167.9%
sub0-neg67.9%
associate-+l-67.9%
neg-sub067.9%
Simplified67.9%
Taylor expanded in x around inf 66.8%
frac-2neg66.8%
metadata-eval66.8%
frac-add66.8%
*-un-lft-identity66.8%
*-commutative66.8%
*-un-lft-identity66.8%
Applied egg-rr66.8%
+-commutative66.8%
unsub-neg66.8%
+-commutative66.8%
*-commutative66.8%
distribute-lft-neg-out66.8%
distribute-rgt-neg-in66.8%
distribute-neg-in66.8%
metadata-eval66.8%
unsub-neg66.8%
Simplified66.8%
if -0.650000000000000022 < x < 1Initial program 100.0%
remove-double-neg100.0%
sub-neg100.0%
sub-neg100.0%
distribute-neg-frac100.0%
metadata-eval100.0%
metadata-eval100.0%
metadata-eval100.0%
associate-/r*100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate--l+100.0%
+-commutative100.0%
distribute-neg-frac100.0%
metadata-eval100.0%
metadata-eval100.0%
metadata-eval100.0%
associate-/r*100.0%
metadata-eval100.0%
neg-mul-1100.0%
sub0-neg100.0%
associate-+l-100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in x around 0 99.2%
+-commutative99.2%
Simplified99.2%
Taylor expanded in x around 0 99.3%
neg-mul-199.3%
sub-neg99.3%
Simplified99.3%
if 1 < x Initial program 61.8%
remove-double-neg61.8%
sub-neg61.8%
sub-neg61.8%
distribute-neg-frac61.8%
metadata-eval61.8%
metadata-eval61.8%
metadata-eval61.8%
associate-/r*61.8%
metadata-eval61.8%
neg-mul-161.8%
associate--l+61.8%
+-commutative61.8%
distribute-neg-frac61.8%
metadata-eval61.8%
metadata-eval61.8%
metadata-eval61.8%
associate-/r*61.8%
metadata-eval61.8%
neg-mul-161.8%
sub0-neg61.8%
associate-+l-61.8%
neg-sub061.8%
Simplified61.8%
Taylor expanded in x around inf 61.8%
Taylor expanded in x around inf 61.8%
Final simplification80.1%
(FPCore (x) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (+ (/ 1.0 x) (/ -1.0 x)) (- (- x) (/ 2.0 x))))
double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = (1.0 / x) + (-1.0 / x);
} else {
tmp = -x - (2.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 = -x - (2.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 = -x - (2.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 = -x - (2.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(-x) - Float64(2.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 = -x - (2.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[((-x) - N[(2.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} + \frac{-1}{x}\\
\mathbf{else}:\\
\;\;\;\;\left(-x\right) - \frac{2}{x}\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 65.0%
remove-double-neg65.0%
sub-neg65.0%
sub-neg65.0%
distribute-neg-frac65.0%
metadata-eval65.0%
metadata-eval65.0%
metadata-eval65.0%
associate-/r*65.0%
metadata-eval65.0%
neg-mul-165.0%
associate--l+65.0%
+-commutative65.0%
distribute-neg-frac65.0%
metadata-eval65.0%
metadata-eval65.0%
metadata-eval65.0%
associate-/r*65.0%
metadata-eval65.0%
neg-mul-165.0%
sub0-neg65.0%
associate-+l-65.0%
neg-sub065.0%
Simplified65.0%
Taylor expanded in x around inf 64.4%
Taylor expanded in x around inf 64.3%
if -1 < x < 1Initial program 100.0%
remove-double-neg100.0%
sub-neg100.0%
sub-neg100.0%
distribute-neg-frac100.0%
metadata-eval100.0%
metadata-eval100.0%
metadata-eval100.0%
associate-/r*100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate--l+100.0%
+-commutative100.0%
distribute-neg-frac100.0%
metadata-eval100.0%
metadata-eval100.0%
metadata-eval100.0%
associate-/r*100.0%
metadata-eval100.0%
neg-mul-1100.0%
sub0-neg100.0%
associate-+l-100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in x around 0 98.9%
distribute-neg-in98.9%
metadata-eval98.9%
unsub-neg98.9%
associate-*r/98.9%
metadata-eval98.9%
Simplified98.9%
Taylor expanded in x around 0 98.9%
neg-mul-198.9%
associate-*r/98.9%
metadata-eval98.9%
Simplified98.9%
Final simplification79.8%
(FPCore (x) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (+ (/ 1.0 x) (/ -1.0 x)) (- (* -2.0 x) (/ 2.0 x))))
double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = (1.0 / x) + (-1.0 / x);
} else {
tmp = (-2.0 * x) - (2.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 = ((-2.0d0) * x) - (2.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 = (-2.0 * x) - (2.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 = (-2.0 * x) - (2.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(-2.0 * x) - Float64(2.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 = (-2.0 * x) - (2.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[(-2.0 * x), $MachinePrecision] - N[(2.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} + \frac{-1}{x}\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot x - \frac{2}{x}\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 65.0%
remove-double-neg65.0%
sub-neg65.0%
sub-neg65.0%
distribute-neg-frac65.0%
metadata-eval65.0%
metadata-eval65.0%
metadata-eval65.0%
associate-/r*65.0%
metadata-eval65.0%
neg-mul-165.0%
associate--l+65.0%
+-commutative65.0%
distribute-neg-frac65.0%
metadata-eval65.0%
metadata-eval65.0%
metadata-eval65.0%
associate-/r*65.0%
metadata-eval65.0%
neg-mul-165.0%
sub0-neg65.0%
associate-+l-65.0%
neg-sub065.0%
Simplified65.0%
Taylor expanded in x around inf 64.4%
Taylor expanded in x around inf 64.3%
if -1 < x < 1Initial program 100.0%
remove-double-neg100.0%
sub-neg100.0%
sub-neg100.0%
distribute-neg-frac100.0%
metadata-eval100.0%
metadata-eval100.0%
metadata-eval100.0%
associate-/r*100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate--l+100.0%
+-commutative100.0%
distribute-neg-frac100.0%
metadata-eval100.0%
metadata-eval100.0%
metadata-eval100.0%
associate-/r*100.0%
metadata-eval100.0%
neg-mul-1100.0%
sub0-neg100.0%
associate-+l-100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in x around 0 99.3%
associate-*r/99.3%
metadata-eval99.3%
Simplified99.3%
Final simplification80.0%
(FPCore (x) :precision binary64 (if (<= x -0.65) (+ (/ -1.0 x) (/ 1.0 (+ x 1.0))) (if (<= x 1.0) (- (* -2.0 x) (/ 2.0 x)) (+ (/ 1.0 x) (/ -1.0 x)))))
double code(double x) {
double tmp;
if (x <= -0.65) {
tmp = (-1.0 / x) + (1.0 / (x + 1.0));
} else if (x <= 1.0) {
tmp = (-2.0 * x) - (2.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 <= (-0.65d0)) then
tmp = ((-1.0d0) / x) + (1.0d0 / (x + 1.0d0))
else if (x <= 1.0d0) then
tmp = ((-2.0d0) * x) - (2.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 <= -0.65) {
tmp = (-1.0 / x) + (1.0 / (x + 1.0));
} else if (x <= 1.0) {
tmp = (-2.0 * x) - (2.0 / x);
} else {
tmp = (1.0 / x) + (-1.0 / x);
}
return tmp;
}
def code(x): tmp = 0 if x <= -0.65: tmp = (-1.0 / x) + (1.0 / (x + 1.0)) elif x <= 1.0: tmp = (-2.0 * x) - (2.0 / x) else: tmp = (1.0 / x) + (-1.0 / x) return tmp
function code(x) tmp = 0.0 if (x <= -0.65) tmp = Float64(Float64(-1.0 / x) + Float64(1.0 / Float64(x + 1.0))); elseif (x <= 1.0) tmp = Float64(Float64(-2.0 * x) - Float64(2.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 <= -0.65) tmp = (-1.0 / x) + (1.0 / (x + 1.0)); elseif (x <= 1.0) tmp = (-2.0 * x) - (2.0 / x); else tmp = (1.0 / x) + (-1.0 / x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -0.65], N[(N[(-1.0 / x), $MachinePrecision] + N[(1.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.0], N[(N[(-2.0 * x), $MachinePrecision] - N[(2.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 -0.65:\\
\;\;\;\;\frac{-1}{x} + \frac{1}{x + 1}\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;-2 \cdot x - \frac{2}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x} + \frac{-1}{x}\\
\end{array}
\end{array}
if x < -0.650000000000000022Initial program 67.9%
remove-double-neg67.9%
sub-neg67.9%
sub-neg67.9%
distribute-neg-frac67.9%
metadata-eval67.9%
metadata-eval67.9%
metadata-eval67.9%
associate-/r*67.9%
metadata-eval67.9%
neg-mul-167.9%
associate--l+67.9%
+-commutative67.9%
distribute-neg-frac67.9%
metadata-eval67.9%
metadata-eval67.9%
metadata-eval67.9%
associate-/r*67.9%
metadata-eval67.9%
neg-mul-167.9%
sub0-neg67.9%
associate-+l-67.9%
neg-sub067.9%
Simplified67.9%
Taylor expanded in x around inf 66.8%
if -0.650000000000000022 < x < 1Initial program 100.0%
remove-double-neg100.0%
sub-neg100.0%
sub-neg100.0%
distribute-neg-frac100.0%
metadata-eval100.0%
metadata-eval100.0%
metadata-eval100.0%
associate-/r*100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate--l+100.0%
+-commutative100.0%
distribute-neg-frac100.0%
metadata-eval100.0%
metadata-eval100.0%
metadata-eval100.0%
associate-/r*100.0%
metadata-eval100.0%
neg-mul-1100.0%
sub0-neg100.0%
associate-+l-100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in x around 0 99.3%
associate-*r/99.3%
metadata-eval99.3%
Simplified99.3%
if 1 < x Initial program 61.8%
remove-double-neg61.8%
sub-neg61.8%
sub-neg61.8%
distribute-neg-frac61.8%
metadata-eval61.8%
metadata-eval61.8%
metadata-eval61.8%
associate-/r*61.8%
metadata-eval61.8%
neg-mul-161.8%
associate--l+61.8%
+-commutative61.8%
distribute-neg-frac61.8%
metadata-eval61.8%
metadata-eval61.8%
metadata-eval61.8%
associate-/r*61.8%
metadata-eval61.8%
neg-mul-161.8%
sub0-neg61.8%
associate-+l-61.8%
neg-sub061.8%
Simplified61.8%
Taylor expanded in x around inf 61.8%
Taylor expanded in x around inf 61.8%
Final simplification80.1%
(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(Float64(-2.0 / x) / Float64(Float64(1.0 - x) * Float64(x + 1.0))) end
function tmp = code(x) tmp = (-2.0 / x) / ((1.0 - x) * (x + 1.0)); end
code[x_] := N[(N[(-2.0 / x), $MachinePrecision] / N[(N[(1.0 - x), $MachinePrecision] * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{-2}{x}}{\left(1 - x\right) \cdot \left(x + 1\right)}
\end{array}
Initial program 80.7%
remove-double-neg80.7%
sub-neg80.7%
sub-neg80.7%
distribute-neg-frac80.7%
metadata-eval80.7%
metadata-eval80.7%
metadata-eval80.7%
associate-/r*80.7%
metadata-eval80.7%
neg-mul-180.7%
associate--l+80.7%
+-commutative80.7%
distribute-neg-frac80.7%
metadata-eval80.7%
metadata-eval80.7%
metadata-eval80.7%
associate-/r*80.7%
metadata-eval80.7%
neg-mul-180.7%
sub0-neg80.7%
associate-+l-80.7%
neg-sub080.7%
Simplified80.7%
frac-sub55.5%
div-inv54.0%
*-rgt-identity54.0%
Applied egg-rr54.0%
associate-/r*57.4%
Simplified57.4%
associate-*r/80.7%
frac-add79.4%
*-un-lft-identity79.4%
div-inv80.7%
Applied egg-rr80.7%
Taylor expanded in x around 0 99.9%
Final simplification99.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 80.7%
remove-double-neg80.7%
sub-neg80.7%
sub-neg80.7%
distribute-neg-frac80.7%
metadata-eval80.7%
metadata-eval80.7%
metadata-eval80.7%
associate-/r*80.7%
metadata-eval80.7%
neg-mul-180.7%
associate--l+80.7%
+-commutative80.7%
distribute-neg-frac80.7%
metadata-eval80.7%
metadata-eval80.7%
metadata-eval80.7%
associate-/r*80.7%
metadata-eval80.7%
neg-mul-180.7%
sub0-neg80.7%
associate-+l-80.7%
neg-sub080.7%
Simplified80.7%
Taylor expanded in x around 0 47.1%
Final simplification47.1%
(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 80.7%
remove-double-neg80.7%
sub-neg80.7%
sub-neg80.7%
distribute-neg-frac80.7%
metadata-eval80.7%
metadata-eval80.7%
metadata-eval80.7%
associate-/r*80.7%
metadata-eval80.7%
neg-mul-180.7%
associate--l+80.7%
+-commutative80.7%
distribute-neg-frac80.7%
metadata-eval80.7%
metadata-eval80.7%
metadata-eval80.7%
associate-/r*80.7%
metadata-eval80.7%
neg-mul-180.7%
sub0-neg80.7%
associate-+l-80.7%
neg-sub080.7%
Simplified80.7%
Taylor expanded in x around 0 46.3%
distribute-neg-in46.3%
metadata-eval46.3%
unsub-neg46.3%
associate-*r/46.3%
metadata-eval46.3%
Simplified46.3%
Taylor expanded in x around inf 3.3%
Final simplification3.3%
(FPCore (x) :precision binary64 2.0)
double code(double x) {
return 2.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0
end function
public static double code(double x) {
return 2.0;
}
def code(x): return 2.0
function code(x) return 2.0 end
function tmp = code(x) tmp = 2.0; end
code[x_] := 2.0
\begin{array}{l}
\\
2
\end{array}
Initial program 80.7%
remove-double-neg80.7%
sub-neg80.7%
sub-neg80.7%
distribute-neg-frac80.7%
metadata-eval80.7%
metadata-eval80.7%
metadata-eval80.7%
associate-/r*80.7%
metadata-eval80.7%
neg-mul-180.7%
associate--l+80.7%
+-commutative80.7%
distribute-neg-frac80.7%
metadata-eval80.7%
metadata-eval80.7%
metadata-eval80.7%
associate-/r*80.7%
metadata-eval80.7%
neg-mul-180.7%
sub0-neg80.7%
associate-+l-80.7%
neg-sub080.7%
Simplified80.7%
frac-sub55.5%
*-rgt-identity55.5%
Applied egg-rr55.5%
Taylor expanded in x around inf 11.8%
Taylor expanded in x around 0 3.4%
Final simplification3.4%
(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 2023320
(FPCore (x)
:name "3frac (problem 3.3.3)"
:precision binary64
:herbie-target
(/ 2.0 (* x (- (* x x) 1.0)))
(+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))