Average Error: 20.4 → 4.5
Time: 9.3s
Precision: binary64
\[ \begin{array}{c}[x, y] = \mathsf{sort}([x, y])\\ [t, a] = \mathsf{sort}([t, a])\\ \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 := \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}\\ t_2 := \frac{y}{c} \cdot \frac{x}{z}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;\mathsf{fma}\left(9, t_2, \frac{\mathsf{fma}\left(a, t \cdot -4, \frac{b}{z}\right)}{c}\right)\\ \mathbf{elif}\;t_1 \leq -2 \cdot 10^{-18}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{-64}:\\ \;\;\;\;\frac{\mathsf{fma}\left(t, a \cdot -4, \frac{b + 9 \cdot \left(x \cdot y\right)}{z}\right)}{c}\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+269}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(9, t_2, \frac{b}{z \cdot c}\right) + -4 \cdot \left(t \cdot \frac{a}{c}\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 (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c)))
        (t_2 (* (/ y c) (/ x z))))
   (if (<= t_1 (- INFINITY))
     (fma 9.0 t_2 (/ (fma a (* t -4.0) (/ b z)) c))
     (if (<= t_1 -2e-18)
       t_1
       (if (<= t_1 2e-64)
         (/ (fma t (* a -4.0) (/ (+ b (* 9.0 (* x y))) z)) c)
         (if (<= t_1 2e+269)
           t_1
           (+ (fma 9.0 t_2 (/ b (* z c))) (* -4.0 (* t (/ a 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 = ((((x * 9.0) * y) - (((z * 4.0) * t) * a)) + b) / (z * c);
	double t_2 = (y / c) * (x / z);
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = fma(9.0, t_2, (fma(a, (t * -4.0), (b / z)) / c));
	} else if (t_1 <= -2e-18) {
		tmp = t_1;
	} else if (t_1 <= 2e-64) {
		tmp = fma(t, (a * -4.0), ((b + (9.0 * (x * y))) / z)) / c;
	} else if (t_1 <= 2e+269) {
		tmp = t_1;
	} else {
		tmp = fma(9.0, t_2, (b / (z * c))) + (-4.0 * (t * (a / c)));
	}
	return tmp;
}
function code(x, y, z, t, a, b, c)
	return Float64(Float64(Float64(Float64(Float64(x * 9.0) * y) - Float64(Float64(Float64(z * 4.0) * t) * a)) + b) / Float64(z * c))
end
function code(x, y, z, t, a, b, c)
	t_1 = Float64(Float64(Float64(Float64(Float64(x * 9.0) * y) - Float64(Float64(Float64(z * 4.0) * t) * a)) + b) / Float64(z * c))
	t_2 = Float64(Float64(y / c) * Float64(x / z))
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = fma(9.0, t_2, Float64(fma(a, Float64(t * -4.0), Float64(b / z)) / c));
	elseif (t_1 <= -2e-18)
		tmp = t_1;
	elseif (t_1 <= 2e-64)
		tmp = Float64(fma(t, Float64(a * -4.0), Float64(Float64(b + Float64(9.0 * Float64(x * y))) / z)) / c);
	elseif (t_1 <= 2e+269)
		tmp = t_1;
	else
		tmp = Float64(fma(9.0, t_2, Float64(b / Float64(z * c))) + Float64(-4.0 * Float64(t * Float64(a / c))));
	end
	return tmp
end
code[x_, y_, z_, t_, a_, b_, c_] := N[(N[(N[(N[(N[(x * 9.0), $MachinePrecision] * y), $MachinePrecision] - N[(N[(N[(z * 4.0), $MachinePrecision] * t), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision] / N[(z * c), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_, b_, c_] := Block[{t$95$1 = N[(N[(N[(N[(N[(x * 9.0), $MachinePrecision] * y), $MachinePrecision] - N[(N[(N[(z * 4.0), $MachinePrecision] * t), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision] / N[(z * c), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(y / c), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(9.0 * t$95$2 + N[(N[(a * N[(t * -4.0), $MachinePrecision] + N[(b / z), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, -2e-18], t$95$1, If[LessEqual[t$95$1, 2e-64], N[(N[(t * N[(a * -4.0), $MachinePrecision] + N[(N[(b + N[(9.0 * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[t$95$1, 2e+269], t$95$1, N[(N[(9.0 * t$95$2 + N[(b / N[(z * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-4.0 * N[(t * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]
\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 := \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}\\
t_2 := \frac{y}{c} \cdot \frac{x}{z}\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;\mathsf{fma}\left(9, t_2, \frac{\mathsf{fma}\left(a, t \cdot -4, \frac{b}{z}\right)}{c}\right)\\

\mathbf{elif}\;t_1 \leq -2 \cdot 10^{-18}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_1 \leq 2 \cdot 10^{-64}:\\
\;\;\;\;\frac{\mathsf{fma}\left(t, a \cdot -4, \frac{b + 9 \cdot \left(x \cdot y\right)}{z}\right)}{c}\\

\mathbf{elif}\;t_1 \leq 2 \cdot 10^{+269}:\\
\;\;\;\;t_1\\

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


\end{array}

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.4
Target14.5
Herbie4.5
\[\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. Simplified25.3

      \[\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 egg-rr25.3

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

      \[\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}} \]
    5. Simplified15.2

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

    if -inf.0 < (/.f64 (+.f64 (-.f64 (*.f64 (*.f64 x 9) y) (*.f64 (*.f64 (*.f64 z 4) t) a)) b) (*.f64 z c)) < -2.0000000000000001e-18 or 1.99999999999999993e-64 < (/.f64 (+.f64 (-.f64 (*.f64 (*.f64 x 9) y) (*.f64 (*.f64 (*.f64 z 4) t) a)) b) (*.f64 z c)) < 2.0000000000000001e269

    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 -2.0000000000000001e-18 < (/.f64 (+.f64 (-.f64 (*.f64 (*.f64 x 9) y) (*.f64 (*.f64 (*.f64 z 4) t) a)) b) (*.f64 z c)) < 1.99999999999999993e-64

    1. Initial program 15.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} \]
    2. Simplified0.9

      \[\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 z around 0 0.9

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

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

    1. Initial program 55.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.2

      \[\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 egg-rr26.2

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

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

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

    \[\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(9, \frac{y}{c} \cdot \frac{x}{z}, \frac{\mathsf{fma}\left(a, t \cdot -4, \frac{b}{z}\right)}{c}\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 -2 \cdot 10^{-18}:\\ \;\;\;\;\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 2 \cdot 10^{-64}:\\ \;\;\;\;\frac{\mathsf{fma}\left(t, a \cdot -4, \frac{b + 9 \cdot \left(x \cdot y\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 2 \cdot 10^{+269}:\\ \;\;\;\;\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(9, \frac{y}{c} \cdot \frac{x}{z}, \frac{b}{z \cdot c}\right) + -4 \cdot \left(t \cdot \frac{a}{c}\right)\\ \end{array} \]

Reproduce

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