Average Error: 19.9 → 7.7
Time: 7.5s
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 := 9 \cdot \left(x \cdot y\right)\\ t_2 := \frac{b}{z \cdot c}\\ t_3 := \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_4 := \left(t_2 + 9 \cdot \frac{x \cdot y}{z \cdot c}\right) + \frac{a}{\frac{c}{t}} \cdot -4\\ \mathbf{if}\;t_3 \leq -5 \cdot 10^{+194}:\\ \;\;\;\;\left(t_2 + x \cdot \left(y \cdot \frac{9}{z \cdot c}\right)\right) + \frac{t \cdot a}{c} \cdot -4\\ \mathbf{elif}\;t_3 \leq -4 \cdot 10^{+58}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;t_3 \leq -1 \cdot 10^{+31}:\\ \;\;\;\;\left(t_2 + \frac{\frac{t_1}{c}}{z}\right) + \left(t \cdot \frac{a}{c}\right) \cdot -4\\ \mathbf{elif}\;t_3 \leq 0:\\ \;\;\;\;\frac{\mathsf{fma}\left(t, a \cdot -4, \frac{b + t_1}{z}\right)}{c}\\ \mathbf{else}:\\ \;\;\;\;t_4\\ \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 (* 9.0 (* x y)))
        (t_2 (/ b (* z c)))
        (t_3 (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c)))
        (t_4 (+ (+ t_2 (* 9.0 (/ (* x y) (* z c)))) (* (/ a (/ c t)) -4.0))))
   (if (<= t_3 -5e+194)
     (+ (+ t_2 (* x (* y (/ 9.0 (* z c))))) (* (/ (* t a) c) -4.0))
     (if (<= t_3 -4e+58)
       t_4
       (if (<= t_3 -1e+31)
         (+ (+ t_2 (/ (/ t_1 c) z)) (* (* t (/ a c)) -4.0))
         (if (<= t_3 0.0) (/ (fma t (* a -4.0) (/ (+ b t_1) z)) c) t_4))))))
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 = 9.0 * (x * y);
	double t_2 = b / (z * c);
	double t_3 = ((((x * 9.0) * y) - (((z * 4.0) * t) * a)) + b) / (z * c);
	double t_4 = (t_2 + (9.0 * ((x * y) / (z * c)))) + ((a / (c / t)) * -4.0);
	double tmp;
	if (t_3 <= -5e+194) {
		tmp = (t_2 + (x * (y * (9.0 / (z * c))))) + (((t * a) / c) * -4.0);
	} else if (t_3 <= -4e+58) {
		tmp = t_4;
	} else if (t_3 <= -1e+31) {
		tmp = (t_2 + ((t_1 / c) / z)) + ((t * (a / c)) * -4.0);
	} else if (t_3 <= 0.0) {
		tmp = fma(t, (a * -4.0), ((b + t_1) / z)) / c;
	} else {
		tmp = t_4;
	}
	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(9.0 * Float64(x * y))
	t_2 = Float64(b / Float64(z * c))
	t_3 = Float64(Float64(Float64(Float64(Float64(x * 9.0) * y) - Float64(Float64(Float64(z * 4.0) * t) * a)) + b) / Float64(z * c))
	t_4 = Float64(Float64(t_2 + Float64(9.0 * Float64(Float64(x * y) / Float64(z * c)))) + Float64(Float64(a / Float64(c / t)) * -4.0))
	tmp = 0.0
	if (t_3 <= -5e+194)
		tmp = Float64(Float64(t_2 + Float64(x * Float64(y * Float64(9.0 / Float64(z * c))))) + Float64(Float64(Float64(t * a) / c) * -4.0));
	elseif (t_3 <= -4e+58)
		tmp = t_4;
	elseif (t_3 <= -1e+31)
		tmp = Float64(Float64(t_2 + Float64(Float64(t_1 / c) / z)) + Float64(Float64(t * Float64(a / c)) * -4.0));
	elseif (t_3 <= 0.0)
		tmp = Float64(fma(t, Float64(a * -4.0), Float64(Float64(b + t_1) / z)) / c);
	else
		tmp = t_4;
	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[(9.0 * N[(x * y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(b / N[(z * c), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = 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$4 = N[(N[(t$95$2 + N[(9.0 * N[(N[(x * y), $MachinePrecision] / N[(z * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(a / N[(c / t), $MachinePrecision]), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$3, -5e+194], N[(N[(t$95$2 + N[(x * N[(y * N[(9.0 / N[(z * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(t * a), $MachinePrecision] / c), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, -4e+58], t$95$4, If[LessEqual[t$95$3, -1e+31], N[(N[(t$95$2 + N[(N[(t$95$1 / c), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision] + N[(N[(t * N[(a / c), $MachinePrecision]), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 0.0], N[(N[(t * N[(a * -4.0), $MachinePrecision] + N[(N[(b + t$95$1), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$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}
\begin{array}{l}
t_1 := 9 \cdot \left(x \cdot y\right)\\
t_2 := \frac{b}{z \cdot c}\\
t_3 := \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_4 := \left(t_2 + 9 \cdot \frac{x \cdot y}{z \cdot c}\right) + \frac{a}{\frac{c}{t}} \cdot -4\\
\mathbf{if}\;t_3 \leq -5 \cdot 10^{+194}:\\
\;\;\;\;\left(t_2 + x \cdot \left(y \cdot \frac{9}{z \cdot c}\right)\right) + \frac{t \cdot a}{c} \cdot -4\\

\mathbf{elif}\;t_3 \leq -4 \cdot 10^{+58}:\\
\;\;\;\;t_4\\

\mathbf{elif}\;t_3 \leq -1 \cdot 10^{+31}:\\
\;\;\;\;\left(t_2 + \frac{\frac{t_1}{c}}{z}\right) + \left(t \cdot \frac{a}{c}\right) \cdot -4\\

\mathbf{elif}\;t_3 \leq 0:\\
\;\;\;\;\frac{\mathsf{fma}\left(t, a \cdot -4, \frac{b + t_1}{z}\right)}{c}\\

\mathbf{else}:\\
\;\;\;\;t_4\\


\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

Original19.9
Target14.0
Herbie7.7
\[\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)) < -4.99999999999999989e194

    1. Initial program 31.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} \]
    2. Simplified22.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 t around 0 16.7

      \[\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. Applied egg-rr21.1

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

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

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

    if -4.99999999999999989e194 < (/.f64 (+.f64 (-.f64 (*.f64 (*.f64 x 9) y) (*.f64 (*.f64 (*.f64 z 4) t) a)) b) (*.f64 z c)) < -3.99999999999999978e58 or 0.0 < (/.f64 (+.f64 (-.f64 (*.f64 (*.f64 x 9) y) (*.f64 (*.f64 (*.f64 z 4) t) a)) b) (*.f64 z c))

    1. Initial program 18.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} \]
    2. Simplified15.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. Taylor expanded in t around 0 10.8

      \[\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. Applied egg-rr8.9

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

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

    if -3.99999999999999978e58 < (/.f64 (+.f64 (-.f64 (*.f64 (*.f64 x 9) y) (*.f64 (*.f64 (*.f64 z 4) t) a)) b) (*.f64 z c)) < -9.9999999999999996e30

    1. Initial program 0.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. Simplified6.4

      \[\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 0.8

      \[\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. Applied egg-rr1.7

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

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

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

    1. Initial program 16.3

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

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

    \[\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 -5 \cdot 10^{+194}:\\ \;\;\;\;\left(\frac{b}{z \cdot c} + x \cdot \left(y \cdot \frac{9}{z \cdot c}\right)\right) + \frac{t \cdot a}{c} \cdot -4\\ \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 -4 \cdot 10^{+58}:\\ \;\;\;\;\left(\frac{b}{z \cdot c} + 9 \cdot \frac{x \cdot y}{z \cdot c}\right) + \frac{a}{\frac{c}{t}} \cdot -4\\ \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 \cdot 10^{+31}:\\ \;\;\;\;\left(\frac{b}{z \cdot c} + \frac{\frac{9 \cdot \left(x \cdot y\right)}{c}}{z}\right) + \left(t \cdot \frac{a}{c}\right) \cdot -4\\ \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{b + 9 \cdot \left(x \cdot y\right)}{z}\right)}{c}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{b}{z \cdot c} + 9 \cdot \frac{x \cdot y}{z \cdot c}\right) + \frac{a}{\frac{c}{t}} \cdot -4\\ \end{array} \]

Reproduce

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