Average Error: 7.8 → 4.4
Time: 10.6s
Precision: binary64
Cost: 1612
\[ \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} \mathbf{if}\;x \cdot y \leq -\infty:\\ \;\;\;\;0.5 \cdot \left(y \cdot \frac{x}{a}\right)\\ \mathbf{elif}\;x \cdot y \leq -2 \cdot 10^{-318}:\\ \;\;\;\;\frac{t \cdot -4.5}{\frac{a}{z}} + 0.5 \cdot \frac{x \cdot y}{a}\\ \mathbf{elif}\;x \cdot y \leq 2 \cdot 10^{+250}:\\ \;\;\;\;\frac{x \cdot y - t \cdot \left(z \cdot 9\right)}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{x}{\frac{a}{y}}\\ \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
 (if (<= (* x y) (- INFINITY))
   (* 0.5 (* y (/ x a)))
   (if (<= (* x y) -2e-318)
     (+ (/ (* t -4.5) (/ a z)) (* 0.5 (/ (* x y) a)))
     (if (<= (* x y) 2e+250)
       (/ (- (* x y) (* t (* z 9.0))) (* a 2.0))
       (* 0.5 (/ x (/ a y)))))))
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 tmp;
	if ((x * y) <= -((double) INFINITY)) {
		tmp = 0.5 * (y * (x / a));
	} else if ((x * y) <= -2e-318) {
		tmp = ((t * -4.5) / (a / z)) + (0.5 * ((x * y) / a));
	} else if ((x * y) <= 2e+250) {
		tmp = ((x * y) - (t * (z * 9.0))) / (a * 2.0);
	} else {
		tmp = 0.5 * (x / (a / y));
	}
	return tmp;
}
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 tmp;
	if ((x * y) <= -Double.POSITIVE_INFINITY) {
		tmp = 0.5 * (y * (x / a));
	} else if ((x * y) <= -2e-318) {
		tmp = ((t * -4.5) / (a / z)) + (0.5 * ((x * y) / a));
	} else if ((x * y) <= 2e+250) {
		tmp = ((x * y) - (t * (z * 9.0))) / (a * 2.0);
	} else {
		tmp = 0.5 * (x / (a / y));
	}
	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):
	tmp = 0
	if (x * y) <= -math.inf:
		tmp = 0.5 * (y * (x / a))
	elif (x * y) <= -2e-318:
		tmp = ((t * -4.5) / (a / z)) + (0.5 * ((x * y) / a))
	elif (x * y) <= 2e+250:
		tmp = ((x * y) - (t * (z * 9.0))) / (a * 2.0)
	else:
		tmp = 0.5 * (x / (a / y))
	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)
	tmp = 0.0
	if (Float64(x * y) <= Float64(-Inf))
		tmp = Float64(0.5 * Float64(y * Float64(x / a)));
	elseif (Float64(x * y) <= -2e-318)
		tmp = Float64(Float64(Float64(t * -4.5) / Float64(a / z)) + Float64(0.5 * Float64(Float64(x * y) / a)));
	elseif (Float64(x * y) <= 2e+250)
		tmp = Float64(Float64(Float64(x * y) - Float64(t * Float64(z * 9.0))) / Float64(a * 2.0));
	else
		tmp = Float64(0.5 * Float64(x / Float64(a / y)));
	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)
	tmp = 0.0;
	if ((x * y) <= -Inf)
		tmp = 0.5 * (y * (x / a));
	elseif ((x * y) <= -2e-318)
		tmp = ((t * -4.5) / (a / z)) + (0.5 * ((x * y) / a));
	elseif ((x * y) <= 2e+250)
		tmp = ((x * y) - (t * (z * 9.0))) / (a * 2.0);
	else
		tmp = 0.5 * (x / (a / y));
	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_] := If[LessEqual[N[(x * y), $MachinePrecision], (-Infinity)], N[(0.5 * N[(y * N[(x / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], -2e-318], N[(N[(N[(t * -4.5), $MachinePrecision] / N[(a / z), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(N[(x * y), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 2e+250], N[(N[(N[(x * y), $MachinePrecision] - N[(t * N[(z * 9.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(x / N[(a / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -\infty:\\
\;\;\;\;0.5 \cdot \left(y \cdot \frac{x}{a}\right)\\

\mathbf{elif}\;x \cdot y \leq -2 \cdot 10^{-318}:\\
\;\;\;\;\frac{t \cdot -4.5}{\frac{a}{z}} + 0.5 \cdot \frac{x \cdot y}{a}\\

\mathbf{elif}\;x \cdot y \leq 2 \cdot 10^{+250}:\\
\;\;\;\;\frac{x \cdot y - t \cdot \left(z \cdot 9\right)}{a \cdot 2}\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{x}{\frac{a}{y}}\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original7.8
Target5.7
Herbie4.4
\[\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 4 regimes
  2. if (*.f64 x y) < -inf.0

    1. Initial program 64.0

      \[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \]
    2. Taylor expanded in x around 0 64.0

      \[\leadsto \color{blue}{-4.5 \cdot \frac{t \cdot z}{a} + 0.5 \cdot \frac{y \cdot x}{a}} \]
    3. Applied egg-rr64.0

      \[\leadsto \color{blue}{\frac{t \cdot -4.5}{\frac{a}{z}}} + 0.5 \cdot \frac{y \cdot x}{a} \]
    4. Taylor expanded in t around 0 64.0

      \[\leadsto \color{blue}{0.5 \cdot \frac{y \cdot x}{a}} \]
    5. Simplified4.6

      \[\leadsto \color{blue}{0.5 \cdot \left(y \cdot \frac{x}{a}\right)} \]

    if -inf.0 < (*.f64 x y) < -2.0000024e-318

    1. Initial program 3.9

      \[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \]
    2. Taylor expanded in x around 0 3.8

      \[\leadsto \color{blue}{-4.5 \cdot \frac{t \cdot z}{a} + 0.5 \cdot \frac{y \cdot x}{a}} \]
    3. Applied egg-rr3.7

      \[\leadsto \color{blue}{\frac{t \cdot -4.5}{\frac{a}{z}}} + 0.5 \cdot \frac{y \cdot x}{a} \]

    if -2.0000024e-318 < (*.f64 x y) < 1.9999999999999998e250

    1. Initial program 4.8

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

    if 1.9999999999999998e250 < (*.f64 x y)

    1. Initial program 41.2

      \[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \]
    2. Taylor expanded in x around inf 41.8

      \[\leadsto \color{blue}{0.5 \cdot \frac{y \cdot x}{a}} \]
    3. Applied egg-rr5.5

      \[\leadsto \color{blue}{\frac{0.5 \cdot y}{\frac{a}{x}}} \]
    4. Taylor expanded in y around 0 41.8

      \[\leadsto \color{blue}{0.5 \cdot \frac{y \cdot x}{a}} \]
    5. Simplified5.8

      \[\leadsto \color{blue}{0.5 \cdot \frac{x}{\frac{a}{y}}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification4.4

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

Alternatives

Alternative 1
Error4.4
Cost2632
\[\begin{array}{l} t_1 := \frac{x \cdot y - t \cdot \left(z \cdot 9\right)}{a \cdot 2}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;z \cdot \left(-4.5 \cdot \frac{t}{a}\right)\\ \mathbf{elif}\;t_1 \leq 10^{+302}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{x}{\frac{a}{y}}\\ \end{array} \]
Alternative 2
Error23.5
Cost1108
\[\begin{array}{l} t_1 := \frac{t \cdot \left(-4.5 \cdot z\right)}{a}\\ t_2 := 0.5 \cdot \left(y \cdot \frac{x}{a}\right)\\ \mathbf{if}\;y \leq -9.988929591502933 \cdot 10^{-45}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 1.0560528955304978 \cdot 10^{-128}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 7.8 \cdot 10^{+60}:\\ \;\;\;\;\frac{t \cdot -4.5}{\frac{a}{z}}\\ \mathbf{elif}\;y \leq 3.5 \cdot 10^{+180}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 1.5 \cdot 10^{+195}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error23.5
Cost1108
\[\begin{array}{l} t_1 := 0.5 \cdot \left(y \cdot \frac{x}{a}\right)\\ t_2 := \frac{t \cdot \left(-4.5 \cdot z\right)}{a}\\ \mathbf{if}\;y \leq -9.988929591502933 \cdot 10^{-45}:\\ \;\;\;\;0.5 \cdot \frac{x}{\frac{a}{y}}\\ \mathbf{elif}\;y \leq 1.0560528955304978 \cdot 10^{-128}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 7.8 \cdot 10^{+60}:\\ \;\;\;\;\frac{t \cdot -4.5}{\frac{a}{z}}\\ \mathbf{elif}\;y \leq 3.5 \cdot 10^{+180}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.5 \cdot 10^{+195}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error23.2
Cost1108
\[\begin{array}{l} t_1 := 0.5 \cdot \left(y \cdot \frac{x}{a}\right)\\ t_2 := \frac{t \cdot \left(-4.5 \cdot z\right)}{a}\\ \mathbf{if}\;y \leq -1.9431080243008287 \cdot 10^{-69}:\\ \;\;\;\;0.5 \cdot \left(x \cdot \frac{y}{a}\right)\\ \mathbf{elif}\;y \leq 1.0560528955304978 \cdot 10^{-128}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 7.8 \cdot 10^{+60}:\\ \;\;\;\;\frac{t \cdot -4.5}{\frac{a}{z}}\\ \mathbf{elif}\;y \leq 3.5 \cdot 10^{+180}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.5 \cdot 10^{+195}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error24.3
Cost712
\[\begin{array}{l} t_1 := \frac{t \cdot -4.5}{\frac{a}{z}}\\ \mathbf{if}\;z \leq -5.897822101772531 \cdot 10^{-83}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 8.524017256470145 \cdot 10^{-158}:\\ \;\;\;\;0.5 \cdot \left(y \cdot \frac{x}{a}\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error32.1
Cost448
\[0.5 \cdot \left(y \cdot \frac{x}{a}\right) \]

Error

Reproduce

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