
(FPCore (x) :precision binary64 :pre TRUE (/ (- (exp x) (exp (- x))) 2.0))
double code(double x) {
return (exp(x) - exp(-x)) / 2.0;
}
real(8) function code(x)
use fmin_fmax_functions
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]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = ((exp(x)) - (exp((- x)))) / (2) END code
\frac{e^{x} - e^{-x}}{2}
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 :pre TRUE (/ (- (exp x) (exp (- x))) 2.0))
double code(double x) {
return (exp(x) - exp(-x)) / 2.0;
}
real(8) function code(x)
use fmin_fmax_functions
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]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = ((exp(x)) - (exp((- x)))) / (2) END code
\frac{e^{x} - e^{-x}}{2}
(FPCore (x) :precision binary64 :pre TRUE (sinh x))
double code(double x) {
return sinh(x);
}
real(8) function code(x)
use fmin_fmax_functions
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]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = ((1) / (2)) * ((exp(x)) + ((- (1)) / (exp(x)))) END code
\sinh x
Initial program 53.6%
Applied rewrites100.0%
(FPCore (x) :precision binary64 :pre TRUE (* (copysign 1.0 x) (* 1.0 (expm1 (fabs x)))))
double code(double x) {
return copysign(1.0, x) * (1.0 * expm1(fabs(x)));
}
public static double code(double x) {
return Math.copySign(1.0, x) * (1.0 * Math.expm1(Math.abs(x)));
}
def code(x): return math.copysign(1.0, x) * (1.0 * math.expm1(math.fabs(x)))
function code(x) return Float64(copysign(1.0, x) * Float64(1.0 * expm1(abs(x)))) end
code[x_] := N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(1.0 * N[(Exp[N[Abs[x], $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\mathsf{copysign}\left(1, x\right) \cdot \left(1 \cdot \mathsf{expm1}\left(\left|x\right|\right)\right)
Initial program 53.6%
Applied rewrites75.3%
Taylor expanded in x around 0
Applied rewrites87.6%
Taylor expanded in x around 0
Applied rewrites75.1%
(FPCore (x) :precision binary64 :pre TRUE (/ (+ x x) 2.0))
double code(double x) {
return (x + x) / 2.0;
}
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
code = (x + x) / 2.0d0
end function
public static double code(double x) {
return (x + x) / 2.0;
}
def code(x): return (x + x) / 2.0
function code(x) return Float64(Float64(x + x) / 2.0) end
function tmp = code(x) tmp = (x + x) / 2.0; end
code[x_] := N[(N[(x + x), $MachinePrecision] / 2.0), $MachinePrecision]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = (x + x) / (2) END code
\frac{x + x}{2}
Initial program 53.6%
Taylor expanded in x around 0
Applied rewrites52.8%
Applied rewrites52.8%
(FPCore (x) :precision binary64 :pre TRUE (* 1.0 0.0))
double code(double x) {
return 1.0 * 0.0;
}
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
code = 1.0d0 * 0.0d0
end function
public static double code(double x) {
return 1.0 * 0.0;
}
def code(x): return 1.0 * 0.0
function code(x) return Float64(1.0 * 0.0) end
function tmp = code(x) tmp = 1.0 * 0.0; end
code[x_] := N[(1.0 * 0.0), $MachinePrecision]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = (1) * (0) END code
1 \cdot 0
Initial program 53.6%
Applied rewrites75.3%
Taylor expanded in x around 0
Applied rewrites87.6%
Taylor expanded in x around 0
Applied rewrites75.1%
Applied rewrites3.5%
herbie shell --seed 2026074 +o generate:egglog
(FPCore (x)
:name "Hyperbolic sine"
:precision binary64
(/ (- (exp x) (exp (- x))) 2.0))