Average Error: 7.5 → 6.6
Time: 12.0s
Precision: binary64
\[[x, y] = \mathsf{sort}([x, y]) \[z, t] = \mathsf{sort}([z, t]) \\]
\[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \]
\[\begin{array}{l} t_1 := 0.5 \cdot \frac{y \cdot x}{a}\\ t_2 := t_1 - 4.5 \cdot \left(z \cdot \frac{t}{a}\right)\\ t_3 := 0.5 \cdot \left(y \cdot \frac{x}{a}\right) - 4.5 \cdot \frac{z \cdot t}{a}\\ \mathbf{if}\;z \cdot 9 \leq -5.431548242204504 \cdot 10^{+204}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \cdot 9 \leq -8.016112209692877 \cdot 10^{+153}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \cdot 9 \leq -2.420614830843783 \cdot 10^{-19}:\\ \;\;\;\;t_1 - \frac{4.5 \cdot t}{\frac{a}{z}}\\ \mathbf{elif}\;z \cdot 9 \leq -1.06181703990814 \cdot 10^{-229}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \cdot 9 \leq 1.0299690472364976 \cdot 10^{-170}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y, 0.5 \cdot x, \left(z \cdot t\right) \cdot -4.5\right)}{a}\\ \mathbf{elif}\;z \cdot 9 \leq 2.9959683726465978 \cdot 10^{+82}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\begin{array}{l}
t_1 := 0.5 \cdot \frac{y \cdot x}{a}\\
t_2 := t_1 - 4.5 \cdot \left(z \cdot \frac{t}{a}\right)\\
t_3 := 0.5 \cdot \left(y \cdot \frac{x}{a}\right) - 4.5 \cdot \frac{z \cdot t}{a}\\
\mathbf{if}\;z \cdot 9 \leq -5.431548242204504 \cdot 10^{+204}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;z \cdot 9 \leq -8.016112209692877 \cdot 10^{+153}:\\
\;\;\;\;t_3\\

\mathbf{elif}\;z \cdot 9 \leq -2.420614830843783 \cdot 10^{-19}:\\
\;\;\;\;t_1 - \frac{4.5 \cdot t}{\frac{a}{z}}\\

\mathbf{elif}\;z \cdot 9 \leq -1.06181703990814 \cdot 10^{-229}:\\
\;\;\;\;t_3\\

\mathbf{elif}\;z \cdot 9 \leq 1.0299690472364976 \cdot 10^{-170}:\\
\;\;\;\;\frac{\mathsf{fma}\left(y, 0.5 \cdot x, \left(z \cdot t\right) \cdot -4.5\right)}{a}\\

\mathbf{elif}\;z \cdot 9 \leq 2.9959683726465978 \cdot 10^{+82}:\\
\;\;\;\;t_3\\

\mathbf{else}:\\
\;\;\;\;t_2\\


\end{array}
(FPCore (x y z t a)
 :precision binary64
 (/ (- (* x y) (* (* z 9.0) t)) (* a 2.0)))
(FPCore (x y z t a)
 :precision binary64
 (let* ((t_1 (* 0.5 (/ (* y x) a)))
        (t_2 (- t_1 (* 4.5 (* z (/ t a)))))
        (t_3 (- (* 0.5 (* y (/ x a))) (* 4.5 (/ (* z t) a)))))
   (if (<= (* z 9.0) -5.431548242204504e+204)
     t_2
     (if (<= (* z 9.0) -8.016112209692877e+153)
       t_3
       (if (<= (* z 9.0) -2.420614830843783e-19)
         (- t_1 (/ (* 4.5 t) (/ a z)))
         (if (<= (* z 9.0) -1.06181703990814e-229)
           t_3
           (if (<= (* z 9.0) 1.0299690472364976e-170)
             (/ (fma y (* 0.5 x) (* (* z t) -4.5)) a)
             (if (<= (* z 9.0) 2.9959683726465978e+82) t_3 t_2))))))))
double code(double x, double y, double z, double t, double a) {
	return ((x * y) - ((z * 9.0) * t)) / (a * 2.0);
}
double code(double x, double y, double z, double t, double a) {
	double t_1 = 0.5 * ((y * x) / a);
	double t_2 = t_1 - (4.5 * (z * (t / a)));
	double t_3 = (0.5 * (y * (x / a))) - (4.5 * ((z * t) / a));
	double tmp;
	if ((z * 9.0) <= -5.431548242204504e+204) {
		tmp = t_2;
	} else if ((z * 9.0) <= -8.016112209692877e+153) {
		tmp = t_3;
	} else if ((z * 9.0) <= -2.420614830843783e-19) {
		tmp = t_1 - ((4.5 * t) / (a / z));
	} else if ((z * 9.0) <= -1.06181703990814e-229) {
		tmp = t_3;
	} else if ((z * 9.0) <= 1.0299690472364976e-170) {
		tmp = fma(y, (0.5 * x), ((z * t) * -4.5)) / a;
	} else if ((z * 9.0) <= 2.9959683726465978e+82) {
		tmp = t_3;
	} else {
		tmp = t_2;
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Bits error versus a

Target

Original7.5
Target5.7
Herbie6.6
\[\begin{array}{l} \mathbf{if}\;a < -2.090464557976709 \cdot 10^{+86}:\\ \;\;\;\;0.5 \cdot \frac{y \cdot x}{a} - 4.5 \cdot \frac{t}{\frac{a}{z}}\\ \mathbf{elif}\;a < 2.144030707833976 \cdot 10^{+99}:\\ \;\;\;\;\frac{x \cdot y - z \cdot \left(9 \cdot t\right)}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a} \cdot \left(x \cdot 0.5\right) - \frac{t}{a} \cdot \left(z \cdot 4.5\right)\\ \end{array} \]

Derivation

  1. Split input into 4 regimes
  2. if (*.f64 z 9) < -5.4315482422045038e204 or 2.9959683726465978e82 < (*.f64 z 9)

    1. Initial program 19.2

      \[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \]
    2. Simplified18.9

      \[\leadsto \color{blue}{\mathsf{fma}\left(-9, z \cdot t, x \cdot y\right) \cdot \frac{0.5}{a}} \]
    3. Taylor expanded in z around 0 18.8

      \[\leadsto \color{blue}{0.5 \cdot \frac{y \cdot x}{a} - 4.5 \cdot \frac{t \cdot z}{a}} \]
    4. Applied egg-rr11.2

      \[\leadsto 0.5 \cdot \frac{y \cdot x}{a} - 4.5 \cdot \color{blue}{\left(\frac{t}{a} \cdot z\right)} \]

    if -5.4315482422045038e204 < (*.f64 z 9) < -8.0161122096928771e153 or -2.42061483084378297e-19 < (*.f64 z 9) < -1.06181703990814e-229 or 1.02996904723649759e-170 < (*.f64 z 9) < 2.9959683726465978e82

    1. Initial program 5.9

      \[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \]
    2. Simplified6.0

      \[\leadsto \color{blue}{\mathsf{fma}\left(-9, z \cdot t, x \cdot y\right) \cdot \frac{0.5}{a}} \]
    3. Taylor expanded in z around 0 5.9

      \[\leadsto \color{blue}{0.5 \cdot \frac{y \cdot x}{a} - 4.5 \cdot \frac{t \cdot z}{a}} \]
    4. Applied egg-rr6.3

      \[\leadsto 0.5 \cdot \color{blue}{\left(\frac{y}{1} \cdot \frac{x}{a}\right)} - 4.5 \cdot \frac{t \cdot z}{a} \]

    if -8.0161122096928771e153 < (*.f64 z 9) < -2.42061483084378297e-19

    1. Initial program 5.6

      \[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \]
    2. Simplified5.6

      \[\leadsto \color{blue}{\mathsf{fma}\left(-9, z \cdot t, x \cdot y\right) \cdot \frac{0.5}{a}} \]
    3. Taylor expanded in z around 0 5.5

      \[\leadsto \color{blue}{0.5 \cdot \frac{y \cdot x}{a} - 4.5 \cdot \frac{t \cdot z}{a}} \]
    4. Applied egg-rr5.8

      \[\leadsto 0.5 \cdot \frac{y \cdot x}{a} - \color{blue}{\frac{t \cdot 4.5}{\frac{a}{z}}} \]

    if -1.06181703990814e-229 < (*.f64 z 9) < 1.02996904723649759e-170

    1. Initial program 4.7

      \[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \]
    2. Simplified4.7

      \[\leadsto \color{blue}{\mathsf{fma}\left(-9, z \cdot t, x \cdot y\right) \cdot \frac{0.5}{a}} \]
    3. Taylor expanded in z around 0 4.7

      \[\leadsto \color{blue}{0.5 \cdot \frac{y \cdot x}{a} - 4.5 \cdot \frac{t \cdot z}{a}} \]
    4. Applied egg-rr4.7

      \[\leadsto \color{blue}{\frac{\left(y \cdot x\right) \cdot 0.5 - \left(t \cdot z\right) \cdot 4.5}{a}} \]
    5. Applied egg-rr4.7

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \cdot 9 \leq -5.431548242204504 \cdot 10^{+204}:\\ \;\;\;\;0.5 \cdot \frac{y \cdot x}{a} - 4.5 \cdot \left(z \cdot \frac{t}{a}\right)\\ \mathbf{elif}\;z \cdot 9 \leq -8.016112209692877 \cdot 10^{+153}:\\ \;\;\;\;0.5 \cdot \left(y \cdot \frac{x}{a}\right) - 4.5 \cdot \frac{z \cdot t}{a}\\ \mathbf{elif}\;z \cdot 9 \leq -2.420614830843783 \cdot 10^{-19}:\\ \;\;\;\;0.5 \cdot \frac{y \cdot x}{a} - \frac{4.5 \cdot t}{\frac{a}{z}}\\ \mathbf{elif}\;z \cdot 9 \leq -1.06181703990814 \cdot 10^{-229}:\\ \;\;\;\;0.5 \cdot \left(y \cdot \frac{x}{a}\right) - 4.5 \cdot \frac{z \cdot t}{a}\\ \mathbf{elif}\;z \cdot 9 \leq 1.0299690472364976 \cdot 10^{-170}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y, 0.5 \cdot x, \left(z \cdot t\right) \cdot -4.5\right)}{a}\\ \mathbf{elif}\;z \cdot 9 \leq 2.9959683726465978 \cdot 10^{+82}:\\ \;\;\;\;0.5 \cdot \left(y \cdot \frac{x}{a}\right) - 4.5 \cdot \frac{z \cdot t}{a}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{y \cdot x}{a} - 4.5 \cdot \left(z \cdot \frac{t}{a}\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2022130 
(FPCore (x y z t a)
  :name "Diagrams.Solve.Polynomial:cubForm  from diagrams-solve-0.1, I"
  :precision binary64

  :herbie-target
  (if (< a -2.090464557976709e+86) (- (* 0.5 (/ (* y x) a)) (* 4.5 (/ t (/ a z)))) (if (< a 2.144030707833976e+99) (/ (- (* x y) (* z (* 9.0 t))) (* a 2.0)) (- (* (/ y a) (* x 0.5)) (* (/ t a) (* z 4.5)))))

  (/ (- (* x y) (* (* z 9.0) t)) (* a 2.0)))