?

Average Error: 92.78% → 37.34%
Time: 13.9s
Precision: binary64
Cost: 103561

?

\[\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \]
\[\begin{array}{l} t_0 := e^{-x}\\ t_1 := \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot t_0\\ \mathbf{if}\;t_1 \leq 0 \lor \neg \left(t_1 \leq 2\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left({\left({\cos x}^{0.25}\right)}^{2}\right)\right)}{e^{x}}\\ \end{array} \]
(FPCore (x) :precision binary64 (* (fmod (exp x) (sqrt (cos x))) (exp (- x))))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (exp (- x))) (t_1 (* (fmod (exp x) (sqrt (cos x))) t_0)))
   (if (or (<= t_1 0.0) (not (<= t_1 2.0)))
     t_0
     (/ (fmod (exp x) (pow (pow (cos x) 0.25) 2.0)) (exp x)))))
double code(double x) {
	return fmod(exp(x), sqrt(cos(x))) * exp(-x);
}
double code(double x) {
	double t_0 = exp(-x);
	double t_1 = fmod(exp(x), sqrt(cos(x))) * t_0;
	double tmp;
	if ((t_1 <= 0.0) || !(t_1 <= 2.0)) {
		tmp = t_0;
	} else {
		tmp = fmod(exp(x), pow(pow(cos(x), 0.25), 2.0)) / 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) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = exp(-x)
    t_1 = mod(exp(x), sqrt(cos(x))) * t_0
    if ((t_1 <= 0.0d0) .or. (.not. (t_1 <= 2.0d0))) then
        tmp = t_0
    else
        tmp = mod(exp(x), ((cos(x) ** 0.25d0) ** 2.0d0)) / 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):
	t_0 = math.exp(-x)
	t_1 = math.fmod(math.exp(x), math.sqrt(math.cos(x))) * t_0
	tmp = 0
	if (t_1 <= 0.0) or not (t_1 <= 2.0):
		tmp = t_0
	else:
		tmp = math.fmod(math.exp(x), math.pow(math.pow(math.cos(x), 0.25), 2.0)) / math.exp(x)
	return tmp
function code(x)
	return Float64(rem(exp(x), sqrt(cos(x))) * exp(Float64(-x)))
end
function code(x)
	t_0 = exp(Float64(-x))
	t_1 = Float64(rem(exp(x), sqrt(cos(x))) * t_0)
	tmp = 0.0
	if ((t_1 <= 0.0) || !(t_1 <= 2.0))
		tmp = t_0;
	else
		tmp = Float64(rem(exp(x), ((cos(x) ^ 0.25) ^ 2.0)) / exp(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_] := Block[{t$95$0 = N[Exp[(-x)], $MachinePrecision]}, Block[{t$95$1 = N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * t$95$0), $MachinePrecision]}, If[Or[LessEqual[t$95$1, 0.0], N[Not[LessEqual[t$95$1, 2.0]], $MachinePrecision]], t$95$0, N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Power[N[Power[N[Cos[x], $MachinePrecision], 0.25], $MachinePrecision], 2.0], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]]]]
\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x}
\begin{array}{l}
t_0 := e^{-x}\\
t_1 := \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot t_0\\
\mathbf{if}\;t_1 \leq 0 \lor \neg \left(t_1 \leq 2\right):\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left({\left({\cos x}^{0.25}\right)}^{2}\right)\right)}{e^{x}}\\


\end{array}

Error?

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 or 2 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x)))

    1. Initial program 96.57

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

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

      [Start]96.57

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

      exp-neg [=>]96.57

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

      associate-*r/ [=>]96.57

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

      *-rgt-identity [=>]96.57

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

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \color{blue}{1}\right)}{e^{x}} \]
    4. Applied egg-rr96.56

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

      \[\leadsto e^{\color{blue}{-1 \cdot x}} \]
    6. Simplified38.22

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

      [Start]38.22

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

      mul-1-neg [=>]38.22

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

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

    1. Initial program 20.93

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

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

      [Start]20.93

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

      exp-neg [=>]20.81

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

      associate-*r/ [=>]20.72

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

      *-rgt-identity [=>]20.72

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

      \[\leadsto \frac{\left(\left(e^{x}\right) \bmod \color{blue}{\left({\left({\cos x}^{0.25}\right)}^{2}\right)}\right)}{e^{x}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification37.34

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

Alternatives

Alternative 1
Error37.34%
Cost97033
\[\begin{array}{l} t_0 := \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\\ t_1 := e^{-x}\\ t_2 := t_0 \cdot t_1\\ \mathbf{if}\;t_2 \leq 0 \lor \neg \left(t_2 \leq 2\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0}{e^{x}}\\ \end{array} \]
Alternative 2
Error38.53%
Cost25988
\[\begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{-15}:\\ \;\;\;\;e^{\log \left(\left(e^{x}\right) \bmod 1\right) - x}\\ \mathbf{else}:\\ \;\;\;\;e^{-x}\\ \end{array} \]
Alternative 3
Error38.54%
Cost19588
\[\begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{-15}:\\ \;\;\;\;\frac{\left(\left(e^{x}\right) \bmod 1\right)}{e^{x}}\\ \mathbf{else}:\\ \;\;\;\;e^{-x}\\ \end{array} \]
Alternative 4
Error39.49%
Cost6528
\[e^{-x} \]

Error

Reproduce?

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