expfmod (used to be hard to sample)

Percentage Accurate: 7.2% → 43.6%
Time: 16.5s
Alternatives: 5
Speedup: 5.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 5 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.2% accurate, 1.0× speedup?

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

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

Alternative 1: 43.6% accurate, 0.5× speedup?

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

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

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


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

    1. Initial program 4.4%

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

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

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

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

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

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

      \[\leadsto \color{blue}{e^{\left(0.3333333333333333 \cdot \left(x + \log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\right)\right) \cdot 3}} \]
    5. Taylor expanded in x around inf 49.4%

      \[\leadsto e^{\color{blue}{\left(0.3333333333333333 \cdot x\right)} \cdot 3} \]
    6. Step-by-step derivation
      1. *-commutative49.4%

        \[\leadsto e^{\color{blue}{\left(x \cdot 0.3333333333333333\right)} \cdot 3} \]
    7. Simplified49.4%

      \[\leadsto e^{\color{blue}{\left(x \cdot 0.3333333333333333\right)} \cdot 3} \]
    8. Taylor expanded in x around 0 49.4%

      \[\leadsto e^{\color{blue}{x}} \]

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

    1. Initial program 14.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 43.5% accurate, 0.4× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 43.7% accurate, 0.5× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\frac{t\_0}{e^{x}}\\


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

    1. Initial program 4.4%

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

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

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

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

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

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

      \[\leadsto \color{blue}{e^{\left(0.3333333333333333 \cdot \left(x + \log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\right)\right) \cdot 3}} \]
    5. Taylor expanded in x around inf 49.4%

      \[\leadsto e^{\color{blue}{\left(0.3333333333333333 \cdot x\right)} \cdot 3} \]
    6. Step-by-step derivation
      1. *-commutative49.4%

        \[\leadsto e^{\color{blue}{\left(x \cdot 0.3333333333333333\right)} \cdot 3} \]
    7. Simplified49.4%

      \[\leadsto e^{\color{blue}{\left(x \cdot 0.3333333333333333\right)} \cdot 3} \]
    8. Taylor expanded in x around 0 49.4%

      \[\leadsto e^{\color{blue}{x}} \]

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

    1. Initial program 14.3%

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

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

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

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

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

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

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

Alternative 4: 41.6% accurate, 2.5× speedup?

\[\begin{array}{l} \\ e^{\left|x\right|} \end{array} \]
(FPCore (x) :precision binary64 (exp (fabs x)))
double code(double x) {
	return exp(fabs(x));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = exp(abs(x))
end function
public static double code(double x) {
	return Math.exp(Math.abs(x));
}
def code(x):
	return math.exp(math.fabs(x))
function code(x)
	return exp(abs(x))
end
function tmp = code(x)
	tmp = exp(abs(x));
end
code[x_] := N[Exp[N[Abs[x], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
e^{\left|x\right|}
\end{array}
Derivation
  1. Initial program 6.8%

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

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

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

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

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

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

    \[\leadsto \color{blue}{e^{\left(0.3333333333333333 \cdot \left(x + \log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\right)\right) \cdot 3}} \]
  5. Taylor expanded in x around inf 38.9%

    \[\leadsto e^{\color{blue}{\left(0.3333333333333333 \cdot x\right)} \cdot 3} \]
  6. Step-by-step derivation
    1. *-commutative38.9%

      \[\leadsto e^{\color{blue}{\left(x \cdot 0.3333333333333333\right)} \cdot 3} \]
  7. Simplified38.9%

    \[\leadsto e^{\color{blue}{\left(x \cdot 0.3333333333333333\right)} \cdot 3} \]
  8. Step-by-step derivation
    1. associate-*l*38.9%

      \[\leadsto e^{\color{blue}{x \cdot \left(0.3333333333333333 \cdot 3\right)}} \]
    2. metadata-eval38.9%

      \[\leadsto e^{x \cdot \color{blue}{1}} \]
    3. *-rgt-identity38.9%

      \[\leadsto e^{\color{blue}{x}} \]
    4. add-sqr-sqrt2.6%

      \[\leadsto e^{\color{blue}{\sqrt{x} \cdot \sqrt{x}}} \]
    5. sqrt-prod38.9%

      \[\leadsto e^{\color{blue}{\sqrt{x \cdot x}}} \]
    6. rem-sqrt-square38.9%

      \[\leadsto e^{\color{blue}{\left|x\right|}} \]
  9. Applied egg-rr38.9%

    \[\leadsto e^{\color{blue}{\left|x\right|}} \]
  10. Final simplification38.9%

    \[\leadsto e^{\left|x\right|} \]
  11. Add Preprocessing

Alternative 5: 41.6% accurate, 5.0× speedup?

\[\begin{array}{l} \\ e^{x} \end{array} \]
(FPCore (x) :precision binary64 (exp x))
double code(double x) {
	return exp(x);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = exp(x)
end function
public static double code(double x) {
	return Math.exp(x);
}
def code(x):
	return math.exp(x)
function code(x)
	return exp(x)
end
function tmp = code(x)
	tmp = exp(x);
end
code[x_] := N[Exp[x], $MachinePrecision]
\begin{array}{l}

\\
e^{x}
\end{array}
Derivation
  1. Initial program 6.8%

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

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

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

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

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

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

    \[\leadsto \color{blue}{e^{\left(0.3333333333333333 \cdot \left(x + \log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\right)\right) \cdot 3}} \]
  5. Taylor expanded in x around inf 38.9%

    \[\leadsto e^{\color{blue}{\left(0.3333333333333333 \cdot x\right)} \cdot 3} \]
  6. Step-by-step derivation
    1. *-commutative38.9%

      \[\leadsto e^{\color{blue}{\left(x \cdot 0.3333333333333333\right)} \cdot 3} \]
  7. Simplified38.9%

    \[\leadsto e^{\color{blue}{\left(x \cdot 0.3333333333333333\right)} \cdot 3} \]
  8. Taylor expanded in x around 0 38.9%

    \[\leadsto e^{\color{blue}{x}} \]
  9. Final simplification38.9%

    \[\leadsto e^{x} \]
  10. Add Preprocessing

Reproduce

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