expfmod (used to be hard to sample)

Percentage Accurate: 6.8% → 43.0%
Time: 20.1s
Alternatives: 13
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 13 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 6.8% accurate, 1.0× speedup?

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

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

Alternative 1: 43.0% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \leq 0:\\ \;\;\;\;\left(1 - x\right) \cdot \left(\left(e^{x}\right) \bmod \left(\log \left(\sqrt[3]{e^{2}}\right) + \log \left(\sqrt[3]{e}\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;e^{\log \left(\left(e^{x}\right) \bmod \left({\left(\sqrt[3]{\cos x}\right)}^{1.5}\right)\right) - x}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= (* (fmod (exp x) (sqrt (cos x))) (exp (- x))) 0.0)
   (* (- 1.0 x) (fmod (exp x) (+ (log (cbrt (exp 2.0))) (log (cbrt E)))))
   (exp (- (log (fmod (exp x) (pow (cbrt (cos x)) 1.5))) x))))
double code(double x) {
	double tmp;
	if ((fmod(exp(x), sqrt(cos(x))) * exp(-x)) <= 0.0) {
		tmp = (1.0 - x) * fmod(exp(x), (log(cbrt(exp(2.0))) + log(cbrt(((double) M_E)))));
	} else {
		tmp = exp((log(fmod(exp(x), pow(cbrt(cos(x)), 1.5))) - x));
	}
	return tmp;
}
function code(x)
	tmp = 0.0
	if (Float64(rem(exp(x), sqrt(cos(x))) * exp(Float64(-x))) <= 0.0)
		tmp = Float64(Float64(1.0 - x) * rem(exp(x), Float64(log(cbrt(exp(2.0))) + log(cbrt(exp(1))))));
	else
		tmp = exp(Float64(log(rem(exp(x), (cbrt(cos(x)) ^ 1.5))) - x));
	end
	return tmp
end
code[x_] := If[LessEqual[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], 0.0], N[(N[(1.0 - x), $MachinePrecision] * N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(N[Log[N[Power[N[Exp[2.0], $MachinePrecision], 1/3], $MachinePrecision]], $MachinePrecision] + N[Log[N[Power[E, 1/3], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision], N[Exp[N[(N[Log[N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Power[N[Power[N[Cos[x], $MachinePrecision], 1/3], $MachinePrecision], 1.5], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]], $MachinePrecision] - x), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \leq 0:\\
\;\;\;\;\left(1 - x\right) \cdot \left(\left(e^{x}\right) \bmod \left(\log \left(\sqrt[3]{e^{2}}\right) + \log \left(\sqrt[3]{e}\right)\right)\right)\\

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


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

    1. Initial program 4.6%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\log \color{blue}{\left(\sqrt[3]{{\left(e^{1}\right)}^{2}}\right)} + \log \left(\sqrt[3]{e^{\sqrt{\cos x}}}\right)\right)\right)}{e^{x}} \]
    8. Step-by-step derivation
      1. unpow247.5%

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

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

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

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

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\log \left(\sqrt[3]{e^{2}}\right) + \log \color{blue}{\left(\sqrt[3]{e^{1}}\right)}\right)\right)}{e^{x}} \]
    11. Step-by-step derivation
      1. exp-1-e47.5%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\log \left(\sqrt[3]{e^{2}}\right) + \log \left(\sqrt[3]{\color{blue}{e}}\right)\right)\right)}{e^{x}} \]
    12. Simplified47.5%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\log \left(\sqrt[3]{e^{2}}\right) + \log \color{blue}{\left(\sqrt[3]{e}\right)}\right)\right)}{e^{x}} \]
    13. Taylor expanded in x around 0 47.5%

      \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \left(\left(e^{x}\right) \bmod \left(\log \left(\sqrt[3]{e}\right) + \log \left(\sqrt[3]{e^{2}}\right)\right)\right)\right) + \left(\left(e^{x}\right) \bmod \left(\log \left(\sqrt[3]{e}\right) + \log \left(\sqrt[3]{e^{2}}\right)\right)\right)} \]
    14. Step-by-step derivation
      1. associate-*r*47.5%

        \[\leadsto \color{blue}{\left(-1 \cdot x\right) \cdot \left(\left(e^{x}\right) \bmod \left(\log \left(\sqrt[3]{e}\right) + \log \left(\sqrt[3]{e^{2}}\right)\right)\right)} + \left(\left(e^{x}\right) \bmod \left(\log \left(\sqrt[3]{e}\right) + \log \left(\sqrt[3]{e^{2}}\right)\right)\right) \]
      2. neg-mul-147.5%

        \[\leadsto \color{blue}{\left(-x\right)} \cdot \left(\left(e^{x}\right) \bmod \left(\log \left(\sqrt[3]{e}\right) + \log \left(\sqrt[3]{e^{2}}\right)\right)\right) + \left(\left(e^{x}\right) \bmod \left(\log \left(\sqrt[3]{e}\right) + \log \left(\sqrt[3]{e^{2}}\right)\right)\right) \]
      3. distribute-lft1-in47.5%

        \[\leadsto \color{blue}{\left(\left(-x\right) + 1\right) \cdot \left(\left(e^{x}\right) \bmod \left(\log \left(\sqrt[3]{e}\right) + \log \left(\sqrt[3]{e^{2}}\right)\right)\right)} \]
      4. +-commutative47.5%

        \[\leadsto \color{blue}{\left(1 + \left(-x\right)\right)} \cdot \left(\left(e^{x}\right) \bmod \left(\log \left(\sqrt[3]{e}\right) + \log \left(\sqrt[3]{e^{2}}\right)\right)\right) \]
      5. sub-neg47.5%

        \[\leadsto \color{blue}{\left(1 - x\right)} \cdot \left(\left(e^{x}\right) \bmod \left(\log \left(\sqrt[3]{e}\right) + \log \left(\sqrt[3]{e^{2}}\right)\right)\right) \]
    15. Simplified47.5%

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

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

    1. Initial program 17.3%

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

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

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

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

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

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

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

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

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

        \[\leadsto e^{\log \left(\left(e^{x}\right) \bmod \color{blue}{\left({\cos x}^{0.5}\right)}\right) - x} \]
      2. add-cube-cbrt17.7%

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

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

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

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

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

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

Alternative 2: 42.9% accurate, 0.4× speedup?

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

\\
\begin{array}{l}
t_0 := \sqrt[3]{e^{\sqrt{\cos x}}}\\
\frac{\left(\left(e^{x}\right) \bmod \left(\log \left({t\_0}^{2}\right) + \log t\_0\right)\right)}{e^{x}}
\end{array}
\end{array}
Derivation
  1. Initial program 7.9%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 42.5% accurate, 0.5× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\log \color{blue}{\left(\sqrt[3]{e^{2}}\right)} + \log \left(\sqrt[3]{e^{\sqrt{\cos x}}}\right)\right)\right)}{e^{x}} \]
  10. Final simplification38.8%

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

Alternative 4: 42.5% accurate, 0.6× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\log \left(\sqrt[3]{e^{2}}\right) + \log \color{blue}{\left(\sqrt[3]{e^{1}}\right)}\right)\right)}{e^{x}} \]
  11. Step-by-step derivation
    1. exp-1-e38.7%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\log \left(\sqrt[3]{e^{2}}\right) + \log \left(\sqrt[3]{\color{blue}{e}}\right)\right)\right)}{e^{x}} \]
  12. Simplified38.7%

    \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\log \left(\sqrt[3]{e^{2}}\right) + \log \color{blue}{\left(\sqrt[3]{e}\right)}\right)\right)}{e^{x}} \]
  13. Final simplification38.7%

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

Alternative 5: 6.8% accurate, 0.7× speedup?

\[\begin{array}{l} \\ e^{\log \left(\left(e^{x}\right) \bmod \left({\left(\sqrt[3]{\cos x}\right)}^{1.5}\right)\right) - x} \end{array} \]
(FPCore (x)
 :precision binary64
 (exp (- (log (fmod (exp x) (pow (cbrt (cos x)) 1.5))) x)))
double code(double x) {
	return exp((log(fmod(exp(x), pow(cbrt(cos(x)), 1.5))) - x));
}
function code(x)
	return exp(Float64(log(rem(exp(x), (cbrt(cos(x)) ^ 1.5))) - x))
end
code[x_] := N[Exp[N[(N[Log[N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Power[N[Power[N[Cos[x], $MachinePrecision], 1/3], $MachinePrecision], 1.5], $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({\left(\sqrt[3]{\cos x}\right)}^{1.5}\right)\right) - x}
\end{array}
Derivation
  1. Initial program 7.9%

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

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

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

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

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

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

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

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

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

      \[\leadsto e^{\log \left(\left(e^{x}\right) \bmod \color{blue}{\left({\cos x}^{0.5}\right)}\right) - x} \]
    2. add-cube-cbrt8.0%

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

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

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

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

    \[\leadsto e^{\log \left(\left(e^{x}\right) \bmod \color{blue}{\left({\left(\sqrt[3]{\cos x}\right)}^{1.5}\right)}\right) - x} \]
  9. Final simplification8.0%

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

Alternative 6: 6.8% 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.9%

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

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

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

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

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

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

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

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

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

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

Alternative 7: 6.8% accurate, 1.0× speedup?

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

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

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

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

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

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

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

    \[\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. clear-num7.9%

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

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

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

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

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

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

Alternative 8: 6.8% accurate, 1.0× speedup?

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

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

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

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

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

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

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

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

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

Alternative 9: 6.6% accurate, 1.2× speedup?

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

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

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

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

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

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

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

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

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

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

Alternative 10: 6.4% accurate, 1.3× speedup?

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

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

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

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

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

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

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

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

    \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \color{blue}{1}\right)}{e^{x}} \]
  6. Step-by-step derivation
    1. add-exp-log6.9%

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

      \[\leadsto \color{blue}{e^{\log \left(\left(e^{x}\right) \bmod 1\right) - x}} \]
  7. Applied egg-rr7.0%

    \[\leadsto \color{blue}{e^{\log \left(\left(e^{x}\right) \bmod 1\right) - x}} \]
  8. Final simplification7.0%

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

Alternative 11: 6.3% accurate, 1.7× speedup?

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

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

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

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

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

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

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

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

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

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

Alternative 12: 5.9% accurate, 2.5× speedup?

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

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

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

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

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

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

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

    \[\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 \color{blue}{\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)} \]
    2. mul-1-neg6.6%

      \[\leadsto \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)} \]
    3. unsub-neg6.6%

      \[\leadsto \color{blue}{\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)} \]
    4. *-lft-identity6.6%

      \[\leadsto \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) \]
    5. distribute-rgt-out--6.6%

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

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

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

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

Alternative 13: 5.4% accurate, 2.5× speedup?

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

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

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

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

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

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

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

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

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

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

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

Reproduce

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