Average Error: 3.0 → 0.7
Time: 27.7s
Precision: binary64
Cost: 13764
\[ \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 := a \cdot \left(27 \cdot b\right)\\ \mathbf{if}\;z \leq 10^{-59}:\\ \;\;\;\;\mathsf{fma}\left(x, 2, \mathsf{fma}\left(y, t \cdot \left(z \cdot -9\right), t_1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + \left(t_1 + \left(z \cdot -9\right) \cdot \left(y \cdot t\right)\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 (* a (* 27.0 b))))
   (if (<= z 1e-59)
     (fma x 2.0 (fma y (* t (* z -9.0)) t_1))
     (+ (* x 2.0) (+ t_1 (* (* z -9.0) (* y t)))))))
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 = a * (27.0 * b);
	double tmp;
	if (z <= 1e-59) {
		tmp = fma(x, 2.0, fma(y, (t * (z * -9.0)), t_1));
	} else {
		tmp = (x * 2.0) + (t_1 + ((z * -9.0) * (y * t)));
	}
	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(a * Float64(27.0 * b))
	tmp = 0.0
	if (z <= 1e-59)
		tmp = fma(x, 2.0, fma(y, Float64(t * Float64(z * -9.0)), t_1));
	else
		tmp = Float64(Float64(x * 2.0) + Float64(t_1 + Float64(Float64(z * -9.0) * Float64(y * t))));
	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[(a * N[(27.0 * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, 1e-59], N[(x * 2.0 + N[(y * N[(t * N[(z * -9.0), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision], N[(N[(x * 2.0), $MachinePrecision] + N[(t$95$1 + N[(N[(z * -9.0), $MachinePrecision] * N[(y * t), $MachinePrecision]), $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 := a \cdot \left(27 \cdot b\right)\\
\mathbf{if}\;z \leq 10^{-59}:\\
\;\;\;\;\mathsf{fma}\left(x, 2, \mathsf{fma}\left(y, t \cdot \left(z \cdot -9\right), t_1\right)\right)\\

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


\end{array}

Error

Target

Original3.0
Target3.4
Herbie0.7
\[\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 < 1e-59

    1. Initial program 3.5

      \[\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b \]
    2. Simplified0.5

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, 2, \mathsf{fma}\left(y, t \cdot \left(z \cdot -9\right), a \cdot \left(27 \cdot b\right)\right)\right)} \]
      Proof
      (fma.f64 x 2 (fma.f64 y (*.f64 t (*.f64 z -9)) (*.f64 a (*.f64 27 b)))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x 2 (fma.f64 y (*.f64 t (*.f64 z (Rewrite<= metadata-eval (neg.f64 9)))) (*.f64 a (*.f64 27 b)))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x 2 (fma.f64 y (*.f64 t (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 z 9)))) (*.f64 a (*.f64 27 b)))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x 2 (fma.f64 y (*.f64 t (neg.f64 (Rewrite<= *-commutative_binary64 (*.f64 9 z)))) (*.f64 a (*.f64 27 b)))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x 2 (fma.f64 y (Rewrite<= *-commutative_binary64 (*.f64 (neg.f64 (*.f64 9 z)) t)) (*.f64 a (*.f64 27 b)))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x 2 (fma.f64 y (Rewrite=> distribute-lft-neg-out_binary64 (neg.f64 (*.f64 (*.f64 9 z) t))) (*.f64 a (*.f64 27 b)))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x 2 (fma.f64 y (neg.f64 (*.f64 (*.f64 9 z) t)) (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 a 27) b)))): 17 points increase in error, 12 points decrease in error
      (fma.f64 x 2 (Rewrite<= fma-def_binary64 (+.f64 (*.f64 y (neg.f64 (*.f64 (*.f64 9 z) t))) (*.f64 (*.f64 a 27) b)))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x 2 (+.f64 (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 y (*.f64 (*.f64 9 z) t)))) (*.f64 (*.f64 a 27) b))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x 2 (+.f64 (neg.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 y (*.f64 9 z)) t))) (*.f64 (*.f64 a 27) b))): 20 points increase in error, 21 points decrease in error
      (fma.f64 x 2 (+.f64 (neg.f64 (*.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 y 9) z)) t)) (*.f64 (*.f64 a 27) b))): 8 points increase in error, 8 points decrease in error
      (fma.f64 x 2 (+.f64 (neg.f64 (*.f64 (*.f64 (*.f64 y 9) z) t)) (Rewrite<= remove-double-neg_binary64 (neg.f64 (neg.f64 (*.f64 (*.f64 a 27) b)))))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x 2 (Rewrite<= distribute-neg-in_binary64 (neg.f64 (+.f64 (*.f64 (*.f64 (*.f64 y 9) z) t) (neg.f64 (*.f64 (*.f64 a 27) b)))))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x 2 (neg.f64 (Rewrite<= sub-neg_binary64 (-.f64 (*.f64 (*.f64 (*.f64 y 9) z) t) (*.f64 (*.f64 a 27) b))))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-neg_binary64 (-.f64 (*.f64 x 2) (-.f64 (*.f64 (*.f64 (*.f64 y 9) z) t) (*.f64 (*.f64 a 27) b)))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-+l-_binary64 (+.f64 (-.f64 (*.f64 x 2) (*.f64 (*.f64 (*.f64 y 9) z) t)) (*.f64 (*.f64 a 27) b))): 0 points increase in error, 0 points decrease in error

    if 1e-59 < 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. Simplified13.5

      \[\leadsto \color{blue}{x \cdot 2 - \left(\left(y \cdot 9\right) \cdot \left(z \cdot t\right) - a \cdot \left(27 \cdot b\right)\right)} \]
      Proof
      (-.f64 (*.f64 x 2) (-.f64 (*.f64 (*.f64 y 9) (*.f64 z t)) (*.f64 a (*.f64 27 b)))): 0 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 x 2) (-.f64 (*.f64 (*.f64 y 9) (*.f64 z t)) (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 a 27) b)))): 17 points increase in error, 12 points decrease in error
      (-.f64 (*.f64 x 2) (-.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 (*.f64 y 9) z) t)) (*.f64 (*.f64 a 27) b))): 19 points increase in error, 25 points decrease in error
      (Rewrite<= associate-+l-_binary64 (+.f64 (-.f64 (*.f64 x 2) (*.f64 (*.f64 (*.f64 y 9) z) t)) (*.f64 (*.f64 a 27) b))): 0 points increase in error, 0 points decrease in error
    3. Taylor expanded in y around 0 13.5

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

      \[\leadsto x \cdot 2 - \left(\color{blue}{\left(9 \cdot z\right) \cdot \left(y \cdot t\right)} - a \cdot \left(27 \cdot b\right)\right) \]
      Proof
      (*.f64 (*.f64 9 z) (*.f64 y t)): 0 points increase in error, 0 points decrease in error
      (Rewrite=> *-commutative_binary64 (*.f64 (*.f64 y t) (*.f64 9 z))): 0 points increase in error, 0 points decrease in error
      (*.f64 (*.f64 y t) (Rewrite=> *-commutative_binary64 (*.f64 z 9))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 (*.f64 y t) z) 9)): 34 points increase in error, 41 points decrease in error
      (*.f64 (Rewrite<= associate-*r*_binary64 (*.f64 y (*.f64 t z))) 9): 38 points increase in error, 59 points decrease in error
      (Rewrite<= *-commutative_binary64 (*.f64 9 (*.f64 y (*.f64 t z)))): 0 points increase in error, 0 points decrease in error
  3. Recombined 2 regimes into one program.
  4. Final simplification0.7

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

Alternatives

Alternative 1
Error1.1
Cost13892
\[\begin{array}{l} \mathbf{if}\;y \cdot 9 \leq -5 \cdot 10^{+199}:\\ \;\;\;\;\mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 + y \cdot \left(-9 \cdot \left(z \cdot t\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, 2, \mathsf{fma}\left(t, y \cdot \left(z \cdot -9\right), a \cdot \left(27 \cdot b\right)\right)\right)\\ \end{array} \]
Alternative 2
Error19.0
Cost1500
\[\begin{array}{l} t_1 := x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ t_2 := t \cdot \left(y \cdot \left(z \cdot -9\right)\right)\\ \mathbf{if}\;t \leq -9.2 \cdot 10^{-82}:\\ \;\;\;\;y \cdot \left(t \cdot \left(z \cdot -9\right)\right)\\ \mathbf{elif}\;t \leq 2.15 \cdot 10^{+82}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.75 \cdot 10^{+93}:\\ \;\;\;\;-9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;t \leq 6.5 \cdot 10^{+174}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 2 \cdot 10^{+218}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 2.45 \cdot 10^{+235}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 9.2 \cdot 10^{+258}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error0.9
Cost1476
\[\begin{array}{l} \mathbf{if}\;z \cdot \left(y \cdot 9\right) \leq 1.2 \cdot 10^{+285}:\\ \;\;\;\;\left(x \cdot 2 + t \cdot \left(z \cdot \left(y \cdot -9\right)\right)\right) + b \cdot \left(a \cdot 27\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + -9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \end{array} \]
Alternative 4
Error0.7
Cost1220
\[\begin{array}{l} \mathbf{if}\;t \leq 1.7 \cdot 10^{-81}:\\ \;\;\;\;x \cdot 2 + \left(a \cdot \left(27 \cdot b\right) + \left(z \cdot -9\right) \cdot \left(y \cdot t\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot 2 + t \cdot \left(z \cdot \left(y \cdot -9\right)\right)\right) + b \cdot \left(a \cdot 27\right)\\ \end{array} \]
Alternative 5
Error0.7
Cost1220
\[\begin{array}{l} t_1 := a \cdot \left(27 \cdot b\right)\\ \mathbf{if}\;z \leq 2 \cdot 10^{-57}:\\ \;\;\;\;x \cdot 2 + \left(t_1 + \left(z \cdot t\right) \cdot \left(y \cdot -9\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + \left(t_1 + \left(z \cdot -9\right) \cdot \left(y \cdot t\right)\right)\\ \end{array} \]
Alternative 6
Error14.2
Cost1100
\[\begin{array}{l} t_1 := x \cdot 2 + -9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \mathbf{if}\;z \leq -4.9 \cdot 10^{+38}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 4.5 \cdot 10^{-89}:\\ \;\;\;\;x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;z \leq 4 \cdot 10^{+59}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t \cdot \left(y \cdot \left(z \cdot -9\right)\right)\\ \end{array} \]
Alternative 7
Error13.2
Cost968
\[\begin{array}{l} \mathbf{if}\;z \leq -1.7 \cdot 10^{+36}:\\ \;\;\;\;x \cdot 2 + -9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;z \leq 4.5 \cdot 10^{-89}:\\ \;\;\;\;x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + t \cdot \left(z \cdot \left(y \cdot -9\right)\right)\\ \end{array} \]
Alternative 8
Error28.0
Cost848
\[\begin{array}{l} t_1 := 27 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;x \leq -1.65 \cdot 10^{+115}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;x \leq -6 \cdot 10^{+85}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -9.2 \cdot 10^{+23}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;x \leq 2.8 \cdot 10^{-26}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x + x\\ \end{array} \]
Alternative 9
Error28.0
Cost848
\[\begin{array}{l} \mathbf{if}\;x \leq -6.6 \cdot 10^{+116}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;x \leq -6.2 \cdot 10^{+85}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right)\\ \mathbf{elif}\;x \leq -5.8 \cdot 10^{+23}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;x \leq 1.55 \cdot 10^{-25}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x + x\\ \end{array} \]
Alternative 10
Error36.8
Cost192
\[x + x \]

Error

Reproduce

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