?

Average Accuracy: 6.9% → 61.6%
Time: 14.9s
Precision: binary64
Cost: 6660

?

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

\mathbf{else}:\\
\;\;\;\;e^{-x}\\


\end{array}

Error?

Derivation?

  1. Split input into 2 regimes
  2. if x < -2.0000000000000002e-15

    1. Initial program 80.3%

      \[\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \]
    2. Simplified80.6%

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

      [Start]80.3

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

      exp-neg [=>]80.5

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

      associate-*r/ [=>]80.6

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

      *-rgt-identity [=>]80.6

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

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

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

      [Start]80.3

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

      *-commutative [=>]80.3

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

      unpow2 [=>]80.3

      \[ \frac{\left(\left(e^{x}\right) \bmod \left(1 + \color{blue}{\left(x \cdot x\right)} \cdot -0.25\right)\right)}{e^{x}} \]
    5. Applied egg-rr80.9%

      \[\leadsto \color{blue}{e^{\log \left(\left(e^{x}\right) \bmod \left(\mathsf{fma}\left(x, x \cdot -0.25, 1\right)\right)\right) - x}} \]
    6. Applied egg-rr80.9%

      \[\leadsto \color{blue}{{\left(e^{{\left(\sqrt[3]{\log \left(\left(e^{x}\right) \bmod \left(\mathsf{fma}\left(x, x \cdot -0.25, 1\right)\right)\right) - x}\right)}^{2}}\right)}^{\left(\sqrt[3]{\log \left(\left(e^{x}\right) \bmod \left(\mathsf{fma}\left(x, x \cdot -0.25, 1\right)\right)\right) - x}\right)}} \]
    7. Taylor expanded in x around inf 99.6%

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

    if -2.0000000000000002e-15 < x

    1. Initial program 4.9%

      \[\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \]
    2. Simplified4.9%

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

      [Start]4.9

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

      exp-neg [=>]4.9

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

      associate-*r/ [=>]4.9

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

      *-rgt-identity [=>]4.9

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

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

      \[\leadsto e^{\color{blue}{-1 \cdot x}} \]
    5. Simplified60.5%

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

      [Start]60.5

      \[ e^{-1 \cdot x} \]

      mul-1-neg [=>]60.5

      \[ e^{\color{blue}{-x}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification61.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2 \cdot 10^{-15}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;e^{-x}\\ \end{array} \]

Alternatives

Alternative 1
Accuracy42.7%
Cost64
\[1 \]

Error

Reproduce?

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