Average Error: 3.0 → 0.5
Time: 17.8s
Precision: binary64
Cost: 7492
\[ \begin{array}{c}[y, z, t] = \mathsf{sort}([y, z, t])\\ \end{array} \]
\[\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b \]
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot 27\right)\\ \mathbf{if}\;z \leq -3.880781187588443 \cdot 10^{-8}:\\ \;\;\;\;\left(x \cdot 2 + y \cdot \left(t \cdot \left(z \cdot -9\right)\right)\right) + t_1\\ \mathbf{else}:\\ \;\;\;\;t_1 + \mathsf{fma}\left(\left(z \cdot y\right) \cdot -9, t, x + x\right)\\ \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (+ (- (* x 2.0) (* (* (* y 9.0) z) t)) (* (* a 27.0) b)))
(FPCore (x y z t a b)
 :precision binary64
 (let* ((t_1 (* b (* a 27.0))))
   (if (<= z -3.880781187588443e-8)
     (+ (+ (* x 2.0) (* y (* t (* z -9.0)))) t_1)
     (+ t_1 (fma (* (* z y) -9.0) t (+ x x))))))
double code(double x, double y, double z, double t, double a, double b) {
	return ((x * 2.0) - (((y * 9.0) * z) * t)) + ((a * 27.0) * b);
}
double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = b * (a * 27.0);
	double tmp;
	if (z <= -3.880781187588443e-8) {
		tmp = ((x * 2.0) + (y * (t * (z * -9.0)))) + t_1;
	} else {
		tmp = t_1 + fma(((z * y) * -9.0), t, (x + x));
	}
	return tmp;
}
function code(x, y, z, t, a, b)
	return Float64(Float64(Float64(x * 2.0) - Float64(Float64(Float64(y * 9.0) * z) * t)) + Float64(Float64(a * 27.0) * b))
end
function code(x, y, z, t, a, b)
	t_1 = Float64(b * Float64(a * 27.0))
	tmp = 0.0
	if (z <= -3.880781187588443e-8)
		tmp = Float64(Float64(Float64(x * 2.0) + Float64(y * Float64(t * Float64(z * -9.0)))) + t_1);
	else
		tmp = Float64(t_1 + fma(Float64(Float64(z * y) * -9.0), t, Float64(x + x)));
	end
	return tmp
end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(x * 2.0), $MachinePrecision] - N[(N[(N[(y * 9.0), $MachinePrecision] * z), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision] + N[(N[(a * 27.0), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(b * N[(a * 27.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -3.880781187588443e-8], N[(N[(N[(x * 2.0), $MachinePrecision] + N[(y * N[(t * N[(z * -9.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision], N[(t$95$1 + N[(N[(N[(z * y), $MachinePrecision] * -9.0), $MachinePrecision] * t + N[(x + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b
\begin{array}{l}
t_1 := b \cdot \left(a \cdot 27\right)\\
\mathbf{if}\;z \leq -3.880781187588443 \cdot 10^{-8}:\\
\;\;\;\;\left(x \cdot 2 + y \cdot \left(t \cdot \left(z \cdot -9\right)\right)\right) + t_1\\

\mathbf{else}:\\
\;\;\;\;t_1 + \mathsf{fma}\left(\left(z \cdot y\right) \cdot -9, t, x + x\right)\\


\end{array}

Error

Target

Original3.0
Target3.4
Herbie0.5
\[\begin{array}{l} \mathbf{if}\;y < 7.590524218811189 \cdot 10^{-161}:\\ \;\;\;\;\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + a \cdot \left(27 \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot 2 - 9 \cdot \left(y \cdot \left(t \cdot z\right)\right)\right) + \left(a \cdot 27\right) \cdot b\\ \end{array} \]

Derivation

  1. Split input into 2 regimes
  2. if z < -3.88078118758844331e-8

    1. Initial program 22.2

      \[\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b \]
    2. Taylor expanded in y around 0 22.2

      \[\leadsto \left(x \cdot 2 - \color{blue}{\left(9 \cdot \left(y \cdot z\right)\right)} \cdot t\right) + \left(a \cdot 27\right) \cdot b \]
    3. Taylor expanded in y around 0 0.3

      \[\leadsto \left(x \cdot 2 - \color{blue}{9 \cdot \left(y \cdot \left(t \cdot z\right)\right)}\right) + \left(a \cdot 27\right) \cdot b \]
    4. Simplified0.3

      \[\leadsto \left(x \cdot 2 - \color{blue}{y \cdot \left(t \cdot \left(9 \cdot z\right)\right)}\right) + \left(a \cdot 27\right) \cdot b \]
      Proof
      (*.f64 y (*.f64 t (*.f64 9 z))): 0 points increase in error, 0 points decrease in error
      (*.f64 y (*.f64 t (Rewrite<= *-commutative_binary64 (*.f64 z 9)))): 0 points increase in error, 0 points decrease in error
      (*.f64 y (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 t z) 9))): 32 points increase in error, 27 points decrease in error
      (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 y (*.f64 t z)) 9)): 34 points increase in error, 37 points decrease in error
      (Rewrite<= *-commutative_binary64 (*.f64 9 (*.f64 y (*.f64 t z)))): 0 points increase in error, 0 points decrease in error

    if -3.88078118758844331e-8 < z

    1. Initial program 0.6

      \[\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b \]
    2. Taylor expanded in y around 0 0.5

      \[\leadsto \left(x \cdot 2 - \color{blue}{\left(9 \cdot \left(y \cdot z\right)\right)} \cdot t\right) + \left(a \cdot 27\right) \cdot b \]
    3. Applied egg-rr0.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -3.880781187588443 \cdot 10^{-8}:\\ \;\;\;\;\left(x \cdot 2 + y \cdot \left(t \cdot \left(z \cdot -9\right)\right)\right) + b \cdot \left(a \cdot 27\right)\\ \mathbf{else}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right) + \mathsf{fma}\left(\left(z \cdot y\right) \cdot -9, t, x + x\right)\\ \end{array} \]

Alternatives

Alternative 1
Error1.2
Cost1220
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot 27\right)\\ \mathbf{if}\;z \leq 4.81396441917767 \cdot 10^{-130}:\\ \;\;\;\;\left(x \cdot 2 + y \cdot \left(t \cdot \left(z \cdot -9\right)\right)\right) + t_1\\ \mathbf{else}:\\ \;\;\;\;t_1 + \left(\left(x + x\right) - \left(z \cdot 9\right) \cdot \left(y \cdot t\right)\right)\\ \end{array} \]
Alternative 2
Error0.5
Cost1220
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot 27\right)\\ \mathbf{if}\;z \leq -1997915.999399946:\\ \;\;\;\;\left(x \cdot 2 + y \cdot \left(t \cdot \left(z \cdot -9\right)\right)\right) + t_1\\ \mathbf{else}:\\ \;\;\;\;t_1 + \left(x \cdot 2 + t \cdot \left(y \cdot \left(z \cdot -9\right)\right)\right)\\ \end{array} \]
Alternative 3
Error0.5
Cost1220
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot 27\right)\\ \mathbf{if}\;z \leq -3.880781187588443 \cdot 10^{-8}:\\ \;\;\;\;\left(x \cdot 2 + y \cdot \left(t \cdot \left(z \cdot -9\right)\right)\right) + t_1\\ \mathbf{else}:\\ \;\;\;\;t_1 + \left(x \cdot 2 + t \cdot \left(\left(z \cdot y\right) \cdot -9\right)\right)\\ \end{array} \]
Alternative 4
Error29.1
Cost1108
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot 27\right)\\ \mathbf{if}\;x \leq -6.3274694791194915 \cdot 10^{-9}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq 4.4073829173746234 \cdot 10^{-209}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 6.872283774376131 \cdot 10^{-193}:\\ \;\;\;\;y \cdot \left(z \cdot \left(t \cdot -9\right)\right)\\ \mathbf{elif}\;x \leq 2.3518512293282752 \cdot 10^{-95}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.935549636815217 \cdot 10^{+55}:\\ \;\;\;\;-9 \cdot \left(z \cdot \left(y \cdot t\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 5
Error29.1
Cost1108
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot 27\right)\\ \mathbf{if}\;x \leq -6.3274694791194915 \cdot 10^{-9}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq 4.4073829173746234 \cdot 10^{-209}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 6.872283774376131 \cdot 10^{-193}:\\ \;\;\;\;-9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;x \leq 2.3518512293282752 \cdot 10^{-95}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.935549636815217 \cdot 10^{+55}:\\ \;\;\;\;-9 \cdot \left(z \cdot \left(y \cdot t\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 6
Error14.0
Cost1100
\[\begin{array}{l} t_1 := x \cdot 2 + -9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \mathbf{if}\;z \leq -2.245442788341001 \cdot 10^{-54}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 5.679288592415012 \cdot 10^{-50}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right) + x \cdot 2\\ \mathbf{elif}\;z \leq 10^{+115}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;-9 \cdot \left(z \cdot \left(y \cdot t\right)\right)\\ \end{array} \]
Alternative 7
Error12.9
Cost1096
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot 27\right)\\ t_2 := t_1 + x \cdot 2\\ \mathbf{if}\;x \leq -6.3274694791194915 \cdot 10^{-9}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 3.935549636815217 \cdot 10^{+55}:\\ \;\;\;\;t_1 - \left(z \cdot 9\right) \cdot \left(y \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 8
Error11.8
Cost1096
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot 27\right)\\ t_2 := t_1 + x \cdot 2\\ \mathbf{if}\;x \leq -6.3274694791194915 \cdot 10^{-9}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 3.935549636815217 \cdot 10^{+55}:\\ \;\;\;\;t_1 + t \cdot \left(y \cdot \left(z \cdot -9\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 9
Error5.2
Cost1088
\[b \cdot \left(a \cdot 27\right) + \left(\left(x + x\right) - \left(z \cdot 9\right) \cdot \left(y \cdot t\right)\right) \]
Alternative 10
Error17.7
Cost972
\[\begin{array}{l} t_1 := -9 \cdot \left(z \cdot \left(y \cdot t\right)\right)\\ t_2 := b \cdot \left(a \cdot 27\right) + x \cdot 2\\ \mathbf{if}\;z \leq 10465718716.422607:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 2.3 \cdot 10^{+39}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.36 \cdot 10^{+119}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 11
Error17.7
Cost972
\[\begin{array}{l} t_1 := -9 \cdot \left(z \cdot \left(y \cdot t\right)\right)\\ \mathbf{if}\;z \leq 10465718716.422607:\\ \;\;\;\;b \cdot \left(a \cdot 27\right) + x \cdot 2\\ \mathbf{elif}\;z \leq 2.3 \cdot 10^{+39}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.36 \cdot 10^{+119}:\\ \;\;\;\;x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 12
Error28.0
Cost848
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot 27\right)\\ \mathbf{if}\;x \leq -6.3274694791194915 \cdot 10^{-9}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq 4.4073829173746234 \cdot 10^{-209}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 6.872283774376131 \cdot 10^{-193}:\\ \;\;\;\;y \cdot \left(z \cdot \left(t \cdot -9\right)\right)\\ \mathbf{elif}\;x \leq 4.354028017044254 \cdot 10^{+20}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 13
Error27.8
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -6.3274694791194915 \cdot 10^{-9}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq 4.354028017044254 \cdot 10^{+20}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 14
Error27.8
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -6.3274694791194915 \cdot 10^{-9}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq 4.354028017044254 \cdot 10^{+20}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 15
Error37.9
Cost192
\[x \cdot 2 \]
Alternative 16
Error62.4
Cost64
\[0 \]

Error

Reproduce

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

  :herbie-target
  (if (< y 7.590524218811189e-161) (+ (- (* x 2.0) (* (* (* y 9.0) z) t)) (* a (* 27.0 b))) (+ (- (* x 2.0) (* 9.0 (* y (* t z)))) (* (* a 27.0) b)))

  (+ (- (* x 2.0) (* (* (* y 9.0) z) t)) (* (* a 27.0) b)))