
(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 12 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 (log1p (expm1 (- (log 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(log1p(expm1((log(t_0) - x))));
}
return tmp;
}
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.log1p(math.expm1((math.log(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(log1p(expm1(Float64(log(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[Log[1 + N[(Exp[N[(N[Log[t$95$0], $MachinePrecision] - x), $MachinePrecision]] - 1), $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^{\mathsf{log1p}\left(\mathsf{expm1}\left(\log t\_0 - 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 0.2%
/-rgt-identity0.2%
associate-/r/0.2%
exp-neg0.2%
remove-double-neg0.2%
Simplified0.2%
add-exp-log0.2%
div-exp0.2%
Applied egg-rr0.2%
Taylor expanded in x around inf 99.6%
neg-mul-199.6%
Simplified99.6%
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/85.3%
exp-neg85.5%
remove-double-neg85.5%
Simplified85.5%
add-exp-log85.5%
div-exp85.5%
Applied egg-rr85.5%
log1p-expm1-u86.0%
Applied egg-rr86.0%
Final simplification97.6%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (cos x))) (t_1 (cbrt (exp t_0))) (t_2 (exp (- x))))
(if (<= (* (fmod (exp x) t_0) t_2) 2.0)
(/ (fmod (exp x) (+ (log (pow t_1 2.0)) (log t_1))) (exp x))
t_2)))
double code(double x) {
double t_0 = sqrt(cos(x));
double t_1 = cbrt(exp(t_0));
double t_2 = exp(-x);
double tmp;
if ((fmod(exp(x), t_0) * t_2) <= 2.0) {
tmp = fmod(exp(x), (log(pow(t_1, 2.0)) + log(t_1))) / exp(x);
} else {
tmp = t_2;
}
return tmp;
}
function code(x) t_0 = sqrt(cos(x)) t_1 = cbrt(exp(t_0)) t_2 = exp(Float64(-x)) tmp = 0.0 if (Float64(rem(exp(x), t_0) * t_2) <= 2.0) tmp = Float64(rem(exp(x), Float64(log((t_1 ^ 2.0)) + log(t_1))) / exp(x)); else tmp = t_2; end return tmp end
code[x_] := Block[{t$95$0 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Power[N[Exp[t$95$0], $MachinePrecision], 1/3], $MachinePrecision]}, Block[{t$95$2 = N[Exp[(-x)], $MachinePrecision]}, If[LessEqual[N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = t$95$0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * t$95$2), $MachinePrecision], 2.0], N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(N[Log[N[Power[t$95$1, 2.0], $MachinePrecision]], $MachinePrecision] + N[Log[t$95$1], $MachinePrecision]), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision], t$95$2]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\cos x}\\
t_1 := \sqrt[3]{e^{t\_0}}\\
t_2 := e^{-x}\\
\mathbf{if}\;\left(\left(e^{x}\right) \bmod t\_0\right) \cdot t\_2 \leq 2:\\
\;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left(\log \left({t\_1}^{2}\right) + \log t\_1\right)\right)}{e^{x}}\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 2Initial program 65.3%
/-rgt-identity65.3%
associate-/r/65.2%
exp-neg65.3%
remove-double-neg65.3%
Simplified65.3%
add-log-exp65.2%
add-cube-cbrt87.0%
log-prod87.0%
pow287.0%
Applied egg-rr87.0%
if 2 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) Initial program 0.0%
/-rgt-identity0.0%
associate-/r/0.0%
exp-neg0.0%
remove-double-neg0.0%
Simplified0.0%
add-exp-log0.0%
div-exp0.0%
Applied egg-rr0.0%
Taylor expanded in x around inf 99.5%
neg-mul-199.5%
Simplified99.5%
Final simplification97.1%
(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
(pow (cbrt (/ t_0 (exp x))) 3.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 = pow(cbrt((t_0 / exp(x))), 3.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 = cbrt(Float64(t_0 / exp(x))) ^ 3.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[Power[N[Power[N[(t$95$0 / N[Exp[x], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision], 3.0], $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}:\\
\;\;\;\;{\left(\sqrt[3]{\frac{t\_0}{e^{x}}}\right)}^{3}\\
\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 0.2%
/-rgt-identity0.2%
associate-/r/0.2%
exp-neg0.2%
remove-double-neg0.2%
Simplified0.2%
add-exp-log0.2%
div-exp0.2%
Applied egg-rr0.2%
Taylor expanded in x around inf 99.6%
neg-mul-199.6%
Simplified99.6%
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/85.3%
exp-neg85.5%
remove-double-neg85.5%
Simplified85.5%
add-cube-cbrt85.6%
pow385.7%
Applied egg-rr85.7%
Final simplification97.6%
(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)) 1.0) -1.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 = ((t_0 / exp(x)) + 1.0) + -1.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 = ((t_0 / exp(x)) + 1.0d0) + (-1.0d0)
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)) + 1.0) + -1.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(Float64(Float64(t_0 / exp(x)) + 1.0) + -1.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[(N[(N[(t$95$0 / N[Exp[x], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision] + -1.0), $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}:\\
\;\;\;\;\left(\frac{t\_0}{e^{x}} + 1\right) + -1\\
\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 0.2%
/-rgt-identity0.2%
associate-/r/0.2%
exp-neg0.2%
remove-double-neg0.2%
Simplified0.2%
add-exp-log0.2%
div-exp0.2%
Applied egg-rr0.2%
Taylor expanded in x around inf 99.6%
neg-mul-199.6%
Simplified99.6%
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/85.3%
exp-neg85.5%
remove-double-neg85.5%
Simplified85.5%
add-log-exp85.3%
add-cube-cbrt82.8%
log-prod82.8%
pow282.8%
Applied egg-rr82.8%
sum-log82.8%
unpow282.8%
add-cube-cbrt85.3%
add-log-exp85.5%
expm1-log1p-u85.5%
expm1-define85.7%
log1p-undefine85.7%
rem-exp-log85.7%
Applied egg-rr85.7%
Final simplification97.6%
(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 0.2%
/-rgt-identity0.2%
associate-/r/0.2%
exp-neg0.2%
remove-double-neg0.2%
Simplified0.2%
add-exp-log0.2%
div-exp0.2%
Applied egg-rr0.2%
Taylor expanded in x around inf 99.6%
neg-mul-199.6%
Simplified99.6%
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/85.3%
exp-neg85.5%
remove-double-neg85.5%
Simplified85.5%
Final simplification97.5%
(FPCore (x)
:precision binary64
(if (<= x -2e-16)
(exp (- (log (fmod (exp x) 1.0)) x))
(if (or (<= x -5e-26) (not (<= x 1.26)))
(exp (- x))
(/ (fmod (exp x) (+ 1.0 (* -0.25 (pow x 2.0)))) (exp x)))))
double code(double x) {
double tmp;
if (x <= -2e-16) {
tmp = exp((log(fmod(exp(x), 1.0)) - x));
} else if ((x <= -5e-26) || !(x <= 1.26)) {
tmp = exp(-x);
} else {
tmp = fmod(exp(x), (1.0 + (-0.25 * pow(x, 2.0)))) / exp(x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-2d-16)) then
tmp = exp((log(mod(exp(x), 1.0d0)) - x))
else if ((x <= (-5d-26)) .or. (.not. (x <= 1.26d0))) then
tmp = exp(-x)
else
tmp = mod(exp(x), (1.0d0 + ((-0.25d0) * (x ** 2.0d0)))) / exp(x)
end if
code = tmp
end function
def code(x): tmp = 0 if x <= -2e-16: tmp = math.exp((math.log(math.fmod(math.exp(x), 1.0)) - x)) elif (x <= -5e-26) or not (x <= 1.26): tmp = math.exp(-x) else: tmp = math.fmod(math.exp(x), (1.0 + (-0.25 * math.pow(x, 2.0)))) / math.exp(x) return tmp
function code(x) tmp = 0.0 if (x <= -2e-16) tmp = exp(Float64(log(rem(exp(x), 1.0)) - x)); elseif ((x <= -5e-26) || !(x <= 1.26)) tmp = exp(Float64(-x)); else tmp = Float64(rem(exp(x), Float64(1.0 + Float64(-0.25 * (x ^ 2.0)))) / exp(x)); end return tmp end
code[x_] := If[LessEqual[x, -2e-16], N[Exp[N[(N[Log[N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]], $MachinePrecision] - x), $MachinePrecision]], $MachinePrecision], If[Or[LessEqual[x, -5e-26], N[Not[LessEqual[x, 1.26]], $MachinePrecision]], N[Exp[(-x)], $MachinePrecision], N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(1.0 + N[(-0.25 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-16}:\\
\;\;\;\;e^{\log \left(\left(e^{x}\right) \bmod 1\right) - x}\\
\mathbf{elif}\;x \leq -5 \cdot 10^{-26} \lor \neg \left(x \leq 1.26\right):\\
\;\;\;\;e^{-x}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left(1 + -0.25 \cdot {x}^{2}\right)\right)}{e^{x}}\\
\end{array}
\end{array}
if x < -2e-16Initial program 94.8%
/-rgt-identity94.8%
associate-/r/94.5%
exp-neg95.0%
remove-double-neg95.0%
Simplified95.0%
Taylor expanded in x around 0 95.0%
add-exp-log95.0%
div-exp95.2%
Applied egg-rr95.2%
if -2e-16 < x < -5.00000000000000019e-26 or 1.26000000000000001 < x Initial program 0.6%
/-rgt-identity0.6%
associate-/r/0.6%
exp-neg0.6%
remove-double-neg0.6%
Simplified0.6%
add-exp-log0.6%
div-exp0.6%
Applied egg-rr0.6%
Taylor expanded in x around inf 99.6%
neg-mul-199.6%
Simplified99.6%
if -5.00000000000000019e-26 < x < 1.26000000000000001Initial program 68.6%
/-rgt-identity68.6%
associate-/r/68.7%
exp-neg68.7%
remove-double-neg68.7%
Simplified68.7%
Taylor expanded in x around 0 59.1%
Final simplification96.6%
(FPCore (x)
:precision binary64
(if (<= x -2e-16)
(exp (- (log (fmod (exp x) 1.0)) x))
(if (or (<= x -5e-26) (not (<= x 0.93)))
(exp (- x))
(* (fmod (exp x) (sqrt (cos x))) (- 1.0 x)))))
double code(double x) {
double tmp;
if (x <= -2e-16) {
tmp = exp((log(fmod(exp(x), 1.0)) - x));
} else if ((x <= -5e-26) || !(x <= 0.93)) {
tmp = exp(-x);
} else {
tmp = fmod(exp(x), sqrt(cos(x))) * (1.0 - x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-2d-16)) then
tmp = exp((log(mod(exp(x), 1.0d0)) - x))
else if ((x <= (-5d-26)) .or. (.not. (x <= 0.93d0))) then
tmp = exp(-x)
else
tmp = mod(exp(x), sqrt(cos(x))) * (1.0d0 - x)
end if
code = tmp
end function
def code(x): tmp = 0 if x <= -2e-16: tmp = math.exp((math.log(math.fmod(math.exp(x), 1.0)) - x)) elif (x <= -5e-26) or not (x <= 0.93): tmp = math.exp(-x) else: tmp = math.fmod(math.exp(x), math.sqrt(math.cos(x))) * (1.0 - x) return tmp
function code(x) tmp = 0.0 if (x <= -2e-16) tmp = exp(Float64(log(rem(exp(x), 1.0)) - x)); elseif ((x <= -5e-26) || !(x <= 0.93)) tmp = exp(Float64(-x)); else tmp = Float64(rem(exp(x), sqrt(cos(x))) * Float64(1.0 - x)); end return tmp end
code[x_] := If[LessEqual[x, -2e-16], N[Exp[N[(N[Log[N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]], $MachinePrecision] - x), $MachinePrecision]], $MachinePrecision], If[Or[LessEqual[x, -5e-26], N[Not[LessEqual[x, 0.93]], $MachinePrecision]], N[Exp[(-x)], $MachinePrecision], 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[(1.0 - x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-16}:\\
\;\;\;\;e^{\log \left(\left(e^{x}\right) \bmod 1\right) - x}\\
\mathbf{elif}\;x \leq -5 \cdot 10^{-26} \lor \neg \left(x \leq 0.93\right):\\
\;\;\;\;e^{-x}\\
\mathbf{else}:\\
\;\;\;\;\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if x < -2e-16Initial program 94.8%
/-rgt-identity94.8%
associate-/r/94.5%
exp-neg95.0%
remove-double-neg95.0%
Simplified95.0%
Taylor expanded in x around 0 95.0%
add-exp-log95.0%
div-exp95.2%
Applied egg-rr95.2%
if -2e-16 < x < -5.00000000000000019e-26 or 0.930000000000000049 < x Initial program 0.6%
/-rgt-identity0.6%
associate-/r/0.6%
exp-neg0.6%
remove-double-neg0.6%
Simplified0.6%
add-exp-log0.6%
div-exp0.6%
Applied egg-rr0.6%
Taylor expanded in x around inf 99.6%
neg-mul-199.6%
Simplified99.6%
if -5.00000000000000019e-26 < x < 0.930000000000000049Initial program 68.6%
/-rgt-identity68.6%
associate-/r/68.7%
exp-neg68.7%
remove-double-neg68.7%
Simplified68.7%
Taylor expanded in x around 0 53.0%
+-commutative53.0%
mul-1-neg53.0%
unsub-neg53.0%
*-lft-identity53.0%
distribute-rgt-out--53.0%
Simplified53.0%
Final simplification96.2%
(FPCore (x)
:precision binary64
(let* ((t_0 (fmod (exp x) 1.0)))
(if (<= x -2e-16)
(exp (- (log t_0) x))
(if (or (<= x -5e-26) (not (<= x 2.0))) (exp (- x)) (/ t_0 (exp x))))))
double code(double x) {
double t_0 = fmod(exp(x), 1.0);
double tmp;
if (x <= -2e-16) {
tmp = exp((log(t_0) - x));
} else if ((x <= -5e-26) || !(x <= 2.0)) {
tmp = exp(-x);
} else {
tmp = t_0 / exp(x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = mod(exp(x), 1.0d0)
if (x <= (-2d-16)) then
tmp = exp((log(t_0) - x))
else if ((x <= (-5d-26)) .or. (.not. (x <= 2.0d0))) then
tmp = exp(-x)
else
tmp = t_0 / exp(x)
end if
code = tmp
end function
def code(x): t_0 = math.fmod(math.exp(x), 1.0) tmp = 0 if x <= -2e-16: tmp = math.exp((math.log(t_0) - x)) elif (x <= -5e-26) or not (x <= 2.0): tmp = math.exp(-x) else: tmp = t_0 / math.exp(x) return tmp
function code(x) t_0 = rem(exp(x), 1.0) tmp = 0.0 if (x <= -2e-16) tmp = exp(Float64(log(t_0) - x)); elseif ((x <= -5e-26) || !(x <= 2.0)) tmp = exp(Float64(-x)); 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 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]}, If[LessEqual[x, -2e-16], N[Exp[N[(N[Log[t$95$0], $MachinePrecision] - x), $MachinePrecision]], $MachinePrecision], If[Or[LessEqual[x, -5e-26], N[Not[LessEqual[x, 2.0]], $MachinePrecision]], N[Exp[(-x)], $MachinePrecision], N[(t$95$0 / N[Exp[x], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\left(e^{x}\right) \bmod 1\right)\\
\mathbf{if}\;x \leq -2 \cdot 10^{-16}:\\
\;\;\;\;e^{\log t\_0 - x}\\
\mathbf{elif}\;x \leq -5 \cdot 10^{-26} \lor \neg \left(x \leq 2\right):\\
\;\;\;\;e^{-x}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0}{e^{x}}\\
\end{array}
\end{array}
if x < -2e-16Initial program 94.8%
/-rgt-identity94.8%
associate-/r/94.5%
exp-neg95.0%
remove-double-neg95.0%
Simplified95.0%
Taylor expanded in x around 0 95.0%
add-exp-log95.0%
div-exp95.2%
Applied egg-rr95.2%
if -2e-16 < x < -5.00000000000000019e-26 or 2 < x Initial program 0.2%
/-rgt-identity0.2%
associate-/r/0.2%
exp-neg0.2%
remove-double-neg0.2%
Simplified0.2%
add-exp-log0.2%
div-exp0.2%
Applied egg-rr0.2%
Taylor expanded in x around inf 100.0%
neg-mul-1100.0%
Simplified100.0%
if -5.00000000000000019e-26 < x < 2Initial program 70.2%
/-rgt-identity70.2%
associate-/r/70.3%
exp-neg70.3%
remove-double-neg70.3%
Simplified70.3%
Taylor expanded in x around 0 44.2%
Final simplification95.7%
(FPCore (x) :precision binary64 (if (or (<= x -2e-16) (and (not (<= x -5e-26)) (<= x 2.0))) (/ (fmod (exp x) 1.0) (exp x)) (exp (- x))))
double code(double x) {
double tmp;
if ((x <= -2e-16) || (!(x <= -5e-26) && (x <= 2.0))) {
tmp = fmod(exp(x), 1.0) / exp(x);
} else {
tmp = exp(-x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-2d-16)) .or. (.not. (x <= (-5d-26))) .and. (x <= 2.0d0)) then
tmp = mod(exp(x), 1.0d0) / exp(x)
else
tmp = exp(-x)
end if
code = tmp
end function
def code(x): tmp = 0 if (x <= -2e-16) or (not (x <= -5e-26) and (x <= 2.0)): tmp = math.fmod(math.exp(x), 1.0) / math.exp(x) else: tmp = math.exp(-x) return tmp
function code(x) tmp = 0.0 if ((x <= -2e-16) || (!(x <= -5e-26) && (x <= 2.0))) tmp = Float64(rem(exp(x), 1.0) / exp(x)); else tmp = exp(Float64(-x)); end return tmp end
code[x_] := If[Or[LessEqual[x, -2e-16], And[N[Not[LessEqual[x, -5e-26]], $MachinePrecision], LessEqual[x, 2.0]]], 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[Exp[(-x)], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-16} \lor \neg \left(x \leq -5 \cdot 10^{-26}\right) \land x \leq 2:\\
\;\;\;\;\frac{\left(\left(e^{x}\right) \bmod 1\right)}{e^{x}}\\
\mathbf{else}:\\
\;\;\;\;e^{-x}\\
\end{array}
\end{array}
if x < -2e-16 or -5.00000000000000019e-26 < x < 2Initial program 83.2%
/-rgt-identity83.2%
associate-/r/83.0%
exp-neg83.3%
remove-double-neg83.3%
Simplified83.3%
Taylor expanded in x around 0 70.9%
if -2e-16 < x < -5.00000000000000019e-26 or 2 < x Initial program 0.2%
/-rgt-identity0.2%
associate-/r/0.2%
exp-neg0.2%
remove-double-neg0.2%
Simplified0.2%
add-exp-log0.2%
div-exp0.2%
Applied egg-rr0.2%
Taylor expanded in x around inf 100.0%
neg-mul-1100.0%
Simplified100.0%
Final simplification95.7%
(FPCore (x) :precision binary64 (if (or (<= x -5e-26) (not (<= x 0.48))) (exp (- x)) (fmod (exp x) 1.0)))
double code(double x) {
double tmp;
if ((x <= -5e-26) || !(x <= 0.48)) {
tmp = exp(-x);
} else {
tmp = fmod(exp(x), 1.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-5d-26)) .or. (.not. (x <= 0.48d0))) then
tmp = exp(-x)
else
tmp = mod(exp(x), 1.0d0)
end if
code = tmp
end function
def code(x): tmp = 0 if (x <= -5e-26) or not (x <= 0.48): tmp = math.exp(-x) else: tmp = math.fmod(math.exp(x), 1.0) return tmp
function code(x) tmp = 0.0 if ((x <= -5e-26) || !(x <= 0.48)) tmp = exp(Float64(-x)); else tmp = rem(exp(x), 1.0); end return tmp end
code[x_] := If[Or[LessEqual[x, -5e-26], N[Not[LessEqual[x, 0.48]], $MachinePrecision]], N[Exp[(-x)], $MachinePrecision], N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-26} \lor \neg \left(x \leq 0.48\right):\\
\;\;\;\;e^{-x}\\
\mathbf{else}:\\
\;\;\;\;\left(\left(e^{x}\right) \bmod 1\right)\\
\end{array}
\end{array}
if x < -5.00000000000000019e-26 or 0.47999999999999998 < x Initial program 8.9%
/-rgt-identity8.9%
associate-/r/8.8%
exp-neg8.9%
remove-double-neg8.9%
Simplified8.9%
add-exp-log8.9%
div-exp8.9%
Applied egg-rr8.9%
Taylor expanded in x around inf 95.4%
neg-mul-195.4%
Simplified95.4%
if -5.00000000000000019e-26 < x < 0.47999999999999998Initial program 66.9%
/-rgt-identity66.9%
associate-/r/67.0%
exp-neg67.0%
remove-double-neg67.0%
Simplified67.0%
Taylor expanded in x around 0 47.4%
Taylor expanded in x around 0 46.1%
Final simplification92.4%
(FPCore (x) :precision binary64 (if (<= x -1.15e-16) (* (fmod (exp x) 1.0) (- 1.0 x)) (exp (- x))))
double code(double x) {
double tmp;
if (x <= -1.15e-16) {
tmp = fmod(exp(x), 1.0) * (1.0 - x);
} else {
tmp = exp(-x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-1.15d-16)) then
tmp = mod(exp(x), 1.0d0) * (1.0d0 - x)
else
tmp = exp(-x)
end if
code = tmp
end function
def code(x): tmp = 0 if x <= -1.15e-16: tmp = math.fmod(math.exp(x), 1.0) * (1.0 - x) else: tmp = math.exp(-x) return tmp
function code(x) tmp = 0.0 if (x <= -1.15e-16) tmp = Float64(rem(exp(x), 1.0) * Float64(1.0 - x)); else tmp = exp(Float64(-x)); end return tmp end
code[x_] := If[LessEqual[x, -1.15e-16], N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * N[(1.0 - x), $MachinePrecision]), $MachinePrecision], N[Exp[(-x)], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.15 \cdot 10^{-16}:\\
\;\;\;\;\left(\left(e^{x}\right) \bmod 1\right) \cdot \left(1 - x\right)\\
\mathbf{else}:\\
\;\;\;\;e^{-x}\\
\end{array}
\end{array}
if x < -1.15e-16Initial program 94.8%
/-rgt-identity94.8%
associate-/r/94.5%
exp-neg95.0%
remove-double-neg95.0%
Simplified95.0%
Taylor expanded in x around 0 95.0%
Taylor expanded in x around 0 73.8%
+-commutative73.8%
*-lft-identity73.8%
associate-*r*73.8%
neg-mul-173.8%
distribute-rgt-out73.6%
Simplified73.6%
Taylor expanded in x around 0 73.8%
+-commutative73.8%
mul-1-neg73.8%
*-commutative73.8%
sub-neg73.8%
*-rgt-identity73.8%
distribute-lft-out--73.6%
Simplified73.6%
if -1.15e-16 < x Initial program 5.5%
/-rgt-identity5.5%
associate-/r/5.5%
exp-neg5.5%
remove-double-neg5.5%
Simplified5.5%
add-exp-log5.5%
div-exp5.5%
Applied egg-rr5.5%
Taylor expanded in x around inf 93.3%
neg-mul-193.3%
Simplified93.3%
Final simplification91.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 12.5%
/-rgt-identity12.5%
associate-/r/12.5%
exp-neg12.5%
remove-double-neg12.5%
Simplified12.5%
add-exp-log12.5%
div-exp12.5%
Applied egg-rr12.5%
Taylor expanded in x around inf 90.2%
neg-mul-190.2%
Simplified90.2%
Final simplification90.2%
herbie shell --seed 2024085
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))