expfmod (used to be hard to sample)

Percentage Accurate: 6.9% → 98.9%
Time: 12.3s
Alternatives: 5
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 5 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: 98.9% accurate, 0.4× speedup?

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

\\
\begin{array}{l}
t_0 := \log \left(\left(e^{x}\right) \bmod \left({\cos x}^{0.5}\right)\right)\\
\mathbf{if}\;x \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\frac{1}{{\left({e}^{\left(x \cdot x - {t\_0}^{2}\right)}\right)}^{\left(\frac{1}{x + t\_0}\right)}}\\

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


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

    1. Initial program 6.2%

      \[\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. exp-negN/A

        \[\leadsto \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot \frac{1}{\color{blue}{e^{x}}} \]
      2. un-div-invN/A

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{\color{blue}{e^{x}}} \]
      3. clear-numN/A

        \[\leadsto \frac{1}{\color{blue}{\frac{e^{x}}{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}}} \]
      4. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left(\frac{e^{x}}{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}\right)}\right) \]
      5. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\left(e^{x}\right), \color{blue}{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}\right)\right) \]
      6. exp-lowering-exp.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{exp.f64}\left(x\right), \left(\color{blue}{\left(e^{x}\right)} \bmod \left(\sqrt{\cos x}\right)\right)\right)\right) \]
      7. fmod-lowering-fmod.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{exp.f64}\left(x\right), \mathsf{fmod.f64}\left(\left(e^{x}\right), \color{blue}{\left(\sqrt{\cos x}\right)}\right)\right)\right) \]
      8. exp-lowering-exp.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{exp.f64}\left(x\right), \mathsf{fmod.f64}\left(\mathsf{exp.f64}\left(x\right), \left(\sqrt{\color{blue}{\cos x}}\right)\right)\right)\right) \]
      9. pow1/2N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{exp.f64}\left(x\right), \mathsf{fmod.f64}\left(\mathsf{exp.f64}\left(x\right), \left({\cos x}^{\color{blue}{\frac{1}{2}}}\right)\right)\right)\right) \]
      10. pow-lowering-pow.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{exp.f64}\left(x\right), \mathsf{fmod.f64}\left(\mathsf{exp.f64}\left(x\right), \mathsf{pow.f64}\left(\cos x, \color{blue}{\frac{1}{2}}\right)\right)\right)\right) \]
      11. cos-lowering-cos.f646.2%

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{exp.f64}\left(x\right), \mathsf{fmod.f64}\left(\mathsf{exp.f64}\left(x\right), \mathsf{pow.f64}\left(\mathsf{cos.f64}\left(x\right), \frac{1}{2}\right)\right)\right)\right) \]
    4. Applied egg-rr6.2%

      \[\leadsto \color{blue}{\frac{1}{\frac{e^{x}}{\left(\left(e^{x}\right) \bmod \left({\cos x}^{0.5}\right)\right)}}} \]
    5. Step-by-step derivation
      1. rem-exp-logN/A

        \[\leadsto \mathsf{/.f64}\left(1, \left(e^{\log \left(\frac{e^{x}}{\left(\left(e^{x}\right) \bmod \left({\cos x}^{\frac{1}{2}}\right)\right)}\right)}\right)\right) \]
      2. unpow1N/A

        \[\leadsto \mathsf{/.f64}\left(1, \left(e^{\log \left({\left(\frac{e^{x}}{\left(\left(e^{x}\right) \bmod \left({\cos x}^{\frac{1}{2}}\right)\right)}\right)}^{1}\right)}\right)\right) \]
      3. log-powN/A

        \[\leadsto \mathsf{/.f64}\left(1, \left(e^{1 \cdot \log \left(\frac{e^{x}}{\left(\left(e^{x}\right) \bmod \left({\cos x}^{\frac{1}{2}}\right)\right)}\right)}\right)\right) \]
      4. exp-prodN/A

        \[\leadsto \mathsf{/.f64}\left(1, \left({\left(e^{1}\right)}^{\color{blue}{\log \left(\frac{e^{x}}{\left(\left(e^{x}\right) \bmod \left({\cos x}^{\frac{1}{2}}\right)\right)}\right)}}\right)\right) \]
      5. pow-lowering-pow.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{pow.f64}\left(\left(e^{1}\right), \color{blue}{\log \left(\frac{e^{x}}{\left(\left(e^{x}\right) \bmod \left({\cos x}^{\frac{1}{2}}\right)\right)}\right)}\right)\right) \]
      6. exp-1-eN/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{pow.f64}\left(\mathsf{E}\left(\right), \log \color{blue}{\left(\frac{e^{x}}{\left(\left(e^{x}\right) \bmod \left({\cos x}^{\frac{1}{2}}\right)\right)}\right)}\right)\right) \]
      7. E-lowering-E.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{pow.f64}\left(\mathsf{E.f64}\left(\right), \log \color{blue}{\left(\frac{e^{x}}{\left(\left(e^{x}\right) \bmod \left({\cos x}^{\frac{1}{2}}\right)\right)}\right)}\right)\right) \]
      8. log-divN/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{pow.f64}\left(\mathsf{E.f64}\left(\right), \left(\log \left(e^{x}\right) - \color{blue}{\log \left(\left(e^{x}\right) \bmod \left({\cos x}^{\frac{1}{2}}\right)\right)}\right)\right)\right) \]
      9. rem-log-expN/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{pow.f64}\left(\mathsf{E.f64}\left(\right), \left(x - \log \color{blue}{\left(\left(e^{x}\right) \bmod \left({\cos x}^{\frac{1}{2}}\right)\right)}\right)\right)\right) \]
      10. --lowering--.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{pow.f64}\left(\mathsf{E.f64}\left(\right), \mathsf{\_.f64}\left(x, \color{blue}{\log \left(\left(e^{x}\right) \bmod \left({\cos x}^{\frac{1}{2}}\right)\right)}\right)\right)\right) \]
      11. log-lowering-log.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{pow.f64}\left(\mathsf{E.f64}\left(\right), \mathsf{\_.f64}\left(x, \mathsf{log.f64}\left(\left(\left(e^{x}\right) \bmod \left({\cos x}^{\frac{1}{2}}\right)\right)\right)\right)\right)\right) \]
      12. pow1/2N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{pow.f64}\left(\mathsf{E.f64}\left(\right), \mathsf{\_.f64}\left(x, \mathsf{log.f64}\left(\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\right)\right)\right)\right) \]
      13. fmod-lowering-fmod.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{pow.f64}\left(\mathsf{E.f64}\left(\right), \mathsf{\_.f64}\left(x, \mathsf{log.f64}\left(\mathsf{fmod.f64}\left(\left(e^{x}\right), \left(\sqrt{\cos x}\right)\right)\right)\right)\right)\right) \]
      14. exp-lowering-exp.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{pow.f64}\left(\mathsf{E.f64}\left(\right), \mathsf{\_.f64}\left(x, \mathsf{log.f64}\left(\mathsf{fmod.f64}\left(\mathsf{exp.f64}\left(x\right), \left(\sqrt{\cos x}\right)\right)\right)\right)\right)\right) \]
      15. pow1/2N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{pow.f64}\left(\mathsf{E.f64}\left(\right), \mathsf{\_.f64}\left(x, \mathsf{log.f64}\left(\mathsf{fmod.f64}\left(\mathsf{exp.f64}\left(x\right), \left({\cos x}^{\frac{1}{2}}\right)\right)\right)\right)\right)\right) \]
      16. pow-lowering-pow.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{pow.f64}\left(\mathsf{E.f64}\left(\right), \mathsf{\_.f64}\left(x, \mathsf{log.f64}\left(\mathsf{fmod.f64}\left(\mathsf{exp.f64}\left(x\right), \mathsf{pow.f64}\left(\cos x, \frac{1}{2}\right)\right)\right)\right)\right)\right) \]
      17. cos-lowering-cos.f646.2%

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{pow.f64}\left(\mathsf{E.f64}\left(\right), \mathsf{\_.f64}\left(x, \mathsf{log.f64}\left(\mathsf{fmod.f64}\left(\mathsf{exp.f64}\left(x\right), \mathsf{pow.f64}\left(\mathsf{cos.f64}\left(x\right), \frac{1}{2}\right)\right)\right)\right)\right)\right) \]
    6. Applied egg-rr6.2%

      \[\leadsto \frac{1}{\color{blue}{{e}^{\left(x - \log \left(\left(e^{x}\right) \bmod \left({\cos x}^{0.5}\right)\right)\right)}}} \]
    7. Step-by-step derivation
      1. flip--N/A

        \[\leadsto \mathsf{/.f64}\left(1, \left({\mathsf{E}\left(\right)}^{\left(\frac{x \cdot x - \log \left(\left(e^{x}\right) \bmod \left({\cos x}^{\frac{1}{2}}\right)\right) \cdot \log \left(\left(e^{x}\right) \bmod \left({\cos x}^{\frac{1}{2}}\right)\right)}{\color{blue}{x + \log \left(\left(e^{x}\right) \bmod \left({\cos x}^{\frac{1}{2}}\right)\right)}}\right)}\right)\right) \]
      2. div-invN/A

        \[\leadsto \mathsf{/.f64}\left(1, \left({\mathsf{E}\left(\right)}^{\left(\left(x \cdot x - \log \left(\left(e^{x}\right) \bmod \left({\cos x}^{\frac{1}{2}}\right)\right) \cdot \log \left(\left(e^{x}\right) \bmod \left({\cos x}^{\frac{1}{2}}\right)\right)\right) \cdot \color{blue}{\frac{1}{x + \log \left(\left(e^{x}\right) \bmod \left({\cos x}^{\frac{1}{2}}\right)\right)}}\right)}\right)\right) \]
      3. pow-unpowN/A

        \[\leadsto \mathsf{/.f64}\left(1, \left({\left({\mathsf{E}\left(\right)}^{\left(x \cdot x - \log \left(\left(e^{x}\right) \bmod \left({\cos x}^{\frac{1}{2}}\right)\right) \cdot \log \left(\left(e^{x}\right) \bmod \left({\cos x}^{\frac{1}{2}}\right)\right)\right)}\right)}^{\color{blue}{\left(\frac{1}{x + \log \left(\left(e^{x}\right) \bmod \left({\cos x}^{\frac{1}{2}}\right)\right)}\right)}}\right)\right) \]
      4. pow-lowering-pow.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{pow.f64}\left(\left({\mathsf{E}\left(\right)}^{\left(x \cdot x - \log \left(\left(e^{x}\right) \bmod \left({\cos x}^{\frac{1}{2}}\right)\right) \cdot \log \left(\left(e^{x}\right) \bmod \left({\cos x}^{\frac{1}{2}}\right)\right)\right)}\right), \color{blue}{\left(\frac{1}{x + \log \left(\left(e^{x}\right) \bmod \left({\cos x}^{\frac{1}{2}}\right)\right)}\right)}\right)\right) \]
    8. Applied egg-rr100.0%

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

    if -1.999999999999994e-310 < x

    1. Initial program 5.5%

      \[\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \mathsf{*.f64}\left(\mathsf{fmod.f64}\left(\color{blue}{\left(1 + x\right)}, \mathsf{sqrt.f64}\left(\mathsf{cos.f64}\left(x\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{neg.f64}\left(x\right)\right)\right) \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{fmod.f64}\left(\left(x + 1\right), \mathsf{sqrt.f64}\left(\mathsf{cos.f64}\left(x\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{neg.f64}\left(\color{blue}{x}\right)\right)\right) \]
      2. +-lowering-+.f6438.9%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{fmod.f64}\left(\mathsf{+.f64}\left(x, 1\right), \mathsf{sqrt.f64}\left(\mathsf{cos.f64}\left(x\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{neg.f64}\left(\color{blue}{x}\right)\right)\right) \]
    5. Simplified38.9%

      \[\leadsto \left(\color{blue}{\left(x + 1\right)} \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \]
    6. Taylor expanded in x around inf

      \[\leadsto \mathsf{*.f64}\left(\mathsf{fmod.f64}\left(\color{blue}{x}, \mathsf{sqrt.f64}\left(\mathsf{cos.f64}\left(x\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{neg.f64}\left(x\right)\right)\right) \]
    7. Step-by-step derivation
      1. Simplified98.6%

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{fmod.f64}\left(x, \color{blue}{1}\right), \mathsf{exp.f64}\left(\mathsf{neg.f64}\left(x\right)\right)\right) \]
      3. Step-by-step derivation
        1. Simplified98.6%

          \[\leadsto \left(x \bmod \color{blue}{1}\right) \cdot e^{-x} \]
        2. Step-by-step derivation
          1. exp-negN/A

            \[\leadsto \left(x \bmod 1\right) \cdot \frac{1}{\color{blue}{e^{x}}} \]
          2. un-div-invN/A

            \[\leadsto \frac{\left(x \bmod 1\right)}{\color{blue}{e^{x}}} \]
          3. /-lowering-/.f64N/A

            \[\leadsto \mathsf{/.f64}\left(\left(x \bmod 1\right), \color{blue}{\left(e^{x}\right)}\right) \]
          4. fmod-lowering-fmod.f64N/A

            \[\leadsto \mathsf{/.f64}\left(\mathsf{fmod.f64}\left(x, 1\right), \left(e^{\color{blue}{x}}\right)\right) \]
          5. exp-lowering-exp.f6498.6%

            \[\leadsto \mathsf{/.f64}\left(\mathsf{fmod.f64}\left(x, 1\right), \mathsf{exp.f64}\left(x\right)\right) \]
        3. Applied egg-rr98.6%

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

      Alternative 2: 62.9% accurate, 2.2× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.75 \cdot 10^{-103}:\\ \;\;\;\;\left(\left(\left(x \cdot x\right) \cdot \left(x \cdot \left(0.16666666666666666 + \frac{\frac{1}{x} + \left(0.5 + \frac{1}{x \cdot x}\right)}{x}\right)\right)\right) \bmod 1\right) \cdot e^{0 - x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(x \bmod 1\right)}{e^{x}}\\ \end{array} \end{array} \]
      (FPCore (x)
       :precision binary64
       (if (<= x -1.75e-103)
         (*
          (fmod
           (*
            (* x x)
            (*
             x
             (+ 0.16666666666666666 (/ (+ (/ 1.0 x) (+ 0.5 (/ 1.0 (* x x)))) x))))
           1.0)
          (exp (- 0.0 x)))
         (/ (fmod x 1.0) (exp x))))
      double code(double x) {
      	double tmp;
      	if (x <= -1.75e-103) {
      		tmp = fmod(((x * x) * (x * (0.16666666666666666 + (((1.0 / x) + (0.5 + (1.0 / (x * x)))) / x)))), 1.0) * exp((0.0 - x));
      	} else {
      		tmp = fmod(x, 1.0) / exp(x);
      	}
      	return tmp;
      }
      
      real(8) function code(x)
          real(8), intent (in) :: x
          real(8) :: tmp
          if (x <= (-1.75d-103)) then
              tmp = mod(((x * x) * (x * (0.16666666666666666d0 + (((1.0d0 / x) + (0.5d0 + (1.0d0 / (x * x)))) / x)))), 1.0d0) * exp((0.0d0 - x))
          else
              tmp = mod(x, 1.0d0) / exp(x)
          end if
          code = tmp
      end function
      
      def code(x):
      	tmp = 0
      	if x <= -1.75e-103:
      		tmp = math.fmod(((x * x) * (x * (0.16666666666666666 + (((1.0 / x) + (0.5 + (1.0 / (x * x)))) / x)))), 1.0) * math.exp((0.0 - x))
      	else:
      		tmp = math.fmod(x, 1.0) / math.exp(x)
      	return tmp
      
      function code(x)
      	tmp = 0.0
      	if (x <= -1.75e-103)
      		tmp = Float64(rem(Float64(Float64(x * x) * Float64(x * Float64(0.16666666666666666 + Float64(Float64(Float64(1.0 / x) + Float64(0.5 + Float64(1.0 / Float64(x * x)))) / x)))), 1.0) * exp(Float64(0.0 - x)));
      	else
      		tmp = Float64(rem(x, 1.0) / exp(x));
      	end
      	return tmp
      end
      
      code[x_] := If[LessEqual[x, -1.75e-103], N[(N[With[{TMP1 = N[(N[(x * x), $MachinePrecision] * N[(x * N[(0.16666666666666666 + N[(N[(N[(1.0 / x), $MachinePrecision] + N[(0.5 + N[(1.0 / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * N[Exp[N[(0.0 - x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[With[{TMP1 = x, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;x \leq -1.75 \cdot 10^{-103}:\\
      \;\;\;\;\left(\left(\left(x \cdot x\right) \cdot \left(x \cdot \left(0.16666666666666666 + \frac{\frac{1}{x} + \left(0.5 + \frac{1}{x \cdot x}\right)}{x}\right)\right)\right) \bmod 1\right) \cdot e^{0 - x}\\
      
      \mathbf{else}:\\
      \;\;\;\;\frac{\left(x \bmod 1\right)}{e^{x}}\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if x < -1.75000000000000008e-103

        1. Initial program 11.6%

          \[\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \]
        2. Add Preprocessing
        3. Taylor expanded in x around 0

          \[\leadsto \mathsf{*.f64}\left(\mathsf{fmod.f64}\left(\mathsf{exp.f64}\left(x\right), \color{blue}{1}\right), \mathsf{exp.f64}\left(\mathsf{neg.f64}\left(x\right)\right)\right) \]
        4. Step-by-step derivation
          1. Simplified11.6%

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

            \[\leadsto \mathsf{*.f64}\left(\mathsf{fmod.f64}\left(\color{blue}{\left(1 + x \cdot \left(1 + x \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot x\right)\right)\right)}, 1\right), \mathsf{exp.f64}\left(\mathsf{neg.f64}\left(x\right)\right)\right) \]
          3. Step-by-step derivation
            1. +-lowering-+.f64N/A

              \[\leadsto \mathsf{*.f64}\left(\mathsf{fmod.f64}\left(\mathsf{+.f64}\left(1, \left(x \cdot \left(1 + x \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot x\right)\right)\right)\right), 1\right), \mathsf{exp.f64}\left(\mathsf{neg.f64}\left(\color{blue}{x}\right)\right)\right) \]
            2. *-lowering-*.f64N/A

              \[\leadsto \mathsf{*.f64}\left(\mathsf{fmod.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \left(1 + x \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot x\right)\right)\right)\right), 1\right), \mathsf{exp.f64}\left(\mathsf{neg.f64}\left(x\right)\right)\right) \]
            3. +-lowering-+.f64N/A

              \[\leadsto \mathsf{*.f64}\left(\mathsf{fmod.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \left(x \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot x\right)\right)\right)\right)\right), 1\right), \mathsf{exp.f64}\left(\mathsf{neg.f64}\left(x\right)\right)\right) \]
            4. *-lowering-*.f64N/A

              \[\leadsto \mathsf{*.f64}\left(\mathsf{fmod.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \left(\frac{1}{2} + \frac{1}{6} \cdot x\right)\right)\right)\right)\right), 1\right), \mathsf{exp.f64}\left(\mathsf{neg.f64}\left(x\right)\right)\right) \]
            5. +-lowering-+.f64N/A

              \[\leadsto \mathsf{*.f64}\left(\mathsf{fmod.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \left(\frac{1}{6} \cdot x\right)\right)\right)\right)\right)\right), 1\right), \mathsf{exp.f64}\left(\mathsf{neg.f64}\left(x\right)\right)\right) \]
            6. *-commutativeN/A

              \[\leadsto \mathsf{*.f64}\left(\mathsf{fmod.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \left(x \cdot \frac{1}{6}\right)\right)\right)\right)\right)\right), 1\right), \mathsf{exp.f64}\left(\mathsf{neg.f64}\left(x\right)\right)\right) \]
            7. *-lowering-*.f648.8%

              \[\leadsto \mathsf{*.f64}\left(\mathsf{fmod.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \frac{1}{6}\right)\right)\right)\right)\right)\right), 1\right), \mathsf{exp.f64}\left(\mathsf{neg.f64}\left(x\right)\right)\right) \]
          4. Simplified8.8%

            \[\leadsto \left(\color{blue}{\left(1 + x \cdot \left(1 + x \cdot \left(0.5 + x \cdot 0.16666666666666666\right)\right)\right)} \bmod 1\right) \cdot e^{-x} \]
          5. Taylor expanded in x around -inf

            \[\leadsto \mathsf{*.f64}\left(\mathsf{fmod.f64}\left(\color{blue}{\left(-1 \cdot \left({x}^{3} \cdot \left(-1 \cdot \frac{\frac{1}{2} + \left(\frac{1}{x} + \frac{1}{{x}^{2}}\right)}{x} - \frac{1}{6}\right)\right)\right)}, 1\right), \mathsf{exp.f64}\left(\mathsf{neg.f64}\left(x\right)\right)\right) \]
          6. Step-by-step derivation
            1. mul-1-negN/A

              \[\leadsto \mathsf{*.f64}\left(\mathsf{fmod.f64}\left(\left(\mathsf{neg}\left({x}^{3} \cdot \left(-1 \cdot \frac{\frac{1}{2} + \left(\frac{1}{x} + \frac{1}{{x}^{2}}\right)}{x} - \frac{1}{6}\right)\right)\right), 1\right), \mathsf{exp.f64}\left(\mathsf{neg.f64}\left(\color{blue}{x}\right)\right)\right) \]
            2. unpow3N/A

              \[\leadsto \mathsf{*.f64}\left(\mathsf{fmod.f64}\left(\left(\mathsf{neg}\left(\left(\left(x \cdot x\right) \cdot x\right) \cdot \left(-1 \cdot \frac{\frac{1}{2} + \left(\frac{1}{x} + \frac{1}{{x}^{2}}\right)}{x} - \frac{1}{6}\right)\right)\right), 1\right), \mathsf{exp.f64}\left(\mathsf{neg.f64}\left(x\right)\right)\right) \]
            3. unpow2N/A

              \[\leadsto \mathsf{*.f64}\left(\mathsf{fmod.f64}\left(\left(\mathsf{neg}\left(\left({x}^{2} \cdot x\right) \cdot \left(-1 \cdot \frac{\frac{1}{2} + \left(\frac{1}{x} + \frac{1}{{x}^{2}}\right)}{x} - \frac{1}{6}\right)\right)\right), 1\right), \mathsf{exp.f64}\left(\mathsf{neg.f64}\left(x\right)\right)\right) \]
            4. associate-*l*N/A

              \[\leadsto \mathsf{*.f64}\left(\mathsf{fmod.f64}\left(\left(\mathsf{neg}\left({x}^{2} \cdot \left(x \cdot \left(-1 \cdot \frac{\frac{1}{2} + \left(\frac{1}{x} + \frac{1}{{x}^{2}}\right)}{x} - \frac{1}{6}\right)\right)\right)\right), 1\right), \mathsf{exp.f64}\left(\mathsf{neg.f64}\left(x\right)\right)\right) \]
            5. distribute-rgt-neg-inN/A

              \[\leadsto \mathsf{*.f64}\left(\mathsf{fmod.f64}\left(\left({x}^{2} \cdot \left(\mathsf{neg}\left(x \cdot \left(-1 \cdot \frac{\frac{1}{2} + \left(\frac{1}{x} + \frac{1}{{x}^{2}}\right)}{x} - \frac{1}{6}\right)\right)\right)\right), 1\right), \mathsf{exp.f64}\left(\mathsf{neg.f64}\left(\color{blue}{x}\right)\right)\right) \]
            6. *-commutativeN/A

              \[\leadsto \mathsf{*.f64}\left(\mathsf{fmod.f64}\left(\left({x}^{2} \cdot \left(\mathsf{neg}\left(\left(-1 \cdot \frac{\frac{1}{2} + \left(\frac{1}{x} + \frac{1}{{x}^{2}}\right)}{x} - \frac{1}{6}\right) \cdot x\right)\right)\right), 1\right), \mathsf{exp.f64}\left(\mathsf{neg.f64}\left(x\right)\right)\right) \]
            7. *-lowering-*.f64N/A

              \[\leadsto \mathsf{*.f64}\left(\mathsf{fmod.f64}\left(\mathsf{*.f64}\left(\left({x}^{2}\right), \left(\mathsf{neg}\left(\left(-1 \cdot \frac{\frac{1}{2} + \left(\frac{1}{x} + \frac{1}{{x}^{2}}\right)}{x} - \frac{1}{6}\right) \cdot x\right)\right)\right), 1\right), \mathsf{exp.f64}\left(\mathsf{neg.f64}\left(\color{blue}{x}\right)\right)\right) \]
            8. unpow2N/A

              \[\leadsto \mathsf{*.f64}\left(\mathsf{fmod.f64}\left(\mathsf{*.f64}\left(\left(x \cdot x\right), \left(\mathsf{neg}\left(\left(-1 \cdot \frac{\frac{1}{2} + \left(\frac{1}{x} + \frac{1}{{x}^{2}}\right)}{x} - \frac{1}{6}\right) \cdot x\right)\right)\right), 1\right), \mathsf{exp.f64}\left(\mathsf{neg.f64}\left(x\right)\right)\right) \]
            9. *-lowering-*.f64N/A

              \[\leadsto \mathsf{*.f64}\left(\mathsf{fmod.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \left(\mathsf{neg}\left(\left(-1 \cdot \frac{\frac{1}{2} + \left(\frac{1}{x} + \frac{1}{{x}^{2}}\right)}{x} - \frac{1}{6}\right) \cdot x\right)\right)\right), 1\right), \mathsf{exp.f64}\left(\mathsf{neg.f64}\left(x\right)\right)\right) \]
            10. *-commutativeN/A

              \[\leadsto \mathsf{*.f64}\left(\mathsf{fmod.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \left(\mathsf{neg}\left(x \cdot \left(-1 \cdot \frac{\frac{1}{2} + \left(\frac{1}{x} + \frac{1}{{x}^{2}}\right)}{x} - \frac{1}{6}\right)\right)\right)\right), 1\right), \mathsf{exp.f64}\left(\mathsf{neg.f64}\left(x\right)\right)\right) \]
            11. distribute-rgt-neg-inN/A

              \[\leadsto \mathsf{*.f64}\left(\mathsf{fmod.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \left(x \cdot \left(\mathsf{neg}\left(\left(-1 \cdot \frac{\frac{1}{2} + \left(\frac{1}{x} + \frac{1}{{x}^{2}}\right)}{x} - \frac{1}{6}\right)\right)\right)\right)\right), 1\right), \mathsf{exp.f64}\left(\mathsf{neg.f64}\left(x\right)\right)\right) \]
          7. Simplified17.3%

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

          if -1.75000000000000008e-103 < x

          1. Initial program 4.9%

            \[\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \]
          2. Add Preprocessing
          3. Taylor expanded in x around 0

            \[\leadsto \mathsf{*.f64}\left(\mathsf{fmod.f64}\left(\color{blue}{\left(1 + x\right)}, \mathsf{sqrt.f64}\left(\mathsf{cos.f64}\left(x\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{neg.f64}\left(x\right)\right)\right) \]
          4. Step-by-step derivation
            1. +-commutativeN/A

              \[\leadsto \mathsf{*.f64}\left(\mathsf{fmod.f64}\left(\left(x + 1\right), \mathsf{sqrt.f64}\left(\mathsf{cos.f64}\left(x\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{neg.f64}\left(\color{blue}{x}\right)\right)\right) \]
            2. +-lowering-+.f6429.3%

              \[\leadsto \mathsf{*.f64}\left(\mathsf{fmod.f64}\left(\mathsf{+.f64}\left(x, 1\right), \mathsf{sqrt.f64}\left(\mathsf{cos.f64}\left(x\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{neg.f64}\left(\color{blue}{x}\right)\right)\right) \]
          5. Simplified29.3%

            \[\leadsto \left(\color{blue}{\left(x + 1\right)} \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \]
          6. Taylor expanded in x around inf

            \[\leadsto \mathsf{*.f64}\left(\mathsf{fmod.f64}\left(\color{blue}{x}, \mathsf{sqrt.f64}\left(\mathsf{cos.f64}\left(x\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{neg.f64}\left(x\right)\right)\right) \]
          7. Step-by-step derivation
            1. Simplified72.6%

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

              \[\leadsto \mathsf{*.f64}\left(\mathsf{fmod.f64}\left(x, \color{blue}{1}\right), \mathsf{exp.f64}\left(\mathsf{neg.f64}\left(x\right)\right)\right) \]
            3. Step-by-step derivation
              1. Simplified72.6%

                \[\leadsto \left(x \bmod \color{blue}{1}\right) \cdot e^{-x} \]
              2. Step-by-step derivation
                1. exp-negN/A

                  \[\leadsto \left(x \bmod 1\right) \cdot \frac{1}{\color{blue}{e^{x}}} \]
                2. un-div-invN/A

                  \[\leadsto \frac{\left(x \bmod 1\right)}{\color{blue}{e^{x}}} \]
                3. /-lowering-/.f64N/A

                  \[\leadsto \mathsf{/.f64}\left(\left(x \bmod 1\right), \color{blue}{\left(e^{x}\right)}\right) \]
                4. fmod-lowering-fmod.f64N/A

                  \[\leadsto \mathsf{/.f64}\left(\mathsf{fmod.f64}\left(x, 1\right), \left(e^{\color{blue}{x}}\right)\right) \]
                5. exp-lowering-exp.f6472.6%

                  \[\leadsto \mathsf{/.f64}\left(\mathsf{fmod.f64}\left(x, 1\right), \mathsf{exp.f64}\left(x\right)\right) \]
              3. Applied egg-rr72.6%

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

              \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.75 \cdot 10^{-103}:\\ \;\;\;\;\left(\left(\left(x \cdot x\right) \cdot \left(x \cdot \left(0.16666666666666666 + \frac{\frac{1}{x} + \left(0.5 + \frac{1}{x \cdot x}\right)}{x}\right)\right)\right) \bmod 1\right) \cdot e^{0 - x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(x \bmod 1\right)}{e^{x}}\\ \end{array} \]
            6. Add Preprocessing

            Alternative 3: 59.2% accurate, 2.5× speedup?

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

              \[\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \]
            2. Add Preprocessing
            3. Taylor expanded in x around 0

              \[\leadsto \mathsf{*.f64}\left(\mathsf{fmod.f64}\left(\color{blue}{\left(1 + x\right)}, \mathsf{sqrt.f64}\left(\mathsf{cos.f64}\left(x\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{neg.f64}\left(x\right)\right)\right) \]
            4. Step-by-step derivation
              1. +-commutativeN/A

                \[\leadsto \mathsf{*.f64}\left(\mathsf{fmod.f64}\left(\left(x + 1\right), \mathsf{sqrt.f64}\left(\mathsf{cos.f64}\left(x\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{neg.f64}\left(\color{blue}{x}\right)\right)\right) \]
              2. +-lowering-+.f6426.5%

                \[\leadsto \mathsf{*.f64}\left(\mathsf{fmod.f64}\left(\mathsf{+.f64}\left(x, 1\right), \mathsf{sqrt.f64}\left(\mathsf{cos.f64}\left(x\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{neg.f64}\left(\color{blue}{x}\right)\right)\right) \]
            5. Simplified26.5%

              \[\leadsto \left(\color{blue}{\left(x + 1\right)} \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \]
            6. Taylor expanded in x around inf

              \[\leadsto \mathsf{*.f64}\left(\mathsf{fmod.f64}\left(\color{blue}{x}, \mathsf{sqrt.f64}\left(\mathsf{cos.f64}\left(x\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{neg.f64}\left(x\right)\right)\right) \]
            7. Step-by-step derivation
              1. Simplified63.2%

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

                \[\leadsto \mathsf{*.f64}\left(\mathsf{fmod.f64}\left(x, \color{blue}{1}\right), \mathsf{exp.f64}\left(\mathsf{neg.f64}\left(x\right)\right)\right) \]
              3. Step-by-step derivation
                1. Simplified63.2%

                  \[\leadsto \left(x \bmod \color{blue}{1}\right) \cdot e^{-x} \]
                2. Step-by-step derivation
                  1. exp-negN/A

                    \[\leadsto \left(x \bmod 1\right) \cdot \frac{1}{\color{blue}{e^{x}}} \]
                  2. un-div-invN/A

                    \[\leadsto \frac{\left(x \bmod 1\right)}{\color{blue}{e^{x}}} \]
                  3. /-lowering-/.f64N/A

                    \[\leadsto \mathsf{/.f64}\left(\left(x \bmod 1\right), \color{blue}{\left(e^{x}\right)}\right) \]
                  4. fmod-lowering-fmod.f64N/A

                    \[\leadsto \mathsf{/.f64}\left(\mathsf{fmod.f64}\left(x, 1\right), \left(e^{\color{blue}{x}}\right)\right) \]
                  5. exp-lowering-exp.f6463.2%

                    \[\leadsto \mathsf{/.f64}\left(\mathsf{fmod.f64}\left(x, 1\right), \mathsf{exp.f64}\left(x\right)\right) \]
                3. Applied egg-rr63.2%

                  \[\leadsto \color{blue}{\frac{\left(x \bmod 1\right)}{e^{x}}} \]
                4. Add Preprocessing

                Alternative 4: 58.3% accurate, 5.0× speedup?

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

                  \[\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \]
                2. Add Preprocessing
                3. Taylor expanded in x around 0

                  \[\leadsto \mathsf{*.f64}\left(\mathsf{fmod.f64}\left(\color{blue}{\left(1 + x\right)}, \mathsf{sqrt.f64}\left(\mathsf{cos.f64}\left(x\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{neg.f64}\left(x\right)\right)\right) \]
                4. Step-by-step derivation
                  1. +-commutativeN/A

                    \[\leadsto \mathsf{*.f64}\left(\mathsf{fmod.f64}\left(\left(x + 1\right), \mathsf{sqrt.f64}\left(\mathsf{cos.f64}\left(x\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{neg.f64}\left(\color{blue}{x}\right)\right)\right) \]
                  2. +-lowering-+.f6426.5%

                    \[\leadsto \mathsf{*.f64}\left(\mathsf{fmod.f64}\left(\mathsf{+.f64}\left(x, 1\right), \mathsf{sqrt.f64}\left(\mathsf{cos.f64}\left(x\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{neg.f64}\left(\color{blue}{x}\right)\right)\right) \]
                5. Simplified26.5%

                  \[\leadsto \left(\color{blue}{\left(x + 1\right)} \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \]
                6. Taylor expanded in x around inf

                  \[\leadsto \mathsf{*.f64}\left(\mathsf{fmod.f64}\left(\color{blue}{x}, \mathsf{sqrt.f64}\left(\mathsf{cos.f64}\left(x\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{neg.f64}\left(x\right)\right)\right) \]
                7. Step-by-step derivation
                  1. Simplified63.2%

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

                    \[\leadsto \mathsf{*.f64}\left(\mathsf{fmod.f64}\left(x, \color{blue}{1}\right), \mathsf{exp.f64}\left(\mathsf{neg.f64}\left(x\right)\right)\right) \]
                  3. Step-by-step derivation
                    1. Simplified63.2%

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

                      \[\leadsto \color{blue}{\left(x \bmod 1\right)} \]
                    3. Step-by-step derivation
                      1. fmod-lowering-fmod.f6462.1%

                        \[\leadsto \mathsf{fmod.f64}\left(x, \color{blue}{1}\right) \]
                    4. Simplified62.1%

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

                    Alternative 5: 23.0% 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 5.8%

                      \[\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \]
                    2. Add Preprocessing
                    3. Taylor expanded in x around 0

                      \[\leadsto \color{blue}{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)} \]
                    4. Step-by-step derivation
                      1. fmod-lowering-fmod.f64N/A

                        \[\leadsto \mathsf{fmod.f64}\left(\left(e^{x}\right), \color{blue}{\left(\sqrt{\cos x}\right)}\right) \]
                      2. exp-lowering-exp.f64N/A

                        \[\leadsto \mathsf{fmod.f64}\left(\mathsf{exp.f64}\left(x\right), \left(\sqrt{\color{blue}{\cos x}}\right)\right) \]
                      3. sqrt-lowering-sqrt.f64N/A

                        \[\leadsto \mathsf{fmod.f64}\left(\mathsf{exp.f64}\left(x\right), \mathsf{sqrt.f64}\left(\cos x\right)\right) \]
                      4. cos-lowering-cos.f644.8%

                        \[\leadsto \mathsf{fmod.f64}\left(\mathsf{exp.f64}\left(x\right), \mathsf{sqrt.f64}\left(\mathsf{cos.f64}\left(x\right)\right)\right) \]
                    5. Simplified4.8%

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

                      \[\leadsto \mathsf{fmod.f64}\left(\mathsf{exp.f64}\left(x\right), \color{blue}{1}\right) \]
                    7. Step-by-step derivation
                      1. Simplified4.8%

                        \[\leadsto \left(\left(e^{x}\right) \bmod \color{blue}{1}\right) \]
                      2. Taylor expanded in x around 0

                        \[\leadsto \mathsf{fmod.f64}\left(\color{blue}{1}, 1\right) \]
                      3. Step-by-step derivation
                        1. Simplified24.8%

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

                        Reproduce

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