
(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 5 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 (log (fmod (exp x) (pow (cos x) 0.5)))))
(if (<= x -2e-310)
(/ 1.0 (pow (pow E (- (* x x) (pow t_0 2.0))) (/ 1.0 (+ x t_0))))
(/ (fmod x 1.0) (exp x)))))
double code(double x) {
double t_0 = log(fmod(exp(x), pow(cos(x), 0.5)));
double tmp;
if (x <= -2e-310) {
tmp = 1.0 / pow(pow(((double) M_E), ((x * x) - pow(t_0, 2.0))), (1.0 / (x + t_0)));
} else {
tmp = fmod(x, 1.0) / exp(x);
}
return tmp;
}
def code(x): t_0 = math.log(math.fmod(math.exp(x), math.pow(math.cos(x), 0.5))) tmp = 0 if x <= -2e-310: tmp = 1.0 / math.pow(math.pow(math.e, ((x * x) - math.pow(t_0, 2.0))), (1.0 / (x + t_0))) else: tmp = math.fmod(x, 1.0) / math.exp(x) return tmp
function code(x) t_0 = log(rem(exp(x), (cos(x) ^ 0.5))) tmp = 0.0 if (x <= -2e-310) tmp = Float64(1.0 / ((exp(1) ^ Float64(Float64(x * x) - (t_0 ^ 2.0))) ^ Float64(1.0 / Float64(x + t_0)))); else tmp = Float64(rem(x, 1.0) / exp(x)); end return tmp end
code[x_] := Block[{t$95$0 = N[Log[N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Power[N[Cos[x], $MachinePrecision], 0.5], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, -2e-310], N[(1.0 / N[Power[N[Power[E, N[(N[(x * x), $MachinePrecision] - N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(1.0 / N[(x + t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[With[{TMP1 = x, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \log \left(\left(e^{x}\right) \bmod \left({\cos x}^{0.5}\right)\right)\\
\mathbf{if}\;x \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\frac{1}{{\left({e}^{\left(x \cdot x - {t\_0}^{2}\right)}\right)}^{\left(\frac{1}{x + t\_0}\right)}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(x \bmod 1\right)}{e^{x}}\\
\end{array}
\end{array}
if x < -1.999999999999994e-310Initial program 6.2%
exp-negN/A
un-div-invN/A
clear-numN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
exp-lowering-exp.f64N/A
fmod-lowering-fmod.f64N/A
exp-lowering-exp.f64N/A
pow1/2N/A
pow-lowering-pow.f64N/A
cos-lowering-cos.f646.2%
Applied egg-rr6.2%
rem-exp-logN/A
unpow1N/A
log-powN/A
exp-prodN/A
pow-lowering-pow.f64N/A
exp-1-eN/A
E-lowering-E.f64N/A
log-divN/A
rem-log-expN/A
--lowering--.f64N/A
log-lowering-log.f64N/A
pow1/2N/A
fmod-lowering-fmod.f64N/A
exp-lowering-exp.f64N/A
pow1/2N/A
pow-lowering-pow.f64N/A
cos-lowering-cos.f646.2%
Applied egg-rr6.2%
flip--N/A
div-invN/A
pow-unpowN/A
pow-lowering-pow.f64N/A
Applied egg-rr100.0%
if -1.999999999999994e-310 < x Initial program 5.5%
Taylor expanded in x around 0
+-commutativeN/A
+-lowering-+.f6438.9%
Simplified38.9%
Taylor expanded in x around inf
Simplified98.6%
Taylor expanded in x around 0
Simplified98.6%
exp-negN/A
un-div-invN/A
/-lowering-/.f64N/A
fmod-lowering-fmod.f64N/A
exp-lowering-exp.f6498.6%
Applied egg-rr98.6%
(FPCore (x)
:precision binary64
(if (<= x -1.75e-103)
(*
(fmod
(*
(* x x)
(*
x
(+ 0.16666666666666666 (/ (+ (/ 1.0 x) (+ 0.5 (/ 1.0 (* x x)))) x))))
1.0)
(exp (- 0.0 x)))
(/ (fmod x 1.0) (exp x))))
double code(double x) {
double tmp;
if (x <= -1.75e-103) {
tmp = fmod(((x * x) * (x * (0.16666666666666666 + (((1.0 / x) + (0.5 + (1.0 / (x * x)))) / x)))), 1.0) * exp((0.0 - x));
} else {
tmp = fmod(x, 1.0) / exp(x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-1.75d-103)) then
tmp = mod(((x * x) * (x * (0.16666666666666666d0 + (((1.0d0 / x) + (0.5d0 + (1.0d0 / (x * x)))) / x)))), 1.0d0) * exp((0.0d0 - x))
else
tmp = mod(x, 1.0d0) / exp(x)
end if
code = tmp
end function
def code(x): tmp = 0 if x <= -1.75e-103: tmp = math.fmod(((x * x) * (x * (0.16666666666666666 + (((1.0 / x) + (0.5 + (1.0 / (x * x)))) / x)))), 1.0) * math.exp((0.0 - x)) else: tmp = math.fmod(x, 1.0) / math.exp(x) return tmp
function code(x) tmp = 0.0 if (x <= -1.75e-103) tmp = Float64(rem(Float64(Float64(x * x) * Float64(x * Float64(0.16666666666666666 + Float64(Float64(Float64(1.0 / x) + Float64(0.5 + Float64(1.0 / Float64(x * x)))) / x)))), 1.0) * exp(Float64(0.0 - x))); else tmp = Float64(rem(x, 1.0) / exp(x)); end return tmp end
code[x_] := If[LessEqual[x, -1.75e-103], N[(N[With[{TMP1 = N[(N[(x * x), $MachinePrecision] * N[(x * N[(0.16666666666666666 + N[(N[(N[(1.0 / x), $MachinePrecision] + N[(0.5 + N[(1.0 / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * N[Exp[N[(0.0 - x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[With[{TMP1 = x, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.75 \cdot 10^{-103}:\\
\;\;\;\;\left(\left(\left(x \cdot x\right) \cdot \left(x \cdot \left(0.16666666666666666 + \frac{\frac{1}{x} + \left(0.5 + \frac{1}{x \cdot x}\right)}{x}\right)\right)\right) \bmod 1\right) \cdot e^{0 - x}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(x \bmod 1\right)}{e^{x}}\\
\end{array}
\end{array}
if x < -1.75000000000000008e-103Initial program 11.6%
Taylor expanded in x around 0
Simplified11.6%
Taylor expanded in x around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f648.8%
Simplified8.8%
Taylor expanded in x around -inf
mul-1-negN/A
unpow3N/A
unpow2N/A
associate-*l*N/A
distribute-rgt-neg-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
Simplified17.3%
if -1.75000000000000008e-103 < x Initial program 4.9%
Taylor expanded in x around 0
+-commutativeN/A
+-lowering-+.f6429.3%
Simplified29.3%
Taylor expanded in x around inf
Simplified72.6%
Taylor expanded in x around 0
Simplified72.6%
exp-negN/A
un-div-invN/A
/-lowering-/.f64N/A
fmod-lowering-fmod.f64N/A
exp-lowering-exp.f6472.6%
Applied egg-rr72.6%
Final simplification65.3%
(FPCore (x) :precision binary64 (/ (fmod x 1.0) (exp x)))
double code(double x) {
return fmod(x, 1.0) / exp(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod(x, 1.0d0) / exp(x)
end function
def code(x): return math.fmod(x, 1.0) / math.exp(x)
function code(x) return Float64(rem(x, 1.0) / exp(x)) end
code[x_] := N[(N[With[{TMP1 = x, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(x \bmod 1\right)}{e^{x}}
\end{array}
Initial program 5.8%
Taylor expanded in x around 0
+-commutativeN/A
+-lowering-+.f6426.5%
Simplified26.5%
Taylor expanded in x around inf
Simplified63.2%
Taylor expanded in x around 0
Simplified63.2%
exp-negN/A
un-div-invN/A
/-lowering-/.f64N/A
fmod-lowering-fmod.f64N/A
exp-lowering-exp.f6463.2%
Applied egg-rr63.2%
(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 5.8%
Taylor expanded in x around 0
+-commutativeN/A
+-lowering-+.f6426.5%
Simplified26.5%
Taylor expanded in x around inf
Simplified63.2%
Taylor expanded in x around 0
Simplified63.2%
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 5.8%
Taylor expanded in x around 0
fmod-lowering-fmod.f64N/A
exp-lowering-exp.f64N/A
sqrt-lowering-sqrt.f64N/A
cos-lowering-cos.f644.8%
Simplified4.8%
Taylor expanded in x around 0
Simplified4.8%
Taylor expanded in x around 0
Simplified24.8%
herbie shell --seed 2024192
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))