
(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 (fmod (exp x) (sqrt (cos x))))
(t_1 (exp (- x)))
(t_2 (* t_0 t_1)))
(if (or (<= t_2 0.0) (not (<= t_2 2.0)))
t_1
(exp (- (log (log (exp t_0))) x)))))
double code(double x) {
double t_0 = fmod(exp(x), sqrt(cos(x)));
double t_1 = exp(-x);
double t_2 = t_0 * t_1;
double tmp;
if ((t_2 <= 0.0) || !(t_2 <= 2.0)) {
tmp = t_1;
} else {
tmp = exp((log(log(exp(t_0))) - 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 = mod(exp(x), sqrt(cos(x)))
t_1 = exp(-x)
t_2 = t_0 * t_1
if ((t_2 <= 0.0d0) .or. (.not. (t_2 <= 2.0d0))) then
tmp = t_1
else
tmp = exp((log(log(exp(t_0))) - x))
end if
code = tmp
end function
def code(x): t_0 = math.fmod(math.exp(x), math.sqrt(math.cos(x))) t_1 = math.exp(-x) t_2 = t_0 * t_1 tmp = 0 if (t_2 <= 0.0) or not (t_2 <= 2.0): tmp = t_1 else: tmp = math.exp((math.log(math.log(math.exp(t_0))) - x)) return tmp
function code(x) t_0 = rem(exp(x), sqrt(cos(x))) t_1 = exp(Float64(-x)) t_2 = Float64(t_0 * t_1) tmp = 0.0 if ((t_2 <= 0.0) || !(t_2 <= 2.0)) tmp = t_1; else tmp = exp(Float64(log(log(exp(t_0))) - x)); end return tmp end
code[x_] := Block[{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]}, Block[{t$95$1 = N[Exp[(-x)], $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$1, N[Exp[N[(N[Log[N[Log[N[Exp[t$95$0], $MachinePrecision]], $MachinePrecision]], $MachinePrecision] - x), $MachinePrecision]], $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\\
t_1 := e^{-x}\\
t_2 := t_0 \cdot t_1\\
\mathbf{if}\;t_2 \leq 0 \lor \neg \left(t_2 \leq 2\right):\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;e^{\log \log \left(e^{t_0}\right) - 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%
/-rgt-identity3.5%
associate-/r/3.5%
exp-neg3.5%
remove-double-neg3.5%
Simplified3.5%
add-exp-log3.5%
div-exp3.5%
Applied egg-rr3.5%
Taylor expanded in x around inf 66.1%
neg-mul-166.1%
Simplified66.1%
if 0.0 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 2Initial program 85.4%
/-rgt-identity85.4%
associate-/r/84.9%
exp-neg85.7%
remove-double-neg85.7%
Simplified85.7%
add-exp-log85.7%
div-exp85.7%
Applied egg-rr85.7%
add-log-exp86.2%
Applied egg-rr86.2%
Final simplification66.8%
(FPCore (x)
:precision binary64
(let* ((t_0 (fmod (exp x) (sqrt (cos x))))
(t_1 (exp (- x)))
(t_2 (* t_0 t_1)))
(if (or (<= t_2 0.0) (not (<= t_2 2.0))) t_1 (exp (log (/ t_0 (exp x)))))))
double code(double x) {
double t_0 = fmod(exp(x), sqrt(cos(x)));
double t_1 = exp(-x);
double t_2 = t_0 * t_1;
double tmp;
if ((t_2 <= 0.0) || !(t_2 <= 2.0)) {
tmp = t_1;
} else {
tmp = exp(log((t_0 / 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 = mod(exp(x), sqrt(cos(x)))
t_1 = exp(-x)
t_2 = t_0 * t_1
if ((t_2 <= 0.0d0) .or. (.not. (t_2 <= 2.0d0))) then
tmp = t_1
else
tmp = exp(log((t_0 / exp(x))))
end if
code = tmp
end function
def code(x): t_0 = math.fmod(math.exp(x), math.sqrt(math.cos(x))) t_1 = math.exp(-x) t_2 = t_0 * t_1 tmp = 0 if (t_2 <= 0.0) or not (t_2 <= 2.0): tmp = t_1 else: tmp = math.exp(math.log((t_0 / math.exp(x)))) return tmp
function code(x) t_0 = rem(exp(x), sqrt(cos(x))) t_1 = exp(Float64(-x)) t_2 = Float64(t_0 * t_1) tmp = 0.0 if ((t_2 <= 0.0) || !(t_2 <= 2.0)) tmp = t_1; else tmp = exp(log(Float64(t_0 / exp(x)))); end return tmp end
code[x_] := Block[{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]}, Block[{t$95$1 = N[Exp[(-x)], $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$1, N[Exp[N[Log[N[(t$95$0 / N[Exp[x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\\
t_1 := e^{-x}\\
t_2 := t_0 \cdot t_1\\
\mathbf{if}\;t_2 \leq 0 \lor \neg \left(t_2 \leq 2\right):\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;e^{\log \left(\frac{t_0}{e^{x}}\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%
/-rgt-identity3.5%
associate-/r/3.5%
exp-neg3.5%
remove-double-neg3.5%
Simplified3.5%
add-exp-log3.5%
div-exp3.5%
Applied egg-rr3.5%
Taylor expanded in x around inf 66.1%
neg-mul-166.1%
Simplified66.1%
if 0.0 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 2Initial program 85.4%
/-rgt-identity85.4%
associate-/r/84.9%
exp-neg85.7%
remove-double-neg85.7%
Simplified85.7%
add-exp-log85.7%
div-exp85.7%
Applied egg-rr85.7%
add-log-exp85.7%
diff-log85.7%
Applied egg-rr85.7%
Final simplification66.8%
(FPCore (x)
:precision binary64
(let* ((t_0 (fmod (exp x) (sqrt (cos x))))
(t_1 (exp (- x)))
(t_2 (* t_0 t_1)))
(if (or (<= t_2 0.0) (not (<= t_2 2.0))) t_1 (/ (log (exp t_0)) (exp x)))))
double code(double x) {
double t_0 = fmod(exp(x), sqrt(cos(x)));
double t_1 = exp(-x);
double t_2 = t_0 * t_1;
double tmp;
if ((t_2 <= 0.0) || !(t_2 <= 2.0)) {
tmp = t_1;
} else {
tmp = log(exp(t_0)) / 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 = mod(exp(x), sqrt(cos(x)))
t_1 = exp(-x)
t_2 = t_0 * t_1
if ((t_2 <= 0.0d0) .or. (.not. (t_2 <= 2.0d0))) then
tmp = t_1
else
tmp = log(exp(t_0)) / exp(x)
end if
code = tmp
end function
def code(x): t_0 = math.fmod(math.exp(x), math.sqrt(math.cos(x))) t_1 = math.exp(-x) t_2 = t_0 * t_1 tmp = 0 if (t_2 <= 0.0) or not (t_2 <= 2.0): tmp = t_1 else: tmp = math.log(math.exp(t_0)) / math.exp(x) return tmp
function code(x) t_0 = rem(exp(x), sqrt(cos(x))) t_1 = exp(Float64(-x)) t_2 = Float64(t_0 * t_1) tmp = 0.0 if ((t_2 <= 0.0) || !(t_2 <= 2.0)) tmp = t_1; else tmp = Float64(log(exp(t_0)) / exp(x)); end return tmp end
code[x_] := Block[{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]}, Block[{t$95$1 = N[Exp[(-x)], $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$1, N[(N[Log[N[Exp[t$95$0], $MachinePrecision]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\\
t_1 := e^{-x}\\
t_2 := t_0 \cdot t_1\\
\mathbf{if}\;t_2 \leq 0 \lor \neg \left(t_2 \leq 2\right):\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\frac{\log \left(e^{t_0}\right)}{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%
/-rgt-identity3.5%
associate-/r/3.5%
exp-neg3.5%
remove-double-neg3.5%
Simplified3.5%
add-exp-log3.5%
div-exp3.5%
Applied egg-rr3.5%
Taylor expanded in x around inf 66.1%
neg-mul-166.1%
Simplified66.1%
if 0.0 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 2Initial program 85.4%
/-rgt-identity85.4%
associate-/r/84.9%
exp-neg85.7%
remove-double-neg85.7%
Simplified85.7%
add-log-exp86.2%
Applied egg-rr86.2%
Final simplification66.8%
(FPCore (x)
:precision binary64
(let* ((t_0 (fmod (exp x) (sqrt (cos x))))
(t_1 (exp (- x)))
(t_2 (* t_0 t_1)))
(if (or (<= t_2 0.0) (not (<= t_2 2.0))) t_1 (/ 1.0 (/ (exp x) t_0)))))
double code(double x) {
double t_0 = fmod(exp(x), sqrt(cos(x)));
double t_1 = exp(-x);
double t_2 = t_0 * t_1;
double tmp;
if ((t_2 <= 0.0) || !(t_2 <= 2.0)) {
tmp = t_1;
} else {
tmp = 1.0 / (exp(x) / t_0);
}
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 = mod(exp(x), sqrt(cos(x)))
t_1 = exp(-x)
t_2 = t_0 * t_1
if ((t_2 <= 0.0d0) .or. (.not. (t_2 <= 2.0d0))) then
tmp = t_1
else
tmp = 1.0d0 / (exp(x) / t_0)
end if
code = tmp
end function
def code(x): t_0 = math.fmod(math.exp(x), math.sqrt(math.cos(x))) t_1 = math.exp(-x) t_2 = t_0 * t_1 tmp = 0 if (t_2 <= 0.0) or not (t_2 <= 2.0): tmp = t_1 else: tmp = 1.0 / (math.exp(x) / t_0) return tmp
function code(x) t_0 = rem(exp(x), sqrt(cos(x))) t_1 = exp(Float64(-x)) t_2 = Float64(t_0 * t_1) tmp = 0.0 if ((t_2 <= 0.0) || !(t_2 <= 2.0)) tmp = t_1; else tmp = Float64(1.0 / Float64(exp(x) / t_0)); end return tmp end
code[x_] := Block[{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]}, Block[{t$95$1 = N[Exp[(-x)], $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$1, N[(1.0 / N[(N[Exp[x], $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\\
t_1 := e^{-x}\\
t_2 := t_0 \cdot t_1\\
\mathbf{if}\;t_2 \leq 0 \lor \neg \left(t_2 \leq 2\right):\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{e^{x}}{t_0}}\\
\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%
/-rgt-identity3.5%
associate-/r/3.5%
exp-neg3.5%
remove-double-neg3.5%
Simplified3.5%
add-exp-log3.5%
div-exp3.5%
Applied egg-rr3.5%
Taylor expanded in x around inf 66.1%
neg-mul-166.1%
Simplified66.1%
if 0.0 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 2Initial program 85.4%
/-rgt-identity85.4%
associate-/r/84.9%
exp-neg85.7%
remove-double-neg85.7%
Simplified85.7%
frac-2neg85.7%
div-inv85.5%
Applied egg-rr85.5%
un-div-inv85.7%
frac-2neg85.7%
clear-num85.7%
Applied egg-rr85.7%
Final simplification66.8%
(FPCore (x)
:precision binary64
(let* ((t_0 (fmod (exp x) (sqrt (cos x))))
(t_1 (exp (- x)))
(t_2 (* t_0 t_1)))
(if (or (<= t_2 0.0) (not (<= t_2 2.0))) t_1 (/ t_0 (exp x)))))
double code(double x) {
double t_0 = fmod(exp(x), sqrt(cos(x)));
double t_1 = exp(-x);
double t_2 = t_0 * t_1;
double tmp;
if ((t_2 <= 0.0) || !(t_2 <= 2.0)) {
tmp = t_1;
} else {
tmp = t_0 / 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 = mod(exp(x), sqrt(cos(x)))
t_1 = exp(-x)
t_2 = t_0 * t_1
if ((t_2 <= 0.0d0) .or. (.not. (t_2 <= 2.0d0))) then
tmp = t_1
else
tmp = t_0 / exp(x)
end if
code = tmp
end function
def code(x): t_0 = math.fmod(math.exp(x), math.sqrt(math.cos(x))) t_1 = math.exp(-x) t_2 = t_0 * t_1 tmp = 0 if (t_2 <= 0.0) or not (t_2 <= 2.0): tmp = t_1 else: tmp = t_0 / math.exp(x) return tmp
function code(x) t_0 = rem(exp(x), sqrt(cos(x))) t_1 = exp(Float64(-x)) t_2 = Float64(t_0 * t_1) tmp = 0.0 if ((t_2 <= 0.0) || !(t_2 <= 2.0)) tmp = t_1; else tmp = Float64(t_0 / exp(x)); end return tmp end
code[x_] := Block[{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]}, Block[{t$95$1 = N[Exp[(-x)], $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$1, N[(t$95$0 / N[Exp[x], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\\
t_1 := e^{-x}\\
t_2 := t_0 \cdot t_1\\
\mathbf{if}\;t_2 \leq 0 \lor \neg \left(t_2 \leq 2\right):\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\frac{t_0}{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%
/-rgt-identity3.5%
associate-/r/3.5%
exp-neg3.5%
remove-double-neg3.5%
Simplified3.5%
add-exp-log3.5%
div-exp3.5%
Applied egg-rr3.5%
Taylor expanded in x around inf 66.1%
neg-mul-166.1%
Simplified66.1%
if 0.0 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 2Initial program 85.4%
/-rgt-identity85.4%
associate-/r/84.9%
exp-neg85.7%
remove-double-neg85.7%
Simplified85.7%
Final simplification66.8%
(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 6.4%
/-rgt-identity6.4%
associate-/r/6.4%
exp-neg6.4%
remove-double-neg6.4%
Simplified6.4%
add-exp-log6.4%
div-exp6.4%
Applied egg-rr6.4%
Taylor expanded in x around inf 64.7%
neg-mul-164.7%
Simplified64.7%
Final simplification64.7%
herbie shell --seed 2024010
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))