Average Error: 59.7 → 23.7
Time: 16.2s
Precision: binary64
Cost: 109832
\[\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \]
\[\begin{array}{l} t_0 := \sqrt{\cos x}\\ t_1 := e^{-x}\\ t_2 := \left(\left(e^{x}\right) \bmod t_0\right) \cdot t_1\\ \mathbf{if}\;t_2 \leq 0:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 2:\\ \;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \log \left(e^{t_0}\right)\right)}{e^{x}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
(FPCore (x) :precision binary64 (* (fmod (exp x) (sqrt (cos x))) (exp (- x))))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (sqrt (cos x)))
        (t_1 (exp (- x)))
        (t_2 (* (fmod (exp x) t_0) t_1)))
   (if (<= t_2 0.0)
     t_1
     (if (<= t_2 2.0) (/ (fmod (exp x) (log (exp t_0))) (exp x)) t_1))))
double code(double x) {
	return fmod(exp(x), sqrt(cos(x))) * exp(-x);
}
double code(double x) {
	double t_0 = sqrt(cos(x));
	double t_1 = exp(-x);
	double t_2 = fmod(exp(x), t_0) * t_1;
	double tmp;
	if (t_2 <= 0.0) {
		tmp = t_1;
	} else if (t_2 <= 2.0) {
		tmp = fmod(exp(x), log(exp(t_0))) / exp(x);
	} else {
		tmp = t_1;
	}
	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) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_0 = sqrt(cos(x))
    t_1 = exp(-x)
    t_2 = mod(exp(x), t_0) * t_1
    if (t_2 <= 0.0d0) then
        tmp = t_1
    else if (t_2 <= 2.0d0) then
        tmp = mod(exp(x), log(exp(t_0))) / exp(x)
    else
        tmp = t_1
    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):
	t_0 = math.sqrt(math.cos(x))
	t_1 = math.exp(-x)
	t_2 = math.fmod(math.exp(x), t_0) * t_1
	tmp = 0
	if t_2 <= 0.0:
		tmp = t_1
	elif t_2 <= 2.0:
		tmp = math.fmod(math.exp(x), math.log(math.exp(t_0))) / math.exp(x)
	else:
		tmp = t_1
	return tmp
function code(x)
	return Float64(rem(exp(x), sqrt(cos(x))) * exp(Float64(-x)))
end
function code(x)
	t_0 = sqrt(cos(x))
	t_1 = exp(Float64(-x))
	t_2 = Float64(rem(exp(x), t_0) * t_1)
	tmp = 0.0
	if (t_2 <= 0.0)
		tmp = t_1;
	elseif (t_2 <= 2.0)
		tmp = Float64(rem(exp(x), log(exp(t_0))) / exp(x));
	else
		tmp = t_1;
	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_] := Block[{t$95$0 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Exp[(-x)], $MachinePrecision]}, Block[{t$95$2 = N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = t$95$0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * t$95$1), $MachinePrecision]}, If[LessEqual[t$95$2, 0.0], t$95$1, If[LessEqual[t$95$2, 2.0], N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Log[N[Exp[t$95$0], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision], t$95$1]]]]]
\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x}
\begin{array}{l}
t_0 := \sqrt{\cos x}\\
t_1 := e^{-x}\\
t_2 := \left(\left(e^{x}\right) \bmod t_0\right) \cdot t_1\\
\mathbf{if}\;t_2 \leq 0:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_2 \leq 2:\\
\;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \log \left(e^{t_0}\right)\right)}{e^{x}}\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error

Derivation

  1. Split input into 2 regimes
  2. 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)))

    1. Initial program 61.8

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

      \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}} \]
      Proof
      (/.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 x)): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= *-rgt-identity_binary64 (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) 1)) (exp.f64 x)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-*r/_binary64 (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (/.f64 1 (exp.f64 x)))): 2 points increase in error, 2 points decrease in error
      (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (Rewrite<= exp-neg_binary64 (exp.f64 (neg.f64 x)))): 4 points increase in error, 0 points decrease in error
    3. Applied egg-rr61.8

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

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

      \[\leadsto e^{\color{blue}{-x}} \]
      Proof
      (neg.f64 x): 0 points increase in error, 0 points decrease in error
      (Rewrite<= mul-1-neg_binary64 (*.f64 -1 x)): 0 points increase in error, 0 points decrease in error

    if 0.0 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 2

    1. Initial program 12.5

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

      \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}} \]
      Proof
      (/.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 x)): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= *-rgt-identity_binary64 (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) 1)) (exp.f64 x)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-*r/_binary64 (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (/.f64 1 (exp.f64 x)))): 2 points increase in error, 2 points decrease in error
      (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (Rewrite<= exp-neg_binary64 (exp.f64 (neg.f64 x)))): 4 points increase in error, 0 points decrease in error
    3. Applied egg-rr12.4

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \color{blue}{\log \left(e^{\sqrt{\cos x}}\right)}\right)}{e^{x}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification23.7

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

Alternatives

Alternative 1
Error23.7
Cost97288
\[\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:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 2:\\ \;\;\;\;\left(1 + \frac{t_0}{e^{x}}\right) + -1\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error23.7
Cost97160
\[\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:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 2:\\ \;\;\;\;t_0 \cdot \frac{1}{e^{x}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error23.7
Cost97160
\[\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:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 2:\\ \;\;\;\;\frac{1}{\frac{e^{x}}{t_0}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error23.7
Cost97032
\[\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:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 2:\\ \;\;\;\;\frac{t_0}{e^{x}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error25.0
Cost6528
\[e^{-x} \]

Error

Reproduce

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