Average Error: 20.8 → 4.5
Time: 7.6s
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 := \mathsf{fma}\left(-4, \frac{a}{\frac{c}{t}}, \frac{b}{z \cdot c}\right)\\ \mathbf{if}\;t_1 \leq -1 \cdot 10^{+87}:\\ \;\;\;\;\mathsf{fma}\left(9, x \cdot \frac{y}{z \cdot c}, t_2\right)\\ \mathbf{elif}\;t_1 \leq 4 \cdot 10^{-294}:\\ \;\;\;\;\frac{\mathsf{fma}\left(t, a \cdot -4, \frac{b}{z} + 9 \cdot \frac{x \cdot y}{z}\right)}{c}\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+307}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(9, \frac{y}{c \cdot \frac{z}{x}}, t_2\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 (fma -4.0 (/ a (/ c t)) (/ b (* z c)))))
   (if (<= t_1 -1e+87)
     (fma 9.0 (* x (/ y (* z c))) t_2)
     (if (<= t_1 4e-294)
       (/ (fma t (* a -4.0) (+ (/ b z) (* 9.0 (/ (* x y) z)))) c)
       (if (<= t_1 2e+307) t_1 (fma 9.0 (/ y (* c (/ z x))) t_2))))))
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 = fma(-4.0, (a / (c / t)), (b / (z * c)));
	double tmp;
	if (t_1 <= -1e+87) {
		tmp = fma(9.0, (x * (y / (z * c))), t_2);
	} else if (t_1 <= 4e-294) {
		tmp = fma(t, (a * -4.0), ((b / z) + (9.0 * ((x * y) / z)))) / c;
	} else if (t_1 <= 2e+307) {
		tmp = t_1;
	} else {
		tmp = fma(9.0, (y / (c * (z / x))), t_2);
	}
	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 = fma(-4.0, Float64(a / Float64(c / t)), Float64(b / Float64(z * c)))
	tmp = 0.0
	if (t_1 <= -1e+87)
		tmp = fma(9.0, Float64(x * Float64(y / Float64(z * c))), t_2);
	elseif (t_1 <= 4e-294)
		tmp = Float64(fma(t, Float64(a * -4.0), Float64(Float64(b / z) + Float64(9.0 * Float64(Float64(x * y) / z)))) / c);
	elseif (t_1 <= 2e+307)
		tmp = t_1;
	else
		tmp = fma(9.0, Float64(y / Float64(c * Float64(z / x))), t_2);
	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[(-4.0 * N[(a / N[(c / t), $MachinePrecision]), $MachinePrecision] + N[(b / N[(z * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -1e+87], N[(9.0 * N[(x * N[(y / N[(z * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$2), $MachinePrecision], If[LessEqual[t$95$1, 4e-294], N[(N[(t * N[(a * -4.0), $MachinePrecision] + N[(N[(b / z), $MachinePrecision] + N[(9.0 * N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[t$95$1, 2e+307], t$95$1, N[(9.0 * N[(y / N[(c * N[(z / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$2), $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 := \mathsf{fma}\left(-4, \frac{a}{\frac{c}{t}}, \frac{b}{z \cdot c}\right)\\
\mathbf{if}\;t_1 \leq -1 \cdot 10^{+87}:\\
\;\;\;\;\mathsf{fma}\left(9, x \cdot \frac{y}{z \cdot c}, t_2\right)\\

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

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

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(9, \frac{y}{c \cdot \frac{z}{x}}, t_2\right)\\


\end{array}

Error

Target

Original20.8
Target14.4
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)) < -9.9999999999999996e86

    1. Initial program 19.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. Simplified19.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. Taylor expanded in t around 0 11.9

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

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

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

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

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

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

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

    if -9.9999999999999996e86 < (/.f64 (+.f64 (-.f64 (*.f64 (*.f64 x 9) y) (*.f64 (*.f64 (*.f64 z 4) t) a)) b) (*.f64 z c)) < 4.00000000000000007e-294

    1. Initial program 15.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. Simplified1.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. Taylor expanded in x around 0 1.4

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

    if 4.00000000000000007e-294 < (/.f64 (+.f64 (-.f64 (*.f64 (*.f64 x 9) y) (*.f64 (*.f64 (*.f64 z 4) t) a)) b) (*.f64 z c)) < 1.99999999999999997e307

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

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

    1. Initial program 63.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. Simplified26.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 30.0

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(9, \frac{y}{\color{blue}{c \cdot \frac{z}{x}}}, \mathsf{fma}\left(-4, \frac{a}{\frac{c}{t}}, \frac{b}{z \cdot c}\right)\right) \]
  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 -1 \cdot 10^{+87}:\\ \;\;\;\;\mathsf{fma}\left(9, x \cdot \frac{y}{z \cdot c}, \mathsf{fma}\left(-4, \frac{a}{\frac{c}{t}}, \frac{b}{z \cdot c}\right)\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 4 \cdot 10^{-294}:\\ \;\;\;\;\frac{\mathsf{fma}\left(t, a \cdot -4, \frac{b}{z} + 9 \cdot \frac{x \cdot y}{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^{+307}:\\ \;\;\;\;\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{z}{x}}, \mathsf{fma}\left(-4, \frac{a}{\frac{c}{t}}, \frac{b}{z \cdot c}\right)\right)\\ \end{array} \]

Reproduce

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