?

Average Error: 59.4 → 23.0
Time: 18.0s
Precision: binary64
Cost: 200521

?

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

\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{-1 + {\left(1 + t_2\right)}^{2}}}{\frac{\sqrt{2 + t_2}}{\sqrt{\frac{\left(\left(e^{x}\right) \bmod \log \left(e^{t_0}\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 61.9

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

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

      [Start]61.9

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

      exp-neg [=>]61.9

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

      associate-*r/ [=>]61.9

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

      *-rgt-identity [=>]61.9

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

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

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

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

      [Start]23.5

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

      mul-1-neg [=>]23.5

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

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

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

      [Start]12.4

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

      exp-neg [=>]12.3

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

      associate-*r/ [=>]12.3

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

      *-rgt-identity [=>]12.3

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

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}\right)} - 1} \]
    4. Applied egg-rr12.5

      \[\leadsto \color{blue}{\frac{\sqrt{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}} \cdot \sqrt{{\left(\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}} + 1\right)}^{2} + -1}}{\sqrt{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}} + 2}}} \]
    5. Simplified12.5

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

      [Start]12.5

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

      *-commutative [=>]12.5

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

      associate-/l* [=>]12.5

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

      +-commutative [=>]12.5

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

      +-commutative [=>]12.5

      \[ \frac{\sqrt{-1 + {\color{blue}{\left(1 + \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}\right)}}^{2}}}{\frac{\sqrt{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}} + 2}}{\sqrt{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}}}} \]
    6. Applied egg-rr12.6

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

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

Alternatives

Alternative 1
Error23.0
Cost187721
\[\begin{array}{l} t_0 := \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\\ t_1 := \frac{t_0}{e^{x}}\\ t_2 := e^{-x}\\ t_3 := t_0 \cdot t_2\\ \mathbf{if}\;t_3 \leq 0 \lor \neg \left(t_3 \leq 2\right):\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{-1 + {\left(1 + t_1\right)}^{2}}}{\frac{\sqrt{2 + t_1}}{\sqrt{t_1}}}\\ \end{array} \]
Alternative 2
Error23.0
Cost135625
\[\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}:\\ \;\;\;\;{\left({\left(\sqrt[3]{{\left(\sqrt[3]{\sqrt[3]{\frac{t_0}{e^{x}}}}\right)}^{3}}\right)}^{3}\right)}^{3}\\ \end{array} \]
Alternative 3
Error23.0
Cost116297
\[\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}:\\ \;\;\;\;e^{{\left(\sqrt[3]{\log t_0 - x}\right)}^{3}}\\ \end{array} \]
Alternative 4
Error23.0
Cost97289
\[\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}:\\ \;\;\;\;1 + \left(-1 + \frac{t_0}{e^{x}}\right)\\ \end{array} \]
Alternative 5
Error23.0
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 6
Error23.7
Cost19588
\[\begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{-16}:\\ \;\;\;\;\frac{\left(\left(e^{x}\right) \bmod 1\right)}{e^{x}}\\ \mathbf{else}:\\ \;\;\;\;e^{-x}\\ \end{array} \]
Alternative 7
Error24.4
Cost6528
\[e^{-x} \]

Error

Reproduce?

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