Average Error: 3.0 → 0.5
Time: 11.9s
Precision: binary64
Cost: 1348
\[ \begin{array}{c}[y, z, t] = \mathsf{sort}([y, z, t])\\ [a, b] = \mathsf{sort}([a, b])\\ \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} \mathbf{if}\;y \cdot 9 \leq -4 \cdot 10^{+14}:\\ \;\;\;\;\left(a \cdot \left(27 \cdot b\right) + x \cdot 2\right) + y \cdot \left(\left(z \cdot t\right) \cdot -9\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot 2 + \left(z \cdot \left(y \cdot t\right)\right) \cdot -9\right) + b \cdot \left(a \cdot 27\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
 (if (<= (* y 9.0) -4e+14)
   (+ (+ (* a (* 27.0 b)) (* x 2.0)) (* y (* (* z t) -9.0)))
   (+ (+ (* x 2.0) (* (* z (* y t)) -9.0)) (* b (* a 27.0)))))
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 tmp;
	if ((y * 9.0) <= -4e+14) {
		tmp = ((a * (27.0 * b)) + (x * 2.0)) + (y * ((z * t) * -9.0));
	} else {
		tmp = ((x * 2.0) + ((z * (y * t)) * -9.0)) + (b * (a * 27.0));
	}
	return tmp;
}
real(8) function code(x, y, z, t, a, b)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = ((x * 2.0d0) - (((y * 9.0d0) * z) * t)) + ((a * 27.0d0) * b)
end function
real(8) function code(x, y, z, t, a, b)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: tmp
    if ((y * 9.0d0) <= (-4d+14)) then
        tmp = ((a * (27.0d0 * b)) + (x * 2.0d0)) + (y * ((z * t) * (-9.0d0)))
    else
        tmp = ((x * 2.0d0) + ((z * (y * t)) * (-9.0d0))) + (b * (a * 27.0d0))
    end if
    code = tmp
end function
public static 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);
}
public static double code(double x, double y, double z, double t, double a, double b) {
	double tmp;
	if ((y * 9.0) <= -4e+14) {
		tmp = ((a * (27.0 * b)) + (x * 2.0)) + (y * ((z * t) * -9.0));
	} else {
		tmp = ((x * 2.0) + ((z * (y * t)) * -9.0)) + (b * (a * 27.0));
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	return ((x * 2.0) - (((y * 9.0) * z) * t)) + ((a * 27.0) * b)
def code(x, y, z, t, a, b):
	tmp = 0
	if (y * 9.0) <= -4e+14:
		tmp = ((a * (27.0 * b)) + (x * 2.0)) + (y * ((z * t) * -9.0))
	else:
		tmp = ((x * 2.0) + ((z * (y * t)) * -9.0)) + (b * (a * 27.0))
	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)
	tmp = 0.0
	if (Float64(y * 9.0) <= -4e+14)
		tmp = Float64(Float64(Float64(a * Float64(27.0 * b)) + Float64(x * 2.0)) + Float64(y * Float64(Float64(z * t) * -9.0)));
	else
		tmp = Float64(Float64(Float64(x * 2.0) + Float64(Float64(z * Float64(y * t)) * -9.0)) + Float64(b * Float64(a * 27.0)));
	end
	return tmp
end
function tmp = code(x, y, z, t, a, b)
	tmp = ((x * 2.0) - (((y * 9.0) * z) * t)) + ((a * 27.0) * b);
end
function tmp_2 = code(x, y, z, t, a, b)
	tmp = 0.0;
	if ((y * 9.0) <= -4e+14)
		tmp = ((a * (27.0 * b)) + (x * 2.0)) + (y * ((z * t) * -9.0));
	else
		tmp = ((x * 2.0) + ((z * (y * t)) * -9.0)) + (b * (a * 27.0));
	end
	tmp_2 = 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_] := If[LessEqual[N[(y * 9.0), $MachinePrecision], -4e+14], N[(N[(N[(a * N[(27.0 * b), $MachinePrecision]), $MachinePrecision] + N[(x * 2.0), $MachinePrecision]), $MachinePrecision] + N[(y * N[(N[(z * t), $MachinePrecision] * -9.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x * 2.0), $MachinePrecision] + N[(N[(z * N[(y * t), $MachinePrecision]), $MachinePrecision] * -9.0), $MachinePrecision]), $MachinePrecision] + N[(b * N[(a * 27.0), $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}
\mathbf{if}\;y \cdot 9 \leq -4 \cdot 10^{+14}:\\
\;\;\;\;\left(a \cdot \left(27 \cdot b\right) + x \cdot 2\right) + y \cdot \left(\left(z \cdot t\right) \cdot -9\right)\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original3.0
Target3.3
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 (*.f64 y 9) < -4e14

    1. Initial program 5.1

      \[\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.8

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

      [Start]5.1

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

      +-commutative [=>]5.1

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

      associate-*l* [=>]5.1

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

      fma-def [=>]5.1

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

      associate-*l* [=>]0.9

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

      associate-*l* [=>]0.8

      \[ \mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - \color{blue}{y \cdot \left(9 \cdot \left(z \cdot t\right)\right)}\right) \]
    3. Applied egg-rr0.8

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

    if -4e14 < (*.f64 y 9)

    1. Initial program 0.8

      \[\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 4.6

      \[\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 \]
    3. Simplified0.2

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

      [Start]4.6

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

      associate-*r* [=>]0.2

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

      *-commutative [=>]0.2

      \[ \left(x \cdot 2 - 9 \cdot \color{blue}{\left(z \cdot \left(y \cdot t\right)\right)}\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}\;y \cdot 9 \leq -4 \cdot 10^{+14}:\\ \;\;\;\;\left(a \cdot \left(27 \cdot b\right) + x \cdot 2\right) + y \cdot \left(\left(z \cdot t\right) \cdot -9\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot 2 + \left(z \cdot \left(y \cdot t\right)\right) \cdot -9\right) + b \cdot \left(a \cdot 27\right)\\ \end{array} \]

Alternatives

Alternative 1
Error0.6
Cost1348
\[\begin{array}{l} \mathbf{if}\;y \cdot 9 \leq -4 \cdot 10^{+20}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right) + \left(x \cdot 2 - \left(y \cdot 9\right) \cdot \left(z \cdot t\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot 2 + \left(z \cdot \left(y \cdot t\right)\right) \cdot -9\right) + b \cdot \left(a \cdot 27\right)\\ \end{array} \]
Alternative 2
Error0.6
Cost1220
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot 27\right)\\ \mathbf{if}\;t \leq 4 \cdot 10^{-55}:\\ \;\;\;\;\left(x \cdot 2 + \left(z \cdot \left(y \cdot t\right)\right) \cdot -9\right) + t_1\\ \mathbf{else}:\\ \;\;\;\;t_1 + \left(x \cdot 2 + t \cdot \left(\left(y \cdot z\right) \cdot -9\right)\right)\\ \end{array} \]
Alternative 3
Error13.4
Cost1096
\[\begin{array}{l} t_1 := \left(y \cdot \left(z \cdot t\right)\right) \cdot -9\\ t_2 := 27 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;x \leq -5 \cdot 10^{-174}:\\ \;\;\;\;x \cdot 2 + t_2\\ \mathbf{elif}\;x \leq 2.8 \cdot 10^{-12}:\\ \;\;\;\;t_2 + t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + t_1\\ \end{array} \]
Alternative 4
Error5.2
Cost1088
\[\left(x \cdot 2 + \left(z \cdot \left(y \cdot t\right)\right) \cdot -9\right) + b \cdot \left(a \cdot 27\right) \]
Alternative 5
Error13.4
Cost969
\[\begin{array}{l} \mathbf{if}\;a \leq -2.6 \cdot 10^{-119} \lor \neg \left(a \leq 6.2 \cdot 10^{-173}\right):\\ \;\;\;\;x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + \left(y \cdot \left(z \cdot t\right)\right) \cdot -9\\ \end{array} \]
Alternative 6
Error16.2
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -3.2 \cdot 10^{+101}:\\ \;\;\;\;\left(z \cdot \left(y \cdot t\right)\right) \cdot -9\\ \mathbf{elif}\;z \leq 2.35 \cdot 10^{+25}:\\ \;\;\;\;x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;-9 \cdot \left(t \cdot \left(y \cdot z\right)\right)\\ \end{array} \]
Alternative 7
Error28.3
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -4.1 \cdot 10^{-72}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq 2.7 \cdot 10^{-6}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 8
Error28.3
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -4 \cdot 10^{-72}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq 1.7 \cdot 10^{-10}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 9
Error37.1
Cost192
\[x \cdot 2 \]

Error

Reproduce

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