
(FPCore (x) :precision binary64 (* (fmod (exp x) (sqrt (cos x))) (exp (- x))))
double code(double x) {
return fmod(exp(x), sqrt(cos(x))) * exp(-x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod(exp(x), sqrt(cos(x))) * exp(-x)
end function
def code(x): return math.fmod(math.exp(x), math.sqrt(math.cos(x))) * math.exp(-x)
function code(x) return Float64(rem(exp(x), sqrt(cos(x))) * exp(Float64(-x))) end
code[x_] := N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 13 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (* (fmod (exp x) (sqrt (cos x))) (exp (- x))))
double code(double x) {
return fmod(exp(x), sqrt(cos(x))) * exp(-x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod(exp(x), sqrt(cos(x))) * exp(-x)
end function
def code(x): return math.fmod(math.exp(x), math.sqrt(math.cos(x))) * math.exp(-x)
function code(x) return Float64(rem(exp(x), sqrt(cos(x))) * exp(Float64(-x))) end
code[x_] := N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x}
\end{array}
(FPCore (x)
:precision binary64
(let* ((t_0 (exp (- x))))
(if (<= x -5e-72)
(*
(fmod
(*
(* x (* x x))
(+
0.16666666666666666
(+
(/ (/ (/ 1.0 (* x x)) (- (/ 1.0 x) (fma x 0.5 1.0))) (* x x))
(/
(/
(* (fma x 0.5 1.0) (fma x 0.5 1.0))
(+ (fma x 0.5 1.0) (/ -1.0 x)))
(* x x)))))
1.0)
t_0)
(if (<= x -1.55e-162)
(*
t_0
(fmod
(fma
(/ (* x x) x)
(/ x (/ x (+ 1.0 (fma x 0.5 (/ 1.0 x)))))
(* x (* 0.16666666666666666 (* x x))))
1.0))
(if (<= x 0.6)
(* t_0 (fmod (fma x (* x 0.5) x) 1.0))
(* t_0 (fmod (+ x 1.0) (sqrt (cos x)))))))))
double code(double x) {
double t_0 = exp(-x);
double tmp;
if (x <= -5e-72) {
tmp = fmod(((x * (x * x)) * (0.16666666666666666 + ((((1.0 / (x * x)) / ((1.0 / x) - fma(x, 0.5, 1.0))) / (x * x)) + (((fma(x, 0.5, 1.0) * fma(x, 0.5, 1.0)) / (fma(x, 0.5, 1.0) + (-1.0 / x))) / (x * x))))), 1.0) * t_0;
} else if (x <= -1.55e-162) {
tmp = t_0 * fmod(fma(((x * x) / x), (x / (x / (1.0 + fma(x, 0.5, (1.0 / x))))), (x * (0.16666666666666666 * (x * x)))), 1.0);
} else if (x <= 0.6) {
tmp = t_0 * fmod(fma(x, (x * 0.5), x), 1.0);
} else {
tmp = t_0 * fmod((x + 1.0), sqrt(cos(x)));
}
return tmp;
}
function code(x) t_0 = exp(Float64(-x)) tmp = 0.0 if (x <= -5e-72) tmp = Float64(rem(Float64(Float64(x * Float64(x * x)) * Float64(0.16666666666666666 + Float64(Float64(Float64(Float64(1.0 / Float64(x * x)) / Float64(Float64(1.0 / x) - fma(x, 0.5, 1.0))) / Float64(x * x)) + Float64(Float64(Float64(fma(x, 0.5, 1.0) * fma(x, 0.5, 1.0)) / Float64(fma(x, 0.5, 1.0) + Float64(-1.0 / x))) / Float64(x * x))))), 1.0) * t_0); elseif (x <= -1.55e-162) tmp = Float64(t_0 * rem(fma(Float64(Float64(x * x) / x), Float64(x / Float64(x / Float64(1.0 + fma(x, 0.5, Float64(1.0 / x))))), Float64(x * Float64(0.16666666666666666 * Float64(x * x)))), 1.0)); elseif (x <= 0.6) tmp = Float64(t_0 * rem(fma(x, Float64(x * 0.5), x), 1.0)); else tmp = Float64(t_0 * rem(Float64(x + 1.0), sqrt(cos(x)))); end return tmp end
code[x_] := Block[{t$95$0 = N[Exp[(-x)], $MachinePrecision]}, If[LessEqual[x, -5e-72], N[(N[With[{TMP1 = N[(N[(x * N[(x * x), $MachinePrecision]), $MachinePrecision] * N[(0.16666666666666666 + N[(N[(N[(N[(1.0 / N[(x * x), $MachinePrecision]), $MachinePrecision] / N[(N[(1.0 / x), $MachinePrecision] - N[(x * 0.5 + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(N[(x * 0.5 + 1.0), $MachinePrecision] * N[(x * 0.5 + 1.0), $MachinePrecision]), $MachinePrecision] / N[(N[(x * 0.5 + 1.0), $MachinePrecision] + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * t$95$0), $MachinePrecision], If[LessEqual[x, -1.55e-162], N[(t$95$0 * N[With[{TMP1 = N[(N[(N[(x * x), $MachinePrecision] / x), $MachinePrecision] * N[(x / N[(x / N[(1.0 + N[(x * 0.5 + N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(x * N[(0.16666666666666666 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 0.6], N[(t$95$0 * N[With[{TMP1 = N[(x * N[(x * 0.5), $MachinePrecision] + x), $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[With[{TMP1 = N[(x + 1.0), $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-x}\\
\mathbf{if}\;x \leq -5 \cdot 10^{-72}:\\
\;\;\;\;\left(\left(\left(x \cdot \left(x \cdot x\right)\right) \cdot \left(0.16666666666666666 + \left(\frac{\frac{\frac{1}{x \cdot x}}{\frac{1}{x} - \mathsf{fma}\left(x, 0.5, 1\right)}}{x \cdot x} + \frac{\frac{\mathsf{fma}\left(x, 0.5, 1\right) \cdot \mathsf{fma}\left(x, 0.5, 1\right)}{\mathsf{fma}\left(x, 0.5, 1\right) + \frac{-1}{x}}}{x \cdot x}\right)\right)\right) \bmod 1\right) \cdot t\_0\\
\mathbf{elif}\;x \leq -1.55 \cdot 10^{-162}:\\
\;\;\;\;t\_0 \cdot \left(\left(\mathsf{fma}\left(\frac{x \cdot x}{x}, \frac{x}{\frac{x}{1 + \mathsf{fma}\left(x, 0.5, \frac{1}{x}\right)}}, x \cdot \left(0.16666666666666666 \cdot \left(x \cdot x\right)\right)\right)\right) \bmod 1\right)\\
\mathbf{elif}\;x \leq 0.6:\\
\;\;\;\;t\_0 \cdot \left(\left(\mathsf{fma}\left(x, x \cdot 0.5, x\right)\right) \bmod 1\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \left(\left(x + 1\right) \bmod \left(\sqrt{\cos x}\right)\right)\\
\end{array}
\end{array}
if x < -4.9999999999999996e-72Initial program 20.3%
Taylor expanded in x around 0
Applied rewrites20.3%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6412.9
Applied rewrites12.9%
Taylor expanded in x around -inf
Applied rewrites27.5%
Applied rewrites57.0%
if -4.9999999999999996e-72 < x < -1.5499999999999999e-162Initial program 3.1%
Taylor expanded in x around 0
Applied rewrites3.1%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f643.1
Applied rewrites3.1%
Taylor expanded in x around -inf
Applied rewrites7.8%
Applied rewrites31.5%
if -1.5499999999999999e-162 < x < 0.599999999999999978Initial program 5.2%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f645.2
Applied rewrites5.2%
Taylor expanded in x around inf
Applied rewrites62.9%
Taylor expanded in x around 0
Applied rewrites62.9%
if 0.599999999999999978 < x Initial program 2.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f6496.8
Applied rewrites96.8%
Final simplification65.7%
(FPCore (x)
:precision binary64
(let* ((t_0 (exp (- x))))
(if (<= (* t_0 (fmod (exp x) (sqrt (cos x)))) 0.001)
(* t_0 (fmod (fma x (* x 0.5) x) 1.0))
(/ (fmod (+ x 1.0) 1.0) (exp x)))))
double code(double x) {
double t_0 = exp(-x);
double tmp;
if ((t_0 * fmod(exp(x), sqrt(cos(x)))) <= 0.001) {
tmp = t_0 * fmod(fma(x, (x * 0.5), x), 1.0);
} else {
tmp = fmod((x + 1.0), 1.0) / exp(x);
}
return tmp;
}
function code(x) t_0 = exp(Float64(-x)) tmp = 0.0 if (Float64(t_0 * rem(exp(x), sqrt(cos(x)))) <= 0.001) tmp = Float64(t_0 * rem(fma(x, Float64(x * 0.5), x), 1.0)); else tmp = Float64(rem(Float64(x + 1.0), 1.0) / exp(x)); end return tmp end
code[x_] := Block[{t$95$0 = N[Exp[(-x)], $MachinePrecision]}, If[LessEqual[N[(t$95$0 * N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision], 0.001], N[(t$95$0 * N[With[{TMP1 = N[(x * N[(x * 0.5), $MachinePrecision] + x), $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision], N[(N[With[{TMP1 = N[(x + 1.0), $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-x}\\
\mathbf{if}\;t\_0 \cdot \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \leq 0.001:\\
\;\;\;\;t\_0 \cdot \left(\left(\mathsf{fma}\left(x, x \cdot 0.5, x\right)\right) \bmod 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\left(x + 1\right) \bmod 1\right)}{e^{x}}\\
\end{array}
\end{array}
if (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 1e-3Initial program 5.6%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f645.5
Applied rewrites5.5%
Taylor expanded in x around inf
Applied rewrites50.6%
Taylor expanded in x around 0
Applied rewrites50.6%
if 1e-3 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) Initial program 12.5%
Taylor expanded in x around 0
Applied rewrites11.1%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f6494.1
Applied rewrites94.1%
lift-*.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
exp-negN/A
un-div-invN/A
lower-/.f64N/A
lift-exp.f6494.2
Applied rewrites94.2%
Final simplification60.4%
herbie shell --seed 2024230
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))