expfmod (used to be hard to sample)

Percentage Accurate: 6.7% → 10.2%
Time: 20.1s
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.7% 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: 10.2% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\\ t_1 := \mathsf{expm1}\left(x + t_0\right)\\ t_2 := \mathsf{expm1}\left(t_0 - x\right)\\ \frac{\frac{1}{1 - {t_1}^{3}} - \frac{{t_1}^{6}}{1 - {\left(\mathsf{expm1}\left(x + \left|t_0\right|\right)\right)}^{3}}}{1 + t_2 \cdot \left(t_2 + -1\right)} \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (log (fmod (exp x) (sqrt (cos x)))))
        (t_1 (expm1 (+ x t_0)))
        (t_2 (expm1 (- t_0 x))))
   (/
    (-
     (/ 1.0 (- 1.0 (pow t_1 3.0)))
     (/ (pow t_1 6.0) (- 1.0 (pow (expm1 (+ x (fabs t_0))) 3.0))))
    (+ 1.0 (* t_2 (+ t_2 -1.0))))))
double code(double x) {
	double t_0 = log(fmod(exp(x), sqrt(cos(x))));
	double t_1 = expm1((x + t_0));
	double t_2 = expm1((t_0 - x));
	return ((1.0 / (1.0 - pow(t_1, 3.0))) - (pow(t_1, 6.0) / (1.0 - pow(expm1((x + fabs(t_0))), 3.0)))) / (1.0 + (t_2 * (t_2 + -1.0)));
}
def code(x):
	t_0 = math.log(math.fmod(math.exp(x), math.sqrt(math.cos(x))))
	t_1 = math.expm1((x + t_0))
	t_2 = math.expm1((t_0 - x))
	return ((1.0 / (1.0 - math.pow(t_1, 3.0))) - (math.pow(t_1, 6.0) / (1.0 - math.pow(math.expm1((x + math.fabs(t_0))), 3.0)))) / (1.0 + (t_2 * (t_2 + -1.0)))
function code(x)
	t_0 = log(rem(exp(x), sqrt(cos(x))))
	t_1 = expm1(Float64(x + t_0))
	t_2 = expm1(Float64(t_0 - x))
	return Float64(Float64(Float64(1.0 / Float64(1.0 - (t_1 ^ 3.0))) - Float64((t_1 ^ 6.0) / Float64(1.0 - (expm1(Float64(x + abs(t_0))) ^ 3.0)))) / Float64(1.0 + Float64(t_2 * Float64(t_2 + -1.0))))
end
code[x_] := Block[{t$95$0 = N[Log[N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(Exp[N[(x + t$95$0), $MachinePrecision]] - 1), $MachinePrecision]}, Block[{t$95$2 = N[(Exp[N[(t$95$0 - x), $MachinePrecision]] - 1), $MachinePrecision]}, N[(N[(N[(1.0 / N[(1.0 - N[Power[t$95$1, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Power[t$95$1, 6.0], $MachinePrecision] / N[(1.0 - N[Power[N[(Exp[N[(x + N[Abs[t$95$0], $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[(t$95$2 * N[(t$95$2 + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\\
t_1 := \mathsf{expm1}\left(x + t_0\right)\\
t_2 := \mathsf{expm1}\left(t_0 - x\right)\\
\frac{\frac{1}{1 - {t_1}^{3}} - \frac{{t_1}^{6}}{1 - {\left(\mathsf{expm1}\left(x + \left|t_0\right|\right)\right)}^{3}}}{1 + t_2 \cdot \left(t_2 + -1\right)}
\end{array}
\end{array}
Derivation
  1. Initial program 5.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1 + {\left(\mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - \color{blue}{x}\right)\right)}^{3}}{1 \cdot 1 + \left(\left(\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}} - 1\right) \cdot \left(\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}} - 1\right) - 1 \cdot \left(\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}} - 1\right)\right)} \]
  7. Applied egg-rr5.9%

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

      \[\leadsto \frac{1 + {\left(\mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x\right)\right)}^{3}}{1 + \left(\mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x\right) \cdot \mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x\right) - \color{blue}{\mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x\right) \cdot 1}\right)} \]
    2. distribute-lft-out--5.9%

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

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{1}{1 - {\left(\mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x\right)\right)}^{3}} - \frac{{\left(\mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x\right)\right)}^{3} \cdot {\left(\mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x\right)\right)}^{3}}{1 - {\left(\mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x\right)\right)}^{3}}}}{1 + \mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x\right) \cdot \left(\mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x\right) - 1\right)} \]
  11. Applied egg-rr5.5%

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

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

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

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

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

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

      \[\leadsto \frac{\frac{1}{1 - {\left(\mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) + x\right)\right)}^{3}} - \frac{{\left(\mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) + x\right)\right)}^{6}}{1 - {\left(\mathsf{expm1}\left(\color{blue}{\left|\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\right|} + x\right)\right)}^{3}}}{1 + \mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x\right) \cdot \left(\mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x\right) - 1\right)} \]
  15. Simplified11.0%

    \[\leadsto \frac{\frac{1}{1 - {\left(\mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) + x\right)\right)}^{3}} - \frac{{\left(\mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) + x\right)\right)}^{6}}{1 - {\left(\mathsf{expm1}\left(\color{blue}{\left|\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\right|} + x\right)\right)}^{3}}}{1 + \mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x\right) \cdot \left(\mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x\right) - 1\right)} \]
  16. Final simplification11.0%

    \[\leadsto \frac{\frac{1}{1 - {\left(\mathsf{expm1}\left(x + \log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\right)\right)}^{3}} - \frac{{\left(\mathsf{expm1}\left(x + \log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\right)\right)}^{6}}{1 - {\left(\mathsf{expm1}\left(x + \left|\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\right|\right)\right)}^{3}}}{1 + \mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x\right) \cdot \left(\mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x\right) + -1\right)} \]

Alternative 2: 6.7% accurate, 0.3× speedup?

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

\\
\begin{array}{l}
t_0 := \mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x\right)\\
\frac{1 + {t_0}^{3}}{1 + t_0 \cdot \left(t_0 + -1\right)}
\end{array}
\end{array}
Derivation
  1. Initial program 5.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1 + {\left(\mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - \color{blue}{x}\right)\right)}^{3}}{1 \cdot 1 + \left(\left(\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}} - 1\right) \cdot \left(\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}} - 1\right) - 1 \cdot \left(\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}} - 1\right)\right)} \]
  7. Applied egg-rr5.9%

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

      \[\leadsto \frac{1 + {\left(\mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x\right)\right)}^{3}}{1 + \left(\mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x\right) \cdot \mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x\right) - \color{blue}{\mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x\right) \cdot 1}\right)} \]
    2. distribute-lft-out--5.9%

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

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

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

Alternative 3: 6.7% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x\right)\\ \frac{1 - t_0 \cdot t_0}{1 - t_0} \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (expm1 (- (log (fmod (exp x) (sqrt (cos x)))) x))))
   (/ (- 1.0 (* t_0 t_0)) (- 1.0 t_0))))
double code(double x) {
	double t_0 = expm1((log(fmod(exp(x), sqrt(cos(x)))) - x));
	return (1.0 - (t_0 * t_0)) / (1.0 - t_0);
}
def code(x):
	t_0 = math.expm1((math.log(math.fmod(math.exp(x), math.sqrt(math.cos(x)))) - x))
	return (1.0 - (t_0 * t_0)) / (1.0 - t_0)
function code(x)
	t_0 = expm1(Float64(log(rem(exp(x), sqrt(cos(x)))) - x))
	return Float64(Float64(1.0 - Float64(t_0 * t_0)) / Float64(1.0 - t_0))
end
code[x_] := Block[{t$95$0 = N[(Exp[N[(N[Log[N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]], $MachinePrecision] - x), $MachinePrecision]] - 1), $MachinePrecision]}, N[(N[(1.0 - N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision] / N[(1.0 - t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x\right)\\
\frac{1 - t_0 \cdot t_0}{1 - t_0}
\end{array}
\end{array}
Derivation
  1. Initial program 5.8%

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{1 - \mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x\right) \cdot \mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x\right)}{1 - \mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x\right)}} \]
  8. Final simplification5.9%

    \[\leadsto \frac{1 - \mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x\right) \cdot \mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x\right)}{1 - \mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x\right)} \]

Alternative 4: 6.7% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \frac{\left(\left(e^{x}\right) \bmod \left({\left({\cos x}^{1.5}\right)}^{0.3333333333333333}\right)\right)}{e^{x}} \end{array} \]
(FPCore (x)
 :precision binary64
 (/ (fmod (exp x) (pow (pow (cos x) 1.5) 0.3333333333333333)) (exp x)))
double code(double x) {
	return fmod(exp(x), pow(pow(cos(x), 1.5), 0.3333333333333333)) / exp(x);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = mod(exp(x), ((cos(x) ** 1.5d0) ** 0.3333333333333333d0)) / exp(x)
end function
def code(x):
	return math.fmod(math.exp(x), math.pow(math.pow(math.cos(x), 1.5), 0.3333333333333333)) / math.exp(x)
function code(x)
	return Float64(rem(exp(x), ((cos(x) ^ 1.5) ^ 0.3333333333333333)) / exp(x))
end
code[x_] := N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Power[N[Power[N[Cos[x], $MachinePrecision], 1.5], $MachinePrecision], 0.3333333333333333], $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({\left({\cos x}^{1.5}\right)}^{0.3333333333333333}\right)\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. Step-by-step derivation
    1. exp-neg5.8%

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

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

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

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

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

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

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\left(\color{blue}{\cos x} \cdot \sqrt{\cos x}\right)}^{0.3333333333333333}\right)\right)}{e^{x}} \]
    4. pow15.8%

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

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\left({\cos x}^{1} \cdot \color{blue}{{\cos x}^{0.5}}\right)}^{0.3333333333333333}\right)\right)}{e^{x}} \]
    6. pow-prod-up5.8%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\color{blue}{\left({\cos x}^{\left(1 + 0.5\right)}\right)}}^{0.3333333333333333}\right)\right)}{e^{x}} \]
    7. metadata-eval5.8%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\left({\cos x}^{\color{blue}{1.5}}\right)}^{0.3333333333333333}\right)\right)}{e^{x}} \]
  5. Applied egg-rr5.8%

    \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \color{blue}{\left({\left({\cos x}^{1.5}\right)}^{0.3333333333333333}\right)}\right)}{e^{x}} \]
  6. Final simplification5.8%

    \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\left({\cos x}^{1.5}\right)}^{0.3333333333333333}\right)\right)}{e^{x}} \]

Alternative 5: 6.7% accurate, 1.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 6.7% 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 5.8%

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

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

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

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

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

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

Alternative 7: 6.4% accurate, 1.6× speedup?

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

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

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

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

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

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

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

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

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

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

Alternative 8: 6.2% 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 5.8%

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

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

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

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

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

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

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

Alternative 9: 5.2% 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 5.8%

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

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

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

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

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

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

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

    \[\leadsto \left(\left(e^{x}\right) \bmod 1\right) \]

Reproduce

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