?

Average Error: 93.07% → 37.05%
Time: 13.9s
Precision: binary64
Cost: 109833

?

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


\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.58

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

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

      [Start]96.58

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

      exp-neg [=>]96.58

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

      associate-*r/ [=>]96.58

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

      *-rgt-identity [=>]96.58

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

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

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

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

      [Start]37.87

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

      mul-1-neg [=>]37.87

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

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

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

      [Start]19.78

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

      exp-neg [=>]19.63

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

      associate-*r/ [=>]19.53

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

      *-rgt-identity [=>]19.53

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

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

    \[\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}:\\ \;\;\;\;\log \left(e^{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}}\right)\\ \end{array} \]

Alternatives

Alternative 1
Error37.03%
Cost103560
\[\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:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_1 \leq 2:\\ \;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left({\left({\cos x}^{1.5}\right)}^{0.3333333333333333}\right)\right)}{e^{x}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error37.03%
Cost97161
\[\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{1}{\frac{e^{x}}{t_0}}\\ \end{array} \]
Alternative 3
Error37.03%
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 4
Error39.11%
Cost6528
\[e^{-x} \]

Error

Reproduce?

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