expfmod (used to be hard to sample)

Percentage Accurate: 6.7% → 43.3%
Time: 20.9s
Alternatives: 13
Speedup: 1.2×

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.7% accurate, 1.0× speedup?

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

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

Alternative 1: 43.3% accurate, 0.5× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{e^{x}}{t_0}}\\


\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.2%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\color{blue}{{\left(\sqrt{1 + \sqrt{\cos x}}\right)}^{2}} - 1\right)\right)}{e^{x}} \]
      3. add-sqr-sqrt49.4%

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

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\color{blue}{\left(\mathsf{hypot}\left(1, \sqrt{\sqrt{\cos x}}\right)\right)}}^{2} - 1\right)\right)}{e^{x}} \]
      5. pow1/249.4%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\left(\mathsf{hypot}\left(1, \sqrt{\color{blue}{{\cos x}^{0.5}}}\right)\right)}^{2} - 1\right)\right)}{e^{x}} \]
      6. sqrt-pow149.4%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\left(\mathsf{hypot}\left(1, \color{blue}{{\cos x}^{\left(\frac{0.5}{2}\right)}}\right)\right)}^{2} - 1\right)\right)}{e^{x}} \]
      7. metadata-eval49.4%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\left(\mathsf{hypot}\left(1, {\cos x}^{\color{blue}{0.25}}\right)\right)}^{2} - 1\right)\right)}{e^{x}} \]
    7. Applied egg-rr49.4%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\color{blue}{{\left(\mathsf{hypot}\left(1, {\cos x}^{0.25}\right)\right)}^{2}} - 1\right)\right)}{e^{x}} \]
    8. Taylor expanded in x around 0 49.4%

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

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

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

    1. Initial program 23.6%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{{\left({\left(\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}\right)}^{3}\right)}^{0.3333333333333333}} \]
    6. Step-by-step derivation
      1. unpow1/323.8%

        \[\leadsto \color{blue}{\sqrt[3]{{\left(\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}\right)}^{3}}} \]
      2. rem-cbrt-cube23.8%

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

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

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

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

Alternative 2: 43.3% accurate, 0.5× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\frac{t_0}{e^{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.2%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\color{blue}{{\left(\sqrt{1 + \sqrt{\cos x}}\right)}^{2}} - 1\right)\right)}{e^{x}} \]
      3. add-sqr-sqrt49.4%

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

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\color{blue}{\left(\mathsf{hypot}\left(1, \sqrt{\sqrt{\cos x}}\right)\right)}}^{2} - 1\right)\right)}{e^{x}} \]
      5. pow1/249.4%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\left(\mathsf{hypot}\left(1, \sqrt{\color{blue}{{\cos x}^{0.5}}}\right)\right)}^{2} - 1\right)\right)}{e^{x}} \]
      6. sqrt-pow149.4%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\left(\mathsf{hypot}\left(1, \color{blue}{{\cos x}^{\left(\frac{0.5}{2}\right)}}\right)\right)}^{2} - 1\right)\right)}{e^{x}} \]
      7. metadata-eval49.4%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\left(\mathsf{hypot}\left(1, {\cos x}^{\color{blue}{0.25}}\right)\right)}^{2} - 1\right)\right)}{e^{x}} \]
    7. Applied egg-rr49.4%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\color{blue}{{\left(\mathsf{hypot}\left(1, {\cos x}^{0.25}\right)\right)}^{2}} - 1\right)\right)}{e^{x}} \]
    8. Taylor expanded in x around 0 49.4%

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

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

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

    1. Initial program 23.6%

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

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

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

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

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

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

Alternative 3: 43.3% accurate, 0.7× speedup?

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

\\
\frac{\left(\left(e^{x}\right) \bmod \left({\left(\mathsf{hypot}\left(1, {\cos x}^{0.25}\right)\right)}^{2} + -1\right)\right)}{e^{x}}
\end{array}
Derivation
  1. Initial program 8.3%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\color{blue}{{\left(\sqrt{1 + \sqrt{\cos x}}\right)}^{2}} - 1\right)\right)}{e^{x}} \]
    3. add-sqr-sqrt43.8%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\left(\sqrt{1 + \color{blue}{\sqrt{\sqrt{\cos x}} \cdot \sqrt{\sqrt{\cos x}}}}\right)}^{2} - 1\right)\right)}{e^{x}} \]
    4. hypot-1-def43.8%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\color{blue}{\left(\mathsf{hypot}\left(1, \sqrt{\sqrt{\cos x}}\right)\right)}}^{2} - 1\right)\right)}{e^{x}} \]
    5. pow1/243.8%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\left(\mathsf{hypot}\left(1, \sqrt{\color{blue}{{\cos x}^{0.5}}}\right)\right)}^{2} - 1\right)\right)}{e^{x}} \]
    6. sqrt-pow143.8%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\left(\mathsf{hypot}\left(1, \color{blue}{{\cos x}^{\left(\frac{0.5}{2}\right)}}\right)\right)}^{2} - 1\right)\right)}{e^{x}} \]
    7. metadata-eval43.8%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\left(\mathsf{hypot}\left(1, {\cos x}^{\color{blue}{0.25}}\right)\right)}^{2} - 1\right)\right)}{e^{x}} \]
  7. Applied egg-rr43.8%

    \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\color{blue}{{\left(\mathsf{hypot}\left(1, {\cos x}^{0.25}\right)\right)}^{2}} - 1\right)\right)}{e^{x}} \]
  8. Final simplification43.8%

    \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\left(\mathsf{hypot}\left(1, {\cos x}^{0.25}\right)\right)}^{2} + -1\right)\right)}{e^{x}} \]

Alternative 4: 42.8% accurate, 1.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\color{blue}{{\left(\sqrt{1 + \sqrt{\cos x}}\right)}^{2}} - 1\right)\right)}{e^{x}} \]
    3. add-sqr-sqrt43.8%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\left(\sqrt{1 + \color{blue}{\sqrt{\sqrt{\cos x}} \cdot \sqrt{\sqrt{\cos x}}}}\right)}^{2} - 1\right)\right)}{e^{x}} \]
    4. hypot-1-def43.8%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\color{blue}{\left(\mathsf{hypot}\left(1, \sqrt{\sqrt{\cos x}}\right)\right)}}^{2} - 1\right)\right)}{e^{x}} \]
    5. pow1/243.8%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\left(\mathsf{hypot}\left(1, \sqrt{\color{blue}{{\cos x}^{0.5}}}\right)\right)}^{2} - 1\right)\right)}{e^{x}} \]
    6. sqrt-pow143.8%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\left(\mathsf{hypot}\left(1, \color{blue}{{\cos x}^{\left(\frac{0.5}{2}\right)}}\right)\right)}^{2} - 1\right)\right)}{e^{x}} \]
    7. metadata-eval43.8%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\left(\mathsf{hypot}\left(1, {\cos x}^{\color{blue}{0.25}}\right)\right)}^{2} - 1\right)\right)}{e^{x}} \]
  7. Applied egg-rr43.8%

    \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\color{blue}{{\left(\mathsf{hypot}\left(1, {\cos x}^{0.25}\right)\right)}^{2}} - 1\right)\right)}{e^{x}} \]
  8. Taylor expanded in x around 0 43.6%

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

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

Alternative 5: 41.8% accurate, 1.2× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\color{blue}{{\left(\sqrt{1 + \sqrt{\cos x}}\right)}^{2}} - 1\right)\right)}{e^{x}} \]
    3. add-sqr-sqrt43.8%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\left(\sqrt{1 + \color{blue}{\sqrt{\sqrt{\cos x}} \cdot \sqrt{\sqrt{\cos x}}}}\right)}^{2} - 1\right)\right)}{e^{x}} \]
    4. hypot-1-def43.8%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\color{blue}{\left(\mathsf{hypot}\left(1, \sqrt{\sqrt{\cos x}}\right)\right)}}^{2} - 1\right)\right)}{e^{x}} \]
    5. pow1/243.8%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\left(\mathsf{hypot}\left(1, \sqrt{\color{blue}{{\cos x}^{0.5}}}\right)\right)}^{2} - 1\right)\right)}{e^{x}} \]
    6. sqrt-pow143.8%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\left(\mathsf{hypot}\left(1, \color{blue}{{\cos x}^{\left(\frac{0.5}{2}\right)}}\right)\right)}^{2} - 1\right)\right)}{e^{x}} \]
    7. metadata-eval43.8%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\left(\mathsf{hypot}\left(1, {\cos x}^{\color{blue}{0.25}}\right)\right)}^{2} - 1\right)\right)}{e^{x}} \]
  7. Applied egg-rr43.8%

    \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left(\color{blue}{{\left(\mathsf{hypot}\left(1, {\cos x}^{0.25}\right)\right)}^{2}} - 1\right)\right)}{e^{x}} \]
  8. Taylor expanded in x around 0 43.6%

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

    \[\leadsto \color{blue}{\left(\left(e^{x}\right) \bmod \left({\left(\sqrt{2}\right)}^{2} - 1\right)\right)} \]
  10. Final simplification42.0%

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

Alternative 6: 6.5% accurate, 1.6× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 6.5% accurate, 1.6× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 6.5% accurate, 1.6× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 6.3% accurate, 1.6× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 6.3% accurate, 1.6× speedup?

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{{\left({\left(\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}\right)}^{3}\right)}^{0.3333333333333333}} \]
  6. Step-by-step derivation
    1. unpow1/38.3%

      \[\leadsto \color{blue}{\sqrt[3]{{\left(\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}\right)}^{3}}} \]
    2. rem-cbrt-cube8.3%

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

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

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

      \[\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. +-commutative8.3%

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

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

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

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

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

Alternative 11: 6.3% accurate, 1.7× speedup?

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

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

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

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

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

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

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

    \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \color{blue}{1}\right)}{e^{x}} \]
  5. Step-by-step derivation
    1. div-inv8.0%

      \[\leadsto \color{blue}{\left(\left(e^{x}\right) \bmod 1\right) \cdot \frac{1}{e^{x}}} \]
    2. rec-exp7.9%

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

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

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

      \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod 1\right)}{e^{x}}} \]
    3. clear-num8.0%

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

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

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

Alternative 12: 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 8.3%

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

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

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

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

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

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

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

Alternative 13: 5.3% accurate, 2.5× speedup?

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

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

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

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

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

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

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

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

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

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

Reproduce

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