Average Error: 20.6 → 3.8
Time: 17.0s
Precision: binary64
\[[x, y] = \mathsf{sort}([x, y]) \[t, a] = \mathsf{sort}([t, a]) \\]
\[\frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c} \]
\[\begin{array}{l} t_1 := \mathsf{fma}\left(\frac{y}{c}, \frac{x}{z}, 0.1111111111111111 \cdot \frac{b}{z \cdot c}\right)\\ t_2 := \frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c}\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;\mathsf{fma}\left(\sqrt[3]{729}, t_1, \frac{a}{\frac{c}{t}} \cdot -4\right)\\ \mathbf{elif}\;t_2 \leq -5266711554336.997:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_2 \leq 0:\\ \;\;\;\;\frac{\mathsf{fma}\left(t, a \cdot -4, \frac{\mathsf{fma}\left(x, 9 \cdot y, b\right)}{z}\right)}{c}\\ \mathbf{elif}\;t_2 \leq 1.3778404511985451 \cdot 10^{+290}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\sqrt[3]{729}, t_1, -4 \cdot \left(a \cdot \frac{t}{c}\right)\right)\\ \end{array} \]
\frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c}
\begin{array}{l}
t_1 := \mathsf{fma}\left(\frac{y}{c}, \frac{x}{z}, 0.1111111111111111 \cdot \frac{b}{z \cdot c}\right)\\
t_2 := \frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c}\\
\mathbf{if}\;t_2 \leq -\infty:\\
\;\;\;\;\mathsf{fma}\left(\sqrt[3]{729}, t_1, \frac{a}{\frac{c}{t}} \cdot -4\right)\\

\mathbf{elif}\;t_2 \leq -5266711554336.997:\\
\;\;\;\;t_2\\

\mathbf{elif}\;t_2 \leq 0:\\
\;\;\;\;\frac{\mathsf{fma}\left(t, a \cdot -4, \frac{\mathsf{fma}\left(x, 9 \cdot y, b\right)}{z}\right)}{c}\\

\mathbf{elif}\;t_2 \leq 1.3778404511985451 \cdot 10^{+290}:\\
\;\;\;\;t_2\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\sqrt[3]{729}, t_1, -4 \cdot \left(a \cdot \frac{t}{c}\right)\right)\\


\end{array}
(FPCore (x y z t a b c)
 :precision binary64
 (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c)))
(FPCore (x y z t a b c)
 :precision binary64
 (let* ((t_1 (fma (/ y c) (/ x z) (* 0.1111111111111111 (/ b (* z c)))))
        (t_2 (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c))))
   (if (<= t_2 (- INFINITY))
     (fma (cbrt 729.0) t_1 (* (/ a (/ c t)) -4.0))
     (if (<= t_2 -5266711554336.997)
       t_2
       (if (<= t_2 0.0)
         (/ (fma t (* a -4.0) (/ (fma x (* 9.0 y) b) z)) c)
         (if (<= t_2 1.3778404511985451e+290)
           t_2
           (fma (cbrt 729.0) t_1 (* -4.0 (* a (/ t c))))))))))
double code(double x, double y, double z, double t, double a, double b, double c) {
	return ((((x * 9.0) * y) - (((z * 4.0) * t) * a)) + b) / (z * c);
}
double code(double x, double y, double z, double t, double a, double b, double c) {
	double t_1 = fma((y / c), (x / z), (0.1111111111111111 * (b / (z * c))));
	double t_2 = ((((x * 9.0) * y) - (((z * 4.0) * t) * a)) + b) / (z * c);
	double tmp;
	if (t_2 <= -((double) INFINITY)) {
		tmp = fma(cbrt(729.0), t_1, ((a / (c / t)) * -4.0));
	} else if (t_2 <= -5266711554336.997) {
		tmp = t_2;
	} else if (t_2 <= 0.0) {
		tmp = fma(t, (a * -4.0), (fma(x, (9.0 * y), b) / z)) / c;
	} else if (t_2 <= 1.3778404511985451e+290) {
		tmp = t_2;
	} else {
		tmp = fma(cbrt(729.0), t_1, (-4.0 * (a * (t / c))));
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original20.6
Target14.4
Herbie3.8
\[\begin{array}{l} \mathbf{if}\;\frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c} < -1.100156740804105 \cdot 10^{-171}:\\ \;\;\;\;\frac{\left(\left(x \cdot 9\right) \cdot y - \left(z \cdot 4\right) \cdot \left(t \cdot a\right)\right) + b}{z \cdot c}\\ \mathbf{elif}\;\frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c} < 0:\\ \;\;\;\;\frac{\frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z}}{c}\\ \mathbf{elif}\;\frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c} < 1.1708877911747488 \cdot 10^{-53}:\\ \;\;\;\;\frac{\left(\left(x \cdot 9\right) \cdot y - \left(z \cdot 4\right) \cdot \left(t \cdot a\right)\right) + b}{z \cdot c}\\ \mathbf{elif}\;\frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c} < 2.876823679546137 \cdot 10^{+130}:\\ \;\;\;\;\left(\left(9 \cdot \frac{y}{c}\right) \cdot \frac{x}{z} + \frac{b}{c \cdot z}\right) - 4 \cdot \frac{a \cdot t}{c}\\ \mathbf{elif}\;\frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c} < 1.3838515042456319 \cdot 10^{+158}:\\ \;\;\;\;\frac{\left(\left(x \cdot 9\right) \cdot y - \left(z \cdot 4\right) \cdot \left(t \cdot a\right)\right) + b}{z \cdot c}\\ \mathbf{else}:\\ \;\;\;\;\left(9 \cdot \left(\frac{y}{c \cdot z} \cdot x\right) + \frac{b}{c \cdot z}\right) - 4 \cdot \frac{a \cdot t}{c}\\ \end{array} \]

Derivation

  1. Split input into 4 regimes
  2. if (/.f64 (+.f64 (-.f64 (*.f64 (*.f64 x 9) y) (*.f64 (*.f64 (*.f64 z 4) t) a)) b) (*.f64 z c)) < -inf.0

    1. Initial program 64.0

      \[\frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c} \]
    2. Simplified24.6

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(t, a \cdot -4, \frac{\mathsf{fma}\left(x, 9 \cdot y, b\right)}{z}\right)}{c}} \]
    3. Applied div-inv_binary6424.7

      \[\leadsto \color{blue}{\mathsf{fma}\left(t, a \cdot -4, \frac{\mathsf{fma}\left(x, 9 \cdot y, b\right)}{z}\right) \cdot \frac{1}{c}} \]
    4. Applied add-cube-cbrt_binary6424.8

      \[\leadsto \mathsf{fma}\left(t, a \cdot -4, \frac{\color{blue}{\left(\sqrt[3]{\mathsf{fma}\left(x, 9 \cdot y, b\right)} \cdot \sqrt[3]{\mathsf{fma}\left(x, 9 \cdot y, b\right)}\right) \cdot \sqrt[3]{\mathsf{fma}\left(x, 9 \cdot y, b\right)}}}{z}\right) \cdot \frac{1}{c} \]
    5. Applied associate-/l*_binary6424.8

      \[\leadsto \mathsf{fma}\left(t, a \cdot -4, \color{blue}{\frac{\sqrt[3]{\mathsf{fma}\left(x, 9 \cdot y, b\right)} \cdot \sqrt[3]{\mathsf{fma}\left(x, 9 \cdot y, b\right)}}{\frac{z}{\sqrt[3]{\mathsf{fma}\left(x, 9 \cdot y, b\right)}}}}\right) \cdot \frac{1}{c} \]
    6. Simplified24.8

      \[\leadsto \mathsf{fma}\left(t, a \cdot -4, \frac{\sqrt[3]{\mathsf{fma}\left(x, 9 \cdot y, b\right)} \cdot \sqrt[3]{\mathsf{fma}\left(x, 9 \cdot y, b\right)}}{\color{blue}{\frac{z}{\sqrt[3]{\mathsf{fma}\left(9, y \cdot x, b\right)}}}}\right) \cdot \frac{1}{c} \]
    7. Taylor expanded in b around 0 30.2

      \[\leadsto \color{blue}{\left(\frac{y \cdot x}{c \cdot z} \cdot {729}^{0.3333333333333333} + 0.1111111111111111 \cdot \left(\frac{b}{c \cdot z} \cdot {729}^{0.3333333333333333}\right)\right) - 4 \cdot \frac{a \cdot t}{c}} \]
    8. Simplified19.5

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt[3]{729}, \mathsf{fma}\left(\frac{y}{c}, \frac{x}{z}, 0.1111111111111111 \cdot \frac{b}{z \cdot c}\right), \frac{a \cdot t}{c} \cdot -4\right)} \]
    9. Applied associate-/l*_binary6416.5

      \[\leadsto \mathsf{fma}\left(\sqrt[3]{729}, \mathsf{fma}\left(\frac{y}{c}, \frac{x}{z}, 0.1111111111111111 \cdot \frac{b}{z \cdot c}\right), \color{blue}{\frac{a}{\frac{c}{t}}} \cdot -4\right) \]

    if -inf.0 < (/.f64 (+.f64 (-.f64 (*.f64 (*.f64 x 9) y) (*.f64 (*.f64 (*.f64 z 4) t) a)) b) (*.f64 z c)) < -5266711554336.99707 or -0.0 < (/.f64 (+.f64 (-.f64 (*.f64 (*.f64 x 9) y) (*.f64 (*.f64 (*.f64 z 4) t) a)) b) (*.f64 z c)) < 1.37784045119854511e290

    1. Initial program 0.7

      \[\frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c} \]

    if -5266711554336.99707 < (/.f64 (+.f64 (-.f64 (*.f64 (*.f64 x 9) y) (*.f64 (*.f64 (*.f64 z 4) t) a)) b) (*.f64 z c)) < -0.0

    1. Initial program 20.0

      \[\frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c} \]
    2. Simplified1.0

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(t, a \cdot -4, \frac{\mathsf{fma}\left(x, 9 \cdot y, b\right)}{z}\right)}{c}} \]

    if 1.37784045119854511e290 < (/.f64 (+.f64 (-.f64 (*.f64 (*.f64 x 9) y) (*.f64 (*.f64 (*.f64 z 4) t) a)) b) (*.f64 z c))

    1. Initial program 60.4

      \[\frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c} \]
    2. Simplified26.8

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(t, a \cdot -4, \frac{\mathsf{fma}\left(x, 9 \cdot y, b\right)}{z}\right)}{c}} \]
    3. Applied div-inv_binary6426.9

      \[\leadsto \color{blue}{\mathsf{fma}\left(t, a \cdot -4, \frac{\mathsf{fma}\left(x, 9 \cdot y, b\right)}{z}\right) \cdot \frac{1}{c}} \]
    4. Applied add-cube-cbrt_binary6427.0

      \[\leadsto \mathsf{fma}\left(t, a \cdot -4, \frac{\color{blue}{\left(\sqrt[3]{\mathsf{fma}\left(x, 9 \cdot y, b\right)} \cdot \sqrt[3]{\mathsf{fma}\left(x, 9 \cdot y, b\right)}\right) \cdot \sqrt[3]{\mathsf{fma}\left(x, 9 \cdot y, b\right)}}}{z}\right) \cdot \frac{1}{c} \]
    5. Applied associate-/l*_binary6427.0

      \[\leadsto \mathsf{fma}\left(t, a \cdot -4, \color{blue}{\frac{\sqrt[3]{\mathsf{fma}\left(x, 9 \cdot y, b\right)} \cdot \sqrt[3]{\mathsf{fma}\left(x, 9 \cdot y, b\right)}}{\frac{z}{\sqrt[3]{\mathsf{fma}\left(x, 9 \cdot y, b\right)}}}}\right) \cdot \frac{1}{c} \]
    6. Simplified27.0

      \[\leadsto \mathsf{fma}\left(t, a \cdot -4, \frac{\sqrt[3]{\mathsf{fma}\left(x, 9 \cdot y, b\right)} \cdot \sqrt[3]{\mathsf{fma}\left(x, 9 \cdot y, b\right)}}{\color{blue}{\frac{z}{\sqrt[3]{\mathsf{fma}\left(9, y \cdot x, b\right)}}}}\right) \cdot \frac{1}{c} \]
    7. Taylor expanded in b around 0 29.5

      \[\leadsto \color{blue}{\left(\frac{y \cdot x}{c \cdot z} \cdot {729}^{0.3333333333333333} + 0.1111111111111111 \cdot \left(\frac{b}{c \cdot z} \cdot {729}^{0.3333333333333333}\right)\right) - 4 \cdot \frac{a \cdot t}{c}} \]
    8. Simplified17.8

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt[3]{729}, \mathsf{fma}\left(\frac{y}{c}, \frac{x}{z}, 0.1111111111111111 \cdot \frac{b}{z \cdot c}\right), \frac{a \cdot t}{c} \cdot -4\right)} \]
    9. Applied *-un-lft-identity_binary6417.8

      \[\leadsto \mathsf{fma}\left(\sqrt[3]{729}, \mathsf{fma}\left(\frac{y}{c}, \frac{x}{z}, 0.1111111111111111 \cdot \frac{b}{z \cdot c}\right), \frac{a \cdot t}{\color{blue}{1 \cdot c}} \cdot -4\right) \]
    10. Applied times-frac_binary6410.9

      \[\leadsto \mathsf{fma}\left(\sqrt[3]{729}, \mathsf{fma}\left(\frac{y}{c}, \frac{x}{z}, 0.1111111111111111 \cdot \frac{b}{z \cdot c}\right), \color{blue}{\left(\frac{a}{1} \cdot \frac{t}{c}\right)} \cdot -4\right) \]
    11. Simplified10.9

      \[\leadsto \mathsf{fma}\left(\sqrt[3]{729}, \mathsf{fma}\left(\frac{y}{c}, \frac{x}{z}, 0.1111111111111111 \cdot \frac{b}{z \cdot c}\right), \left(\color{blue}{a} \cdot \frac{t}{c}\right) \cdot -4\right) \]
  3. Recombined 4 regimes into one program.
  4. Final simplification3.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c} \leq -\infty:\\ \;\;\;\;\mathsf{fma}\left(\sqrt[3]{729}, \mathsf{fma}\left(\frac{y}{c}, \frac{x}{z}, 0.1111111111111111 \cdot \frac{b}{z \cdot c}\right), \frac{a}{\frac{c}{t}} \cdot -4\right)\\ \mathbf{elif}\;\frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c} \leq -5266711554336.997:\\ \;\;\;\;\frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c}\\ \mathbf{elif}\;\frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c} \leq 0:\\ \;\;\;\;\frac{\mathsf{fma}\left(t, a \cdot -4, \frac{\mathsf{fma}\left(x, 9 \cdot y, b\right)}{z}\right)}{c}\\ \mathbf{elif}\;\frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c} \leq 1.3778404511985451 \cdot 10^{+290}:\\ \;\;\;\;\frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\sqrt[3]{729}, \mathsf{fma}\left(\frac{y}{c}, \frac{x}{z}, 0.1111111111111111 \cdot \frac{b}{z \cdot c}\right), -4 \cdot \left(a \cdot \frac{t}{c}\right)\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2022125 
(FPCore (x y z t a b c)
  :name "Diagrams.Solve.Polynomial:cubForm  from diagrams-solve-0.1, J"
  :precision binary64

  :herbie-target
  (if (< (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c)) -1.100156740804105e-171) (/ (+ (- (* (* x 9.0) y) (* (* z 4.0) (* t a))) b) (* z c)) (if (< (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c)) 0.0) (/ (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) z) c) (if (< (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c)) 1.1708877911747488e-53) (/ (+ (- (* (* x 9.0) y) (* (* z 4.0) (* t a))) b) (* z c)) (if (< (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c)) 2.876823679546137e+130) (- (+ (* (* 9.0 (/ y c)) (/ x z)) (/ b (* c z))) (* 4.0 (/ (* a t) c))) (if (< (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c)) 1.3838515042456319e+158) (/ (+ (- (* (* x 9.0) y) (* (* z 4.0) (* t a))) b) (* z c)) (- (+ (* 9.0 (* (/ y (* c z)) x)) (/ b (* c z))) (* 4.0 (/ (* a t) c))))))))

  (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c)))