Average Error: 43.9 → 0.6
Time: 13.0s
Precision: 64
\[\Im(\left(\frac{e^{x} + e^{-x}}{2} \cdot \cos y + \frac{e^{x} - e^{-x}}{2} \cdot \sin y i\right))\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.013606942973814946:\\ \;\;\;\;\Im(\left(\frac{e^{x} + e^{-x}}{2} \cdot \cos y + 0.5 \cdot \left(\left(e^{x} - e^{-1 \cdot x}\right) \cdot \sin y\right) i\right))\\ \mathbf{else}:\\ \;\;\;\;\Im(\left(\frac{e^{x} + e^{-x}}{2} \cdot \cos y + \left(\sqrt[3]{\frac{\frac{1}{2}}{\sqrt{2}}} \cdot \frac{\mathsf{fma}\left(\frac{1}{3}, {x}^{3}, \mathsf{fma}\left(\frac{1}{60}, {x}^{5}, 2 \cdot x\right)\right)}{\sqrt{2}}\right) \cdot \sin y i\right))\\ \end{array}\]
\Im(\left(\frac{e^{x} + e^{-x}}{2} \cdot \cos y + \frac{e^{x} - e^{-x}}{2} \cdot \sin y i\right))
\begin{array}{l}
\mathbf{if}\;x \le -0.013606942973814946:\\
\;\;\;\;\Im(\left(\frac{e^{x} + e^{-x}}{2} \cdot \cos y + 0.5 \cdot \left(\left(e^{x} - e^{-1 \cdot x}\right) \cdot \sin y\right) i\right))\\

\mathbf{else}:\\
\;\;\;\;\Im(\left(\frac{e^{x} + e^{-x}}{2} \cdot \cos y + \left(\sqrt[3]{\frac{\frac{1}{2}}{\sqrt{2}}} \cdot \frac{\mathsf{fma}\left(\frac{1}{3}, {x}^{3}, \mathsf{fma}\left(\frac{1}{60}, {x}^{5}, 2 \cdot x\right)\right)}{\sqrt{2}}\right) \cdot \sin y i\right))\\

\end{array}
double f(double x, double y) {
        double r56155 = x;
        double r56156 = exp(r56155);
        double r56157 = -r56155;
        double r56158 = exp(r56157);
        double r56159 = r56156 + r56158;
        double r56160 = 2.0;
        double r56161 = r56159 / r56160;
        double r56162 = y;
        double r56163 = cos(r56162);
        double r56164 = r56161 * r56163;
        double r56165 = r56156 - r56158;
        double r56166 = r56165 / r56160;
        double r56167 = sin(r56162);
        double r56168 = r56166 * r56167;
        double r56169 = /* ERROR: no complex support in C */;
        double r56170 = /* ERROR: no complex support in C */;
        return r56170;
}

double f(double x, double y) {
        double r56171 = x;
        double r56172 = -0.013606942973814946;
        bool r56173 = r56171 <= r56172;
        double r56174 = exp(r56171);
        double r56175 = -r56171;
        double r56176 = exp(r56175);
        double r56177 = r56174 + r56176;
        double r56178 = 2.0;
        double r56179 = r56177 / r56178;
        double r56180 = y;
        double r56181 = cos(r56180);
        double r56182 = r56179 * r56181;
        double r56183 = 0.5;
        double r56184 = -1.0;
        double r56185 = r56184 * r56171;
        double r56186 = exp(r56185);
        double r56187 = r56174 - r56186;
        double r56188 = sin(r56180);
        double r56189 = r56187 * r56188;
        double r56190 = r56183 * r56189;
        double r56191 = /* ERROR: no complex support in C */;
        double r56192 = /* ERROR: no complex support in C */;
        double r56193 = 1.0;
        double r56194 = r56193 / r56178;
        double r56195 = sqrt(r56178);
        double r56196 = r56194 / r56195;
        double r56197 = cbrt(r56196);
        double r56198 = 0.3333333333333333;
        double r56199 = 3.0;
        double r56200 = pow(r56171, r56199);
        double r56201 = 0.016666666666666666;
        double r56202 = 5.0;
        double r56203 = pow(r56171, r56202);
        double r56204 = 2.0;
        double r56205 = r56204 * r56171;
        double r56206 = fma(r56201, r56203, r56205);
        double r56207 = fma(r56198, r56200, r56206);
        double r56208 = r56207 / r56195;
        double r56209 = r56197 * r56208;
        double r56210 = r56209 * r56188;
        double r56211 = /* ERROR: no complex support in C */;
        double r56212 = /* ERROR: no complex support in C */;
        double r56213 = r56173 ? r56192 : r56212;
        return r56213;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 2 regimes
  2. if x < -0.013606942973814946

    1. Initial program 5.4

      \[\Im(\left(\frac{e^{x} + e^{-x}}{2} \cdot \cos y + \frac{e^{x} - e^{-x}}{2} \cdot \sin y i\right))\]
    2. Taylor expanded around inf 5.4

      \[\leadsto \Im(\left(\frac{e^{x} + e^{-x}}{2} \cdot \cos y + \color{blue}{0.5 \cdot \left(\sin y \cdot \left(e^{x} - e^{-x}\right)\right)} i\right))\]
    3. Simplified5.4

      \[\leadsto \Im(\left(\frac{e^{x} + e^{-x}}{2} \cdot \cos y + \color{blue}{0.5 \cdot \left(\left(e^{x} - e^{-1 \cdot x}\right) \cdot \sin y\right)} i\right))\]

    if -0.013606942973814946 < x

    1. Initial program 44.2

      \[\Im(\left(\frac{e^{x} + e^{-x}}{2} \cdot \cos y + \frac{e^{x} - e^{-x}}{2} \cdot \sin y i\right))\]
    2. Taylor expanded around 0 0.5

      \[\leadsto \Im(\left(\frac{e^{x} + e^{-x}}{2} \cdot \cos y + \frac{\color{blue}{\frac{1}{3} \cdot {x}^{3} + \left(\frac{1}{60} \cdot {x}^{5} + 2 \cdot x\right)}}{2} \cdot \sin y i\right))\]
    3. Simplified0.5

      \[\leadsto \Im(\left(\frac{e^{x} + e^{-x}}{2} \cdot \cos y + \frac{\color{blue}{\mathsf{fma}\left(\frac{1}{3}, {x}^{3}, \mathsf{fma}\left(\frac{1}{60}, {x}^{5}, 2 \cdot x\right)\right)}}{2} \cdot \sin y i\right))\]
    4. Using strategy rm
    5. Applied add-sqr-sqrt1.3

      \[\leadsto \Im(\left(\frac{e^{x} + e^{-x}}{2} \cdot \cos y + \frac{\mathsf{fma}\left(\frac{1}{3}, {x}^{3}, \mathsf{fma}\left(\frac{1}{60}, {x}^{5}, 2 \cdot x\right)\right)}{\color{blue}{\sqrt{2} \cdot \sqrt{2}}} \cdot \sin y i\right))\]
    6. Applied *-un-lft-identity1.3

      \[\leadsto \Im(\left(\frac{e^{x} + e^{-x}}{2} \cdot \cos y + \frac{\color{blue}{1 \cdot \mathsf{fma}\left(\frac{1}{3}, {x}^{3}, \mathsf{fma}\left(\frac{1}{60}, {x}^{5}, 2 \cdot x\right)\right)}}{\sqrt{2} \cdot \sqrt{2}} \cdot \sin y i\right))\]
    7. Applied times-frac1.1

      \[\leadsto \Im(\left(\frac{e^{x} + e^{-x}}{2} \cdot \cos y + \color{blue}{\left(\frac{1}{\sqrt{2}} \cdot \frac{\mathsf{fma}\left(\frac{1}{3}, {x}^{3}, \mathsf{fma}\left(\frac{1}{60}, {x}^{5}, 2 \cdot x\right)\right)}{\sqrt{2}}\right)} \cdot \sin y i\right))\]
    8. Applied associate-*l*1.0

      \[\leadsto \Im(\left(\frac{e^{x} + e^{-x}}{2} \cdot \cos y + \color{blue}{\frac{1}{\sqrt{2}} \cdot \left(\frac{\mathsf{fma}\left(\frac{1}{3}, {x}^{3}, \mathsf{fma}\left(\frac{1}{60}, {x}^{5}, 2 \cdot x\right)\right)}{\sqrt{2}} \cdot \sin y\right)} i\right))\]
    9. Using strategy rm
    10. Applied add-cbrt-cube1.5

      \[\leadsto \Im(\left(\frac{e^{x} + e^{-x}}{2} \cdot \cos y + \frac{1}{\color{blue}{\sqrt[3]{\left(\sqrt{2} \cdot \sqrt{2}\right) \cdot \sqrt{2}}}} \cdot \left(\frac{\mathsf{fma}\left(\frac{1}{3}, {x}^{3}, \mathsf{fma}\left(\frac{1}{60}, {x}^{5}, 2 \cdot x\right)\right)}{\sqrt{2}} \cdot \sin y\right) i\right))\]
    11. Applied add-cbrt-cube1.5

      \[\leadsto \Im(\left(\frac{e^{x} + e^{-x}}{2} \cdot \cos y + \frac{\color{blue}{\sqrt[3]{\left(1 \cdot 1\right) \cdot 1}}}{\sqrt[3]{\left(\sqrt{2} \cdot \sqrt{2}\right) \cdot \sqrt{2}}} \cdot \left(\frac{\mathsf{fma}\left(\frac{1}{3}, {x}^{3}, \mathsf{fma}\left(\frac{1}{60}, {x}^{5}, 2 \cdot x\right)\right)}{\sqrt{2}} \cdot \sin y\right) i\right))\]
    12. Applied cbrt-undiv1.0

      \[\leadsto \Im(\left(\frac{e^{x} + e^{-x}}{2} \cdot \cos y + \color{blue}{\sqrt[3]{\frac{\left(1 \cdot 1\right) \cdot 1}{\left(\sqrt{2} \cdot \sqrt{2}\right) \cdot \sqrt{2}}}} \cdot \left(\frac{\mathsf{fma}\left(\frac{1}{3}, {x}^{3}, \mathsf{fma}\left(\frac{1}{60}, {x}^{5}, 2 \cdot x\right)\right)}{\sqrt{2}} \cdot \sin y\right) i\right))\]
    13. Simplified0.6

      \[\leadsto \Im(\left(\frac{e^{x} + e^{-x}}{2} \cdot \cos y + \sqrt[3]{\color{blue}{\frac{\frac{1}{2}}{\sqrt{2}}}} \cdot \left(\frac{\mathsf{fma}\left(\frac{1}{3}, {x}^{3}, \mathsf{fma}\left(\frac{1}{60}, {x}^{5}, 2 \cdot x\right)\right)}{\sqrt{2}} \cdot \sin y\right) i\right))\]
    14. Using strategy rm
    15. Applied associate-*r*0.5

      \[\leadsto \Im(\left(\frac{e^{x} + e^{-x}}{2} \cdot \cos y + \color{blue}{\left(\sqrt[3]{\frac{\frac{1}{2}}{\sqrt{2}}} \cdot \frac{\mathsf{fma}\left(\frac{1}{3}, {x}^{3}, \mathsf{fma}\left(\frac{1}{60}, {x}^{5}, 2 \cdot x\right)\right)}{\sqrt{2}}\right) \cdot \sin y} i\right))\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.013606942973814946:\\ \;\;\;\;\Im(\left(\frac{e^{x} + e^{-x}}{2} \cdot \cos y + 0.5 \cdot \left(\left(e^{x} - e^{-1 \cdot x}\right) \cdot \sin y\right) i\right))\\ \mathbf{else}:\\ \;\;\;\;\Im(\left(\frac{e^{x} + e^{-x}}{2} \cdot \cos y + \left(\sqrt[3]{\frac{\frac{1}{2}}{\sqrt{2}}} \cdot \frac{\mathsf{fma}\left(\frac{1}{3}, {x}^{3}, \mathsf{fma}\left(\frac{1}{60}, {x}^{5}, 2 \cdot x\right)\right)}{\sqrt{2}}\right) \cdot \sin y i\right))\\ \end{array}\]

Reproduce

herbie shell --seed 2020081 +o rules:numerics
(FPCore (x y)
  :name "Euler formula imaginary part (p55)"
  :precision binary64
  (im (complex (* (/ (+ (exp x) (exp (- x))) 2) (cos y)) (* (/ (- (exp x) (exp (- x))) 2) (sin y)))))