
(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 5 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 (- (/ 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}
Initial program 53.4%
(FPCore (x y) :precision binary64 (/ 2.0 (+ 1.0 (+ 1.0 (exp (* -2.0 x))))))
double code(double x, double y) {
return 2.0 / (1.0 + (1.0 + exp((-2.0 * x))));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 2.0d0 / (1.0d0 + (1.0d0 + exp(((-2.0d0) * x))))
end function
public static double code(double x, double y) {
return 2.0 / (1.0 + (1.0 + Math.exp((-2.0 * x))));
}
def code(x, y): return 2.0 / (1.0 + (1.0 + math.exp((-2.0 * x))))
function code(x, y) return Float64(2.0 / Float64(1.0 + Float64(1.0 + exp(Float64(-2.0 * x))))) end
function tmp = code(x, y) tmp = 2.0 / (1.0 + (1.0 + exp((-2.0 * x)))); end
code[x_, y_] := N[(2.0 / N[(1.0 + N[(1.0 + N[Exp[N[(-2.0 * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{1 + \left(1 + e^{-2 \cdot x}\right)}
\end{array}
Initial program 53.4%
Taylor expanded in x around 0
Applied rewrites6.8%
Taylor expanded in x around 0
Applied rewrites24.6%
(FPCore (x y) :precision binary64 (+ 1.0 (exp (* -2.0 x))))
double code(double x, double y) {
return 1.0 + exp((-2.0 * x));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 + exp(((-2.0d0) * x))
end function
public static double code(double x, double y) {
return 1.0 + Math.exp((-2.0 * x));
}
def code(x, y): return 1.0 + math.exp((-2.0 * x))
function code(x, y) return Float64(1.0 + exp(Float64(-2.0 * x))) end
function tmp = code(x, y) tmp = 1.0 + exp((-2.0 * x)); end
code[x_, y_] := N[(1.0 + N[Exp[N[(-2.0 * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + e^{-2 \cdot x}
\end{array}
Initial program 53.4%
Taylor expanded in x around 0
Applied rewrites23.9%
(FPCore (x y) :precision binary64 (exp (* -2.0 x)))
double code(double x, double y) {
return exp((-2.0 * x));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = exp(((-2.0d0) * x))
end function
public static double code(double x, double y) {
return Math.exp((-2.0 * x));
}
def code(x, y): return math.exp((-2.0 * x))
function code(x, y) return exp(Float64(-2.0 * x)) end
function tmp = code(x, y) tmp = exp((-2.0 * x)); end
code[x_, y_] := N[Exp[N[(-2.0 * x), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{-2 \cdot x}
\end{array}
Initial program 53.4%
Taylor expanded in x around 0
Applied rewrites2.7%
(FPCore (x y) :precision binary64 (* -2.0 x))
double code(double x, double y) {
return -2.0 * x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (-2.0d0) * x
end function
public static double code(double x, double y) {
return -2.0 * x;
}
def code(x, y): return -2.0 * x
function code(x, y) return Float64(-2.0 * x) end
function tmp = code(x, y) tmp = -2.0 * x; end
code[x_, y_] := N[(-2.0 * x), $MachinePrecision]
\begin{array}{l}
\\
-2 \cdot x
\end{array}
Initial program 53.4%
Taylor expanded in x around 0
Applied rewrites2.7%
Taylor expanded in x around 0
Applied rewrites2.4%
herbie shell --seed 2024321
(FPCore (x y)
:name "Logistic function from Lakshay Garg"
:precision binary64
:pre (TRUE)
(- (/ 2.0 (+ 1.0 (exp (* -2.0 x)))) 1.0))