
(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 2 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 (sinh x))
double code(double x) {
return sinh(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = sinh(x)
end function
public static double code(double x) {
return Math.sinh(x);
}
def code(x): return math.sinh(x)
function code(x) return sinh(x) end
function tmp = code(x) tmp = sinh(x); end
code[x_] := N[Sinh[x], $MachinePrecision]
\begin{array}{l}
\\
\sinh x
\end{array}
Initial program 54.9%
div-sub54.9%
metadata-eval54.9%
associate-/l*54.9%
*-commutative54.9%
associate-/l*54.9%
associate-/r/54.9%
*-commutative54.9%
fma-neg54.9%
metadata-eval54.9%
exp-neg54.8%
associate-/l/54.8%
distribute-neg-frac54.8%
metadata-eval54.8%
associate-/r*54.8%
metadata-eval54.8%
Simplified54.8%
Taylor expanded in x around inf 54.8%
distribute-lft-out--54.8%
rec-exp54.9%
sinh-undef100.0%
Applied egg-rr100.0%
associate-*r*100.0%
metadata-eval100.0%
*-lft-identity100.0%
Simplified100.0%
Final simplification100.0%
(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 54.9%
div-sub54.9%
metadata-eval54.9%
associate-/l*54.9%
*-commutative54.9%
associate-/l*54.9%
associate-/r/54.9%
*-commutative54.9%
fma-neg54.9%
metadata-eval54.9%
exp-neg54.8%
associate-/l/54.8%
distribute-neg-frac54.8%
metadata-eval54.8%
associate-/r*54.8%
metadata-eval54.8%
Simplified54.8%
Taylor expanded in x around 0 51.4%
Final simplification51.4%
herbie shell --seed 2023320
(FPCore (x)
:name "Hyperbolic sine"
:precision binary64
(/ (- (exp x) (exp (- x))) 2.0))