?

Average Error: 93.32% → 37.05%
Time: 16.3s
Precision: binary64
Cost: 45320

?

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

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

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


\end{array}

Error?

Derivation?

  1. Split input into 3 regimes
  2. if x < -9.999999999999969e-311

    1. Initial program 91.87

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

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

      [Start]91.87

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

      exp-neg [=>]91.85

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

      associate-*r/ [=>]91.84

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

      *-rgt-identity [=>]91.84

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

      \[\leadsto \color{blue}{e^{\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x}} \]
    4. Applied egg-rr91.81

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

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

    if -9.999999999999969e-311 < x < 0.050000000000000003

    1. Initial program 92.01

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

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

      [Start]92.01

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

      exp-neg [=>]92.01

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

      associate-*r/ [=>]92.01

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

      *-rgt-identity [=>]92.01

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

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

    if 0.050000000000000003 < x

    1. Initial program 98.98

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

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

      [Start]98.98

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

      exp-neg [=>]98.98

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

      associate-*r/ [=>]98.98

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

      *-rgt-identity [=>]98.98

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

      \[\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 1.32

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

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

      [Start]1.32

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

      mul-1-neg [=>]1.32

      \[ e^{\color{blue}{-x}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification37.05

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

Alternatives

Alternative 1
Error36.91%
Cost39048
\[\begin{array}{l} t_0 := e^{-x}\\ \mathbf{if}\;x \leq -1 \cdot 10^{-310}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 200:\\ \;\;\;\;t_0 \cdot \left(\left(e^{x}\right) \bmod \left(\sqrt[3]{{\cos x}^{1.5}}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error36.91%
Cost38984
\[\begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{-310}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 200:\\ \;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt[3]{{\cos x}^{1.5}}\right)\right)}{e^{x}}\\ \mathbf{else}:\\ \;\;\;\;e^{-x}\\ \end{array} \]
Alternative 3
Error36.91%
Cost32648
\[\begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{-310}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 200:\\ \;\;\;\;\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot \frac{1}{e^{x}}\\ \mathbf{else}:\\ \;\;\;\;e^{-x}\\ \end{array} \]
Alternative 4
Error36.91%
Cost32584
\[\begin{array}{l} t_0 := e^{-x}\\ \mathbf{if}\;x \leq -1 \cdot 10^{-310}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 200:\\ \;\;\;\;\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot t_0\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error36.91%
Cost32520
\[\begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{-310}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 200:\\ \;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}\\ \mathbf{else}:\\ \;\;\;\;e^{-x}\\ \end{array} \]
Alternative 6
Error37.13%
Cost20104
\[\begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{-310}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 0.05:\\ \;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left(1 + \left(x \cdot x\right) \cdot -0.25\right)\right)}{e^{x}}\\ \mathbf{else}:\\ \;\;\;\;e^{-x}\\ \end{array} \]
Alternative 7
Error39.48%
Cost6528
\[e^{-x} \]
Alternative 8
Error56.82%
Cost64
\[1 \]

Error

Reproduce?

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