?

Average Error: 3.3 → 0.9
Time: 18.1s
Precision: binary64
Cost: 1220

?

\[ \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}\;z \leq 3 \cdot 10^{-307}:\\ \;\;\;\;\left(x \cdot 2 + \left(z \cdot t\right) \cdot \left(y \cdot -9\right)\right) + a \cdot \left(27 \cdot b\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} \]
(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 (<= z 3e-307)
   (+ (+ (* x 2.0) (* (* z t) (* y -9.0))) (* a (* 27.0 b)))
   (+ (+ (* x 2.0) (* t (* z (* y -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 (z <= 3e-307) {
		tmp = ((x * 2.0) + ((z * t) * (y * -9.0))) + (a * (27.0 * b));
	} else {
		tmp = ((x * 2.0) + (t * (z * (y * -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 (z <= 3d-307) then
        tmp = ((x * 2.0d0) + ((z * t) * (y * (-9.0d0)))) + (a * (27.0d0 * b))
    else
        tmp = ((x * 2.0d0) + (t * (z * (y * (-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 (z <= 3e-307) {
		tmp = ((x * 2.0) + ((z * t) * (y * -9.0))) + (a * (27.0 * b));
	} else {
		tmp = ((x * 2.0) + (t * (z * (y * -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 z <= 3e-307:
		tmp = ((x * 2.0) + ((z * t) * (y * -9.0))) + (a * (27.0 * b))
	else:
		tmp = ((x * 2.0) + (t * (z * (y * -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 (z <= 3e-307)
		tmp = Float64(Float64(Float64(x * 2.0) + Float64(Float64(z * t) * Float64(y * -9.0))) + Float64(a * Float64(27.0 * b)));
	else
		tmp = Float64(Float64(Float64(x * 2.0) + Float64(t * Float64(z * Float64(y * -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 (z <= 3e-307)
		tmp = ((x * 2.0) + ((z * t) * (y * -9.0))) + (a * (27.0 * b));
	else
		tmp = ((x * 2.0) + (t * (z * (y * -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[z, 3e-307], N[(N[(N[(x * 2.0), $MachinePrecision] + N[(N[(z * t), $MachinePrecision] * N[(y * -9.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(a * N[(27.0 * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x * 2.0), $MachinePrecision] + N[(t * N[(z * N[(y * -9.0), $MachinePrecision]), $MachinePrecision]), $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}\;z \leq 3 \cdot 10^{-307}:\\
\;\;\;\;\left(x \cdot 2 + \left(z \cdot t\right) \cdot \left(y \cdot -9\right)\right) + a \cdot \left(27 \cdot b\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}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original3.3
Target3.7
Herbie0.9
\[\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 < 2.9999999999999999e-307

    1. Initial program 5.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. Simplified0.9

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

      [Start]5.6

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

      associate-*l* [=>]0.8

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

      associate-*l* [=>]0.9

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

    if 2.9999999999999999e-307 < z

    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 \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq 3 \cdot 10^{-307}:\\ \;\;\;\;\left(x \cdot 2 + \left(z \cdot t\right) \cdot \left(y \cdot -9\right)\right) + a \cdot \left(27 \cdot b\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} \]

Alternatives

Alternative 1
Error37.4
Cost2033
\[\begin{array}{l} t_1 := 27 \cdot \left(a \cdot b\right)\\ t_2 := t \cdot \left(\left(z \cdot y\right) \cdot -9\right)\\ \mathbf{if}\;t \leq 1.65 \cdot 10^{-108}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;t \leq 4.2 \cdot 10^{-69}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.25 \cdot 10^{-40}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;t \leq 4.3 \cdot 10^{+29}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 3.9 \cdot 10^{+66}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 10^{+96}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;t \leq 8.4 \cdot 10^{+113}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 6.4 \cdot 10^{+135}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;t \leq 7.2 \cdot 10^{+170}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 2.6 \cdot 10^{+210}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;t \leq 6.2 \cdot 10^{+284} \lor \neg \left(t \leq 5 \cdot 10^{+298}\right):\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error37.5
Cost2032
\[\begin{array}{l} t_1 := t \cdot \left(\left(z \cdot y\right) \cdot -9\right)\\ t_2 := 27 \cdot \left(a \cdot b\right)\\ t_3 := y \cdot \left(\left(z \cdot t\right) \cdot -9\right)\\ \mathbf{if}\;t \leq 4.2 \cdot 10^{-104}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;t \leq 3.4 \cdot 10^{-68}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 1.6 \cdot 10^{-40}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;t \leq 2.75 \cdot 10^{+29}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 1.2 \cdot 10^{+68}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 7.2 \cdot 10^{+96}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;t \leq 7 \cdot 10^{+113}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 8.8 \cdot 10^{+133}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;t \leq 1.7 \cdot 10^{+171}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq 2.8 \cdot 10^{+210}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;t \leq 2.5 \cdot 10^{+285}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 3.9 \cdot 10^{+298}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 3
Error37.5
Cost2032
\[\begin{array}{l} t_1 := 27 \cdot \left(a \cdot b\right)\\ t_2 := t \cdot \left(\left(z \cdot y\right) \cdot -9\right)\\ \mathbf{if}\;t \leq 9 \cdot 10^{-105}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;t \leq 6.2 \cdot 10^{-69}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.5 \cdot 10^{-40}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;t \leq 6.4 \cdot 10^{+28}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 3.4 \cdot 10^{+67}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 2.85 \cdot 10^{+97}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;t \leq 5.4 \cdot 10^{+113}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 2.7 \cdot 10^{+134}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;t \leq 1.7 \cdot 10^{+171}:\\ \;\;\;\;y \cdot \left(\left(z \cdot t\right) \cdot -9\right)\\ \mathbf{elif}\;t \leq 2.9 \cdot 10^{+210}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;t \leq 2.5 \cdot 10^{+285}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 7.2 \cdot 10^{+299}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\left(y \cdot \left(z \cdot t\right)\right) \cdot -9\\ \end{array} \]
Alternative 4
Error37.6
Cost2032
\[\begin{array}{l} t_1 := 27 \cdot \left(a \cdot b\right)\\ t_2 := t \cdot \left(\left(z \cdot y\right) \cdot -9\right)\\ \mathbf{if}\;t \leq 1.8 \cdot 10^{-103}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;t \leq 3.25 \cdot 10^{-68}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.45 \cdot 10^{-40}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;t \leq 6.4 \cdot 10^{+28}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 6.6 \cdot 10^{+66}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 1.06 \cdot 10^{+97}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;t \leq 2.9 \cdot 10^{+113}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 4.5 \cdot 10^{+134}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;t \leq 10^{+171}:\\ \;\;\;\;y \cdot \left(\left(z \cdot t\right) \cdot -9\right)\\ \mathbf{elif}\;t \leq 9.6 \cdot 10^{+210}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;t \leq 3.8 \cdot 10^{+284}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 3.7 \cdot 10^{+298}:\\ \;\;\;\;\frac{1}{\frac{0.037037037037037035}{a \cdot b}}\\ \mathbf{else}:\\ \;\;\;\;\left(y \cdot \left(z \cdot t\right)\right) \cdot -9\\ \end{array} \]
Alternative 5
Error13.4
Cost1232
\[\begin{array}{l} t_1 := 27 \cdot \left(a \cdot b\right) + x \cdot 2\\ t_2 := x \cdot 2 + z \cdot \left(t \cdot \left(y \cdot -9\right)\right)\\ \mathbf{if}\;z \leq -7.8 \cdot 10^{+24}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -7.2 \cdot 10^{-94}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.3 \cdot 10^{-103}:\\ \;\;\;\;\left(y \cdot \left(z \cdot t\right)\right) \cdot -9\\ \mathbf{elif}\;z \leq 1.16 \cdot 10^{-76}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 6
Error13.1
Cost1232
\[\begin{array}{l} t_1 := 27 \cdot \left(a \cdot b\right) + x \cdot 2\\ t_2 := x \cdot 2 + \left(y \cdot \left(z \cdot t\right)\right) \cdot -9\\ \mathbf{if}\;z \leq -7.8 \cdot 10^{+24}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -8.5 \cdot 10^{-93}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.02 \cdot 10^{-103}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 8.5 \cdot 10^{-75}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + z \cdot \left(t \cdot \left(y \cdot -9\right)\right)\\ \end{array} \]
Alternative 7
Error13.5
Cost1232
\[\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)\\ t_3 := t_2 + x \cdot 2\\ \mathbf{if}\;z \leq -140000000:\\ \;\;\;\;t_2 + t_1\\ \mathbf{elif}\;z \leq -8.5 \cdot 10^{-93}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq -2.6 \cdot 10^{-104}:\\ \;\;\;\;x \cdot 2 + t_1\\ \mathbf{elif}\;z \leq 8.4 \cdot 10^{-75}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + z \cdot \left(t \cdot \left(y \cdot -9\right)\right)\\ \end{array} \]
Alternative 8
Error1.8
Cost1220
\[\begin{array}{l} \mathbf{if}\;z \leq -9 \cdot 10^{+76}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right) + \left(y \cdot \left(z \cdot t\right)\right) \cdot -9\\ \mathbf{else}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right) + \left(x \cdot 2 + t \cdot \left(\left(z \cdot y\right) \cdot -9\right)\right)\\ \end{array} \]
Alternative 9
Error0.8
Cost1220
\[\begin{array}{l} \mathbf{if}\;z \leq 7.5 \cdot 10^{-291}:\\ \;\;\;\;\left(x \cdot 2 + \left(z \cdot t\right) \cdot \left(y \cdot -9\right)\right) + a \cdot \left(27 \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right) + \left(x \cdot 2 + t \cdot \left(\left(z \cdot y\right) \cdot -9\right)\right)\\ \end{array} \]
Alternative 10
Error17.3
Cost972
\[\begin{array}{l} t_1 := 27 \cdot \left(a \cdot b\right) + x \cdot 2\\ \mathbf{if}\;z \leq -7.2 \cdot 10^{-94}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.3 \cdot 10^{-103}:\\ \;\;\;\;\left(y \cdot \left(z \cdot t\right)\right) \cdot -9\\ \mathbf{elif}\;z \leq 0.0031:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(-9 \cdot \left(y \cdot t\right)\right)\\ \end{array} \]
Alternative 11
Error32.6
Cost585
\[\begin{array}{l} \mathbf{if}\;b \leq -2.3 \cdot 10^{-20} \lor \neg \left(b \leq 5.5 \cdot 10^{+64}\right):\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 12
Error37.2
Cost192
\[x \cdot 2 \]

Error

Reproduce?

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