expfmod (used to be hard to sample)

Percentage Accurate: 6.7% → 6.6%
Time: 17.7s
Alternatives: 11
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 11 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: 6.6% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\\ \frac{1 - \left(\left(1 + {\left(\mathsf{expm1}\left(\log t_0 - x\right)\right)}^{2}\right) + -1\right)}{1 - \mathsf{expm1}\left(\log \left(\left(1 + t_0\right) + -1\right) - x\right)} \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (fmod (exp x) (sqrt (cos x)))))
   (/
    (- 1.0 (+ (+ 1.0 (pow (expm1 (- (log t_0) x)) 2.0)) -1.0))
    (- 1.0 (expm1 (- (log (+ (+ 1.0 t_0) -1.0)) x))))))
double code(double x) {
	double t_0 = fmod(exp(x), sqrt(cos(x)));
	return (1.0 - ((1.0 + pow(expm1((log(t_0) - x)), 2.0)) + -1.0)) / (1.0 - expm1((log(((1.0 + t_0) + -1.0)) - x)));
}
def code(x):
	t_0 = math.fmod(math.exp(x), math.sqrt(math.cos(x)))
	return (1.0 - ((1.0 + math.pow(math.expm1((math.log(t_0) - x)), 2.0)) + -1.0)) / (1.0 - math.expm1((math.log(((1.0 + t_0) + -1.0)) - x)))
function code(x)
	t_0 = rem(exp(x), sqrt(cos(x)))
	return Float64(Float64(1.0 - Float64(Float64(1.0 + (expm1(Float64(log(t_0) - x)) ^ 2.0)) + -1.0)) / Float64(1.0 - expm1(Float64(log(Float64(Float64(1.0 + t_0) + -1.0)) - x))))
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]}, N[(N[(1.0 - N[(N[(1.0 + N[Power[N[(Exp[N[(N[Log[t$95$0], $MachinePrecision] - x), $MachinePrecision]] - 1), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision] / N[(1.0 - N[(Exp[N[(N[Log[N[(N[(1.0 + t$95$0), $MachinePrecision] + -1.0), $MachinePrecision]], $MachinePrecision] - x), $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

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

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

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

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

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

      \[\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-udef6.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-udef6.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-log6.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-rr6.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+6.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 6.7% accurate, 0.4× speedup?

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

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

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

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

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

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

      \[\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-udef6.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-udef6.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-log6.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-rr6.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+6.3%

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

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

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

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

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

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

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

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

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

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

Alternative 3: 6.7% accurate, 0.4× speedup?

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

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

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

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

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

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

      \[\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-udef6.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-udef6.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-log6.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-rr6.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+6.3%

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

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

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

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

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

    \[\leadsto \frac{\color{blue}{1 - {\left(\mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x\right)\right)}^{2}}}{1 - \mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x\right)} \]
  11. Final simplification6.3%

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

Alternative 4: 6.7% accurate, 1.0× speedup?

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

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

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

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

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

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

      \[\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-udef6.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-udef6.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-log6.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-rr6.3%

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

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

Alternative 5: 6.7% 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 6.2%

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

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

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

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

      \[\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-udef6.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-udef6.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-log6.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-rr6.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. add-exp-log6.3%

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

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

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

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

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

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

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

Alternative 6: 6.7% accurate, 1.0× speedup?

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

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

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

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

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

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

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

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

Alternative 7: 6.5% accurate, 1.6× speedup?

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

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

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

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

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

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

      \[\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-udef6.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-udef6.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-log6.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-rr6.3%

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

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

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

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

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

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

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 6.2%

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

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

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

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

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

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

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

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

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

    \[\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.2% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \left(\left(e^{x}\right) \bmod 1\right) \cdot 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(Float64(-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}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Reproduce

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