
(FPCore (x) :precision binary64 (/ (- (exp x) (exp (- x))) 2.0))
double code(double x) {
return (exp(x) - exp(-x)) / 2.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (exp(x) - exp(-x)) / 2.0d0
end function
public static double code(double x) {
return (Math.exp(x) - Math.exp(-x)) / 2.0;
}
def code(x): return (math.exp(x) - math.exp(-x)) / 2.0
function code(x) return Float64(Float64(exp(x) - exp(Float64(-x))) / 2.0) end
function tmp = code(x) tmp = (exp(x) - exp(-x)) / 2.0; end
code[x_] := N[(N[(N[Exp[x], $MachinePrecision] - N[Exp[(-x)], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{e^{x} - e^{-x}}{2}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (/ (- (exp x) (exp (- x))) 2.0))
double code(double x) {
return (exp(x) - exp(-x)) / 2.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (exp(x) - exp(-x)) / 2.0d0
end function
public static double code(double x) {
return (Math.exp(x) - Math.exp(-x)) / 2.0;
}
def code(x): return (math.exp(x) - math.exp(-x)) / 2.0
function code(x) return Float64(Float64(exp(x) - exp(Float64(-x))) / 2.0) end
function tmp = code(x) tmp = (exp(x) - exp(-x)) / 2.0; end
code[x_] := N[(N[(N[Exp[x], $MachinePrecision] - N[Exp[(-x)], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{e^{x} - e^{-x}}{2}
\end{array}
(FPCore (x) :precision binary64 (log1p (expm1 x)))
double code(double x) {
return log1p(expm1(x));
}
public static double code(double x) {
return Math.log1p(Math.expm1(x));
}
def code(x): return math.log1p(math.expm1(x))
function code(x) return log1p(expm1(x)) end
code[x_] := N[Log[1 + N[(Exp[x] - 1), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\mathsf{log1p}\left(\mathsf{expm1}\left(x\right)\right)
\end{array}
Initial program 55.1%
Taylor expanded in x around 0 52.3%
associate-/l*51.5%
associate-/r/51.7%
metadata-eval51.7%
*-un-lft-identity51.7%
log1p-expm1-u98.7%
Applied egg-rr98.7%
Final simplification98.7%
(FPCore (x) :precision binary64 (/ (+ (* x (* x (* x 0.3333333333333333))) (* x 2.0)) 2.0))
double code(double x) {
return ((x * (x * (x * 0.3333333333333333))) + (x * 2.0)) / 2.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((x * (x * (x * 0.3333333333333333d0))) + (x * 2.0d0)) / 2.0d0
end function
public static double code(double x) {
return ((x * (x * (x * 0.3333333333333333))) + (x * 2.0)) / 2.0;
}
def code(x): return ((x * (x * (x * 0.3333333333333333))) + (x * 2.0)) / 2.0
function code(x) return Float64(Float64(Float64(x * Float64(x * Float64(x * 0.3333333333333333))) + Float64(x * 2.0)) / 2.0) end
function tmp = code(x) tmp = ((x * (x * (x * 0.3333333333333333))) + (x * 2.0)) / 2.0; end
code[x_] := N[(N[(N[(x * N[(x * N[(x * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(x * 2.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(x \cdot \left(x \cdot 0.3333333333333333\right)\right) + x \cdot 2}{2}
\end{array}
Initial program 55.1%
Taylor expanded in x around 0 83.4%
unpow383.4%
associate-*r*83.4%
distribute-rgt-out83.4%
*-commutative83.4%
associate-*l*83.4%
fma-def83.4%
Simplified83.4%
fma-udef83.4%
distribute-rgt-in83.4%
Applied egg-rr83.4%
Final simplification83.4%
(FPCore (x) :precision binary64 (/ (* x (+ 2.0 (* 0.3333333333333333 (* x x)))) 2.0))
double code(double x) {
return (x * (2.0 + (0.3333333333333333 * (x * x)))) / 2.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x * (2.0d0 + (0.3333333333333333d0 * (x * x)))) / 2.0d0
end function
public static double code(double x) {
return (x * (2.0 + (0.3333333333333333 * (x * x)))) / 2.0;
}
def code(x): return (x * (2.0 + (0.3333333333333333 * (x * x)))) / 2.0
function code(x) return Float64(Float64(x * Float64(2.0 + Float64(0.3333333333333333 * Float64(x * x)))) / 2.0) end
function tmp = code(x) tmp = (x * (2.0 + (0.3333333333333333 * (x * x)))) / 2.0; end
code[x_] := N[(N[(x * N[(2.0 + N[(0.3333333333333333 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(2 + 0.3333333333333333 \cdot \left(x \cdot x\right)\right)}{2}
\end{array}
Initial program 55.1%
Taylor expanded in x around 0 83.4%
unpow383.4%
associate-*r*83.4%
distribute-rgt-out83.4%
*-commutative83.4%
associate-*l*83.4%
fma-def83.4%
Simplified83.4%
Taylor expanded in x around 0 83.4%
unpow383.4%
associate-*r*83.4%
*-commutative83.4%
associate-*r*83.4%
distribute-rgt-out83.4%
associate-*r*83.4%
*-commutative83.4%
fma-def83.4%
Simplified83.4%
fma-udef83.4%
Applied egg-rr83.4%
Final simplification83.4%
(FPCore (x) :precision binary64 (/ (* x 2.0) 2.0))
double code(double x) {
return (x * 2.0) / 2.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x * 2.0d0) / 2.0d0
end function
public static double code(double x) {
return (x * 2.0) / 2.0;
}
def code(x): return (x * 2.0) / 2.0
function code(x) return Float64(Float64(x * 2.0) / 2.0) end
function tmp = code(x) tmp = (x * 2.0) / 2.0; end
code[x_] := N[(N[(x * 2.0), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot 2}{2}
\end{array}
Initial program 55.1%
Taylor expanded in x around 0 52.3%
Final simplification52.3%
(FPCore (x) :precision binary64 x)
double code(double x) {
return x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = x
end function
public static double code(double x) {
return x;
}
def code(x): return x
function code(x) return x end
function tmp = code(x) tmp = x; end
code[x_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 55.1%
Taylor expanded in x around 0 52.3%
Taylor expanded in x around 0 51.7%
Final simplification51.7%
herbie shell --seed 2023275
(FPCore (x)
:name "Hyperbolic sine"
:precision binary64
(/ (- (exp x) (exp (- x))) 2.0))