?

Average Error: 7.5 → 4.6
Time: 13.7s
Precision: binary64
Cost: 3400

?

\[ \begin{array}{c}[x, y] = \mathsf{sort}([x, y])\\ \end{array} \]
\[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \]
\[\begin{array}{l} t_1 := -4.5 \cdot \frac{t \cdot z}{a} + 0.5 \cdot \left(y \cdot \left(-9 \cdot \frac{t \cdot \left(z \cdot 0\right)}{a} + \frac{x}{a}\right)\right)\\ t_2 := \frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}\\ \mathbf{if}\;t_2 \leq -1 \cdot 10^{+275}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 10^{+301}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
(FPCore (x y z t a)
 :precision binary64
 (/ (- (* x y) (* (* z 9.0) t)) (* a 2.0)))
(FPCore (x y z t a)
 :precision binary64
 (let* ((t_1
         (+
          (* -4.5 (/ (* t z) a))
          (* 0.5 (* y (+ (* -9.0 (/ (* t (* z 0.0)) a)) (/ x a))))))
        (t_2 (/ (- (* x y) (* (* z 9.0) t)) (* a 2.0))))
   (if (<= t_2 -1e+275) t_1 (if (<= t_2 1e+301) t_2 t_1))))
double code(double x, double y, double z, double t, double a) {
	return ((x * y) - ((z * 9.0) * t)) / (a * 2.0);
}
double code(double x, double y, double z, double t, double a) {
	double t_1 = (-4.5 * ((t * z) / a)) + (0.5 * (y * ((-9.0 * ((t * (z * 0.0)) / a)) + (x / a))));
	double t_2 = ((x * y) - ((z * 9.0) * t)) / (a * 2.0);
	double tmp;
	if (t_2 <= -1e+275) {
		tmp = t_1;
	} else if (t_2 <= 1e+301) {
		tmp = t_2;
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(x, y, z, t, a)
    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
    code = ((x * y) - ((z * 9.0d0) * t)) / (a * 2.0d0)
end function
real(8) function code(x, y, z, t, a)
    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) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_1 = ((-4.5d0) * ((t * z) / a)) + (0.5d0 * (y * (((-9.0d0) * ((t * (z * 0.0d0)) / a)) + (x / a))))
    t_2 = ((x * y) - ((z * 9.0d0) * t)) / (a * 2.0d0)
    if (t_2 <= (-1d+275)) then
        tmp = t_1
    else if (t_2 <= 1d+301) then
        tmp = t_2
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
	return ((x * y) - ((z * 9.0) * t)) / (a * 2.0);
}
public static double code(double x, double y, double z, double t, double a) {
	double t_1 = (-4.5 * ((t * z) / a)) + (0.5 * (y * ((-9.0 * ((t * (z * 0.0)) / a)) + (x / a))));
	double t_2 = ((x * y) - ((z * 9.0) * t)) / (a * 2.0);
	double tmp;
	if (t_2 <= -1e+275) {
		tmp = t_1;
	} else if (t_2 <= 1e+301) {
		tmp = t_2;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z, t, a):
	return ((x * y) - ((z * 9.0) * t)) / (a * 2.0)
def code(x, y, z, t, a):
	t_1 = (-4.5 * ((t * z) / a)) + (0.5 * (y * ((-9.0 * ((t * (z * 0.0)) / a)) + (x / a))))
	t_2 = ((x * y) - ((z * 9.0) * t)) / (a * 2.0)
	tmp = 0
	if t_2 <= -1e+275:
		tmp = t_1
	elif t_2 <= 1e+301:
		tmp = t_2
	else:
		tmp = t_1
	return tmp
function code(x, y, z, t, a)
	return Float64(Float64(Float64(x * y) - Float64(Float64(z * 9.0) * t)) / Float64(a * 2.0))
end
function code(x, y, z, t, a)
	t_1 = Float64(Float64(-4.5 * Float64(Float64(t * z) / a)) + Float64(0.5 * Float64(y * Float64(Float64(-9.0 * Float64(Float64(t * Float64(z * 0.0)) / a)) + Float64(x / a)))))
	t_2 = Float64(Float64(Float64(x * y) - Float64(Float64(z * 9.0) * t)) / Float64(a * 2.0))
	tmp = 0.0
	if (t_2 <= -1e+275)
		tmp = t_1;
	elseif (t_2 <= 1e+301)
		tmp = t_2;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp = code(x, y, z, t, a)
	tmp = ((x * y) - ((z * 9.0) * t)) / (a * 2.0);
end
function tmp_2 = code(x, y, z, t, a)
	t_1 = (-4.5 * ((t * z) / a)) + (0.5 * (y * ((-9.0 * ((t * (z * 0.0)) / a)) + (x / a))));
	t_2 = ((x * y) - ((z * 9.0) * t)) / (a * 2.0);
	tmp = 0.0;
	if (t_2 <= -1e+275)
		tmp = t_1;
	elseif (t_2 <= 1e+301)
		tmp = t_2;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_] := N[(N[(N[(x * y), $MachinePrecision] - N[(N[(z * 9.0), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(-4.5 * N[(N[(t * z), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(y * N[(N[(-9.0 * N[(N[(t * N[(z * 0.0), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision] + N[(x / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(x * y), $MachinePrecision] - N[(N[(z * 9.0), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -1e+275], t$95$1, If[LessEqual[t$95$2, 1e+301], t$95$2, t$95$1]]]]
\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\begin{array}{l}
t_1 := -4.5 \cdot \frac{t \cdot z}{a} + 0.5 \cdot \left(y \cdot \left(-9 \cdot \frac{t \cdot \left(z \cdot 0\right)}{a} + \frac{x}{a}\right)\right)\\
t_2 := \frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}\\
\mathbf{if}\;t_2 \leq -1 \cdot 10^{+275}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_2 \leq 10^{+301}:\\
\;\;\;\;t_2\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original7.5
Target5.4
Herbie4.6
\[\begin{array}{l} \mathbf{if}\;a < -2.090464557976709 \cdot 10^{+86}:\\ \;\;\;\;0.5 \cdot \frac{y \cdot x}{a} - 4.5 \cdot \frac{t}{\frac{a}{z}}\\ \mathbf{elif}\;a < 2.144030707833976 \cdot 10^{+99}:\\ \;\;\;\;\frac{x \cdot y - z \cdot \left(9 \cdot t\right)}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a} \cdot \left(x \cdot 0.5\right) - \frac{t}{a} \cdot \left(z \cdot 4.5\right)\\ \end{array} \]

Derivation?

  1. Split input into 2 regimes
  2. if (/.f64 (-.f64 (*.f64 x y) (*.f64 (*.f64 z 9) t)) (*.f64 a 2)) < -9.9999999999999996e274 or 1.00000000000000005e301 < (/.f64 (-.f64 (*.f64 x y) (*.f64 (*.f64 z 9) t)) (*.f64 a 2))

    1. Initial program 51.6

      \[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \]
    2. Simplified51.3

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

      [Start]51.6

      \[ \frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \]

      rational_best_oopsla_all_46_json_45_simplify-74 [=>]51.6

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

      rational_best_oopsla_all_46_json_45_simplify-7 [=>]51.3

      \[ \frac{x \cdot y - \color{blue}{z \cdot \left(t \cdot 9\right)}}{a \cdot 2} \]
    3. Applied egg-rr51.3

      \[\leadsto \frac{\color{blue}{\left(x \cdot y + z \cdot \left(t \cdot -9\right)\right) \cdot \left(\left(x \cdot y + z \cdot \left(t \cdot -9\right)\right) \cdot \frac{1}{x \cdot y + z \cdot \left(t \cdot -9\right)}\right)}}{a \cdot 2} \]
    4. Applied egg-rr51.3

      \[\leadsto \frac{\left(x \cdot y + z \cdot \left(t \cdot -9\right)\right) \cdot \color{blue}{\left(\left(z \cdot \left(t \cdot -9\right)\right) \cdot \frac{1}{x \cdot y + z \cdot \left(t \cdot -9\right)} + x \cdot \left(\frac{1}{x \cdot y + z \cdot \left(t \cdot -9\right)} \cdot y\right)\right)}}{a \cdot 2} \]
    5. Applied egg-rr51.3

      \[\leadsto \frac{\left(x \cdot y + z \cdot \left(t \cdot -9\right)\right) \cdot \left(\left(z \cdot \left(t \cdot -9\right)\right) \cdot \frac{1}{x \cdot y + z \cdot \left(t \cdot -9\right)} + \color{blue}{\left(x \cdot \left(y \cdot \frac{1}{z \cdot \left(t \cdot -9\right) + x \cdot y}\right) + 0\right)}\right)}{a \cdot 2} \]
    6. Simplified51.3

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

      [Start]51.3

      \[ \frac{\left(x \cdot y + z \cdot \left(t \cdot -9\right)\right) \cdot \left(\left(z \cdot \left(t \cdot -9\right)\right) \cdot \frac{1}{x \cdot y + z \cdot \left(t \cdot -9\right)} + \left(x \cdot \left(y \cdot \frac{1}{z \cdot \left(t \cdot -9\right) + x \cdot y}\right) + 0\right)\right)}{a \cdot 2} \]

      rational_best_oopsla_all_46_json_45_simplify-85 [=>]51.3

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

      rational_best_oopsla_all_46_json_45_simplify-7 [=>]51.3

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

      rational_best_oopsla_all_46_json_45_simplify-74 [=>]51.3

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

      rational_best_oopsla_all_46_json_45_simplify-7 [=>]51.3

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

      rational_best_oopsla_all_46_json_45_simplify-74 [<=]51.3

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

      rational_best_oopsla_all_46_json_45_simplify-74 [=>]51.3

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

      rational_best_oopsla_all_46_json_45_simplify-35 [<=]51.3

      \[ \frac{\left(x \cdot y + z \cdot \left(t \cdot -9\right)\right) \cdot \left(\left(z \cdot \left(t \cdot -9\right)\right) \cdot \frac{1}{x \cdot y + z \cdot \left(t \cdot -9\right)} + y \cdot \left(x \cdot \frac{1}{\color{blue}{y \cdot x + -9 \cdot \left(t \cdot z\right)}}\right)\right)}{a \cdot 2} \]
    7. Taylor expanded in y around 0 39.6

      \[\leadsto \color{blue}{-4.5 \cdot \frac{t \cdot z}{a} + 0.5 \cdot \left(y \cdot \left(-9 \cdot \frac{t \cdot \left(\left(0.1111111111111111 \cdot \frac{x}{t \cdot z} + -0.1111111111111111 \cdot \frac{x}{t \cdot z}\right) \cdot z\right)}{a} + \frac{x}{a}\right)\right)} \]
    8. Simplified30.3

      \[\leadsto \color{blue}{-4.5 \cdot \frac{t \cdot z}{a} + 0.5 \cdot \left(y \cdot \left(-9 \cdot \frac{t \cdot \left(z \cdot 0\right)}{a} + \frac{x}{a}\right)\right)} \]
      Proof

      [Start]39.6

      \[ -4.5 \cdot \frac{t \cdot z}{a} + 0.5 \cdot \left(y \cdot \left(-9 \cdot \frac{t \cdot \left(\left(0.1111111111111111 \cdot \frac{x}{t \cdot z} + -0.1111111111111111 \cdot \frac{x}{t \cdot z}\right) \cdot z\right)}{a} + \frac{x}{a}\right)\right) \]

    if -9.9999999999999996e274 < (/.f64 (-.f64 (*.f64 x y) (*.f64 (*.f64 z 9) t)) (*.f64 a 2)) < 1.00000000000000005e301

    1. Initial program 0.7

      \[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification4.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \leq -1 \cdot 10^{+275}:\\ \;\;\;\;-4.5 \cdot \frac{t \cdot z}{a} + 0.5 \cdot \left(y \cdot \left(-9 \cdot \frac{t \cdot \left(z \cdot 0\right)}{a} + \frac{x}{a}\right)\right)\\ \mathbf{elif}\;\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \leq 10^{+301}:\\ \;\;\;\;\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-4.5 \cdot \frac{t \cdot z}{a} + 0.5 \cdot \left(y \cdot \left(-9 \cdot \frac{t \cdot \left(z \cdot 0\right)}{a} + \frac{x}{a}\right)\right)\\ \end{array} \]

Alternatives

Alternative 1
Error24.9
Cost976
\[\begin{array}{l} t_1 := -4.5 \cdot \frac{t \cdot z}{a}\\ t_2 := \frac{y \cdot x}{a \cdot 2}\\ \mathbf{if}\;y \leq -7 \cdot 10^{-154}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 6.8 \cdot 10^{-65}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 5.8 \cdot 10^{-14}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 4.4 \cdot 10^{+46}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 2
Error24.9
Cost976
\[\begin{array}{l} t_1 := \frac{y \cdot x}{a \cdot 2}\\ \mathbf{if}\;y \leq -1.8 \cdot 10^{-154}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.4 \cdot 10^{-57}:\\ \;\;\;\;\frac{-\left(-t \cdot -9\right) \cdot z}{a \cdot 2}\\ \mathbf{elif}\;y \leq 5.8 \cdot 10^{-14}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.16 \cdot 10^{+46}:\\ \;\;\;\;-4.5 \cdot \frac{t \cdot z}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error7.4
Cost832
\[\frac{x \cdot y - z \cdot \left(t \cdot 9\right)}{a \cdot 2} \]
Alternative 4
Error7.5
Cost832
\[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \]
Alternative 5
Error33.0
Cost448
\[-4.5 \cdot \frac{t \cdot z}{a} \]

Error

Reproduce?

herbie shell --seed 2023090 
(FPCore (x y z t a)
  :name "Diagrams.Solve.Polynomial:cubForm  from diagrams-solve-0.1, I"
  :precision binary64

  :herbie-target
  (if (< a -2.090464557976709e+86) (- (* 0.5 (/ (* y x) a)) (* 4.5 (/ t (/ a z)))) (if (< a 2.144030707833976e+99) (/ (- (* x y) (* z (* 9.0 t))) (* a 2.0)) (- (* (/ y a) (* x 0.5)) (* (/ t a) (* z 4.5)))))

  (/ (- (* x y) (* (* z 9.0) t)) (* a 2.0)))