?

Average Error: 7.8 → 0.9
Time: 16.4s
Precision: binary64
Cost: 8520

?

\[ \begin{array}{c}[x, y] = \mathsf{sort}([x, y])\\ [z, t] = \mathsf{sort}([z, t])\\ \end{array} \]
\[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \]
\[\begin{array}{l} t_1 := x \cdot y - \left(z \cdot 9\right) \cdot t\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{+239}:\\ \;\;\;\;\frac{y \cdot 0.5}{\frac{a}{x}} - \frac{z \cdot 4.5}{\frac{a}{t}}\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+288}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, y, z \cdot \left(t \cdot -9\right)\right)}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-4.5, \frac{t}{\frac{a}{z}}, 0.5 \cdot \frac{y}{\frac{a}{x}}\right)\\ \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 (- (* x y) (* (* z 9.0) t))))
   (if (<= t_1 -2e+239)
     (- (/ (* y 0.5) (/ a x)) (/ (* z 4.5) (/ a t)))
     (if (<= t_1 2e+288)
       (/ (fma x y (* z (* t -9.0))) (* a 2.0))
       (fma -4.5 (/ t (/ a z)) (* 0.5 (/ y (/ a x))))))))
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 = (x * y) - ((z * 9.0) * t);
	double tmp;
	if (t_1 <= -2e+239) {
		tmp = ((y * 0.5) / (a / x)) - ((z * 4.5) / (a / t));
	} else if (t_1 <= 2e+288) {
		tmp = fma(x, y, (z * (t * -9.0))) / (a * 2.0);
	} else {
		tmp = fma(-4.5, (t / (a / z)), (0.5 * (y / (a / x))));
	}
	return tmp;
}
function code(x, y, z, t, a)
	return Float64(Float64(Float64(x * y) - Float64(Float64(z * 9.0) * t)) / Float64(a * 2.0))
end
function code(x, y, z, t, a)
	t_1 = Float64(Float64(x * y) - Float64(Float64(z * 9.0) * t))
	tmp = 0.0
	if (t_1 <= -2e+239)
		tmp = Float64(Float64(Float64(y * 0.5) / Float64(a / x)) - Float64(Float64(z * 4.5) / Float64(a / t)));
	elseif (t_1 <= 2e+288)
		tmp = Float64(fma(x, y, Float64(z * Float64(t * -9.0))) / Float64(a * 2.0));
	else
		tmp = fma(-4.5, Float64(t / Float64(a / z)), Float64(0.5 * Float64(y / Float64(a / x))));
	end
	return tmp
end
code[x_, y_, z_, t_, a_] := N[(N[(N[(x * y), $MachinePrecision] - N[(N[(z * 9.0), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(x * y), $MachinePrecision] - N[(N[(z * 9.0), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -2e+239], N[(N[(N[(y * 0.5), $MachinePrecision] / N[(a / x), $MachinePrecision]), $MachinePrecision] - N[(N[(z * 4.5), $MachinePrecision] / N[(a / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2e+288], N[(N[(x * y + N[(z * N[(t * -9.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(-4.5 * N[(t / N[(a / z), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(y / N[(a / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\begin{array}{l}
t_1 := x \cdot y - \left(z \cdot 9\right) \cdot t\\
\mathbf{if}\;t_1 \leq -2 \cdot 10^{+239}:\\
\;\;\;\;\frac{y \cdot 0.5}{\frac{a}{x}} - \frac{z \cdot 4.5}{\frac{a}{t}}\\

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

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-4.5, \frac{t}{\frac{a}{z}}, 0.5 \cdot \frac{y}{\frac{a}{x}}\right)\\


\end{array}

Error?

Target

Original7.8
Target5.3
Herbie0.9
\[\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 3 regimes
  2. if (-.f64 (*.f64 x y) (*.f64 (*.f64 z 9) t)) < -1.99999999999999998e239

    1. Initial program 37.0

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

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

      [Start]37.0

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

      associate-*l* [=>]36.9

      \[ \frac{x \cdot y - \color{blue}{z \cdot \left(9 \cdot t\right)}}{a \cdot 2} \]
    3. Applied egg-rr18.1

      \[\leadsto \color{blue}{\left(x \cdot y\right) \cdot \frac{0.5}{a} + \left(-\frac{z}{a} \cdot \frac{9 \cdot t}{2}\right)} \]
    4. Simplified1.0

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

      [Start]18.1

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

      sub-neg [<=]18.1

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

      associate-*l* [=>]1.0

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

      associate-/l* [=>]1.0

      \[ x \cdot \left(y \cdot \frac{0.5}{a}\right) - \frac{z}{a} \cdot \color{blue}{\frac{9}{\frac{2}{t}}} \]
    5. Applied egg-rr1.0

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

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

    if -1.99999999999999998e239 < (-.f64 (*.f64 x y) (*.f64 (*.f64 z 9) t)) < 2e288

    1. Initial program 0.9

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

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

      [Start]0.9

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

      fma-neg [=>]0.9

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

      associate-*l* [=>]0.9

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

      distribute-rgt-neg-in [=>]0.9

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

      *-commutative [=>]0.9

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

      distribute-rgt-neg-in [=>]0.9

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

      metadata-eval [=>]0.9

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

    if 2e288 < (-.f64 (*.f64 x y) (*.f64 (*.f64 z 9) t))

    1. Initial program 54.5

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

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

      [Start]54.5

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

      associate-*l* [=>]54.4

      \[ \frac{x \cdot y - \color{blue}{z \cdot \left(9 \cdot t\right)}}{a \cdot 2} \]
    3. Taylor expanded in x around 0 54.1

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

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

      [Start]54.1

      \[ -4.5 \cdot \frac{t \cdot z}{a} + 0.5 \cdot \frac{y \cdot x}{a} \]

      fma-def [=>]54.1

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

      associate-/l* [=>]29.9

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

      associate-/l* [=>]0.7

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y - \left(z \cdot 9\right) \cdot t \leq -2 \cdot 10^{+239}:\\ \;\;\;\;\frac{y \cdot 0.5}{\frac{a}{x}} - \frac{z \cdot 4.5}{\frac{a}{t}}\\ \mathbf{elif}\;x \cdot y - \left(z \cdot 9\right) \cdot t \leq 2 \cdot 10^{+288}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, y, z \cdot \left(t \cdot -9\right)\right)}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-4.5, \frac{t}{\frac{a}{z}}, 0.5 \cdot \frac{y}{\frac{a}{x}}\right)\\ \end{array} \]

Alternatives

Alternative 1
Error0.9
Cost8393
\[\begin{array}{l} t_1 := x \cdot y - \left(z \cdot 9\right) \cdot t\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{+239} \lor \neg \left(t_1 \leq 2 \cdot 10^{+288}\right):\\ \;\;\;\;\frac{y \cdot 0.5}{\frac{a}{x}} - \frac{z \cdot 4.5}{\frac{a}{t}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, y, z \cdot \left(t \cdot -9\right)\right)}{a \cdot 2}\\ \end{array} \]
Alternative 2
Error0.9
Cost2249
\[\begin{array}{l} t_1 := x \cdot y - \left(z \cdot 9\right) \cdot t\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{+239} \lor \neg \left(t_1 \leq 2 \cdot 10^{+288}\right):\\ \;\;\;\;x \cdot \left(y \cdot \frac{0.5}{a}\right) + \frac{z \cdot -4.5}{\frac{a}{t}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot y + z \cdot \left(t \cdot -9\right)}{a \cdot 2}\\ \end{array} \]
Alternative 3
Error0.9
Cost2249
\[\begin{array}{l} t_1 := x \cdot y - \left(z \cdot 9\right) \cdot t\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{+239} \lor \neg \left(t_1 \leq 2 \cdot 10^{+288}\right):\\ \;\;\;\;\frac{y \cdot 0.5}{\frac{a}{x}} - \frac{z \cdot 4.5}{\frac{a}{t}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot y + z \cdot \left(t \cdot -9\right)}{a \cdot 2}\\ \end{array} \]
Alternative 4
Error4.3
Cost2120
\[\begin{array}{l} t_1 := x \cdot y - \left(z \cdot 9\right) \cdot t\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;-4.5 \cdot \left(z \cdot \frac{t}{a}\right)\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+293}:\\ \;\;\;\;\frac{x \cdot y + z \cdot \left(t \cdot -9\right)}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{y}{a}}{\frac{2}{x}}\\ \end{array} \]
Alternative 5
Error24.8
Cost1505
\[\begin{array}{l} t_1 := 0.5 \cdot \left(x \cdot \frac{y}{a}\right)\\ t_2 := z \cdot \frac{t \cdot -4.5}{a}\\ \mathbf{if}\;z \leq -1.35 \cdot 10^{+225}:\\ \;\;\;\;-4.5 \cdot \frac{t}{\frac{a}{z}}\\ \mathbf{elif}\;z \leq -1.65 \cdot 10^{+186}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.7 \cdot 10^{+123}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -1.45 \cdot 10^{+99}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.3 \cdot 10^{+54}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -2.1 \cdot 10^{+29}:\\ \;\;\;\;\frac{x \cdot 0.5}{\frac{a}{y}}\\ \mathbf{elif}\;z \leq -2.8 \cdot 10^{+21} \lor \neg \left(z \leq 2.25 \cdot 10^{-125}\right):\\ \;\;\;\;-4.5 \cdot \left(t \cdot \frac{z}{a}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot y\right) \cdot \frac{0.5}{a}\\ \end{array} \]
Alternative 6
Error5.0
Cost1353
\[\begin{array}{l} \mathbf{if}\;x \cdot y \leq -5 \cdot 10^{+221} \lor \neg \left(x \cdot y \leq 2 \cdot 10^{+180}\right):\\ \;\;\;\;0.5 \cdot \left(x \cdot \frac{y}{a}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5}{a} \cdot \left(x \cdot y + z \cdot \left(t \cdot -9\right)\right)\\ \end{array} \]
Alternative 7
Error23.5
Cost1108
\[\begin{array}{l} \mathbf{if}\;y \leq -6.2 \cdot 10^{-106}:\\ \;\;\;\;0.5 \cdot \left(x \cdot \frac{y}{a}\right)\\ \mathbf{elif}\;y \leq 3.15:\\ \;\;\;\;-4.5 \cdot \frac{t}{\frac{a}{z}}\\ \mathbf{elif}\;y \leq 290000000000:\\ \;\;\;\;y \cdot \frac{x \cdot 0.5}{a}\\ \mathbf{elif}\;y \leq 3.35 \cdot 10^{+44}:\\ \;\;\;\;-4.5 \cdot \left(z \cdot \frac{t}{a}\right)\\ \mathbf{elif}\;y \leq 3.8 \cdot 10^{+225}:\\ \;\;\;\;\left(x \cdot y\right) \cdot \frac{0.5}{a}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{y}{\frac{a}{x}}\\ \end{array} \]
Alternative 8
Error23.6
Cost1108
\[\begin{array}{l} t_1 := \left(x \cdot y\right) \cdot \frac{0.5}{a}\\ \mathbf{if}\;y \leq -6.1 \cdot 10^{-106}:\\ \;\;\;\;0.5 \cdot \left(x \cdot \frac{y}{a}\right)\\ \mathbf{elif}\;y \leq 7.6 \cdot 10^{-62}:\\ \;\;\;\;\frac{-4.5}{\frac{a}{z \cdot t}}\\ \mathbf{elif}\;y \leq 54000000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 7.8 \cdot 10^{+46}:\\ \;\;\;\;-4.5 \cdot \left(z \cdot \frac{t}{a}\right)\\ \mathbf{elif}\;y \leq 2.6 \cdot 10^{+224}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{y}{\frac{a}{x}}\\ \end{array} \]
Alternative 9
Error23.4
Cost977
\[\begin{array}{l} t_1 := 0.5 \cdot \left(x \cdot \frac{y}{a}\right)\\ \mathbf{if}\;y \leq -4.05 \cdot 10^{-106}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 0.026:\\ \;\;\;\;-4.5 \cdot \frac{t}{\frac{a}{z}}\\ \mathbf{elif}\;y \leq 4000000000 \lor \neg \left(y \leq 2.25 \cdot 10^{+43}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;-4.5 \cdot \left(z \cdot \frac{t}{a}\right)\\ \end{array} \]
Alternative 10
Error23.4
Cost976
\[\begin{array}{l} t_1 := 0.5 \cdot \left(x \cdot \frac{y}{a}\right)\\ \mathbf{if}\;y \leq -1.5 \cdot 10^{-106}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 0.014:\\ \;\;\;\;-4.5 \cdot \frac{t}{\frac{a}{z}}\\ \mathbf{elif}\;y \leq 200000000000:\\ \;\;\;\;0.5 \cdot \frac{y}{\frac{a}{x}}\\ \mathbf{elif}\;y \leq 7.6 \cdot 10^{+46}:\\ \;\;\;\;-4.5 \cdot \left(z \cdot \frac{t}{a}\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 11
Error23.4
Cost976
\[\begin{array}{l} t_1 := 0.5 \cdot \left(x \cdot \frac{y}{a}\right)\\ \mathbf{if}\;y \leq -3.6 \cdot 10^{-107}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 0.68:\\ \;\;\;\;-4.5 \cdot \frac{t}{\frac{a}{z}}\\ \mathbf{elif}\;y \leq 480000000000:\\ \;\;\;\;y \cdot \frac{x \cdot 0.5}{a}\\ \mathbf{elif}\;y \leq 1.1 \cdot 10^{+40}:\\ \;\;\;\;-4.5 \cdot \left(z \cdot \frac{t}{a}\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 12
Error32.5
Cost580
\[\begin{array}{l} \mathbf{if}\;a \leq 1.25 \cdot 10^{-205}:\\ \;\;\;\;-4.5 \cdot \left(t \cdot \frac{z}{a}\right)\\ \mathbf{else}:\\ \;\;\;\;-4.5 \cdot \left(z \cdot \frac{t}{a}\right)\\ \end{array} \]
Alternative 13
Error32.5
Cost448
\[-4.5 \cdot \left(z \cdot \frac{t}{a}\right) \]
Alternative 14
Error32.3
Cost448
\[-4.5 \cdot \frac{t}{\frac{a}{z}} \]

Error

Reproduce?

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