
(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 (exp (- x)))
(t_1 (fmod (exp x) (sqrt (cos x))))
(t_2 (* t_0 t_1)))
(if (or (<= t_2 0.0) (not (<= t_2 2.0)))
t_0
(exp (* 3.0 (* 0.3333333333333333 (- (log t_1) x)))))))
double code(double x) {
double t_0 = exp(-x);
double t_1 = fmod(exp(x), sqrt(cos(x)));
double t_2 = t_0 * t_1;
double tmp;
if ((t_2 <= 0.0) || !(t_2 <= 2.0)) {
tmp = t_0;
} else {
tmp = exp((3.0 * (0.3333333333333333 * (log(t_1) - x))));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_0 = exp(-x)
t_1 = mod(exp(x), sqrt(cos(x)))
t_2 = t_0 * t_1
if ((t_2 <= 0.0d0) .or. (.not. (t_2 <= 2.0d0))) then
tmp = t_0
else
tmp = exp((3.0d0 * (0.3333333333333333d0 * (log(t_1) - x))))
end if
code = tmp
end function
def code(x): t_0 = math.exp(-x) t_1 = math.fmod(math.exp(x), math.sqrt(math.cos(x))) t_2 = t_0 * t_1 tmp = 0 if (t_2 <= 0.0) or not (t_2 <= 2.0): tmp = t_0 else: tmp = math.exp((3.0 * (0.3333333333333333 * (math.log(t_1) - x)))) return tmp
function code(x) t_0 = exp(Float64(-x)) t_1 = rem(exp(x), sqrt(cos(x))) t_2 = Float64(t_0 * t_1) tmp = 0.0 if ((t_2 <= 0.0) || !(t_2 <= 2.0)) tmp = t_0; else tmp = exp(Float64(3.0 * Float64(0.3333333333333333 * Float64(log(t_1) - x)))); end return tmp end
code[x_] := Block[{t$95$0 = N[Exp[(-x)], $MachinePrecision]}, Block[{t$95$1 = N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]}, Block[{t$95$2 = N[(t$95$0 * t$95$1), $MachinePrecision]}, If[Or[LessEqual[t$95$2, 0.0], N[Not[LessEqual[t$95$2, 2.0]], $MachinePrecision]], t$95$0, N[Exp[N[(3.0 * N[(0.3333333333333333 * N[(N[Log[t$95$1], $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-x}\\
t_1 := \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\\
t_2 := t_0 \cdot t_1\\
\mathbf{if}\;t_2 \leq 0 \lor \neg \left(t_2 \leq 2\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;e^{3 \cdot \left(0.3333333333333333 \cdot \left(\log t_1 - x\right)\right)}\\
\end{array}
\end{array}
if (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 0.0 or 2 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) Initial program 3.5%
exp-neg3.5%
associate-*r/3.5%
*-rgt-identity3.5%
Simplified3.5%
add-exp-log3.5%
div-exp3.5%
Applied egg-rr3.5%
Taylor expanded in x around inf 60.9%
neg-mul-160.9%
Simplified60.9%
if 0.0 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 2Initial program 85.9%
exp-neg86.2%
associate-*r/86.3%
*-rgt-identity86.3%
Simplified86.3%
add-cube-cbrt86.1%
pow386.2%
pow-to-exp86.2%
pow1/386.4%
log-pow86.6%
log-div86.6%
add-log-exp86.6%
Applied egg-rr86.6%
Final simplification62.2%
(FPCore (x)
:precision binary64
(let* ((t_0 (exp (- x)))
(t_1 (fmod (exp x) (sqrt (cos x))))
(t_2 (* t_0 t_1)))
(if (or (<= t_2 0.0) (not (<= t_2 2.0))) t_0 (exp (- (log t_1) x)))))
double code(double x) {
double t_0 = exp(-x);
double t_1 = fmod(exp(x), sqrt(cos(x)));
double t_2 = t_0 * t_1;
double tmp;
if ((t_2 <= 0.0) || !(t_2 <= 2.0)) {
tmp = t_0;
} else {
tmp = exp((log(t_1) - x));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_0 = exp(-x)
t_1 = mod(exp(x), sqrt(cos(x)))
t_2 = t_0 * t_1
if ((t_2 <= 0.0d0) .or. (.not. (t_2 <= 2.0d0))) then
tmp = t_0
else
tmp = exp((log(t_1) - x))
end if
code = tmp
end function
def code(x): t_0 = math.exp(-x) t_1 = math.fmod(math.exp(x), math.sqrt(math.cos(x))) t_2 = t_0 * t_1 tmp = 0 if (t_2 <= 0.0) or not (t_2 <= 2.0): tmp = t_0 else: tmp = math.exp((math.log(t_1) - x)) return tmp
function code(x) t_0 = exp(Float64(-x)) t_1 = rem(exp(x), sqrt(cos(x))) t_2 = Float64(t_0 * t_1) tmp = 0.0 if ((t_2 <= 0.0) || !(t_2 <= 2.0)) tmp = t_0; else tmp = exp(Float64(log(t_1) - x)); end return tmp end
code[x_] := Block[{t$95$0 = N[Exp[(-x)], $MachinePrecision]}, Block[{t$95$1 = N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]}, Block[{t$95$2 = N[(t$95$0 * t$95$1), $MachinePrecision]}, If[Or[LessEqual[t$95$2, 0.0], N[Not[LessEqual[t$95$2, 2.0]], $MachinePrecision]], t$95$0, N[Exp[N[(N[Log[t$95$1], $MachinePrecision] - x), $MachinePrecision]], $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-x}\\
t_1 := \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\\
t_2 := t_0 \cdot t_1\\
\mathbf{if}\;t_2 \leq 0 \lor \neg \left(t_2 \leq 2\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;e^{\log t_1 - x}\\
\end{array}
\end{array}
if (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 0.0 or 2 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) Initial program 3.5%
exp-neg3.5%
associate-*r/3.5%
*-rgt-identity3.5%
Simplified3.5%
add-exp-log3.5%
div-exp3.5%
Applied egg-rr3.5%
Taylor expanded in x around inf 60.9%
neg-mul-160.9%
Simplified60.9%
if 0.0 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 2Initial program 85.9%
exp-neg86.2%
associate-*r/86.3%
*-rgt-identity86.3%
Simplified86.3%
add-exp-log86.3%
div-exp86.4%
Applied egg-rr86.4%
Final simplification62.2%
(FPCore (x)
:precision binary64
(let* ((t_0 (exp (- x)))
(t_1 (fmod (exp x) (sqrt (cos x))))
(t_2 (* t_0 t_1)))
(if (or (<= t_2 0.0) (not (<= t_2 2.0))) t_0 (/ t_1 (exp x)))))
double code(double x) {
double t_0 = exp(-x);
double t_1 = fmod(exp(x), sqrt(cos(x)));
double t_2 = t_0 * t_1;
double tmp;
if ((t_2 <= 0.0) || !(t_2 <= 2.0)) {
tmp = t_0;
} else {
tmp = t_1 / exp(x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_0 = exp(-x)
t_1 = mod(exp(x), sqrt(cos(x)))
t_2 = t_0 * t_1
if ((t_2 <= 0.0d0) .or. (.not. (t_2 <= 2.0d0))) then
tmp = t_0
else
tmp = t_1 / exp(x)
end if
code = tmp
end function
def code(x): t_0 = math.exp(-x) t_1 = math.fmod(math.exp(x), math.sqrt(math.cos(x))) t_2 = t_0 * t_1 tmp = 0 if (t_2 <= 0.0) or not (t_2 <= 2.0): tmp = t_0 else: tmp = t_1 / math.exp(x) return tmp
function code(x) t_0 = exp(Float64(-x)) t_1 = rem(exp(x), sqrt(cos(x))) t_2 = Float64(t_0 * t_1) tmp = 0.0 if ((t_2 <= 0.0) || !(t_2 <= 2.0)) tmp = t_0; else tmp = Float64(t_1 / exp(x)); end return tmp end
code[x_] := Block[{t$95$0 = N[Exp[(-x)], $MachinePrecision]}, Block[{t$95$1 = N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]}, Block[{t$95$2 = N[(t$95$0 * t$95$1), $MachinePrecision]}, If[Or[LessEqual[t$95$2, 0.0], N[Not[LessEqual[t$95$2, 2.0]], $MachinePrecision]], t$95$0, N[(t$95$1 / N[Exp[x], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-x}\\
t_1 := \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\\
t_2 := t_0 \cdot t_1\\
\mathbf{if}\;t_2 \leq 0 \lor \neg \left(t_2 \leq 2\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{t_1}{e^{x}}\\
\end{array}
\end{array}
if (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 0.0 or 2 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) Initial program 3.5%
exp-neg3.5%
associate-*r/3.5%
*-rgt-identity3.5%
Simplified3.5%
add-exp-log3.5%
div-exp3.5%
Applied egg-rr3.5%
Taylor expanded in x around inf 60.9%
neg-mul-160.9%
Simplified60.9%
if 0.0 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 2Initial program 85.9%
exp-neg86.2%
associate-*r/86.3%
*-rgt-identity86.3%
Simplified86.3%
Final simplification62.2%
(FPCore (x) :precision binary64 (if (<= x 1.0) (/ (fmod (exp x) (* 3.0 (log (cbrt (exp (sqrt (cos x))))))) (exp x)) (exp (- x))))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = fmod(exp(x), (3.0 * log(cbrt(exp(sqrt(cos(x))))))) / exp(x);
} else {
tmp = exp(-x);
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 1.0) tmp = Float64(rem(exp(x), Float64(3.0 * log(cbrt(exp(sqrt(cos(x))))))) / exp(x)); else tmp = exp(Float64(-x)); end return tmp end
code[x_] := If[LessEqual[x, 1.0], N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(3.0 * N[Log[N[Power[N[Exp[N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision], N[Exp[(-x)], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left(3 \cdot \log \left(\sqrt[3]{e^{\sqrt{\cos x}}}\right)\right)\right)}{e^{x}}\\
\mathbf{else}:\\
\;\;\;\;e^{-x}\\
\end{array}
\end{array}
if x < 1Initial program 9.6%
exp-neg9.6%
associate-*r/9.6%
*-rgt-identity9.6%
Simplified9.6%
add-log-exp9.6%
add-cube-cbrt52.9%
log-prod52.9%
pow252.9%
Applied egg-rr52.9%
log-pow52.9%
distribute-lft1-in52.9%
metadata-eval52.9%
Simplified52.9%
if 1 < x Initial program 0.0%
exp-neg0.0%
associate-*r/0.0%
*-rgt-identity0.0%
Simplified0.0%
add-exp-log0.0%
div-exp0.0%
Applied egg-rr0.0%
Taylor expanded in x around inf 100.0%
neg-mul-1100.0%
Simplified100.0%
Final simplification62.1%
(FPCore (x) :precision binary64 (exp (- x)))
double code(double x) {
return exp(-x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = exp(-x)
end function
public static double code(double x) {
return Math.exp(-x);
}
def code(x): return math.exp(-x)
function code(x) return exp(Float64(-x)) end
function tmp = code(x) tmp = exp(-x); end
code[x_] := N[Exp[(-x)], $MachinePrecision]
\begin{array}{l}
\\
e^{-x}
\end{array}
Initial program 7.7%
exp-neg7.7%
associate-*r/7.7%
*-rgt-identity7.7%
Simplified7.7%
add-exp-log7.7%
div-exp7.7%
Applied egg-rr7.7%
Taylor expanded in x around inf 59.8%
neg-mul-159.8%
Simplified59.8%
Final simplification59.8%
herbie shell --seed 2023313
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))