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

\mathbf{else}:\\
\;\;\;\;\frac{t_0}{e^{x}}\\


\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

    1. Initial program 61.3

      \[\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \]
    2. Simplified61.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, 0 points decrease in error
      (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (Rewrite<= exp-neg_binary64 (exp.f64 (neg.f64 x)))): 3 points increase in error, 0 points decrease in error
    3. Applied egg-rr61.3

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \color{blue}{\left(\left(1 + \sqrt{\cos x}\right) - 1\right)}\right)}{e^{x}} \]
    4. Applied egg-rr30.2

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\color{blue}{{\left(\mathsf{hypot}\left(1, {\cos x}^{0.25}\right)\right)}^{2}} - 1\right)\right)}{e^{x}} \]
    5. Taylor expanded in x around 0 30.2

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \color{blue}{\left({\left(\sqrt{2}\right)}^{2} - 1\right)}\right)}{e^{x}} \]
    6. Taylor expanded in x around 0 30.2

      \[\leadsto \color{blue}{\left(\left(e^{x}\right) \bmod \left({\left(\sqrt{2}\right)}^{2} - 1\right)\right)} \]

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

    1. Initial program 53.9

      \[\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \]
    2. Simplified53.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, 0 points decrease in error
      (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (Rewrite<= exp-neg_binary64 (exp.f64 (neg.f64 x)))): 3 points increase in error, 0 points decrease in error
  3. Recombined 2 regimes into one program.
  4. Final simplification36.0

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

Alternatives

Alternative 1
Error36.1
Cost45376
\[\frac{\left(\left(e^{x}\right) \bmod \left({\left(\mathsf{hypot}\left(1, {\cos x}^{0.25}\right)\right)}^{2} + -1\right)\right)}{e^{x}} \]
Alternative 2
Error36.3
Cost32448
\[\frac{\left(\left(e^{x}\right) \bmod \left({\left(\sqrt{2}\right)}^{2} + -1\right)\right)}{e^{x}} \]
Alternative 3
Error37.1
Cost25920
\[\left(\left(e^{x}\right) \bmod \left({\left(\sqrt{2}\right)}^{2} + -1\right)\right) \]
Alternative 4
Error59.6
Cost19840
\[\frac{\left(\left(e^{x}\right) \bmod \left(1 + x \cdot \left(x \cdot -0.25\right)\right)\right)}{e^{x}} \]
Alternative 5
Error59.7
Cost19712
\[\left(1 + \frac{\left(\left(e^{x}\right) \bmod 1\right)}{e^{x}}\right) + -1 \]
Alternative 6
Error59.7
Cost19456
\[\frac{\left(\left(e^{x}\right) \bmod 1\right)}{e^{x}} \]
Alternative 7
Error60.0
Cost13824
\[\left(1 + \left(\left(e^{x}\right) \bmod 1\right) \cdot \left(1 + \left(\left(x \cdot x\right) \cdot 0.5 - x\right)\right)\right) + -1 \]
Alternative 8
Error60.0
Cost13568
\[\left(\left(e^{x}\right) \bmod 1\right) \cdot \left(1 + \left(\left(x \cdot x\right) \cdot 0.5 - x\right)\right) \]
Alternative 9
Error60.1
Cost13440
\[\left(1 - x\right) \cdot \left(\left(1 + \left(\left(e^{x}\right) \bmod 1\right)\right) + -1\right) \]
Alternative 10
Error60.1
Cost13440
\[\left(1 + \left(\left(e^{x}\right) \bmod 1\right) \cdot \left(1 - x\right)\right) + -1 \]
Alternative 11
Error60.1
Cost13184
\[\left(\left(e^{x}\right) \bmod 1\right) \cdot \left(1 - x\right) \]
Alternative 12
Error60.5
Cost12928
\[\left(\left(e^{x}\right) \bmod 1\right) \]

Error

Reproduce

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