expfmod (used to be hard to sample)

Percentage Accurate: 7.0% → 8.4%
Time: 13.5s
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: 7.0% accurate, 1.0× speedup?

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

\\
\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x}
\end{array}

Alternative 1: 8.4% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt[3]{\mathsf{fma}\left(\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right), 1 - x, 2\right)}\\ \mathsf{fma}\left(t\_0 \cdot t\_0, t\_0, -1\right) + -1 \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (cbrt (fma (fmod (exp x) (sqrt (cos x))) (- 1.0 x) 2.0))))
   (+ (fma (* t_0 t_0) t_0 -1.0) -1.0)))
double code(double x) {
	double t_0 = cbrt(fma(fmod(exp(x), sqrt(cos(x))), (1.0 - x), 2.0));
	return fma((t_0 * t_0), t_0, -1.0) + -1.0;
}
function code(x)
	t_0 = cbrt(fma(rem(exp(x), sqrt(cos(x))), Float64(1.0 - x), 2.0))
	return Float64(fma(Float64(t_0 * t_0), t_0, -1.0) + -1.0)
end
code[x_] := Block[{t$95$0 = N[Power[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[(1.0 - x), $MachinePrecision] + 2.0), $MachinePrecision], 1/3], $MachinePrecision]}, N[(N[(N[(t$95$0 * t$95$0), $MachinePrecision] * t$95$0 + -1.0), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sqrt[3]{\mathsf{fma}\left(\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right), 1 - x, 2\right)}\\
\mathsf{fma}\left(t\_0 \cdot t\_0, t\_0, -1\right) + -1
\end{array}
\end{array}
Derivation
  1. Initial program 7.5%

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. add-exp-log7.5%

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

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

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

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

      \[\leadsto \frac{\color{blue}{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}}{e^{x}} \]
    3. expm1-log1p-u7.5%

      \[\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)} \]
    4. expm1-define7.5%

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

      \[\leadsto e^{\color{blue}{\log \left(1 + \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}\right)}} - 1 \]
    6. rem-exp-log7.5%

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

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

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

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

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

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

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

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

    \[\leadsto \left(1 + \color{blue}{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot \left(1 - x\right)}\right) - 1 \]
  12. Step-by-step derivation
    1. expm1-log1p-u6.5%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(1 + \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot \left(1 - x\right)\right)\right)} - 1 \]
    2. expm1-undefine6.5%

      \[\leadsto \color{blue}{\left(e^{\mathsf{log1p}\left(1 + \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot \left(1 - x\right)\right)} - 1\right)} - 1 \]
    3. log1p-undefine6.6%

      \[\leadsto \left(e^{\color{blue}{\log \left(1 + \left(1 + \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot \left(1 - x\right)\right)\right)}} - 1\right) - 1 \]
    4. +-commutative6.6%

      \[\leadsto \left(e^{\log \color{blue}{\left(\left(1 + \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot \left(1 - x\right)\right) + 1\right)}} - 1\right) - 1 \]
    5. add-exp-log6.6%

      \[\leadsto \left(\color{blue}{\left(\left(1 + \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot \left(1 - x\right)\right) + 1\right)} - 1\right) - 1 \]
    6. add-cube-cbrt8.9%

      \[\leadsto \left(\color{blue}{\left(\sqrt[3]{\left(1 + \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot \left(1 - x\right)\right) + 1} \cdot \sqrt[3]{\left(1 + \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot \left(1 - x\right)\right) + 1}\right) \cdot \sqrt[3]{\left(1 + \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot \left(1 - x\right)\right) + 1}} - 1\right) - 1 \]
    7. fmm-def8.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt[3]{\left(1 + \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot \left(1 - x\right)\right) + 1} \cdot \sqrt[3]{\left(1 + \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot \left(1 - x\right)\right) + 1}, \sqrt[3]{\left(1 + \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot \left(1 - x\right)\right) + 1}, -1\right)} - 1 \]
  13. Applied egg-rr8.9%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt[3]{\mathsf{fma}\left(\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right), 1 - x, 2\right)} \cdot \sqrt[3]{\mathsf{fma}\left(\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right), 1 - x, 2\right)}, \sqrt[3]{\mathsf{fma}\left(\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right), 1 - x, 2\right)}, -1\right)} - 1 \]
  14. Final simplification8.9%

    \[\leadsto \mathsf{fma}\left(\sqrt[3]{\mathsf{fma}\left(\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right), 1 - x, 2\right)} \cdot \sqrt[3]{\mathsf{fma}\left(\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right), 1 - x, 2\right)}, \sqrt[3]{\mathsf{fma}\left(\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right), 1 - x, 2\right)}, -1\right) + -1 \]
  15. Add Preprocessing

Alternative 2: 8.4% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt{\mathsf{fma}\left(\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right), 1 - x, 2\right)}\\ \mathsf{fma}\left(t\_0, t\_0, -1\right) + -1 \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (sqrt (fma (fmod (exp x) (sqrt (cos x))) (- 1.0 x) 2.0))))
   (+ (fma t_0 t_0 -1.0) -1.0)))
double code(double x) {
	double t_0 = sqrt(fma(fmod(exp(x), sqrt(cos(x))), (1.0 - x), 2.0));
	return fma(t_0, t_0, -1.0) + -1.0;
}
function code(x)
	t_0 = sqrt(fma(rem(exp(x), sqrt(cos(x))), Float64(1.0 - x), 2.0))
	return Float64(fma(t_0, t_0, -1.0) + -1.0)
end
code[x_] := Block[{t$95$0 = N[Sqrt[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[(1.0 - x), $MachinePrecision] + 2.0), $MachinePrecision]], $MachinePrecision]}, N[(N[(t$95$0 * t$95$0 + -1.0), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{fma}\left(\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right), 1 - x, 2\right)}\\
\mathsf{fma}\left(t\_0, t\_0, -1\right) + -1
\end{array}
\end{array}
Derivation
  1. Initial program 7.5%

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. add-exp-log7.5%

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

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

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

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

      \[\leadsto \frac{\color{blue}{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}}{e^{x}} \]
    3. expm1-log1p-u7.5%

      \[\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)} \]
    4. expm1-define7.5%

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

      \[\leadsto e^{\color{blue}{\log \left(1 + \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}\right)}} - 1 \]
    6. rem-exp-log7.5%

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

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

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

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

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

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

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

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

    \[\leadsto \left(1 + \color{blue}{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot \left(1 - x\right)}\right) - 1 \]
  12. Step-by-step derivation
    1. expm1-log1p-u6.5%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(1 + \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot \left(1 - x\right)\right)\right)} - 1 \]
    2. expm1-undefine6.5%

      \[\leadsto \color{blue}{\left(e^{\mathsf{log1p}\left(1 + \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot \left(1 - x\right)\right)} - 1\right)} - 1 \]
    3. log1p-undefine6.6%

      \[\leadsto \left(e^{\color{blue}{\log \left(1 + \left(1 + \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot \left(1 - x\right)\right)\right)}} - 1\right) - 1 \]
    4. +-commutative6.6%

      \[\leadsto \left(e^{\log \color{blue}{\left(\left(1 + \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot \left(1 - x\right)\right) + 1\right)}} - 1\right) - 1 \]
    5. add-exp-log6.6%

      \[\leadsto \left(\color{blue}{\left(\left(1 + \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot \left(1 - x\right)\right) + 1\right)} - 1\right) - 1 \]
    6. add-sqr-sqrt8.9%

      \[\leadsto \left(\color{blue}{\sqrt{\left(1 + \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot \left(1 - x\right)\right) + 1} \cdot \sqrt{\left(1 + \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot \left(1 - x\right)\right) + 1}} - 1\right) - 1 \]
    7. fmm-def8.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{\left(1 + \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot \left(1 - x\right)\right) + 1}, \sqrt{\left(1 + \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot \left(1 - x\right)\right) + 1}, -1\right)} - 1 \]
  13. Applied egg-rr8.8%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{\mathsf{fma}\left(\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right), 1 - x, 2\right)}, \sqrt{\mathsf{fma}\left(\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right), 1 - x, 2\right)}, -1\right)} - 1 \]
  14. Final simplification8.8%

    \[\leadsto \mathsf{fma}\left(\sqrt{\mathsf{fma}\left(\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right), 1 - x, 2\right)}, \sqrt{\mathsf{fma}\left(\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right), 1 - x, 2\right)}, -1\right) + -1 \]
  15. Add Preprocessing

Alternative 3: 7.0% accurate, 0.8× speedup?

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. add-exp-log7.5%

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

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

    \[\leadsto \color{blue}{e^{\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x}} \]
  7. Final simplification7.5%

    \[\leadsto e^{\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x} \]
  8. Add Preprocessing

Alternative 4: 6.9% 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 7.5%

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. add-exp-log7.5%

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

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

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

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

      \[\leadsto \frac{\color{blue}{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}}{e^{x}} \]
    3. expm1-log1p-u7.5%

      \[\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)} \]
    4. expm1-define7.5%

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

      \[\leadsto e^{\color{blue}{\log \left(1 + \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}\right)}} - 1 \]
    6. rem-exp-log7.5%

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

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

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

Alternative 5: 7.0% 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.5%

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

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

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

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

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

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

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

Alternative 6: 6.0% accurate, 1.2× speedup?

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. add-exp-log7.5%

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

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

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

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

      \[\leadsto \frac{\color{blue}{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}}{e^{x}} \]
    3. expm1-log1p-u7.5%

      \[\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)} \]
    4. expm1-define7.5%

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

      \[\leadsto e^{\color{blue}{\log \left(1 + \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}\right)}} - 1 \]
    6. rem-exp-log7.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 6.0% accurate, 1.2× speedup?

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. add-exp-log7.5%

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

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

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

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

      \[\leadsto \frac{\color{blue}{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}}{e^{x}} \]
    3. expm1-log1p-u7.5%

      \[\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)} \]
    4. expm1-define7.5%

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

      \[\leadsto e^{\color{blue}{\log \left(1 + \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}\right)}} - 1 \]
    6. rem-exp-log7.5%

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

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

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

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

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

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

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

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

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

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

Alternative 8: 6.0% accurate, 1.2× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 5.4% accurate, 1.3× speedup?

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

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

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

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

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

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

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

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

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

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

Reproduce

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