expfmod (used to be hard to sample)

Percentage Accurate: 7.0% → 99.1%
Time: 19.7s
Alternatives: 9
Speedup: 5.0×

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 9 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: 7.0% 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: 99.1% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt[3]{e^{\cos x}}\\ \mathbf{if}\;x \leq -1 \cdot 10^{-8}:\\ \;\;\;\;\frac{\left(\left(x + 1\right) \bmod \left(1 + -0.25 \cdot {x}^{2}\right)\right)}{x + 1}\\ \mathbf{elif}\;x \leq -5 \cdot 10^{-310}:\\ \;\;\;\;\left(1 \bmod \left(\sqrt{\log \left({t\_0}^{2}\right) + \log t\_0}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (cbrt (exp (cos x)))))
   (if (<= x -1e-8)
     (/ (fmod (+ x 1.0) (+ 1.0 (* -0.25 (pow x 2.0)))) (+ x 1.0))
     (if (<= x -5e-310)
       (fmod 1.0 (sqrt (+ (log (pow t_0 2.0)) (log t_0))))
       (* (fmod x (sqrt (cos x))) (exp (- x)))))))
double code(double x) {
	double t_0 = cbrt(exp(cos(x)));
	double tmp;
	if (x <= -1e-8) {
		tmp = fmod((x + 1.0), (1.0 + (-0.25 * pow(x, 2.0)))) / (x + 1.0);
	} else if (x <= -5e-310) {
		tmp = fmod(1.0, sqrt((log(pow(t_0, 2.0)) + log(t_0))));
	} else {
		tmp = fmod(x, sqrt(cos(x))) * exp(-x);
	}
	return tmp;
}
function code(x)
	t_0 = cbrt(exp(cos(x)))
	tmp = 0.0
	if (x <= -1e-8)
		tmp = Float64(rem(Float64(x + 1.0), Float64(1.0 + Float64(-0.25 * (x ^ 2.0)))) / Float64(x + 1.0));
	elseif (x <= -5e-310)
		tmp = rem(1.0, sqrt(Float64(log((t_0 ^ 2.0)) + log(t_0))));
	else
		tmp = Float64(rem(x, sqrt(cos(x))) * exp(Float64(-x)));
	end
	return tmp
end
code[x_] := Block[{t$95$0 = N[Power[N[Exp[N[Cos[x], $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision]}, If[LessEqual[x, -1e-8], N[(N[With[{TMP1 = N[(x + 1.0), $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], If[LessEqual[x, -5e-310], N[With[{TMP1 = 1.0, TMP2 = N[Sqrt[N[(N[Log[N[Power[t$95$0, 2.0], $MachinePrecision]], $MachinePrecision] + N[Log[t$95$0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision], N[(N[With[{TMP1 = x, 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}
t_0 := \sqrt[3]{e^{\cos x}}\\
\mathbf{if}\;x \leq -1 \cdot 10^{-8}:\\
\;\;\;\;\frac{\left(\left(x + 1\right) \bmod \left(1 + -0.25 \cdot {x}^{2}\right)\right)}{x + 1}\\

\mathbf{elif}\;x \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\left(1 \bmod \left(\sqrt{\log \left({t\_0}^{2}\right) + \log t\_0}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\left(x \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x}\\


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

    1. Initial program 59.7%

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

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

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

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

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

      \[\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 30.6%

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

        \[\leadsto \frac{\left(\color{blue}{\left(x + 1\right)} \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}} \]
    7. Simplified30.6%

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

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

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

        \[\leadsto \frac{\left(\color{blue}{\left(x + 1\right)} \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}} \]
    11. Simplified100.0%

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

    if -1e-8 < x < -4.999999999999985e-310

    1. Initial program 4.9%

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

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

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

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

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

      \[\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.4%

      \[\leadsto \color{blue}{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)} \]
    6. Taylor expanded in x around 0 3.1%

      \[\leadsto \left(\color{blue}{1} \bmod \left(\sqrt{\cos x}\right)\right) \]
    7. Step-by-step derivation
      1. add-log-exp4.9%

        \[\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-cbrt100.0%

        \[\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-prod100.0%

        \[\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. pow2100.0%

        \[\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}} \]
    8. Applied egg-rr100.0%

      \[\leadsto \left(1 \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) \]

    if -4.999999999999985e-310 < x

    1. Initial program 5.4%

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

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

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

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

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{\color{blue}{x}}} \]
    3. Simplified5.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 43.3%

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

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

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

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

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

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

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

Alternative 2: 98.6% accurate, 0.5× speedup?

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

\mathbf{else}:\\
\;\;\;\;\left(x \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x}\\


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

    1. Initial program 7.4%

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

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

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

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

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{\color{blue}{x}}} \]
    3. Simplified7.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. add-log-exp7.4%

        \[\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-cbrt98.2%

        \[\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-prod98.2%

        \[\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. pow298.2%

        \[\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-rr98.2%

      \[\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. Taylor expanded in x around 0 98.2%

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

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

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

    if -4.999999999999985e-310 < x

    1. Initial program 5.4%

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

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

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

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

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{\color{blue}{x}}} \]
    3. Simplified5.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 43.3%

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

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

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

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

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

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

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

Alternative 3: 66.8% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt{\cos x}\\ \mathbf{if}\;x \leq -6 \cdot 10^{-309}:\\ \;\;\;\;\frac{\left(\left(x \cdot \left(1 + \frac{1}{x}\right)\right) \bmod \left(1 + -0.25 \cdot {x}^{2}\right)\right)}{e^{x}}\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;\left(x \bmod t\_0\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(1 \bmod t\_0\right)}{e^{x}}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (sqrt (cos x))))
   (if (<= x -6e-309)
     (/ (fmod (* x (+ 1.0 (/ 1.0 x))) (+ 1.0 (* -0.25 (pow x 2.0)))) (exp x))
     (if (<= x 1.0) (fmod x t_0) (/ (fmod 1.0 t_0) (exp x))))))
double code(double x) {
	double t_0 = sqrt(cos(x));
	double tmp;
	if (x <= -6e-309) {
		tmp = fmod((x * (1.0 + (1.0 / x))), (1.0 + (-0.25 * pow(x, 2.0)))) / exp(x);
	} else if (x <= 1.0) {
		tmp = fmod(x, t_0);
	} else {
		tmp = fmod(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 = sqrt(cos(x))
    if (x <= (-6d-309)) then
        tmp = mod((x * (1.0d0 + (1.0d0 / x))), (1.0d0 + ((-0.25d0) * (x ** 2.0d0)))) / exp(x)
    else if (x <= 1.0d0) then
        tmp = mod(x, t_0)
    else
        tmp = mod(1.0d0, t_0) / exp(x)
    end if
    code = tmp
end function
def code(x):
	t_0 = math.sqrt(math.cos(x))
	tmp = 0
	if x <= -6e-309:
		tmp = math.fmod((x * (1.0 + (1.0 / x))), (1.0 + (-0.25 * math.pow(x, 2.0)))) / math.exp(x)
	elif x <= 1.0:
		tmp = math.fmod(x, t_0)
	else:
		tmp = math.fmod(1.0, t_0) / math.exp(x)
	return tmp
function code(x)
	t_0 = sqrt(cos(x))
	tmp = 0.0
	if (x <= -6e-309)
		tmp = Float64(rem(Float64(x * Float64(1.0 + Float64(1.0 / x))), Float64(1.0 + Float64(-0.25 * (x ^ 2.0)))) / exp(x));
	elseif (x <= 1.0)
		tmp = rem(x, t_0);
	else
		tmp = Float64(rem(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, -6e-309], 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[Exp[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.0], N[With[{TMP1 = x, TMP2 = t$95$0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision], N[(N[With[{TMP1 = 1.0, 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 -6 \cdot 10^{-309}:\\
\;\;\;\;\frac{\left(\left(x \cdot \left(1 + \frac{1}{x}\right)\right) \bmod \left(1 + -0.25 \cdot {x}^{2}\right)\right)}{e^{x}}\\

\mathbf{elif}\;x \leq 1:\\
\;\;\;\;\left(x \bmod t\_0\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -6.000000000000001e-309

    1. Initial program 7.4%

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

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

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

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

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{\color{blue}{x}}} \]
    3. Simplified7.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.1%

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

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

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

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

      \[\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)}{e^{x}} \]

    if -6.000000000000001e-309 < x < 1

    1. Initial program 7.7%

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

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

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

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

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

      \[\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 7.0%

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

        \[\leadsto \frac{\left(\color{blue}{\left(x + 1\right)} \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}} \]
    7. Simplified7.0%

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

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

      \[\leadsto \color{blue}{\left(x \bmod \left(\sqrt{\cos x}\right)\right)} \]

    if 1 < x

    1. Initial program 2.1%

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

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

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

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

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

      \[\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 97.2%

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

Alternative 4: 66.7% accurate, 1.2× speedup?

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

\mathbf{else}:\\
\;\;\;\;\left(x \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x}\\


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

    1. Initial program 7.4%

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

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

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

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

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{\color{blue}{x}}} \]
    3. Simplified7.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.1%

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

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

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

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

      \[\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)}{e^{x}} \]

    if -6.000000000000001e-309 < x

    1. Initial program 5.4%

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

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

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

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

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{\color{blue}{x}}} \]
    3. Simplified5.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 43.3%

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

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

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

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

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

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

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

Alternative 5: 66.7% accurate, 1.2× speedup?

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

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


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

    1. Initial program 7.4%

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

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

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

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

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{\color{blue}{x}}} \]
    3. Simplified7.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.1%

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

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

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

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

      \[\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)}{e^{x}} \]

    if -6.000000000000001e-309 < x

    1. Initial program 5.4%

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

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

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

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

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{\color{blue}{x}}} \]
    3. Simplified5.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 43.3%

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

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

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

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

Alternative 6: 66.8% accurate, 1.6× speedup?

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

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

\mathbf{elif}\;x \leq 0.92:\\
\;\;\;\;\left(x \bmod \left(\sqrt{\cos x}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{\left(\left(x + 1\right) \bmod \left(1 + -0.25 \cdot \left(x \cdot x\right)\right)\right)}{e^{x}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -6.000000000000001e-309

    1. Initial program 7.4%

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

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

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

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

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{\color{blue}{x}}} \]
    3. Simplified7.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.1%

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

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

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

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

      \[\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)}{e^{x}} \]

    if -6.000000000000001e-309 < x < 0.92000000000000004

    1. Initial program 7.7%

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

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

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

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

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

      \[\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 7.0%

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

        \[\leadsto \frac{\left(\color{blue}{\left(x + 1\right)} \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}} \]
    7. Simplified7.0%

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

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

      \[\leadsto \color{blue}{\left(x \bmod \left(\sqrt{\cos x}\right)\right)} \]

    if 0.92000000000000004 < x

    1. Initial program 2.1%

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

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

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

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

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

      \[\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 97.2%

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

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

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

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

        \[\leadsto \frac{\left(\left(x + 1\right) \bmod \left(1 + -0.25 \cdot \color{blue}{\left(x \cdot x\right)}\right)\right)}{e^{x}} \]
    10. Applied egg-rr97.1%

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

Alternative 7: 62.1% accurate, 1.6× speedup?

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

\mathbf{elif}\;x \leq 0.92:\\
\;\;\;\;\left(x \bmod \left(\sqrt{\cos x}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{\left(\left(x + 1\right) \bmod \left(1 + -0.25 \cdot \left(x \cdot x\right)\right)\right)}{e^{x}}\\


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

    1. Initial program 7.4%

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

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

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

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

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{\color{blue}{x}}} \]
    3. Simplified7.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.1%

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

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

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

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

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

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

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

    if -4.999999999999985e-310 < x < 0.92000000000000004

    1. Initial program 7.7%

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

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

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

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

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

      \[\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 7.0%

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

        \[\leadsto \frac{\left(\color{blue}{\left(x + 1\right)} \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}} \]
    7. Simplified7.0%

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

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

      \[\leadsto \color{blue}{\left(x \bmod \left(\sqrt{\cos x}\right)\right)} \]

    if 0.92000000000000004 < x

    1. Initial program 2.1%

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

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

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

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

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

      \[\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 97.2%

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

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

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

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

        \[\leadsto \frac{\left(\left(x + 1\right) \bmod \left(1 + -0.25 \cdot \color{blue}{\left(x \cdot x\right)}\right)\right)}{e^{x}} \]
    10. Applied egg-rr97.1%

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

Alternative 8: 25.3% accurate, 2.4× speedup?

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

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

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

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

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

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

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

    \[\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 27.0%

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

      \[\leadsto \frac{\left(\color{blue}{\left(x + 1\right)} \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}} \]
  7. Simplified27.0%

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

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

      \[\leadsto \frac{\left(\left(x + 1\right) \bmod \left(1 + -0.25 \cdot \color{blue}{\left(x \cdot x\right)}\right)\right)}{e^{x}} \]
  10. Applied egg-rr27.0%

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

Alternative 9: 22.8% accurate, 5.0× speedup?

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

\\
\left(1 \bmod 1\right)
\end{array}
Derivation
  1. Initial program 6.3%

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

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

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

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

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

    \[\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.7%

    \[\leadsto \color{blue}{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)} \]
  6. Taylor expanded in x around 0 4.3%

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

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

    \[\leadsto \left(1 \bmod \color{blue}{1}\right) \]
  9. Add Preprocessing

Reproduce

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