Average Error: 7.8 → 0.9
Time: 10.8s
Precision: binary64
Cost: 8392
\[ \begin{array}{c}[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 := y \cdot \frac{x}{a + a} + t \cdot \left(z \cdot \frac{-4.5}{a}\right)\\ t_2 := x \cdot y + t \cdot \left(z \cdot -9\right)\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 5 \cdot 10^{+217}:\\ \;\;\;\;\frac{\mathsf{fma}\left(z \cdot -9, t, x \cdot y\right)}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \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 (+ (* y (/ x (+ a a))) (* t (* z (/ -4.5 a)))))
        (t_2 (+ (* x y) (* t (* z -9.0)))))
   (if (<= t_2 (- INFINITY))
     t_1
     (if (<= t_2 5e+217) (/ (fma (* z -9.0) t (* x y)) (* a 2.0)) t_1))))
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 = (y * (x / (a + a))) + (t * (z * (-4.5 / a)));
	double t_2 = (x * y) + (t * (z * -9.0));
	double tmp;
	if (t_2 <= -((double) INFINITY)) {
		tmp = t_1;
	} else if (t_2 <= 5e+217) {
		tmp = fma((z * -9.0), t, (x * y)) / (a * 2.0);
	} else {
		tmp = t_1;
	}
	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(y * Float64(x / Float64(a + a))) + Float64(t * Float64(z * Float64(-4.5 / a))))
	t_2 = Float64(Float64(x * y) + Float64(t * Float64(z * -9.0)))
	tmp = 0.0
	if (t_2 <= Float64(-Inf))
		tmp = t_1;
	elseif (t_2 <= 5e+217)
		tmp = Float64(fma(Float64(z * -9.0), t, Float64(x * y)) / Float64(a * 2.0));
	else
		tmp = t_1;
	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[(y * N[(x / N[(a + a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(t * N[(z * N[(-4.5 / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x * y), $MachinePrecision] + N[(t * N[(z * -9.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, (-Infinity)], t$95$1, If[LessEqual[t$95$2, 5e+217], N[(N[(N[(z * -9.0), $MachinePrecision] * t + N[(x * y), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\begin{array}{l}
t_1 := y \cdot \frac{x}{a + a} + t \cdot \left(z \cdot \frac{-4.5}{a}\right)\\
t_2 := x \cdot y + t \cdot \left(z \cdot -9\right)\\
\mathbf{if}\;t_2 \leq -\infty:\\
\;\;\;\;t_1\\

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

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


\end{array}

Error

Target

Original7.8
Target5.7
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 2 regimes
  2. if (-.f64 (*.f64 x y) (*.f64 (*.f64 z 9) t)) < -inf.0 or 5.00000000000000041e217 < (-.f64 (*.f64 x y) (*.f64 (*.f64 z 9) t))

    1. Initial program 42.2

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x}{1}, \frac{y}{a + a}, -\left(9 \cdot \left(z \cdot t\right)\right) \cdot \frac{0.5}{a}\right)} \]
    3. Simplified22.3

      \[\leadsto \color{blue}{y \cdot \frac{x}{a + a} - \frac{\left(t \cdot z\right) \cdot 4.5}{a}} \]
      Proof
      (-.f64 (*.f64 y (/.f64 x (+.f64 a a))) (/.f64 (*.f64 (*.f64 t z) 9/2) a)): 0 points increase in error, 0 points decrease in error
      (-.f64 (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 y x) (+.f64 a a))) (/.f64 (*.f64 (*.f64 t z) 9/2) a)): 25 points increase in error, 33 points decrease in error
      (-.f64 (/.f64 (Rewrite<= *-commutative_binary64 (*.f64 x y)) (+.f64 a a)) (/.f64 (*.f64 (*.f64 t z) 9/2) a)): 0 points increase in error, 0 points decrease in error
      (-.f64 (Rewrite<= associate-*r/_binary64 (*.f64 x (/.f64 y (+.f64 a a)))) (/.f64 (*.f64 (*.f64 t z) 9/2) a)): 29 points increase in error, 26 points decrease in error
      (-.f64 (*.f64 x (/.f64 y (+.f64 a a))) (/.f64 (*.f64 (Rewrite<= *-commutative_binary64 (*.f64 z t)) 9/2) a)): 0 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 x (/.f64 y (+.f64 a a))) (/.f64 (*.f64 (*.f64 z t) (Rewrite<= metadata-eval (*.f64 9 1/2))) a)): 0 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 x (/.f64 y (+.f64 a a))) (/.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 (*.f64 z t) 9) 1/2)) a)): 0 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 x (/.f64 y (+.f64 a a))) (/.f64 (*.f64 (Rewrite<= *-commutative_binary64 (*.f64 9 (*.f64 z t))) 1/2) a)): 0 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 x (/.f64 y (+.f64 a a))) (Rewrite<= associate-*r/_binary64 (*.f64 (*.f64 9 (*.f64 z t)) (/.f64 1/2 a)))): 19 points increase in error, 16 points decrease in error
      (Rewrite=> fma-neg_binary64 (fma.f64 x (/.f64 y (+.f64 a a)) (neg.f64 (*.f64 (*.f64 9 (*.f64 z t)) (/.f64 1/2 a))))): 1 points increase in error, 0 points decrease in error
      (fma.f64 (Rewrite<= /-rgt-identity_binary64 (/.f64 x 1)) (/.f64 y (+.f64 a a)) (neg.f64 (*.f64 (*.f64 9 (*.f64 z t)) (/.f64 1/2 a)))): 0 points increase in error, 0 points decrease in error
    4. Taylor expanded in t around 0 22.2

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

      \[\leadsto y \cdot \frac{x}{a + a} - \color{blue}{t \cdot \left(z \cdot \frac{4.5}{a}\right)} \]
      Proof
      (*.f64 t (*.f64 z (/.f64 9/2 a))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 t z) (/.f64 9/2 a))): 69 points increase in error, 47 points decrease in error
      (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 (*.f64 t z) 9/2) a)): 30 points increase in error, 40 points decrease in error
      (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 (*.f64 t z) a) 9/2)): 27 points increase in error, 42 points decrease in error
      (Rewrite=> *-commutative_binary64 (*.f64 9/2 (/.f64 (*.f64 t z) a))): 0 points increase in error, 0 points decrease in error

    if -inf.0 < (-.f64 (*.f64 x y) (*.f64 (*.f64 z 9) t)) < 5.00000000000000041e217

    1. Initial program 0.9

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

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

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

Alternatives

Alternative 1
Error4.6
Cost2632
\[\begin{array}{l} t_1 := \frac{x \cdot y + t \cdot \left(z \cdot -9\right)}{a \cdot 2}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;\frac{t}{a} \cdot \frac{-4.5}{\frac{1}{z}}\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+294}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;-4.5 \cdot \left(t \cdot \frac{z}{a}\right)\\ \end{array} \]
Alternative 2
Error0.9
Cost2248
\[\begin{array}{l} t_1 := y \cdot \frac{x}{a + a} + t \cdot \left(z \cdot \frac{-4.5}{a}\right)\\ t_2 := x \cdot y + t \cdot \left(z \cdot -9\right)\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 5 \cdot 10^{+217}:\\ \;\;\;\;\frac{t_2}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error25.5
Cost1108
\[\begin{array}{l} t_1 := -4.5 \cdot \left(z \cdot \frac{t}{a}\right)\\ t_2 := 0.5 \cdot \left(x \cdot \frac{y}{a}\right)\\ \mathbf{if}\;y \leq -7.6 \cdot 10^{+40}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -1.8 \cdot 10^{-157}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -5.9 \cdot 10^{-179}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 2.1 \cdot 10^{-298}:\\ \;\;\;\;-4.5 \cdot \left(t \cdot \frac{z}{a}\right)\\ \mathbf{elif}\;y \leq 2.9 \cdot 10^{+65}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error25.5
Cost1108
\[\begin{array}{l} t_1 := -4.5 \cdot \left(z \cdot \frac{t}{a}\right)\\ t_2 := 0.5 \cdot \left(x \cdot \frac{y}{a}\right)\\ \mathbf{if}\;y \leq -9 \cdot 10^{+39}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -1.8 \cdot 10^{-157}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -5.9 \cdot 10^{-179}:\\ \;\;\;\;x \cdot \left(y \cdot \frac{0.5}{a}\right)\\ \mathbf{elif}\;y \leq 1.85 \cdot 10^{-301}:\\ \;\;\;\;-4.5 \cdot \left(t \cdot \frac{z}{a}\right)\\ \mathbf{elif}\;y \leq 1.2 \cdot 10^{+66}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 5
Error25.3
Cost1108
\[\begin{array}{l} t_1 := -4.5 \cdot \left(z \cdot \frac{t}{a}\right)\\ \mathbf{if}\;y \leq -1.2 \cdot 10^{+37}:\\ \;\;\;\;0.5 \cdot \left(x \cdot \frac{y}{a}\right)\\ \mathbf{elif}\;y \leq -1.8 \cdot 10^{-157}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -5.9 \cdot 10^{-179}:\\ \;\;\;\;x \cdot \left(y \cdot \frac{0.5}{a}\right)\\ \mathbf{elif}\;y \leq 1.26 \cdot 10^{-300}:\\ \;\;\;\;-4.5 \cdot \left(t \cdot \frac{z}{a}\right)\\ \mathbf{elif}\;y \leq 1.9 \cdot 10^{+71}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x \cdot \frac{0.5}{a}\right)\\ \end{array} \]
Alternative 6
Error25.3
Cost1108
\[\begin{array}{l} t_1 := -4.5 \cdot \left(z \cdot \frac{t}{a}\right)\\ \mathbf{if}\;y \leq -2.8 \cdot 10^{+40}:\\ \;\;\;\;0.5 \cdot \left(x \cdot \frac{y}{a}\right)\\ \mathbf{elif}\;y \leq -1.8 \cdot 10^{-157}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -5.9 \cdot 10^{-179}:\\ \;\;\;\;x \cdot \left(y \cdot \frac{0.5}{a}\right)\\ \mathbf{elif}\;y \leq 5.2 \cdot 10^{-300}:\\ \;\;\;\;-4.5 \cdot \left(t \cdot \frac{z}{a}\right)\\ \mathbf{elif}\;y \leq 2.9 \cdot 10^{+65}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot 0.5}{\frac{a}{x}}\\ \end{array} \]
Alternative 7
Error25.3
Cost1108
\[\begin{array}{l} t_1 := -4.5 \cdot \left(z \cdot \frac{t}{a}\right)\\ \mathbf{if}\;y \leq -2 \cdot 10^{+42}:\\ \;\;\;\;0.5 \cdot \left(x \cdot \frac{y}{a}\right)\\ \mathbf{elif}\;y \leq -1.8 \cdot 10^{-157}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -1.75 \cdot 10^{-190}:\\ \;\;\;\;\frac{x \cdot y}{a \cdot 2}\\ \mathbf{elif}\;y \leq 7.5 \cdot 10^{-302}:\\ \;\;\;\;\frac{t \cdot -4.5}{\frac{a}{z}}\\ \mathbf{elif}\;y \leq 2.9 \cdot 10^{+65}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot 0.5}{\frac{a}{x}}\\ \end{array} \]
Alternative 8
Error7.2
Cost1096
\[\begin{array}{l} \mathbf{if}\;z \leq -5.5 \cdot 10^{+269}:\\ \;\;\;\;-4.5 \cdot \left(z \cdot \frac{t}{a}\right)\\ \mathbf{elif}\;z \leq 7.2 \cdot 10^{+48}:\\ \;\;\;\;\frac{0.5}{a} \cdot \left(x \cdot y + -9 \cdot \left(z \cdot t\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{t}{a} \cdot \frac{-4.5}{\frac{1}{z}}\\ \end{array} \]
Alternative 9
Error31.3
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -4 \cdot 10^{+88}:\\ \;\;\;\;-4.5 \cdot \frac{t}{\frac{a}{z}}\\ \mathbf{elif}\;z \leq 2.2 \cdot 10^{-41}:\\ \;\;\;\;-4.5 \cdot \frac{z \cdot t}{a}\\ \mathbf{else}:\\ \;\;\;\;-4.5 \cdot \left(t \cdot \frac{z}{a}\right)\\ \end{array} \]
Alternative 10
Error32.9
Cost448
\[-4.5 \cdot \left(t \cdot \frac{z}{a}\right) \]
Alternative 11
Error32.9
Cost448
\[-4.5 \cdot \left(z \cdot \frac{t}{a}\right) \]

Error

Reproduce

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