
(FPCore (x y) :precision binary64 (- (/ 2.0 (+ 1.0 (exp (* -2.0 x)))) 1.0))
double code(double x, double y) {
return (2.0 / (1.0 + exp((-2.0 * x)))) - 1.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (2.0d0 / (1.0d0 + exp(((-2.0d0) * x)))) - 1.0d0
end function
public static double code(double x, double y) {
return (2.0 / (1.0 + Math.exp((-2.0 * x)))) - 1.0;
}
def code(x, y): return (2.0 / (1.0 + math.exp((-2.0 * x)))) - 1.0
function code(x, y) return Float64(Float64(2.0 / Float64(1.0 + exp(Float64(-2.0 * x)))) - 1.0) end
function tmp = code(x, y) tmp = (2.0 / (1.0 + exp((-2.0 * x)))) - 1.0; end
code[x_, y_] := 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 y) :precision binary64 (- (/ 2.0 (+ 1.0 (exp (* -2.0 x)))) 1.0))
double code(double x, double y) {
return (2.0 / (1.0 + exp((-2.0 * x)))) - 1.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (2.0d0 / (1.0d0 + exp(((-2.0d0) * x)))) - 1.0d0
end function
public static double code(double x, double y) {
return (2.0 / (1.0 + Math.exp((-2.0 * x)))) - 1.0;
}
def code(x, y): return (2.0 / (1.0 + math.exp((-2.0 * x)))) - 1.0
function code(x, y) return Float64(Float64(2.0 / Float64(1.0 + exp(Float64(-2.0 * x)))) - 1.0) end
function tmp = code(x, y) tmp = (2.0 / (1.0 + exp((-2.0 * x)))) - 1.0; end
code[x_, y_] := 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 y)
:precision binary64
(let* ((t_0 (/ 2.0 (+ 1.0 (exp (* -2.0 x))))))
(if (<= t_0 0.0)
-1.0
(if (<= t_0 1.0)
(fma
(- (* 0.13333333333333333 (pow x 2.0)) 0.3333333333333333)
(pow x 3.0)
x)
(cbrt (pow (+ t_0 -1.0) 3.0))))))
double code(double x, double y) {
double t_0 = 2.0 / (1.0 + exp((-2.0 * x)));
double tmp;
if (t_0 <= 0.0) {
tmp = -1.0;
} else if (t_0 <= 1.0) {
tmp = fma(((0.13333333333333333 * pow(x, 2.0)) - 0.3333333333333333), pow(x, 3.0), x);
} else {
tmp = cbrt(pow((t_0 + -1.0), 3.0));
}
return tmp;
}
function code(x, y) t_0 = Float64(2.0 / Float64(1.0 + exp(Float64(-2.0 * x)))) tmp = 0.0 if (t_0 <= 0.0) tmp = -1.0; elseif (t_0 <= 1.0) tmp = fma(Float64(Float64(0.13333333333333333 * (x ^ 2.0)) - 0.3333333333333333), (x ^ 3.0), x); else tmp = cbrt((Float64(t_0 + -1.0) ^ 3.0)); end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(2.0 / N[(1.0 + N[Exp[N[(-2.0 * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 0.0], -1.0, If[LessEqual[t$95$0, 1.0], N[(N[(N[(0.13333333333333333 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision] - 0.3333333333333333), $MachinePrecision] * N[Power[x, 3.0], $MachinePrecision] + x), $MachinePrecision], N[Power[N[Power[N[(t$95$0 + -1.0), $MachinePrecision], 3.0], $MachinePrecision], 1/3], $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{2}{1 + e^{-2 \cdot x}}\\
\mathbf{if}\;t\_0 \leq 0:\\
\;\;\;\;-1\\
\mathbf{elif}\;t\_0 \leq 1:\\
\;\;\;\;\mathsf{fma}\left(0.13333333333333333 \cdot {x}^{2} - 0.3333333333333333, {x}^{3}, x\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{{\left(t\_0 + -1\right)}^{3}}\\
\end{array}
\end{array}
if (/.f64 #s(literal 2 binary64) (+.f64 #s(literal 1 binary64) (exp.f64 (*.f64 #s(literal -2 binary64) x)))) < 0.0Initial program 100.0%
Taylor expanded in x around 0 98.9%
*-commutative98.9%
Simplified98.9%
Taylor expanded in x around inf 100.0%
if 0.0 < (/.f64 #s(literal 2 binary64) (+.f64 #s(literal 1 binary64) (exp.f64 (*.f64 #s(literal -2 binary64) x)))) < 1Initial program 6.9%
Taylor expanded in x around 0 100.0%
+-commutative100.0%
distribute-rgt-in100.0%
*-commutative100.0%
associate-*l*100.0%
*-lft-identity100.0%
fma-define100.0%
*-commutative100.0%
fma-neg100.0%
metadata-eval100.0%
pow-plus100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
if 1 < (/.f64 #s(literal 2 binary64) (+.f64 #s(literal 1 binary64) (exp.f64 (*.f64 #s(literal -2 binary64) x)))) Initial program 99.4%
add-cbrt-cube99.4%
pow399.4%
sub-neg99.4%
exp-prod99.4%
metadata-eval99.4%
Applied egg-rr99.4%
Taylor expanded in x around inf 99.4%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ 2.0 (+ 1.0 (exp (* -2.0 x))))))
(if (<= t_0 0.0)
-1.0
(if (<= t_0 1.0)
(fma
(- (* 0.13333333333333333 (pow x 2.0)) 0.3333333333333333)
(pow x 3.0)
x)
(+ t_0 -1.0)))))
double code(double x, double y) {
double t_0 = 2.0 / (1.0 + exp((-2.0 * x)));
double tmp;
if (t_0 <= 0.0) {
tmp = -1.0;
} else if (t_0 <= 1.0) {
tmp = fma(((0.13333333333333333 * pow(x, 2.0)) - 0.3333333333333333), pow(x, 3.0), x);
} else {
tmp = t_0 + -1.0;
}
return tmp;
}
function code(x, y) t_0 = Float64(2.0 / Float64(1.0 + exp(Float64(-2.0 * x)))) tmp = 0.0 if (t_0 <= 0.0) tmp = -1.0; elseif (t_0 <= 1.0) tmp = fma(Float64(Float64(0.13333333333333333 * (x ^ 2.0)) - 0.3333333333333333), (x ^ 3.0), x); else tmp = Float64(t_0 + -1.0); end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(2.0 / N[(1.0 + N[Exp[N[(-2.0 * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 0.0], -1.0, If[LessEqual[t$95$0, 1.0], N[(N[(N[(0.13333333333333333 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision] - 0.3333333333333333), $MachinePrecision] * N[Power[x, 3.0], $MachinePrecision] + x), $MachinePrecision], N[(t$95$0 + -1.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{2}{1 + e^{-2 \cdot x}}\\
\mathbf{if}\;t\_0 \leq 0:\\
\;\;\;\;-1\\
\mathbf{elif}\;t\_0 \leq 1:\\
\;\;\;\;\mathsf{fma}\left(0.13333333333333333 \cdot {x}^{2} - 0.3333333333333333, {x}^{3}, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0 + -1\\
\end{array}
\end{array}
if (/.f64 #s(literal 2 binary64) (+.f64 #s(literal 1 binary64) (exp.f64 (*.f64 #s(literal -2 binary64) x)))) < 0.0Initial program 100.0%
Taylor expanded in x around 0 98.9%
*-commutative98.9%
Simplified98.9%
Taylor expanded in x around inf 100.0%
if 0.0 < (/.f64 #s(literal 2 binary64) (+.f64 #s(literal 1 binary64) (exp.f64 (*.f64 #s(literal -2 binary64) x)))) < 1Initial program 6.9%
Taylor expanded in x around 0 100.0%
+-commutative100.0%
distribute-rgt-in100.0%
*-commutative100.0%
associate-*l*100.0%
*-lft-identity100.0%
fma-define100.0%
*-commutative100.0%
fma-neg100.0%
metadata-eval100.0%
pow-plus100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
if 1 < (/.f64 #s(literal 2 binary64) (+.f64 #s(literal 1 binary64) (exp.f64 (*.f64 #s(literal -2 binary64) x)))) Initial program 99.4%
Final simplification99.8%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ 2.0 (+ 1.0 (exp (* -2.0 x))))))
(if (<= t_0 0.0)
-1.0
(if (<= t_0 1.0)
(*
x
(+
1.0
(*
(pow x 2.0)
(- (* 0.13333333333333333 (pow x 2.0)) 0.3333333333333333))))
(+ t_0 -1.0)))))
double code(double x, double y) {
double t_0 = 2.0 / (1.0 + exp((-2.0 * x)));
double tmp;
if (t_0 <= 0.0) {
tmp = -1.0;
} else if (t_0 <= 1.0) {
tmp = x * (1.0 + (pow(x, 2.0) * ((0.13333333333333333 * pow(x, 2.0)) - 0.3333333333333333)));
} else {
tmp = t_0 + -1.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = 2.0d0 / (1.0d0 + exp(((-2.0d0) * x)))
if (t_0 <= 0.0d0) then
tmp = -1.0d0
else if (t_0 <= 1.0d0) then
tmp = x * (1.0d0 + ((x ** 2.0d0) * ((0.13333333333333333d0 * (x ** 2.0d0)) - 0.3333333333333333d0)))
else
tmp = t_0 + (-1.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = 2.0 / (1.0 + Math.exp((-2.0 * x)));
double tmp;
if (t_0 <= 0.0) {
tmp = -1.0;
} else if (t_0 <= 1.0) {
tmp = x * (1.0 + (Math.pow(x, 2.0) * ((0.13333333333333333 * Math.pow(x, 2.0)) - 0.3333333333333333)));
} else {
tmp = t_0 + -1.0;
}
return tmp;
}
def code(x, y): t_0 = 2.0 / (1.0 + math.exp((-2.0 * x))) tmp = 0 if t_0 <= 0.0: tmp = -1.0 elif t_0 <= 1.0: tmp = x * (1.0 + (math.pow(x, 2.0) * ((0.13333333333333333 * math.pow(x, 2.0)) - 0.3333333333333333))) else: tmp = t_0 + -1.0 return tmp
function code(x, y) t_0 = Float64(2.0 / Float64(1.0 + exp(Float64(-2.0 * x)))) tmp = 0.0 if (t_0 <= 0.0) tmp = -1.0; elseif (t_0 <= 1.0) tmp = Float64(x * Float64(1.0 + Float64((x ^ 2.0) * Float64(Float64(0.13333333333333333 * (x ^ 2.0)) - 0.3333333333333333)))); else tmp = Float64(t_0 + -1.0); end return tmp end
function tmp_2 = code(x, y) t_0 = 2.0 / (1.0 + exp((-2.0 * x))); tmp = 0.0; if (t_0 <= 0.0) tmp = -1.0; elseif (t_0 <= 1.0) tmp = x * (1.0 + ((x ^ 2.0) * ((0.13333333333333333 * (x ^ 2.0)) - 0.3333333333333333))); else tmp = t_0 + -1.0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(2.0 / N[(1.0 + N[Exp[N[(-2.0 * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 0.0], -1.0, If[LessEqual[t$95$0, 1.0], N[(x * N[(1.0 + N[(N[Power[x, 2.0], $MachinePrecision] * N[(N[(0.13333333333333333 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision] - 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 + -1.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{2}{1 + e^{-2 \cdot x}}\\
\mathbf{if}\;t\_0 \leq 0:\\
\;\;\;\;-1\\
\mathbf{elif}\;t\_0 \leq 1:\\
\;\;\;\;x \cdot \left(1 + {x}^{2} \cdot \left(0.13333333333333333 \cdot {x}^{2} - 0.3333333333333333\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0 + -1\\
\end{array}
\end{array}
if (/.f64 #s(literal 2 binary64) (+.f64 #s(literal 1 binary64) (exp.f64 (*.f64 #s(literal -2 binary64) x)))) < 0.0Initial program 100.0%
Taylor expanded in x around 0 98.9%
*-commutative98.9%
Simplified98.9%
Taylor expanded in x around inf 100.0%
if 0.0 < (/.f64 #s(literal 2 binary64) (+.f64 #s(literal 1 binary64) (exp.f64 (*.f64 #s(literal -2 binary64) x)))) < 1Initial program 6.9%
Taylor expanded in x around 0 100.0%
if 1 < (/.f64 #s(literal 2 binary64) (+.f64 #s(literal 1 binary64) (exp.f64 (*.f64 #s(literal -2 binary64) x)))) Initial program 99.4%
Final simplification99.8%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ 2.0 (+ 1.0 (exp (* -2.0 x))))))
(if (<= t_0 0.0)
-1.0
(if (<= t_0 1.0)
(+ x (* (pow x 3.0) -0.3333333333333333))
(+ t_0 -1.0)))))
double code(double x, double y) {
double t_0 = 2.0 / (1.0 + exp((-2.0 * x)));
double tmp;
if (t_0 <= 0.0) {
tmp = -1.0;
} else if (t_0 <= 1.0) {
tmp = x + (pow(x, 3.0) * -0.3333333333333333);
} else {
tmp = t_0 + -1.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = 2.0d0 / (1.0d0 + exp(((-2.0d0) * x)))
if (t_0 <= 0.0d0) then
tmp = -1.0d0
else if (t_0 <= 1.0d0) then
tmp = x + ((x ** 3.0d0) * (-0.3333333333333333d0))
else
tmp = t_0 + (-1.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = 2.0 / (1.0 + Math.exp((-2.0 * x)));
double tmp;
if (t_0 <= 0.0) {
tmp = -1.0;
} else if (t_0 <= 1.0) {
tmp = x + (Math.pow(x, 3.0) * -0.3333333333333333);
} else {
tmp = t_0 + -1.0;
}
return tmp;
}
def code(x, y): t_0 = 2.0 / (1.0 + math.exp((-2.0 * x))) tmp = 0 if t_0 <= 0.0: tmp = -1.0 elif t_0 <= 1.0: tmp = x + (math.pow(x, 3.0) * -0.3333333333333333) else: tmp = t_0 + -1.0 return tmp
function code(x, y) t_0 = Float64(2.0 / Float64(1.0 + exp(Float64(-2.0 * x)))) tmp = 0.0 if (t_0 <= 0.0) tmp = -1.0; elseif (t_0 <= 1.0) tmp = Float64(x + Float64((x ^ 3.0) * -0.3333333333333333)); else tmp = Float64(t_0 + -1.0); end return tmp end
function tmp_2 = code(x, y) t_0 = 2.0 / (1.0 + exp((-2.0 * x))); tmp = 0.0; if (t_0 <= 0.0) tmp = -1.0; elseif (t_0 <= 1.0) tmp = x + ((x ^ 3.0) * -0.3333333333333333); else tmp = t_0 + -1.0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(2.0 / N[(1.0 + N[Exp[N[(-2.0 * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 0.0], -1.0, If[LessEqual[t$95$0, 1.0], N[(x + N[(N[Power[x, 3.0], $MachinePrecision] * -0.3333333333333333), $MachinePrecision]), $MachinePrecision], N[(t$95$0 + -1.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{2}{1 + e^{-2 \cdot x}}\\
\mathbf{if}\;t\_0 \leq 0:\\
\;\;\;\;-1\\
\mathbf{elif}\;t\_0 \leq 1:\\
\;\;\;\;x + {x}^{3} \cdot -0.3333333333333333\\
\mathbf{else}:\\
\;\;\;\;t\_0 + -1\\
\end{array}
\end{array}
if (/.f64 #s(literal 2 binary64) (+.f64 #s(literal 1 binary64) (exp.f64 (*.f64 #s(literal -2 binary64) x)))) < 0.0Initial program 100.0%
Taylor expanded in x around 0 98.9%
*-commutative98.9%
Simplified98.9%
Taylor expanded in x around inf 100.0%
if 0.0 < (/.f64 #s(literal 2 binary64) (+.f64 #s(literal 1 binary64) (exp.f64 (*.f64 #s(literal -2 binary64) x)))) < 1Initial program 6.9%
Taylor expanded in x around 0 100.0%
+-commutative100.0%
distribute-rgt-in100.0%
*-lft-identity100.0%
associate-*l*100.0%
fma-define100.0%
pow-plus100.0%
metadata-eval100.0%
Simplified100.0%
fma-undefine100.0%
Applied egg-rr100.0%
if 1 < (/.f64 #s(literal 2 binary64) (+.f64 #s(literal 1 binary64) (exp.f64 (*.f64 #s(literal -2 binary64) x)))) Initial program 99.4%
Final simplification99.8%
(FPCore (x y)
:precision binary64
(if (<= x -1.16)
-1.0
(if (<= x -1e-24)
(+ x (* (pow x 3.0) -0.3333333333333333))
(* x (/ 2.0 (+ 2.0 x))))))
double code(double x, double y) {
double tmp;
if (x <= -1.16) {
tmp = -1.0;
} else if (x <= -1e-24) {
tmp = x + (pow(x, 3.0) * -0.3333333333333333);
} else {
tmp = x * (2.0 / (2.0 + x));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-1.16d0)) then
tmp = -1.0d0
else if (x <= (-1d-24)) then
tmp = x + ((x ** 3.0d0) * (-0.3333333333333333d0))
else
tmp = x * (2.0d0 / (2.0d0 + x))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.16) {
tmp = -1.0;
} else if (x <= -1e-24) {
tmp = x + (Math.pow(x, 3.0) * -0.3333333333333333);
} else {
tmp = x * (2.0 / (2.0 + x));
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.16: tmp = -1.0 elif x <= -1e-24: tmp = x + (math.pow(x, 3.0) * -0.3333333333333333) else: tmp = x * (2.0 / (2.0 + x)) return tmp
function code(x, y) tmp = 0.0 if (x <= -1.16) tmp = -1.0; elseif (x <= -1e-24) tmp = Float64(x + Float64((x ^ 3.0) * -0.3333333333333333)); else tmp = Float64(x * Float64(2.0 / Float64(2.0 + x))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.16) tmp = -1.0; elseif (x <= -1e-24) tmp = x + ((x ^ 3.0) * -0.3333333333333333); else tmp = x * (2.0 / (2.0 + x)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.16], -1.0, If[LessEqual[x, -1e-24], N[(x + N[(N[Power[x, 3.0], $MachinePrecision] * -0.3333333333333333), $MachinePrecision]), $MachinePrecision], N[(x * N[(2.0 / N[(2.0 + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.16:\\
\;\;\;\;-1\\
\mathbf{elif}\;x \leq -1 \cdot 10^{-24}:\\
\;\;\;\;x + {x}^{3} \cdot -0.3333333333333333\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{2}{2 + x}\\
\end{array}
\end{array}
if x < -1.15999999999999992Initial program 100.0%
Taylor expanded in x around 0 98.9%
*-commutative98.9%
Simplified98.9%
Taylor expanded in x around inf 100.0%
if -1.15999999999999992 < x < -9.99999999999999924e-25Initial program 29.6%
Taylor expanded in x around 0 99.4%
+-commutative99.4%
distribute-rgt-in99.5%
*-lft-identity99.5%
associate-*l*99.5%
fma-define99.5%
pow-plus99.5%
metadata-eval99.5%
Simplified99.5%
fma-undefine99.5%
Applied egg-rr99.5%
if -9.99999999999999924e-25 < x Initial program 42.3%
Taylor expanded in x around 0 5.9%
+-commutative5.9%
Simplified5.9%
flip--5.7%
metadata-eval5.7%
difference-of-sqr-15.7%
associate-+l+5.7%
metadata-eval5.7%
associate--l+63.4%
metadata-eval63.4%
+-rgt-identity63.4%
associate-+l+63.4%
metadata-eval63.4%
Applied egg-rr63.4%
Taylor expanded in x around 0 68.4%
*-commutative68.4%
Simplified68.4%
associate-/l*68.4%
*-commutative68.4%
Applied egg-rr68.4%
Final simplification77.6%
(FPCore (x y) :precision binary64 (if (<= x -1.05e+18) -1.0 (if (<= x 2.55) x (- 2.0 (/ 4.0 x)))))
double code(double x, double y) {
double tmp;
if (x <= -1.05e+18) {
tmp = -1.0;
} else if (x <= 2.55) {
tmp = x;
} else {
tmp = 2.0 - (4.0 / x);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-1.05d+18)) then
tmp = -1.0d0
else if (x <= 2.55d0) then
tmp = x
else
tmp = 2.0d0 - (4.0d0 / x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.05e+18) {
tmp = -1.0;
} else if (x <= 2.55) {
tmp = x;
} else {
tmp = 2.0 - (4.0 / x);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.05e+18: tmp = -1.0 elif x <= 2.55: tmp = x else: tmp = 2.0 - (4.0 / x) return tmp
function code(x, y) tmp = 0.0 if (x <= -1.05e+18) tmp = -1.0; elseif (x <= 2.55) tmp = x; else tmp = Float64(2.0 - Float64(4.0 / x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.05e+18) tmp = -1.0; elseif (x <= 2.55) tmp = x; else tmp = 2.0 - (4.0 / x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.05e+18], -1.0, If[LessEqual[x, 2.55], x, N[(2.0 - N[(4.0 / x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.05 \cdot 10^{+18}:\\
\;\;\;\;-1\\
\mathbf{elif}\;x \leq 2.55:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;2 - \frac{4}{x}\\
\end{array}
\end{array}
if x < -1.05e18Initial program 100.0%
Taylor expanded in x around 0 100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
if -1.05e18 < x < 2.5499999999999998Initial program 9.7%
Taylor expanded in x around 0 97.4%
if 2.5499999999999998 < x Initial program 100.0%
Taylor expanded in x around 0 5.7%
+-commutative5.7%
Simplified5.7%
flip--5.3%
metadata-eval5.3%
difference-of-sqr-15.3%
associate-+l+5.3%
metadata-eval5.3%
associate--l+5.3%
metadata-eval5.3%
+-rgt-identity5.3%
associate-+l+5.3%
metadata-eval5.3%
Applied egg-rr5.3%
Taylor expanded in x around 0 18.8%
*-commutative18.8%
Simplified18.8%
Taylor expanded in x around inf 18.8%
associate-*r/18.8%
metadata-eval18.8%
Simplified18.8%
(FPCore (x y) :precision binary64 (if (<= x -1.05e+18) -1.0 (/ (* 2.0 x) (+ 2.0 x))))
double code(double x, double y) {
double tmp;
if (x <= -1.05e+18) {
tmp = -1.0;
} else {
tmp = (2.0 * x) / (2.0 + x);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-1.05d+18)) then
tmp = -1.0d0
else
tmp = (2.0d0 * x) / (2.0d0 + x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.05e+18) {
tmp = -1.0;
} else {
tmp = (2.0 * x) / (2.0 + x);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.05e+18: tmp = -1.0 else: tmp = (2.0 * x) / (2.0 + x) return tmp
function code(x, y) tmp = 0.0 if (x <= -1.05e+18) tmp = -1.0; else tmp = Float64(Float64(2.0 * x) / Float64(2.0 + x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.05e+18) tmp = -1.0; else tmp = (2.0 * x) / (2.0 + x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.05e+18], -1.0, N[(N[(2.0 * x), $MachinePrecision] / N[(2.0 + x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.05 \cdot 10^{+18}:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot x}{2 + x}\\
\end{array}
\end{array}
if x < -1.05e18Initial program 100.0%
Taylor expanded in x around 0 100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
if -1.05e18 < x Initial program 42.8%
Taylor expanded in x around 0 6.7%
+-commutative6.7%
Simplified6.7%
flip--6.6%
metadata-eval6.6%
difference-of-sqr-16.6%
associate-+l+6.6%
metadata-eval6.6%
associate--l+63.7%
metadata-eval63.7%
+-rgt-identity63.7%
associate-+l+63.7%
metadata-eval63.7%
Applied egg-rr63.7%
Taylor expanded in x around 0 67.9%
*-commutative67.9%
Simplified67.9%
Final simplification76.0%
(FPCore (x y) :precision binary64 (if (<= x -1.05e+18) -1.0 (* x (/ 2.0 (+ 2.0 x)))))
double code(double x, double y) {
double tmp;
if (x <= -1.05e+18) {
tmp = -1.0;
} else {
tmp = x * (2.0 / (2.0 + x));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-1.05d+18)) then
tmp = -1.0d0
else
tmp = x * (2.0d0 / (2.0d0 + x))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.05e+18) {
tmp = -1.0;
} else {
tmp = x * (2.0 / (2.0 + x));
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.05e+18: tmp = -1.0 else: tmp = x * (2.0 / (2.0 + x)) return tmp
function code(x, y) tmp = 0.0 if (x <= -1.05e+18) tmp = -1.0; else tmp = Float64(x * Float64(2.0 / Float64(2.0 + x))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.05e+18) tmp = -1.0; else tmp = x * (2.0 / (2.0 + x)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.05e+18], -1.0, N[(x * N[(2.0 / N[(2.0 + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.05 \cdot 10^{+18}:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{2}{2 + x}\\
\end{array}
\end{array}
if x < -1.05e18Initial program 100.0%
Taylor expanded in x around 0 100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
if -1.05e18 < x Initial program 42.8%
Taylor expanded in x around 0 6.7%
+-commutative6.7%
Simplified6.7%
flip--6.6%
metadata-eval6.6%
difference-of-sqr-16.6%
associate-+l+6.6%
metadata-eval6.6%
associate--l+63.7%
metadata-eval63.7%
+-rgt-identity63.7%
associate-+l+63.7%
metadata-eval63.7%
Applied egg-rr63.7%
Taylor expanded in x around 0 67.9%
*-commutative67.9%
Simplified67.9%
associate-/l*67.9%
*-commutative67.9%
Applied egg-rr67.9%
Final simplification76.0%
(FPCore (x y) :precision binary64 (if (<= x -1.05e+18) -1.0 (if (<= x 2.0) x 2.0)))
double code(double x, double y) {
double tmp;
if (x <= -1.05e+18) {
tmp = -1.0;
} else if (x <= 2.0) {
tmp = x;
} else {
tmp = 2.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-1.05d+18)) then
tmp = -1.0d0
else if (x <= 2.0d0) then
tmp = x
else
tmp = 2.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.05e+18) {
tmp = -1.0;
} else if (x <= 2.0) {
tmp = x;
} else {
tmp = 2.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.05e+18: tmp = -1.0 elif x <= 2.0: tmp = x else: tmp = 2.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -1.05e+18) tmp = -1.0; elseif (x <= 2.0) tmp = x; else tmp = 2.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.05e+18) tmp = -1.0; elseif (x <= 2.0) tmp = x; else tmp = 2.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.05e+18], -1.0, If[LessEqual[x, 2.0], x, 2.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.05 \cdot 10^{+18}:\\
\;\;\;\;-1\\
\mathbf{elif}\;x \leq 2:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;2\\
\end{array}
\end{array}
if x < -1.05e18Initial program 100.0%
Taylor expanded in x around 0 100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
if -1.05e18 < x < 2Initial program 9.7%
Taylor expanded in x around 0 97.4%
if 2 < x Initial program 100.0%
Taylor expanded in x around 0 5.7%
+-commutative5.7%
Simplified5.7%
flip--5.3%
metadata-eval5.3%
difference-of-sqr-15.3%
associate-+l+5.3%
metadata-eval5.3%
associate--l+5.3%
metadata-eval5.3%
+-rgt-identity5.3%
associate-+l+5.3%
metadata-eval5.3%
Applied egg-rr5.3%
Taylor expanded in x around 0 18.8%
*-commutative18.8%
Simplified18.8%
Taylor expanded in x around inf 18.8%
(FPCore (x y) :precision binary64 (if (<= x -360000000000.0) -1.0 2.0))
double code(double x, double y) {
double tmp;
if (x <= -360000000000.0) {
tmp = -1.0;
} else {
tmp = 2.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-360000000000.0d0)) then
tmp = -1.0d0
else
tmp = 2.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -360000000000.0) {
tmp = -1.0;
} else {
tmp = 2.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -360000000000.0: tmp = -1.0 else: tmp = 2.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -360000000000.0) tmp = -1.0; else tmp = 2.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -360000000000.0) tmp = -1.0; else tmp = 2.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -360000000000.0], -1.0, 2.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -360000000000:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;2\\
\end{array}
\end{array}
if x < -3.6e11Initial program 100.0%
Taylor expanded in x around 0 100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
if -3.6e11 < x Initial program 42.5%
Taylor expanded in x around 0 6.7%
+-commutative6.7%
Simplified6.7%
flip--6.6%
metadata-eval6.6%
difference-of-sqr-16.6%
associate-+l+6.6%
metadata-eval6.6%
associate--l+63.9%
metadata-eval63.9%
+-rgt-identity63.9%
associate-+l+64.0%
metadata-eval64.0%
Applied egg-rr64.0%
Taylor expanded in x around 0 68.2%
*-commutative68.2%
Simplified68.2%
Taylor expanded in x around inf 9.1%
(FPCore (x y) :precision binary64 -1.0)
double code(double x, double y) {
return -1.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = -1.0d0
end function
public static double code(double x, double y) {
return -1.0;
}
def code(x, y): return -1.0
function code(x, y) return -1.0 end
function tmp = code(x, y) tmp = -1.0; end
code[x_, y_] := -1.0
\begin{array}{l}
\\
-1
\end{array}
Initial program 57.3%
Taylor expanded in x around 0 30.0%
*-commutative30.0%
Simplified30.0%
Taylor expanded in x around inf 28.8%
herbie shell --seed 2024107
(FPCore (x y)
:name "Logistic function from Lakshay Garg"
:precision binary64
(- (/ 2.0 (+ 1.0 (exp (* -2.0 x)))) 1.0))