Average Error: 59.6 → 24.3
Time: 11.9s
Precision: binary64
Cost: 6660
\[\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \]
\[\begin{array}{l} \mathbf{if}\;x \leq 1.1815051286954552 \cdot 10^{-120}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;e^{-x}\\ \end{array} \]
(FPCore (x) :precision binary64 (* (fmod (exp x) (sqrt (cos x))) (exp (- x))))
(FPCore (x)
 :precision binary64
 (if (<= x 1.1815051286954552e-120) 1.0 (exp (- x))))
double code(double x) {
	return fmod(exp(x), sqrt(cos(x))) * exp(-x);
}
double code(double x) {
	double tmp;
	if (x <= 1.1815051286954552e-120) {
		tmp = 1.0;
	} else {
		tmp = exp(-x);
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = mod(exp(x), sqrt(cos(x))) * exp(-x)
end function
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= 1.1815051286954552d-120) then
        tmp = 1.0d0
    else
        tmp = exp(-x)
    end if
    code = tmp
end function
def code(x):
	return math.fmod(math.exp(x), math.sqrt(math.cos(x))) * math.exp(-x)
def code(x):
	tmp = 0
	if x <= 1.1815051286954552e-120:
		tmp = 1.0
	else:
		tmp = math.exp(-x)
	return tmp
function code(x)
	return Float64(rem(exp(x), sqrt(cos(x))) * exp(Float64(-x)))
end
function code(x)
	tmp = 0.0
	if (x <= 1.1815051286954552e-120)
		tmp = 1.0;
	else
		tmp = exp(Float64(-x));
	end
	return tmp
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]
code[x_] := If[LessEqual[x, 1.1815051286954552e-120], 1.0, N[Exp[(-x)], $MachinePrecision]]
\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x}
\begin{array}{l}
\mathbf{if}\;x \leq 1.1815051286954552 \cdot 10^{-120}:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;e^{-x}\\


\end{array}

Error

Derivation

  1. Split input into 2 regimes
  2. if x < 1.1815051286954552e-120

    1. Initial program 59.0

      \[\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \]
    2. Simplified58.9

      \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}} \]
    3. Applied egg-rr58.9

      \[\leadsto \color{blue}{e^{\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x}} \]
    4. Applied egg-rr58.9

      \[\leadsto \color{blue}{{\left(e^{{\left(\sqrt[3]{\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x}\right)}^{2}}\right)}^{\left(\sqrt[3]{\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x}\right)}} \]
    5. Taylor expanded in x around inf 23.0

      \[\leadsto \color{blue}{1} \]

    if 1.1815051286954552e-120 < x

    1. Initial program 60.7

      \[\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \]
    2. Simplified60.7

      \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}} \]
    3. Applied egg-rr60.7

      \[\leadsto \color{blue}{e^{\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x}} \]
    4. Taylor expanded in x around inf 26.8

      \[\leadsto e^{\color{blue}{-1 \cdot x}} \]
    5. Simplified26.8

      \[\leadsto e^{\color{blue}{-x}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification24.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 1.1815051286954552 \cdot 10^{-120}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;e^{-x}\\ \end{array} \]

Alternatives

Alternative 1
Error36.3
Cost64
\[1 \]

Error

Reproduce

herbie shell --seed 2022228 
(FPCore (x)
  :name "expfmod"
  :precision binary64
  (* (fmod (exp x) (sqrt (cos x))) (exp (- x))))