Average Error: 59.6 → 56.5
Time: 12.8s
Precision: binary64
Cost: 58624
\[\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \]
\[\begin{array}{l} t_0 := \mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod 1\right) - x\right)\\ \frac{1 - t_0 \cdot \mathsf{expm1}\left(-x\right)}{1 - t_0} \end{array} \]
(FPCore (x) :precision binary64 (* (fmod (exp x) (sqrt (cos x))) (exp (- x))))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (expm1 (- (log (fmod (exp x) 1.0)) x))))
   (/ (- 1.0 (* t_0 (expm1 (- x)))) (- 1.0 t_0))))
double code(double x) {
	return fmod(exp(x), sqrt(cos(x))) * exp(-x);
}
double code(double x) {
	double t_0 = expm1((log(fmod(exp(x), 1.0)) - x));
	return (1.0 - (t_0 * expm1(-x))) / (1.0 - t_0);
}
def code(x):
	return math.fmod(math.exp(x), math.sqrt(math.cos(x))) * math.exp(-x)
def code(x):
	t_0 = math.expm1((math.log(math.fmod(math.exp(x), 1.0)) - x))
	return (1.0 - (t_0 * math.expm1(-x))) / (1.0 - t_0)
function code(x)
	return Float64(rem(exp(x), sqrt(cos(x))) * exp(Float64(-x)))
end
function code(x)
	t_0 = expm1(Float64(log(rem(exp(x), 1.0)) - x))
	return Float64(Float64(1.0 - Float64(t_0 * expm1(Float64(-x)))) / Float64(1.0 - t_0))
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[(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]] - 1), $MachinePrecision]}, N[(N[(1.0 - N[(t$95$0 * N[(Exp[(-x)] - 1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(1.0 - t$95$0), $MachinePrecision]), $MachinePrecision]]
\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x}
\begin{array}{l}
t_0 := \mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod 1\right) - x\right)\\
\frac{1 - t_0 \cdot \mathsf{expm1}\left(-x\right)}{1 - t_0}
\end{array}

Error

Derivation

  1. Initial program 59.6

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

    \[\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)))): 0 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)))): 5 points increase in error, 0 points decrease in error
  3. Taylor expanded in x around 0 59.9

    \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \color{blue}{1}\right)}{e^{x}} \]
  4. Applied egg-rr59.9

    \[\leadsto \color{blue}{\left(1 + \frac{\left(\left(e^{x}\right) \bmod 1\right)}{e^{x}}\right) - 1} \]
  5. Applied egg-rr59.9

    \[\leadsto \color{blue}{\frac{1 - \mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod 1\right) - x\right) \cdot \mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod 1\right) - x\right)}{1 - \mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod 1\right) - x\right)}} \]
  6. Taylor expanded in x around inf 56.5

    \[\leadsto \frac{1 - \mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod 1\right) - x\right) \cdot \mathsf{expm1}\left(\color{blue}{-1 \cdot x}\right)}{1 - \mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod 1\right) - x\right)} \]
  7. Simplified56.5

    \[\leadsto \frac{1 - \mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod 1\right) - x\right) \cdot \mathsf{expm1}\left(\color{blue}{-x}\right)}{1 - \mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod 1\right) - x\right)} \]
    Proof
    (neg.f64 x): 0 points increase in error, 0 points decrease in error
    (Rewrite=> neg-mul-1_binary64 (*.f64 -1 x)): 0 points increase in error, 0 points decrease in error
  8. Final simplification56.5

    \[\leadsto \frac{1 - \mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod 1\right) - x\right) \cdot \mathsf{expm1}\left(-x\right)}{1 - \mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod 1\right) - x\right)} \]

Alternatives

Alternative 1
Error59.5
Cost32256
\[\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}} \]
Alternative 2
Error59.7
Cost19840
\[\frac{\left(\left(e^{x}\right) \bmod \left(1 + \left(x \cdot x\right) \cdot -0.25\right)\right)}{e^{x}} \]
Alternative 3
Error59.9
Cost19456
\[\frac{\left(\left(e^{x}\right) \bmod 1\right)}{e^{x}} \]
Alternative 4
Error60.2
Cost13568
\[\left(\left(e^{x}\right) \bmod 1\right) \cdot \frac{1 - x \cdot x}{1 + x} \]
Alternative 5
Error60.2
Cost13440
\[\left(1 + \left(\left(e^{x}\right) \bmod 1\right) \cdot \left(1 - x\right)\right) + -1 \]
Alternative 6
Error60.2
Cost13184
\[\left(\left(e^{x}\right) \bmod 1\right) \cdot \left(1 - x\right) \]
Alternative 7
Error60.5
Cost12928
\[\left(\left(e^{x}\right) \bmod 1\right) \]

Error

Reproduce

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