Average Error: 59.5 → 23.7
Time: 13.2s
Precision: binary64
Cost: 161672
\[\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)\\ t_1 := t_0 \cdot e^{-x}\\ t_2 := \mathsf{expm1}\left(\log t_0 - x\right)\\ t_3 := \mathsf{expm1}\left(-x\right)\\ t_4 := \frac{{t_3}^{2} + -1}{t_3 + -1}\\ \mathbf{if}\;t_1 \leq 0:\\ \;\;\;\;t_4\\ \mathbf{elif}\;t_1 \leq 2:\\ \;\;\;\;\frac{\log \left(e^{{t_2}^{2} + -1}\right)}{t_2 + -1}\\ \mathbf{else}:\\ \;\;\;\;t_4\\ \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))))
        (t_1 (* t_0 (exp (- x))))
        (t_2 (expm1 (- (log t_0) x)))
        (t_3 (expm1 (- x)))
        (t_4 (/ (+ (pow t_3 2.0) -1.0) (+ t_3 -1.0))))
   (if (<= t_1 0.0)
     t_4
     (if (<= t_1 2.0)
       (/ (log (exp (+ (pow t_2 2.0) -1.0))) (+ t_2 -1.0))
       t_4))))
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 t_1 = t_0 * exp(-x);
	double t_2 = expm1((log(t_0) - x));
	double t_3 = expm1(-x);
	double t_4 = (pow(t_3, 2.0) + -1.0) / (t_3 + -1.0);
	double tmp;
	if (t_1 <= 0.0) {
		tmp = t_4;
	} else if (t_1 <= 2.0) {
		tmp = log(exp((pow(t_2, 2.0) + -1.0))) / (t_2 + -1.0);
	} else {
		tmp = t_4;
	}
	return tmp;
}
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)))
	t_1 = t_0 * math.exp(-x)
	t_2 = math.expm1((math.log(t_0) - x))
	t_3 = math.expm1(-x)
	t_4 = (math.pow(t_3, 2.0) + -1.0) / (t_3 + -1.0)
	tmp = 0
	if t_1 <= 0.0:
		tmp = t_4
	elif t_1 <= 2.0:
		tmp = math.log(math.exp((math.pow(t_2, 2.0) + -1.0))) / (t_2 + -1.0)
	else:
		tmp = t_4
	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)))
	t_1 = Float64(t_0 * exp(Float64(-x)))
	t_2 = expm1(Float64(log(t_0) - x))
	t_3 = expm1(Float64(-x))
	t_4 = Float64(Float64((t_3 ^ 2.0) + -1.0) / Float64(t_3 + -1.0))
	tmp = 0.0
	if (t_1 <= 0.0)
		tmp = t_4;
	elseif (t_1 <= 2.0)
		tmp = Float64(log(exp(Float64((t_2 ^ 2.0) + -1.0))) / Float64(t_2 + -1.0));
	else
		tmp = t_4;
	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]}, Block[{t$95$1 = N[(t$95$0 * N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(Exp[N[(N[Log[t$95$0], $MachinePrecision] - x), $MachinePrecision]] - 1), $MachinePrecision]}, Block[{t$95$3 = N[(Exp[(-x)] - 1), $MachinePrecision]}, Block[{t$95$4 = N[(N[(N[Power[t$95$3, 2.0], $MachinePrecision] + -1.0), $MachinePrecision] / N[(t$95$3 + -1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, 0.0], t$95$4, If[LessEqual[t$95$1, 2.0], N[(N[Log[N[Exp[N[(N[Power[t$95$2, 2.0], $MachinePrecision] + -1.0), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / N[(t$95$2 + -1.0), $MachinePrecision]), $MachinePrecision], t$95$4]]]]]]]
\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)\\
t_1 := t_0 \cdot e^{-x}\\
t_2 := \mathsf{expm1}\left(\log t_0 - x\right)\\
t_3 := \mathsf{expm1}\left(-x\right)\\
t_4 := \frac{{t_3}^{2} + -1}{t_3 + -1}\\
\mathbf{if}\;t_1 \leq 0:\\
\;\;\;\;t_4\\

\mathbf{elif}\;t_1 \leq 2:\\
\;\;\;\;\frac{\log \left(e^{{t_2}^{2} + -1}\right)}{t_2 + -1}\\

\mathbf{else}:\\
\;\;\;\;t_4\\


\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, 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)))): 0 points increase in error, 0 points decrease in error
    3. Applied egg-rr61.8

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

      \[\leadsto \color{blue}{1 + \left(\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}} - 1\right)} \]
      Proof
      (+.f64 1 (-.f64 (/.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 x)) 1)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate--l+_binary64 (-.f64 (+.f64 1 (/.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 x))) 1)): 1 points increase in error, 0 points decrease in error
    5. Applied egg-rr61.8

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

      \[\leadsto \frac{{\left(\mathsf{expm1}\left(\color{blue}{-1 \cdot x}\right)\right)}^{2} - 1}{\mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x\right) - 1} \]
    7. Simplified57.9

      \[\leadsto \frac{{\left(\mathsf{expm1}\left(\color{blue}{-x}\right)\right)}^{2} - 1}{\mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x\right) - 1} \]
      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. Taylor expanded in x around inf 24.2

      \[\leadsto \frac{{\left(\mathsf{expm1}\left(-x\right)\right)}^{2} - 1}{\mathsf{expm1}\left(\color{blue}{-1 \cdot x}\right) - 1} \]
    9. Simplified24.2

      \[\leadsto \frac{{\left(\mathsf{expm1}\left(-x\right)\right)}^{2} - 1}{\mathsf{expm1}\left(\color{blue}{-x}\right) - 1} \]
      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

    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, 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)))): 0 points increase in error, 0 points decrease in error
    3. Applied egg-rr12.7

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

      \[\leadsto \color{blue}{1 + \left(\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}} - 1\right)} \]
      Proof
      (+.f64 1 (-.f64 (/.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 x)) 1)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate--l+_binary64 (-.f64 (+.f64 1 (/.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 x))) 1)): 1 points increase in error, 0 points decrease in error
    5. Applied egg-rr12.6

      \[\leadsto \color{blue}{\frac{{\left(\mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x\right)\right)}^{2} - 1}{\mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x\right) - 1}} \]
    6. Applied egg-rr12.6

      \[\leadsto \frac{\color{blue}{\log \left(e^{{\left(\mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x\right)\right)}^{2} + -1}\right)}}{\mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x\right) - 1} \]
  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:\\ \;\;\;\;\frac{{\left(\mathsf{expm1}\left(-x\right)\right)}^{2} + -1}{\mathsf{expm1}\left(-x\right) + -1}\\ \mathbf{elif}\;\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \leq 2:\\ \;\;\;\;\frac{\log \left(e^{{\left(\mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x\right)\right)}^{2} + -1}\right)}{\mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x\right) + -1}\\ \mathbf{else}:\\ \;\;\;\;\frac{{\left(\mathsf{expm1}\left(-x\right)\right)}^{2} + -1}{\mathsf{expm1}\left(-x\right) + -1}\\ \end{array} \]

Alternatives

Alternative 1
Error23.8
Cost136584
\[\begin{array}{l} t_0 := \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x}\\ t_1 := \mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\mathsf{fma}\left(x, x \cdot -0.25, 1\right)\right)\right) - x\right)\\ t_2 := \mathsf{expm1}\left(-x\right)\\ t_3 := \frac{{t_2}^{2} + -1}{t_2 + -1}\\ \mathbf{if}\;t_0 \leq 0:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t_0 \leq 2:\\ \;\;\;\;\frac{-1 + {t_1}^{2}}{-1 + t_1}\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 2
Error23.8
Cost84872
\[\begin{array}{l} t_0 := \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x}\\ t_1 := \mathsf{expm1}\left(-x\right)\\ t_2 := \frac{{t_1}^{2} + -1}{t_1 + -1}\\ \mathbf{if}\;t_0 \leq 0:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_0 \leq 2:\\ \;\;\;\;1 + \left(-1 + \frac{\left(\left(e^{x}\right) \bmod \left(1 + -0.25 \cdot \left(x \cdot x\right)\right)\right)}{e^{x}}\right)\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error25.0
Cost19840
\[\begin{array}{l} t_0 := \mathsf{expm1}\left(-x\right)\\ \frac{{t_0}^{2} + -1}{t_0 + -1} \end{array} \]
Alternative 4
Error59.8
Cost19456
\[\frac{\left(\left(e^{x}\right) \bmod 1\right)}{e^{x}} \]
Alternative 5
Error60.2
Cost13440
\[\left(1 - x\right) \cdot \left(-1 + \left(1 + \left(\left(e^{x}\right) \bmod 1\right)\right)\right) \]
Alternative 6
Error60.2
Cost13440
\[-1 + \left(1 + \left(\left(e^{x}\right) \bmod 1\right) \cdot \left(1 - x\right)\right) \]
Alternative 7
Error60.2
Cost13184
\[\left(\left(e^{x}\right) \bmod 1\right) \cdot \left(1 - x\right) \]
Alternative 8
Error60.5
Cost12928
\[\left(\left(e^{x}\right) \bmod 1\right) \]

Error

Reproduce

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