?

Average Error: 3.1 → 0.5
Time: 16.5s
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 4 \cdot 10^{-153}:\\ \;\;\;\;y \cdot \left(t \cdot \left(z \cdot -9\right)\right) + \left(\left(b \cdot a\right) \cdot 27 + x \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot 2 + t \cdot \left(-9 \cdot \left(z \cdot y\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 4e-153)
   (+ (* y (* t (* z -9.0))) (+ (* (* b a) 27.0) (* x 2.0)))
   (+ (+ (* x 2.0) (* t (* -9.0 (* z y)))) (* 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 <= 4e-153) {
		tmp = (y * (t * (z * -9.0))) + (((b * a) * 27.0) + (x * 2.0));
	} else {
		tmp = ((x * 2.0) + (t * (-9.0 * (z * y)))) + (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 <= 4d-153) then
        tmp = (y * (t * (z * (-9.0d0)))) + (((b * a) * 27.0d0) + (x * 2.0d0))
    else
        tmp = ((x * 2.0d0) + (t * ((-9.0d0) * (z * y)))) + (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 <= 4e-153) {
		tmp = (y * (t * (z * -9.0))) + (((b * a) * 27.0) + (x * 2.0));
	} else {
		tmp = ((x * 2.0) + (t * (-9.0 * (z * y)))) + (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 <= 4e-153:
		tmp = (y * (t * (z * -9.0))) + (((b * a) * 27.0) + (x * 2.0))
	else:
		tmp = ((x * 2.0) + (t * (-9.0 * (z * y)))) + (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 <= 4e-153)
		tmp = Float64(Float64(y * Float64(t * Float64(z * -9.0))) + Float64(Float64(Float64(b * a) * 27.0) + Float64(x * 2.0)));
	else
		tmp = Float64(Float64(Float64(x * 2.0) + Float64(t * Float64(-9.0 * Float64(z * y)))) + 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 <= 4e-153)
		tmp = (y * (t * (z * -9.0))) + (((b * a) * 27.0) + (x * 2.0));
	else
		tmp = ((x * 2.0) + (t * (-9.0 * (z * y)))) + (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, 4e-153], N[(N[(y * N[(t * N[(z * -9.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(b * a), $MachinePrecision] * 27.0), $MachinePrecision] + N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x * 2.0), $MachinePrecision] + N[(t * N[(-9.0 * N[(z * y), $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 4 \cdot 10^{-153}:\\
\;\;\;\;y \cdot \left(t \cdot \left(z \cdot -9\right)\right) + \left(\left(b \cdot a\right) \cdot 27 + x \cdot 2\right)\\

\mathbf{else}:\\
\;\;\;\;\left(x \cdot 2 + t \cdot \left(-9 \cdot \left(z \cdot y\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.1
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 < 4.00000000000000016e-153

    1. Initial program 4.0

      \[\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), \left(a \cdot 27\right) \cdot b\right)\right)} \]
      Proof

      [Start]4.0

      \[ \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- [=>]4.0

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

      fma-neg [=>]4.0

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

      neg-sub0 [=>]4.0

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

      associate-+l- [<=]4.0

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

      neg-sub0 [<=]4.0

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

      *-commutative [=>]4.0

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

      distribute-lft-neg-in [=>]4.0

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

      associate-*l* [=>]3.9

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

      *-commutative [=>]3.9

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

      associate-*r* [=>]0.5

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

      *-commutative [=>]0.5

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

      fma-def [=>]0.5

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

      distribute-lft-neg-in [<=]0.5

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

      distribute-rgt-neg-in [=>]0.5

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

      *-commutative [=>]0.5

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

      distribute-rgt-neg-in [=>]0.5

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

      metadata-eval [=>]0.5

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

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

    if 4.00000000000000016e-153 < z

    1. Initial program 0.7

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

      \[\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. Recombined 2 regimes into one program.
  4. Final simplification0.5

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

Alternatives

Alternative 1
Error16.7
Cost2020
\[\begin{array}{l} t_1 := \left(z \cdot y\right) \cdot \left(t \cdot -9\right)\\ t_2 := \left(b \cdot a\right) \cdot 27\\ t_3 := t_2 + x \cdot 2\\ t_4 := t_2 + -9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ t_5 := x \cdot 2 + \left(z \cdot t\right) \cdot \left(y \cdot -9\right)\\ \mathbf{if}\;z \leq -1.05 \cdot 10^{-88}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;z \leq -2.7 \cdot 10^{-157}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq -3.2 \cdot 10^{-180}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;z \leq 1.18 \cdot 10^{-209}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 1.25 \cdot 10^{-183}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;z \leq 5.6 \cdot 10^{-164}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 1.3 \cdot 10^{-122}:\\ \;\;\;\;t_5\\ \mathbf{elif}\;z \leq 5.5 \cdot 10^{-86}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right) + t_1\\ \mathbf{elif}\;z \leq 5.2 \cdot 10^{+96}:\\ \;\;\;\;t_5\\ \mathbf{else}:\\ \;\;\;\;t_1 + a \cdot \left(b \cdot 27\right)\\ \end{array} \]
Alternative 2
Error12.2
Cost1360
\[\begin{array}{l} t_1 := \left(z \cdot y\right) \cdot \left(t \cdot -9\right) + a \cdot \left(b \cdot 27\right)\\ t_2 := \left(b \cdot a\right) \cdot 27 + x \cdot 2\\ \mathbf{if}\;x \leq -5 \cdot 10^{-22}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 10^{-108}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.3 \cdot 10^{-76}:\\ \;\;\;\;x \cdot 2 + \left(z \cdot t\right) \cdot \left(y \cdot -9\right)\\ \mathbf{elif}\;x \leq 1.5 \cdot 10^{+32}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error12.2
Cost1360
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot 27\right) + \left(z \cdot y\right) \cdot \left(t \cdot -9\right)\\ t_2 := \left(b \cdot a\right) \cdot 27 + x \cdot 2\\ \mathbf{if}\;x \leq -9.8 \cdot 10^{-24}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 1.1 \cdot 10^{-108}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.35 \cdot 10^{-76}:\\ \;\;\;\;x \cdot 2 + \left(z \cdot t\right) \cdot \left(y \cdot -9\right)\\ \mathbf{elif}\;x \leq 8 \cdot 10^{+31}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error13.9
Cost1234
\[\begin{array}{l} \mathbf{if}\;b \leq -1.45 \cdot 10^{-190} \lor \neg \left(b \leq 1.4 \cdot 10^{-49} \lor \neg \left(b \leq 3.9 \cdot 10^{+55}\right) \land b \leq 7.6 \cdot 10^{+96}\right):\\ \;\;\;\;\left(b \cdot a\right) \cdot 27 + x \cdot 2\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + \left(z \cdot t\right) \cdot \left(y \cdot -9\right)\\ \end{array} \]
Alternative 5
Error1.6
Cost1220
\[\begin{array}{l} \mathbf{if}\;z \leq 8.2 \cdot 10^{+95}:\\ \;\;\;\;y \cdot \left(t \cdot \left(z \cdot -9\right)\right) + \left(\left(b \cdot a\right) \cdot 27 + x \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;-9 \cdot \left(z \cdot \left(y \cdot t\right)\right)\\ \end{array} \]
Alternative 6
Error29.2
Cost848
\[\begin{array}{l} \mathbf{if}\;x \leq -1.35 \cdot 10^{-22}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq 6.5 \cdot 10^{-176}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{elif}\;x \leq 4.1 \cdot 10^{-74}:\\ \;\;\;\;-9 \cdot \left(z \cdot \left(y \cdot t\right)\right)\\ \mathbf{elif}\;x \leq 3.6 \cdot 10^{+71}:\\ \;\;\;\;\left(b \cdot a\right) \cdot 27\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 7
Error29.0
Cost848
\[\begin{array}{l} \mathbf{if}\;x \leq -1.9 \cdot 10^{-21}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq 4.7 \cdot 10^{-176}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{elif}\;x \leq 1.55 \cdot 10^{-64}:\\ \;\;\;\;y \cdot \left(-9 \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;x \leq 3.5 \cdot 10^{+69}:\\ \;\;\;\;\left(b \cdot a\right) \cdot 27\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 8
Error16.1
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -1.2 \cdot 10^{+29}:\\ \;\;\;\;y \cdot \left(-9 \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;z \leq 1.58 \cdot 10^{+66}:\\ \;\;\;\;\left(b \cdot a\right) \cdot 27 + x \cdot 2\\ \mathbf{else}:\\ \;\;\;\;-9 \cdot \left(z \cdot \left(y \cdot t\right)\right)\\ \end{array} \]
Alternative 9
Error28.5
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{-22} \lor \neg \left(x \leq 3.6 \cdot 10^{+69}\right):\\ \;\;\;\;x \cdot 2\\ \mathbf{else}:\\ \;\;\;\;\left(b \cdot a\right) \cdot 27\\ \end{array} \]
Alternative 10
Error37.4
Cost192
\[x \cdot 2 \]

Error

Reproduce?

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