
(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 6 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 (- 0.0 x))) (t_1 (* x (fma x x 0.0))))
(if (<= x -1.35e-108)
(*
(fmod
(exp x)
(fma
(fma x x 0.0)
(fma
x
(*
x
(fma
(* t_1 (/ t_1 (fma x t_1 0.0)))
-0.003298611111111111
-0.010416666666666666))
-0.25)
1.0))
t_0)
(* t_0 (fmod x 1.0)))))
double code(double x) {
double t_0 = exp((0.0 - x));
double t_1 = x * fma(x, x, 0.0);
double tmp;
if (x <= -1.35e-108) {
tmp = fmod(exp(x), fma(fma(x, x, 0.0), fma(x, (x * fma((t_1 * (t_1 / fma(x, t_1, 0.0))), -0.003298611111111111, -0.010416666666666666)), -0.25), 1.0)) * t_0;
} else {
tmp = t_0 * fmod(x, 1.0);
}
return tmp;
}
function code(x) t_0 = exp(Float64(0.0 - x)) t_1 = Float64(x * fma(x, x, 0.0)) tmp = 0.0 if (x <= -1.35e-108) tmp = Float64(rem(exp(x), fma(fma(x, x, 0.0), fma(x, Float64(x * fma(Float64(t_1 * Float64(t_1 / fma(x, t_1, 0.0))), -0.003298611111111111, -0.010416666666666666)), -0.25), 1.0)) * t_0); else tmp = Float64(t_0 * rem(x, 1.0)); end return tmp end
code[x_] := Block[{t$95$0 = N[Exp[N[(0.0 - x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(x * N[(x * x + 0.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.35e-108], N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(N[(x * x + 0.0), $MachinePrecision] * N[(x * N[(x * N[(N[(t$95$1 * N[(t$95$1 / N[(x * t$95$1 + 0.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * -0.003298611111111111 + -0.010416666666666666), $MachinePrecision]), $MachinePrecision] + -0.25), $MachinePrecision] + 1.0), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * t$95$0), $MachinePrecision], N[(t$95$0 * N[With[{TMP1 = x, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{0 - x}\\
t_1 := x \cdot \mathsf{fma}\left(x, x, 0\right)\\
\mathbf{if}\;x \leq -1.35 \cdot 10^{-108}:\\
\;\;\;\;\left(\left(e^{x}\right) \bmod \left(\mathsf{fma}\left(\mathsf{fma}\left(x, x, 0\right), \mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(t\_1 \cdot \frac{t\_1}{\mathsf{fma}\left(x, t\_1, 0\right)}, -0.003298611111111111, -0.010416666666666666\right), -0.25\right), 1\right)\right)\right) \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \left(x \bmod 1\right)\\
\end{array}
\end{array}
if x < -1.35000000000000002e-108Initial program 15.8%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f64N/A
+-lft-identityN/A
+-commutativeN/A
unpow2N/A
accelerator-lowering-fma.f64N/A
sub-negN/A
unpow2N/A
associate-*l*N/A
metadata-evalN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
accelerator-lowering-fma.f64N/A
+-lft-identityN/A
+-commutativeN/A
unpow2N/A
accelerator-lowering-fma.f6415.8
Simplified15.8%
flip-+N/A
metadata-evalN/A
--rgt-identityN/A
associate-*r*N/A
unpow3N/A
flip--N/A
metadata-evalN/A
--rgt-identityN/A
+-rgt-identityN/A
div-invN/A
+-rgt-identityN/A
mul0-lftN/A
+-lft-identityN/A
metadata-evalN/A
times-fracN/A
un-div-invN/A
Applied egg-rr38.4%
if -1.35000000000000002e-108 < x Initial program 6.6%
Taylor expanded in x around 0
Simplified5.6%
Taylor expanded in x around 0
+-lowering-+.f6428.5
Simplified28.5%
Taylor expanded in x around inf
Simplified71.3%
Final simplification67.4%
(FPCore (x) :precision binary64 (if (<= x -5e-310) (/ (fmod (exp x) 1.0) (exp x)) (* (exp (- 0.0 x)) (fmod x 1.0))))
double code(double x) {
double tmp;
if (x <= -5e-310) {
tmp = fmod(exp(x), 1.0) / exp(x);
} else {
tmp = exp((0.0 - x)) * fmod(x, 1.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-5d-310)) then
tmp = mod(exp(x), 1.0d0) / exp(x)
else
tmp = exp((0.0d0 - x)) * mod(x, 1.0d0)
end if
code = tmp
end function
def code(x): tmp = 0 if x <= -5e-310: tmp = math.fmod(math.exp(x), 1.0) / math.exp(x) else: tmp = math.exp((0.0 - x)) * math.fmod(x, 1.0) return tmp
function code(x) tmp = 0.0 if (x <= -5e-310) tmp = Float64(rem(exp(x), 1.0) / exp(x)); else tmp = Float64(exp(Float64(0.0 - x)) * rem(x, 1.0)); end return tmp end
code[x_] := If[LessEqual[x, -5e-310], N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision], N[(N[Exp[N[(0.0 - x), $MachinePrecision]], $MachinePrecision] * N[With[{TMP1 = x, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{\left(\left(e^{x}\right) \bmod 1\right)}{e^{x}}\\
\mathbf{else}:\\
\;\;\;\;e^{0 - x} \cdot \left(x \bmod 1\right)\\
\end{array}
\end{array}
if x < -4.999999999999985e-310Initial program 7.3%
Taylor expanded in x around 0
Simplified7.3%
exp-negN/A
un-div-invN/A
/-lowering-/.f64N/A
fmod-lowering-fmod.f64N/A
exp-lowering-exp.f64N/A
exp-lowering-exp.f647.3
Applied egg-rr7.3%
if -4.999999999999985e-310 < x Initial program 7.9%
Taylor expanded in x around 0
Simplified6.5%
Taylor expanded in x around 0
+-lowering-+.f6438.1
Simplified38.1%
Taylor expanded in x around inf
Simplified97.3%
Final simplification64.9%
(FPCore (x) :precision binary64 (let* ((t_0 (exp (- 0.0 x)))) (if (<= x -5e-310) (* t_0 (fmod (exp x) 1.0)) (* t_0 (fmod x 1.0)))))
double code(double x) {
double t_0 = exp((0.0 - x));
double tmp;
if (x <= -5e-310) {
tmp = t_0 * fmod(exp(x), 1.0);
} else {
tmp = t_0 * fmod(x, 1.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = exp((0.0d0 - x))
if (x <= (-5d-310)) then
tmp = t_0 * mod(exp(x), 1.0d0)
else
tmp = t_0 * mod(x, 1.0d0)
end if
code = tmp
end function
def code(x): t_0 = math.exp((0.0 - x)) tmp = 0 if x <= -5e-310: tmp = t_0 * math.fmod(math.exp(x), 1.0) else: tmp = t_0 * math.fmod(x, 1.0) return tmp
function code(x) t_0 = exp(Float64(0.0 - x)) tmp = 0.0 if (x <= -5e-310) tmp = Float64(t_0 * rem(exp(x), 1.0)); else tmp = Float64(t_0 * rem(x, 1.0)); end return tmp end
code[x_] := Block[{t$95$0 = N[Exp[N[(0.0 - x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, -5e-310], N[(t$95$0 * N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[With[{TMP1 = x, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{0 - x}\\
\mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\
\;\;\;\;t\_0 \cdot \left(\left(e^{x}\right) \bmod 1\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \left(x \bmod 1\right)\\
\end{array}
\end{array}
if x < -4.999999999999985e-310Initial program 7.3%
Taylor expanded in x around 0
Simplified7.3%
if -4.999999999999985e-310 < x Initial program 7.9%
Taylor expanded in x around 0
Simplified6.5%
Taylor expanded in x around 0
+-lowering-+.f6438.1
Simplified38.1%
Taylor expanded in x around inf
Simplified97.3%
Final simplification64.9%
(FPCore (x) :precision binary64 (* (exp (- 0.0 x)) (fmod x 1.0)))
double code(double x) {
return exp((0.0 - x)) * fmod(x, 1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = exp((0.0d0 - x)) * mod(x, 1.0d0)
end function
def code(x): return math.exp((0.0 - x)) * math.fmod(x, 1.0)
function code(x) return Float64(exp(Float64(0.0 - x)) * rem(x, 1.0)) end
code[x_] := N[(N[Exp[N[(0.0 - x), $MachinePrecision]], $MachinePrecision] * N[With[{TMP1 = x, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
e^{0 - x} \cdot \left(x \bmod 1\right)
\end{array}
Initial program 7.6%
Taylor expanded in x around 0
Simplified6.8%
Taylor expanded in x around 0
+-lowering-+.f6426.6
Simplified26.6%
Taylor expanded in x around inf
Simplified63.1%
Final simplification63.1%
(FPCore (x) :precision binary64 (fmod x 1.0))
double code(double x) {
return fmod(x, 1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod(x, 1.0d0)
end function
def code(x): return math.fmod(x, 1.0)
function code(x) return rem(x, 1.0) end
code[x_] := N[With[{TMP1 = x, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]
\begin{array}{l}
\\
\left(x \bmod 1\right)
\end{array}
Initial program 7.6%
Taylor expanded in x around 0
Simplified6.8%
Taylor expanded in x around 0
+-lowering-+.f6426.6
Simplified26.6%
Taylor expanded in x around inf
Simplified63.1%
Taylor expanded in x around 0
fmod-lowering-fmod.f6462.1
Simplified62.1%
(FPCore (x) :precision binary64 (fmod 1.0 1.0))
double code(double x) {
return fmod(1.0, 1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod(1.0d0, 1.0d0)
end function
def code(x): return math.fmod(1.0, 1.0)
function code(x) return rem(1.0, 1.0) end
code[x_] := N[With[{TMP1 = 1.0, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]
\begin{array}{l}
\\
\left(1 \bmod 1\right)
\end{array}
Initial program 7.6%
Taylor expanded in x around 0
Simplified6.8%
Taylor expanded in x around 0
fmod-lowering-fmod.f64N/A
exp-lowering-exp.f645.9
Simplified5.9%
Taylor expanded in x around 0
Simplified24.0%
herbie shell --seed 2024195
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))