
(FPCore (x) :precision binary64 :pre TRUE (- (/ 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)
use fmin_fmax_functions
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]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = (x / (x + (1))) - ((x + (1)) / (x - (1))) END code
\frac{x}{x + 1} - \frac{x + 1}{x - 1}
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 :pre TRUE (- (/ 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)
use fmin_fmax_functions
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]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = (x / (x + (1))) - ((x + (1)) / (x - (1))) END code
\frac{x}{x + 1} - \frac{x + 1}{x - 1}
(FPCore (x) :precision binary64 :pre TRUE (if (<= (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))) 0.0) (/ (- (* -1.0 (/ (+ 1.0 (* 3.0 (/ 1.0 x))) x)) 3.0) x) (/ 1.0 (/ (fma x x -1.0) (fma -3.0 x -1.0)))))
double code(double x) {
double tmp;
if (((x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))) <= 0.0) {
tmp = ((-1.0 * ((1.0 + (3.0 * (1.0 / x))) / x)) - 3.0) / x;
} else {
tmp = 1.0 / (fma(x, x, -1.0) / fma(-3.0, x, -1.0));
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(x / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / Float64(x - 1.0))) <= 0.0) tmp = Float64(Float64(Float64(-1.0 * Float64(Float64(1.0 + Float64(3.0 * Float64(1.0 / x))) / x)) - 3.0) / x); else tmp = Float64(1.0 / Float64(fma(x, x, -1.0) / fma(-3.0, x, -1.0))); end return tmp end
code[x_] := If[LessEqual[N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0], N[(N[(N[(-1.0 * N[(N[(1.0 + N[(3.0 * N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision] - 3.0), $MachinePrecision] / x), $MachinePrecision], N[(1.0 / N[(N[(x * x + -1.0), $MachinePrecision] / N[(-3.0 * x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = LET tmp = IF (((x / (x + (1))) - ((x + (1)) / (x - (1)))) <= (0)) THEN ((((-1) * (((1) + ((3) * ((1) / x))) / x)) - (3)) / x) ELSE ((1) / (((x * x) + (-1)) / (((-3) * x) + (-1)))) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 0:\\
\;\;\;\;\frac{-1 \cdot \frac{1 + 3 \cdot \frac{1}{x}}{x} - 3}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{\mathsf{fma}\left(x, x, -1\right)}{\mathsf{fma}\left(-3, x, -1\right)}}\\
\end{array}
if (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) < 0.0Initial program 53.7%
Taylor expanded in x around inf
Applied rewrites51.4%
if 0.0 < (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) Initial program 53.7%
Applied rewrites57.7%
Taylor expanded in x around 0
Applied rewrites76.7%
Applied rewrites76.7%
(FPCore (x) :precision binary64 :pre TRUE (if (<= (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))) 0.0) (/ (- (/ -1.0 x) 3.0) x) (/ 1.0 (/ (fma x x -1.0) (fma -3.0 x -1.0)))))
double code(double x) {
double tmp;
if (((x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))) <= 0.0) {
tmp = ((-1.0 / x) - 3.0) / x;
} else {
tmp = 1.0 / (fma(x, x, -1.0) / fma(-3.0, x, -1.0));
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(x / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / Float64(x - 1.0))) <= 0.0) tmp = Float64(Float64(Float64(-1.0 / x) - 3.0) / x); else tmp = Float64(1.0 / Float64(fma(x, x, -1.0) / fma(-3.0, x, -1.0))); end return tmp end
code[x_] := If[LessEqual[N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0], N[(N[(N[(-1.0 / x), $MachinePrecision] - 3.0), $MachinePrecision] / x), $MachinePrecision], N[(1.0 / N[(N[(x * x + -1.0), $MachinePrecision] / N[(-3.0 * x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = LET tmp = IF (((x / (x + (1))) - ((x + (1)) / (x - (1)))) <= (0)) THEN ((((-1) / x) - (3)) / x) ELSE ((1) / (((x * x) + (-1)) / (((-3) * x) + (-1)))) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 0:\\
\;\;\;\;\frac{\frac{-1}{x} - 3}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{\mathsf{fma}\left(x, x, -1\right)}{\mathsf{fma}\left(-3, x, -1\right)}}\\
\end{array}
if (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) < 0.0Initial program 53.7%
Taylor expanded in x around inf
Applied rewrites50.4%
Applied rewrites50.4%
if 0.0 < (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) Initial program 53.7%
Applied rewrites57.7%
Taylor expanded in x around 0
Applied rewrites76.7%
Applied rewrites76.7%
(FPCore (x) :precision binary64 :pre TRUE (if (<= (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))) 0.0) (/ (- (/ -1.0 x) 3.0) x) (/ (fma -3.0 x -1.0) (fma x x -1.0))))
double code(double x) {
double tmp;
if (((x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))) <= 0.0) {
tmp = ((-1.0 / x) - 3.0) / x;
} else {
tmp = fma(-3.0, x, -1.0) / fma(x, x, -1.0);
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(x / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / Float64(x - 1.0))) <= 0.0) tmp = Float64(Float64(Float64(-1.0 / x) - 3.0) / x); else tmp = Float64(fma(-3.0, x, -1.0) / fma(x, x, -1.0)); end return tmp end
code[x_] := If[LessEqual[N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0], N[(N[(N[(-1.0 / x), $MachinePrecision] - 3.0), $MachinePrecision] / x), $MachinePrecision], N[(N[(-3.0 * x + -1.0), $MachinePrecision] / N[(x * x + -1.0), $MachinePrecision]), $MachinePrecision]]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = LET tmp = IF (((x / (x + (1))) - ((x + (1)) / (x - (1)))) <= (0)) THEN ((((-1) / x) - (3)) / x) ELSE ((((-3) * x) + (-1)) / ((x * x) + (-1))) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 0:\\
\;\;\;\;\frac{\frac{-1}{x} - 3}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-3, x, -1\right)}{\mathsf{fma}\left(x, x, -1\right)}\\
\end{array}
if (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) < 0.0Initial program 53.7%
Taylor expanded in x around inf
Applied rewrites50.4%
Applied rewrites50.4%
if 0.0 < (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) Initial program 53.7%
Applied rewrites57.8%
Taylor expanded in x around 0
Applied rewrites76.8%
Applied rewrites76.8%
(FPCore (x) :precision binary64 :pre TRUE (if (<= (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))) 0.5) (+ (/ -3.0 x) (/ -1.0 (* x x))) (* (fma x x 1.0) (fma x 3.0 1.0))))
double code(double x) {
double tmp;
if (((x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))) <= 0.5) {
tmp = (-3.0 / x) + (-1.0 / (x * x));
} else {
tmp = fma(x, x, 1.0) * fma(x, 3.0, 1.0);
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(x / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / Float64(x - 1.0))) <= 0.5) tmp = Float64(Float64(-3.0 / x) + Float64(-1.0 / Float64(x * x))); else tmp = Float64(fma(x, x, 1.0) * fma(x, 3.0, 1.0)); end return tmp end
code[x_] := If[LessEqual[N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.5], N[(N[(-3.0 / x), $MachinePrecision] + N[(-1.0 / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * x + 1.0), $MachinePrecision] * N[(x * 3.0 + 1.0), $MachinePrecision]), $MachinePrecision]]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = LET tmp = IF (((x / (x + (1))) - ((x + (1)) / (x - (1)))) <= (5e-1)) THEN (((-3) / x) + ((-1) / (x * x))) ELSE (((x * x) + (1)) * ((x * (3)) + (1))) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 0.5:\\
\;\;\;\;\frac{-3}{x} + \frac{-1}{x \cdot x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, x, 1\right) \cdot \mathsf{fma}\left(x, 3, 1\right)\\
\end{array}
if (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) < 0.5Initial program 53.7%
Taylor expanded in x around inf
Applied rewrites50.4%
Applied rewrites50.4%
if 0.5 < (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) Initial program 53.7%
Taylor expanded in x around 0
Applied rewrites49.8%
Applied rewrites49.8%
(FPCore (x) :precision binary64 :pre TRUE (if (<= (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))) 0.5) (/ (- (/ -1.0 x) 3.0) x) (* (fma x x 1.0) (fma x 3.0 1.0))))
double code(double x) {
double tmp;
if (((x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))) <= 0.5) {
tmp = ((-1.0 / x) - 3.0) / x;
} else {
tmp = fma(x, x, 1.0) * fma(x, 3.0, 1.0);
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(x / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / Float64(x - 1.0))) <= 0.5) tmp = Float64(Float64(Float64(-1.0 / x) - 3.0) / x); else tmp = Float64(fma(x, x, 1.0) * fma(x, 3.0, 1.0)); end return tmp end
code[x_] := If[LessEqual[N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.5], N[(N[(N[(-1.0 / x), $MachinePrecision] - 3.0), $MachinePrecision] / x), $MachinePrecision], N[(N[(x * x + 1.0), $MachinePrecision] * N[(x * 3.0 + 1.0), $MachinePrecision]), $MachinePrecision]]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = LET tmp = IF (((x / (x + (1))) - ((x + (1)) / (x - (1)))) <= (5e-1)) THEN ((((-1) / x) - (3)) / x) ELSE (((x * x) + (1)) * ((x * (3)) + (1))) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 0.5:\\
\;\;\;\;\frac{\frac{-1}{x} - 3}{x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, x, 1\right) \cdot \mathsf{fma}\left(x, 3, 1\right)\\
\end{array}
if (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) < 0.5Initial program 53.7%
Taylor expanded in x around inf
Applied rewrites50.4%
Applied rewrites50.4%
if 0.5 < (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) Initial program 53.7%
Taylor expanded in x around 0
Applied rewrites49.8%
Applied rewrites49.8%
(FPCore (x) :precision binary64 :pre TRUE (if (<= (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))) 0.5) (/ (- (/ -1.0 x) 3.0) x) (fma x (- x -3.0) 1.0)))
double code(double x) {
double tmp;
if (((x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))) <= 0.5) {
tmp = ((-1.0 / x) - 3.0) / x;
} else {
tmp = fma(x, (x - -3.0), 1.0);
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(x / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / Float64(x - 1.0))) <= 0.5) tmp = Float64(Float64(Float64(-1.0 / x) - 3.0) / x); else tmp = fma(x, Float64(x - -3.0), 1.0); end return tmp end
code[x_] := If[LessEqual[N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.5], N[(N[(N[(-1.0 / x), $MachinePrecision] - 3.0), $MachinePrecision] / x), $MachinePrecision], N[(x * N[(x - -3.0), $MachinePrecision] + 1.0), $MachinePrecision]]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = LET tmp = IF (((x / (x + (1))) - ((x + (1)) / (x - (1)))) <= (5e-1)) THEN ((((-1) / x) - (3)) / x) ELSE ((x * (x - (-3))) + (1)) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 0.5:\\
\;\;\;\;\frac{\frac{-1}{x} - 3}{x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, x - -3, 1\right)\\
\end{array}
if (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) < 0.5Initial program 53.7%
Taylor expanded in x around inf
Applied rewrites50.4%
Applied rewrites50.4%
if 0.5 < (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) Initial program 53.7%
Taylor expanded in x around 0
Applied rewrites50.2%
Applied rewrites50.2%
(FPCore (x) :precision binary64 :pre TRUE (if (<= (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))) 0.5) (/ -3.0 x) (fma x (- x -3.0) 1.0)))
double code(double x) {
double tmp;
if (((x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))) <= 0.5) {
tmp = -3.0 / x;
} else {
tmp = fma(x, (x - -3.0), 1.0);
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(x / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / Float64(x - 1.0))) <= 0.5) tmp = Float64(-3.0 / x); else tmp = fma(x, Float64(x - -3.0), 1.0); end return tmp end
code[x_] := If[LessEqual[N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.5], N[(-3.0 / x), $MachinePrecision], N[(x * N[(x - -3.0), $MachinePrecision] + 1.0), $MachinePrecision]]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = LET tmp = IF (((x / (x + (1))) - ((x + (1)) / (x - (1)))) <= (5e-1)) THEN ((-3) / x) ELSE ((x * (x - (-3))) + (1)) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 0.5:\\
\;\;\;\;\frac{-3}{x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, x - -3, 1\right)\\
\end{array}
if (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) < 0.5Initial program 53.7%
Taylor expanded in x around inf
Applied rewrites51.1%
if 0.5 < (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) Initial program 53.7%
Taylor expanded in x around 0
Applied rewrites50.2%
Applied rewrites50.2%
(FPCore (x) :precision binary64 :pre TRUE (if (<= (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))) 0.5) (/ -3.0 x) (fma 3.0 x 1.0)))
double code(double x) {
double tmp;
if (((x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))) <= 0.5) {
tmp = -3.0 / x;
} else {
tmp = fma(3.0, x, 1.0);
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(x / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / Float64(x - 1.0))) <= 0.5) tmp = Float64(-3.0 / x); else tmp = fma(3.0, x, 1.0); end return tmp end
code[x_] := If[LessEqual[N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.5], N[(-3.0 / x), $MachinePrecision], N[(3.0 * x + 1.0), $MachinePrecision]]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = LET tmp = IF (((x / (x + (1))) - ((x + (1)) / (x - (1)))) <= (5e-1)) THEN ((-3) / x) ELSE (((3) * x) + (1)) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 0.5:\\
\;\;\;\;\frac{-3}{x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(3, x, 1\right)\\
\end{array}
if (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) < 0.5Initial program 53.7%
Taylor expanded in x around inf
Applied rewrites51.1%
if 0.5 < (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) Initial program 53.7%
Taylor expanded in x around 0
Applied rewrites49.7%
Applied rewrites49.7%
(FPCore (x) :precision binary64 :pre TRUE (if (<= (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))) 0.5) (/ -3.0 x) 1.0))
double code(double x) {
double tmp;
if (((x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))) <= 0.5) {
tmp = -3.0 / x;
} else {
tmp = 1.0;
}
return tmp;
}
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8) :: tmp
if (((x / (x + 1.0d0)) - ((x + 1.0d0) / (x - 1.0d0))) <= 0.5d0) 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 / (x + 1.0)) - ((x + 1.0) / (x - 1.0))) <= 0.5) {
tmp = -3.0 / x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x): tmp = 0 if ((x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))) <= 0.5: tmp = -3.0 / x else: tmp = 1.0 return tmp
function code(x) tmp = 0.0 if (Float64(Float64(x / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / Float64(x - 1.0))) <= 0.5) tmp = Float64(-3.0 / x); else tmp = 1.0; end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (((x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))) <= 0.5) tmp = -3.0 / x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.5], N[(-3.0 / x), $MachinePrecision], 1.0]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = LET tmp = IF (((x / (x + (1))) - ((x + (1)) / (x - (1)))) <= (5e-1)) THEN ((-3) / x) ELSE (1) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 0.5:\\
\;\;\;\;\frac{-3}{x}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
if (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) < 0.5Initial program 53.7%
Taylor expanded in x around inf
Applied rewrites51.1%
if 0.5 < (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) Initial program 53.7%
Taylor expanded in x around inf
Applied rewrites50.4%
Applied rewrites50.4%
Applied rewrites27.2%
Taylor expanded in x around 0
Applied rewrites50.2%
(FPCore (x) :precision binary64 :pre TRUE 1.0)
double code(double x) {
return 1.0;
}
real(8) function code(x)
use fmin_fmax_functions
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
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = 1 END code
1
Initial program 53.7%
Taylor expanded in x around inf
Applied rewrites50.4%
Applied rewrites50.4%
Applied rewrites27.2%
Taylor expanded in x around 0
Applied rewrites50.2%
herbie shell --seed 2026074 +o generate:egglog
(FPCore (x)
:name "Asymptote C"
:precision binary64
(- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))