expfmod (used to be hard to sample)

Percentage Accurate: 7.1% → 63.3%
Time: 17.9s
Alternatives: 7
Speedup: 505.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 7 alternatives:

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

Initial Program: 7.1% 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: 63.3% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -2 \cdot 10^{-310}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 10:\\ \;\;\;\;{\left(e^{-1}\right)}^{\left(x - \log \log \left(e^{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;{\left(e^{-1}\right)}^{x}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x -2e-310)
   1.0
   (if (<= x 10.0)
     (pow (exp -1.0) (- x (log (log (exp (fmod (exp x) (sqrt (cos x))))))))
     (pow (exp -1.0) x))))
double code(double x) {
	double tmp;
	if (x <= -2e-310) {
		tmp = 1.0;
	} else if (x <= 10.0) {
		tmp = pow(exp(-1.0), (x - log(log(exp(fmod(exp(x), sqrt(cos(x))))))));
	} else {
		tmp = pow(exp(-1.0), x);
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= (-2d-310)) then
        tmp = 1.0d0
    else if (x <= 10.0d0) then
        tmp = exp((-1.0d0)) ** (x - log(log(exp(mod(exp(x), sqrt(cos(x)))))))
    else
        tmp = exp((-1.0d0)) ** x
    end if
    code = tmp
end function
def code(x):
	tmp = 0
	if x <= -2e-310:
		tmp = 1.0
	elif x <= 10.0:
		tmp = math.pow(math.exp(-1.0), (x - math.log(math.log(math.exp(math.fmod(math.exp(x), math.sqrt(math.cos(x))))))))
	else:
		tmp = math.pow(math.exp(-1.0), x)
	return tmp
function code(x)
	tmp = 0.0
	if (x <= -2e-310)
		tmp = 1.0;
	elseif (x <= 10.0)
		tmp = exp(-1.0) ^ Float64(x - log(log(exp(rem(exp(x), sqrt(cos(x)))))));
	else
		tmp = exp(-1.0) ^ x;
	end
	return tmp
end
code[x_] := If[LessEqual[x, -2e-310], 1.0, If[LessEqual[x, 10.0], N[Power[N[Exp[-1.0], $MachinePrecision], N[(x - N[Log[N[Log[N[Exp[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]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Power[N[Exp[-1.0], $MachinePrecision], x], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-310}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \leq 10:\\
\;\;\;\;{\left(e^{-1}\right)}^{\left(x - \log \log \left(e^{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}\right)\right)}\\

\mathbf{else}:\\
\;\;\;\;{\left(e^{-1}\right)}^{x}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -1.999999999999994e-310

    1. Initial program 9.0%

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

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

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

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

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

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \color{blue}{\left({\cos x}^{0.5}\right)}\right)}{e^{x}} \]
      2. metadata-eval9.0%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\cos x}^{\color{blue}{\left(0.25 \cdot 2\right)}}\right)\right)}{e^{x}} \]
      3. metadata-eval9.0%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\cos x}^{\left(\color{blue}{\frac{0.5}{2}} \cdot 2\right)}\right)\right)}{e^{x}} \]
      4. pow-pow9.0%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \color{blue}{\left({\left({\cos x}^{\left(\frac{0.5}{2}\right)}\right)}^{2}\right)}\right)}{e^{x}} \]
      5. metadata-eval9.0%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\left({\cos x}^{\color{blue}{0.25}}\right)}^{2}\right)\right)}{e^{x}} \]
    5. Applied egg-rr9.0%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \color{blue}{\left({\left({\cos x}^{0.25}\right)}^{2}\right)}\right)}{e^{x}} \]
    6. Applied egg-rr97.7%

      \[\leadsto \color{blue}{{\left(\sqrt{\cos x}\right)}^{-1}} \]
    7. Taylor expanded in x around 0 100.0%

      \[\leadsto \color{blue}{1} \]

    if -1.999999999999994e-310 < x < 10

    1. Initial program 11.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 10 < x

    1. Initial program 0.0%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{e^{\log \left(\frac{e^{x}}{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}\right) \cdot -1}} \]
      4. *-commutative0.0%

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

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

        \[\leadsto {\left(e^{-1}\right)}^{\color{blue}{\left(\log \left(e^{x}\right) - \log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\right)}} \]
      7. rem-log-exp0.0%

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

      \[\leadsto \color{blue}{{\left(e^{-1}\right)}^{\left(x - \log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\right)}} \]
    6. Taylor expanded in x around inf 100.0%

      \[\leadsto {\left(e^{-1}\right)}^{\color{blue}{x}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification62.9%

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

Alternative 2: 63.3% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -2 \cdot 10^{-310}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 10:\\ \;\;\;\;\frac{\log \left(e^{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}\right)}{e^{x}}\\ \mathbf{else}:\\ \;\;\;\;{\left(e^{-1}\right)}^{x}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x -2e-310)
   1.0
   (if (<= x 10.0)
     (/ (log (exp (fmod (exp x) (sqrt (cos x))))) (exp x))
     (pow (exp -1.0) x))))
double code(double x) {
	double tmp;
	if (x <= -2e-310) {
		tmp = 1.0;
	} else if (x <= 10.0) {
		tmp = log(exp(fmod(exp(x), sqrt(cos(x))))) / exp(x);
	} else {
		tmp = pow(exp(-1.0), x);
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= (-2d-310)) then
        tmp = 1.0d0
    else if (x <= 10.0d0) then
        tmp = log(exp(mod(exp(x), sqrt(cos(x))))) / exp(x)
    else
        tmp = exp((-1.0d0)) ** x
    end if
    code = tmp
end function
def code(x):
	tmp = 0
	if x <= -2e-310:
		tmp = 1.0
	elif x <= 10.0:
		tmp = math.log(math.exp(math.fmod(math.exp(x), math.sqrt(math.cos(x))))) / math.exp(x)
	else:
		tmp = math.pow(math.exp(-1.0), x)
	return tmp
function code(x)
	tmp = 0.0
	if (x <= -2e-310)
		tmp = 1.0;
	elseif (x <= 10.0)
		tmp = Float64(log(exp(rem(exp(x), sqrt(cos(x))))) / exp(x));
	else
		tmp = exp(-1.0) ^ x;
	end
	return tmp
end
code[x_] := If[LessEqual[x, -2e-310], 1.0, If[LessEqual[x, 10.0], N[(N[Log[N[Exp[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] / N[Exp[x], $MachinePrecision]), $MachinePrecision], N[Power[N[Exp[-1.0], $MachinePrecision], x], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-310}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \leq 10:\\
\;\;\;\;\frac{\log \left(e^{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}\right)}{e^{x}}\\

\mathbf{else}:\\
\;\;\;\;{\left(e^{-1}\right)}^{x}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -1.999999999999994e-310

    1. Initial program 9.0%

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

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

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

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

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

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \color{blue}{\left({\cos x}^{0.5}\right)}\right)}{e^{x}} \]
      2. metadata-eval9.0%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\cos x}^{\color{blue}{\left(0.25 \cdot 2\right)}}\right)\right)}{e^{x}} \]
      3. metadata-eval9.0%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\cos x}^{\left(\color{blue}{\frac{0.5}{2}} \cdot 2\right)}\right)\right)}{e^{x}} \]
      4. pow-pow9.0%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \color{blue}{\left({\left({\cos x}^{\left(\frac{0.5}{2}\right)}\right)}^{2}\right)}\right)}{e^{x}} \]
      5. metadata-eval9.0%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\left({\cos x}^{\color{blue}{0.25}}\right)}^{2}\right)\right)}{e^{x}} \]
    5. Applied egg-rr9.0%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \color{blue}{\left({\left({\cos x}^{0.25}\right)}^{2}\right)}\right)}{e^{x}} \]
    6. Applied egg-rr97.7%

      \[\leadsto \color{blue}{{\left(\sqrt{\cos x}\right)}^{-1}} \]
    7. Taylor expanded in x around 0 100.0%

      \[\leadsto \color{blue}{1} \]

    if -1.999999999999994e-310 < x < 10

    1. Initial program 11.3%

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

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

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

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

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

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

    if 10 < x

    1. Initial program 0.0%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{e^{\log \left(\frac{e^{x}}{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}\right) \cdot -1}} \]
      4. *-commutative0.0%

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

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

        \[\leadsto {\left(e^{-1}\right)}^{\color{blue}{\left(\log \left(e^{x}\right) - \log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\right)}} \]
      7. rem-log-exp0.0%

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

      \[\leadsto \color{blue}{{\left(e^{-1}\right)}^{\left(x - \log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\right)}} \]
    6. Taylor expanded in x around inf 100.0%

      \[\leadsto {\left(e^{-1}\right)}^{\color{blue}{x}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification62.9%

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

Alternative 3: 63.3% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -2 \cdot 10^{-310}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 10:\\ \;\;\;\;e^{\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x}\\ \mathbf{else}:\\ \;\;\;\;{\left(e^{-1}\right)}^{x}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x -2e-310)
   1.0
   (if (<= x 10.0)
     (exp (- (log (fmod (exp x) (sqrt (cos x)))) x))
     (pow (exp -1.0) x))))
double code(double x) {
	double tmp;
	if (x <= -2e-310) {
		tmp = 1.0;
	} else if (x <= 10.0) {
		tmp = exp((log(fmod(exp(x), sqrt(cos(x)))) - x));
	} else {
		tmp = pow(exp(-1.0), x);
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= (-2d-310)) then
        tmp = 1.0d0
    else if (x <= 10.0d0) then
        tmp = exp((log(mod(exp(x), sqrt(cos(x)))) - x))
    else
        tmp = exp((-1.0d0)) ** x
    end if
    code = tmp
end function
def code(x):
	tmp = 0
	if x <= -2e-310:
		tmp = 1.0
	elif x <= 10.0:
		tmp = math.exp((math.log(math.fmod(math.exp(x), math.sqrt(math.cos(x)))) - x))
	else:
		tmp = math.pow(math.exp(-1.0), x)
	return tmp
function code(x)
	tmp = 0.0
	if (x <= -2e-310)
		tmp = 1.0;
	elseif (x <= 10.0)
		tmp = exp(Float64(log(rem(exp(x), sqrt(cos(x)))) - x));
	else
		tmp = exp(-1.0) ^ x;
	end
	return tmp
end
code[x_] := If[LessEqual[x, -2e-310], 1.0, If[LessEqual[x, 10.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]], $MachinePrecision], N[Power[N[Exp[-1.0], $MachinePrecision], x], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-310}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \leq 10:\\
\;\;\;\;e^{\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x}\\

\mathbf{else}:\\
\;\;\;\;{\left(e^{-1}\right)}^{x}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -1.999999999999994e-310

    1. Initial program 9.0%

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

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

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

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

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

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \color{blue}{\left({\cos x}^{0.5}\right)}\right)}{e^{x}} \]
      2. metadata-eval9.0%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\cos x}^{\color{blue}{\left(0.25 \cdot 2\right)}}\right)\right)}{e^{x}} \]
      3. metadata-eval9.0%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\cos x}^{\left(\color{blue}{\frac{0.5}{2}} \cdot 2\right)}\right)\right)}{e^{x}} \]
      4. pow-pow9.0%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \color{blue}{\left({\left({\cos x}^{\left(\frac{0.5}{2}\right)}\right)}^{2}\right)}\right)}{e^{x}} \]
      5. metadata-eval9.0%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\left({\cos x}^{\color{blue}{0.25}}\right)}^{2}\right)\right)}{e^{x}} \]
    5. Applied egg-rr9.0%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \color{blue}{\left({\left({\cos x}^{0.25}\right)}^{2}\right)}\right)}{e^{x}} \]
    6. Applied egg-rr97.7%

      \[\leadsto \color{blue}{{\left(\sqrt{\cos x}\right)}^{-1}} \]
    7. Taylor expanded in x around 0 100.0%

      \[\leadsto \color{blue}{1} \]

    if -1.999999999999994e-310 < x < 10

    1. Initial program 11.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 10 < x

    1. Initial program 0.0%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{e^{\log \left(\frac{e^{x}}{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}\right) \cdot -1}} \]
      4. *-commutative0.0%

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

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

        \[\leadsto {\left(e^{-1}\right)}^{\color{blue}{\left(\log \left(e^{x}\right) - \log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\right)}} \]
      7. rem-log-exp0.0%

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

      \[\leadsto \color{blue}{{\left(e^{-1}\right)}^{\left(x - \log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\right)}} \]
    6. Taylor expanded in x around inf 100.0%

      \[\leadsto {\left(e^{-1}\right)}^{\color{blue}{x}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification62.9%

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

Alternative 4: 63.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -2 \cdot 10^{-310}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 10:\\ \;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}\\ \mathbf{else}:\\ \;\;\;\;{\left(e^{-1}\right)}^{x}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x -2e-310)
   1.0
   (if (<= x 10.0)
     (/ (fmod (exp x) (sqrt (cos x))) (exp x))
     (pow (exp -1.0) x))))
double code(double x) {
	double tmp;
	if (x <= -2e-310) {
		tmp = 1.0;
	} else if (x <= 10.0) {
		tmp = fmod(exp(x), sqrt(cos(x))) / exp(x);
	} else {
		tmp = pow(exp(-1.0), x);
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= (-2d-310)) then
        tmp = 1.0d0
    else if (x <= 10.0d0) then
        tmp = mod(exp(x), sqrt(cos(x))) / exp(x)
    else
        tmp = exp((-1.0d0)) ** x
    end if
    code = tmp
end function
def code(x):
	tmp = 0
	if x <= -2e-310:
		tmp = 1.0
	elif x <= 10.0:
		tmp = math.fmod(math.exp(x), math.sqrt(math.cos(x))) / math.exp(x)
	else:
		tmp = math.pow(math.exp(-1.0), x)
	return tmp
function code(x)
	tmp = 0.0
	if (x <= -2e-310)
		tmp = 1.0;
	elseif (x <= 10.0)
		tmp = Float64(rem(exp(x), sqrt(cos(x))) / exp(x));
	else
		tmp = exp(-1.0) ^ x;
	end
	return tmp
end
code[x_] := If[LessEqual[x, -2e-310], 1.0, If[LessEqual[x, 10.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], N[Power[N[Exp[-1.0], $MachinePrecision], x], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-310}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \leq 10:\\
\;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}\\

\mathbf{else}:\\
\;\;\;\;{\left(e^{-1}\right)}^{x}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -1.999999999999994e-310

    1. Initial program 9.0%

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

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

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

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

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

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \color{blue}{\left({\cos x}^{0.5}\right)}\right)}{e^{x}} \]
      2. metadata-eval9.0%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\cos x}^{\color{blue}{\left(0.25 \cdot 2\right)}}\right)\right)}{e^{x}} \]
      3. metadata-eval9.0%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\cos x}^{\left(\color{blue}{\frac{0.5}{2}} \cdot 2\right)}\right)\right)}{e^{x}} \]
      4. pow-pow9.0%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \color{blue}{\left({\left({\cos x}^{\left(\frac{0.5}{2}\right)}\right)}^{2}\right)}\right)}{e^{x}} \]
      5. metadata-eval9.0%

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\left({\cos x}^{\color{blue}{0.25}}\right)}^{2}\right)\right)}{e^{x}} \]
    5. Applied egg-rr9.0%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \color{blue}{\left({\left({\cos x}^{0.25}\right)}^{2}\right)}\right)}{e^{x}} \]
    6. Applied egg-rr97.7%

      \[\leadsto \color{blue}{{\left(\sqrt{\cos x}\right)}^{-1}} \]
    7. Taylor expanded in x around 0 100.0%

      \[\leadsto \color{blue}{1} \]

    if -1.999999999999994e-310 < x < 10

    1. Initial program 11.3%

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

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

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

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

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

    if 10 < x

    1. Initial program 0.0%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{e^{\log \left(\frac{e^{x}}{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}\right) \cdot -1}} \]
      4. *-commutative0.0%

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

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

        \[\leadsto {\left(e^{-1}\right)}^{\color{blue}{\left(\log \left(e^{x}\right) - \log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\right)}} \]
      7. rem-log-exp0.0%

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

      \[\leadsto \color{blue}{{\left(e^{-1}\right)}^{\left(x - \log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\right)}} \]
    6. Taylor expanded in x around inf 100.0%

      \[\leadsto {\left(e^{-1}\right)}^{\color{blue}{x}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification62.9%

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

Alternative 5: 62.0% accurate, 2.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 5 \cdot 10^{-300}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;{\left(e^{-1}\right)}^{x}\\ \end{array} \end{array} \]
(FPCore (x) :precision binary64 (if (<= x 5e-300) 1.0 (pow (exp -1.0) x)))
double code(double x) {
	double tmp;
	if (x <= 5e-300) {
		tmp = 1.0;
	} else {
		tmp = pow(exp(-1.0), x);
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= 5d-300) then
        tmp = 1.0d0
    else
        tmp = exp((-1.0d0)) ** x
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= 5e-300) {
		tmp = 1.0;
	} else {
		tmp = Math.pow(Math.exp(-1.0), x);
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= 5e-300:
		tmp = 1.0
	else:
		tmp = math.pow(math.exp(-1.0), x)
	return tmp
function code(x)
	tmp = 0.0
	if (x <= 5e-300)
		tmp = 1.0;
	else
		tmp = exp(-1.0) ^ x;
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= 5e-300)
		tmp = 1.0;
	else
		tmp = exp(-1.0) ^ x;
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, 5e-300], 1.0, N[Power[N[Exp[-1.0], $MachinePrecision], x], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 5 \cdot 10^{-300}:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;{\left(e^{-1}\right)}^{x}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 4.99999999999999996e-300

    1. Initial program 9.1%

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

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

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

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

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

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \color{blue}{\left({\cos x}^{0.5}\right)}\right)}{e^{x}} \]
      2. metadata-eval9.1%

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

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

        \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \color{blue}{\left({\left({\cos x}^{\left(\frac{0.5}{2}\right)}\right)}^{2}\right)}\right)}{e^{x}} \]
      5. metadata-eval9.1%

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

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

      \[\leadsto \color{blue}{{\left(\sqrt{\cos x}\right)}^{-1}} \]
    7. Taylor expanded in x around 0 96.2%

      \[\leadsto \color{blue}{1} \]

    if 4.99999999999999996e-300 < x

    1. Initial program 7.6%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{{\left(e^{-1}\right)}^{\left(x - \log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\right)}} \]
    6. Taylor expanded in x around inf 36.7%

      \[\leadsto {\left(e^{-1}\right)}^{\color{blue}{x}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification60.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 5 \cdot 10^{-300}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;{\left(e^{-1}\right)}^{x}\\ \end{array} \]

Alternative 6: 52.2% accurate, 4.7× speedup?

\[\begin{array}{l} \\ {\left(1 + \left(x \cdot x\right) \cdot -0.25\right)}^{-1} \end{array} \]
(FPCore (x) :precision binary64 (pow (+ 1.0 (* (* x x) -0.25)) -1.0))
double code(double x) {
	return pow((1.0 + ((x * x) * -0.25)), -1.0);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (1.0d0 + ((x * x) * (-0.25d0))) ** (-1.0d0)
end function
public static double code(double x) {
	return Math.pow((1.0 + ((x * x) * -0.25)), -1.0);
}
def code(x):
	return math.pow((1.0 + ((x * x) * -0.25)), -1.0)
function code(x)
	return Float64(1.0 + Float64(Float64(x * x) * -0.25)) ^ -1.0
end
function tmp = code(x)
	tmp = (1.0 + ((x * x) * -0.25)) ^ -1.0;
end
code[x_] := N[Power[N[(1.0 + N[(N[(x * x), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision]
\begin{array}{l}

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

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

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

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

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

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \color{blue}{\left({\cos x}^{0.5}\right)}\right)}{e^{x}} \]
    2. metadata-eval8.2%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\cos x}^{\color{blue}{\left(0.25 \cdot 2\right)}}\right)\right)}{e^{x}} \]
    3. metadata-eval8.2%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\cos x}^{\left(\color{blue}{\frac{0.5}{2}} \cdot 2\right)}\right)\right)}{e^{x}} \]
    4. pow-pow8.2%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \color{blue}{\left({\left({\cos x}^{\left(\frac{0.5}{2}\right)}\right)}^{2}\right)}\right)}{e^{x}} \]
    5. metadata-eval8.2%

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

    \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \color{blue}{\left({\left({\cos x}^{0.25}\right)}^{2}\right)}\right)}{e^{x}} \]
  6. Applied egg-rr40.8%

    \[\leadsto \color{blue}{{\left(\sqrt{\cos x}\right)}^{-1}} \]
  7. Taylor expanded in x around 0 50.4%

    \[\leadsto {\color{blue}{\left(1 + -0.25 \cdot {x}^{2}\right)}}^{-1} \]
  8. Step-by-step derivation
    1. *-commutative50.4%

      \[\leadsto {\left(1 + \color{blue}{{x}^{2} \cdot -0.25}\right)}^{-1} \]
    2. unpow250.4%

      \[\leadsto {\left(1 + \color{blue}{\left(x \cdot x\right)} \cdot -0.25\right)}^{-1} \]
  9. Simplified50.4%

    \[\leadsto {\color{blue}{\left(1 + \left(x \cdot x\right) \cdot -0.25\right)}}^{-1} \]
  10. Final simplification50.4%

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

Alternative 7: 43.6% accurate, 505.0× speedup?

\[\begin{array}{l} \\ 1 \end{array} \]
(FPCore (x) :precision binary64 1.0)
double code(double x) {
	return 1.0;
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 1.0d0
end function
public static double code(double x) {
	return 1.0;
}
def code(x):
	return 1.0
function code(x)
	return 1.0
end
function tmp = code(x)
	tmp = 1.0;
end
code[x_] := 1.0
\begin{array}{l}

\\
1
\end{array}
Derivation
  1. Initial program 8.2%

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

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

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

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

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \color{blue}{\left({\cos x}^{0.5}\right)}\right)}{e^{x}} \]
    2. metadata-eval8.2%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\cos x}^{\color{blue}{\left(0.25 \cdot 2\right)}}\right)\right)}{e^{x}} \]
    3. metadata-eval8.2%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \left({\cos x}^{\left(\color{blue}{\frac{0.5}{2}} \cdot 2\right)}\right)\right)}{e^{x}} \]
    4. pow-pow8.2%

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \color{blue}{\left({\left({\cos x}^{\left(\frac{0.5}{2}\right)}\right)}^{2}\right)}\right)}{e^{x}} \]
    5. metadata-eval8.2%

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

    \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \color{blue}{\left({\left({\cos x}^{0.25}\right)}^{2}\right)}\right)}{e^{x}} \]
  6. Applied egg-rr40.8%

    \[\leadsto \color{blue}{{\left(\sqrt{\cos x}\right)}^{-1}} \]
  7. Taylor expanded in x around 0 41.7%

    \[\leadsto \color{blue}{1} \]
  8. Final simplification41.7%

    \[\leadsto 1 \]

Reproduce

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