expfmod (used to be hard to sample)

Percentage Accurate: 7.1% → 7.0%
Time: 23.4s
Alternatives: 9
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 9 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: 7.0% accurate, 0.6× speedup?

\[\begin{array}{l} \\ {\left(\sqrt[3]{\frac{\log \left(e^{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}\right)}{e^{x}}}\right)}^{3} \end{array} \]
(FPCore (x)
 :precision binary64
 (pow (cbrt (/ (log (exp (fmod (exp x) (sqrt (cos x))))) (exp x))) 3.0))
double code(double x) {
	return pow(cbrt((log(exp(fmod(exp(x), sqrt(cos(x))))) / exp(x))), 3.0);
}
function code(x)
	return cbrt(Float64(log(exp(rem(exp(x), sqrt(cos(x))))) / exp(x))) ^ 3.0
end
code[x_] := N[Power[N[Power[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], 1/3], $MachinePrecision], 3.0], $MachinePrecision]
\begin{array}{l}

\\
{\left(\sqrt[3]{\frac{\log \left(e^{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}\right)}{e^{x}}}\right)}^{3}
\end{array}
Derivation
  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. add-cbrt-cube7.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 7.1% accurate, 0.7× speedup?

\[\begin{array}{l} \\ {\left(\sqrt[3]{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}}\right)}^{3} \end{array} \]
(FPCore (x)
 :precision binary64
 (pow (cbrt (/ (fmod (exp x) (sqrt (cos x))) (exp x))) 3.0))
double code(double x) {
	return pow(cbrt((fmod(exp(x), sqrt(cos(x))) / exp(x))), 3.0);
}
function code(x)
	return cbrt(Float64(rem(exp(x), sqrt(cos(x))) / exp(x))) ^ 3.0
end
code[x_] := N[Power[N[Power[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], 1/3], $MachinePrecision], 3.0], $MachinePrecision]
\begin{array}{l}

\\
{\left(\sqrt[3]{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}}\right)}^{3}
\end{array}
Derivation
  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. add-cbrt-cube7.6%

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 7.0% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \frac{\log \left(e^{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}\right)}{e^{x}} \end{array} \]
(FPCore (x)
 :precision binary64
 (/ (log (exp (fmod (exp x) (sqrt (cos x))))) (exp x)))
double code(double x) {
	return log(exp(fmod(exp(x), sqrt(cos(x))))) / exp(x);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = log(exp(mod(exp(x), sqrt(cos(x))))) / exp(x)
end function
def code(x):
	return math.log(math.exp(math.fmod(math.exp(x), math.sqrt(math.cos(x))))) / math.exp(x)
function code(x)
	return Float64(log(exp(rem(exp(x), sqrt(cos(x))))) / exp(x))
end
code[x_] := 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]
\begin{array}{l}

\\
\frac{\log \left(e^{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}\right)}{e^{x}}
\end{array}
Derivation
  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. add-log-exp7.6%

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

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

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

Alternative 4: 7.1% 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 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. Final simplification7.6%

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

Alternative 5: 6.8% 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 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. Taylor expanded in x around 0 7.4%

    \[\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. *-commutative7.4%

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

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

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

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

Alternative 6: 6.6% 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 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. Taylor expanded in x around 0 7.2%

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

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

Alternative 7: 6.1% accurate, 2.4× speedup?

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

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

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

    \[\leadsto \left(\left(e^{x}\right) \bmod \color{blue}{1}\right) \cdot e^{-x} \]
  3. Taylor expanded in x around 0 7.1%

    \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \left(\left(e^{x}\right) \bmod 1\right)\right) + \left(0.5 \cdot \left({x}^{2} \cdot \left(\left(e^{x}\right) \bmod 1\right)\right) + \left(\left(e^{x}\right) \bmod 1\right)\right)} \]
  4. Step-by-step derivation
    1. +-commutative7.1%

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

      \[\leadsto \left(0.5 \cdot \left({x}^{2} \cdot \left(\left(e^{x}\right) \bmod 1\right)\right) + \left(\left(e^{x}\right) \bmod 1\right)\right) + \color{blue}{\left(-x \cdot \left(\left(e^{x}\right) \bmod 1\right)\right)} \]
    3. unsub-neg7.1%

      \[\leadsto \color{blue}{\left(0.5 \cdot \left({x}^{2} \cdot \left(\left(e^{x}\right) \bmod 1\right)\right) + \left(\left(e^{x}\right) \bmod 1\right)\right) - x \cdot \left(\left(e^{x}\right) \bmod 1\right)} \]
    4. associate-*r*7.1%

      \[\leadsto \left(\color{blue}{\left(0.5 \cdot {x}^{2}\right) \cdot \left(\left(e^{x}\right) \bmod 1\right)} + \left(\left(e^{x}\right) \bmod 1\right)\right) - x \cdot \left(\left(e^{x}\right) \bmod 1\right) \]
    5. distribute-lft1-in7.1%

      \[\leadsto \color{blue}{\left(0.5 \cdot {x}^{2} + 1\right) \cdot \left(\left(e^{x}\right) \bmod 1\right)} - x \cdot \left(\left(e^{x}\right) \bmod 1\right) \]
    6. distribute-rgt-out--7.1%

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

      \[\leadsto \left(\left(e^{x}\right) \bmod 1\right) \cdot \left(\left(0.5 \cdot \color{blue}{\left(x \cdot x\right)} + 1\right) - x\right) \]
  5. Simplified7.1%

    \[\leadsto \color{blue}{\left(\left(e^{x}\right) \bmod 1\right) \cdot \left(\left(0.5 \cdot \left(x \cdot x\right) + 1\right) - x\right)} \]
  6. Final simplification7.1%

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

Alternative 8: 5.9% accurate, 2.5× speedup?

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

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

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

    \[\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. +-commutative7.0%

      \[\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. *-lft-identity7.0%

      \[\leadsto \color{blue}{1 \cdot \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) \]
    3. associate-*r*7.0%

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

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

      \[\leadsto \color{blue}{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot \left(1 + \left(-x\right)\right)} \]
    6. unsub-neg7.0%

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

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

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

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

Alternative 9: 5.4% 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 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. Taylor expanded in x around 0 7.2%

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

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

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

Reproduce

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