
(FPCore (x) :precision binary64 (- (/ 2.0 (+ 1.0 (exp (* -2.0 x)))) 1.0))
double code(double x) {
return (2.0 / (1.0 + exp((-2.0 * x)))) - 1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (2.0d0 / (1.0d0 + exp(((-2.0d0) * x)))) - 1.0d0
end function
public static double code(double x) {
return (2.0 / (1.0 + Math.exp((-2.0 * x)))) - 1.0;
}
def code(x): return (2.0 / (1.0 + math.exp((-2.0 * x)))) - 1.0
function code(x) return Float64(Float64(2.0 / Float64(1.0 + exp(Float64(-2.0 * x)))) - 1.0) end
function tmp = code(x) tmp = (2.0 / (1.0 + exp((-2.0 * x)))) - 1.0; end
code[x_] := N[(N[(2.0 / N[(1.0 + N[Exp[N[(-2.0 * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{1 + e^{-2 \cdot x}} - 1
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (- (/ 2.0 (+ 1.0 (exp (* -2.0 x)))) 1.0))
double code(double x) {
return (2.0 / (1.0 + exp((-2.0 * x)))) - 1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (2.0d0 / (1.0d0 + exp(((-2.0d0) * x)))) - 1.0d0
end function
public static double code(double x) {
return (2.0 / (1.0 + Math.exp((-2.0 * x)))) - 1.0;
}
def code(x): return (2.0 / (1.0 + math.exp((-2.0 * x)))) - 1.0
function code(x) return Float64(Float64(2.0 / Float64(1.0 + exp(Float64(-2.0 * x)))) - 1.0) end
function tmp = code(x) tmp = (2.0 / (1.0 + exp((-2.0 * x)))) - 1.0; end
code[x_] := N[(N[(2.0 / N[(1.0 + N[Exp[N[(-2.0 * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{1 + e^{-2 \cdot x}} - 1
\end{array}
(FPCore (x)
:precision binary64
(if (<= x -0.0082)
(- (/ 2.0 (+ 1.0 (exp (* -2.0 x)))) 1.0)
(if (<= x 0.0072)
(*
(fma (- (* 0.13333333333333333 (* x x)) 0.3333333333333333) (* x x) 1.0)
x)
(- (/ (* (expm1 (* -2.0 x)) 2.0) (expm1 (* -4.0 x))) 1.0))))
double code(double x) {
double tmp;
if (x <= -0.0082) {
tmp = (2.0 / (1.0 + exp((-2.0 * x)))) - 1.0;
} else if (x <= 0.0072) {
tmp = fma(((0.13333333333333333 * (x * x)) - 0.3333333333333333), (x * x), 1.0) * x;
} else {
tmp = ((expm1((-2.0 * x)) * 2.0) / expm1((-4.0 * x))) - 1.0;
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= -0.0082) tmp = Float64(Float64(2.0 / Float64(1.0 + exp(Float64(-2.0 * x)))) - 1.0); elseif (x <= 0.0072) tmp = Float64(fma(Float64(Float64(0.13333333333333333 * Float64(x * x)) - 0.3333333333333333), Float64(x * x), 1.0) * x); else tmp = Float64(Float64(Float64(expm1(Float64(-2.0 * x)) * 2.0) / expm1(Float64(-4.0 * x))) - 1.0); end return tmp end
code[x_] := If[LessEqual[x, -0.0082], N[(N[(2.0 / N[(1.0 + N[Exp[N[(-2.0 * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision], If[LessEqual[x, 0.0072], N[(N[(N[(N[(0.13333333333333333 * N[(x * x), $MachinePrecision]), $MachinePrecision] - 0.3333333333333333), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision] * x), $MachinePrecision], N[(N[(N[(N[(Exp[N[(-2.0 * x), $MachinePrecision]] - 1), $MachinePrecision] * 2.0), $MachinePrecision] / N[(Exp[N[(-4.0 * x), $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0082:\\
\;\;\;\;\frac{2}{1 + e^{-2 \cdot x}} - 1\\
\mathbf{elif}\;x \leq 0.0072:\\
\;\;\;\;\mathsf{fma}\left(0.13333333333333333 \cdot \left(x \cdot x\right) - 0.3333333333333333, x \cdot x, 1\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{expm1}\left(-2 \cdot x\right) \cdot 2}{\mathsf{expm1}\left(-4 \cdot x\right)} - 1\\
\end{array}
\end{array}
if x < -0.00820000000000000069Initial program 99.9%
if -0.00820000000000000069 < x < 0.0071999999999999998Initial program 8.4%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
*-commutativeN/A
pow-plusN/A
lower-pow.f64N/A
metadata-evalN/A
lower--.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64100.0
Applied rewrites100.0%
Applied rewrites100.0%
Applied rewrites100.0%
if 0.0071999999999999998 < x Initial program 100.0%
lift-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
flip-+N/A
associate-/r/N/A
lower-*.f64N/A
Applied rewrites100.0%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64100.0
lift-*.f64N/A
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
(FPCore (x)
:precision binary64
(if (or (<= x -0.0082) (not (<= x 0.0072)))
(- (/ 2.0 (+ 1.0 (exp (* -2.0 x)))) 1.0)
(*
(fma (- (* 0.13333333333333333 (* x x)) 0.3333333333333333) (* x x) 1.0)
x)))
double code(double x) {
double tmp;
if ((x <= -0.0082) || !(x <= 0.0072)) {
tmp = (2.0 / (1.0 + exp((-2.0 * x)))) - 1.0;
} else {
tmp = fma(((0.13333333333333333 * (x * x)) - 0.3333333333333333), (x * x), 1.0) * x;
}
return tmp;
}
function code(x) tmp = 0.0 if ((x <= -0.0082) || !(x <= 0.0072)) tmp = Float64(Float64(2.0 / Float64(1.0 + exp(Float64(-2.0 * x)))) - 1.0); else tmp = Float64(fma(Float64(Float64(0.13333333333333333 * Float64(x * x)) - 0.3333333333333333), Float64(x * x), 1.0) * x); end return tmp end
code[x_] := If[Or[LessEqual[x, -0.0082], N[Not[LessEqual[x, 0.0072]], $MachinePrecision]], N[(N[(2.0 / N[(1.0 + N[Exp[N[(-2.0 * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision], N[(N[(N[(N[(0.13333333333333333 * N[(x * x), $MachinePrecision]), $MachinePrecision] - 0.3333333333333333), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0082 \lor \neg \left(x \leq 0.0072\right):\\
\;\;\;\;\frac{2}{1 + e^{-2 \cdot x}} - 1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.13333333333333333 \cdot \left(x \cdot x\right) - 0.3333333333333333, x \cdot x, 1\right) \cdot x\\
\end{array}
\end{array}
if x < -0.00820000000000000069 or 0.0071999999999999998 < x Initial program 99.9%
if -0.00820000000000000069 < x < 0.0071999999999999998Initial program 8.4%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
*-commutativeN/A
pow-plusN/A
lower-pow.f64N/A
metadata-evalN/A
lower--.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64100.0
Applied rewrites100.0%
Applied rewrites100.0%
Applied rewrites100.0%
Final simplification100.0%
(FPCore (x)
:precision binary64
(if (<= x -1.2)
(- (/ 2.0 (* (- (* (fma -1.3333333333333333 x 2.0) x) 2.0) x)) 1.0)
(*
(fma (- (* 0.13333333333333333 (* x x)) 0.3333333333333333) (* x x) 1.0)
x)))
double code(double x) {
double tmp;
if (x <= -1.2) {
tmp = (2.0 / (((fma(-1.3333333333333333, x, 2.0) * x) - 2.0) * x)) - 1.0;
} else {
tmp = fma(((0.13333333333333333 * (x * x)) - 0.3333333333333333), (x * x), 1.0) * x;
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= -1.2) tmp = Float64(Float64(2.0 / Float64(Float64(Float64(fma(-1.3333333333333333, x, 2.0) * x) - 2.0) * x)) - 1.0); else tmp = Float64(fma(Float64(Float64(0.13333333333333333 * Float64(x * x)) - 0.3333333333333333), Float64(x * x), 1.0) * x); end return tmp end
code[x_] := If[LessEqual[x, -1.2], N[(N[(2.0 / N[(N[(N[(N[(-1.3333333333333333 * x + 2.0), $MachinePrecision] * x), $MachinePrecision] - 2.0), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision], N[(N[(N[(N[(0.13333333333333333 * N[(x * x), $MachinePrecision]), $MachinePrecision] - 0.3333333333333333), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.2:\\
\;\;\;\;\frac{2}{\left(\mathsf{fma}\left(-1.3333333333333333, x, 2\right) \cdot x - 2\right) \cdot x} - 1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.13333333333333333 \cdot \left(x \cdot x\right) - 0.3333333333333333, x \cdot x, 1\right) \cdot x\\
\end{array}
\end{array}
if x < -1.19999999999999996Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f6499.3
Applied rewrites99.3%
Taylor expanded in x around -inf
Applied rewrites99.3%
if -1.19999999999999996 < x Initial program 40.3%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
*-commutativeN/A
pow-plusN/A
lower-pow.f64N/A
metadata-evalN/A
lower--.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6466.7
Applied rewrites66.7%
Applied rewrites66.7%
Applied rewrites66.7%
(FPCore (x)
:precision binary64
(if (<= x -1.5)
(- (/ 2.0 (* (* -1.3333333333333333 x) (* x (fabs x)))) 1.0)
(*
(fma (- (* 0.13333333333333333 (* x x)) 0.3333333333333333) (* x x) 1.0)
x)))
double code(double x) {
double tmp;
if (x <= -1.5) {
tmp = (2.0 / ((-1.3333333333333333 * x) * (x * fabs(x)))) - 1.0;
} else {
tmp = fma(((0.13333333333333333 * (x * x)) - 0.3333333333333333), (x * x), 1.0) * x;
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= -1.5) tmp = Float64(Float64(2.0 / Float64(Float64(-1.3333333333333333 * x) * Float64(x * abs(x)))) - 1.0); else tmp = Float64(fma(Float64(Float64(0.13333333333333333 * Float64(x * x)) - 0.3333333333333333), Float64(x * x), 1.0) * x); end return tmp end
code[x_] := If[LessEqual[x, -1.5], N[(N[(2.0 / N[(N[(-1.3333333333333333 * x), $MachinePrecision] * N[(x * N[Abs[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision], N[(N[(N[(N[(0.13333333333333333 * N[(x * x), $MachinePrecision]), $MachinePrecision] - 0.3333333333333333), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5:\\
\;\;\;\;\frac{2}{\left(-1.3333333333333333 \cdot x\right) \cdot \left(x \cdot \left|x\right|\right)} - 1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.13333333333333333 \cdot \left(x \cdot x\right) - 0.3333333333333333, x \cdot x, 1\right) \cdot x\\
\end{array}
\end{array}
if x < -1.5Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f6499.3
Applied rewrites99.3%
Taylor expanded in x around -inf
Applied rewrites99.3%
Taylor expanded in x around inf
Applied rewrites99.3%
Applied rewrites99.4%
if -1.5 < x Initial program 40.3%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
*-commutativeN/A
pow-plusN/A
lower-pow.f64N/A
metadata-evalN/A
lower--.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6466.7
Applied rewrites66.7%
Applied rewrites66.7%
Applied rewrites66.7%
Final simplification75.2%
(FPCore (x)
:precision binary64
(if (<= x -1.3)
(- (/ 2.0 (* (fma -1.3333333333333333 x 2.0) (* x x))) 1.0)
(*
(fma (- (* 0.13333333333333333 (* x x)) 0.3333333333333333) (* x x) 1.0)
x)))
double code(double x) {
double tmp;
if (x <= -1.3) {
tmp = (2.0 / (fma(-1.3333333333333333, x, 2.0) * (x * x))) - 1.0;
} else {
tmp = fma(((0.13333333333333333 * (x * x)) - 0.3333333333333333), (x * x), 1.0) * x;
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= -1.3) tmp = Float64(Float64(2.0 / Float64(fma(-1.3333333333333333, x, 2.0) * Float64(x * x))) - 1.0); else tmp = Float64(fma(Float64(Float64(0.13333333333333333 * Float64(x * x)) - 0.3333333333333333), Float64(x * x), 1.0) * x); end return tmp end
code[x_] := If[LessEqual[x, -1.3], N[(N[(2.0 / N[(N[(-1.3333333333333333 * x + 2.0), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision], N[(N[(N[(N[(0.13333333333333333 * N[(x * x), $MachinePrecision]), $MachinePrecision] - 0.3333333333333333), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.3:\\
\;\;\;\;\frac{2}{\mathsf{fma}\left(-1.3333333333333333, x, 2\right) \cdot \left(x \cdot x\right)} - 1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.13333333333333333 \cdot \left(x \cdot x\right) - 0.3333333333333333, x \cdot x, 1\right) \cdot x\\
\end{array}
\end{array}
if x < -1.30000000000000004Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f6499.3
Applied rewrites99.3%
Taylor expanded in x around -inf
Applied rewrites99.3%
if -1.30000000000000004 < x Initial program 40.3%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
*-commutativeN/A
pow-plusN/A
lower-pow.f64N/A
metadata-evalN/A
lower--.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6466.7
Applied rewrites66.7%
Applied rewrites66.7%
Applied rewrites66.7%
(FPCore (x)
:precision binary64
(if (<= x -1.55)
(- (/ 2.0 (* (* -1.3333333333333333 x) (* x x))) 1.0)
(*
(fma (- (* 0.13333333333333333 (* x x)) 0.3333333333333333) (* x x) 1.0)
x)))
double code(double x) {
double tmp;
if (x <= -1.55) {
tmp = (2.0 / ((-1.3333333333333333 * x) * (x * x))) - 1.0;
} else {
tmp = fma(((0.13333333333333333 * (x * x)) - 0.3333333333333333), (x * x), 1.0) * x;
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= -1.55) tmp = Float64(Float64(2.0 / Float64(Float64(-1.3333333333333333 * x) * Float64(x * x))) - 1.0); else tmp = Float64(fma(Float64(Float64(0.13333333333333333 * Float64(x * x)) - 0.3333333333333333), Float64(x * x), 1.0) * x); end return tmp end
code[x_] := If[LessEqual[x, -1.55], N[(N[(2.0 / N[(N[(-1.3333333333333333 * x), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision], N[(N[(N[(N[(0.13333333333333333 * N[(x * x), $MachinePrecision]), $MachinePrecision] - 0.3333333333333333), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.55:\\
\;\;\;\;\frac{2}{\left(-1.3333333333333333 \cdot x\right) \cdot \left(x \cdot x\right)} - 1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.13333333333333333 \cdot \left(x \cdot x\right) - 0.3333333333333333, x \cdot x, 1\right) \cdot x\\
\end{array}
\end{array}
if x < -1.55000000000000004Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f6499.3
Applied rewrites99.3%
Taylor expanded in x around -inf
Applied rewrites99.3%
Taylor expanded in x around inf
Applied rewrites99.3%
if -1.55000000000000004 < x Initial program 40.3%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
*-commutativeN/A
pow-plusN/A
lower-pow.f64N/A
metadata-evalN/A
lower--.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6466.7
Applied rewrites66.7%
Applied rewrites66.7%
Applied rewrites66.7%
(FPCore (x)
:precision binary64
(if (<= x -1.2)
(- (/ 2.0 (fma (fma x 2.0 -2.0) x 2.0)) 1.0)
(*
(fma (- (* 0.13333333333333333 (* x x)) 0.3333333333333333) (* x x) 1.0)
x)))
double code(double x) {
double tmp;
if (x <= -1.2) {
tmp = (2.0 / fma(fma(x, 2.0, -2.0), x, 2.0)) - 1.0;
} else {
tmp = fma(((0.13333333333333333 * (x * x)) - 0.3333333333333333), (x * x), 1.0) * x;
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= -1.2) tmp = Float64(Float64(2.0 / fma(fma(x, 2.0, -2.0), x, 2.0)) - 1.0); else tmp = Float64(fma(Float64(Float64(0.13333333333333333 * Float64(x * x)) - 0.3333333333333333), Float64(x * x), 1.0) * x); end return tmp end
code[x_] := If[LessEqual[x, -1.2], N[(N[(2.0 / N[(N[(x * 2.0 + -2.0), $MachinePrecision] * x + 2.0), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision], N[(N[(N[(N[(0.13333333333333333 * N[(x * x), $MachinePrecision]), $MachinePrecision] - 0.3333333333333333), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.2:\\
\;\;\;\;\frac{2}{\mathsf{fma}\left(\mathsf{fma}\left(x, 2, -2\right), x, 2\right)} - 1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.13333333333333333 \cdot \left(x \cdot x\right) - 0.3333333333333333, x \cdot x, 1\right) \cdot x\\
\end{array}
\end{array}
if x < -1.19999999999999996Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6498.1
Applied rewrites98.1%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
metadata-evalN/A
metadata-evalN/A
rgt-mult-inverseN/A
distribute-lft-neg-outN/A
associate-*r*N/A
*-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
metadata-evalN/A
*-commutativeN/A
associate-*r*N/A
rgt-mult-inverseN/A
metadata-evalN/A
lower-fma.f6498.7
Applied rewrites98.7%
if -1.19999999999999996 < x Initial program 40.3%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
*-commutativeN/A
pow-plusN/A
lower-pow.f64N/A
metadata-evalN/A
lower--.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6466.7
Applied rewrites66.7%
Applied rewrites66.7%
Applied rewrites66.7%
(FPCore (x) :precision binary64 (if (<= x -0.43) (- (/ 2.0 (fma (fma x 2.0 -2.0) x 2.0)) 1.0) (* 1.0 x)))
double code(double x) {
double tmp;
if (x <= -0.43) {
tmp = (2.0 / fma(fma(x, 2.0, -2.0), x, 2.0)) - 1.0;
} else {
tmp = 1.0 * x;
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= -0.43) tmp = Float64(Float64(2.0 / fma(fma(x, 2.0, -2.0), x, 2.0)) - 1.0); else tmp = Float64(1.0 * x); end return tmp end
code[x_] := If[LessEqual[x, -0.43], N[(N[(2.0 / N[(N[(x * 2.0 + -2.0), $MachinePrecision] * x + 2.0), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.43:\\
\;\;\;\;\frac{2}{\mathsf{fma}\left(\mathsf{fma}\left(x, 2, -2\right), x, 2\right)} - 1\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if x < -0.429999999999999993Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6498.1
Applied rewrites98.1%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
metadata-evalN/A
metadata-evalN/A
rgt-mult-inverseN/A
distribute-lft-neg-outN/A
associate-*r*N/A
*-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
metadata-evalN/A
*-commutativeN/A
associate-*r*N/A
rgt-mult-inverseN/A
metadata-evalN/A
lower-fma.f6498.7
Applied rewrites98.7%
if -0.429999999999999993 < x Initial program 40.3%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
*-commutativeN/A
pow-plusN/A
lower-pow.f64N/A
metadata-evalN/A
lower--.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6466.7
Applied rewrites66.7%
Applied rewrites66.7%
Applied rewrites66.7%
Taylor expanded in x around 0
Applied rewrites66.4%
(FPCore (x) :precision binary64 (if (<= x -1.35) (- (/ -1.0 (+ -1.0 x)) 1.0) (* 1.0 x)))
double code(double x) {
double tmp;
if (x <= -1.35) {
tmp = (-1.0 / (-1.0 + x)) - 1.0;
} else {
tmp = 1.0 * x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-1.35d0)) then
tmp = ((-1.0d0) / ((-1.0d0) + x)) - 1.0d0
else
tmp = 1.0d0 * x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -1.35) {
tmp = (-1.0 / (-1.0 + x)) - 1.0;
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x): tmp = 0 if x <= -1.35: tmp = (-1.0 / (-1.0 + x)) - 1.0 else: tmp = 1.0 * x return tmp
function code(x) tmp = 0.0 if (x <= -1.35) tmp = Float64(Float64(-1.0 / Float64(-1.0 + x)) - 1.0); else tmp = Float64(1.0 * x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -1.35) tmp = (-1.0 / (-1.0 + x)) - 1.0; else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -1.35], N[(N[(-1.0 / N[(-1.0 + x), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.35:\\
\;\;\;\;\frac{-1}{-1 + x} - 1\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if x < -1.3500000000000001Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites3.1%
Taylor expanded in x around 0
+-commutativeN/A
lft-mult-inverseN/A
fp-cancel-sign-subN/A
distribute-lft-neg-outN/A
lft-mult-inverseN/A
metadata-evalN/A
lower--.f645.3
Applied rewrites5.3%
Applied rewrites4.9%
Taylor expanded in x around 0
Applied rewrites98.1%
if -1.3500000000000001 < x Initial program 40.3%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
*-commutativeN/A
pow-plusN/A
lower-pow.f64N/A
metadata-evalN/A
lower--.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6466.7
Applied rewrites66.7%
Applied rewrites66.7%
Applied rewrites66.7%
Taylor expanded in x around 0
Applied rewrites66.4%
(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}
\\
1 \cdot x
\end{array}
Initial program 55.9%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
*-commutativeN/A
pow-plusN/A
lower-pow.f64N/A
metadata-evalN/A
lower--.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6450.1
Applied rewrites50.1%
Applied rewrites50.1%
Applied rewrites50.1%
Taylor expanded in x around 0
Applied rewrites50.4%
(FPCore (x) :precision binary64 (- 1.0 1.0))
double code(double x) {
return 1.0 - 1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 - 1.0d0
end function
public static double code(double x) {
return 1.0 - 1.0;
}
def code(x): return 1.0 - 1.0
function code(x) return Float64(1.0 - 1.0) end
function tmp = code(x) tmp = 1.0 - 1.0; end
code[x_] := N[(1.0 - 1.0), $MachinePrecision]
\begin{array}{l}
\\
1 - 1
\end{array}
Initial program 55.9%
Taylor expanded in x around 0
Applied rewrites4.2%
herbie shell --seed 2024340
(FPCore (x)
:name "Logistic function from Lakshay Garg"
:precision binary64
(- (/ 2.0 (+ 1.0 (exp (* -2.0 x)))) 1.0))