
(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 7 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 52.7%
sinh-undefN/A
*-commutativeN/A
lower-*.f64N/A
lower-sinh.f64100.0
Applied egg-rr100.0%
lift-sinh.f64N/A
associate-/l*N/A
metadata-evalN/A
*-rgt-identity100.0
Applied egg-rr100.0%
(FPCore (x) :precision binary64 (if (<= (- (exp x) (exp (- x))) 0.002) x (* 0.16666666666666666 (* x (* x x)))))
double code(double x) {
double tmp;
if ((exp(x) - exp(-x)) <= 0.002) {
tmp = x;
} else {
tmp = 0.16666666666666666 * (x * (x * x));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((exp(x) - exp(-x)) <= 0.002d0) then
tmp = x
else
tmp = 0.16666666666666666d0 * (x * (x * x))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((Math.exp(x) - Math.exp(-x)) <= 0.002) {
tmp = x;
} else {
tmp = 0.16666666666666666 * (x * (x * x));
}
return tmp;
}
def code(x): tmp = 0 if (math.exp(x) - math.exp(-x)) <= 0.002: tmp = x else: tmp = 0.16666666666666666 * (x * (x * x)) return tmp
function code(x) tmp = 0.0 if (Float64(exp(x) - exp(Float64(-x))) <= 0.002) tmp = x; else tmp = Float64(0.16666666666666666 * Float64(x * Float64(x * x))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((exp(x) - exp(-x)) <= 0.002) tmp = x; else tmp = 0.16666666666666666 * (x * (x * x)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(N[Exp[x], $MachinePrecision] - N[Exp[(-x)], $MachinePrecision]), $MachinePrecision], 0.002], x, N[(0.16666666666666666 * N[(x * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{x} - e^{-x} \leq 0.002:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;0.16666666666666666 \cdot \left(x \cdot \left(x \cdot x\right)\right)\\
\end{array}
\end{array}
if (-.f64 (exp.f64 x) (exp.f64 (neg.f64 x))) < 2e-3Initial program 37.5%
Taylor expanded in x around 0
lower-*.f6469.2
Simplified69.2%
*-commutativeN/A
associate-/l*N/A
metadata-evalN/A
*-rgt-identity69.2
Applied egg-rr69.2%
if 2e-3 < (-.f64 (exp.f64 x) (exp.f64 (neg.f64 x))) Initial program 100.0%
Taylor expanded in x around 0
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6468.2
Simplified68.2%
Taylor expanded in x around inf
lower-*.f64N/A
cube-multN/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6468.2
Simplified68.2%
(FPCore (x)
:precision binary64
(let* ((t_0 (* x (fma x (* x 0.016666666666666666) 0.3333333333333333))))
(if (<= x 5e+60)
(/ (/ (* x (fma (* x x) (* t_0 t_0) -4.0)) (fma x t_0 -2.0)) 2.0)
(fma
(fma (* x x) 0.008333333333333333 0.16666666666666666)
(* x (* x x))
x))))
double code(double x) {
double t_0 = x * fma(x, (x * 0.016666666666666666), 0.3333333333333333);
double tmp;
if (x <= 5e+60) {
tmp = ((x * fma((x * x), (t_0 * t_0), -4.0)) / fma(x, t_0, -2.0)) / 2.0;
} else {
tmp = fma(fma((x * x), 0.008333333333333333, 0.16666666666666666), (x * (x * x)), x);
}
return tmp;
}
function code(x) t_0 = Float64(x * fma(x, Float64(x * 0.016666666666666666), 0.3333333333333333)) tmp = 0.0 if (x <= 5e+60) tmp = Float64(Float64(Float64(x * fma(Float64(x * x), Float64(t_0 * t_0), -4.0)) / fma(x, t_0, -2.0)) / 2.0); else tmp = fma(fma(Float64(x * x), 0.008333333333333333, 0.16666666666666666), Float64(x * Float64(x * x)), x); end return tmp end
code[x_] := Block[{t$95$0 = N[(x * N[(x * N[(x * 0.016666666666666666), $MachinePrecision] + 0.3333333333333333), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 5e+60], N[(N[(N[(x * N[(N[(x * x), $MachinePrecision] * N[(t$95$0 * t$95$0), $MachinePrecision] + -4.0), $MachinePrecision]), $MachinePrecision] / N[(x * t$95$0 + -2.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(N[(x * x), $MachinePrecision] * 0.008333333333333333 + 0.16666666666666666), $MachinePrecision] * N[(x * N[(x * x), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \mathsf{fma}\left(x, x \cdot 0.016666666666666666, 0.3333333333333333\right)\\
\mathbf{if}\;x \leq 5 \cdot 10^{+60}:\\
\;\;\;\;\frac{\frac{x \cdot \mathsf{fma}\left(x \cdot x, t\_0 \cdot t\_0, -4\right)}{\mathsf{fma}\left(x, t\_0, -2\right)}}{2}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.008333333333333333, 0.16666666666666666\right), x \cdot \left(x \cdot x\right), x\right)\\
\end{array}
\end{array}
if x < 4.99999999999999975e60Initial program 41.7%
Taylor expanded in x around 0
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
+-commutativeN/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6486.5
Simplified86.5%
lift-*.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
lift-fma.f64N/A
*-commutativeN/A
lift-fma.f64N/A
flip-+N/A
associate-*l/N/A
lower-/.f64N/A
Applied egg-rr73.9%
if 4.99999999999999975e60 < x Initial program 100.0%
sinh-undefN/A
*-commutativeN/A
lower-*.f64N/A
lower-sinh.f64100.0
Applied egg-rr100.0%
Taylor expanded in x around 0
distribute-rgt-inN/A
*-lft-identityN/A
+-commutativeN/A
*-commutativeN/A
associate-*l*N/A
unpow2N/A
unpow3N/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
cube-multN/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64100.0
Simplified100.0%
Final simplification78.8%
(FPCore (x) :precision binary64 (fma (fma x (* x (fma (* x x) 0.0001984126984126984 0.008333333333333333)) 0.16666666666666666) (* x (* x x)) x))
double code(double x) {
return fma(fma(x, (x * fma((x * x), 0.0001984126984126984, 0.008333333333333333)), 0.16666666666666666), (x * (x * x)), x);
}
function code(x) return fma(fma(x, Float64(x * fma(Float64(x * x), 0.0001984126984126984, 0.008333333333333333)), 0.16666666666666666), Float64(x * Float64(x * x)), x) end
code[x_] := N[(N[(x * N[(x * N[(N[(x * x), $MachinePrecision] * 0.0001984126984126984 + 0.008333333333333333), $MachinePrecision]), $MachinePrecision] + 0.16666666666666666), $MachinePrecision] * N[(x * N[(x * x), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x \cdot x, 0.0001984126984126984, 0.008333333333333333\right), 0.16666666666666666\right), x \cdot \left(x \cdot x\right), x\right)
\end{array}
Initial program 52.7%
sinh-undefN/A
*-commutativeN/A
lower-*.f64N/A
lower-sinh.f64100.0
Applied egg-rr100.0%
lift-sinh.f64N/A
associate-/l*N/A
metadata-evalN/A
*-rgt-identity100.0
Applied egg-rr100.0%
Taylor expanded in x around 0
+-commutativeN/A
distribute-rgt-inN/A
*-commutativeN/A
associate-*l*N/A
unpow2N/A
unpow3N/A
*-lft-identityN/A
lower-fma.f64N/A
Simplified92.7%
(FPCore (x) :precision binary64 (fma (fma (* x x) 0.008333333333333333 0.16666666666666666) (* x (* x x)) x))
double code(double x) {
return fma(fma((x * x), 0.008333333333333333, 0.16666666666666666), (x * (x * x)), x);
}
function code(x) return fma(fma(Float64(x * x), 0.008333333333333333, 0.16666666666666666), Float64(x * Float64(x * x)), x) end
code[x_] := N[(N[(N[(x * x), $MachinePrecision] * 0.008333333333333333 + 0.16666666666666666), $MachinePrecision] * N[(x * N[(x * x), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.008333333333333333, 0.16666666666666666\right), x \cdot \left(x \cdot x\right), x\right)
\end{array}
Initial program 52.7%
sinh-undefN/A
*-commutativeN/A
lower-*.f64N/A
lower-sinh.f64100.0
Applied egg-rr100.0%
Taylor expanded in x around 0
distribute-rgt-inN/A
*-lft-identityN/A
+-commutativeN/A
*-commutativeN/A
associate-*l*N/A
unpow2N/A
unpow3N/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
cube-multN/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6489.0
Simplified89.0%
(FPCore (x) :precision binary64 (fma x (* x (* x 0.16666666666666666)) x))
double code(double x) {
return fma(x, (x * (x * 0.16666666666666666)), x);
}
function code(x) return fma(x, Float64(x * Float64(x * 0.16666666666666666)), x) end
code[x_] := N[(x * N[(x * N[(x * 0.16666666666666666), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, x \cdot \left(x \cdot 0.16666666666666666\right), x\right)
\end{array}
Initial program 52.7%
sinh-undefN/A
*-commutativeN/A
lower-*.f64N/A
lower-sinh.f64100.0
Applied egg-rr100.0%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64N/A
*-commutativeN/A
unpow2N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f6482.6
Simplified82.6%
(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 52.7%
Taylor expanded in x around 0
lower-*.f6453.8
Simplified53.8%
*-commutativeN/A
associate-/l*N/A
metadata-evalN/A
*-rgt-identity53.8
Applied egg-rr53.8%
herbie shell --seed 2024219
(FPCore (x)
:name "Hyperbolic sine"
:precision binary64
(/ (- (exp x) (exp (- x))) 2.0))