Average Error: 35.6 → 27.1
Time: 13.0s
Precision: 64
\[\frac{\tan \left(\frac{x}{y \cdot 2}\right)}{\sin \left(\frac{x}{y \cdot 2}\right)}\]
\[\begin{array}{l} \mathbf{if}\;\frac{x}{y \cdot 2} \le -163906923100785256247066624:\\ \;\;\;\;1\\ \mathbf{elif}\;\frac{x}{y \cdot 2} \le 150459310596020020183040:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{1}{\cos \left(\frac{x}{y \cdot 2}\right)}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]
\frac{\tan \left(\frac{x}{y \cdot 2}\right)}{\sin \left(\frac{x}{y \cdot 2}\right)}
\begin{array}{l}
\mathbf{if}\;\frac{x}{y \cdot 2} \le -163906923100785256247066624:\\
\;\;\;\;1\\

\mathbf{elif}\;\frac{x}{y \cdot 2} \le 150459310596020020183040:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{1}{\cos \left(\frac{x}{y \cdot 2}\right)}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;1\\

\end{array}
double f(double x, double y) {
        double r380515 = x;
        double r380516 = y;
        double r380517 = 2.0;
        double r380518 = r380516 * r380517;
        double r380519 = r380515 / r380518;
        double r380520 = tan(r380519);
        double r380521 = sin(r380519);
        double r380522 = r380520 / r380521;
        return r380522;
}

double f(double x, double y) {
        double r380523 = x;
        double r380524 = y;
        double r380525 = 2.0;
        double r380526 = r380524 * r380525;
        double r380527 = r380523 / r380526;
        double r380528 = -1.6390692310078526e+26;
        bool r380529 = r380527 <= r380528;
        double r380530 = 1.0;
        double r380531 = 1.5045931059602002e+23;
        bool r380532 = r380527 <= r380531;
        double r380533 = 1.0;
        double r380534 = cos(r380527);
        double r380535 = r380533 / r380534;
        double r380536 = expm1(r380535);
        double r380537 = log1p(r380536);
        double r380538 = r380532 ? r380537 : r380530;
        double r380539 = r380529 ? r380530 : r380538;
        return r380539;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original35.6
Target28.7
Herbie27.1
\[\begin{array}{l} \mathbf{if}\;y \lt -1.230369091130699363447511617672816900781 \cdot 10^{114}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \lt -9.102852406811913849731222630299032206502 \cdot 10^{-222}:\\ \;\;\;\;\frac{\sin \left(\frac{x}{y \cdot 2}\right)}{\sin \left(\frac{x}{y \cdot 2}\right) \cdot \log \left(e^{\cos \left(\frac{x}{y \cdot 2}\right)}\right)}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if (/ x (* y 2.0)) < -1.6390692310078526e+26 or 1.5045931059602002e+23 < (/ x (* y 2.0))

    1. Initial program 58.9

      \[\frac{\tan \left(\frac{x}{y \cdot 2}\right)}{\sin \left(\frac{x}{y \cdot 2}\right)}\]
    2. Taylor expanded around 0 56.4

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

    if -1.6390692310078526e+26 < (/ x (* y 2.0)) < 1.5045931059602002e+23

    1. Initial program 16.0

      \[\frac{\tan \left(\frac{x}{y \cdot 2}\right)}{\sin \left(\frac{x}{y \cdot 2}\right)}\]
    2. Using strategy rm
    3. Applied tan-quot16.0

      \[\leadsto \frac{\color{blue}{\frac{\sin \left(\frac{x}{y \cdot 2}\right)}{\cos \left(\frac{x}{y \cdot 2}\right)}}}{\sin \left(\frac{x}{y \cdot 2}\right)}\]
    4. Applied associate-/l/16.0

      \[\leadsto \color{blue}{\frac{\sin \left(\frac{x}{y \cdot 2}\right)}{\sin \left(\frac{x}{y \cdot 2}\right) \cdot \cos \left(\frac{x}{y \cdot 2}\right)}}\]
    5. Using strategy rm
    6. Applied log1p-expm1-u16.0

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\sin \left(\frac{x}{y \cdot 2}\right)}{\sin \left(\frac{x}{y \cdot 2}\right) \cdot \cos \left(\frac{x}{y \cdot 2}\right)}\right)\right)}\]
    7. Simplified2.4

      \[\leadsto \mathsf{log1p}\left(\color{blue}{\mathsf{expm1}\left(\frac{1}{\cos \left(\frac{x}{y \cdot 2}\right)}\right)}\right)\]
  3. Recombined 2 regimes into one program.
  4. Final simplification27.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x}{y \cdot 2} \le -163906923100785256247066624:\\ \;\;\;\;1\\ \mathbf{elif}\;\frac{x}{y \cdot 2} \le 150459310596020020183040:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{1}{\cos \left(\frac{x}{y \cdot 2}\right)}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

herbie shell --seed 2019235 +o rules:numerics
(FPCore (x y)
  :name "Diagrams.TwoD.Layout.CirclePacking:approxRadius from diagrams-contrib-1.3.0.5"
  :precision binary64

  :herbie-target
  (if (< y -1.23036909113069936e114) 1 (if (< y -9.1028524068119138e-222) (/ (sin (/ x (* y 2))) (* (sin (/ x (* y 2))) (log (exp (cos (/ x (* y 2))))))) 1))

  (/ (tan (/ x (* y 2))) (sin (/ x (* y 2)))))