Average Error: 20.0 → 6.0
Time: 12.5s
Precision: binary64
\[[x, y] = \mathsf{sort}([x, y]) \\]
\[\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 := 4 \cdot \left(a \cdot t\right)\\ \mathbf{if}\;z \leq -13120955.299355708:\\ \;\;\;\;\frac{\mathsf{fma}\left(9, y \cdot \frac{x}{z}, \frac{b}{z}\right) - t_1}{c}\\ \mathbf{elif}\;z \leq 4.429411479627045 \cdot 10^{-26}:\\ \;\;\;\;\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(9, \frac{y}{\frac{z}{x}}, \frac{b}{z}\right) - t_1}{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}
t_1 := 4 \cdot \left(a \cdot t\right)\\
\mathbf{if}\;z \leq -13120955.299355708:\\
\;\;\;\;\frac{\mathsf{fma}\left(9, y \cdot \frac{x}{z}, \frac{b}{z}\right) - t_1}{c}\\

\mathbf{elif}\;z \leq 4.429411479627045 \cdot 10^{-26}:\\
\;\;\;\;\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(9, \frac{y}{\frac{z}{x}}, \frac{b}{z}\right) - t_1}{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
 (let* ((t_1 (* 4.0 (* a t))))
   (if (<= z -13120955.299355708)
     (/ (- (fma 9.0 (* y (/ x z)) (/ b z)) t_1) c)
     (if (<= z 4.429411479627045e-26)
       (/ (+ b (- (* y (* 9.0 x)) (* a (* t (* z 4.0))))) (* z c))
       (/ (- (fma 9.0 (/ y (/ z x)) (/ b z)) t_1) 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 = 4.0 * (a * t);
	double tmp;
	if (z <= -13120955.299355708) {
		tmp = (fma(9.0, (y * (x / z)), (b / z)) - t_1) / c;
	} else if (z <= 4.429411479627045e-26) {
		tmp = (b + ((y * (9.0 * x)) - (a * (t * (z * 4.0))))) / (z * c);
	} else {
		tmp = (fma(9.0, (y / (z / x)), (b / z)) - t_1) / 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.0
Target14.2
Herbie6.0
\[\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 < -13120955.299355708

    1. Initial program 29.8

      \[\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. Simplified8.7

      \[\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_binary648.9

      \[\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. Taylor expanded in c around 0 8.5

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(9, \frac{y \cdot x}{z}, \frac{b}{z}\right) - 4 \cdot \left(a \cdot t\right)}{c}} \]
    6. Applied *-un-lft-identity_binary648.5

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

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

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

    if -13120955.299355708 < z < 4.42941147962704476e-26

    1. Initial program 6.5

      \[\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 4.42941147962704476e-26 < z

    1. Initial program 26.9

      \[\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. Simplified8.7

      \[\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_binary649.0

      \[\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. Taylor expanded in c around 0 8.5

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -13120955.299355708:\\ \;\;\;\;\frac{\mathsf{fma}\left(9, y \cdot \frac{x}{z}, \frac{b}{z}\right) - 4 \cdot \left(a \cdot t\right)}{c}\\ \mathbf{elif}\;z \leq 4.429411479627045 \cdot 10^{-26}:\\ \;\;\;\;\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(9, \frac{y}{\frac{z}{x}}, \frac{b}{z}\right) - 4 \cdot \left(a \cdot t\right)}{c}\\ \end{array} \]

Reproduce

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