expfmod (used to be hard to sample)

Percentage Accurate: 6.8% → 43.1%
Time: 28.0s
Alternatives: 9
Speedup: 1.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: 6.8% 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: 43.1% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt{\cos x}\\ \frac{\left(\left(e^{x}\right) \bmod \left(t\_0 \cdot 0.6666666666666666 + \log \left(\sqrt[3]{e^{t\_0}}\right)\right)\right)}{e^{x}} \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (sqrt (cos x))))
   (/
    (fmod (exp x) (+ (* t_0 0.6666666666666666) (log (cbrt (exp t_0)))))
    (exp x))))
double code(double x) {
	double t_0 = sqrt(cos(x));
	return fmod(exp(x), ((t_0 * 0.6666666666666666) + log(cbrt(exp(t_0))))) / exp(x);
}
function code(x)
	t_0 = sqrt(cos(x))
	return Float64(rem(exp(x), Float64(Float64(t_0 * 0.6666666666666666) + log(cbrt(exp(t_0))))) / exp(x))
end
code[x_] := Block[{t$95$0 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(N[(t$95$0 * 0.6666666666666666), $MachinePrecision] + N[Log[N[Power[N[Exp[t$95$0], $MachinePrecision], 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 := \sqrt{\cos x}\\
\frac{\left(\left(e^{x}\right) \bmod \left(t\_0 \cdot 0.6666666666666666 + \log \left(\sqrt[3]{e^{t\_0}}\right)\right)\right)}{e^{x}}
\end{array}
\end{array}
Derivation
  1. Initial program 7.3%

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

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

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

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

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

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

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

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

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

    \[\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}} \]
  7. Step-by-step derivation
    1. unpow243.5%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\log \color{blue}{\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}} \]
    2. log-prod43.5%

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

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

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

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

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

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

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

    \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\color{blue}{\left(0.3333333333333333 \cdot \sqrt{\cos x} + 0.3333333333333333 \cdot \sqrt{\cos x}\right)} + \log \left(\sqrt[3]{e^{\sqrt{\cos x}}}\right)\right)\right)}{e^{x}} \]
  9. Step-by-step derivation
    1. distribute-rgt-out43.6%

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

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

    \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\color{blue}{\sqrt{\cos x} \cdot 0.6666666666666666} + \log \left(\sqrt[3]{e^{\sqrt{\cos x}}}\right)\right)\right)}{e^{x}} \]
  11. Final simplification43.6%

    \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x} \cdot 0.6666666666666666 + \log \left(\sqrt[3]{e^{\sqrt{\cos x}}}\right)\right)\right)}{e^{x}} \]
  12. Add Preprocessing

Alternative 2: 42.8% accurate, 0.7× speedup?

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

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

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

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

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

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

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

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

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

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

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

    \[\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}} \]
  7. Step-by-step derivation
    1. unpow243.5%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\log \color{blue}{\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}} \]
    2. log-prod43.5%

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

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

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

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

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

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

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

    \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\color{blue}{\left(0.3333333333333333 \cdot \sqrt{\cos x} + 0.3333333333333333 \cdot \sqrt{\cos x}\right)} + \log \left(\sqrt[3]{e^{\sqrt{\cos x}}}\right)\right)\right)}{e^{x}} \]
  9. Step-by-step derivation
    1. distribute-rgt-out43.6%

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

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

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

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

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

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

    \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x} \cdot 0.6666666666666666 + \log \left(\sqrt[3]{e}\right)\right)\right)}{e^{x}} \]
  15. Add Preprocessing

Alternative 3: 42.7% accurate, 1.0× speedup?

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

\\
\frac{\left(\left(e^{x}\right) \bmod \left(0.6666666666666666 + \log \left(\sqrt[3]{e}\right)\right)\right)}{e^{x}}
\end{array}
Derivation
  1. Initial program 7.3%

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

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

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

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

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

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

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

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

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

    \[\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}} \]
  7. Step-by-step derivation
    1. unpow243.5%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\log \color{blue}{\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}} \]
    2. log-prod43.5%

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

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

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

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

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

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

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

    \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\color{blue}{\left(0.3333333333333333 \cdot \sqrt{\cos x} + 0.3333333333333333 \cdot \sqrt{\cos x}\right)} + \log \left(\sqrt[3]{e^{\sqrt{\cos x}}}\right)\right)\right)}{e^{x}} \]
  9. Step-by-step derivation
    1. distribute-rgt-out43.6%

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

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

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

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

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

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

    \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\color{blue}{1} \cdot 0.6666666666666666 + \log \left(\sqrt[3]{e}\right)\right)\right)}{e^{x}} \]
  15. Final simplification43.0%

    \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(0.6666666666666666 + \log \left(\sqrt[3]{e}\right)\right)\right)}{e^{x}} \]
  16. Add Preprocessing

Alternative 4: 6.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{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(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}

\\
\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}
\end{array}
Derivation
  1. Initial program 7.3%

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}} \]
  4. Add Preprocessing
  5. Final simplification7.3%

    \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}} \]
  6. Add Preprocessing

Alternative 5: 6.6% accurate, 1.2× speedup?

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

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

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

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

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

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

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

    \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \color{blue}{\left(1 + -0.25 \cdot {x}^{2}\right)}\right)}{e^{x}} \]
  6. Final simplification7.1%

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

Alternative 6: 6.4% accurate, 1.7× speedup?

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

\\
\frac{\left(\left(e^{x}\right) \bmod 1\right)}{e^{x}}
\end{array}
Derivation
  1. Initial program 7.3%

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

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

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

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

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

    \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \color{blue}{1}\right)}{e^{x}} \]
  6. Final simplification6.8%

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

Alternative 7: 5.8% accurate, 2.4× speedup?

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\left(e^{x}\right) \bmod 1\right) + -1 \cdot \left(x \cdot \left(\left(e^{x}\right) \bmod 1\right)\right)} \]
    2. *-lft-identity6.1%

      \[\leadsto \color{blue}{1 \cdot \left(\left(e^{x}\right) \bmod 1\right)} + -1 \cdot \left(x \cdot \left(\left(e^{x}\right) \bmod 1\right)\right) \]
    3. associate-*r*6.1%

      \[\leadsto 1 \cdot \left(\left(e^{x}\right) \bmod 1\right) + \color{blue}{\left(-1 \cdot x\right) \cdot \left(\left(e^{x}\right) \bmod 1\right)} \]
    4. neg-mul-16.1%

      \[\leadsto 1 \cdot \left(\left(e^{x}\right) \bmod 1\right) + \color{blue}{\left(-x\right)} \cdot \left(\left(e^{x}\right) \bmod 1\right) \]
    5. distribute-rgt-out6.1%

      \[\leadsto \color{blue}{\left(\left(e^{x}\right) \bmod 1\right) \cdot \left(1 + \left(-x\right)\right)} \]
    6. sub-neg6.1%

      \[\leadsto \left(\left(e^{x}\right) \bmod 1\right) \cdot \color{blue}{\left(1 - x\right)} \]
  8. Simplified6.1%

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

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

      \[\leadsto x \cdot \left(\color{blue}{\left(\left(e^{x}\right) \bmod 1\right) \cdot -1} + \frac{\left(\left(e^{x}\right) \bmod 1\right)}{x}\right) \]
    2. *-rgt-identity6.1%

      \[\leadsto x \cdot \left(\left(\left(e^{x}\right) \bmod 1\right) \cdot -1 + \frac{\color{blue}{\left(\left(e^{x}\right) \bmod 1\right) \cdot 1}}{x}\right) \]
    3. associate-/l*6.1%

      \[\leadsto x \cdot \left(\left(\left(e^{x}\right) \bmod 1\right) \cdot -1 + \color{blue}{\left(\left(e^{x}\right) \bmod 1\right) \cdot \frac{1}{x}}\right) \]
    4. distribute-lft-out6.1%

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

    \[\leadsto \color{blue}{x \cdot \left(\left(\left(e^{x}\right) \bmod 1\right) \cdot \left(-1 + \frac{1}{x}\right)\right)} \]
  12. Final simplification6.1%

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

Alternative 8: 5.8% accurate, 2.5× speedup?

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\left(e^{x}\right) \bmod 1\right) + -1 \cdot \left(x \cdot \left(\left(e^{x}\right) \bmod 1\right)\right)} \]
    2. *-lft-identity6.1%

      \[\leadsto \color{blue}{1 \cdot \left(\left(e^{x}\right) \bmod 1\right)} + -1 \cdot \left(x \cdot \left(\left(e^{x}\right) \bmod 1\right)\right) \]
    3. associate-*r*6.1%

      \[\leadsto 1 \cdot \left(\left(e^{x}\right) \bmod 1\right) + \color{blue}{\left(-1 \cdot x\right) \cdot \left(\left(e^{x}\right) \bmod 1\right)} \]
    4. neg-mul-16.1%

      \[\leadsto 1 \cdot \left(\left(e^{x}\right) \bmod 1\right) + \color{blue}{\left(-x\right)} \cdot \left(\left(e^{x}\right) \bmod 1\right) \]
    5. distribute-rgt-out6.1%

      \[\leadsto \color{blue}{\left(\left(e^{x}\right) \bmod 1\right) \cdot \left(1 + \left(-x\right)\right)} \]
    6. sub-neg6.1%

      \[\leadsto \left(\left(e^{x}\right) \bmod 1\right) \cdot \color{blue}{\left(1 - x\right)} \]
  8. Simplified6.1%

    \[\leadsto \color{blue}{\left(\left(e^{x}\right) \bmod 1\right) \cdot \left(1 - x\right)} \]
  9. Final simplification6.1%

    \[\leadsto \left(\left(e^{x}\right) \bmod 1\right) \cdot \left(1 - x\right) \]
  10. Add Preprocessing

Alternative 9: 5.3% accurate, 2.5× speedup?

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

\\
\left(\left(e^{x}\right) \bmod 1\right)
\end{array}
Derivation
  1. Initial program 7.3%

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

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

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

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

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

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

    \[\leadsto \color{blue}{\left(\left(e^{x}\right) \bmod 1\right)} \]
  7. Final simplification5.3%

    \[\leadsto \left(\left(e^{x}\right) \bmod 1\right) \]
  8. Add Preprocessing

Reproduce

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