expfmod (used to be hard to sample)

Percentage Accurate: 7.2% → 26.4%
Time: 14.1s
Alternatives: 4
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 4 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: 26.4% 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 2:\\ \;\;\;\;\frac{t_0}{e^{x}}\\ \mathbf{else}:\\ \;\;\;\;\left(1 \bmod 1\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (fmod (exp x) (sqrt (cos x)))))
   (if (<= (* t_0 (exp (- x))) 2.0) (/ t_0 (exp x)) (fmod 1.0 1.0))))
double code(double x) {
	double t_0 = fmod(exp(x), sqrt(cos(x)));
	double tmp;
	if ((t_0 * exp(-x)) <= 2.0) {
		tmp = t_0 / exp(x);
	} else {
		tmp = fmod(1.0, 1.0);
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: t_0
    real(8) :: tmp
    t_0 = mod(exp(x), sqrt(cos(x)))
    if ((t_0 * exp(-x)) <= 2.0d0) then
        tmp = t_0 / exp(x)
    else
        tmp = mod(1.0d0, 1.0d0)
    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)) <= 2.0:
		tmp = t_0 / math.exp(x)
	else:
		tmp = math.fmod(1.0, 1.0)
	return tmp
function code(x)
	t_0 = rem(exp(x), sqrt(cos(x)))
	tmp = 0.0
	if (Float64(t_0 * exp(Float64(-x))) <= 2.0)
		tmp = Float64(t_0 / exp(x));
	else
		tmp = rem(1.0, 1.0);
	end
	return tmp
end
code[x_] := Block[{t$95$0 = N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]}, If[LessEqual[N[(t$95$0 * N[Exp[(-x)], $MachinePrecision]), $MachinePrecision], 2.0], N[(t$95$0 / N[Exp[x], $MachinePrecision]), $MachinePrecision], N[With[{TMP1 = 1.0, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $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 2:\\
\;\;\;\;\frac{t_0}{e^{x}}\\

\mathbf{else}:\\
\;\;\;\;\left(1 \bmod 1\right)\\


\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))) < 2

    1. Initial program 10.4%

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

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

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

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

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

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

    if 2 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 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. /-rgt-identity0.0%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(1 \bmod 1\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification23.0%

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

Alternative 2: 25.4% accurate, 1.2× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\left(1 \bmod 1\right)\\


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

    1. Initial program 10.4%

      \[\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \]
    2. Taylor expanded in x around 0 8.9%

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

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

        \[\leadsto \color{blue}{\left(-x\right)} \cdot \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) + \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \]
      3. distribute-lft1-in8.9%

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

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

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

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

        \[\leadsto \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) + \color{blue}{\left(-x \cdot \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\right)} \]
      3. unsub-neg8.9%

        \[\leadsto \color{blue}{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x \cdot \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)} \]
      4. *-lft-identity8.9%

        \[\leadsto \color{blue}{1 \cdot \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)} - x \cdot \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \]
      5. distribute-rgt-out--8.9%

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

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

    if 1 < 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. /-rgt-identity0.0%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(1 \bmod 1\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification21.7%

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

Alternative 3: 24.7% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(1 \bmod 1\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x 1.0) (fmod (exp x) (sqrt (cos x))) (fmod 1.0 1.0)))
double code(double x) {
	double tmp;
	if (x <= 1.0) {
		tmp = fmod(exp(x), sqrt(cos(x)));
	} else {
		tmp = fmod(1.0, 1.0);
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= 1.0d0) then
        tmp = mod(exp(x), sqrt(cos(x)))
    else
        tmp = mod(1.0d0, 1.0d0)
    end if
    code = tmp
end function
def code(x):
	tmp = 0
	if x <= 1.0:
		tmp = math.fmod(math.exp(x), math.sqrt(math.cos(x)))
	else:
		tmp = math.fmod(1.0, 1.0)
	return tmp
function code(x)
	tmp = 0.0
	if (x <= 1.0)
		tmp = rem(exp(x), sqrt(cos(x)));
	else
		tmp = rem(1.0, 1.0);
	end
	return tmp
end
code[x_] := If[LessEqual[x, 1.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[With[{TMP1 = 1.0, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]]
\begin{array}{l}

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

\mathbf{else}:\\
\;\;\;\;\left(1 \bmod 1\right)\\


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

    1. Initial program 10.4%

      \[\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \]
    2. Taylor expanded in x around 0 7.6%

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

    if 1 < 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. /-rgt-identity0.0%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(1 \bmod 1\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification20.6%

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

Alternative 4: 22.6% accurate, 5.0× speedup?

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

\\
\left(1 \bmod 1\right)
\end{array}
Derivation
  1. Initial program 8.9%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\left(1 \bmod 1\right)} \]
  8. Final simplification17.7%

    \[\leadsto \left(1 \bmod 1\right) \]

Reproduce

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