Average Error: 20.7 → 6.4
Time: 8.1s
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 := \mathsf{fma}\left(9, \frac{y}{z} \cdot \frac{x}{c}, \mathsf{fma}\left(-4, t \cdot \frac{a}{c}, \frac{b}{z \cdot c}\right)\right)\\ t_2 := \frac{\mathsf{fma}\left(t, a \cdot -4, \mathsf{fma}\left(9, y \cdot \frac{x}{z}, \frac{b}{z}\right)\right)}{c}\\ \mathbf{if}\;z \leq -1 \cdot 10^{+15}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 10^{-30}:\\ \;\;\;\;\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{elif}\;z \leq 2.6075979314814033 \cdot 10^{+121}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 5.1232316717931374 \cdot 10^{+287}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \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 9.0 (* (/ y z) (/ x c)) (fma -4.0 (* t (/ a c)) (/ b (* z c)))))
        (t_2 (/ (fma t (* a -4.0) (fma 9.0 (* y (/ x z)) (/ b z))) c)))
   (if (<= z -1e+15)
     t_2
     (if (<= z 1e-30)
       (/ (+ b (- (* y (* 9.0 x)) (* a (* t (* z 4.0))))) (* z c))
       (if (<= z 2.6075979314814033e+121)
         t_1
         (if (<= z 5.1232316717931374e+287) t_2 t_1))))))
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(9.0, ((y / z) * (x / c)), fma(-4.0, (t * (a / c)), (b / (z * c))));
	double t_2 = fma(t, (a * -4.0), fma(9.0, (y * (x / z)), (b / z))) / c;
	double tmp;
	if (z <= -1e+15) {
		tmp = t_2;
	} else if (z <= 1e-30) {
		tmp = (b + ((y * (9.0 * x)) - (a * (t * (z * 4.0))))) / (z * c);
	} else if (z <= 2.6075979314814033e+121) {
		tmp = t_1;
	} else if (z <= 5.1232316717931374e+287) {
		tmp = t_2;
	} else {
		tmp = t_1;
	}
	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 = fma(9.0, Float64(Float64(y / z) * Float64(x / c)), fma(-4.0, Float64(t * Float64(a / c)), Float64(b / Float64(z * c))))
	t_2 = Float64(fma(t, Float64(a * -4.0), fma(9.0, Float64(y * Float64(x / z)), Float64(b / z))) / c)
	tmp = 0.0
	if (z <= -1e+15)
		tmp = t_2;
	elseif (z <= 1e-30)
		tmp = Float64(Float64(b + Float64(Float64(y * Float64(9.0 * x)) - Float64(a * Float64(t * Float64(z * 4.0))))) / Float64(z * c));
	elseif (z <= 2.6075979314814033e+121)
		tmp = t_1;
	elseif (z <= 5.1232316717931374e+287)
		tmp = t_2;
	else
		tmp = t_1;
	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[(N[(y / z), $MachinePrecision] * N[(x / c), $MachinePrecision]), $MachinePrecision] + N[(-4.0 * N[(t * N[(a / c), $MachinePrecision]), $MachinePrecision] + N[(b / N[(z * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(t * N[(a * -4.0), $MachinePrecision] + N[(9.0 * N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision] + N[(b / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[z, -1e+15], t$95$2, If[LessEqual[z, 1e-30], N[(N[(b + N[(N[(y * N[(9.0 * x), $MachinePrecision]), $MachinePrecision] - N[(a * N[(t * N[(z * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(z * c), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2.6075979314814033e+121], t$95$1, If[LessEqual[z, 5.1232316717931374e+287], t$95$2, t$95$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}
\begin{array}{l}
t_1 := \mathsf{fma}\left(9, \frac{y}{z} \cdot \frac{x}{c}, \mathsf{fma}\left(-4, t \cdot \frac{a}{c}, \frac{b}{z \cdot c}\right)\right)\\
t_2 := \frac{\mathsf{fma}\left(t, a \cdot -4, \mathsf{fma}\left(9, y \cdot \frac{x}{z}, \frac{b}{z}\right)\right)}{c}\\
\mathbf{if}\;z \leq -1 \cdot 10^{+15}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;z \leq 10^{-30}:\\
\;\;\;\;\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{elif}\;z \leq 2.6075979314814033 \cdot 10^{+121}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;z \leq 5.1232316717931374 \cdot 10^{+287}:\\
\;\;\;\;t_2\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error

Target

Original20.7
Target14.5
Herbie6.4
\[\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 < -1e15 or 2.6075979314814033e121 < z < 5.1232316717931374e287

    1. Initial program 32.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. Simplified9.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 x around 0 9.6

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

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

    if -1e15 < z < 1e-30

    1. Initial program 6.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} \]

    if 1e-30 < z < 2.6075979314814033e121 or 5.1232316717931374e287 < z

    1. Initial program 21.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. Simplified9.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 11.8

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1 \cdot 10^{+15}:\\ \;\;\;\;\frac{\mathsf{fma}\left(t, a \cdot -4, \mathsf{fma}\left(9, y \cdot \frac{x}{z}, \frac{b}{z}\right)\right)}{c}\\ \mathbf{elif}\;z \leq 10^{-30}:\\ \;\;\;\;\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{elif}\;z \leq 2.6075979314814033 \cdot 10^{+121}:\\ \;\;\;\;\mathsf{fma}\left(9, \frac{y}{z} \cdot \frac{x}{c}, \mathsf{fma}\left(-4, t \cdot \frac{a}{c}, \frac{b}{z \cdot c}\right)\right)\\ \mathbf{elif}\;z \leq 5.1232316717931374 \cdot 10^{+287}:\\ \;\;\;\;\frac{\mathsf{fma}\left(t, a \cdot -4, \mathsf{fma}\left(9, y \cdot \frac{x}{z}, \frac{b}{z}\right)\right)}{c}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(9, \frac{y}{z} \cdot \frac{x}{c}, \mathsf{fma}\left(-4, t \cdot \frac{a}{c}, \frac{b}{z \cdot c}\right)\right)\\ \end{array} \]

Reproduce

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