expfmod (used to be hard to sample)

Percentage Accurate: 6.9% → 62.9%
Time: 17.7s
Alternatives: 6
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 6 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.9% 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: 62.9% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-x}\\ t_1 := \sqrt{\cos x}\\ t_2 := t\_0 \cdot \left(\left(e^{x}\right) \bmod t\_1\right)\\ \mathbf{if}\;t\_2 \leq 0 \lor \neg \left(t\_2 \leq 2\right):\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left(2 \cdot \left(t\_1 \cdot \sqrt[3]{0.125}\right)\right)\right)}{e^{x}}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (exp (- x)))
        (t_1 (sqrt (cos x)))
        (t_2 (* t_0 (fmod (exp x) t_1))))
   (if (or (<= t_2 0.0) (not (<= t_2 2.0)))
     t_0
     (/ (fmod (exp x) (* 2.0 (* t_1 (cbrt 0.125)))) (exp x)))))
double code(double x) {
	double t_0 = exp(-x);
	double t_1 = sqrt(cos(x));
	double t_2 = t_0 * fmod(exp(x), t_1);
	double tmp;
	if ((t_2 <= 0.0) || !(t_2 <= 2.0)) {
		tmp = t_0;
	} else {
		tmp = fmod(exp(x), (2.0 * (t_1 * cbrt(0.125)))) / exp(x);
	}
	return tmp;
}
function code(x)
	t_0 = exp(Float64(-x))
	t_1 = sqrt(cos(x))
	t_2 = Float64(t_0 * rem(exp(x), t_1))
	tmp = 0.0
	if ((t_2 <= 0.0) || !(t_2 <= 2.0))
		tmp = t_0;
	else
		tmp = Float64(rem(exp(x), Float64(2.0 * Float64(t_1 * cbrt(0.125)))) / exp(x));
	end
	return tmp
end
code[x_] := Block[{t$95$0 = N[Exp[(-x)], $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(t$95$0 * N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = t$95$1}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$2, 0.0], N[Not[LessEqual[t$95$2, 2.0]], $MachinePrecision]], t$95$0, N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(2.0 * N[(t$95$1 * N[Power[0.125, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{-x}\\
t_1 := \sqrt{\cos x}\\
t_2 := t\_0 \cdot \left(\left(e^{x}\right) \bmod t\_1\right)\\
\mathbf{if}\;t\_2 \leq 0 \lor \neg \left(t\_2 \leq 2\right):\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left(2 \cdot \left(t\_1 \cdot \sqrt[3]{0.125}\right)\right)\right)}{e^{x}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 0.0 or 2 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x)))

    1. Initial program 3.3%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{e^{\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x}} \]
    7. Taylor expanded in x around inf 63.6%

      \[\leadsto e^{\color{blue}{-1 \cdot x}} \]
    8. Step-by-step derivation
      1. neg-mul-163.6%

        \[\leadsto e^{\color{blue}{-x}} \]
    9. Simplified63.6%

      \[\leadsto e^{\color{blue}{-x}} \]

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

    1. Initial program 79.2%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \color{blue}{\left(2 \cdot \log \left(\sqrt{e^{\sqrt{\cos x}}}\right)\right)}\right)}{e^{x}} \]
    9. Step-by-step derivation
      1. add-cbrt-cube78.6%

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

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(2 \cdot \sqrt[3]{\color{blue}{{\log \left(\sqrt{e^{\sqrt{\cos x}}}\right)}^{3}}}\right)\right)}{e^{x}} \]
      3. pow1/278.6%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(2 \cdot \sqrt[3]{{\log \color{blue}{\left({\left(e^{\sqrt{\cos x}}\right)}^{0.5}\right)}}^{3}}\right)\right)}{e^{x}} \]
      4. log-pow78.6%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(2 \cdot \sqrt[3]{{\color{blue}{\left(0.5 \cdot \log \left(e^{\sqrt{\cos x}}\right)\right)}}^{3}}\right)\right)}{e^{x}} \]
      5. add-log-exp78.6%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(2 \cdot \sqrt[3]{{\left(0.5 \cdot \color{blue}{\sqrt{\cos x}}\right)}^{3}}\right)\right)}{e^{x}} \]
    10. Applied egg-rr78.6%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(2 \cdot \color{blue}{\sqrt[3]{{\left(0.5 \cdot \sqrt{\cos x}\right)}^{3}}}\right)\right)}{e^{x}} \]
    11. Step-by-step derivation
      1. pow1/379.4%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(2 \cdot \color{blue}{{\left({\left(0.5 \cdot \sqrt{\cos x}\right)}^{3}\right)}^{0.3333333333333333}}\right)\right)}{e^{x}} \]
      2. unpow-prod-down79.4%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(2 \cdot {\color{blue}{\left({0.5}^{3} \cdot {\left(\sqrt{\cos x}\right)}^{3}\right)}}^{0.3333333333333333}\right)\right)}{e^{x}} \]
      3. unpow-prod-down79.4%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(2 \cdot \color{blue}{\left({\left({0.5}^{3}\right)}^{0.3333333333333333} \cdot {\left({\left(\sqrt{\cos x}\right)}^{3}\right)}^{0.3333333333333333}\right)}\right)\right)}{e^{x}} \]
      4. metadata-eval79.4%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(2 \cdot \left({\color{blue}{0.125}}^{0.3333333333333333} \cdot {\left({\left(\sqrt{\cos x}\right)}^{3}\right)}^{0.3333333333333333}\right)\right)\right)}{e^{x}} \]
      5. pow379.4%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(2 \cdot \left({0.125}^{0.3333333333333333} \cdot {\color{blue}{\left(\left(\sqrt{\cos x} \cdot \sqrt{\cos x}\right) \cdot \sqrt{\cos x}\right)}}^{0.3333333333333333}\right)\right)\right)}{e^{x}} \]
      6. pow1/378.9%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(2 \cdot \left({0.125}^{0.3333333333333333} \cdot \color{blue}{\sqrt[3]{\left(\sqrt{\cos x} \cdot \sqrt{\cos x}\right) \cdot \sqrt{\cos x}}}\right)\right)\right)}{e^{x}} \]
      7. add-cbrt-cube79.4%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(2 \cdot \left({0.125}^{0.3333333333333333} \cdot \color{blue}{\sqrt{\cos x}}\right)\right)\right)}{e^{x}} \]
    12. Applied egg-rr79.4%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(2 \cdot \color{blue}{\left({0.125}^{0.3333333333333333} \cdot \sqrt{\cos x}\right)}\right)\right)}{e^{x}} \]
    13. Step-by-step derivation
      1. *-commutative79.4%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(2 \cdot \color{blue}{\left(\sqrt{\cos x} \cdot {0.125}^{0.3333333333333333}\right)}\right)\right)}{e^{x}} \]
      2. unpow1/380.4%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(2 \cdot \left(\sqrt{\cos x} \cdot \color{blue}{\sqrt[3]{0.125}}\right)\right)\right)}{e^{x}} \]
    14. Simplified80.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{-x} \cdot \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \leq 0 \lor \neg \left(e^{-x} \cdot \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \leq 2\right):\\ \;\;\;\;e^{-x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left(2 \cdot \left(\sqrt{\cos x} \cdot \sqrt[3]{0.125}\right)\right)\right)}{e^{x}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 63.0% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-x}\\ t_1 := t\_0 \cdot \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\\ \mathbf{if}\;t\_1 \leq 0 \lor \neg \left(t\_1 \leq 2\right):\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left({\left({\cos x}^{0.16666666666666666}\right)}^{3}\right)\right)}{e^{x}}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (exp (- x))) (t_1 (* t_0 (fmod (exp x) (sqrt (cos x))))))
   (if (or (<= t_1 0.0) (not (<= t_1 2.0)))
     t_0
     (/ (fmod (exp x) (pow (pow (cos x) 0.16666666666666666) 3.0)) (exp x)))))
double code(double x) {
	double t_0 = exp(-x);
	double t_1 = t_0 * fmod(exp(x), sqrt(cos(x)));
	double tmp;
	if ((t_1 <= 0.0) || !(t_1 <= 2.0)) {
		tmp = t_0;
	} else {
		tmp = fmod(exp(x), pow(pow(cos(x), 0.16666666666666666), 3.0)) / exp(x);
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = exp(-x)
    t_1 = t_0 * mod(exp(x), sqrt(cos(x)))
    if ((t_1 <= 0.0d0) .or. (.not. (t_1 <= 2.0d0))) then
        tmp = t_0
    else
        tmp = mod(exp(x), ((cos(x) ** 0.16666666666666666d0) ** 3.0d0)) / exp(x)
    end if
    code = tmp
end function
def code(x):
	t_0 = math.exp(-x)
	t_1 = t_0 * math.fmod(math.exp(x), math.sqrt(math.cos(x)))
	tmp = 0
	if (t_1 <= 0.0) or not (t_1 <= 2.0):
		tmp = t_0
	else:
		tmp = math.fmod(math.exp(x), math.pow(math.pow(math.cos(x), 0.16666666666666666), 3.0)) / math.exp(x)
	return tmp
function code(x)
	t_0 = exp(Float64(-x))
	t_1 = Float64(t_0 * rem(exp(x), sqrt(cos(x))))
	tmp = 0.0
	if ((t_1 <= 0.0) || !(t_1 <= 2.0))
		tmp = t_0;
	else
		tmp = Float64(rem(exp(x), ((cos(x) ^ 0.16666666666666666) ^ 3.0)) / exp(x));
	end
	return tmp
end
code[x_] := Block[{t$95$0 = N[Exp[(-x)], $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, 0.0], N[Not[LessEqual[t$95$1, 2.0]], $MachinePrecision]], t$95$0, N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Power[N[Power[N[Cos[x], $MachinePrecision], 0.16666666666666666], $MachinePrecision], 3.0], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{-x}\\
t_1 := t\_0 \cdot \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\\
\mathbf{if}\;t\_1 \leq 0 \lor \neg \left(t\_1 \leq 2\right):\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 0.0 or 2 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x)))

    1. Initial program 3.3%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{e^{\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x}} \]
    7. Taylor expanded in x around inf 63.6%

      \[\leadsto e^{\color{blue}{-1 \cdot x}} \]
    8. Step-by-step derivation
      1. neg-mul-163.6%

        \[\leadsto e^{\color{blue}{-x}} \]
    9. Simplified63.6%

      \[\leadsto e^{\color{blue}{-x}} \]

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

    1. Initial program 79.2%

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

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

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

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

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

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \color{blue}{\left(\left(\sqrt[3]{\sqrt{\cos x}} \cdot \sqrt[3]{\sqrt{\cos x}}\right) \cdot \sqrt[3]{\sqrt{\cos x}}\right)}\right)}{e^{x}} \]
      2. associate-*l*77.8%

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

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt[3]{\sqrt{\cos x}} \cdot \color{blue}{\sqrt[3]{\sqrt{\cos x} \cdot \sqrt{\cos x}}}\right)\right)}{e^{x}} \]
      4. add-sqr-sqrt78.5%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt[3]{\sqrt{\cos x}} \cdot \sqrt[3]{\color{blue}{\cos x}}\right)\right)}{e^{x}} \]
      5. pow1/378.7%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\color{blue}{{\left(\sqrt{\cos x}\right)}^{0.3333333333333333}} \cdot \sqrt[3]{\cos x}\right)\right)}{e^{x}} \]
      6. pow1/278.7%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\color{blue}{\left({\cos x}^{0.5}\right)}}^{0.3333333333333333} \cdot \sqrt[3]{\cos x}\right)\right)}{e^{x}} \]
      7. pow-pow78.7%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\color{blue}{{\cos x}^{\left(0.5 \cdot 0.3333333333333333\right)}} \cdot \sqrt[3]{\cos x}\right)\right)}{e^{x}} \]
      8. metadata-eval78.7%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\cos x}^{\color{blue}{0.16666666666666666}} \cdot \sqrt[3]{\cos x}\right)\right)}{e^{x}} \]
    6. Applied egg-rr78.7%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \color{blue}{\left({\cos x}^{0.16666666666666666} \cdot \sqrt[3]{\cos x}\right)}\right)}{e^{x}} \]
    7. Step-by-step derivation
      1. unpow1/379.4%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\cos x}^{0.16666666666666666} \cdot \color{blue}{{\cos x}^{0.3333333333333333}}\right)\right)}{e^{x}} \]
      2. metadata-eval79.4%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\cos x}^{0.16666666666666666} \cdot {\cos x}^{\color{blue}{\left(2 \cdot 0.16666666666666666\right)}}\right)\right)}{e^{x}} \]
      3. pow-sqr79.9%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\cos x}^{0.16666666666666666} \cdot \color{blue}{\left({\cos x}^{0.16666666666666666} \cdot {\cos x}^{0.16666666666666666}\right)}\right)\right)}{e^{x}} \]
      4. cube-mult79.9%

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

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \color{blue}{\left({\left({\cos x}^{0.16666666666666666}\right)}^{3}\right)}\right)}{e^{x}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification64.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{-x} \cdot \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \leq 0 \lor \neg \left(e^{-x} \cdot \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \leq 2\right):\\ \;\;\;\;e^{-x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left({\left({\cos x}^{0.16666666666666666}\right)}^{3}\right)\right)}{e^{x}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 63.0% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-x}\\ t_1 := t\_0 \cdot \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\\ \mathbf{if}\;t\_1 \leq 0 \lor \neg \left(t\_1 \leq 2\right):\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt[3]{{\cos x}^{1.5}}\right)\right)}{e^{x}}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (exp (- x))) (t_1 (* t_0 (fmod (exp x) (sqrt (cos x))))))
   (if (or (<= t_1 0.0) (not (<= t_1 2.0)))
     t_0
     (/ (fmod (exp x) (cbrt (pow (cos x) 1.5))) (exp x)))))
double code(double x) {
	double t_0 = exp(-x);
	double t_1 = t_0 * fmod(exp(x), sqrt(cos(x)));
	double tmp;
	if ((t_1 <= 0.0) || !(t_1 <= 2.0)) {
		tmp = t_0;
	} else {
		tmp = fmod(exp(x), cbrt(pow(cos(x), 1.5))) / exp(x);
	}
	return tmp;
}
function code(x)
	t_0 = exp(Float64(-x))
	t_1 = Float64(t_0 * rem(exp(x), sqrt(cos(x))))
	tmp = 0.0
	if ((t_1 <= 0.0) || !(t_1 <= 2.0))
		tmp = t_0;
	else
		tmp = Float64(rem(exp(x), cbrt((cos(x) ^ 1.5))) / exp(x));
	end
	return tmp
end
code[x_] := Block[{t$95$0 = N[Exp[(-x)], $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, 0.0], N[Not[LessEqual[t$95$1, 2.0]], $MachinePrecision]], t$95$0, N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Power[N[Power[N[Cos[x], $MachinePrecision], 1.5], $MachinePrecision], 1/3], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{-x}\\
t_1 := t\_0 \cdot \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\\
\mathbf{if}\;t\_1 \leq 0 \lor \neg \left(t\_1 \leq 2\right):\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 0.0 or 2 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x)))

    1. Initial program 3.3%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{e^{\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x}} \]
    7. Taylor expanded in x around inf 63.6%

      \[\leadsto e^{\color{blue}{-1 \cdot x}} \]
    8. Step-by-step derivation
      1. neg-mul-163.6%

        \[\leadsto e^{\color{blue}{-x}} \]
    9. Simplified63.6%

      \[\leadsto e^{\color{blue}{-x}} \]

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

    1. Initial program 79.2%

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

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

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

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

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

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

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

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt[3]{{\color{blue}{\left({\cos x}^{0.5}\right)}}^{3}}\right)\right)}{e^{x}} \]
      4. pow-pow79.6%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt[3]{\color{blue}{{\cos x}^{\left(0.5 \cdot 3\right)}}}\right)\right)}{e^{x}} \]
      5. metadata-eval79.6%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt[3]{{\cos x}^{\color{blue}{1.5}}}\right)\right)}{e^{x}} \]
    6. Applied egg-rr79.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{-x} \cdot \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \leq 0 \lor \neg \left(e^{-x} \cdot \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \leq 2\right):\\ \;\;\;\;e^{-x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt[3]{{\cos x}^{1.5}}\right)\right)}{e^{x}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 63.0% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-x}\\ t_1 := \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\\ t_2 := t\_0 \cdot t\_1\\ \mathbf{if}\;t\_2 \leq 0 \lor \neg \left(t\_2 \leq 2\right):\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{t\_1}{e^{x}}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (exp (- x)))
        (t_1 (fmod (exp x) (sqrt (cos x))))
        (t_2 (* t_0 t_1)))
   (if (or (<= t_2 0.0) (not (<= t_2 2.0))) t_0 (/ t_1 (exp x)))))
double code(double x) {
	double t_0 = exp(-x);
	double t_1 = fmod(exp(x), sqrt(cos(x)));
	double t_2 = t_0 * t_1;
	double tmp;
	if ((t_2 <= 0.0) || !(t_2 <= 2.0)) {
		tmp = t_0;
	} else {
		tmp = t_1 / exp(x);
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_0 = exp(-x)
    t_1 = mod(exp(x), sqrt(cos(x)))
    t_2 = t_0 * t_1
    if ((t_2 <= 0.0d0) .or. (.not. (t_2 <= 2.0d0))) then
        tmp = t_0
    else
        tmp = t_1 / exp(x)
    end if
    code = tmp
end function
def code(x):
	t_0 = math.exp(-x)
	t_1 = math.fmod(math.exp(x), math.sqrt(math.cos(x)))
	t_2 = t_0 * t_1
	tmp = 0
	if (t_2 <= 0.0) or not (t_2 <= 2.0):
		tmp = t_0
	else:
		tmp = t_1 / math.exp(x)
	return tmp
function code(x)
	t_0 = exp(Float64(-x))
	t_1 = rem(exp(x), sqrt(cos(x)))
	t_2 = Float64(t_0 * t_1)
	tmp = 0.0
	if ((t_2 <= 0.0) || !(t_2 <= 2.0))
		tmp = t_0;
	else
		tmp = Float64(t_1 / exp(x));
	end
	return tmp
end
code[x_] := Block[{t$95$0 = N[Exp[(-x)], $MachinePrecision]}, Block[{t$95$1 = N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]}, Block[{t$95$2 = N[(t$95$0 * t$95$1), $MachinePrecision]}, If[Or[LessEqual[t$95$2, 0.0], N[Not[LessEqual[t$95$2, 2.0]], $MachinePrecision]], t$95$0, N[(t$95$1 / N[Exp[x], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{-x}\\
t_1 := \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\\
t_2 := t\_0 \cdot t\_1\\
\mathbf{if}\;t\_2 \leq 0 \lor \neg \left(t\_2 \leq 2\right):\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;\frac{t\_1}{e^{x}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 0.0 or 2 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x)))

    1. Initial program 3.3%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{e^{\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x}} \]
    7. Taylor expanded in x around inf 63.6%

      \[\leadsto e^{\color{blue}{-1 \cdot x}} \]
    8. Step-by-step derivation
      1. neg-mul-163.6%

        \[\leadsto e^{\color{blue}{-x}} \]
    9. Simplified63.6%

      \[\leadsto e^{\color{blue}{-x}} \]

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

    1. Initial program 79.2%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{-x} \cdot \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \leq 0 \lor \neg \left(e^{-x} \cdot \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \leq 2\right):\\ \;\;\;\;e^{-x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 62.7% accurate, 0.4× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;e^{-x}\\


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

    1. Initial program 8.4%

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

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

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

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

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

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

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

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

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

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

    if 0.10000000000000001 < x

    1. Initial program 0.0%

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{e^{\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}}}{e^{x}} \]
      2. div-exp0.0%

        \[\leadsto \color{blue}{e^{\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x}} \]
    6. Applied egg-rr0.0%

      \[\leadsto \color{blue}{e^{\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x}} \]
    7. Taylor expanded in x around inf 100.0%

      \[\leadsto e^{\color{blue}{-1 \cdot x}} \]
    8. Step-by-step derivation
      1. neg-mul-1100.0%

        \[\leadsto e^{\color{blue}{-x}} \]
    9. Simplified100.0%

      \[\leadsto e^{\color{blue}{-x}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification64.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 0.1:\\ \;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left(\log \left({\left(\sqrt[3]{e^{\sqrt{\cos x}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\sqrt{\cos x}}}\right)\right)\right)}{e^{x}}\\ \mathbf{else}:\\ \;\;\;\;e^{-x}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 60.9% accurate, 5.0× speedup?

\[\begin{array}{l} \\ e^{-x} \end{array} \]
(FPCore (x) :precision binary64 (exp (- x)))
double code(double x) {
	return exp(-x);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = exp(-x)
end function
public static double code(double x) {
	return Math.exp(-x);
}
def code(x):
	return math.exp(-x)
function code(x)
	return exp(Float64(-x))
end
function tmp = code(x)
	tmp = exp(-x);
end
code[x_] := N[Exp[(-x)], $MachinePrecision]
\begin{array}{l}

\\
e^{-x}
\end{array}
Derivation
  1. Initial program 6.6%

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{e^{\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}}}{e^{x}} \]
    2. div-exp6.6%

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

    \[\leadsto \color{blue}{e^{\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x}} \]
  7. Taylor expanded in x around inf 62.3%

    \[\leadsto e^{\color{blue}{-1 \cdot x}} \]
  8. Step-by-step derivation
    1. neg-mul-162.3%

      \[\leadsto e^{\color{blue}{-x}} \]
  9. Simplified62.3%

    \[\leadsto e^{\color{blue}{-x}} \]
  10. Final simplification62.3%

    \[\leadsto e^{-x} \]
  11. Add Preprocessing

Reproduce

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