?

Average Error: 92.98% → 36.33%
Time: 14.8s
Precision: binary64
Cost: 39048

?

\[\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \]
\[\begin{array}{l} \mathbf{if}\;x \leq -2 \cdot 10^{-310}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 2:\\ \;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left({\left({\cos x}^{0.25}\right)}^{2}\right)\right)}{e^{x}}\\ \mathbf{else}:\\ \;\;\;\;e^{-x}\\ \end{array} \]
(FPCore (x) :precision binary64 (* (fmod (exp x) (sqrt (cos x))) (exp (- x))))
(FPCore (x)
 :precision binary64
 (if (<= x -2e-310)
   1.0
   (if (<= x 2.0)
     (/ (fmod (exp x) (pow (pow (cos x) 0.25) 2.0)) (exp x))
     (exp (- x)))))
double code(double x) {
	return fmod(exp(x), sqrt(cos(x))) * exp(-x);
}
double code(double x) {
	double tmp;
	if (x <= -2e-310) {
		tmp = 1.0;
	} else if (x <= 2.0) {
		tmp = fmod(exp(x), pow(pow(cos(x), 0.25), 2.0)) / exp(x);
	} 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 <= (-2d-310)) then
        tmp = 1.0d0
    else if (x <= 2.0d0) then
        tmp = mod(exp(x), ((cos(x) ** 0.25d0) ** 2.0d0)) / exp(x)
    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 <= -2e-310:
		tmp = 1.0
	elif x <= 2.0:
		tmp = math.fmod(math.exp(x), math.pow(math.pow(math.cos(x), 0.25), 2.0)) / math.exp(x)
	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 <= -2e-310)
		tmp = 1.0;
	elseif (x <= 2.0)
		tmp = Float64(rem(exp(x), ((cos(x) ^ 0.25) ^ 2.0)) / exp(x));
	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, -2e-310], 1.0, If[LessEqual[x, 2.0], N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Power[N[Power[N[Cos[x], $MachinePrecision], 0.25], $MachinePrecision], 2.0], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision], 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 -2 \cdot 10^{-310}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \leq 2:\\
\;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left({\left({\cos x}^{0.25}\right)}^{2}\right)\right)}{e^{x}}\\

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


\end{array}

Error?

Derivation?

  1. Split input into 3 regimes
  2. if x < -1.999999999999994e-310

    1. Initial program 91.06

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

      \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}} \]
      Proof

      [Start]91.06

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

      exp-neg [=>]91.05

      \[ \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot \color{blue}{\frac{1}{e^{x}}} \]

      associate-*r/ [=>]91.03

      \[ \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot 1}{e^{x}}} \]

      *-rgt-identity [=>]91.03

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

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

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

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

    if -1.999999999999994e-310 < x < 2

    1. Initial program 91.66

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

      \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}} \]
      Proof

      [Start]91.66

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

      exp-neg [=>]91.66

      \[ \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot \color{blue}{\frac{1}{e^{x}}} \]

      associate-*r/ [=>]91.66

      \[ \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot 1}{e^{x}}} \]

      *-rgt-identity [=>]91.66

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

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \color{blue}{\left({\left({\cos x}^{0.25}\right)}^{2}\right)}\right)}{e^{x}} \]

    if 2 < x

    1. Initial program 99.64

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

      \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}} \]
      Proof

      [Start]99.64

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

      exp-neg [=>]99.64

      \[ \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot \color{blue}{\frac{1}{e^{x}}} \]

      associate-*r/ [=>]99.64

      \[ \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot 1}{e^{x}}} \]

      *-rgt-identity [=>]99.64

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

      \[\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 0.63

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

      \[\leadsto e^{\color{blue}{-x}} \]
      Proof

      [Start]0.63

      \[ e^{-1 \cdot x} \]

      mul-1-neg [=>]0.63

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2 \cdot 10^{-310}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 2:\\ \;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left({\left({\cos x}^{0.25}\right)}^{2}\right)\right)}{e^{x}}\\ \mathbf{else}:\\ \;\;\;\;e^{-x}\\ \end{array} \]

Alternatives

Alternative 1
Error36.33%
Cost32648
\[\begin{array}{l} \mathbf{if}\;x \leq -2 \cdot 10^{-310}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 2:\\ \;\;\;\;\frac{1}{\frac{e^{x}}{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;e^{-x}\\ \end{array} \]
Alternative 2
Error36.33%
Cost32520
\[\begin{array}{l} \mathbf{if}\;x \leq -2 \cdot 10^{-310}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 2:\\ \;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}\\ \mathbf{else}:\\ \;\;\;\;e^{-x}\\ \end{array} \]
Alternative 3
Error37.5%
Cost6660
\[\begin{array}{l} \mathbf{if}\;x \leq 10^{-306}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;e^{-x}\\ \end{array} \]
Alternative 4
Error56.43%
Cost64
\[1 \]

Error

Reproduce?

herbie shell --seed 2023093 
(FPCore (x)
  :name "expfmod (used to be hard to sample)"
  :precision binary64
  (* (fmod (exp x) (sqrt (cos x))) (exp (- x))))