?

Average Error: 4.49% → 1.05%
Time: 18.4s
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} t_1 := a \cdot \left(27 \cdot b\right)\\ \mathbf{if}\;y \cdot 9 \leq -1 \cdot 10^{-32}:\\ \;\;\;\;t_1 + \left(x \cdot 2 - \left(y \cdot 9\right) \cdot \left(z \cdot t\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(t_1 + x \cdot 2\right) + z \cdot \left(y \cdot \left(t \cdot -9\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 (<= (* y 9.0) -1e-32)
     (+ t_1 (- (* x 2.0) (* (* y 9.0) (* z t))))
     (+ (+ t_1 (* x 2.0)) (* z (* y (* t -9.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 t_1 = a * (27.0 * b);
	double tmp;
	if ((y * 9.0) <= -1e-32) {
		tmp = t_1 + ((x * 2.0) - ((y * 9.0) * (z * t)));
	} else {
		tmp = (t_1 + (x * 2.0)) + (z * (y * (t * -9.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) :: t_1
    real(8) :: tmp
    t_1 = a * (27.0d0 * b)
    if ((y * 9.0d0) <= (-1d-32)) then
        tmp = t_1 + ((x * 2.0d0) - ((y * 9.0d0) * (z * t)))
    else
        tmp = (t_1 + (x * 2.0d0)) + (z * (y * (t * (-9.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 t_1 = a * (27.0 * b);
	double tmp;
	if ((y * 9.0) <= -1e-32) {
		tmp = t_1 + ((x * 2.0) - ((y * 9.0) * (z * t)));
	} else {
		tmp = (t_1 + (x * 2.0)) + (z * (y * (t * -9.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):
	t_1 = a * (27.0 * b)
	tmp = 0
	if (y * 9.0) <= -1e-32:
		tmp = t_1 + ((x * 2.0) - ((y * 9.0) * (z * t)))
	else:
		tmp = (t_1 + (x * 2.0)) + (z * (y * (t * -9.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)
	t_1 = Float64(a * Float64(27.0 * b))
	tmp = 0.0
	if (Float64(y * 9.0) <= -1e-32)
		tmp = Float64(t_1 + Float64(Float64(x * 2.0) - Float64(Float64(y * 9.0) * Float64(z * t))));
	else
		tmp = Float64(Float64(t_1 + Float64(x * 2.0)) + Float64(z * Float64(y * Float64(t * -9.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)
	t_1 = a * (27.0 * b);
	tmp = 0.0;
	if ((y * 9.0) <= -1e-32)
		tmp = t_1 + ((x * 2.0) - ((y * 9.0) * (z * t)));
	else
		tmp = (t_1 + (x * 2.0)) + (z * (y * (t * -9.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_] := Block[{t$95$1 = N[(a * N[(27.0 * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(y * 9.0), $MachinePrecision], -1e-32], N[(t$95$1 + N[(N[(x * 2.0), $MachinePrecision] - N[(N[(y * 9.0), $MachinePrecision] * N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$1 + N[(x * 2.0), $MachinePrecision]), $MachinePrecision] + N[(z * N[(y * N[(t * -9.0), $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}\;y \cdot 9 \leq -1 \cdot 10^{-32}:\\
\;\;\;\;t_1 + \left(x \cdot 2 - \left(y \cdot 9\right) \cdot \left(z \cdot t\right)\right)\\

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original4.49%
Target5.09%
Herbie1.05%
\[\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) < -1.00000000000000006e-32

    1. Initial program 6.97

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

      \[\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]6.97

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

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

      \[ \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 -1.00000000000000006e-32 < (*.f64 y 9)

    1. Initial program 1.11

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

      \[\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]1.11

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

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

      \[ \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)} \]
    3. Taylor expanded in y around 0 9.47

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

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

      [Start]9.47

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

      *-commutative [<=]9.47

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

      associate-*r* [=>]1.05

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

      associate-*l* [<=]1.04

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

      *-commutative [=>]1.04

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

      associate-*l* [=>]1.25

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

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

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

Alternatives

Alternative 1
Error21.95%
Cost1364
\[\begin{array}{l} t_1 := x \cdot 2 - \left(y \cdot 9\right) \cdot \left(z \cdot t\right)\\ t_2 := x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;a \leq -1.1 \cdot 10^{+37}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq -1.75 \cdot 10^{-42}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -7 \cdot 10^{-113}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq -2.1 \cdot 10^{-184}:\\ \;\;\;\;x \cdot 2 + \left(y \cdot t\right) \cdot \left(z \cdot -9\right)\\ \mathbf{elif}\;a \leq 1.25 \cdot 10^{-177}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 2
Error2.15%
Cost1220
\[\begin{array}{l} \mathbf{if}\;z \leq -8.4 \cdot 10^{+98}:\\ \;\;\;\;x \cdot 2 - \left(y \cdot 9\right) \cdot \left(z \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot 2 + t \cdot \left(\left(y \cdot z\right) \cdot -9\right)\right) + b \cdot \left(a \cdot 27\right)\\ \end{array} \]
Alternative 3
Error0.95%
Cost1220
\[\begin{array}{l} \mathbf{if}\;z \leq 5 \cdot 10^{-48}:\\ \;\;\;\;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 + t \cdot \left(\left(y \cdot z\right) \cdot -9\right)\right) + b \cdot \left(a \cdot 27\right)\\ \end{array} \]
Alternative 4
Error45.63%
Cost1108
\[\begin{array}{l} t_1 := -9 \cdot \left(t \cdot \left(y \cdot z\right)\right)\\ t_2 := 27 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;x \leq -3.7 \cdot 10^{-45}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -3.7 \cdot 10^{-191}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -2.7 \cdot 10^{-292}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.85 \cdot 10^{-136}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 4 \cdot 10^{-71}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 5
Error45.75%
Cost1108
\[\begin{array}{l} t_1 := 27 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;x \leq -1.45 \cdot 10^{-44}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -8 \cdot 10^{-193}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -7.5 \cdot 10^{-297}:\\ \;\;\;\;y \cdot \left(t \cdot \left(z \cdot -9\right)\right)\\ \mathbf{elif}\;x \leq 1.5 \cdot 10^{-135}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.95 \cdot 10^{-70}:\\ \;\;\;\;-9 \cdot \left(t \cdot \left(y \cdot z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 6
Error45.98%
Cost1108
\[\begin{array}{l} t_1 := 27 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;x \leq -4.2 \cdot 10^{-43}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -2.1 \cdot 10^{-186}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -2.8 \cdot 10^{-296}:\\ \;\;\;\;z \cdot \left(y \cdot \left(t \cdot -9\right)\right)\\ \mathbf{elif}\;x \leq 8.4 \cdot 10^{-137}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 4.5 \cdot 10^{-71}:\\ \;\;\;\;-9 \cdot \left(t \cdot \left(y \cdot z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 7
Error29.88%
Cost1105
\[\begin{array}{l} t_1 := x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;x \leq -6.8 \cdot 10^{-194}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -7.3 \cdot 10^{-211}:\\ \;\;\;\;z \cdot \left(y \cdot \left(t \cdot -9\right)\right)\\ \mathbf{elif}\;x \leq 8.2 \cdot 10^{-135} \lor \neg \left(x \leq 10^{-71}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;-9 \cdot \left(t \cdot \left(y \cdot z\right)\right)\\ \end{array} \]
Alternative 8
Error19.33%
Cost1097
\[\begin{array}{l} t_1 := 27 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;x \leq -3.1 \cdot 10^{-56} \lor \neg \left(x \leq 5.4 \cdot 10^{-71}\right):\\ \;\;\;\;x \cdot 2 + t_1\\ \mathbf{else}:\\ \;\;\;\;t_1 + z \cdot \left(y \cdot \left(t \cdot -9\right)\right)\\ \end{array} \]
Alternative 9
Error19.37%
Cost1097
\[\begin{array}{l} \mathbf{if}\;x \leq -6.5 \cdot 10^{-57} \lor \neg \left(x \leq 1.95 \cdot 10^{-71}\right):\\ \;\;\;\;x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right) + z \cdot \left(y \cdot \left(t \cdot -9\right)\right)\\ \end{array} \]
Alternative 10
Error22.15%
Cost969
\[\begin{array}{l} \mathbf{if}\;a \leq -2.6 \cdot 10^{-113} \lor \neg \left(a \leq 2.3 \cdot 10^{-177}\right):\\ \;\;\;\;x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + \left(y \cdot t\right) \cdot \left(z \cdot -9\right)\\ \end{array} \]
Alternative 11
Error44.67%
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -2.6 \cdot 10^{-43}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq 3.7 \cdot 10^{-91}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 12
Error58.2%
Cost192
\[x \cdot 2 \]

Error

Reproduce?

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