
(FPCore (x) :precision binary64 (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))
double code(double x) {
return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x / (x + 1.0d0)) - ((x + 1.0d0) / (x - 1.0d0))
end function
public static double code(double x) {
return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0));
}
def code(x): return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))
function code(x) return Float64(Float64(x / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / Float64(x - 1.0))) end
function tmp = code(x) tmp = (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0)); end
code[x_] := N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{x + 1} - \frac{x + 1}{x - 1}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))
double code(double x) {
return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x / (x + 1.0d0)) - ((x + 1.0d0) / (x - 1.0d0))
end function
public static double code(double x) {
return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0));
}
def code(x): return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))
function code(x) return Float64(Float64(x / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / Float64(x - 1.0))) end
function tmp = code(x) tmp = (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0)); end
code[x_] := N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{x + 1} - \frac{x + 1}{x - 1}
\end{array}
(FPCore (x) :precision binary64 (/ (+ (/ 1.0 x) 3.0) (- (/ 1.0 x) x)))
double code(double x) {
return ((1.0 / x) + 3.0) / ((1.0 / x) - x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((1.0d0 / x) + 3.0d0) / ((1.0d0 / x) - x)
end function
public static double code(double x) {
return ((1.0 / x) + 3.0) / ((1.0 / x) - x);
}
def code(x): return ((1.0 / x) + 3.0) / ((1.0 / x) - x)
function code(x) return Float64(Float64(Float64(1.0 / x) + 3.0) / Float64(Float64(1.0 / x) - x)) end
function tmp = code(x) tmp = ((1.0 / x) + 3.0) / ((1.0 / x) - x); end
code[x_] := N[(N[(N[(1.0 / x), $MachinePrecision] + 3.0), $MachinePrecision] / N[(N[(1.0 / x), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{x} + 3}{\frac{1}{x} - x}
\end{array}
Initial program 54.6%
remove-double-neg54.6%
distribute-neg-frac54.6%
distribute-neg-in54.6%
sub-neg54.6%
distribute-frac-neg254.6%
sub-neg54.6%
+-commutative54.6%
unsub-neg54.6%
metadata-eval54.6%
neg-sub054.6%
associate-+l-54.6%
neg-sub054.6%
+-commutative54.6%
unsub-neg54.6%
Simplified54.6%
clear-num54.5%
frac-sub54.9%
*-un-lft-identity54.9%
Applied egg-rr54.9%
Taylor expanded in x around 0 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
neg-mul-1100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (/ -3.0 x) (+ 1.0 (* x (+ x 3.0)))))
double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = -3.0 / x;
} else {
tmp = 1.0 + (x * (x + 3.0));
}
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 = (-3.0d0) / x
else
tmp = 1.0d0 + (x * (x + 3.0d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = -3.0 / x;
} else {
tmp = 1.0 + (x * (x + 3.0));
}
return tmp;
}
def code(x): tmp = 0 if (x <= -1.0) or not (x <= 1.0): tmp = -3.0 / x else: tmp = 1.0 + (x * (x + 3.0)) return tmp
function code(x) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.0)) tmp = Float64(-3.0 / x); else tmp = Float64(1.0 + Float64(x * Float64(x + 3.0))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -1.0) || ~((x <= 1.0))) tmp = -3.0 / x; else tmp = 1.0 + (x * (x + 3.0)); end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(-3.0 / x), $MachinePrecision], N[(1.0 + N[(x * N[(x + 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\frac{-3}{x}\\
\mathbf{else}:\\
\;\;\;\;1 + x \cdot \left(x + 3\right)\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 9.9%
remove-double-neg9.9%
distribute-neg-frac9.9%
distribute-neg-in9.9%
sub-neg9.9%
distribute-frac-neg29.9%
sub-neg9.9%
+-commutative9.9%
unsub-neg9.9%
metadata-eval9.9%
neg-sub09.9%
associate-+l-9.9%
neg-sub09.9%
+-commutative9.9%
unsub-neg9.9%
Simplified9.9%
Taylor expanded in x around inf 97.3%
if -1 < x < 1Initial program 100.0%
remove-double-neg100.0%
distribute-neg-frac100.0%
distribute-neg-in100.0%
sub-neg100.0%
distribute-frac-neg2100.0%
sub-neg100.0%
+-commutative100.0%
unsub-neg100.0%
metadata-eval100.0%
neg-sub0100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
unpow2100.0%
distribute-rgt-out100.0%
Simplified100.0%
Final simplification98.6%
(FPCore (x) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (/ (+ -3.0 (/ -1.0 x)) x) (+ 1.0 (* x (+ x 3.0)))))
double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = (-3.0 + (-1.0 / x)) / x;
} else {
tmp = 1.0 + (x * (x + 3.0));
}
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 = ((-3.0d0) + ((-1.0d0) / x)) / x
else
tmp = 1.0d0 + (x * (x + 3.0d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = (-3.0 + (-1.0 / x)) / x;
} else {
tmp = 1.0 + (x * (x + 3.0));
}
return tmp;
}
def code(x): tmp = 0 if (x <= -1.0) or not (x <= 1.0): tmp = (-3.0 + (-1.0 / x)) / x else: tmp = 1.0 + (x * (x + 3.0)) return tmp
function code(x) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.0)) tmp = Float64(Float64(-3.0 + Float64(-1.0 / x)) / x); else tmp = Float64(1.0 + Float64(x * Float64(x + 3.0))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -1.0) || ~((x <= 1.0))) tmp = (-3.0 + (-1.0 / x)) / x; else tmp = 1.0 + (x * (x + 3.0)); end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(N[(-3.0 + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], N[(1.0 + N[(x * N[(x + 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\frac{-3 + \frac{-1}{x}}{x}\\
\mathbf{else}:\\
\;\;\;\;1 + x \cdot \left(x + 3\right)\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 9.9%
remove-double-neg9.9%
distribute-neg-frac9.9%
distribute-neg-in9.9%
sub-neg9.9%
distribute-frac-neg29.9%
sub-neg9.9%
+-commutative9.9%
unsub-neg9.9%
metadata-eval9.9%
neg-sub09.9%
associate-+l-9.9%
neg-sub09.9%
+-commutative9.9%
unsub-neg9.9%
Simplified9.9%
clear-num9.8%
associate-/r/9.5%
fma-neg8.1%
distribute-neg-frac28.1%
flip--8.1%
metadata-eval8.1%
metadata-eval8.1%
+-commutative8.1%
distribute-neg-frac28.1%
+-commutative8.1%
distribute-neg-in8.1%
metadata-eval8.1%
sub-neg8.1%
flip-+8.1%
+-commutative8.1%
Applied egg-rr8.1%
Taylor expanded in x around inf 97.8%
distribute-neg-in97.8%
associate-*r/98.4%
metadata-eval98.4%
unsub-neg98.4%
distribute-neg-frac98.4%
metadata-eval98.4%
unpow-198.4%
exp-to-pow49.8%
*-commutative49.8%
exp-prod49.8%
*-commutative49.8%
associate-*r*49.8%
metadata-eval49.8%
*-commutative49.8%
exp-to-pow98.4%
Simplified98.4%
div-inv97.8%
metadata-eval97.8%
pow-prod-up97.8%
inv-pow97.8%
inv-pow97.8%
distribute-rgt-out--97.8%
Applied egg-rr97.8%
associate-*l/98.4%
*-un-lft-identity98.4%
sub-neg98.4%
distribute-neg-frac98.4%
metadata-eval98.4%
Applied egg-rr98.4%
if -1 < x < 1Initial program 100.0%
remove-double-neg100.0%
distribute-neg-frac100.0%
distribute-neg-in100.0%
sub-neg100.0%
distribute-frac-neg2100.0%
sub-neg100.0%
+-commutative100.0%
unsub-neg100.0%
metadata-eval100.0%
neg-sub0100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
unpow2100.0%
distribute-rgt-out100.0%
Simplified100.0%
Final simplification99.2%
(FPCore (x) :precision binary64 (if (<= x -1.0) (/ -3.0 x) (if (<= x 0.65) (+ 1.0 (* x (+ x 3.0))) (/ 3.0 (- (/ 1.0 x) x)))))
double code(double x) {
double tmp;
if (x <= -1.0) {
tmp = -3.0 / x;
} else if (x <= 0.65) {
tmp = 1.0 + (x * (x + 3.0));
} else {
tmp = 3.0 / ((1.0 / x) - x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-1.0d0)) then
tmp = (-3.0d0) / x
else if (x <= 0.65d0) then
tmp = 1.0d0 + (x * (x + 3.0d0))
else
tmp = 3.0d0 / ((1.0d0 / x) - x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -1.0) {
tmp = -3.0 / x;
} else if (x <= 0.65) {
tmp = 1.0 + (x * (x + 3.0));
} else {
tmp = 3.0 / ((1.0 / x) - x);
}
return tmp;
}
def code(x): tmp = 0 if x <= -1.0: tmp = -3.0 / x elif x <= 0.65: tmp = 1.0 + (x * (x + 3.0)) else: tmp = 3.0 / ((1.0 / x) - x) return tmp
function code(x) tmp = 0.0 if (x <= -1.0) tmp = Float64(-3.0 / x); elseif (x <= 0.65) tmp = Float64(1.0 + Float64(x * Float64(x + 3.0))); else tmp = Float64(3.0 / Float64(Float64(1.0 / x) - x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -1.0) tmp = -3.0 / x; elseif (x <= 0.65) tmp = 1.0 + (x * (x + 3.0)); else tmp = 3.0 / ((1.0 / x) - x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -1.0], N[(-3.0 / x), $MachinePrecision], If[LessEqual[x, 0.65], N[(1.0 + N[(x * N[(x + 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(3.0 / N[(N[(1.0 / x), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;\frac{-3}{x}\\
\mathbf{elif}\;x \leq 0.65:\\
\;\;\;\;1 + x \cdot \left(x + 3\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{3}{\frac{1}{x} - x}\\
\end{array}
\end{array}
if x < -1Initial program 8.4%
remove-double-neg8.4%
distribute-neg-frac8.4%
distribute-neg-in8.4%
sub-neg8.4%
distribute-frac-neg28.4%
sub-neg8.4%
+-commutative8.4%
unsub-neg8.4%
metadata-eval8.4%
neg-sub08.4%
associate-+l-8.4%
neg-sub08.4%
+-commutative8.4%
unsub-neg8.4%
Simplified8.4%
Taylor expanded in x around inf 98.6%
if -1 < x < 0.650000000000000022Initial program 100.0%
remove-double-neg100.0%
distribute-neg-frac100.0%
distribute-neg-in100.0%
sub-neg100.0%
distribute-frac-neg2100.0%
sub-neg100.0%
+-commutative100.0%
unsub-neg100.0%
metadata-eval100.0%
neg-sub0100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
unpow2100.0%
distribute-rgt-out100.0%
Simplified100.0%
if 0.650000000000000022 < x Initial program 11.3%
remove-double-neg11.3%
distribute-neg-frac11.3%
distribute-neg-in11.3%
sub-neg11.3%
distribute-frac-neg211.3%
sub-neg11.3%
+-commutative11.3%
unsub-neg11.3%
metadata-eval11.3%
neg-sub011.3%
associate-+l-11.3%
neg-sub011.3%
+-commutative11.3%
unsub-neg11.3%
Simplified11.3%
clear-num11.2%
frac-sub11.5%
*-un-lft-identity11.5%
Applied egg-rr11.5%
Taylor expanded in x around inf 96.0%
Taylor expanded in x around 0 96.0%
neg-mul-1100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified96.0%
Final simplification98.6%
(FPCore (x) :precision binary64 (if (<= x -1.0) (+ (/ -3.0 x) (* (/ 1.0 x) (/ -1.0 x))) (if (<= x 1.0) (+ 1.0 (* x (+ x 3.0))) (/ (+ -3.0 (/ -1.0 x)) x))))
double code(double x) {
double tmp;
if (x <= -1.0) {
tmp = (-3.0 / x) + ((1.0 / x) * (-1.0 / x));
} else if (x <= 1.0) {
tmp = 1.0 + (x * (x + 3.0));
} else {
tmp = (-3.0 + (-1.0 / x)) / x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-1.0d0)) then
tmp = ((-3.0d0) / x) + ((1.0d0 / x) * ((-1.0d0) / x))
else if (x <= 1.0d0) then
tmp = 1.0d0 + (x * (x + 3.0d0))
else
tmp = ((-3.0d0) + ((-1.0d0) / x)) / x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -1.0) {
tmp = (-3.0 / x) + ((1.0 / x) * (-1.0 / x));
} else if (x <= 1.0) {
tmp = 1.0 + (x * (x + 3.0));
} else {
tmp = (-3.0 + (-1.0 / x)) / x;
}
return tmp;
}
def code(x): tmp = 0 if x <= -1.0: tmp = (-3.0 / x) + ((1.0 / x) * (-1.0 / x)) elif x <= 1.0: tmp = 1.0 + (x * (x + 3.0)) else: tmp = (-3.0 + (-1.0 / x)) / x return tmp
function code(x) tmp = 0.0 if (x <= -1.0) tmp = Float64(Float64(-3.0 / x) + Float64(Float64(1.0 / x) * Float64(-1.0 / x))); elseif (x <= 1.0) tmp = Float64(1.0 + Float64(x * Float64(x + 3.0))); else tmp = Float64(Float64(-3.0 + Float64(-1.0 / x)) / x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -1.0) tmp = (-3.0 / x) + ((1.0 / x) * (-1.0 / x)); elseif (x <= 1.0) tmp = 1.0 + (x * (x + 3.0)); else tmp = (-3.0 + (-1.0 / x)) / x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -1.0], N[(N[(-3.0 / x), $MachinePrecision] + N[(N[(1.0 / x), $MachinePrecision] * N[(-1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.0], N[(1.0 + N[(x * N[(x + 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(-3.0 + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;\frac{-3}{x} + \frac{1}{x} \cdot \frac{-1}{x}\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;1 + x \cdot \left(x + 3\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{-3 + \frac{-1}{x}}{x}\\
\end{array}
\end{array}
if x < -1Initial program 8.4%
remove-double-neg8.4%
distribute-neg-frac8.4%
distribute-neg-in8.4%
sub-neg8.4%
distribute-frac-neg28.4%
sub-neg8.4%
+-commutative8.4%
unsub-neg8.4%
metadata-eval8.4%
neg-sub08.4%
associate-+l-8.4%
neg-sub08.4%
+-commutative8.4%
unsub-neg8.4%
Simplified8.4%
clear-num8.3%
associate-/r/7.6%
fma-neg6.1%
distribute-neg-frac26.1%
flip--6.5%
metadata-eval6.5%
metadata-eval6.5%
+-commutative6.5%
distribute-neg-frac26.5%
+-commutative6.5%
distribute-neg-in6.5%
metadata-eval6.5%
sub-neg6.5%
flip-+6.1%
+-commutative6.1%
Applied egg-rr6.1%
Taylor expanded in x around inf 98.8%
distribute-neg-in98.8%
associate-*r/99.4%
metadata-eval99.4%
unsub-neg99.4%
distribute-neg-frac99.4%
metadata-eval99.4%
unpow-199.4%
exp-to-pow0.0%
*-commutative0.0%
exp-prod0.0%
*-commutative0.0%
associate-*r*0.0%
metadata-eval0.0%
*-commutative0.0%
exp-to-pow99.4%
Simplified99.4%
div-inv98.8%
metadata-eval98.8%
pow-prod-up98.8%
inv-pow98.8%
inv-pow98.8%
distribute-rgt-out--98.7%
Applied egg-rr98.7%
sub-neg98.7%
distribute-lft-in98.8%
*-commutative98.8%
un-div-inv99.4%
distribute-neg-frac99.4%
metadata-eval99.4%
Applied egg-rr99.4%
if -1 < x < 1Initial program 100.0%
remove-double-neg100.0%
distribute-neg-frac100.0%
distribute-neg-in100.0%
sub-neg100.0%
distribute-frac-neg2100.0%
sub-neg100.0%
+-commutative100.0%
unsub-neg100.0%
metadata-eval100.0%
neg-sub0100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
unpow2100.0%
distribute-rgt-out100.0%
Simplified100.0%
if 1 < x Initial program 11.3%
remove-double-neg11.3%
distribute-neg-frac11.3%
distribute-neg-in11.3%
sub-neg11.3%
distribute-frac-neg211.3%
sub-neg11.3%
+-commutative11.3%
unsub-neg11.3%
metadata-eval11.3%
neg-sub011.3%
associate-+l-11.3%
neg-sub011.3%
+-commutative11.3%
unsub-neg11.3%
Simplified11.3%
clear-num11.2%
associate-/r/11.4%
fma-neg9.9%
distribute-neg-frac29.9%
flip--9.7%
metadata-eval9.7%
metadata-eval9.7%
+-commutative9.7%
distribute-neg-frac29.7%
+-commutative9.7%
distribute-neg-in9.7%
metadata-eval9.7%
sub-neg9.7%
flip-+9.9%
+-commutative9.9%
Applied egg-rr9.9%
Taylor expanded in x around inf 97.0%
distribute-neg-in97.0%
associate-*r/97.4%
metadata-eval97.4%
unsub-neg97.4%
distribute-neg-frac97.4%
metadata-eval97.4%
unpow-197.4%
exp-to-pow97.4%
*-commutative97.4%
exp-prod97.4%
*-commutative97.4%
associate-*r*97.4%
metadata-eval97.4%
*-commutative97.4%
exp-to-pow97.4%
Simplified97.4%
div-inv97.0%
metadata-eval97.0%
pow-prod-up97.0%
inv-pow97.0%
inv-pow97.0%
distribute-rgt-out--97.0%
Applied egg-rr97.0%
associate-*l/97.4%
*-un-lft-identity97.4%
sub-neg97.4%
distribute-neg-frac97.4%
metadata-eval97.4%
Applied egg-rr97.4%
Final simplification99.2%
(FPCore (x) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (/ -3.0 x) (+ 1.0 (* x 3.0))))
double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = -3.0 / x;
} else {
tmp = 1.0 + (x * 3.0);
}
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 = (-3.0d0) / x
else
tmp = 1.0d0 + (x * 3.0d0)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = -3.0 / x;
} else {
tmp = 1.0 + (x * 3.0);
}
return tmp;
}
def code(x): tmp = 0 if (x <= -1.0) or not (x <= 1.0): tmp = -3.0 / x else: tmp = 1.0 + (x * 3.0) return tmp
function code(x) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.0)) tmp = Float64(-3.0 / x); else tmp = Float64(1.0 + Float64(x * 3.0)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -1.0) || ~((x <= 1.0))) tmp = -3.0 / x; else tmp = 1.0 + (x * 3.0); end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(-3.0 / x), $MachinePrecision], N[(1.0 + N[(x * 3.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\frac{-3}{x}\\
\mathbf{else}:\\
\;\;\;\;1 + x \cdot 3\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 9.9%
remove-double-neg9.9%
distribute-neg-frac9.9%
distribute-neg-in9.9%
sub-neg9.9%
distribute-frac-neg29.9%
sub-neg9.9%
+-commutative9.9%
unsub-neg9.9%
metadata-eval9.9%
neg-sub09.9%
associate-+l-9.9%
neg-sub09.9%
+-commutative9.9%
unsub-neg9.9%
Simplified9.9%
Taylor expanded in x around inf 97.3%
if -1 < x < 1Initial program 100.0%
remove-double-neg100.0%
distribute-neg-frac100.0%
distribute-neg-in100.0%
sub-neg100.0%
distribute-frac-neg2100.0%
sub-neg100.0%
+-commutative100.0%
unsub-neg100.0%
metadata-eval100.0%
neg-sub0100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 99.9%
Final simplification98.6%
(FPCore (x) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (/ -3.0 x) 1.0))
double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = -3.0 / x;
} else {
tmp = 1.0;
}
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 = (-3.0d0) / x
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = -3.0 / x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x): tmp = 0 if (x <= -1.0) or not (x <= 1.0): tmp = -3.0 / x else: tmp = 1.0 return tmp
function code(x) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.0)) tmp = Float64(-3.0 / x); else tmp = 1.0; end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -1.0) || ~((x <= 1.0))) tmp = -3.0 / x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(-3.0 / x), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\frac{-3}{x}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 9.9%
remove-double-neg9.9%
distribute-neg-frac9.9%
distribute-neg-in9.9%
sub-neg9.9%
distribute-frac-neg29.9%
sub-neg9.9%
+-commutative9.9%
unsub-neg9.9%
metadata-eval9.9%
neg-sub09.9%
associate-+l-9.9%
neg-sub09.9%
+-commutative9.9%
unsub-neg9.9%
Simplified9.9%
Taylor expanded in x around inf 97.3%
if -1 < x < 1Initial program 100.0%
remove-double-neg100.0%
distribute-neg-frac100.0%
distribute-neg-in100.0%
sub-neg100.0%
distribute-frac-neg2100.0%
sub-neg100.0%
+-commutative100.0%
unsub-neg100.0%
metadata-eval100.0%
neg-sub0100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 99.1%
Final simplification98.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 54.6%
remove-double-neg54.6%
distribute-neg-frac54.6%
distribute-neg-in54.6%
sub-neg54.6%
distribute-frac-neg254.6%
sub-neg54.6%
+-commutative54.6%
unsub-neg54.6%
metadata-eval54.6%
neg-sub054.6%
associate-+l-54.6%
neg-sub054.6%
+-commutative54.6%
unsub-neg54.6%
Simplified54.6%
Taylor expanded in x around 0 50.9%
Final simplification50.9%
herbie shell --seed 2024052
(FPCore (x)
:name "Asymptote C"
:precision binary64
(- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))