expfmod (used to be hard to sample)

Percentage Accurate: 6.5% → 63.2%
Time: 20.0s
Alternatives: 7
Speedup: 4.4×

Specification

?
\[\begin{array}{l} \\ \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \end{array} \]
(FPCore (x) :precision binary64 (* (fmod (exp x) (sqrt (cos x))) (exp (- x))))
double code(double x) {
	return fmod(exp(x), sqrt(cos(x))) * exp(-x);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = mod(exp(x), sqrt(cos(x))) * exp(-x)
end function
def code(x):
	return math.fmod(math.exp(x), math.sqrt(math.cos(x))) * math.exp(-x)
function code(x)
	return Float64(rem(exp(x), sqrt(cos(x))) * exp(Float64(-x)))
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]
\begin{array}{l}

\\
\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 7 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 6.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \end{array} \]
(FPCore (x) :precision binary64 (* (fmod (exp x) (sqrt (cos x))) (exp (- x))))
double code(double x) {
	return fmod(exp(x), sqrt(cos(x))) * exp(-x);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = mod(exp(x), sqrt(cos(x))) * exp(-x)
end function
def code(x):
	return math.fmod(math.exp(x), math.sqrt(math.cos(x))) * math.exp(-x)
function code(x)
	return Float64(rem(exp(x), sqrt(cos(x))) * exp(Float64(-x)))
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]
\begin{array}{l}

\\
\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x}
\end{array}

Alternative 1: 63.2% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\ \;\;\;\;\frac{\left(\left(x + 1\right) \bmod \left(\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos x \cdot 0.6666666666666666\right)\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\left(x + 1\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x -5e-310)
   (/
    (fmod
     (+ x 1.0)
     (sqrt
      (+
       (expm1 (log1p (* (cos x) 0.6666666666666666)))
       (log (cbrt (exp (cos x)))))))
    (+ x 1.0))
   (/ (fmod (+ x 1.0) (sqrt (cos x))) (exp x))))
double code(double x) {
	double tmp;
	if (x <= -5e-310) {
		tmp = fmod((x + 1.0), sqrt((expm1(log1p((cos(x) * 0.6666666666666666))) + log(cbrt(exp(cos(x))))))) / (x + 1.0);
	} else {
		tmp = fmod((x + 1.0), sqrt(cos(x))) / exp(x);
	}
	return tmp;
}
function code(x)
	tmp = 0.0
	if (x <= -5e-310)
		tmp = Float64(rem(Float64(x + 1.0), sqrt(Float64(expm1(log1p(Float64(cos(x) * 0.6666666666666666))) + log(cbrt(exp(cos(x))))))) / Float64(x + 1.0));
	else
		tmp = Float64(rem(Float64(x + 1.0), sqrt(cos(x))) / exp(x));
	end
	return tmp
end
code[x_] := If[LessEqual[x, -5e-310], N[(N[With[{TMP1 = N[(x + 1.0), $MachinePrecision], TMP2 = N[Sqrt[N[(N[(Exp[N[Log[1 + N[(N[Cos[x], $MachinePrecision] * 0.6666666666666666), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision] + N[Log[N[Power[N[Exp[N[Cos[x], $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[With[{TMP1 = N[(x + 1.0), $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{\left(\left(x + 1\right) \bmod \left(\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos x \cdot 0.6666666666666666\right)\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{x + 1}\\

\mathbf{else}:\\
\;\;\;\;\frac{\left(\left(x + 1\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -4.999999999999985e-310

    1. Initial program 5.1%

      \[\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \]
    2. Step-by-step derivation
      1. /-rgt-identity5.1%

        \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{1}} \cdot e^{-x} \]
      2. associate-/r/5.1%

        \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{\frac{1}{e^{-x}}}} \]
      3. exp-neg5.1%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{\color{blue}{e^{-\left(-x\right)}}} \]
      4. remove-double-neg5.1%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{\color{blue}{x}}} \]
    3. Simplified5.1%

      \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. add-log-exp5.1%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\color{blue}{\log \left(e^{\cos x}\right)}}\right)\right)}{e^{x}} \]
      2. add-cube-cbrt97.9%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\log \color{blue}{\left(\left(\sqrt[3]{e^{\cos x}} \cdot \sqrt[3]{e^{\cos x}}\right) \cdot \sqrt[3]{e^{\cos x}}\right)}}\right)\right)}{e^{x}} \]
      3. log-prod97.9%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\color{blue}{\log \left(\sqrt[3]{e^{\cos x}} \cdot \sqrt[3]{e^{\cos x}}\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}}\right)\right)}{e^{x}} \]
      4. pow297.9%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\log \color{blue}{\left({\left(\sqrt[3]{e^{\cos x}}\right)}^{2}\right)} + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
    6. Applied egg-rr97.9%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\color{blue}{\log \left({\left(\sqrt[3]{e^{\cos x}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}}\right)\right)}{e^{x}} \]
    7. Step-by-step derivation
      1. expm1-log1p-u97.9%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\log \left({\left(\sqrt[3]{e^{\cos x}}\right)}^{2}\right)\right)\right)} + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
      2. expm1-undefine97.9%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\color{blue}{\left(e^{\mathsf{log1p}\left(\log \left({\left(\sqrt[3]{e^{\cos x}}\right)}^{2}\right)\right)} - 1\right)} + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
      3. log-pow97.9%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\left(e^{\mathsf{log1p}\left(\color{blue}{2 \cdot \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)} - 1\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
      4. pow1/397.9%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\left(e^{\mathsf{log1p}\left(2 \cdot \log \color{blue}{\left({\left(e^{\cos x}\right)}^{0.3333333333333333}\right)}\right)} - 1\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
      5. log-pow97.9%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\left(e^{\mathsf{log1p}\left(2 \cdot \color{blue}{\left(0.3333333333333333 \cdot \log \left(e^{\cos x}\right)\right)}\right)} - 1\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
      6. add-log-exp97.9%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\left(e^{\mathsf{log1p}\left(2 \cdot \left(0.3333333333333333 \cdot \color{blue}{\cos x}\right)\right)} - 1\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
    8. Applied egg-rr97.9%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\color{blue}{\left(e^{\mathsf{log1p}\left(2 \cdot \left(0.3333333333333333 \cdot \cos x\right)\right)} - 1\right)} + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
    9. Step-by-step derivation
      1. expm1-define97.9%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(2 \cdot \left(0.3333333333333333 \cdot \cos x\right)\right)\right)} + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
      2. count-297.9%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{0.3333333333333333 \cdot \cos x + 0.3333333333333333 \cdot \cos x}\right)\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
      3. distribute-rgt-out97.9%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\cos x \cdot \left(0.3333333333333333 + 0.3333333333333333\right)}\right)\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
      4. metadata-eval97.9%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos x \cdot \color{blue}{0.6666666666666666}\right)\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
    10. Simplified97.9%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos x \cdot 0.6666666666666666\right)\right)} + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
    11. Taylor expanded in x around 0 97.5%

      \[\leadsto \frac{\left(\color{blue}{\left(1 + x\right)} \bmod \left(\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos x \cdot 0.6666666666666666\right)\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
    12. Step-by-step derivation
      1. +-commutative97.5%

        \[\leadsto \frac{\left(\color{blue}{\left(x + 1\right)} \bmod \left(\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos x \cdot 0.6666666666666666\right)\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
    13. Simplified97.5%

      \[\leadsto \frac{\left(\color{blue}{\left(x + 1\right)} \bmod \left(\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos x \cdot 0.6666666666666666\right)\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
    14. Taylor expanded in x around 0 98.1%

      \[\leadsto \frac{\left(\left(x + 1\right) \bmod \left(\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos x \cdot 0.6666666666666666\right)\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{\color{blue}{1 + x}} \]
    15. Step-by-step derivation
      1. +-commutative97.5%

        \[\leadsto \frac{\left(\color{blue}{\left(x + 1\right)} \bmod \left(\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos x \cdot 0.6666666666666666\right)\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
    16. Simplified98.1%

      \[\leadsto \frac{\left(\left(x + 1\right) \bmod \left(\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos x \cdot 0.6666666666666666\right)\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{\color{blue}{x + 1}} \]

    if -4.999999999999985e-310 < x

    1. Initial program 5.2%

      \[\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \]
    2. Step-by-step derivation
      1. /-rgt-identity5.2%

        \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{1}} \cdot e^{-x} \]
      2. associate-/r/5.2%

        \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{\frac{1}{e^{-x}}}} \]
      3. exp-neg5.2%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{\color{blue}{e^{-\left(-x\right)}}} \]
      4. remove-double-neg5.2%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{\color{blue}{x}}} \]
    3. Simplified5.2%

      \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 36.4%

      \[\leadsto \frac{\left(\color{blue}{\left(1 + x\right)} \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}} \]
    6. Step-by-step derivation
      1. +-commutative36.0%

        \[\leadsto \frac{\left(\color{blue}{\left(x + 1\right)} \bmod \left(\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos x \cdot 0.6666666666666666\right)\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
    7. Simplified36.4%

      \[\leadsto \frac{\left(\color{blue}{\left(x + 1\right)} \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 2: 62.5% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \frac{\left(\left(x + 1\right) \bmod \left(\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos x \cdot 0.6666666666666666\right)\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \end{array} \]
(FPCore (x)
 :precision binary64
 (/
  (fmod
   (+ x 1.0)
   (sqrt
    (+
     (expm1 (log1p (* (cos x) 0.6666666666666666)))
     (log (cbrt (exp (cos x)))))))
  (exp x)))
double code(double x) {
	return fmod((x + 1.0), sqrt((expm1(log1p((cos(x) * 0.6666666666666666))) + log(cbrt(exp(cos(x))))))) / exp(x);
}
function code(x)
	return Float64(rem(Float64(x + 1.0), sqrt(Float64(expm1(log1p(Float64(cos(x) * 0.6666666666666666))) + log(cbrt(exp(cos(x))))))) / exp(x))
end
code[x_] := N[(N[With[{TMP1 = N[(x + 1.0), $MachinePrecision], TMP2 = N[Sqrt[N[(N[(Exp[N[Log[1 + N[(N[Cos[x], $MachinePrecision] * 0.6666666666666666), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision] + N[Log[N[Power[N[Exp[N[Cos[x], $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\left(\left(x + 1\right) \bmod \left(\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos x \cdot 0.6666666666666666\right)\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}}
\end{array}
Derivation
  1. Initial program 5.2%

    \[\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \]
  2. Step-by-step derivation
    1. /-rgt-identity5.2%

      \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{1}} \cdot e^{-x} \]
    2. associate-/r/5.2%

      \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{\frac{1}{e^{-x}}}} \]
    3. exp-neg5.2%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{\color{blue}{e^{-\left(-x\right)}}} \]
    4. remove-double-neg5.2%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{\color{blue}{x}}} \]
  3. Simplified5.2%

    \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. add-log-exp5.2%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\color{blue}{\log \left(e^{\cos x}\right)}}\right)\right)}{e^{x}} \]
    2. add-cube-cbrt39.1%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\log \color{blue}{\left(\left(\sqrt[3]{e^{\cos x}} \cdot \sqrt[3]{e^{\cos x}}\right) \cdot \sqrt[3]{e^{\cos x}}\right)}}\right)\right)}{e^{x}} \]
    3. log-prod39.1%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\color{blue}{\log \left(\sqrt[3]{e^{\cos x}} \cdot \sqrt[3]{e^{\cos x}}\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}}\right)\right)}{e^{x}} \]
    4. pow239.1%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\log \color{blue}{\left({\left(\sqrt[3]{e^{\cos x}}\right)}^{2}\right)} + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
  6. Applied egg-rr39.1%

    \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\color{blue}{\log \left({\left(\sqrt[3]{e^{\cos x}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}}\right)\right)}{e^{x}} \]
  7. Step-by-step derivation
    1. expm1-log1p-u39.1%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\log \left({\left(\sqrt[3]{e^{\cos x}}\right)}^{2}\right)\right)\right)} + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
    2. expm1-undefine39.0%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\color{blue}{\left(e^{\mathsf{log1p}\left(\log \left({\left(\sqrt[3]{e^{\cos x}}\right)}^{2}\right)\right)} - 1\right)} + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
    3. log-pow39.0%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\left(e^{\mathsf{log1p}\left(\color{blue}{2 \cdot \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)} - 1\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
    4. pow1/339.1%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\left(e^{\mathsf{log1p}\left(2 \cdot \log \color{blue}{\left({\left(e^{\cos x}\right)}^{0.3333333333333333}\right)}\right)} - 1\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
    5. log-pow39.1%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\left(e^{\mathsf{log1p}\left(2 \cdot \color{blue}{\left(0.3333333333333333 \cdot \log \left(e^{\cos x}\right)\right)}\right)} - 1\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
    6. add-log-exp39.1%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\left(e^{\mathsf{log1p}\left(2 \cdot \left(0.3333333333333333 \cdot \color{blue}{\cos x}\right)\right)} - 1\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
  8. Applied egg-rr39.1%

    \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\color{blue}{\left(e^{\mathsf{log1p}\left(2 \cdot \left(0.3333333333333333 \cdot \cos x\right)\right)} - 1\right)} + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
  9. Step-by-step derivation
    1. expm1-define39.1%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(2 \cdot \left(0.3333333333333333 \cdot \cos x\right)\right)\right)} + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
    2. count-239.1%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{0.3333333333333333 \cdot \cos x + 0.3333333333333333 \cdot \cos x}\right)\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
    3. distribute-rgt-out39.1%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\cos x \cdot \left(0.3333333333333333 + 0.3333333333333333\right)}\right)\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
    4. metadata-eval39.1%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos x \cdot \color{blue}{0.6666666666666666}\right)\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
  10. Simplified39.1%

    \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos x \cdot 0.6666666666666666\right)\right)} + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
  11. Taylor expanded in x around 0 58.6%

    \[\leadsto \frac{\left(\color{blue}{\left(1 + x\right)} \bmod \left(\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos x \cdot 0.6666666666666666\right)\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
  12. Step-by-step derivation
    1. +-commutative58.6%

      \[\leadsto \frac{\left(\color{blue}{\left(x + 1\right)} \bmod \left(\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos x \cdot 0.6666666666666666\right)\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
  13. Simplified58.6%

    \[\leadsto \frac{\left(\color{blue}{\left(x + 1\right)} \bmod \left(\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos x \cdot 0.6666666666666666\right)\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
  14. Add Preprocessing

Alternative 3: 62.8% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt{\cos x}\\ \mathbf{if}\;x \leq 100:\\ \;\;\;\;\frac{\left(\left(\frac{{e}^{\left(x + 1\right)}}{{\left(\sqrt{e}\right)}^{2}}\right) \bmod t\_0\right)}{e^{x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\left(x + 1\right) \bmod t\_0\right)}{e^{x}}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (sqrt (cos x))))
   (if (<= x 100.0)
     (/ (fmod (/ (pow E (+ x 1.0)) (pow (sqrt E) 2.0)) t_0) (exp x))
     (/ (fmod (+ x 1.0) t_0) (exp x)))))
double code(double x) {
	double t_0 = sqrt(cos(x));
	double tmp;
	if (x <= 100.0) {
		tmp = fmod((pow(((double) M_E), (x + 1.0)) / pow(sqrt(((double) M_E)), 2.0)), t_0) / exp(x);
	} else {
		tmp = fmod((x + 1.0), t_0) / exp(x);
	}
	return tmp;
}
def code(x):
	t_0 = math.sqrt(math.cos(x))
	tmp = 0
	if x <= 100.0:
		tmp = math.fmod((math.pow(math.e, (x + 1.0)) / math.pow(math.sqrt(math.e), 2.0)), t_0) / math.exp(x)
	else:
		tmp = math.fmod((x + 1.0), t_0) / math.exp(x)
	return tmp
function code(x)
	t_0 = sqrt(cos(x))
	tmp = 0.0
	if (x <= 100.0)
		tmp = Float64(rem(Float64((exp(1) ^ Float64(x + 1.0)) / (sqrt(exp(1)) ^ 2.0)), t_0) / exp(x));
	else
		tmp = Float64(rem(Float64(x + 1.0), t_0) / exp(x));
	end
	return tmp
end
code[x_] := Block[{t$95$0 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, 100.0], N[(N[With[{TMP1 = N[(N[Power[E, N[(x + 1.0), $MachinePrecision]], $MachinePrecision] / N[Power[N[Sqrt[E], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], TMP2 = t$95$0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision], N[(N[With[{TMP1 = N[(x + 1.0), $MachinePrecision], TMP2 = t$95$0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sqrt{\cos x}\\
\mathbf{if}\;x \leq 100:\\
\;\;\;\;\frac{\left(\left(\frac{{e}^{\left(x + 1\right)}}{{\left(\sqrt{e}\right)}^{2}}\right) \bmod t\_0\right)}{e^{x}}\\

\mathbf{else}:\\
\;\;\;\;\frac{\left(\left(x + 1\right) \bmod t\_0\right)}{e^{x}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 100

    1. Initial program 6.4%

      \[\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \]
    2. Step-by-step derivation
      1. /-rgt-identity6.4%

        \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{1}} \cdot e^{-x} \]
      2. associate-/r/6.4%

        \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{\frac{1}{e^{-x}}}} \]
      3. exp-neg6.4%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{\color{blue}{e^{-\left(-x\right)}}} \]
      4. remove-double-neg6.4%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{\color{blue}{x}}} \]
    3. Simplified6.4%

      \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. *-un-lft-identity6.4%

        \[\leadsto \frac{\left(\left(e^{\color{blue}{1 \cdot x}}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}} \]
      2. exp-prod6.4%

        \[\leadsto \frac{\left(\color{blue}{\left({\left(e^{1}\right)}^{x}\right)} \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}} \]
      3. expm1-log1p-u6.4%

        \[\leadsto \frac{\left(\left({\left(e^{1}\right)}^{\color{blue}{\left(\mathsf{expm1}\left(\mathsf{log1p}\left(x\right)\right)\right)}}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}} \]
      4. expm1-undefine6.4%

        \[\leadsto \frac{\left(\left({\left(e^{1}\right)}^{\color{blue}{\left(e^{\mathsf{log1p}\left(x\right)} - 1\right)}}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}} \]
      5. pow-sub6.4%

        \[\leadsto \frac{\left(\color{blue}{\left(\frac{{\left(e^{1}\right)}^{\left(e^{\mathsf{log1p}\left(x\right)}\right)}}{{\left(e^{1}\right)}^{1}}\right)} \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}} \]
      6. pow16.4%

        \[\leadsto \frac{\left(\left(\frac{{\left(e^{1}\right)}^{\left(e^{\mathsf{log1p}\left(x\right)}\right)}}{\color{blue}{e^{1}}}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}} \]
    6. Applied egg-rr6.4%

      \[\leadsto \frac{\left(\color{blue}{\left(\frac{{\left(e^{1}\right)}^{\left(e^{\mathsf{log1p}\left(x\right)}\right)}}{e^{1}}\right)} \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}} \]
    7. Step-by-step derivation
      1. exp-1-e6.4%

        \[\leadsto \frac{\left(\left(\frac{{\color{blue}{e}}^{\left(e^{\mathsf{log1p}\left(x\right)}\right)}}{e^{1}}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}} \]
      2. log1p-undefine6.4%

        \[\leadsto \frac{\left(\left(\frac{{e}^{\left(e^{\color{blue}{\log \left(1 + x\right)}}\right)}}{e^{1}}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}} \]
      3. rem-exp-log6.4%

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

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

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

      \[\leadsto \frac{\left(\color{blue}{\left(\frac{{e}^{\left(x + 1\right)}}{e}\right)} \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}} \]
    9. Step-by-step derivation
      1. add-sqr-sqrt48.2%

        \[\leadsto \frac{\left(\left(\frac{{e}^{\left(x + 1\right)}}{\color{blue}{\sqrt{e} \cdot \sqrt{e}}}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}} \]
      2. pow248.2%

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

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

    if 100 < x

    1. Initial program 0.4%

      \[\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \]
    2. Step-by-step derivation
      1. /-rgt-identity0.4%

        \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{1}} \cdot e^{-x} \]
      2. associate-/r/0.4%

        \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{\frac{1}{e^{-x}}}} \]
      3. exp-neg0.4%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{\color{blue}{e^{-\left(-x\right)}}} \]
      4. remove-double-neg0.4%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{\color{blue}{x}}} \]
    3. Simplified0.4%

      \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 98.5%

      \[\leadsto \frac{\left(\color{blue}{\left(1 + x\right)} \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}} \]
    6. Step-by-step derivation
      1. +-commutative98.5%

        \[\leadsto \frac{\left(\color{blue}{\left(x + 1\right)} \bmod \left(\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos x \cdot 0.6666666666666666\right)\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
    7. Simplified98.5%

      \[\leadsto \frac{\left(\color{blue}{\left(x + 1\right)} \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 32.3% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 0.86:\\ \;\;\;\;\frac{\left(\left(x \cdot \left(1 + \frac{1}{x}\right)\right) \bmod \left(1 + -0.25 \cdot {x}^{2}\right)\right)}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\left(x + 1\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x 0.86)
   (/ (fmod (* x (+ 1.0 (/ 1.0 x))) (+ 1.0 (* -0.25 (pow x 2.0)))) (+ x 1.0))
   (/ (fmod (+ x 1.0) (sqrt (cos x))) (exp x))))
double code(double x) {
	double tmp;
	if (x <= 0.86) {
		tmp = fmod((x * (1.0 + (1.0 / x))), (1.0 + (-0.25 * pow(x, 2.0)))) / (x + 1.0);
	} else {
		tmp = fmod((x + 1.0), sqrt(cos(x))) / exp(x);
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= 0.86d0) then
        tmp = mod((x * (1.0d0 + (1.0d0 / x))), (1.0d0 + ((-0.25d0) * (x ** 2.0d0)))) / (x + 1.0d0)
    else
        tmp = mod((x + 1.0d0), sqrt(cos(x))) / exp(x)
    end if
    code = tmp
end function
def code(x):
	tmp = 0
	if x <= 0.86:
		tmp = math.fmod((x * (1.0 + (1.0 / x))), (1.0 + (-0.25 * math.pow(x, 2.0)))) / (x + 1.0)
	else:
		tmp = math.fmod((x + 1.0), math.sqrt(math.cos(x))) / math.exp(x)
	return tmp
function code(x)
	tmp = 0.0
	if (x <= 0.86)
		tmp = Float64(rem(Float64(x * Float64(1.0 + Float64(1.0 / x))), Float64(1.0 + Float64(-0.25 * (x ^ 2.0)))) / Float64(x + 1.0));
	else
		tmp = Float64(rem(Float64(x + 1.0), sqrt(cos(x))) / exp(x));
	end
	return tmp
end
code[x_] := If[LessEqual[x, 0.86], N[(N[With[{TMP1 = N[(x * N[(1.0 + N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], TMP2 = N[(1.0 + N[(-0.25 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[With[{TMP1 = N[(x + 1.0), $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.86:\\
\;\;\;\;\frac{\left(\left(x \cdot \left(1 + \frac{1}{x}\right)\right) \bmod \left(1 + -0.25 \cdot {x}^{2}\right)\right)}{x + 1}\\

\mathbf{else}:\\
\;\;\;\;\frac{\left(\left(x + 1\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 0.859999999999999987

    1. Initial program 6.4%

      \[\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \]
    2. Step-by-step derivation
      1. /-rgt-identity6.4%

        \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{1}} \cdot e^{-x} \]
      2. associate-/r/6.4%

        \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{\frac{1}{e^{-x}}}} \]
      3. exp-neg6.4%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{\color{blue}{e^{-\left(-x\right)}}} \]
      4. remove-double-neg6.4%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{\color{blue}{x}}} \]
    3. Simplified6.4%

      \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 6.0%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{\color{blue}{1 + x}} \]
    6. Step-by-step derivation
      1. +-commutative48.4%

        \[\leadsto \frac{\left(\color{blue}{\left(x + 1\right)} \bmod \left(\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos x \cdot 0.6666666666666666\right)\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
    7. Simplified6.0%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{\color{blue}{x + 1}} \]
    8. Taylor expanded in x around 0 6.3%

      \[\leadsto \frac{\left(\color{blue}{\left(1 + x\right)} \bmod \left(\sqrt{\cos x}\right)\right)}{x + 1} \]
    9. Step-by-step derivation
      1. +-commutative48.4%

        \[\leadsto \frac{\left(\color{blue}{\left(x + 1\right)} \bmod \left(\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos x \cdot 0.6666666666666666\right)\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
    10. Simplified6.3%

      \[\leadsto \frac{\left(\color{blue}{\left(x + 1\right)} \bmod \left(\sqrt{\cos x}\right)\right)}{x + 1} \]
    11. Taylor expanded in x around 0 7.1%

      \[\leadsto \frac{\left(\left(x + 1\right) \bmod \color{blue}{\left(1 + -0.25 \cdot {x}^{2}\right)}\right)}{x + 1} \]
    12. Taylor expanded in x around inf 15.5%

      \[\leadsto \frac{\left(\color{blue}{\left(x \cdot \left(1 + \frac{1}{x}\right)\right)} \bmod \left(1 + -0.25 \cdot {x}^{2}\right)\right)}{x + 1} \]

    if 0.859999999999999987 < x

    1. Initial program 0.4%

      \[\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \]
    2. Step-by-step derivation
      1. /-rgt-identity0.4%

        \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{1}} \cdot e^{-x} \]
      2. associate-/r/0.4%

        \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{\frac{1}{e^{-x}}}} \]
      3. exp-neg0.4%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{\color{blue}{e^{-\left(-x\right)}}} \]
      4. remove-double-neg0.4%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{\color{blue}{x}}} \]
    3. Simplified0.4%

      \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 98.5%

      \[\leadsto \frac{\left(\color{blue}{\left(1 + x\right)} \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}} \]
    6. Step-by-step derivation
      1. +-commutative98.5%

        \[\leadsto \frac{\left(\color{blue}{\left(x + 1\right)} \bmod \left(\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos x \cdot 0.6666666666666666\right)\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
    7. Simplified98.5%

      \[\leadsto \frac{\left(\color{blue}{\left(x + 1\right)} \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 5: 32.2% accurate, 1.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 1 + -0.25 \cdot {x}^{2}\\ \mathbf{if}\;x \leq 0.86:\\ \;\;\;\;\frac{\left(\left(x \cdot \left(1 + \frac{1}{x}\right)\right) \bmod t\_0\right)}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\left(x + 1\right) \bmod t\_0\right)}{e^{x}}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (+ 1.0 (* -0.25 (pow x 2.0)))))
   (if (<= x 0.86)
     (/ (fmod (* x (+ 1.0 (/ 1.0 x))) t_0) (+ x 1.0))
     (/ (fmod (+ x 1.0) t_0) (exp x)))))
double code(double x) {
	double t_0 = 1.0 + (-0.25 * pow(x, 2.0));
	double tmp;
	if (x <= 0.86) {
		tmp = fmod((x * (1.0 + (1.0 / x))), t_0) / (x + 1.0);
	} else {
		tmp = fmod((x + 1.0), t_0) / exp(x);
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: t_0
    real(8) :: tmp
    t_0 = 1.0d0 + ((-0.25d0) * (x ** 2.0d0))
    if (x <= 0.86d0) then
        tmp = mod((x * (1.0d0 + (1.0d0 / x))), t_0) / (x + 1.0d0)
    else
        tmp = mod((x + 1.0d0), t_0) / exp(x)
    end if
    code = tmp
end function
def code(x):
	t_0 = 1.0 + (-0.25 * math.pow(x, 2.0))
	tmp = 0
	if x <= 0.86:
		tmp = math.fmod((x * (1.0 + (1.0 / x))), t_0) / (x + 1.0)
	else:
		tmp = math.fmod((x + 1.0), t_0) / math.exp(x)
	return tmp
function code(x)
	t_0 = Float64(1.0 + Float64(-0.25 * (x ^ 2.0)))
	tmp = 0.0
	if (x <= 0.86)
		tmp = Float64(rem(Float64(x * Float64(1.0 + Float64(1.0 / x))), t_0) / Float64(x + 1.0));
	else
		tmp = Float64(rem(Float64(x + 1.0), t_0) / exp(x));
	end
	return tmp
end
code[x_] := Block[{t$95$0 = N[(1.0 + N[(-0.25 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 0.86], N[(N[With[{TMP1 = N[(x * N[(1.0 + N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], TMP2 = t$95$0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[With[{TMP1 = N[(x + 1.0), $MachinePrecision], TMP2 = t$95$0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 1 + -0.25 \cdot {x}^{2}\\
\mathbf{if}\;x \leq 0.86:\\
\;\;\;\;\frac{\left(\left(x \cdot \left(1 + \frac{1}{x}\right)\right) \bmod t\_0\right)}{x + 1}\\

\mathbf{else}:\\
\;\;\;\;\frac{\left(\left(x + 1\right) \bmod t\_0\right)}{e^{x}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 0.859999999999999987

    1. Initial program 6.4%

      \[\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \]
    2. Step-by-step derivation
      1. /-rgt-identity6.4%

        \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{1}} \cdot e^{-x} \]
      2. associate-/r/6.4%

        \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{\frac{1}{e^{-x}}}} \]
      3. exp-neg6.4%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{\color{blue}{e^{-\left(-x\right)}}} \]
      4. remove-double-neg6.4%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{\color{blue}{x}}} \]
    3. Simplified6.4%

      \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 6.0%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{\color{blue}{1 + x}} \]
    6. Step-by-step derivation
      1. +-commutative48.4%

        \[\leadsto \frac{\left(\color{blue}{\left(x + 1\right)} \bmod \left(\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos x \cdot 0.6666666666666666\right)\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
    7. Simplified6.0%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{\color{blue}{x + 1}} \]
    8. Taylor expanded in x around 0 6.3%

      \[\leadsto \frac{\left(\color{blue}{\left(1 + x\right)} \bmod \left(\sqrt{\cos x}\right)\right)}{x + 1} \]
    9. Step-by-step derivation
      1. +-commutative48.4%

        \[\leadsto \frac{\left(\color{blue}{\left(x + 1\right)} \bmod \left(\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos x \cdot 0.6666666666666666\right)\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
    10. Simplified6.3%

      \[\leadsto \frac{\left(\color{blue}{\left(x + 1\right)} \bmod \left(\sqrt{\cos x}\right)\right)}{x + 1} \]
    11. Taylor expanded in x around 0 7.1%

      \[\leadsto \frac{\left(\left(x + 1\right) \bmod \color{blue}{\left(1 + -0.25 \cdot {x}^{2}\right)}\right)}{x + 1} \]
    12. Taylor expanded in x around inf 15.5%

      \[\leadsto \frac{\left(\color{blue}{\left(x \cdot \left(1 + \frac{1}{x}\right)\right)} \bmod \left(1 + -0.25 \cdot {x}^{2}\right)\right)}{x + 1} \]

    if 0.859999999999999987 < x

    1. Initial program 0.4%

      \[\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \]
    2. Step-by-step derivation
      1. /-rgt-identity0.4%

        \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{1}} \cdot e^{-x} \]
      2. associate-/r/0.4%

        \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{\frac{1}{e^{-x}}}} \]
      3. exp-neg0.4%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{\color{blue}{e^{-\left(-x\right)}}} \]
      4. remove-double-neg0.4%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{\color{blue}{x}}} \]
    3. Simplified0.4%

      \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 0.3%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \color{blue}{\left(1 + -0.25 \cdot {x}^{2}\right)}\right)}{e^{x}} \]
    6. Taylor expanded in x around 0 98.3%

      \[\leadsto \frac{\left(\color{blue}{\left(1 + x\right)} \bmod \left(1 + -0.25 \cdot {x}^{2}\right)\right)}{e^{x}} \]
    7. Step-by-step derivation
      1. +-commutative98.5%

        \[\leadsto \frac{\left(\color{blue}{\left(x + 1\right)} \bmod \left(\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos x \cdot 0.6666666666666666\right)\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
    8. Simplified98.3%

      \[\leadsto \frac{\left(\color{blue}{\left(x + 1\right)} \bmod \left(1 + -0.25 \cdot {x}^{2}\right)\right)}{e^{x}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 6: 12.8% accurate, 2.3× speedup?

\[\begin{array}{l} \\ \frac{\left(\left(x \cdot \left(1 + \frac{1}{x}\right)\right) \bmod \left(1 + -0.25 \cdot {x}^{2}\right)\right)}{x + 1} \end{array} \]
(FPCore (x)
 :precision binary64
 (/ (fmod (* x (+ 1.0 (/ 1.0 x))) (+ 1.0 (* -0.25 (pow x 2.0)))) (+ x 1.0)))
double code(double x) {
	return fmod((x * (1.0 + (1.0 / x))), (1.0 + (-0.25 * pow(x, 2.0)))) / (x + 1.0);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = mod((x * (1.0d0 + (1.0d0 / x))), (1.0d0 + ((-0.25d0) * (x ** 2.0d0)))) / (x + 1.0d0)
end function
def code(x):
	return math.fmod((x * (1.0 + (1.0 / x))), (1.0 + (-0.25 * math.pow(x, 2.0)))) / (x + 1.0)
function code(x)
	return Float64(rem(Float64(x * Float64(1.0 + Float64(1.0 / x))), Float64(1.0 + Float64(-0.25 * (x ^ 2.0)))) / Float64(x + 1.0))
end
code[x_] := N[(N[With[{TMP1 = N[(x * N[(1.0 + N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], TMP2 = N[(1.0 + N[(-0.25 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\left(\left(x \cdot \left(1 + \frac{1}{x}\right)\right) \bmod \left(1 + -0.25 \cdot {x}^{2}\right)\right)}{x + 1}
\end{array}
Derivation
  1. Initial program 5.2%

    \[\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \]
  2. Step-by-step derivation
    1. /-rgt-identity5.2%

      \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{1}} \cdot e^{-x} \]
    2. associate-/r/5.2%

      \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{\frac{1}{e^{-x}}}} \]
    3. exp-neg5.2%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{\color{blue}{e^{-\left(-x\right)}}} \]
    4. remove-double-neg5.2%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{\color{blue}{x}}} \]
  3. Simplified5.2%

    \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}} \]
  4. Add Preprocessing
  5. Taylor expanded in x around 0 4.8%

    \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{\color{blue}{1 + x}} \]
  6. Step-by-step derivation
    1. +-commutative58.6%

      \[\leadsto \frac{\left(\color{blue}{\left(x + 1\right)} \bmod \left(\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos x \cdot 0.6666666666666666\right)\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
  7. Simplified4.8%

    \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{\color{blue}{x + 1}} \]
  8. Taylor expanded in x around 0 6.2%

    \[\leadsto \frac{\left(\color{blue}{\left(1 + x\right)} \bmod \left(\sqrt{\cos x}\right)\right)}{x + 1} \]
  9. Step-by-step derivation
    1. +-commutative58.6%

      \[\leadsto \frac{\left(\color{blue}{\left(x + 1\right)} \bmod \left(\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos x \cdot 0.6666666666666666\right)\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
  10. Simplified6.2%

    \[\leadsto \frac{\left(\color{blue}{\left(x + 1\right)} \bmod \left(\sqrt{\cos x}\right)\right)}{x + 1} \]
  11. Taylor expanded in x around 0 6.3%

    \[\leadsto \frac{\left(\left(x + 1\right) \bmod \color{blue}{\left(1 + -0.25 \cdot {x}^{2}\right)}\right)}{x + 1} \]
  12. Taylor expanded in x around inf 13.0%

    \[\leadsto \frac{\left(\color{blue}{\left(x \cdot \left(1 + \frac{1}{x}\right)\right)} \bmod \left(1 + -0.25 \cdot {x}^{2}\right)\right)}{x + 1} \]
  13. Add Preprocessing

Alternative 7: 7.3% accurate, 4.4× speedup?

\[\begin{array}{l} \\ \frac{\left(\left(x + 1\right) \bmod \left(1 + -0.25 \cdot \left(x \cdot x\right)\right)\right)}{x + 1} \end{array} \]
(FPCore (x)
 :precision binary64
 (/ (fmod (+ x 1.0) (+ 1.0 (* -0.25 (* x x)))) (+ x 1.0)))
double code(double x) {
	return fmod((x + 1.0), (1.0 + (-0.25 * (x * x)))) / (x + 1.0);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = mod((x + 1.0d0), (1.0d0 + ((-0.25d0) * (x * x)))) / (x + 1.0d0)
end function
def code(x):
	return math.fmod((x + 1.0), (1.0 + (-0.25 * (x * x)))) / (x + 1.0)
function code(x)
	return Float64(rem(Float64(x + 1.0), Float64(1.0 + Float64(-0.25 * Float64(x * x)))) / Float64(x + 1.0))
end
code[x_] := N[(N[With[{TMP1 = N[(x + 1.0), $MachinePrecision], TMP2 = N[(1.0 + N[(-0.25 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\left(\left(x + 1\right) \bmod \left(1 + -0.25 \cdot \left(x \cdot x\right)\right)\right)}{x + 1}
\end{array}
Derivation
  1. Initial program 5.2%

    \[\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \]
  2. Step-by-step derivation
    1. /-rgt-identity5.2%

      \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{1}} \cdot e^{-x} \]
    2. associate-/r/5.2%

      \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{\frac{1}{e^{-x}}}} \]
    3. exp-neg5.2%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{\color{blue}{e^{-\left(-x\right)}}} \]
    4. remove-double-neg5.2%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{\color{blue}{x}}} \]
  3. Simplified5.2%

    \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}} \]
  4. Add Preprocessing
  5. Taylor expanded in x around 0 4.8%

    \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{\color{blue}{1 + x}} \]
  6. Step-by-step derivation
    1. +-commutative58.6%

      \[\leadsto \frac{\left(\color{blue}{\left(x + 1\right)} \bmod \left(\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos x \cdot 0.6666666666666666\right)\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
  7. Simplified4.8%

    \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{\color{blue}{x + 1}} \]
  8. Taylor expanded in x around 0 6.2%

    \[\leadsto \frac{\left(\color{blue}{\left(1 + x\right)} \bmod \left(\sqrt{\cos x}\right)\right)}{x + 1} \]
  9. Step-by-step derivation
    1. +-commutative58.6%

      \[\leadsto \frac{\left(\color{blue}{\left(x + 1\right)} \bmod \left(\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos x \cdot 0.6666666666666666\right)\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}} \]
  10. Simplified6.2%

    \[\leadsto \frac{\left(\color{blue}{\left(x + 1\right)} \bmod \left(\sqrt{\cos x}\right)\right)}{x + 1} \]
  11. Taylor expanded in x around 0 6.3%

    \[\leadsto \frac{\left(\left(x + 1\right) \bmod \color{blue}{\left(1 + -0.25 \cdot {x}^{2}\right)}\right)}{x + 1} \]
  12. Step-by-step derivation
    1. unpow26.3%

      \[\leadsto \frac{\left(\left(x + 1\right) \bmod \left(1 + -0.25 \cdot \color{blue}{\left(x \cdot x\right)}\right)\right)}{x + 1} \]
  13. Applied egg-rr6.3%

    \[\leadsto \frac{\left(\left(x + 1\right) \bmod \left(1 + -0.25 \cdot \color{blue}{\left(x \cdot x\right)}\right)\right)}{x + 1} \]
  14. Add Preprocessing

Reproduce

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