Average Error: 13.3 → 5.6
Time: 8.6s
Precision: binary64
\[\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} \mathbf{if}\;z \leq -6.985953318935387 \cdot 10^{-7}:\\ \;\;\;\;\frac{1}{\frac{c}{\mathsf{fma}\left(a, t \cdot -4, \frac{1}{\frac{z}{\mathsf{fma}\left(9, y \cdot x, b\right)}}\right)}}\\ \mathbf{elif}\;z \leq 3.4192677792128576 \cdot 10^{-131}:\\ \;\;\;\;\frac{b + \left(y \cdot \left(9 \cdot x\right) - a \cdot \left(t \cdot \left(z \cdot 4\right)\right)\right)}{z \cdot c}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, t \cdot -4, \frac{b + 9 \cdot \left(y \cdot x\right)}{z}\right)}{c}\\ \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}
\mathbf{if}\;z \leq -6.985953318935387 \cdot 10^{-7}:\\
\;\;\;\;\frac{1}{\frac{c}{\mathsf{fma}\left(a, t \cdot -4, \frac{1}{\frac{z}{\mathsf{fma}\left(9, y \cdot x, b\right)}}\right)}}\\

\mathbf{elif}\;z \leq 3.4192677792128576 \cdot 10^{-131}:\\
\;\;\;\;\frac{b + \left(y \cdot \left(9 \cdot x\right) - a \cdot \left(t \cdot \left(z \cdot 4\right)\right)\right)}{z \cdot c}\\

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


\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
 (if (<= z -6.985953318935387e-7)
   (/ 1.0 (/ c (fma a (* t -4.0) (/ 1.0 (/ z (fma 9.0 (* y x) b))))))
   (if (<= z 3.4192677792128576e-131)
     (/ (+ b (- (* y (* 9.0 x)) (* a (* t (* z 4.0))))) (* z c))
     (/ (fma a (* t -4.0) (/ (+ b (* 9.0 (* y x))) z)) 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 tmp;
	if (z <= -6.985953318935387e-7) {
		tmp = 1.0 / (c / fma(a, (t * -4.0), (1.0 / (z / fma(9.0, (y * x), b)))));
	} else if (z <= 3.4192677792128576e-131) {
		tmp = (b + ((y * (9.0 * x)) - (a * (t * (z * 4.0))))) / (z * c);
	} else {
		tmp = fma(a, (t * -4.0), ((b + (9.0 * (y * x))) / z)) / 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

Original13.3
Target12.6
Herbie5.6
\[\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 3 regimes
  2. if z < -6.9859533189353873e-7

    1. Initial program 23.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. Simplified7.5

      \[\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 clear-num_binary647.6

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

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

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

    if -6.9859533189353873e-7 < z < 3.41926777921285757e-131

    1. Initial program 2.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 3.41926777921285757e-131 < z

    1. Initial program 17.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} \]
    2. Simplified7.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}} \]
    3. Taylor expanded in t around 0 11.2

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

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

      \[\leadsto \frac{\mathsf{fma}\left(a, t \cdot -4, \color{blue}{\frac{9 \cdot \left(y \cdot x\right) + b}{z}}\right)}{c} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification5.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -6.985953318935387 \cdot 10^{-7}:\\ \;\;\;\;\frac{1}{\frac{c}{\mathsf{fma}\left(a, t \cdot -4, \frac{1}{\frac{z}{\mathsf{fma}\left(9, y \cdot x, b\right)}}\right)}}\\ \mathbf{elif}\;z \leq 3.4192677792128576 \cdot 10^{-131}:\\ \;\;\;\;\frac{b + \left(y \cdot \left(9 \cdot x\right) - a \cdot \left(t \cdot \left(z \cdot 4\right)\right)\right)}{z \cdot c}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, t \cdot -4, \frac{b + 9 \cdot \left(y \cdot x\right)}{z}\right)}{c}\\ \end{array} \]

Reproduce

herbie shell --seed 2022088 
(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)))