Average Error: 3.8 → 0.6
Time: 6.6s
Precision: 64
\[\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;t \le -2.217051937980127926982818674661840685718 \cdot 10^{48}:\\ \;\;\;\;\mathsf{fma}\left(0.3333333333333333148296162562473909929395, \frac{t}{z \cdot y}, x - 0.3333333333333333148296162562473909929395 \cdot \frac{y}{z}\right)\\ \mathbf{elif}\;t \le 1.374392757043330110386267311148160852221 \cdot 10^{-73}:\\ \;\;\;\;\left(x - \frac{\frac{y}{z}}{3}\right) + \frac{1}{z} \cdot \frac{\frac{t}{3}}{y}\\ \mathbf{else}:\\ \;\;\;\;\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{{\left(3 \cdot \left(z \cdot y\right)\right)}^{1}}\\ \end{array}\]
\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\begin{array}{l}
\mathbf{if}\;t \le -2.217051937980127926982818674661840685718 \cdot 10^{48}:\\
\;\;\;\;\mathsf{fma}\left(0.3333333333333333148296162562473909929395, \frac{t}{z \cdot y}, x - 0.3333333333333333148296162562473909929395 \cdot \frac{y}{z}\right)\\

\mathbf{elif}\;t \le 1.374392757043330110386267311148160852221 \cdot 10^{-73}:\\
\;\;\;\;\left(x - \frac{\frac{y}{z}}{3}\right) + \frac{1}{z} \cdot \frac{\frac{t}{3}}{y}\\

\mathbf{else}:\\
\;\;\;\;\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{{\left(3 \cdot \left(z \cdot y\right)\right)}^{1}}\\

\end{array}
double f(double x, double y, double z, double t) {
        double r869673 = x;
        double r869674 = y;
        double r869675 = z;
        double r869676 = 3.0;
        double r869677 = r869675 * r869676;
        double r869678 = r869674 / r869677;
        double r869679 = r869673 - r869678;
        double r869680 = t;
        double r869681 = r869677 * r869674;
        double r869682 = r869680 / r869681;
        double r869683 = r869679 + r869682;
        return r869683;
}

double f(double x, double y, double z, double t) {
        double r869684 = t;
        double r869685 = -2.217051937980128e+48;
        bool r869686 = r869684 <= r869685;
        double r869687 = 0.3333333333333333;
        double r869688 = z;
        double r869689 = y;
        double r869690 = r869688 * r869689;
        double r869691 = r869684 / r869690;
        double r869692 = x;
        double r869693 = r869689 / r869688;
        double r869694 = r869687 * r869693;
        double r869695 = r869692 - r869694;
        double r869696 = fma(r869687, r869691, r869695);
        double r869697 = 1.3743927570433301e-73;
        bool r869698 = r869684 <= r869697;
        double r869699 = 3.0;
        double r869700 = r869693 / r869699;
        double r869701 = r869692 - r869700;
        double r869702 = 1.0;
        double r869703 = r869702 / r869688;
        double r869704 = r869684 / r869699;
        double r869705 = r869704 / r869689;
        double r869706 = r869703 * r869705;
        double r869707 = r869701 + r869706;
        double r869708 = r869688 * r869699;
        double r869709 = r869689 / r869708;
        double r869710 = r869692 - r869709;
        double r869711 = r869699 * r869690;
        double r869712 = pow(r869711, r869702);
        double r869713 = r869684 / r869712;
        double r869714 = r869710 + r869713;
        double r869715 = r869698 ? r869707 : r869714;
        double r869716 = r869686 ? r869696 : r869715;
        return r869716;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original3.8
Target1.9
Herbie0.6
\[\left(x - \frac{y}{z \cdot 3}\right) + \frac{\frac{t}{z \cdot 3}}{y}\]

Derivation

  1. Split input into 3 regimes
  2. if t < -2.217051937980128e+48

    1. Initial program 0.6

      \[\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}\]
    2. Taylor expanded around 0 0.8

      \[\leadsto \color{blue}{\left(0.3333333333333333148296162562473909929395 \cdot \frac{t}{z \cdot y} + x\right) - 0.3333333333333333148296162562473909929395 \cdot \frac{y}{z}}\]
    3. Simplified0.8

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.3333333333333333148296162562473909929395, \frac{t}{z \cdot y}, x - 0.3333333333333333148296162562473909929395 \cdot \frac{y}{z}\right)}\]

    if -2.217051937980128e+48 < t < 1.3743927570433301e-73

    1. Initial program 6.3

      \[\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}\]
    2. Using strategy rm
    3. Applied associate-/r*1.3

      \[\leadsto \left(x - \frac{y}{z \cdot 3}\right) + \color{blue}{\frac{\frac{t}{z \cdot 3}}{y}}\]
    4. Using strategy rm
    5. Applied associate-/r*1.3

      \[\leadsto \left(x - \color{blue}{\frac{\frac{y}{z}}{3}}\right) + \frac{\frac{t}{z \cdot 3}}{y}\]
    6. Using strategy rm
    7. Applied *-un-lft-identity1.3

      \[\leadsto \left(x - \frac{\frac{y}{z}}{3}\right) + \frac{\frac{t}{z \cdot 3}}{\color{blue}{1 \cdot y}}\]
    8. Applied *-un-lft-identity1.3

      \[\leadsto \left(x - \frac{\frac{y}{z}}{3}\right) + \frac{\frac{\color{blue}{1 \cdot t}}{z \cdot 3}}{1 \cdot y}\]
    9. Applied times-frac1.3

      \[\leadsto \left(x - \frac{\frac{y}{z}}{3}\right) + \frac{\color{blue}{\frac{1}{z} \cdot \frac{t}{3}}}{1 \cdot y}\]
    10. Applied times-frac0.3

      \[\leadsto \left(x - \frac{\frac{y}{z}}{3}\right) + \color{blue}{\frac{\frac{1}{z}}{1} \cdot \frac{\frac{t}{3}}{y}}\]
    11. Simplified0.3

      \[\leadsto \left(x - \frac{\frac{y}{z}}{3}\right) + \color{blue}{\frac{1}{z}} \cdot \frac{\frac{t}{3}}{y}\]

    if 1.3743927570433301e-73 < t

    1. Initial program 1.0

      \[\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}\]
    2. Using strategy rm
    3. Applied pow11.0

      \[\leadsto \left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot \color{blue}{{y}^{1}}}\]
    4. Applied pow11.0

      \[\leadsto \left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot \color{blue}{{3}^{1}}\right) \cdot {y}^{1}}\]
    5. Applied pow11.0

      \[\leadsto \left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(\color{blue}{{z}^{1}} \cdot {3}^{1}\right) \cdot {y}^{1}}\]
    6. Applied pow-prod-down1.0

      \[\leadsto \left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\color{blue}{{\left(z \cdot 3\right)}^{1}} \cdot {y}^{1}}\]
    7. Applied pow-prod-down1.0

      \[\leadsto \left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\color{blue}{{\left(\left(z \cdot 3\right) \cdot y\right)}^{1}}}\]
    8. Simplified0.9

      \[\leadsto \left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{{\color{blue}{\left(3 \cdot \left(z \cdot y\right)\right)}}^{1}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;t \le -2.217051937980127926982818674661840685718 \cdot 10^{48}:\\ \;\;\;\;\mathsf{fma}\left(0.3333333333333333148296162562473909929395, \frac{t}{z \cdot y}, x - 0.3333333333333333148296162562473909929395 \cdot \frac{y}{z}\right)\\ \mathbf{elif}\;t \le 1.374392757043330110386267311148160852221 \cdot 10^{-73}:\\ \;\;\;\;\left(x - \frac{\frac{y}{z}}{3}\right) + \frac{1}{z} \cdot \frac{\frac{t}{3}}{y}\\ \mathbf{else}:\\ \;\;\;\;\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{{\left(3 \cdot \left(z \cdot y\right)\right)}^{1}}\\ \end{array}\]

Reproduce

herbie shell --seed 2019353 +o rules:numerics
(FPCore (x y z t)
  :name "Diagrams.Solve.Polynomial:cubForm  from diagrams-solve-0.1, H"
  :precision binary64

  :herbie-target
  (+ (- x (/ y (* z 3))) (/ (/ t (* z 3)) y))

  (+ (- x (/ y (* z 3))) (/ t (* (* z 3) y))))