Average Error: 3.6 → 0.3
Time: 5.8s
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 -3097409.71754964394:\\ \;\;\;\;\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{z \cdot \left(3 \cdot y\right)}\\ \mathbf{elif}\;t \le 2.78038066636221327 \cdot 10^{-9}:\\ \;\;\;\;\left(x - \frac{y}{z \cdot 3}\right) + \frac{1}{z \cdot 3} \cdot \frac{t}{y}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(0.333333333333333315, \frac{t}{z \cdot y}, x - 0.333333333333333315 \cdot \frac{y}{z}\right)\\ \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 -3097409.71754964394:\\
\;\;\;\;\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{z \cdot \left(3 \cdot y\right)}\\

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

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.333333333333333315, \frac{t}{z \cdot y}, x - 0.333333333333333315 \cdot \frac{y}{z}\right)\\

\end{array}
double f(double x, double y, double z, double t) {
        double r682971 = x;
        double r682972 = y;
        double r682973 = z;
        double r682974 = 3.0;
        double r682975 = r682973 * r682974;
        double r682976 = r682972 / r682975;
        double r682977 = r682971 - r682976;
        double r682978 = t;
        double r682979 = r682975 * r682972;
        double r682980 = r682978 / r682979;
        double r682981 = r682977 + r682980;
        return r682981;
}

double f(double x, double y, double z, double t) {
        double r682982 = t;
        double r682983 = -3097409.717549644;
        bool r682984 = r682982 <= r682983;
        double r682985 = x;
        double r682986 = y;
        double r682987 = z;
        double r682988 = 3.0;
        double r682989 = r682987 * r682988;
        double r682990 = r682986 / r682989;
        double r682991 = r682985 - r682990;
        double r682992 = r682988 * r682986;
        double r682993 = r682987 * r682992;
        double r682994 = r682982 / r682993;
        double r682995 = r682991 + r682994;
        double r682996 = 2.7803806663622133e-09;
        bool r682997 = r682982 <= r682996;
        double r682998 = 1.0;
        double r682999 = r682998 / r682989;
        double r683000 = r682982 / r682986;
        double r683001 = r682999 * r683000;
        double r683002 = r682991 + r683001;
        double r683003 = 0.3333333333333333;
        double r683004 = r682987 * r682986;
        double r683005 = r682982 / r683004;
        double r683006 = r682986 / r682987;
        double r683007 = r683003 * r683006;
        double r683008 = r682985 - r683007;
        double r683009 = fma(r683003, r683005, r683008);
        double r683010 = r682997 ? r683002 : r683009;
        double r683011 = r682984 ? r682995 : r683010;
        return r683011;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original3.6
Target1.9
Herbie0.3
\[\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 < -3097409.717549644

    1. Initial program 0.4

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

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

    if -3097409.717549644 < t < 2.7803806663622133e-09

    1. Initial program 6.0

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

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

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

    if 2.7803806663622133e-09 < t

    1. Initial program 0.5

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.333333333333333315, \frac{t}{z \cdot y}, x - 0.333333333333333315 \cdot \frac{y}{z}\right)}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.3

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

Reproduce

herbie shell --seed 2020039 +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))))